text-to-map 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/address-points.js +1 -1
- package/dist/bin/regions.js +1 -1
- package/dist/bin/schools.js +1 -1
- package/dist/bin/streets.js +1 -1
- package/dist/bin/sync-all.d.ts +1 -0
- package/dist/bin/sync-all.js +2 -0
- package/dist/db/regions.d.ts +15 -7
- package/dist/db/regions.js +56 -44
- package/dist/open-data-sync/regions.js +7 -1
- package/dist/utils/helpers.d.ts +2 -0
- package/dist/utils/helpers.js +3 -2
- package/package.json +5 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { downloadAndImportAddressPoints } from "../open-data-sync/address-points";
|
|
2
2
|
console.time("downloadAndImportAllLatestAddressPoints");
|
|
3
|
-
downloadAndImportAddressPoints()
|
|
3
|
+
downloadAndImportAddressPoints({ dataDir: "./tmp/db" })
|
|
4
4
|
.then(() => {
|
|
5
5
|
console.timeEnd("downloadAndImportAllLatestAddressPoints");
|
|
6
6
|
})
|
package/dist/bin/regions.js
CHANGED
package/dist/bin/schools.js
CHANGED
package/dist/bin/streets.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { downloadAndImportStreets } from "../open-data-sync/streets";
|
|
2
2
|
console.time("downloadAndImportAllStreets");
|
|
3
|
-
downloadAndImportStreets({})
|
|
3
|
+
downloadAndImportStreets({ dataDir: "./tmp/db" })
|
|
4
4
|
.then(() => {
|
|
5
5
|
console.timeEnd("downloadAndImportAllStreets");
|
|
6
6
|
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/db/regions.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
interface RegionsColumn {
|
|
2
2
|
cityName: number;
|
|
3
3
|
cityCode: number;
|
|
4
4
|
cityType: number;
|
|
@@ -15,9 +15,17 @@ export declare const Column: {
|
|
|
15
15
|
regionCsuCode100: number;
|
|
16
16
|
regionCsuCode108Nuts: number;
|
|
17
17
|
regionRuianCode: number;
|
|
18
|
-
}
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
}
|
|
19
|
+
export interface RegionsTableSchema {
|
|
20
|
+
tableSchema: {
|
|
21
|
+
columns: {
|
|
22
|
+
name: string;
|
|
23
|
+
}[];
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export declare const insertRegionsAndOrps: (data: string[][], schema: RegionsTableSchema) => number;
|
|
27
|
+
export declare const insertRegions: (buffer: string[][], columnIndex: RegionsColumn) => number;
|
|
28
|
+
export declare const insertCounties: (buffer: string[][], columnIndex: RegionsColumn) => number;
|
|
29
|
+
export declare const insertOrps: (buffer: string[][], columnIndex: RegionsColumn) => number;
|
|
30
|
+
export declare const insertCities: (buffer: string[][], columnIndex: RegionsColumn) => number;
|
|
31
|
+
export {};
|
package/dist/db/regions.js
CHANGED
|
@@ -1,30 +1,13 @@
|
|
|
1
1
|
import { extractKeyValuesPairs, getDb, insertMultipleRows } from "./db";
|
|
2
|
-
export const
|
|
3
|
-
|
|
4
|
-
cityCode: 1,
|
|
5
|
-
cityType: 2,
|
|
6
|
-
orpName: 9,
|
|
7
|
-
orpCsuCode65: 10,
|
|
8
|
-
orpRuianCode: 11,
|
|
9
|
-
orpCityCode: 12,
|
|
10
|
-
countyName: 13,
|
|
11
|
-
countyCsuCode101Lau: 14,
|
|
12
|
-
countyCsuCode109Nuts: 15,
|
|
13
|
-
countyRuianCode: 16,
|
|
14
|
-
regionName: 17,
|
|
15
|
-
regionShortName: 18,
|
|
16
|
-
regionCsuCode100: 19,
|
|
17
|
-
regionCsuCode108Nuts: 20,
|
|
18
|
-
regionRuianCode: 21,
|
|
19
|
-
};
|
|
20
|
-
export const insertRegionsAndOrps = (data) => {
|
|
2
|
+
export const insertRegionsAndOrps = (data, schema) => {
|
|
3
|
+
const columnIndex = getColumnIndexFromSchema(schema);
|
|
21
4
|
let changes = 0;
|
|
22
|
-
changes += insertRegions(data);
|
|
23
|
-
changes += insertCounties(data);
|
|
24
|
-
changes += insertOrps(data);
|
|
5
|
+
changes += insertRegions(data, columnIndex);
|
|
6
|
+
changes += insertCounties(data, columnIndex);
|
|
7
|
+
changes += insertOrps(data, columnIndex);
|
|
25
8
|
// cities are most likely already inserted, but in case they're not,
|
|
26
9
|
// we need to insert them before updating them with region data
|
|
27
|
-
changes += insertCities(data);
|
|
10
|
+
changes += insertCities(data, columnIndex);
|
|
28
11
|
const db = getDb();
|
|
29
12
|
const updateStatement = db.prepare(`UPDATE city SET
|
|
30
13
|
region_code = ?,
|
|
@@ -32,34 +15,63 @@ export const insertRegionsAndOrps = (data) => {
|
|
|
32
15
|
orp_code = ?
|
|
33
16
|
WHERE code = ?`);
|
|
34
17
|
data.forEach((data) => {
|
|
35
|
-
changes += updateStatement.run(data[
|
|
18
|
+
changes += updateStatement.run(data[columnIndex.regionRuianCode], data[columnIndex.countyRuianCode], data[columnIndex.orpRuianCode], data[columnIndex.cityCode]).changes;
|
|
36
19
|
});
|
|
37
20
|
return changes;
|
|
38
21
|
};
|
|
39
|
-
export const insertRegions = (buffer) => {
|
|
40
|
-
return insertMultipleRows(extractKeyValuesPairs(buffer,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
22
|
+
export const insertRegions = (buffer, columnIndex) => {
|
|
23
|
+
return insertMultipleRows(extractKeyValuesPairs(buffer, columnIndex.regionRuianCode, [
|
|
24
|
+
columnIndex.regionName,
|
|
25
|
+
columnIndex.regionShortName,
|
|
26
|
+
columnIndex.regionCsuCode100,
|
|
27
|
+
columnIndex.regionCsuCode108Nuts,
|
|
45
28
|
]), "region", ["code", "name", "short_name", "csu_code_100", "csu_code_108_nuts"]);
|
|
46
29
|
};
|
|
47
|
-
export const insertCounties = (buffer) => {
|
|
48
|
-
return insertMultipleRows(extractKeyValuesPairs(buffer,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
30
|
+
export const insertCounties = (buffer, columnIndex) => {
|
|
31
|
+
return insertMultipleRows(extractKeyValuesPairs(buffer, columnIndex.countyRuianCode, [
|
|
32
|
+
columnIndex.countyName,
|
|
33
|
+
columnIndex.countyCsuCode101Lau,
|
|
34
|
+
columnIndex.countyCsuCode109Nuts,
|
|
35
|
+
columnIndex.regionRuianCode,
|
|
53
36
|
]), "county", ["code", "name", "csu_code_101_lau", "csu_code_109_nuts", "region_code"]);
|
|
54
37
|
};
|
|
55
|
-
export const insertOrps = (buffer) => {
|
|
56
|
-
return insertMultipleRows(extractKeyValuesPairs(buffer,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
38
|
+
export const insertOrps = (buffer, columnIndex) => {
|
|
39
|
+
return insertMultipleRows(extractKeyValuesPairs(buffer, columnIndex.orpRuianCode, [
|
|
40
|
+
columnIndex.orpName,
|
|
41
|
+
columnIndex.orpCsuCode65,
|
|
42
|
+
columnIndex.regionRuianCode,
|
|
43
|
+
columnIndex.countyRuianCode,
|
|
61
44
|
]), "orp", ["code", "name", "csu_code_65", "region_code", "county_code"]);
|
|
62
45
|
};
|
|
63
|
-
export const insertCities = (buffer) => {
|
|
64
|
-
return insertMultipleRows(extractKeyValuesPairs(buffer,
|
|
46
|
+
export const insertCities = (buffer, columnIndex) => {
|
|
47
|
+
return insertMultipleRows(extractKeyValuesPairs(buffer, columnIndex.cityCode, [columnIndex.cityName]), "city", ["code", "name"]);
|
|
48
|
+
};
|
|
49
|
+
const getColumnIndexFromSchema = (schema) => {
|
|
50
|
+
const names = schema.tableSchema.columns.map((column) => column.name);
|
|
51
|
+
const columnIndex = {
|
|
52
|
+
cityName: findOrDie(names, "obec_text"),
|
|
53
|
+
cityCode: findOrDie(names, "obec_kod"),
|
|
54
|
+
cityType: findOrDie(names, "obec_typ"),
|
|
55
|
+
orpName: findOrDie(names, "orp_text"),
|
|
56
|
+
orpCsuCode65: findOrDie(names, "orp_csu_cis65_kod"),
|
|
57
|
+
orpRuianCode: findOrDie(names, "orp_ruian_kod"),
|
|
58
|
+
orpCityCode: findOrDie(names, "orp_sidlo_obec_kod"),
|
|
59
|
+
countyName: findOrDie(names, "okres_text"),
|
|
60
|
+
countyCsuCode101Lau: findOrDie(names, "okres_csu_cis101_lau_kod"),
|
|
61
|
+
countyCsuCode109Nuts: findOrDie(names, "okres_csu_cis109_nuts_kod"),
|
|
62
|
+
countyRuianCode: findOrDie(names, "okres_ruian_kod"),
|
|
63
|
+
regionName: findOrDie(names, "kraj_text"),
|
|
64
|
+
regionShortName: findOrDie(names, "kraj_zkratka"),
|
|
65
|
+
regionCsuCode100: findOrDie(names, "kraj_csu_cis100_kod"),
|
|
66
|
+
regionCsuCode108Nuts: findOrDie(names, "kraj_csu_cis108_nuts_kod"),
|
|
67
|
+
regionRuianCode: findOrDie(names, "kraj_ruian_vusc_kod"),
|
|
68
|
+
};
|
|
69
|
+
return columnIndex;
|
|
70
|
+
};
|
|
71
|
+
const findOrDie = (columnNames, name) => {
|
|
72
|
+
const index = columnNames.indexOf(name);
|
|
73
|
+
if (index < 0) {
|
|
74
|
+
throw new Error(`Column '${name}' not found in region schema. Check https://data.gov.cz/datov%C3%A1-sada?iri=https%3A%2F%2Fdata.gov.cz%2Fzdroj%2Fdatov%C3%A9-sady%2F00025593%2F271b0fb7c2abb7f44e12ad57617821b2 for current dataset info or search for 'Struktura území ČR se všemi kódy území od obcí po stát dle číselníků ČSÚ, klasifikace NUTS a kódů RÚIAN.'.`);
|
|
75
|
+
}
|
|
76
|
+
return index;
|
|
65
77
|
};
|
|
@@ -25,9 +25,15 @@ const downloadAndImportDataToDb = (options) => __awaiter(void 0, void 0, void 0,
|
|
|
25
25
|
rows.push(data);
|
|
26
26
|
});
|
|
27
27
|
yield pipeline(response.body, iconv.decodeStream("utf-8"), parseStream);
|
|
28
|
+
const schemaResponse = yield fetch(options.regionsSchemaUrl);
|
|
29
|
+
if (schemaResponse.status !== 200) {
|
|
30
|
+
throw new Error(`The file could not be downloaded. HTTP Code: ${schemaResponse.status}`);
|
|
31
|
+
}
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
const schema = yield schemaResponse.json();
|
|
28
34
|
console.log("Parsing completed. Starting to import data to DB...");
|
|
29
35
|
initDb(options);
|
|
30
|
-
insertRegionsAndOrps(rows);
|
|
36
|
+
insertRegionsAndOrps(rows, schema);
|
|
31
37
|
console.log(`Import completed. Total imported rows: ${rows.length}`);
|
|
32
38
|
});
|
|
33
39
|
export const downloadAndImportRegions = (options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
package/dist/utils/helpers.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export interface OpenDataSyncOptions {
|
|
|
13
13
|
schoolsXmlUrl?: string;
|
|
14
14
|
schoolsXmlFileName?: string;
|
|
15
15
|
regionsCsvUrl?: string;
|
|
16
|
+
regionsSchemaUrl?: string;
|
|
16
17
|
regionsCsvFileName?: string;
|
|
17
18
|
}
|
|
18
19
|
export interface OpenDataSyncOptionsNotEmpty {
|
|
@@ -29,6 +30,7 @@ export interface OpenDataSyncOptionsNotEmpty {
|
|
|
29
30
|
schoolsXmlUrl: string;
|
|
30
31
|
schoolsXmlFileName: string;
|
|
31
32
|
regionsCsvUrl: string;
|
|
33
|
+
regionsSchemaUrl: string;
|
|
32
34
|
regionsCsvFileName: string;
|
|
33
35
|
}
|
|
34
36
|
export declare const getAppDataDirPath: () => string;
|
package/dist/utils/helpers.js
CHANGED
|
@@ -10,7 +10,7 @@ export const getAppDataDirPath = () => join(process.env.APPDATA ||
|
|
|
10
10
|
? process.env.HOME + "/Library/Preferences"
|
|
11
11
|
: process.env.HOME + "/.local/share"), appName);
|
|
12
12
|
export const prepareOptions = (options) => {
|
|
13
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
13
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
14
14
|
const dataDir = (_a = options.dataDir) !== null && _a !== void 0 ? _a : getAppDataDirPath();
|
|
15
15
|
if (!existsSync(dataDir)) {
|
|
16
16
|
mkdirSync(dataDir);
|
|
@@ -35,7 +35,8 @@ export const prepareOptions = (options) => {
|
|
|
35
35
|
schoolsXmlUrl: (_l = options.schoolsXmlUrl) !== null && _l !== void 0 ? _l : "https://rejstriky.msmt.cz/opendata/vrejcelk.xml",
|
|
36
36
|
schoolsXmlFileName: (_m = options.schoolsXmlFileName) !== null && _m !== void 0 ? _m : "school-register.xml",
|
|
37
37
|
regionsCsvUrl: (_o = options.regionsCsvUrl) !== null && _o !== void 0 ? _o : "https://www.czso.cz/documents/10180/23208674/struktura_uzemi_cr.csv",
|
|
38
|
-
|
|
38
|
+
regionsSchemaUrl: (_p = options.regionsSchemaUrl) !== null && _p !== void 0 ? _p : "https://www.czso.cz/documents/10180/23208674/struktura_uzemi_cr-metadata.json",
|
|
39
|
+
regionsCsvFileName: (_q = options.regionsCsvFileName) !== null && _q !== void 0 ? _q : "struktura_uzemi_cr.csv",
|
|
39
40
|
};
|
|
40
41
|
};
|
|
41
42
|
export const initDb = (options) => {
|
package/package.json
CHANGED
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
"ts-node": "^10.9.1"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
|
+
"sync-all": "ts-node --experimental-specifier-resolution=node --esm src/bin/sync-all.ts",
|
|
32
33
|
"address-points": "ts-node --experimental-specifier-resolution=node --esm src/bin/address-points.ts",
|
|
34
|
+
"regions": "ts-node --experimental-specifier-resolution=node --esm src/bin/regions.ts",
|
|
33
35
|
"schools": "ts-node --experimental-specifier-resolution=node --esm src/bin/schools.ts",
|
|
36
|
+
"streets": "ts-node --experimental-specifier-resolution=node --esm src/bin/streets.ts",
|
|
37
|
+
"diagrams": "ts-node --experimental-specifier-resolution=node --esm src/bin/generate-syntax-diagrams.ts",
|
|
34
38
|
"clear-all": "ts-node --experimental-specifier-resolution=node --esm src/bin/clear-all.ts",
|
|
35
39
|
"parse-ordinance": "ts-node --experimental-specifier-resolution=node --esm src/bin/parse-ordinance.ts",
|
|
36
|
-
"diagrams": "ts-node --experimental-specifier-resolution=node --esm src/bin/generate-syntax-diagrams.ts",
|
|
37
|
-
"streets": "ts-node --experimental-specifier-resolution=node --esm src/bin/streets.ts",
|
|
38
|
-
"regions": "ts-node --experimental-specifier-resolution=node --esm src/bin/regions.ts",
|
|
39
|
-
"dbf": "ts-node --experimental-specifier-resolution=node --esm src/bin/dbf.ts",
|
|
40
40
|
"test": "node --experimental-vm-modules --no-warnings node_modules/jest/bin/jest.js -c=jest-esm.config.mjs --no-cache",
|
|
41
41
|
"ordinance-to-csv-rules": "node src/smd-to-csv/ordinance-to-csv-rules.js",
|
|
42
42
|
"clean": "rimraf dist",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"name": "text-to-map",
|
|
50
50
|
"description": "Text To Map usiluje o lepší, strojově zpracovatelné využití částí vyhlášek s výčtem ulic a dalších lokací. Jde o rozšiřitelnou sadu konceptů a nástrojů, které zajistí hladký převod výčtu ulic a jejich rozsahů v lidsky srozumitelném jazyce do strojově zpracovatelného, uchopitelného formátu.",
|
|
51
|
-
"version": "1.0.
|
|
51
|
+
"version": "1.0.6",
|
|
52
52
|
"main": "dist/index.js",
|
|
53
53
|
"types": "dist/index.d.ts",
|
|
54
54
|
"files": [
|