Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

1.0 KB
Raw Blame
export function buildRecentTrendRows(points: SkillUsageTrendPoint[], anchorDay: string): SkillUsageTrendPoint[] {
  const byDay = new Map(points.map((point) => [point.day, point]));
  const rows: SkillUsageTrendPoint[] = [];
  const anchor = parseLocalDayKey(anchorDay);
  for (let offset = 29; offset >= 0; offset -= 1) {
    const date = new Date(anchor);
    date.setDate(anchor.getDate() - offset);
    const day = formatLocalDayKey(date);
    rows.push(byDay.get(day) ?? {
      day,
      useCount: 0,
      averageToolCalls: 0,
      averageRepeatedToolCalls: 0,
      commandFailureRate: null,
    });
  }
  return rows;
}

export function formatLocalDayKey(date: Date): string {
  const year = date.getFullYear();
  const month = `${date.getMonth() + 1}`.padStart(2, '0');
  const day = `${date.getDate()}`.padStart(2, '0');
  return `${year}-${month}-${day}`;
}

function parseLocalDayKey(dayKey: string): Date {
  const [year, month, day] = dayKey.split('-').map((part) => Number.parseInt(part, 10));
  return new Date(year, month - 1, day);
}