3
0

index.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  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 ? 100 : 0;
  6. return Number(((value2 * 100) / value1 - 100).toFixed(2));
  7. };
  8. export const momentToString = (timestamp: number) =>
  9. new Date(timestamp).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. });
  23. }
  24. console.log(`Events:`);
  25. Object.keys(sections).map((section: string) =>
  26. Object.keys(sections[section]).map((method: string) =>
  27. console.log(` ${section}.${method}: ${sections[section][method].length}`)
  28. )
  29. );
  30. };