[pl][blog][names] pesel unisex

This commit is contained in:
Avris 2021-06-18 17:33:25 +02:00
parent e519897b63
commit e8089ddefe
8 changed files with 254 additions and 1 deletions

View File

@ -158,3 +158,10 @@ form[disabled] {
position: fixed !important; position: fixed !important;
bottom: 3px !important; bottom: 3px !important;
} }
@include media-breakpoint-up('lg') {
.table-wide {
margin-left: calc(-50vw + 50% + 3rem);
margin-right: calc(-50vw + 50% + 3rem);
}
}

View File

@ -18,6 +18,7 @@
<script> <script>
import Vue from 'vue'; import Vue from 'vue';
import dark from "../plugins/dark"; import dark from "../plugins/dark";
import sorter from "avris-sorter";
export default { export default {
mixins: [dark], mixins: [dark],
@ -44,10 +45,15 @@
}); });
}; };
this.setMode(this.detectDark()); this.setMode(this.detectDark());
if (process.client) {
sorter();
}
} }
} }
</script> </script>
<style lang="scss"> <style lang="scss">
@import "assets/style"; @import "assets/style";
@import "~avris-sorter/Sorter.min.css";
</style> </style>

File diff suppressed because one or more lines are too long

View File

@ -122,6 +122,7 @@ links:
mediaRoute: 'media' mediaRoute: 'media'
blog: blog:
imiona-unisex-pesel: 'Imiona „unisex” w rejestrze PESEL'
polskie-media-o-demi-lovato: 'Polskie media o coming oucie Demi Lovato' polskie-media-o-demi-lovato: 'Polskie media o coming oucie Demi Lovato'
rodzaj-żeńskoosobowy: 'Rodzaj żeńskoosobowy' rodzaj-żeńskoosobowy: 'Rodzaj żeńskoosobowy'
manifest: 'Manifest Niebinarnej Polszczyzny' manifest: 'Manifest Niebinarnej Polszczyzny'

View File

@ -13,6 +13,7 @@
"@nuxtjs/axios": "^5.12.0", "@nuxtjs/axios": "^5.12.0",
"@nuxtjs/pwa": "^3.0.0-beta.20", "@nuxtjs/pwa": "^3.0.0-beta.20",
"@nuxtjs/redirect-module": "^0.3.1", "@nuxtjs/redirect-module": "^0.3.1",
"avris-sorter": "^0.0.2",
"aws-sdk": "^2.799.0", "aws-sdk": "^2.799.0",
"body-parser": "^1.19.0", "body-parser": "^1.19.0",
"canvas": "^2.6.1", "canvas": "^2.6.1",

View File

@ -24,10 +24,11 @@
export default { export default {
async asyncData({route}) { async asyncData({route}) {
try { try {
const content = (await import(`../data/blog/${route.params.slug}.md`)).default const content = '<div>' + (await import(`../data/blog/${route.params.slug}.md`)).default
.replace(/<table>/g, '<div class="table-responsive"><table class="table table-striped small">') .replace(/<table>/g, '<div class="table-responsive"><table class="table table-striped small">')
.replace(/<\/table>/g, '</table></div>') .replace(/<\/table>/g, '</table></div>')
.replace(/<a href="http/g, '<a target="_blank" rel="noopener" href="http') .replace(/<a href="http/g, '<a target="_blank" rel="noopener" href="http')
+ '</div>'
; ;
const titleMatch = content.match('<h1[^>]*>([^<]+)</h1>'); const titleMatch = content.match('<h1[^>]*>([^<]+)</h1>');
const title = titleMatch ? titleMatch[1] : null; const title = titleMatch ? titleMatch[1] : null;

156
server/pesel.js Normal file
View File

@ -0,0 +1,156 @@
const Papa = require('papaparse');
const fs = require('fs');
const loadTsv = name => Papa.parse(fs.readFileSync(name).toString(), {
dynamicTyping: true,
header: true,
skipEmptyLines: true,
delimiter: '\t',
}).data;
const _each = (obj, callable) => {
const ret = [];
for (let key in obj) {
if (obj.hasOwnProperty(key)) {
ret.push(callable(obj[key], key));
}
}
return ret;
};
const peselK1 = loadTsv('./data/names/K1.tsv');
const peselK2 = loadTsv('./data/names/K2.tsv');
const peselM1 = loadTsv('./data/names/M1.tsv');
const peselM2 = loadTsv('./data/names/M2.tsv');
const pesel = {}
for (let [names, sex, ordinal] of [
[peselK1, 'K', 1],
[peselK2, 'K', 2],
[peselM1, 'M', 1],
[peselM2, 'M', 2],
]) {
for (let {name, count} of names) {
if (pesel[name] === undefined) {
pesel[name] = {K: [0, 0], M: [0, 0]};
}
pesel[name][sex][ordinal - 1] = count;
}
}
const calculateBalance = (k, m) => {
const balance = k / (k + m);
return balance > 0.5
? 1 - balance
: balance;
}
const allUnisex = {};
const popularUnisex = {};
const allFirstUnisex = {};
const popularFirstUnisex = {};
_each(pesel, (counts, name) => {
counts['balanceBoth'] = calculateBalance(counts.K[0] + counts.K[1], counts.M[0] + counts.M[1]);
counts['balanceFirst'] = calculateBalance(counts.K[0], counts.M[0]);
counts['balanceBothPop'] = counts['balanceBoth'] * (counts.K[0] + counts.K[1] + counts.M[0] + counts.M[1]);
counts['balanceFirstPop'] = counts['balanceFirst'] * (counts.K[0] + counts.M[0]);
});
let maxBalanceBoth = {balance: 0, name: ''};
let maxBalanceBothPop = {balance: 0, name: ''};
let maxBalanceFirst = {balance: 0, name: ''};
let maxBalanceFirstPop = {balance: 0, name: ''};
const popularMin = 100;
_each(pesel, (counts, name) => {
if (counts.K[0] + counts.K[1] > 0 && counts.M[0] + counts.M[1] > 0) {
allUnisex[name] = counts;
}
if (counts.K[0] + counts.K[1] >= popularMin && counts.M[0] + counts.M[1] >= popularMin) {
popularUnisex[name] = counts;
if (counts['balanceBoth'] > maxBalanceBoth.balance) {
maxBalanceBoth = {balance: counts['balanceBoth'], name: name};
}
}
if (counts['balanceBothPop'] > maxBalanceBothPop.balance) {
maxBalanceBothPop = {balance: counts['balanceBothPop'], name: name};
}
if (counts.K[0] > 0 && counts.M[0] > 0) {
allFirstUnisex[name] = counts;
}
if (counts.K[0] >= popularMin && counts.M[0] >= popularMin) {
popularFirstUnisex[name] = counts;
if (counts['balanceFirst'] > maxBalanceFirst.balance) {
maxBalanceFirst = {balance: counts['balanceFirst'], name: name};
}
}
if (counts['balanceFirstPop'] > maxBalanceFirstPop.balance) {
maxBalanceFirstPop = {balance: counts['balanceFirstPop'], name: name};
}
});
const buildTable = (names, both, sortBy) => {
names = _each(names, (counts, name) => { return {name, counts} }).sort((a, b) => {
return b.counts[sortBy] - a.counts[sortBy];
})
let table = `<div class="table-wide table-responsive"><table class="table table-sm table-striped"><tr class="sticky-top">`;
table += `<th data-sort><span class="fal fa-signature"></span> Imię</th>`;
table += `<th data-sort="number"><span class="fal fa-venus"></span> Kobiety${both ? ' <small>(pierwsze imię)' : ''}</small></th>`;
if (both) {
table += `<th data-sort="number"><span class="fal fa-venus"></span> Kobiety <small>(drugie imię)</small></th>`;
}
table += `<th data-sort="number"><span class="fal fa-mars"></span> Mężczyźni${both ? ' <small>(pierwsze imię)' : ''}</th>`;
if (both) {
table += `<th data-sort="number"><span class="fal fa-mars"></span> Mężczyźni <small>(drugie imię)</small></th>`;
}
table += `<th data-sort="number"><span class="fal fa-balance-scale"></span> Balans</th>`;
table += `<th data-sort="number" data-sort-auto="desc"><span class="fal fa-trophy"></span> Balans × popularność</th>`;
table += `</tr>`;
for (let {name, counts} of names) {
table += `<tr>`;
table += `<td>${name}</td>`;
table += `<td>${counts.K[0]}</td>`;
if (both) {
table += `<td>${counts.K[1]}</td>`;
}
table += `<td>${counts.M[0]}</td>`;
if (both) {
table += `<td>${counts.M[1]}</td>`;
}
table += `<td>${counts[both ? 'balanceBoth' : 'balanceFirst'].toFixed(3)}</td>`;
table += `<td>${counts[both ? 'balanceBothPop' : 'balanceFirstPop'].toFixed(0)}</td>`;
table += `</tr>`;
}
table += `</table ></div>`;
return table;
}
const buildList = (names) => {
return Object.keys(names).sort().join(', ');
}
console.log('Oba imiona:')
console.log(Object.keys(allUnisex).length);
console.log(buildList(allUnisex));
console.log(Object.keys(popularUnisex).length);
console.log(buildTable(popularUnisex, true, 'balanceBothPop'))
console.log('Max balans', maxBalanceBoth, maxBalanceBothPop)
// console.log(popularUnisex);
console.log('Pierwsze imiona:')
console.log(Object.keys(allFirstUnisex).length);
console.log(buildList(allFirstUnisex));
console.log(Object.keys(popularFirstUnisex).length);
console.log(buildTable(popularFirstUnisex, false, 'balanceFirstPop'))
console.log('Max balans', maxBalanceFirst, maxBalanceFirstPop)
// console.log(popularFirstUnisex);

View File

@ -2012,6 +2012,11 @@ avris-daemonise@^0.0.2:
fs "^0.0.1-security" fs "^0.0.1-security"
yargs "^12.0.1" yargs "^12.0.1"
avris-sorter@^0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/avris-sorter/-/avris-sorter-0.0.2.tgz#d4094fc22fb17867a58f51d139d4549c74d7a6fd"
integrity sha512-VFAb9ffcH036wbdCCIxJL8DYpmu8ZsKPvtu+biDuNsLT+3CJ84GUJ3fBlWiZGgm16vUCf6nzXHO4OQVK9ELumQ==
aws-sdk@^2.799.0: aws-sdk@^2.799.0:
version "2.854.0" version "2.854.0"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.854.0.tgz#531525cdfdfc774232d86619d2c2c2ae3e1a71a8" resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.854.0.tgz#531525cdfdfc774232d86619d2c2c2ae3e1a71a8"