Skip to content

Commit 4b82647

Browse files
committed
fix statistics
1 parent 9a4b012 commit 4b82647

File tree

9 files changed

+83
-112
lines changed

9 files changed

+83
-112
lines changed

server/api/representative.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { nodeCache } = require("../client/cache");
2-
const { REPRESENTATIVE, EXPIRE_1W } = require("../constants");
2+
const { REPRESENTATIVE, EXPIRE_7D } = require("../constants");
33
const { rpc } = require("../rpc");
44
const { Sentry } = require("../sentry");
55

@@ -51,7 +51,7 @@ const setRepresentatives = async ({ metrics, peers }) => {
5151
Sentry.captureException(err);
5252
}
5353

54-
nodeCache.set(REPRESENTATIVE, representatives, EXPIRE_1W);
54+
nodeCache.set(REPRESENTATIVE, representatives, EXPIRE_7D);
5555
};
5656

5757
module.exports = {

server/client/mongo/schema.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const {
44
EXPIRE_1M,
55
EXPIRE_48H,
66
EXPIRE_7D,
7-
EXPIRE_14D,
7+
// EXPIRE_14D,
88
TOTAL_CONFIRMATIONS_COLLECTION,
99
TOTAL_VOLUME_COLLECTION,
1010
LARGE_TRANSACTIONS,
@@ -42,15 +42,15 @@ async function createIndexes() {
4242
if (!indexExists3) {
4343
database
4444
.collection(TOTAL_CONFIRMATIONS_COLLECTION)
45-
.createIndex({ createdAt: 1 }, { expireAfterSeconds: EXPIRE_14D, ...extraOptions });
45+
.createIndex({ createdAt: 1 }, { expireAfterSeconds: EXPIRE_1M, ...extraOptions });
4646
console.log("Index TOTAL_CONFIRMATIONS_COLLECTION createdAt created successfully");
4747
}
4848

4949
const indexExists4 = await database.collection(TOTAL_VOLUME_COLLECTION).indexExists("createdAt");
5050
if (!indexExists4) {
5151
database
5252
.collection(TOTAL_VOLUME_COLLECTION)
53-
.createIndex({ createdAt: 1 }, { expireAfterSeconds: EXPIRE_14D, ...extraOptions });
53+
.createIndex({ createdAt: 1 }, { expireAfterSeconds: EXPIRE_1M, ...extraOptions });
5454
console.log("Index TOTAL_VOLUME_COLLECTION createdAt created successfully");
5555
}
5656

server/constants.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ const EXPIRE_1Y = EXPIRE_24H * 365;
1111
const EXPIRE_5Y = EXPIRE_24H * 365 * 5;
1212
const TOTAL_CONFIRMATIONS_COLLECTION = "TOTAL_CONFIRMATIONS";
1313
const TOTAL_CONFIRMATIONS_24H = "TOTAL_CONFIRMATIONS_24H";
14+
const TOTAL_CONFIRMATIONS_48H = "TOTAL_CONFIRMATIONS_48H";
1415
const TOTAL_CONFIRMATIONS_7D = "TOTAL_CONFIRMATIONS_7D";
1516
const TOTAL_CONFIRMATIONS_14D = "TOTAL_CONFIRMATIONS_14D";
16-
const TOTAL_CONFIRMATIONS_48H = "TOTAL_CONFIRMATIONS_48H";
1717
const TOTAL_VOLUME_COLLECTION = "TOTAL_VOLUME";
1818
const TOTAL_VOLUME_24H = "TOTAL_VOLUME_24H";
1919
const TOTAL_VOLUME_7D = "TOTAL_VOLUME_7D";
@@ -85,9 +85,9 @@ module.exports = {
8585
EXPIRE_5Y,
8686
TOTAL_CONFIRMATIONS_COLLECTION,
8787
TOTAL_CONFIRMATIONS_24H,
88+
TOTAL_CONFIRMATIONS_48H,
8889
TOTAL_CONFIRMATIONS_7D,
8990
TOTAL_CONFIRMATIONS_14D,
90-
TOTAL_CONFIRMATIONS_48H,
9191
TOTAL_VOLUME_COLLECTION,
9292
TOTAL_VOLUME_24H,
9393
TOTAL_VOLUME_7D,

server/cron/distribution.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const { client: redisClient } = require("../client/redis");
1111
const { Sentry } = require("../sentry");
1212
const {
1313
EXPIRE_24H,
14-
EXPIRE_1W,
14+
EXPIRE_7D,
1515
DISTRIBUTION,
1616
DELEGATORS,
1717
DORMANT_FUNDS,
@@ -260,8 +260,8 @@ const doDistributionCron = async () => {
260260

261261
console.log(`Distribution cron finished in ${(new Date() - startTime) / 1000}s`);
262262

263-
nodeCache.set(DISTRIBUTION, distribution, EXPIRE_1W);
264-
nodeCache.set(DORMANT_FUNDS, dormantFunds, EXPIRE_1W);
263+
nodeCache.set(DISTRIBUTION, distribution, EXPIRE_7D);
264+
nodeCache.set(DORMANT_FUNDS, dormantFunds, EXPIRE_7D);
265265
nodeCache.set(KNOWN_EXCHANGES, knownExchanges, EXPIRE_24H);
266266

267267
// @NOTE manual add for now
@@ -324,14 +324,14 @@ const getDistributionData = () => {
324324
distribution = fs.existsSync(DISTRIBUTION_PATH)
325325
? JSON.parse(fs.readFileSync(DISTRIBUTION_PATH, "utf8"))
326326
: [];
327-
nodeCache.set(DISTRIBUTION, distribution, EXPIRE_1W);
327+
nodeCache.set(DISTRIBUTION, distribution, EXPIRE_7D);
328328
}
329329

330330
if (!dormantFunds) {
331331
dormantFunds = fs.existsSync(DORMANT_FUNDS_PATH)
332332
? JSON.parse(fs.readFileSync(DORMANT_FUNDS_PATH, "utf8"))
333333
: {};
334-
nodeCache.set(DORMANT_FUNDS, dormantFunds, EXPIRE_1W);
334+
nodeCache.set(DORMANT_FUNDS, dormantFunds, EXPIRE_7D);
335335
}
336336

337337
if (!knownExchanges) {
@@ -343,7 +343,7 @@ const getDistributionData = () => {
343343

344344
if (!status) {
345345
status = fs.existsSync(STATUS_PATH) ? JSON.parse(fs.readFileSync(STATUS_PATH, "utf8")) : {};
346-
nodeCache.set(STATUS, status, EXPIRE_1W);
346+
nodeCache.set(STATUS, status, EXPIRE_7D);
347347
}
348348

349349
return {

server/cron/ws.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,18 @@ const { Sentry } = require("../sentry");
77
const {
88
EXPIRE_1M,
99
EXPIRE_24H,
10-
EXPIRE_1W,
10+
EXPIRE_48H,
1111
EXPIRE_7D,
1212
EXPIRE_14D,
13-
EXPIRE_48H,
1413
TOTAL_CONFIRMATIONS_COLLECTION,
1514
TOTAL_CONFIRMATIONS_24H,
16-
TOTAL_CONFIRMATIONS_7D,
1715
TOTAL_CONFIRMATIONS_48H,
16+
TOTAL_CONFIRMATIONS_7D,
1817
TOTAL_CONFIRMATIONS_14D,
1918
TOTAL_VOLUME_COLLECTION,
2019
TOTAL_VOLUME_24H,
21-
TOTAL_VOLUME_7D,
2220
TOTAL_VOLUME_48H,
21+
TOTAL_VOLUME_7D,
2322
TOTAL_VOLUME_14D,
2423
CONFIRMATIONS_PER_SECOND,
2524
} = require("../constants");
@@ -85,22 +84,22 @@ cron.schedule("*/10 * * * * *", async () => {
8584
.then(([{ totalConfirmations24h = 0 } = {}]) => {
8685
nodeCache.set(TOTAL_CONFIRMATIONS_24H, totalConfirmations24h);
8786
});
88-
// conf 7d
87+
8988
database
9089
.collection(TOTAL_CONFIRMATIONS_COLLECTION)
9190
.aggregate([
9291
{
9392
$match: {
9493
createdAt: {
95-
$gte: new Date(Date.now() - EXPIRE_1W * 1000),
94+
$gte: new Date(Date.now() - EXPIRE_48H * 1000),
9695
},
9796
},
9897
},
99-
{ $group: { _id: null, totalConfirmations7d: { $sum: "$value" } } },
98+
{ $group: { _id: null, totalConfirmations48h: { $sum: "$value" } } },
10099
])
101100
.toArray()
102-
.then(([{ totalConfirmations7d = 0 } = {}]) => {
103-
nodeCache.set(TOTAL_CONFIRMATIONS_7D, totalConfirmations7d);
101+
.then(([{ totalConfirmations48h = 0 } = {}]) => {
102+
nodeCache.set(TOTAL_CONFIRMATIONS_48H, totalConfirmations48h);
104103
});
105104

106105
database
@@ -109,15 +108,15 @@ cron.schedule("*/10 * * * * *", async () => {
109108
{
110109
$match: {
111110
createdAt: {
112-
$lt: new Date(Date.now() + EXPIRE_48H * 1000),
111+
$gte: new Date(Date.now() - EXPIRE_14D * 1000),
113112
},
114113
},
115114
},
116-
{ $group: { _id: null, totalConfirmations48h: { $sum: "$value" } } },
115+
{ $group: { _id: null, totalConfirmations7d: { $sum: "$value" } } },
117116
])
118117
.toArray()
119-
.then(([{ totalConfirmations48h = 0 } = {}]) => {
120-
nodeCache.set(TOTAL_CONFIRMATIONS_48H, totalConfirmations48h);
118+
.then(([{ totalConfirmations7d = 0 } = {}]) => {
119+
nodeCache.set(TOTAL_CONFIRMATIONS_7D, totalConfirmations7d);
121120
});
122121

123122
//conf 1w
@@ -144,7 +143,7 @@ cron.schedule("*/10 * * * * *", async () => {
144143
{
145144
$match: {
146145
createdAt: {
147-
$lt: new Date(Date.now() + EXPIRE_24H * 1000),
146+
$gte: new Date(Date.now() - EXPIRE_24H * 1000),
148147
},
149148
},
150149
},
@@ -178,7 +177,7 @@ cron.schedule("*/10 * * * * *", async () => {
178177
{
179178
$match: {
180179
createdAt: {
181-
$lt: new Date(Date.now() +TOTAL_VOLUME_14D * 1000),
180+
$lt: new Date(Date.now() + TOTAL_VOLUME_14D * 1000),
182181
},
183182
},
184183
},
@@ -195,7 +194,7 @@ cron.schedule("*/10 * * * * *", async () => {
195194
{
196195
$match: {
197196
createdAt: {
198-
$lt: new Date(Date.now() + EXPIRE_48H * 1000),
197+
$gte: new Date(Date.now() - EXPIRE_48H * 1000),
199198
},
200199
},
201200
},

server/server.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ const path = require("path");
3131
const { nodeCache } = require("./client/cache");
3232
const {
3333
TOTAL_CONFIRMATIONS_24H,
34+
TOTAL_CONFIRMATIONS_48H,
3435
TOTAL_CONFIRMATIONS_7D,
3536
TOTAL_CONFIRMATIONS_14D,
3637
TOTAL_VOLUME_24H,
37-
TOTAL_VOLUME_7D,
38-
TOTAL_CONFIRMATIONS_48H,
3938
TOTAL_VOLUME_48H,
39+
TOTAL_VOLUME_7D,
4040
TOTAL_VOLUME_14D,
4141
CONFIRMATIONS_PER_SECOND,
4242
NANOTICKER_STATS,
@@ -150,12 +150,12 @@ app.get("/api/developer-fund/transactions", async (req, res) => {
150150

151151
app.get("/api/market-statistics", async (req, res) => {
152152
const cachedConfirmations24h = nodeCache.get(TOTAL_CONFIRMATIONS_24H);
153+
const cachedConfirmations48h = nodeCache.get(TOTAL_CONFIRMATIONS_48H);
153154
const cachedConfirmations7d = nodeCache.get(TOTAL_CONFIRMATIONS_7D);
154155
const cachedConfirmations14d = nodeCache.get(TOTAL_CONFIRMATIONS_14D);
155156
const cachedVolume24h = nodeCache.get(TOTAL_VOLUME_24H);
156-
const cachedVolume7d = nodeCache.get(TOTAL_VOLUME_7D);
157-
const cachedConfirmations48h = nodeCache.get(TOTAL_CONFIRMATIONS_48H);
158157
const cachedVolume48h = nodeCache.get(TOTAL_VOLUME_48H);
158+
const cachedVolume7d = nodeCache.get(TOTAL_VOLUME_7D);
159159
const cachedVolume14d = nodeCache.get(TOTAL_VOLUME_14D);
160160
const nanotpsStats = nodeCache.get(NANOTPS_STATS);
161161
const nanoSpeedStats = nodeCache.get(NANOSPEED_STATS);
@@ -171,15 +171,14 @@ app.get("/api/market-statistics", async (req, res) => {
171171

172172
cryptocurrency: req.query.cryptocurrency,
173173
});
174-
175174
res.send({
176175
[TOTAL_CONFIRMATIONS_24H]: cachedConfirmations24h,
176+
[TOTAL_CONFIRMATIONS_48H]: cachedConfirmations48h,
177177
[TOTAL_CONFIRMATIONS_7D]: cachedConfirmations7d,
178178
[TOTAL_CONFIRMATIONS_14D]: cachedConfirmations14d,
179179
[TOTAL_VOLUME_24H]: cachedVolume24h,
180-
[TOTAL_VOLUME_7D]: cachedVolume7d,
181-
[TOTAL_CONFIRMATIONS_48H]: cachedConfirmations48h,
182180
[TOTAL_VOLUME_48H]: cachedVolume48h,
181+
[TOTAL_VOLUME_7D]: cachedVolume7d,
183182
[TOTAL_VOLUME_14D]: cachedVolume14d,
184183
[BITCOIN_TOTAL_TRANSACTION_FEES_24H]: btcTransactionFees24h,
185184
[BITCOIN_TOTAL_TRANSACTION_FEES_7D]: btcTransactionFees7d,

src/api/contexts/MarketStatistics.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ export const TOTAL_CONFIRMATIONS_24H = "TOTAL_CONFIRMATIONS_24H";
88
export const TOTAL_CONFIRMATIONS_7D = "TOTAL_CONFIRMATIONS_7D";
99
export const TOTAL_CONFIRMATIONS_14D = "TOTAL_CONFIRMATIONS_14D";
1010
export const TOTAL_VOLUME_24H = "TOTAL_VOLUME_24H";
11+
export const TOTAL_CONFIRMATIONS_48H = "TOTAL_CONFIRMATIONS_48H";
1112
export const TOTAL_VOLUME_7D = "TOTAL_VOLUME_7D";
1213
export const TOTAL_VOLUME_14D = "TOTAL_VOLUME_14D";
13-
export const TOTAL_CONFIRMATIONS_48H = "TOTAL_CONFIRMATIONS_48H";
1414
export const TOTAL_VOLUME_48H = "TOTAL_VOLUME_48H";
1515
export const BITCOIN_TOTAL_TRANSACTION_FEES_24H = "BITCOIN_TOTAL_TRANSACTION_FEES_24H";
1616
export const BITCOIN_TOTAL_TRANSACTION_FEES_7D = "BITCOIN_TOTAL_TRANSACTION_FEES_7D";
@@ -21,12 +21,12 @@ export const NANOSPEED_STATS = "NANOSPEED_STATS";
2121

2222
export interface Response {
2323
[TOTAL_CONFIRMATIONS_24H]: number;
24-
[TOTAL_CONFIRMATIONS_7D]: number;
25-
[TOTAL_VOLUME_24H]: number;
26-
[TOTAL_VOLUME_7D]: number;
2724
[TOTAL_CONFIRMATIONS_48H]: number;
25+
[TOTAL_CONFIRMATIONS_7D]: number;
2826
[TOTAL_CONFIRMATIONS_14D]: number;
27+
[TOTAL_VOLUME_24H]: number;
2928
[TOTAL_VOLUME_48H]: number;
29+
[TOTAL_VOLUME_7D]: number;
3030
[TOTAL_VOLUME_14D]: number;
3131
[BITCOIN_TOTAL_TRANSACTION_FEES_24H]: number;
3232
[BITCOIN_TOTAL_TRANSACTION_FEES_7D]: number;
@@ -66,12 +66,12 @@ let pollMarketStatisticsTimeout: number | undefined;
6666
export const MarketStatisticsContext = React.createContext<Context>({
6767
marketStatistics: {
6868
[TOTAL_CONFIRMATIONS_24H]: 0,
69+
[TOTAL_CONFIRMATIONS_48H]: 0,
6970
[TOTAL_CONFIRMATIONS_7D]: 0,
7071
[TOTAL_CONFIRMATIONS_14D]: 0,
7172
[TOTAL_VOLUME_24H]: 0,
72-
[TOTAL_VOLUME_7D]: 0,
73-
[TOTAL_CONFIRMATIONS_48H]: 0,
7473
[TOTAL_VOLUME_48H]: 0,
74+
[TOTAL_VOLUME_7D]: 0,
7575
[TOTAL_VOLUME_14D]: 0,
7676
[BITCOIN_TOTAL_TRANSACTION_FEES_24H]: 0,
7777
[BITCOIN_TOTAL_TRANSACTION_FEES_7D]: 0,

src/components/StatisticsChange/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ interface StatisticsChangeProps {
1414
}
1515

1616
const StatisticsChange: React.FC<StatisticsChangeProps> = ({
17-
value,
17+
value: rawValue,
1818
isPercent,
1919
isNumber,
2020
suffix,
2121
}) => {
22+
let value = rawValue;
2223
const { theme } = React.useContext(PreferencesContext);
2324
const color = (
2425
value === 0

0 commit comments

Comments
 (0)