text-to-map 1.1.12 → 1.1.15
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/cities.d.ts +1 -0
- package/dist/bin/cities.js +9 -0
- package/dist/db/cities.d.ts +2 -0
- package/dist/db/cities.js +49 -0
- package/dist/db/migrations/20230731232915_city_positions.js +25 -0
- package/dist/db/types.d.ts +2 -1
- package/dist/db/types.js +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +5 -3
- package/dist/open-data-sync/address-points.js +11 -13
- package/dist/open-data-sync/cities.d.ts +2 -0
- package/dist/open-data-sync/cities.js +40 -0
- package/dist/souradnice.csv +6260 -0
- package/package.json +5 -2
- package/dist/address_points_init.db +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import chunk from "lodash/chunk";
|
|
11
|
+
import { extractKeyValuesPairs, getKnexDb, insertMultipleRows } from "./db";
|
|
12
|
+
const citiesColumn = {
|
|
13
|
+
cityName: 0,
|
|
14
|
+
cityCode: 1,
|
|
15
|
+
countyName: 2,
|
|
16
|
+
countyCode: 3,
|
|
17
|
+
regionName: 4,
|
|
18
|
+
regionCode: 5,
|
|
19
|
+
postalCode: 6,
|
|
20
|
+
latitude: 7,
|
|
21
|
+
longitude: 8,
|
|
22
|
+
};
|
|
23
|
+
export const insertCityPositions = (data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
let changes = 0;
|
|
25
|
+
// cities are most likely already inserted, but in case they're not,
|
|
26
|
+
// we need to insert them before updating them with region data
|
|
27
|
+
changes += yield insertCities(data);
|
|
28
|
+
const prev = changes;
|
|
29
|
+
const knex = getKnexDb();
|
|
30
|
+
for (const arrayChunk of chunk(data, 1000)) {
|
|
31
|
+
const queries = [];
|
|
32
|
+
for (const row of arrayChunk) {
|
|
33
|
+
queries.push(knex.raw(`UPDATE city SET wgs84_latitude = ?, wgs84_longitude = ? WHERE code = ?`, [
|
|
34
|
+
row[citiesColumn.latitude],
|
|
35
|
+
row[citiesColumn.longitude],
|
|
36
|
+
row[citiesColumn.cityCode],
|
|
37
|
+
]));
|
|
38
|
+
}
|
|
39
|
+
yield Promise.all(queries);
|
|
40
|
+
changes += queries.length;
|
|
41
|
+
console.log(`Done ${changes - prev} / ${data.length} rows...`);
|
|
42
|
+
}
|
|
43
|
+
return changes;
|
|
44
|
+
});
|
|
45
|
+
export const insertCities = (buffer) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
return yield insertMultipleRows(extractKeyValuesPairs(buffer, citiesColumn.cityCode, [
|
|
47
|
+
citiesColumn.cityName,
|
|
48
|
+
]), "city", ["code", "name"]);
|
|
49
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export function up(knex) {
|
|
11
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
yield knex.schema.alterTable("city", (t) => {
|
|
13
|
+
t.double("wgs84_latitude").nullable();
|
|
14
|
+
t.double("wgs84_longitude").nullable();
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
export function down(knex) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
yield knex.schema.alterTable("city", (t) => {
|
|
21
|
+
t.dropColumn("wgs84_latitude");
|
|
22
|
+
t.dropColumn("wgs84_longitude");
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
package/dist/db/types.d.ts
CHANGED
package/dist/db/types.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { clearDb, initDb } from "./db/db";
|
|
2
2
|
import { downloadAndImportAddressPoints } from "./open-data-sync/address-points";
|
|
3
|
+
import { importCities } from "./open-data-sync/cities";
|
|
3
4
|
import { downloadAndImportRegions } from "./open-data-sync/regions";
|
|
4
5
|
import { downloadAndImportSchools } from "./open-data-sync/schools";
|
|
5
6
|
import { downloadAndImportStreets } from "./open-data-sync/streets";
|
|
6
7
|
import { OpenDataSyncOptionsPartial } from "./utils/helpers";
|
|
7
|
-
export * from "./street-markdown/types";
|
|
8
8
|
export * from "./street-markdown/smd";
|
|
9
|
+
export * from "./street-markdown/types";
|
|
9
10
|
/**
|
|
10
11
|
* Download and import all open data to SQLite DB. The DB file will be located
|
|
11
12
|
* in the `dataDir` folder.
|
|
@@ -18,4 +19,4 @@ export * from "./street-markdown/smd";
|
|
|
18
19
|
* ```
|
|
19
20
|
*/
|
|
20
21
|
export declare function downloadAndImportEverything(options?: OpenDataSyncOptionsPartial, syncStreets?: boolean): Promise<void>;
|
|
21
|
-
export {
|
|
22
|
+
export { clearDb, downloadAndImportAddressPoints, downloadAndImportRegions, downloadAndImportSchools, downloadAndImportStreets, importCities, initDb, };
|
package/dist/index.js
CHANGED
|
@@ -8,12 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { clearDb, initDb } from "./db/db";
|
|
11
|
-
import { downloadAndImportAddressPoints
|
|
11
|
+
import { downloadAndImportAddressPoints } from "./open-data-sync/address-points";
|
|
12
|
+
import { importCities } from "./open-data-sync/cities";
|
|
12
13
|
import { downloadAndImportRegions } from "./open-data-sync/regions";
|
|
13
14
|
import { downloadAndImportSchools } from "./open-data-sync/schools";
|
|
14
15
|
import { downloadAndImportStreets } from "./open-data-sync/streets";
|
|
15
|
-
export * from "./street-markdown/types";
|
|
16
16
|
export * from "./street-markdown/smd";
|
|
17
|
+
export * from "./street-markdown/types";
|
|
17
18
|
/**
|
|
18
19
|
* Download and import all open data to SQLite DB. The DB file will be located
|
|
19
20
|
* in the `dataDir` folder.
|
|
@@ -31,9 +32,10 @@ export function downloadAndImportEverything(options = {}, syncStreets = true) {
|
|
|
31
32
|
yield downloadAndImportAddressPoints(options);
|
|
32
33
|
yield downloadAndImportSchools(options);
|
|
33
34
|
yield downloadAndImportRegions(options);
|
|
35
|
+
yield importCities(options);
|
|
34
36
|
if (syncStreets) {
|
|
35
37
|
yield downloadAndImportStreets(options);
|
|
36
38
|
}
|
|
37
39
|
});
|
|
38
40
|
}
|
|
39
|
-
export {
|
|
41
|
+
export { clearDb, downloadAndImportAddressPoints, downloadAndImportRegions, downloadAndImportSchools, downloadAndImportStreets, importCities, initDb, };
|
|
@@ -14,6 +14,7 @@ import iconv from "iconv-lite";
|
|
|
14
14
|
import fetch from "node-fetch";
|
|
15
15
|
import { join } from "path";
|
|
16
16
|
import { pipeline } from "stream/promises";
|
|
17
|
+
import chunk from "lodash/chunk";
|
|
17
18
|
import { commitAddressPoints } from "../db/address-points";
|
|
18
19
|
import { SyncPart } from "../db/types";
|
|
19
20
|
import { getLatestUrlFromAtomFeed } from "../utils/atom";
|
|
@@ -42,24 +43,21 @@ const importDataToDb = (options) => __awaiter(void 0, void 0, void 0, function*
|
|
|
42
43
|
let total = 0;
|
|
43
44
|
let next = 0;
|
|
44
45
|
console.log("Initiating import of RUIAN data to search DB (~3 million rows to be imported).");
|
|
45
|
-
const buffer = [];
|
|
46
46
|
for (const file of files) {
|
|
47
|
+
const rows = [];
|
|
47
48
|
const parseStream = parse({ delimiter: ";", fromLine: 2 }).on("data", (data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
|
-
|
|
49
|
-
if (buffer.length >= maxBufferSize) {
|
|
50
|
-
parseStream.pause();
|
|
51
|
-
total += yield commitAddressPoints(buffer);
|
|
52
|
-
if (total - next >= 100000) {
|
|
53
|
-
next += 100000;
|
|
54
|
-
console.log(`Total imported rows: ${next}`);
|
|
55
|
-
}
|
|
56
|
-
buffer.length = 0;
|
|
57
|
-
parseStream.resume();
|
|
58
|
-
}
|
|
49
|
+
rows.push(data);
|
|
59
50
|
}));
|
|
60
51
|
yield pipeline(createReadStream(join(extractionFolder, file)), iconv.decodeStream("win1250"), parseStream);
|
|
52
|
+
const chunks = chunk(rows, maxBufferSize);
|
|
53
|
+
yield Promise.all(chunks.map((chunk) => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
+
total += yield commitAddressPoints(chunk);
|
|
55
|
+
if (total - next >= 100000) {
|
|
56
|
+
next += 100000;
|
|
57
|
+
console.log(`Total imported rows: ${next}`);
|
|
58
|
+
}
|
|
59
|
+
})));
|
|
61
60
|
}
|
|
62
|
-
total += yield commitAddressPoints(buffer);
|
|
63
61
|
console.log(`Import completed. Total imported rows: ${total}`);
|
|
64
62
|
});
|
|
65
63
|
const getExtractionFolder = (options) => join(options.tmpDir, options.addressPointsCsvFolderName);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { parse } from "csv-parse";
|
|
11
|
+
import iconv from "iconv-lite";
|
|
12
|
+
import { pipeline } from "stream/promises";
|
|
13
|
+
import { SyncPart } from "../db/types";
|
|
14
|
+
import { prepareOptions, } from "../utils/helpers";
|
|
15
|
+
import { runSyncPart } from "./common";
|
|
16
|
+
import { createReadStream } from "fs";
|
|
17
|
+
import { insertCityPositions } from "../db/cities";
|
|
18
|
+
import { fileURLToPath } from "url";
|
|
19
|
+
import { dirname, join } from "path";
|
|
20
|
+
const importDataToDb = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
console.log("Starting to parse CSV file...");
|
|
22
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
23
|
+
const __dirname = dirname(__filename);
|
|
24
|
+
// source: https://github.com/33bcdd/souradnice-mest/blob/master/souradnice.csv
|
|
25
|
+
const csvStream = createReadStream(join(__dirname, "..", "souradnice.csv"));
|
|
26
|
+
const rows = [];
|
|
27
|
+
const parseStream = parse({ delimiter: ",", fromLine: 2 }).on("data", (data) => {
|
|
28
|
+
rows.push(data);
|
|
29
|
+
});
|
|
30
|
+
yield pipeline(csvStream, iconv.decodeStream("utf-8"), parseStream);
|
|
31
|
+
console.log("Parsing completed. Starting to import data to DB...");
|
|
32
|
+
yield insertCityPositions(rows);
|
|
33
|
+
console.log(`Import completed. Total imported rows: ${rows.length}`);
|
|
34
|
+
});
|
|
35
|
+
export const importCities = (options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
yield runSyncPart(SyncPart.Regions, [], () => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
const completeOptions = prepareOptions(options);
|
|
38
|
+
yield importDataToDb(completeOptions);
|
|
39
|
+
}));
|
|
40
|
+
});
|