Skip to content

Commit

Permalink
Update index.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
tombertrand committed Jan 9, 2024
1 parent 9186441 commit 61edf51
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 69 deletions.
10 changes: 5 additions & 5 deletions server/client/mongo/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const db = require("./");
const {
EXPIRE_1M,
EXPIRE_48H,
EXPIRE_1W,
EXPIRE_2W,
EXPIRE_7D,
EXPIRE_14D,
TOTAL_CONFIRMATIONS_COLLECTION,
TOTAL_VOLUME_COLLECTION,
LARGE_TRANSACTIONS,
Expand All @@ -24,7 +24,7 @@ async function createIndexes() {
if (!indexExists1) {
database
.collection(LARGE_TRANSACTIONS)
.createIndex({ createdAt: 1 }, { expireAfterSeconds: EXPIRE_1W, ...extraOptions });
.createIndex({ createdAt: 1 }, { expireAfterSeconds: EXPIRE_7D, ...extraOptions });
console.log("Index LARGE_TRANSACTIONS createdAt created successfully");
}

Expand All @@ -42,15 +42,15 @@ async function createIndexes() {
if (!indexExists3) {
database
.collection(TOTAL_CONFIRMATIONS_COLLECTION)
.createIndex({ createdAt: 1 }, { expireAfterSeconds: EXPIRE_2W, ...extraOptions });
.createIndex({ createdAt: 1 }, { expireAfterSeconds: EXPIRE_14D, ...extraOptions });
console.log("Index TOTAL_CONFIRMATIONS_COLLECTION createdAt created successfully");
}

const indexExists4 = await database.collection(TOTAL_VOLUME_COLLECTION).indexExists("createdAt");
if (!indexExists4) {
database
.collection(TOTAL_VOLUME_COLLECTION)
.createIndex({ createdAt: 1 }, { expireAfterSeconds: EXPIRE_48H, ...extraOptions });
.createIndex({ createdAt: 1 }, { expireAfterSeconds: EXPIRE_14D, ...extraOptions });
console.log("Index TOTAL_VOLUME_COLLECTION createdAt created successfully");
}

Expand Down
10 changes: 6 additions & 4 deletions server/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const EXPIRE_1H = 3600;
const EXPIRE_6H = 3600 * 6;
const EXPIRE_24H = EXPIRE_1H * 24;
const EXPIRE_48H = EXPIRE_24H * 2;
const EXPIRE_1W = EXPIRE_24H * 7;
const EXPIRE_2W = EXPIRE_24H * 14;
const EXPIRE_7D = EXPIRE_24H * 7;
const EXPIRE_14D = EXPIRE_24H * 14;
const EXPIRE_1Y = EXPIRE_24H * 365;
const EXPIRE_5Y = EXPIRE_24H * 365 * 5;
const TOTAL_CONFIRMATIONS_COLLECTION = "TOTAL_CONFIRMATIONS";
Expand All @@ -18,6 +18,7 @@ const TOTAL_VOLUME_COLLECTION = "TOTAL_VOLUME";
const TOTAL_VOLUME_24H = "TOTAL_VOLUME_24H";
const TOTAL_VOLUME_7D = "TOTAL_VOLUME_7D";
const TOTAL_VOLUME_48H = "TOTAL_VOLUME_48H";
const TOTAL_VOLUME_14D = "TOTAL_VOLUME_14D";
const MARKET_CAP_RANK_COLLECTION = "MARKET_CAP_RANK";
const MARKET_CAP_STATS_COLLECTION = "MARKET_CAP_STATS";
const MARKET_CAP_RANK = "MARKET_CAP_RANK";
Expand Down Expand Up @@ -78,8 +79,8 @@ module.exports = {
EXPIRE_6H,
EXPIRE_24H,
EXPIRE_48H,
EXPIRE_1W,
EXPIRE_2W,
EXPIRE_7D,
EXPIRE_14D,
EXPIRE_1Y,
EXPIRE_5Y,
TOTAL_CONFIRMATIONS_COLLECTION,
Expand All @@ -91,6 +92,7 @@ module.exports = {
TOTAL_VOLUME_24H,
TOTAL_VOLUME_7D,
TOTAL_VOLUME_48H,
TOTAL_VOLUME_14D,
MARKET_CAP_RANK_COLLECTION,
MARKET_CAP_STATS_COLLECTION,
MARKET_CAP_RANK,
Expand Down
123 changes: 97 additions & 26 deletions server/cron/ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const {
EXPIRE_1M,
EXPIRE_24H,
EXPIRE_1W,
EXPIRE_7D,
EXPIRE_14D,
EXPIRE_48H,
TOTAL_CONFIRMATIONS_COLLECTION,
TOTAL_CONFIRMATIONS_24H,
Expand All @@ -16,7 +18,9 @@ const {
TOTAL_CONFIRMATIONS_14D,
TOTAL_VOLUME_COLLECTION,
TOTAL_VOLUME_24H,
TOTAL_VOLUME_7D,
TOTAL_VOLUME_48H,
TOTAL_VOLUME_14D,
CONFIRMATIONS_PER_SECOND,
} = require("../constants");
const { rawToRai } = require("../utils");
Expand All @@ -36,7 +40,7 @@ cron.schedule("*/3 * * * * *", async () => {
{
$match: {
createdAt: {
$lt: new Date(Date.now() - EXPIRE_1M * 1000),
$gte: new Date(Date.now() - EXPIRE_1M * 1000),
},
},
},
Expand Down Expand Up @@ -71,32 +75,32 @@ cron.schedule("*/10 * * * * *", async () => {
{
$match: {
createdAt: {
$lt: new Date(Date.now() - EXPIRE_24H * 1000),
$gte: new Date(Date.now() - EXPIRE_24H * 1000),
},
},
},
{ $group: { _id: null, totalConfirmations: { $sum: "$value" } } },
{ $group: { _id: null, totalConfirmations24h: { $sum: "$value" } } },
])
.toArray()
.then(([{ totalConfirmations = 0 } = {}]) => {
nodeCache.set(TOTAL_CONFIRMATIONS_24H, totalConfirmations);
.then(([{ totalConfirmations24h = 0 } = {}]) => {
nodeCache.set(TOTAL_CONFIRMATIONS_24H, totalConfirmations24h);
});
// conf 7d
database
// conf 7d
database
.collection(TOTAL_CONFIRMATIONS_COLLECTION)
.aggregate([
{
$match: {
createdAt: {
$lt: new Date(Date.now() - EXPIRE_1W * 1000),
$gte: new Date(Date.now() - EXPIRE_1W * 1000),
},
},
},
{ $group: { _id: null, totalConfirmations14d: { $sum: "$value" } } },
{ $group: { _id: null, totalConfirmations7d: { $sum: "$value" } } },
])
.toArray()
.then(([{ totalConfirmations14d = 0 } = {}]) => {
nodeCache.set(TOTAL_CONFIRMATIONS_7D, totalConfirmations14d);
.then(([{ totalConfirmations7d = 0 } = {}]) => {
nodeCache.set(TOTAL_CONFIRMATIONS_7D, totalConfirmations7d);
});

database
Expand All @@ -105,25 +109,25 @@ cron.schedule("*/10 * * * * *", async () => {
{
$match: {
createdAt: {
$lt: new Date(Date.now() - EXPIRE_48H * 1000),
$gte: new Date(Date.now() - EXPIRE_48H * 1000),
},
},
},
{ $group: { _id: null, totalConfirmations: { $sum: "$value" } } },
{ $group: { _id: null, totalConfirmations48h: { $sum: "$value" } } },
])
.toArray()
.then(([{ totalConfirmations = 0 } = {}]) => {
nodeCache.set(TOTAL_CONFIRMATIONS_48H, totalConfirmations);
.then(([{ totalConfirmations48h = 0 } = {}]) => {
nodeCache.set(TOTAL_CONFIRMATIONS_48H, totalConfirmations48h);
});

//conf 1w
database
//conf 1w
database
.collection(TOTAL_CONFIRMATIONS_COLLECTION)
.aggregate([
{
$match: {
createdAt: {
$lt: new Date(Date.now() - EXPIRE_1W * 1000),
$gte: new Date(Date.now() - EXPIRE_14D * 1000),
},
},
},
Expand All @@ -140,15 +144,32 @@ cron.schedule("*/10 * * * * *", async () => {
{
$match: {
createdAt: {
$lt: new Date(Date.now() - EXPIRE_24H * 1000),
$gte: new Date(Date.now() - EXPIRE_24H * 1000),
},
},
},
{ $group: { _id: null, totalVolume24h: { $sum: "$value" } } },
])
.toArray()
.then(([{ totalVolume24h = 0 } = {}]) => {
nodeCache.set(TOTAL_VOLUME_24H, rawToRai(totalVolume24h));
});

database
.collection(TOTAL_VOLUME_COLLECTION)
.aggregate([
{
$match: {
createdAt: {
$gte: new Date(Date.now() - EXPIRE_7D * 1000),
},
},
},
{ $group: { _id: null, totalVolume: { $sum: "$value" } } },
{ $group: { _id: null, totalVolume7d: { $sum: "$value" } } },
])
.toArray()
.then(([{ totalVolume = 0 } = {}]) => {
nodeCache.set(TOTAL_VOLUME_24H, rawToRai(totalVolume));
.then(([{ totalVolume7d = 0 } = {}]) => {
nodeCache.set(TOTAL_VOLUME_7D, rawToRai(totalVolume7d));
});

database
Expand All @@ -157,15 +178,65 @@ cron.schedule("*/10 * * * * *", async () => {
{
$match: {
createdAt: {
$lt: new Date(Date.now() - EXPIRE_48H * 1000),
$gte: new Date(Date.now() - TOTAL_VOLUME_14D * 1000),
},
},
},
{ $group: { _id: null, totalVolume14d: { $sum: "$value" } } },
])
.toArray()
.then(([{ totalVolume14d = 0 } = {}]) => {
nodeCache.set(TOTAL_VOLUME_14D, rawToRai(totalVolume14d));
});

database
.collection(TOTAL_VOLUME_COLLECTION)
.aggregate([
{
$match: {
createdAt: {
$gte: new Date(Date.now() - EXPIRE_48H * 1000),
},
},
},
{ $group: { _id: null, totalVolume48h: { $sum: "$value" } } },
])
.toArray()
.then(([{ totalVolume48h = 0 } = {}]) => {
nodeCache.set(TOTAL_VOLUME_48H, rawToRai(totalVolume48h));
});

database
.collection(TOTAL_VOLUME_COLLECTION)
.aggregate([
{
$match: {
createdAt: {
$gte: new Date(Date.now() - EXPIRE_7D * 1000),
},
},
},
{ $group: { _id: null, totalVolume7d: { $sum: "$value" } } },
])
.toArray()
.then(([{ totalVolume7d = 0 } = {}]) => {
nodeCache.set(TOTAL_VOLUME_7D, rawToRai(totalVolume7d));
});
database
.collection(TOTAL_VOLUME_COLLECTION)
.aggregate([
{
$match: {
createdAt: {
$gte: new Date(Date.now() - EXPIRE_14D * 1000),
},
},
},
{ $group: { _id: null, totalVolume: { $sum: "$value" } } },
{ $group: { _id: null, totalVolume14d: { $sum: "$value" } } },
])
.toArray()
.then(([{ totalVolume = 0 } = {}]) => {
nodeCache.set(TOTAL_VOLUME_48H, rawToRai(totalVolume));
.then(([{ totalVolume14d = 0 } = {}]) => {
nodeCache.set(TOTAL_VOLUME_14D, rawToRai(totalVolume14d));
});
} catch (err) {
Sentry.captureException(err, {
Expand Down
2 changes: 1 addition & 1 deletion server/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const BigNumber = require("bignumber.js");

const rawToRai = raw => {
const value = new BigNumber(raw.toString());
return value.shiftedBy(30 * -1).toNumber();
return value.shiftedBy(30 * -1).toNumber() || 0;
};

const raiToRaw = rai => {
Expand Down
1 change: 1 addition & 0 deletions server/ws/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ ws.onmessage = msg => {

if (topic === "confirmation") {
accumulatedConfirmations = accumulatedConfirmations + 1;


// 10,000 NANO
if (subtype === "send" && amount.length >= 35) {
Expand Down
3 changes: 3 additions & 0 deletions src/api/contexts/MarketStatistics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const TOTAL_CONFIRMATIONS_7D = "TOTAL_CONFIRMATIONS_7D";
export const TOTAL_CONFIRMATIONS_14D = "TOTAL_CONFIRMATIONS_14D";
export const TOTAL_VOLUME_24H = "TOTAL_VOLUME_24H";
export const TOTAL_VOLUME_7D = "TOTAL_VOLUME_7D";
export const TOTAL_VOLUME_14D = "TOTAL_VOLUME_14D";
export const TOTAL_CONFIRMATIONS_48H = "TOTAL_CONFIRMATIONS_48H";
export const TOTAL_VOLUME_48H = "TOTAL_VOLUME_48H";
export const BITCOIN_TOTAL_TRANSACTION_FEES_24H = "BITCOIN_TOTAL_TRANSACTION_FEES_24H";
Expand All @@ -26,6 +27,7 @@ export interface Response {
[TOTAL_CONFIRMATIONS_48H]: number;
[TOTAL_CONFIRMATIONS_14D]: number;
[TOTAL_VOLUME_48H]: number;
[TOTAL_VOLUME_14D]: number;
[BITCOIN_TOTAL_TRANSACTION_FEES_24H]: number;
[BITCOIN_TOTAL_TRANSACTION_FEES_7D]: number;
[BITCOIN_TOTAL_TRANSACTION_FEES_14D]: number;
Expand Down Expand Up @@ -70,6 +72,7 @@ export const MarketStatisticsContext = React.createContext<Context>({
[TOTAL_VOLUME_7D]: 0,
[TOTAL_CONFIRMATIONS_48H]: 0,
[TOTAL_VOLUME_48H]: 0,
[TOTAL_VOLUME_14D]: 0,
[BITCOIN_TOTAL_TRANSACTION_FEES_24H]: 0,
[BITCOIN_TOTAL_TRANSACTION_FEES_7D]: 0,
[BITCOIN_TOTAL_TRANSACTION_FEES_14D]: 0,
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@
"senderFilter": "Filter blocks to include only or exclude all send transactions from a specific address. To filter multiple addresses, separate them with a comma.",
"receiverFilter": "Filter blocks to include only or exclude all send transactions from a specific address. To filter multiple addresses, separate them with a comma.",
"filterTransactions": "Only accounts with equal or less than 5,000 confirmed transactions can be filtered",
"averageTps": "On {{date}}, {{block_count}} {{block_type}} blocks were broadcasted at a rate of {{bps}} BPS (blocks per second) to measure the network efficiency. The network reached a P90 of {{cps_p90}} CPS (confirmations per seconds) across the nodes. For more details visit https://nanotps.net/."
"averageTps": "On {{date}}, {{block_count}} {{block_type}} blocks were broadcasted at a rate of {{bps}} BPS (blocks per second) to measure the network efficiency. The network reached a P90 of {{cps_p90}} CPS (confirmations per seconds) across the nodes. For more details visit https://nanotps.net/.",
"last24Hours": "Displays a comparison of data trends and metrics from the last 24 hours against those from the preceding 48 hours, providing insights into recent changes and patterns.",
"last7days": "Shows a comparative analysis of data and trends over the past 7 days against the previous 14 days, highlighting shifts and patterns over a broader time frame for a comprehensive view."
},
"search": {
"searchBy": "Search by Address / Block / Known Account",
Expand Down
Loading

0 comments on commit 61edf51

Please sign in to comment.