Skip to content
This repository has been archived by the owner on Mar 15, 2021. It is now read-only.

Commit

Permalink
Phase 5
Browse files Browse the repository at this point in the history
See PR #240
  • Loading branch information
RiccardoM committed Jul 8, 2020
1 parent 811b03e commit eeed58d
Show file tree
Hide file tree
Showing 19 changed files with 480 additions and 44 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Docs
on: [pull_request]

jobs:

Build-Docs:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2
with:
persist-credentials: false

- name: Build 🔧
run: |
npm install
npm ci
npm run build-scripts
npm run gather-data -- --csv-file-path=output.csv --scoreboard-file-path=scoreboard/scoreboard.md
npm run upload-data -- --csv-file-path=output.csv
npm run docs:build
echo 'primer.desmos.network' > .vuepress/dist/CNAME
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:

Build-and-Deploy:
Build-Docs:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
Expand All @@ -24,6 +24,10 @@ jobs:
npm run docs:build
echo 'primer.desmos.network' > .vuepress/dist/CNAME
Deploy-Docs:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@releases/v3
with:
Expand Down
22 changes: 15 additions & 7 deletions .scripts/file-writers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export class FileWriter {
phase3ValidatorsTotal: usersData.map((d) => d.phase3ValidatorReward).sumValues(),
phase4Total: usersData.map((d) => d.phase4Tokens).sumValues(),
phase4ValidatorsTotal: usersData.map((d) => d.phase4ValidatorReward).sumValues(),
phase5Total: usersData.map((d) => d.phase5Tokens).sumValues(),
phase5ValidatorsTotal: usersData.map((d) => d.phase5ValidatorReward).sumValues(),
globalTokens: usersData.map((d) => d.totalTokens).sumValues(),
};

Expand All @@ -25,10 +27,11 @@ export class FileWriter {
* @return {string}
*/
this.toCsvRow = function (userData) {
return vsprintf("%s,%s,%s,%s,%s,%s,%s,%s\n", [
return vsprintf("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n", [
userData.user, userData.phase1Tokens, userData.phase2Tokens,
userData.phase3Tokens, userData.phase3ValidatorReward,
userData.phase4Tokens, userData.phase4ValidatorReward,
userData.phase5Tokens, userData.phase5ValidatorReward,
userData.totalTokens,
]);
}
Expand All @@ -39,10 +42,11 @@ export class FileWriter {
* @return {string}
*/
this.toMdRow = function (userData) {
return vsprintf(`| %s | %s | %s | %s | %s | %s | %s | %s |\n`, [
return vsprintf(`| %s | %s | %s | %s | %s | %s | %s | %s | %s | %s |\n`, [
userData.user, userData.phase1Tokens, userData.phase2Tokens,
userData.phase3Tokens, userData.phase3ValidatorReward,
userData.phase4Tokens, userData.phase4ValidatorReward,
userData.phase5Tokens, userData.phase5ValidatorReward,
userData.totalTokens,
]);
}
Expand Down Expand Up @@ -77,10 +81,11 @@ export class FileWriter {
}

// Header
const header = vsprintf("%s,%s,%s,%s,%s,%s,%s,%s\n", [
const header = vsprintf("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n", [
"User", "Phase 1", "Phase 2",
"Phase 3", "Phase 3 VP",
"Phase 4", "Phase 4 VP",
"Phase 5", "Phase 5 VP",
"Total",
]);
fs.writeFileSync(csvPath, header);
Expand All @@ -91,10 +96,11 @@ export class FileWriter {
});

// Footer
const footer = vsprintf("%s,%s,%s,%s,%s,%s,%s,%s\n", [
const footer = vsprintf("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n", [
"TOTAL", this.tokensData.phase1Total, this.tokensData.phase2Total,
this.tokensData.phase3Total, this.tokensData.phase3ValidatorsTotal,
this.tokensData.phase4Total, this.tokensData.phase4ValidatorsTotal,
this.tokensData.phase5Total, this.tokensData.phase5ValidatorsTotal,
this.tokensData.globalTokens,
]);
fs.appendFileSync(csvPath, footer);
Expand All @@ -111,24 +117,26 @@ export class FileWriter {
}

// Header
let table = vsprintf(`| %s | %s | %s | %s | %s | %s | %s | %s |\n`, [
let table = vsprintf(`| %s | %s | %s | %s | %s | %s | %s | %s | %s | %s |\n`, [
"User", "Phase 1", "Phase 2",
"Phase 3", "Phase 3 VP",
"Phase 4", "Phase 4 VP",
"Phase 5", "Phase 5 VP",
"Total",
]);
table += "| :--- | :---: | :---: | :---: | :---: | :---: | :---: | :---: |\n"
table += "| :--- | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |\n"

// Rows
this.usersData.forEach((data) => {
table += this.toMdRow(data);
});

// Footer
table += vsprintf(`| %s | %s | %s | %s | %s | %s | %s | %s |`, [
table += vsprintf(`| %s | %s | %s | %s | %s | %s | %s | %s | %s | %s |`, [
"**Total**", this.tokensData.phase1Total, this.tokensData.phase2Total,
this.tokensData.phase3Total, this.tokensData.phase3ValidatorsTotal,
this.tokensData.phase4Total, this.tokensData.phase4ValidatorsTotal,
this.tokensData.phase5Total, this.tokensData.phase5ValidatorsTotal,
this.tokensData.globalTokens,
]);

Expand Down
6 changes: 4 additions & 2 deletions .scripts/gather-data.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {Phase4} from "./phases/phases";
import {Phase1, Phase2, Phase3, Phase4, Phase5} from "./phases/phases.js";
import {UserData} from "./types/user-data.js";
import {Phase1, Phase2, Phase3} from "./phases/phases.js";
import {FileWriter} from "./file-writers"

require("@babel/core");
Expand All @@ -15,13 +14,15 @@ async function readData() {
const phase2Data = await Phase2.getData();
const phase3Data = await Phase3.getData();
const phase4Data = await Phase4.getData();
const phase5Data = await Phase5.getData();

// --- Users ---
const users = [
...phase1Data.getUsers(),
...phase2Data.getUsers(),
...phase3Data.getUsers(),
...phase4Data.getUsers(),
...phase5Data.getUsers(),
];

return users.unique().map(function (key) {
Expand All @@ -31,6 +32,7 @@ async function readData() {
phase2Data,
phase3Data,
phase4Data,
phase5Data,
);
});
}
Expand Down
4 changes: 2 additions & 2 deletions .scripts/phases/phase-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const csv = require('jquery-csv');
const PHASE_3_SUBMISSIONS = path.join(__dirname, `../../phase-3/submissions`);

/**
* Allows to easily get the data from the Phase 2 of the Primer program.
* Allows to easily get the data from the Phase 3 of the Primer program.
*/
export class Phase3 {

Expand Down Expand Up @@ -68,7 +68,7 @@ export class Phase3 {

/**
* Gathers all the data.
* @returns {Promise<Phase3Data>} containing all the Phase 2 data.
* @returns {Promise<Phase3Data>} containing all the Phase 3 data.
*/
static async getData() {
return new Phase3Data(
Expand Down
4 changes: 2 additions & 2 deletions .scripts/phases/phase-4.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const csv = require('jquery-csv');
const PHASE_4_SUBMISSIONS = path.join(__dirname, `../../phase-4/submissions`);

/**
* Allows to easily get the data from the Phase 2 of the Primer program.
* Allows to easily get the data from the Phase 4 of the Primer program.
*/
export class Phase4 {

Expand Down Expand Up @@ -66,7 +66,7 @@ export class Phase4 {

/**
* Gathers all the data.
* @returns {Promise<Phase4Data>} containing all the Phase 2 data.
* @returns {Promise<Phase4Data>} containing all the Phase 4 data.
*/
static async getData() {
return new Phase4Data(
Expand Down
142 changes: 142 additions & 0 deletions .scripts/phases/phase-5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import {Utils} from "./common";

const path = require('path');
const csv = require('jquery-csv');
const PHASE_5_SUBMISSIONS = path.join(__dirname, `../../phase-5/submissions`);

/**
* Allows to easily get the data from the Phase 5 of the Primer program.
*/
export class Phase5 {

/**
* Gets all the hashtag posts created.
* @returns {Promise<Map<String, String>>} a map containing all the created posts.
* The keys represent the names of the user, while the values represent the hashes of the post creation
* transactions.
*/
static async _getHashtags() {
return Utils.removeEmptyValue(await Utils.getFilesContents(`${PHASE_5_SUBMISSIONS}/hashtags`));
}

/**
* Gets all the profiles.
* @returns {Promise<Map<String, String>>} a map containing all the created or edited profiles.
* The keys represent the names of the user, while the values represent the hashes of
* the profile creation/edit transactions.
*/
static async _getProfiles() {
return Utils.removeEmptyValue(await Utils.getFilesContents(`${PHASE_5_SUBMISSIONS}/profiles`));
}

/**
* Gets all the posts in which a user is tagged.
* @returns {Promise<Map<String, String>>} a map containing all the created posts.
* The keys represent the names of the user, while the values represent the hashes of the post creation
* transactions.
*/
static async _getTags() {
return Utils.removeEmptyValue(await Utils.getFilesContents(`${PHASE_5_SUBMISSIONS}/tags`));
}

/**
* Gets all the created reports.
* @returns {Promise<Map<String, String>>} a map containing all the created reports.
* The keys represent the names of the user, while the values represent the hashes of the report creation
* transactions.
*/
static async _getReports() {
return Utils.removeEmptyValue(await Utils.getFilesContents(`${PHASE_5_SUBMISSIONS}/reports`));
}

/**
* Gets all the updated validators
* @returns {Promise<Map<String, String>>} a map containing all the updated validators.
* The keys represent the names of the user, while the values represent the operator address of the associated
* validator.
*/
static async _getValidators() {
return Utils.removeEmptyValue(await Utils.getFilesContents(`${PHASE_5_SUBMISSIONS}/updates`));
}

/**
* Gets all the number of precommits that all the validators have signed.
* @return {Promise<Map<String, int>>} Map containing the number of precommits that the validators have signed.
* The key is going to be the address of the validator, and the value is going to be the number of precommits.
*/
static async _getPrecommits() {
const fileContents = await Utils.getFilesContents(`${PHASE_5_SUBMISSIONS}/precommits`);
if (fileContents.size === 0) {
return new Map();
}

const morpheus4000Precommits = fileContents.get('precommits-morpheus-5000.csv');
const objects = csv.toObjects(morpheus4000Precommits.join("\n"));

const map = new Map();
for (const object of objects) {
const existingPrecommitsCount = map.get(object.operatorAddress) ?? 0;
const currentPrecommitsCount = parseInt(object.precommitCount.replace(",", ""));
map.set(object.operatorAddress, existingPrecommitsCount + currentPrecommitsCount);
}

return map;
}

/**
* Gathers all the data.
* @returns {Promise<Phase5Data>} containing all the Phase 5 data.
*/
static async getData() {
return new Phase5Data(
await this._getHashtags(),
await this._getProfiles(),
await this._getReports(),
await this._getTags(),
await this._getValidators(),
await this._getPrecommits(),
)
}
}

/**
* @property {Map<String, String>} hashtags
* @property {Map<String, String>} profiles
* @property {Map<String, String>} reports
* @property {Map<String, String>} tags
* @property {Map<String, String>} validators
* @property {Map<String, int>} precommits
*/
class Phase5Data {
constructor(hashtags, profiles, reports, tags, validators, precommits) {
this.hashtags = hashtags;
console.log(`Hashtags created: ${this.hashtags.size}`);

this.profiles = profiles;
console.log(`Profiles created/edited: ${this.profiles.size}`);

this.reports = reports;
console.log(`Reports created: ${this.reports.size}`);

this.tags = tags;
console.log(`Tags created: ${this.tags.size}`);

this.validators = validators;
console.log(`Updated validators: ${this.validators.size}`);

this.precommits = precommits;
}

/**
* @returns {Array<String>}
*/
getUsers() {
return [
...this.hashtags.keys(),
...this.profiles.keys(),
...this.reports.keys(),
...this.tags.keys(),
...this.validators.keys(),
];
}
}
3 changes: 2 additions & 1 deletion .scripts/phases/phases.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import {Phase1} from "./phase-1"
import {Phase2} from "./phase-2";
import {Phase3} from "./phase-3";
import {Phase4} from "./phase-4";
import {Phase5} from "./phase-5";

export {Phase1, Phase2, Phase3, Phase4}
export {Phase1, Phase2, Phase3, Phase4, Phase5}
Loading

0 comments on commit eeed58d

Please sign in to comment.