codebuddy-stats 1.2.10 → 1.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +10 -5
- package/dist/lib/data-loader.js +2 -1
- package/dist/lib/utils.js +10 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
5
5
|
import blessed from 'blessed';
|
|
6
6
|
import { loadUsageData } from './lib/data-loader.js';
|
|
7
7
|
import { resolveProjectName } from './lib/workspace-resolver.js';
|
|
8
|
-
import { formatCost, formatNumber, formatPercent, formatTokens, truncate } from './lib/utils.js';
|
|
8
|
+
import { compareByCostThenTokens, formatCost, formatNumber, formatPercent, formatTokens, truncate } from './lib/utils.js';
|
|
9
9
|
// 读取 package.json 获取版本号
|
|
10
10
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
11
11
|
const pkgPath = path.resolve(__dirname, '../package.json');
|
|
@@ -259,7 +259,7 @@ function renderOverview(box, data, width, height, note) {
|
|
|
259
259
|
// 渲染 By Model 视图
|
|
260
260
|
function renderByModel(box, data, scrollOffset = 0, width, note, pageSize) {
|
|
261
261
|
const { modelTotals, grandTotal } = data;
|
|
262
|
-
const sorted = Object.entries(modelTotals).sort(
|
|
262
|
+
const sorted = Object.entries(modelTotals).sort(compareByCostThenTokens);
|
|
263
263
|
// 根据宽度计算列宽
|
|
264
264
|
const availableWidth = width - 6; // padding
|
|
265
265
|
const fixedCols = 12 + 12 + 12 + 10; // Cost + Requests + Tokens + Avg/Req
|
|
@@ -447,8 +447,13 @@ function renderDailyDetail(box, data, date, scrollOffset = 0, width, pageSize) {
|
|
|
447
447
|
totalTokens += tokens;
|
|
448
448
|
totalRequests += requests;
|
|
449
449
|
}
|
|
450
|
-
// 按 cost 降序排序 models
|
|
451
|
-
modelList.sort((a, b) =>
|
|
450
|
+
// 按 cost 降序排序 models,cost 相同时按 tokens 降序
|
|
451
|
+
modelList.sort((a, b) => {
|
|
452
|
+
const costDiff = b.cost - a.cost;
|
|
453
|
+
if (Math.abs(costDiff) > 0.001)
|
|
454
|
+
return costDiff;
|
|
455
|
+
return b.tokens - a.tokens;
|
|
456
|
+
});
|
|
452
457
|
projectDetails.push({
|
|
453
458
|
name: projectName,
|
|
454
459
|
shortName,
|
|
@@ -544,7 +549,7 @@ function printTextReport(data) {
|
|
|
544
549
|
}
|
|
545
550
|
console.log('\n' + '-'.repeat(50));
|
|
546
551
|
console.log('By Model:');
|
|
547
|
-
for (const [model, stats] of Object.entries(modelTotals).sort(
|
|
552
|
+
for (const [model, stats] of Object.entries(modelTotals).sort(compareByCostThenTokens)) {
|
|
548
553
|
console.log(` ${model}: ${formatCost(stats.cost)} (${formatNumber(stats.requests)} req)`); // eslint-disable-line no-console
|
|
549
554
|
}
|
|
550
555
|
console.log('\n' + '-'.repeat(50));
|
package/dist/lib/data-loader.js
CHANGED
|
@@ -4,6 +4,7 @@ import path from 'node:path';
|
|
|
4
4
|
import { createInterface } from 'node:readline';
|
|
5
5
|
import { getIdeDataDir, getProjectsDir, getSettingsPath } from './paths.js';
|
|
6
6
|
import { DEFAULT_MODEL_ID, getPricingForModel, tokensToCost } from './pricing.js';
|
|
7
|
+
import { compareByCostThenTokens } from './utils.js';
|
|
7
8
|
import { loadWorkspaceMappings } from './workspace-resolver.js';
|
|
8
9
|
export const BASE_DIR = getProjectsDir();
|
|
9
10
|
async function loadModelFromSettings() {
|
|
@@ -127,7 +128,7 @@ function finalizeAnalysis(defaultModelId, dailyData, modelTotals, projectTotals,
|
|
|
127
128
|
}
|
|
128
129
|
}
|
|
129
130
|
}
|
|
130
|
-
const topModelEntry = Object.entries(modelTotals).sort(
|
|
131
|
+
const topModelEntry = Object.entries(modelTotals).sort(compareByCostThenTokens)[0];
|
|
131
132
|
const topProjectEntry = Object.entries(projectTotals).sort((a, b) => b[1].cost - a[1].cost)[0];
|
|
132
133
|
const cacheHitRate = grandTotal.cacheHitTokens + grandTotal.cacheMissTokens > 0
|
|
133
134
|
? grandTotal.cacheHitTokens / (grandTotal.cacheHitTokens + grandTotal.cacheMissTokens)
|
package/dist/lib/utils.js
CHANGED
|
@@ -55,3 +55,13 @@ export function padLeft(str, len) {
|
|
|
55
55
|
export function padRight(str, len) {
|
|
56
56
|
return str.padEnd(len);
|
|
57
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* 按 cost 和 tokens 排序的比较函数
|
|
60
|
+
* 优先按 cost 降序,cost 相同时按 tokens 降序
|
|
61
|
+
*/
|
|
62
|
+
export function compareByCostThenTokens(a, b) {
|
|
63
|
+
const costDiff = b[1].cost - a[1].cost;
|
|
64
|
+
if (Math.abs(costDiff) > 0.001)
|
|
65
|
+
return costDiff;
|
|
66
|
+
return b[1].tokens - a[1].tokens;
|
|
67
|
+
}
|