mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-13 05:12:55 -07:00
Implement bot that performs time-series metric analysis and suggests repo management improvements (#25945)
This commit is contained in:
committed by
GitHub
parent
54b7586106
commit
58a57b72ae
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2026 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { readFileSync, existsSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
|
||||
const TIMESERIES_FILE = join(
|
||||
process.cwd(),
|
||||
'tools',
|
||||
'gemini-cli-bot',
|
||||
'history',
|
||||
'metrics-timeseries.csv',
|
||||
);
|
||||
|
||||
/**
|
||||
* Calculates the historical average of a metric over a given number of days.
|
||||
*/
|
||||
export function getHistoricalAverage(
|
||||
metric: string,
|
||||
days: number,
|
||||
): number | null {
|
||||
if (!existsSync(TIMESERIES_FILE)) return null;
|
||||
|
||||
try {
|
||||
const content = readFileSync(TIMESERIES_FILE, 'utf-8');
|
||||
const lines = content.split('\n').slice(1); // skip header
|
||||
const now = new Date();
|
||||
const threshold = new Date(now.getTime() - days * 24 * 60 * 60 * 1000);
|
||||
|
||||
const values: number[] = [];
|
||||
for (const line of lines) {
|
||||
if (!line.trim()) continue;
|
||||
const parts = line.split(',');
|
||||
if (parts.length < 3) continue;
|
||||
|
||||
const timestamp = parts[0];
|
||||
const m = parts[1];
|
||||
const value = parts[2];
|
||||
|
||||
if (m === metric) {
|
||||
const date = new Date(timestamp);
|
||||
if (date >= threshold) {
|
||||
const numValue = parseFloat(value);
|
||||
if (!isNaN(numValue)) {
|
||||
values.push(numValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (values.length === 0) return null;
|
||||
const sum = values.reduce((a, b) => a + b, 0);
|
||||
return sum / values.length;
|
||||
} catch (error) {
|
||||
console.error(`Error reading historical average for ${metric}:`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user