-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Add daily block statistics (#1265)
* feat: Refactor influx classes for stardust/nova (they now share functionaliy in super class InfluxClient). Add daily blocks statistics for nova (api). * feat: Add statitics page for Nova. Add daily blocks chart. * feat: Remove noPayload row from Daily Block query
- Loading branch information
Showing
24 changed files
with
772 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { IBlocksDailyInflux } from "./IInfluxTimedEntries"; | ||
import { DayKey } from "../types"; | ||
|
||
/** | ||
* The cache for influx graphs (daily). | ||
*/ | ||
export interface IInfluxDailyCache { | ||
blocksDaily: Map<DayKey, IBlocksDailyInflux>; | ||
} | ||
|
||
/** | ||
* The helper to initialize empty maps | ||
* @returns The initial cache object | ||
*/ | ||
export const initializeEmptyDailyCache = () => ({ | ||
blocksDaily: new Map(), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ITimedEntry } from "../types"; | ||
|
||
export type IBlocksDailyInflux = ITimedEntry & { | ||
transaction: number | null; | ||
taggedData: number | null; | ||
validation: number | null; | ||
candidacy: number | null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 1 addition & 5 deletions
6
api/src/models/influx/IInfluxTimedEntries.ts → ...ls/influx/stardust/IInfluxTimedEntries.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { INanoDate } from "influx"; | ||
|
||
export interface ITimedEntry { | ||
time: INanoDate; | ||
} | ||
|
||
/** | ||
* The key is a date in string format "DD-MM-YYYY" | ||
*/ | ||
export type DayKey = string; | ||
|
||
/** | ||
* The format used for moment.format(...) | ||
*/ | ||
export const DAY_KEY_FORMAT = "DD-MM-YYYY"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { ServiceFactory } from "../../../../../factories/serviceFactory"; | ||
import { INetworkBoundGetRequest } from "../../../../../models/api/INetworkBoundGetRequest"; | ||
import { IConfiguration } from "../../../../../models/configuration/IConfiguration"; | ||
import { NOVA } from "../../../../../models/db/protocolVersion"; | ||
import { IBlocksDailyInflux } from "../../../../../models/influx/nova/IInfluxTimedEntries"; | ||
import { NetworkService } from "../../../../../services/networkService"; | ||
import { InfluxServiceNova } from "../../../../../services/nova/influx/influxServiceNova"; | ||
import { ValidationHelper } from "../../../../../utils/validationHelper"; | ||
|
||
/** | ||
* The response with the current cached analytic data. | ||
*/ | ||
export interface IDailyAnalyticsResponse { | ||
error?: string; | ||
blocksDaily?: IBlocksDailyInflux[]; | ||
} | ||
|
||
/** | ||
* Get influx cached analytic stats for the requested network. | ||
* @param _ The configuration. | ||
* @param request The request. | ||
* @returns The response. | ||
*/ | ||
export async function get(_: IConfiguration, request: INetworkBoundGetRequest): Promise<IDailyAnalyticsResponse> { | ||
const networkService = ServiceFactory.get<NetworkService>("network"); | ||
const networks = networkService.networkNames(); | ||
const networkConfig = networkService.get(request.network); | ||
ValidationHelper.oneOf(request.network, networks, "network"); | ||
|
||
if (networkConfig.protocolVersion !== NOVA) { | ||
return {}; | ||
} | ||
|
||
const influxService = ServiceFactory.get<InfluxServiceNova>(`influxdb-${request.network}`); | ||
|
||
return influxService | ||
? { | ||
blocksDaily: influxService.blocksDaily, | ||
} | ||
: { | ||
error: "Influx service not found for this network.", | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.