Browse Source

Add council info

Ricardo Maltez 4 years ago
parent
commit
bb099db3b3

+ 1 - 1
council/report-generator/report-template.md

@@ -28,7 +28,7 @@ This is a report which explains the current state of the Joystream network in nu
 * Council session #: {councilRound}
 * Number of council members: {councilMembers}
 * Total number of proposals: {newProposals}
-* Total number of Approved proposals:
+* Total number of Approved proposals: {newApprovedProposals}
 
 * ### 3.1 Elections
 | Property                    | Start Block  |

+ 1 - 0
council/report-generator/src/StatisticsData.ts

@@ -55,6 +55,7 @@ export class StatisticsData {
     perNewCategories: number = 0;
 
     newProposals: number = 0;
+    newApprovedProposals: number = 0;
 
     newChannels: number = 0;
     totalChannels: number = 0;

+ 33 - 9
council/report-generator/src/statistics.ts

@@ -23,6 +23,7 @@ import {PostId, ThreadId} from "@joystream/types/common";
 import {CategoryId} from "@joystream/types/forum";
 import {Event} from "@polkadot/types/interfaces/system/types";
 import number from "@polkadot/util/is/number";
+import toNumber from "@polkadot/util/hex/toNumber";
 
 const fsSync = require('fs');
 const fs = fsSync.promises;
@@ -58,6 +59,7 @@ export class StatisticsCollector {
         await this.buildBlocksEventCache(startBlock, endBlock);
         await this.fillBasicInfo(startHash, endHash);
         await this.fillMintsInfo(startHash, endHash);
+        await this.fillCouncilInfo(startHash, endHash);
         await this.fillCouncilElectionInfo(startBlock, endBlock);
         await this.fillForumInfo(startHash, endHash);
         this.api.disconnect();
@@ -148,9 +150,7 @@ export class StatisticsCollector {
         // // }
         //
         //
-        // let startNrProposals = await this.api.query.proposalsEngine.proposalCount.at(startHash) as unknown as u32;
-        // let endNrProposals = await this.api.query.proposalsEngine.proposalCount.at(endHash) as unknown as u32;
-        // statistics.newProposals = endNrProposals.toNumber() - startNrProposals.toNumber();
+
         //
         // for (let i = startNrProposals.toNumber(); i < endNrProposals.toNumber(); ++i) {
         //     let proposalNumber = i - 1;
@@ -235,6 +235,7 @@ export class StatisticsCollector {
         let endDate = (await this.api.query.timestamp.now.at(endHash)) as Moment;
         this.statistics.dateStart = new Date(startDate.toNumber()).toLocaleDateString("en-US");
         this.statistics.dateEnd = new Date(endDate.toNumber()).toLocaleDateString("en-US");
+
     }
 
     async fillMintsInfo(startHash: Hash, endHash: Hash) {
@@ -324,22 +325,45 @@ export class StatisticsCollector {
         return mintStatistics;
     }
 
+    async fillCouncilInfo(startHash: Hash, endHash: Hash) {
+        this.statistics.councilRound = (await this.api.query.councilElection.round.at(endHash) as u32).toNumber();
+        this.statistics.councilMembers = (await this.api.query.councilElection.councilSize.at(endHash) as u32).toNumber();
+        let startNrProposals = await this.api.query.proposalsEngine.proposalCount.at(startHash) as u32;
+        let endNrProposals = await this.api.query.proposalsEngine.proposalCount.at(endHash) as u32;
+        this.statistics.newProposals = endNrProposals.toNumber() - startNrProposals.toNumber();
+
+        let approvedProposals = new Set();
+        for (let [key, blockEvents] of this.blocksEventsCache) {
+            for (let event of blockEvents) {
+                if (event.section == "proposalsEngine" && event.method == "ProposalStatusUpdated") {
+                    let statusUpdateData = event.data[1] as any;
+                    let finalizedData = statusUpdateData["Finalized"];
+                    if (finalizedData.proposalStatus["Approved"]){
+                        approvedProposals.add(Number(event.data[0]))
+                    }
+                }
+            }
+        }
+
+        this.statistics.newApprovedProposals = approvedProposals.size;
+    }
+
     async fillCouncilElectionInfo(startBlock: number, endBlock: number) {
 
         for (let i = startBlock; i < endBlock; i++) {
             let events = this.blocksEventsCache.get(i);
-            for (let [key, event] of events.entries()){
-                if (event.section == "councilElection" && event.method == "Applied"){
+            for (let [key, event] of events.entries()) {
+                if (event.section == "councilElection" && event.method == "Applied") {
                     ++this.statistics.electionApplicants;
-                    if (key == 0){
+                    if (key == 0) {
                         continue;
                     }
                     let previousEvent = events[key - 1];
-                    if (previousEvent.section == "balances" && previousEvent.method == "Reserved"){
+                    if (previousEvent.section == "balances" && previousEvent.method == "Reserved") {
                         let stake = Number(previousEvent.data[1]);
                         this.statistics.electionApplicantsStakes += stake;
                     }
-                }else if (event.section == "councilElection" && event.method == "Voted"){
+                } else if (event.section == "councilElection" && event.method == "Voted") {
                     ++this.statistics.electionVotes;
                 }
             }
@@ -481,7 +505,7 @@ export class StatisticsCollector {
                 const blockHash: Hash = await this.api.rpc.chain.getBlockHash(i);
                 let eventRecord = await this.api.query.system.events.at(blockHash) as Vec<EventRecord>;
                 let cacheEvents = new Array<CacheEvent>();
-                for (let event of eventRecord){
+                for (let event of eventRecord) {
                     cacheEvents.push(new CacheEvent(event.event.section, event.event.method, event.event.data));
                 }
                 this.blocksEventsCache.set(i, cacheEvents);