Browse Source

report-generator: print event stats

Joystream Stats 3 years ago
parent
commit
403318a894

+ 28 - 0
community-contributions/report-generator/src/lib/index.ts

@@ -1,3 +1,4 @@
+import { CacheEvent } from "../types";
 import { Mint, MintId } from "@joystream/types/mint";
 import { Moment } from "@polkadot/types/interfaces";
 
@@ -11,3 +12,30 @@ export const momentToString = (moment: Moment) =>
 
 export const getTotalMinted = (mint: Mint) =>
   Number(mint.getField("total_minted").toString());
+
+export const eventStats = (blockEventsCache: Map<number, CacheEvent[]>) => {
+  let sections: {
+    [key: string]: { [key: string]: [{ key: number; data: any }] };
+  } = {};
+  for (let [key, blockEvents] of blockEventsCache) {
+    blockEvents.map(({ section, method, data }) => {
+      if (!sections[section]) sections[section] = {};
+      if (sections[section][method])
+        sections[section][method].push({ key, data });
+      else sections[section][method] = [{ key, data }];
+      if (section === "system" && method === "ExtrinsicSuccess") return;
+      if (section === "imOnline" && method === "HeartbeatReceived") return;
+      if (section === "imOnline" && method === "AllGood") return;
+      if (section === "utility" && method === "BatchCompleted") return;
+      if (section === "grandpa" && method === "NewAuthorities") return;
+      if (section === "session" && method === "NewSession") return;
+      //console.log(section, method, data);
+    });
+  }
+  console.log(`Events:`);
+  Object.keys(sections).map((section: string) =>
+    Object.keys(sections[section]).map((method: string) =>
+      console.log(` ${section}.${method}: ${sections[section][method].length}`)
+    )
+  );
+};

+ 2 - 1
contributions/tech/report-generator/src/StatisticsCollector.ts

@@ -53,7 +53,7 @@ import { ProposalDetails, ProposalOf } from "@joystream/types/augment/types";
 import { SpendingParams } from "@joystream/types/proposals";
 import * as constants from "constants";
 
-import { getPercent, getTotalMinted, momentToString } from "./lib";
+import { eventStats, getPercent, getTotalMinted, momentToString } from "./lib";
 import {
   getBlock,
   getBlockHash,
@@ -169,6 +169,7 @@ export class StatisticsCollector {
     });
 
     await this.buildBlocksEventCache(startBlock, endBlock);
+    eventStats(this.blocksEventsCache);
     await this.fillTokenGenerationInfo(
       startBlock,
       endBlock,