2020-01-07 20:23:53 +00:00
|
|
|
import { name } from 'country-emoji';
|
|
|
|
|
import people from '../data.js';
|
|
|
|
|
|
|
|
|
|
function merge(prop) {
|
|
|
|
|
return function(acc, obj) {
|
|
|
|
|
return [...obj[prop], ...acc];
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function countInstances(acc, tag) {
|
|
|
|
|
acc[tag] = acc[tag] ? acc[tag] + 1 : 1;
|
|
|
|
|
return acc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function countries() {
|
|
|
|
|
const data = people
|
|
|
|
|
.map(person => ({
|
|
|
|
|
name: name(person.country),
|
|
|
|
|
emoji: person.country,
|
|
|
|
|
}))
|
|
|
|
|
.reduce((acc, country) => {
|
|
|
|
|
if (acc[country.name]) {
|
|
|
|
|
// exists, update
|
2020-01-17 21:33:12 +00:00
|
|
|
acc[country.name].count += 1;
|
2020-01-07 20:23:53 +00:00
|
|
|
} else {
|
|
|
|
|
acc[country.name] = {
|
|
|
|
|
...country,
|
|
|
|
|
count: 1,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return acc;
|
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
|
|
const sorted = Object.entries(data)
|
|
|
|
|
.map(([, country]) => country)
|
|
|
|
|
.sort((a, b) => b.count - a.count);
|
|
|
|
|
|
|
|
|
|
return sorted;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function tags() {
|
|
|
|
|
const allTags = people.reduce(merge('tags'), []);
|
|
|
|
|
const counts = allTags.reduce(countInstances, {});
|
|
|
|
|
// sort and filter for any tags that only have 1
|
|
|
|
|
const tags = Object.entries(counts)
|
|
|
|
|
.sort(([, countA], [, countB]) => countB - countA)
|
2020-01-09 17:12:28 +00:00
|
|
|
// Only show the tag if this topic has 3 or more people in it
|
|
|
|
|
.filter(([, count]) => count >= 3)
|
2020-01-07 20:23:53 +00:00
|
|
|
.map(([name, count]) => ({ name, count }));
|
|
|
|
|
|
|
|
|
|
return [{ name: 'all', count: people.length }, ...tags];
|
|
|
|
|
}
|
2020-01-08 11:44:52 +00:00
|
|
|
|
2020-01-08 15:53:02 +00:00
|
|
|
export function devices() {
|
|
|
|
|
const all = [
|
|
|
|
|
...people.map(person => person.computer),
|
|
|
|
|
...people.map(person => person.phone),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return Object.entries(all.reduce(countInstances, {}))
|
|
|
|
|
.map(([device, count]) => ({ name: device, count }))
|
2020-01-08 11:44:52 +00:00
|
|
|
.sort((a, b) => b.count - a.count);
|
|
|
|
|
}
|