update resources

This commit is contained in:
Hugoren Martinako 2022-11-26 14:20:24 +01:00
parent 16f41728d4
commit 83a1d99eb6
5 changed files with 15 additions and 149 deletions

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
data/*
batch/*
!*/.gitkeep
node_modules/
node_modules/
**/package-lock.json

View File

@ -1,88 +0,0 @@
/**
* node compare_csv.js <CSV_1> <CSV_2>
*/
const fs = require('fs');
const csv = require('csv-parser')
const [,, ...files] = process.argv
function groupBy(data, key) {
return data.reduce((acc, x) => {
const cat = key instanceof Function ? key(x) : x[key];
(acc[cat] = acc[cat] || []).push(x);
return acc;
}, {})
};
const map = {
"01": "VI",
"02": "AB",
"03": "A",
"04": "AL",
"05": "AV",
"06": "BA",
"07": "PM",
"08": "B",
"09": "BU",
"10": "CC",
"11": "CA",
"12": "CS",
"13": "CR",
"14": "CO",
"15": "C",
"16": "CU",
"17": "GI",
"18": "GR",
"19": "GU",
"20": "SS",
"21": "H",
"22": "HU",
"23": "J",
"24": "LE",
"25": "L",
"26": "LO",
"27": "LU",
"28": "M",
"29": "MA",
"30": "MU",
"31": "NA",
"32": "OR",
"33": "O",
"34": "P",
"35": "GC",
"36": "PO",
"37": "SA",
"38": "TF",
"39": "S",
"40": "SG",
"41": "SE",
"42": "SO",
"43": "T",
"44": "TE",
"45": "TO",
"46": "V",
"47": "VA",
"48": "BI",
"49": "ZA",
"50": "Z",
"51": "CE",
"52": "ML"
}
Promise.all(files.map(x => new Promise((resolve) => {
const results = [];
fs.createReadStream(x)
.pipe(csv({ separator: ";", headers: ["INE", "NAME",,, "TIPO"] }))
.on('data', (data) => results.push(data))
.on('end', () => resolve(results));
}))).then(([a,b]) => {
const INES = b.map(({ INE }) => INE)
const missing = a.filter(({ INE, TIPO }) => TIPO === "Entidad singular" && !INES.includes(INE))
const json = Object.entries(groupBy(missing, ({ INE }) => INE.slice(0, 2))).map(([k,v]) => [k, v.reduce((acc, { INE, NAME }) => ({ ...acc, [NAME]: INE }), {})])
for (let index = 0; index < json.length; index++) {
const [key, values] = json[index];
fs.writeFile(`../data/missing_ref_ine/${map[key]}.json`, JSON.stringify(values, null, 2), () => {})
}
})

View File

@ -3,76 +3,24 @@
*/
const fs = require('fs');
const [,, folder] = process.argv
const path = require('path');
const __root = path.join(__dirname, "..");
const map = {
"01": "VI",
"02": "AB",
"03": "A",
"04": "AL",
"05": "AV",
"06": "BA",
"07": "PM",
"08": "B",
"09": "BU",
"10": "CC",
"11": "CA",
"12": "CS",
"13": "CR",
"14": "CO",
"15": "C",
"16": "CU",
"17": "GI",
"18": "GR",
"19": "GU",
"20": "SS",
"21": "H",
"22": "HU",
"23": "J",
"24": "LE",
"25": "L",
"26": "LO",
"27": "LU",
"28": "M",
"29": "MA",
"30": "MU",
"31": "NA",
"32": "OR",
"33": "O",
"34": "P",
"35": "GC",
"36": "PO",
"37": "SA",
"38": "TF",
"39": "S",
"40": "SG",
"41": "SE",
"42": "SO",
"43": "T",
"44": "TE",
"45": "TO",
"46": "V",
"47": "VA",
"48": "BI",
"49": "ZA",
"50": "Z",
"51": "CE",
"52": "ML"
}
const [,, folder] = process.argv
fs.readdir(folder, (err, files) => {
const json = files.filter(x => /.json/.test(x))
Promise.all(json.map(f => import(`${folder}/${f}`, {
Promise.all(json.map(f => import(path.join(__root, `${folder}/${f}`), {
assert: {
type: "json",
}
}))).then((responses) => {
for (let index = 0; index < responses.length; index++) {
const { default: element } = responses[index];
const code = map[Object.values(element)?.[0]?.slice(0, 2)]
const overpass = `node["place"]["place"!~"islet|locality|plot|neighbourhood|state|square|quarter|region|farm|suburb"]["ref:ine"!~".*"]["name"~"${Object.keys(element).reduce((acc, key) => acc + `${key.toLowerCase()}|`, "")}",i];`;
fs.writeFile(`../batch/${code}.ql`, overpass, () => { })
const cleanKey = (key = "") => key.split(/\/|-/).map(x => x.trim().toLowerCase().replace(/['"]+/g, "").replace(/ +/g, "\\\\s+")).join("|")
const overpass = `node["place"]["place"!~"plot|neighbourhood|state|square|quarter|region|farm|city_block"]["ref:ine"!~".*"][~"name"~"${Object.keys(element).map((key) => key && cleanKey(key)).join("|")}",i];`;
fs.writeFile(path.join(__root, `batch/${path.basename(json[index], ".json")}.ql`), overpass, () => { })
}
})
})

6
fixes/package.json Normal file
View File

@ -0,0 +1,6 @@
{
"dependencies": {
"csv-parser": "^3.0.0",
"xml2js": "^0.4.23"
}
}

View File

@ -1 +0,0 @@
rel["boundary"]["admin_level"~"4|6|8"]->.a;node(r.a:"admin_centre");(._;.a;);