tokmon 0.3.3 → 0.4.0
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/cli.js +27 -11
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -227,6 +227,19 @@ function isoWeekLabel(ts) {
|
|
|
227
227
|
function monthLabel(ts) {
|
|
228
228
|
return new Date(ts).toISOString().slice(0, 7);
|
|
229
229
|
}
|
|
230
|
+
function findBlockStart(entries, now) {
|
|
231
|
+
const recent = entries.filter((e) => e.ts <= now).sort((a, b) => a.ts - b.ts);
|
|
232
|
+
if (recent.length === 0) return 0;
|
|
233
|
+
const GAP = 30 * 6e4;
|
|
234
|
+
let blockStart = recent[0].ts;
|
|
235
|
+
for (let i = 1; i < recent.length; i++) {
|
|
236
|
+
if (recent[i].ts - recent[i - 1].ts > GAP) {
|
|
237
|
+
blockStart = recent[i].ts;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (now - blockStart > 5 * 36e5) return 0;
|
|
241
|
+
return blockStart;
|
|
242
|
+
}
|
|
230
243
|
async function fetchDashboard() {
|
|
231
244
|
const now = Date.now();
|
|
232
245
|
const d = /* @__PURE__ */ new Date();
|
|
@@ -235,17 +248,20 @@ async function fetchDashboard() {
|
|
|
235
248
|
const weekDay = d.getDay();
|
|
236
249
|
const weekStart = new Date(d.getFullYear(), d.getMonth(), d.getDate() - (weekDay === 0 ? 6 : weekDay - 1)).getTime();
|
|
237
250
|
const entries = await loadEntries(monthStart);
|
|
238
|
-
const fiveHoursAgo = now - 5 * 36e5;
|
|
239
|
-
const blockEntries = entries.filter((e) => e.ts >= fiveHoursAgo);
|
|
240
251
|
let block = null;
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
const
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
252
|
+
const blockStart = findBlockStart(entries, now);
|
|
253
|
+
if (blockStart > 0) {
|
|
254
|
+
const blockEnd = blockStart + 5 * 36e5;
|
|
255
|
+
const blockEntries = entries.filter((e) => e.ts >= blockStart && e.ts < blockEnd);
|
|
256
|
+
if (blockEntries.length > 0) {
|
|
257
|
+
const spent = blockEntries.reduce((s, e) => s + e.cost, 0);
|
|
258
|
+
const elapsedMs = now - blockStart;
|
|
259
|
+
const elapsedHrs = elapsedMs / 36e5;
|
|
260
|
+
const burnRate = elapsedHrs > 0 ? spent / elapsedHrs : 0;
|
|
261
|
+
const remainMs = Math.max(0, blockEnd - now);
|
|
262
|
+
const percent = Math.min(100, elapsedMs / (5 * 36e5) * 100);
|
|
263
|
+
block = { spent, projected: burnRate * 5, burnRate, percent, remaining: minutes(remainMs / 6e4) };
|
|
264
|
+
}
|
|
249
265
|
}
|
|
250
266
|
return {
|
|
251
267
|
today: sum(entries.filter((e) => e.ts >= todayStart)),
|
|
@@ -444,7 +460,7 @@ function App({ interval: cliInterval }) {
|
|
|
444
460
|
if (error) return /* @__PURE__ */ jsx(Box, { padding: 1, children: /* @__PURE__ */ jsx(Text, { color: "red", children: error }) });
|
|
445
461
|
if (!dashboard) return /* @__PURE__ */ jsx(Box, { padding: 1, children: /* @__PURE__ */ jsx(Text, { dimColor: true, children: "Loading..." }) });
|
|
446
462
|
const tableData = table ? [table.daily, table.weekly, table.monthly][view] : [];
|
|
447
|
-
return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", paddingX: 2, paddingY: 1, children: [
|
|
463
|
+
return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", paddingX: 2, paddingY: 1, minHeight: rows, children: [
|
|
448
464
|
/* @__PURE__ */ jsxs(Box, { justifyContent: "space-between", children: [
|
|
449
465
|
/* @__PURE__ */ jsxs(Box, { children: [
|
|
450
466
|
/* @__PURE__ */ jsxs(Text, { bold: true, color: "greenBright", children: [
|