openvibers/openvibe.network Commits

Internal coin stats: rolling seven-day windows with the previous period

OP OpenVibers committed 16 Sept 2026 · 84d4326aca · 1 file, +16 −0

OpenVibe.Live's stat board shows a trend on every figure now; the coin totals are the ones that
live here, so they need the same shape as the rest: this seven days and the seven before it, for
earned, spent and active holders.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01CMxJm1dB8rdsaMSgNjVa82

Changes

ddiff --git a/server/internal/routes.js b/server/internal/routes.js
iindex cf29e78a..4c27e4d6 100644
---- a/server/internal/routes.js
++++ b/server/internal/routes.js
@@@ -190,6 +190,22 @@ router.get('/coins/stats', (req, res) => {
circulating: one('SELECT COALESCE(SUM(balance), 0) AS n FROM wallets'),
holders: one('SELECT COUNT(*) AS n FROM wallets WHERE balance > 0'),
transactions: one('SELECT COUNT(*) AS n FROM coin_transactions'),
++ // Rolling windows so the display can say whether the economy is speeding up. Same
++ // shape the Live stats use: this seven days, and the seven before it.
++ recent: {
++ earned: {
++ w: one("SELECT COALESCE(SUM(delta), 0) AS n FROM coin_transactions WHERE delta > 0 AND created_at >= datetime('now','-7 days')"),
++ pw: one("SELECT COALESCE(SUM(delta), 0) AS n FROM coin_transactions WHERE delta > 0 AND created_at >= datetime('now','-14 days') AND created_at < datetime('now','-7 days')"),
++ },
++ spent: {
++ w: one("SELECT COALESCE(-SUM(delta), 0) AS n FROM coin_transactions WHERE delta < 0 AND created_at >= datetime('now','-7 days')"),
++ pw: one("SELECT COALESCE(-SUM(delta), 0) AS n FROM coin_transactions WHERE delta < 0 AND created_at >= datetime('now','-14 days') AND created_at < datetime('now','-7 days')"),
++ },
++ holders: {
++ w: one("SELECT COUNT(DISTINCT user_id) AS n FROM coin_transactions WHERE created_at >= datetime('now','-7 days')"),
++ pw: one("SELECT COUNT(DISTINCT user_id) AS n FROM coin_transactions WHERE created_at >= datetime('now','-14 days') AND created_at < datetime('now','-7 days')"),
++ },
++ },
};
_coinStats = { at: Date.now(), data };
res.json(data);