Skip to content

Commit

Permalink
[w3capi] compile list of eligible voters (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
elf-pavlik authored Nov 16, 2023
1 parent 6a6820c commit c8fe9fb
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 27 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ node_modules
users.json
orgs.json
participants.html
affiliations.md
affiliation-default-voters.md
affiliation-designated-voters.md
eligible-voters.txt
11 changes: 8 additions & 3 deletions node-w3capi/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import w3capi from "node-w3capi"

const W3C_INVITED_EXPERTS_ID = 36747;

export function alphaSort(a, b) {
return a.localeCompare(b, "en", { ignorePunctuation: true })
}

export async function fetchData(groupId) {
const groupUsers = await w3capi.group(groupId).users().fetch();
const users = [];
Expand Down Expand Up @@ -46,10 +50,11 @@ export async function fetchData(groupId) {

const orgs = Object.values(orgsMap)

// sort by org name
orgs.sort((a, b) => a.name.localeCompare(b.name, "en", { ignorePunctuation: true }))
// sort by name
users.sort((a, b) => alphaSort(a.name, b.name))
orgs.sort((a, b) => alphaSort(a.name, b.name))

// sort users by w3c id
// sort org users by w3c id
orgs.forEach(organization => {
organization.orgUsers.sort((a, b) => a.id - b.id)
})
Expand Down
47 changes: 38 additions & 9 deletions node-w3capi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

import fs from "fs";
import ora from "ora";
import { fetchData } from "./api.js";
import tablemark from 'tablemark'
import { fetchData, alphaSort} from "./api.js";
import { renderHTML } from "./html.js";
import { renderMarkdown } from "./markdown.js";

const SOLID_CG_ID = 110151;

Expand All @@ -34,7 +34,11 @@ const filenames = {
participants: "participants.html"
},
md: {
affiliations: "affiliations.md"
default: "affiliation-default-voters.md",
designated: "affiliation-designated-voters.md"
},
txt: {
voters: "eligible-voters.txt"
}
}

Expand Down Expand Up @@ -63,7 +67,6 @@ if (localDataExists(filenames.json)) {
spinner.succeed("💾 Wrote local data")
}


spinner.start("🤖 Generating HTML")
const html = renderHTML(data.users, data.orgs, {
name: "W3C Solid Community Group",
Expand All @@ -72,12 +75,38 @@ const html = renderHTML(data.users, data.orgs, {
fs.writeFileSync(filenames.html.participants, html);
spinner.succeed("Generated HTML")

const nonSingularOrgs = data.orgs.filter(org => org.orgUsers.length > 1)

spinner.start("🤖 Generating markdown")
const markdown = renderMarkdown(data.users, data.orgs, {
name: "W3C Solid Community Group",
description: "test",
});
fs.writeFileSync(filenames.md.affiliations, markdown);
const markdown = tablemark(nonSingularOrgs
.map(o => ({
name: o.name,
members: o.orgUsers.length,
default: o.orgUsers[0].name,
designated: ''
}))
)
fs.writeFileSync(filenames.md.default, markdown);
spinner.succeed("Generated markdown")

if (localDataExists(filenames.md)) {
spinner.start("🤖 Generating eligible voters list")
const representativesTable = fs.readFileSync(filenames.md.designated, 'utf-8')
.split('\n').slice(2).filter(Boolean)

const orgRepresentatives = representativesTable.map(row => {
const fallback = row.split('|')[3].trim()
const designated = row.split('|')[4].trim()
return designated || fallback
})

const simpleVoters = data.users
.filter(user => !nonSingularOrgs.some(org => org.orgUsers.find(u => u.id === user.id)))
.map(user => user.name)
const eligibleVoters = [...simpleVoters, ...orgRepresentatives]
eligibleVoters.sort(alphaSort)
fs.writeFileSync(filenames.txt.voters, eligibleVoters.join('\n') + '\n');
spinner.succeed("Generated eligible voters list")
}

spinner.stop()
14 changes: 0 additions & 14 deletions node-w3capi/markdown.js

This file was deleted.

0 comments on commit c8fe9fb

Please sign in to comment.