-
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: use nova models on visualizer three (#1053)
* feat: use nova models on visualizer three * fix: remove unnecessary file and update client to nova * fix: set long timestamp without time reference
- Loading branch information
Showing
13 changed files
with
226 additions
and
176 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,56 @@ | ||
import { INetwork } from "../../../models/db/INetwork"; | ||
import { IStatistics } from "../../../models/services/IStatistics"; | ||
import { IStatsService } from "../../../models/services/IStatsService"; | ||
|
||
/** | ||
* Class to handle stats service. | ||
*/ | ||
export abstract class BaseStatsService implements IStatsService { | ||
/** | ||
* The network configuration. | ||
*/ | ||
protected readonly _networkConfiguration: INetwork; | ||
|
||
/** | ||
* The statistics. | ||
*/ | ||
protected _statistics: IStatistics[]; | ||
|
||
/** | ||
* Create a new instance of BaseStatsService. | ||
* @param networkConfiguration The network configuration. | ||
*/ | ||
constructor(networkConfiguration: INetwork) { | ||
this._networkConfiguration = networkConfiguration; | ||
this._statistics = [ | ||
{ | ||
itemsPerSecond: 0, | ||
confirmedItemsPerSecond: 0, | ||
confirmationRate: 0, | ||
}, | ||
]; | ||
|
||
setInterval(async () => this.updateStatistics(), 2000); | ||
} | ||
|
||
/** | ||
* Get the current stats. | ||
* @returns The statistics for the network. | ||
*/ | ||
public getStats(): IStatistics { | ||
return this._statistics.at(-1); | ||
} | ||
|
||
/** | ||
* Get the stats history. | ||
* @returns The historical statistics for the network. | ||
*/ | ||
public getItemsPerSecondHistory(): number[] { | ||
return this._statistics.map((s) => s.itemsPerSecond); | ||
} | ||
|
||
/** | ||
* Gather more statistics. | ||
*/ | ||
protected abstract updateStatistics(): Promise<void>; | ||
} |
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,37 @@ | ||
// eslint-disable-next-line import/no-unresolved | ||
import { Client } from "@iota/sdk-nova"; | ||
import { BaseStatsService } from "./baseStatsService"; | ||
import { ServiceFactory } from "../../../factories/serviceFactory"; | ||
import logger from "../../../logger"; | ||
|
||
/** | ||
* Class to handle stats service. | ||
*/ | ||
export class NovaStatsService extends BaseStatsService { | ||
/** | ||
* Gather general statistics. | ||
*/ | ||
protected async updateStatistics(): Promise<void> { | ||
try { | ||
const client = ServiceFactory.get<Client>(`client-${this._networkConfiguration.network}`); | ||
const response = await client.getInfo(); | ||
|
||
if (response) { | ||
const metrics = response.nodeInfo.metrics; | ||
this._statistics.push({ | ||
itemsPerSecond: Number(metrics.blocksPerSecond), | ||
confirmedItemsPerSecond: Number(metrics.confirmedBlocksPerSecond), | ||
confirmationRate: Number(metrics.confirmationRate), | ||
}); | ||
|
||
logger.debug(`[NovaStatsService] Updating network statistics for ${this._networkConfiguration.network}`); | ||
|
||
if (this._statistics.length > 30) { | ||
this._statistics = this._statistics.slice(-30); | ||
} | ||
} | ||
} catch (err) { | ||
logger.debug(`[NovaStatsService] Update statistics failed: ${err}`); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import Viva from "vivagraphjs"; | ||
import { IFeedBlockData } from "../../models/api/stardust/feed/IFeedBlockData"; | ||
import { IFeedBlockData as IFeedBlockDataStardust } from "../../models/api/stardust/feed/IFeedBlockData"; | ||
import { IFeedBlockData as IFeedBlockDataNova } from "../../models/api/nova/feed/IFeedBlockData"; | ||
import { INodeData } from "../../models/graph/stardust/INodeData"; | ||
|
||
export type TSelectNode = (node?: Viva.Graph.INode<INodeData, unknown>) => void; | ||
|
||
export type TSelectFeedItem = IFeedBlockData | null; | ||
export type TSelectFeedItem = IFeedBlockDataStardust | null; | ||
export type TSelectFeedItemNova = IFeedBlockDataNova | 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
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 |
---|---|---|
@@ -1,8 +1,5 @@ | ||
import { IFeedBlockData } from "../../models/api/stardust/feed/IFeedBlockData"; | ||
import { IFeedBlockMetadata } from "../../models/api/stardust/feed/IFeedBlockMetadata"; | ||
import { IFeedBlockData } from "../../models/api/nova/feed/IFeedBlockData"; | ||
|
||
export type TFeedBlockAdd = (newBlock: IFeedBlockData) => void; | ||
|
||
export type TFeedBlockMetadataUpdate = (metadataUpdate: { [id: string]: IFeedBlockMetadata }) => void; | ||
|
||
export type TangleMeshType = THREE.Mesh<THREE.PlaneGeometry, THREE.MeshBasicMaterial, THREE.Object3DEventMap>; |
Oops, something went wrong.