index.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { CacheEvent } from "../types";
  2. import { Mint, MintId } from "@joystream/types/mint";
  3. import { Moment } from "@polkadot/types/interfaces";
  4. export const getPercent = (value1: number, value2: number): number => {
  5. if (value1 == 0) return value2 > 0 ? Infinity : 0;
  6. return Number(((value2 * 100) / value1 - 100).toFixed(2));
  7. };
  8. export const momentToString = (moment: Moment) =>
  9. new Date(moment.toNumber()).toLocaleDateString("en-US");
  10. export const getTotalMinted = (mint: Mint) =>
  11. Number(mint.getField("total_minted").toString());
  12. export const eventStats = (blockEventsCache: Map<number, CacheEvent[]>) => {
  13. let sections: {
  14. [key: string]: { [key: string]: [{ key: number; data: any }] };
  15. } = {};
  16. for (let [key, blockEvents] of blockEventsCache) {
  17. blockEvents.map(({ section, method, data }) => {
  18. if (!sections[section]) sections[section] = {};
  19. if (sections[section][method])
  20. sections[section][method].push({ key, data });
  21. else sections[section][method] = [{ key, data }];
  22. if (section === "system" && method === "ExtrinsicSuccess") return;
  23. if (section === "imOnline" && method === "HeartbeatReceived") return;
  24. if (section === "imOnline" && method === "AllGood") return;
  25. if (section === "utility" && method === "BatchCompleted") return;
  26. if (section === "grandpa" && method === "NewAuthorities") return;
  27. if (section === "session" && method === "NewSession") return;
  28. //console.log(section, method, data);
  29. });
  30. }
  31. console.log(`Events:`);
  32. Object.keys(sections).map((section: string) =>
  33. Object.keys(sections[section]).map((method: string) =>
  34. console.log(` ${section}.${method}: ${sections[section][method].length}`)
  35. )
  36. );
  37. };