@lls-a1/dsh-balance-float 1.1.55 → 1.1.56
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/client.js +64 -45
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -109,6 +109,7 @@ window.__ModuleLoader__.load({
|
|
|
109
109
|
'price.miss': '未命中',
|
|
110
110
|
'price.out': '输出',
|
|
111
111
|
history: '用量趋势',
|
|
112
|
+
'history.window.today': '今天',
|
|
112
113
|
'history.window.7': '近7天',
|
|
113
114
|
'history.window.30': '近30天',
|
|
114
115
|
'history.window.month': '本月',
|
|
@@ -203,6 +204,7 @@ window.__ModuleLoader__.load({
|
|
|
203
204
|
'price.miss': 'Miss',
|
|
204
205
|
'price.out': 'Out',
|
|
205
206
|
history: 'Usage trend',
|
|
207
|
+
'history.window.today': 'Today',
|
|
206
208
|
'history.window.7': '7d',
|
|
207
209
|
'history.window.30': '30d',
|
|
208
210
|
'history.window.month': 'Month',
|
|
@@ -614,10 +616,10 @@ window.__ModuleLoader__.load({
|
|
|
614
616
|
const [bubbleUp, setBubbleUp] = useState(false);
|
|
615
617
|
// «?» next to the current billing period: reveals the peak/valley windows.
|
|
616
618
|
const [hintOpen, setHintOpen] = useState(false);
|
|
617
|
-
// A bar of the chart opens that day's detail view; the chart shows
|
|
618
|
-
// 30 days
|
|
619
|
+
// A bar of the chart opens that day's detail view; the chart shows today,
|
|
620
|
+
// 7 or 30 days, or the current month depending on the chosen window.
|
|
619
621
|
const [selectedDay, setSelectedDay] = useState(null);
|
|
620
|
-
const [chartWindow, setChartWindow] = useState('
|
|
622
|
+
const [chartWindow, setChartWindow] = useState('today');
|
|
621
623
|
// Token buckets are collapsed until asked for.
|
|
622
624
|
const [tokensOpen, setTokensOpen] = useState(false);
|
|
623
625
|
// Auto check: null | {phase, latest, current, hasUpdate}
|
|
@@ -1062,17 +1064,32 @@ window.__ModuleLoader__.load({
|
|
|
1062
1064
|
const stale = typeof snapshot?.today === 'string' && snapshot.today !== new Date(now + 8 * 3600 * 1000).toISOString().slice(0, 10);
|
|
1063
1065
|
const prices = Array.isArray(snapshot?.prices) ? snapshot.prices : [];
|
|
1064
1066
|
const allHistory = Array.isArray(snapshot?.history) ? snapshot.history : [];
|
|
1065
|
-
const
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1067
|
+
const todayWindow = chartWindow === 'today';
|
|
1068
|
+
const history = todayWindow
|
|
1069
|
+
? allHistory.filter((row) => row.day === snapshot?.today)
|
|
1070
|
+
: chartWindow === 'month'
|
|
1071
|
+
? (() => {
|
|
1072
|
+
const prefix = (snapshot?.today ?? '').slice(0, 7);
|
|
1073
|
+
return allHistory.filter((row) => row.day.startsWith(prefix));
|
|
1074
|
+
})()
|
|
1075
|
+
: allHistory.slice(-Number(chartWindow));
|
|
1076
|
+
// "Today" reads the live counters: the history row is written by the
|
|
1077
|
+
// ledger and can lag behind the current turn.
|
|
1078
|
+
const windowTotal = todayWindow
|
|
1079
|
+
? (snapshot?.todayUsed ?? 0)
|
|
1080
|
+
: history.reduce((sum, row) => sum + (row.cost ?? 0), 0);
|
|
1081
|
+
const windowPeakCost = todayWindow
|
|
1082
|
+
? (snapshot?.todayPeakCost ?? 0)
|
|
1083
|
+
: history.reduce((sum, row) => sum + (row.peakCost ?? 0), 0);
|
|
1084
|
+
const windowValleyCost = todayWindow
|
|
1085
|
+
? (snapshot?.todayValleyCost ?? 0)
|
|
1086
|
+
: history.reduce((sum, row) => sum + (row.valleyCost ?? 0), 0);
|
|
1087
|
+
const windowCalls = todayWindow
|
|
1088
|
+
? (snapshot?.todayCalls ?? 0)
|
|
1089
|
+
: history.reduce((sum, row) => sum + (row.calls ?? 0), 0);
|
|
1090
|
+
const windowModels = todayWindow
|
|
1091
|
+
? (Array.isArray(snapshot?.models) ? snapshot.models : [])
|
|
1092
|
+
: (() => {
|
|
1076
1093
|
const table = {};
|
|
1077
1094
|
for (const row of history) {
|
|
1078
1095
|
for (const model of row.models ?? []) {
|
|
@@ -1409,7 +1426,7 @@ window.__ModuleLoader__.load({
|
|
|
1409
1426
|
h(
|
|
1410
1427
|
'span',
|
|
1411
1428
|
{ className: 'dbf-windows' },
|
|
1412
|
-
['7', '30', 'month'].map((key) =>
|
|
1429
|
+
['today', '7', '30', 'month'].map((key) =>
|
|
1413
1430
|
h(
|
|
1414
1431
|
'button',
|
|
1415
1432
|
{
|
|
@@ -1430,7 +1447,7 @@ window.__ModuleLoader__.load({
|
|
|
1430
1447
|
h(
|
|
1431
1448
|
'span',
|
|
1432
1449
|
{ className: 'dbf-trend-calls' },
|
|
1433
|
-
t('history.calls', { calls:
|
|
1450
|
+
t('history.calls', { calls: windowCalls }),
|
|
1434
1451
|
),
|
|
1435
1452
|
),
|
|
1436
1453
|
h(
|
|
@@ -1458,36 +1475,38 @@ window.__ModuleLoader__.load({
|
|
|
1458
1475
|
}),
|
|
1459
1476
|
)
|
|
1460
1477
|
: null,
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
'
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1478
|
+
todayWindow
|
|
1479
|
+
? null
|
|
1480
|
+
: h(
|
|
1481
|
+
'div',
|
|
1482
|
+
{ className: 'dbf-bars' },
|
|
1483
|
+
history.map((row) => {
|
|
1484
|
+
const value = typeof row.cost === 'number' ? row.cost : 0;
|
|
1485
|
+
const windowMax = Math.max(...history.map((entry) => entry.cost ?? 0), 0);
|
|
1486
|
+
const ratio = windowMax > 0 ? Math.max(2, Math.round((value / windowMax) * 38)) : 2;
|
|
1487
|
+
const isToday = typeof snapshot?.today === 'string' && row.day === snapshot.today;
|
|
1488
|
+
return h(
|
|
1489
|
+
'div',
|
|
1490
|
+
{
|
|
1491
|
+
key: row.day,
|
|
1492
|
+
className: 'dbf-bar' + (isToday ? ' is-today' : ''),
|
|
1493
|
+
role: 'button',
|
|
1494
|
+
tabIndex: 0,
|
|
1495
|
+
title: row.day + ' ¥' + money(value),
|
|
1496
|
+
onClick: () => setSelectedDay(row.day),
|
|
1497
|
+
onKeyDown: (event) => {
|
|
1498
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
1499
|
+
event.preventDefault();
|
|
1500
|
+
setSelectedDay(row.day);
|
|
1501
|
+
}
|
|
1502
|
+
},
|
|
1483
1503
|
},
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
)
|
|
1488
|
-
|
|
1489
|
-
)
|
|
1490
|
-
);
|
|
1504
|
+
h('div', { className: 'dbf-bar-fill', style: { height: ratio + 'px' } }),
|
|
1505
|
+
h('div', { className: 'dbf-bar-day' }, row.day.slice(8).replace(/^0/, '')),
|
|
1506
|
+
);
|
|
1507
|
+
}),
|
|
1508
|
+
),
|
|
1509
|
+
);
|
|
1491
1510
|
|
|
1492
1511
|
const selected = selectedDay === null ? null : history.find((row) => row.day === selectedDay) ?? null;
|
|
1493
1512
|
const dayBlock =
|