feat: stats page, and the client becomes Chamber Go
- 全部功能 gains 统计 (Stats): ranges Today/7/30/90 days/all time, a project scope (reusing the shared project sheet, plus "All projects"), session/prompt/token/cost/active-days/streak tiles, a daily activity chart (weekly past 92 days), token composition, efficiency tiles, model ranking by tokens/cost/steps and on-request tool-call stats; data comes from /api/experimental/session/stats and the day buckets use the device's IANA zone (a small platform channel; desktop falls back to UTC) - the model bars draw a full-width track with a left-aligned fill, so a small token share reads as a sliver instead of an empty bar - AI token strings read 词元 (not 令牌) in Chinese - the client's display name is Chamber Go (launcher, iOS, Linux window, About), package unchanged; pairing/login labels and the user-agent follow, so a newly paired device shows "Chamber Go" on the web client's "Connect to this server" list - bump to 0.5.6
This commit is contained in:
1 parent
a70e9290ef
commit
b65498d73e
19 files changed
+1637
-25
No files matched your search
@@ -10,6 +10,7 @@ import 'package:openchamber/l10n/zh.dart';
|
||||
const _notTranslated = <String>{
|
||||
'English',
|
||||
'中文',
|
||||
'Chamber Go',
|
||||
// Product names, separators and glyphs read the same everywhere.
|
||||
'OpenChamber',
|
||||
'OpenCode',
|
||||
|
||||
@@ -58,6 +58,44 @@ void main() {
|
||||
expect(choice!.isChat, isFalse);
|
||||
});
|
||||
|
||||
testWidgets('the stats picker adds All projects and drops the Chat row',
|
||||
(tester) async {
|
||||
final app = AppState();
|
||||
addTearDown(app.dispose);
|
||||
app.projects = const [
|
||||
ProjectInfo(id: 'p1', canonical: '/home/me/project', name: 'My project'),
|
||||
];
|
||||
|
||||
ProjectChoice? choice;
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Builder(
|
||||
builder: (context) => TextButton(
|
||||
onPressed: () async {
|
||||
choice = await showProjectPicker(context,
|
||||
app: app,
|
||||
selected: allProjectsTarget,
|
||||
includeAll: true,
|
||||
includeChat: false);
|
||||
},
|
||||
child: const Text('open'),
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
await tester.tap(find.text('open'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('All projects'), findsOneWidget);
|
||||
expect(find.text('Chat'), findsNothing);
|
||||
expect(find.text('My project'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('All projects'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(choice, isNotNull);
|
||||
expect(choice!.isAll, isTrue);
|
||||
});
|
||||
|
||||
testWidgets('scheduled tasks open the same project sheet', (tester) async {
|
||||
final app = AppState();
|
||||
addTearDown(app.dispose);
|
||||
|
||||
@@ -151,6 +151,8 @@ void main() {
|
||||
expect(find.text('全部功能'), findsOneWidget);
|
||||
expect(find.text('计划任务'), findsOneWidget);
|
||||
expect(find.text('按时间向会话发送提示词'), findsOneWidget);
|
||||
expect(find.text('统计'), findsOneWidget);
|
||||
expect(find.text('提示词、词元、费用与模型活动'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('计划任务'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:openchamber/api/usage_stats.dart';
|
||||
|
||||
void main() {
|
||||
test('a report reads tokens, tools and models', () {
|
||||
final stats = UsageStats.fromJson({
|
||||
'range': {'from': 1000, 'to': 2000},
|
||||
'sessions': 3,
|
||||
'subagents': 5,
|
||||
'prompts': 12,
|
||||
'steps': 240,
|
||||
'tokens': {
|
||||
'input': 100,
|
||||
'output': 40,
|
||||
'reasoning': 10,
|
||||
'cache': {'read': 900, 'write': 50},
|
||||
},
|
||||
'cost': 0.25,
|
||||
'activeDays': 2,
|
||||
'streak': 1,
|
||||
'activity': [
|
||||
{'date': '2026-11-25', 'steps': 40},
|
||||
],
|
||||
'tools': {
|
||||
'mode': 'detail',
|
||||
'totals': {'calls': 9, 'succeeded': 8, 'failed': 1, 'unfinished': 0},
|
||||
'usage': [
|
||||
{
|
||||
'name': 'read',
|
||||
'calls': 4,
|
||||
'succeeded': 4,
|
||||
'failed': 0,
|
||||
'unfinished': 0,
|
||||
'durationP50': 25.5,
|
||||
},
|
||||
],
|
||||
},
|
||||
'models': [
|
||||
{
|
||||
'model': {'providerID': 'p', 'id': 'm', 'variant': 'high'},
|
||||
'steps': 240,
|
||||
'tokens': {
|
||||
'input': 100,
|
||||
'output': 40,
|
||||
'reasoning': 10,
|
||||
'cache': {'read': 900, 'write': 50},
|
||||
},
|
||||
'cost': 0.25,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(stats.isEmpty, isFalse);
|
||||
expect(stats.sessions, 3);
|
||||
expect(stats.tokens.total, 1100);
|
||||
expect(stats.tokens.produced, 50);
|
||||
expect(stats.tools.hasTotals, isTrue);
|
||||
expect(stats.tools.rows.single.durationP50, 25.5);
|
||||
expect(stats.models.single.variant, 'high');
|
||||
expect(stats.models.single.tokens.cacheRead, 900);
|
||||
});
|
||||
|
||||
test('an empty report says so', () {
|
||||
expect(const UsageStats().isEmpty, isTrue);
|
||||
});
|
||||
|
||||
test('ranges start at local midnight', () {
|
||||
final now = DateTime(2026, 11, 26, 15, 30);
|
||||
expect(UsageRange.day.startFrom(now),
|
||||
DateTime(2026, 11, 26).millisecondsSinceEpoch);
|
||||
expect(UsageRange.week.startFrom(now),
|
||||
DateTime(2026, 11, 20).millisecondsSinceEpoch);
|
||||
expect(UsageRange.month.startFrom(now),
|
||||
DateTime(2026, 10, 28).millisecondsSinceEpoch);
|
||||
expect(UsageRange.all.startFrom(now), isNull);
|
||||
});
|
||||
|
||||
test('activity fills quiet days and groups long ranges into weeks', () {
|
||||
final from = DateTime(2026, 11, 20).millisecondsSinceEpoch;
|
||||
final to = DateTime(2026, 11, 26).millisecondsSinceEpoch;
|
||||
final series = buildUsageActivity(UsageStats(
|
||||
from: from,
|
||||
to: to,
|
||||
activity: const [
|
||||
UsageActivityDay('2026-11-21', 4),
|
||||
UsageActivityDay('2026-11-24', 6),
|
||||
],
|
||||
));
|
||||
expect(series.weekly, isFalse);
|
||||
expect(series.bars.length, 6);
|
||||
expect(series.bars.map((bar) => bar.steps), [0, 4, 0, 0, 6, 0]);
|
||||
expect(series.max, 6);
|
||||
|
||||
// More than 92 days become weekly bars.
|
||||
final long = buildUsageActivity(UsageStats(
|
||||
from: DateTime(2026, 1, 1).millisecondsSinceEpoch,
|
||||
to: DateTime(2026, 6, 1).millisecondsSinceEpoch,
|
||||
));
|
||||
expect(long.weekly, isTrue);
|
||||
expect(long.bars.length, lessThanOrEqualTo(92));
|
||||
});
|
||||
|
||||
test('the number and duration helpers read like the web client', () {
|
||||
expect(usageCompactNumber(999), '999');
|
||||
expect(usageCompactNumber(1234), '1.2K');
|
||||
expect(usageCompactNumber(1234567), '1.2M');
|
||||
expect(usageCompactNumber(123.4), '123');
|
||||
expect(usagePercent(0.1234), '12.3%');
|
||||
expect(usageCost(1.5), r'$1.50');
|
||||
expect(usageDuration(48), '48 ms');
|
||||
expect(usageDuration(1500), '1.5 s');
|
||||
expect(usageDuration(65000), '1 min 5 s');
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user