text-to-map 1.1.18 → 1.1.19

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.
@@ -36,9 +36,15 @@ function main() {
36
36
  };
37
37
  console.time("downloadAndImportAllLatestAddressPoints");
38
38
  const { municipality } = yield getNewMunicipalityByName("Česká Lípa");
39
- const addressPoints = yield parseOrdinanceToAddressPoints(lines, {
40
- // currentMunicipality: municipality,
41
- }, reportErrors, reportWarnings);
39
+ const addressPoints = yield parseOrdinanceToAddressPoints({
40
+ lines,
41
+ initialState: {
42
+ // currentMunicipality: municipality,
43
+ },
44
+ onError: reportErrors,
45
+ onWarning: reportWarnings,
46
+ includeUnmappedAddressPoints: true,
47
+ });
42
48
  console.timeEnd("downloadAndImportAllLatestAddressPoints");
43
49
  console.log(`Parsed ${lines.length} lines, ${errorCount} errors, ${warningCount} warnings.`);
44
50
  if (errorCount > 0) {
@@ -1,14 +1,17 @@
1
1
  import { Founder } from "../db/types";
2
- import { ErrorCallbackParams, Municipality, MunicipalityWithFounder, ProcessLineCallbackParams, School, SmdError, SmdState } from "./types";
3
- export declare const parseOrdinanceToAddressPoints: (lines: string[], initialState?: Partial<SmdState>, onError?: (params: ErrorCallbackParams) => void, onWarning?: (params: ErrorCallbackParams) => void, onProcessedLine?: (params: ProcessLineCallbackParams) => void) => Promise<Municipality[]>;
2
+ import { ErrorCallbackParams, Municipality, MunicipalityWithFounder, MunicipalityWithFounderResult, ProcessLineCallbackParams, School, SmdError, SmdState } from "./types";
3
+ interface ParseOrdinanceProps {
4
+ lines: string[];
5
+ initialState?: Partial<SmdState>;
6
+ onError?: (params: ErrorCallbackParams) => void;
7
+ onWarning?: (params: ErrorCallbackParams) => void;
8
+ onProcessedLine?: (params: ProcessLineCallbackParams) => void;
9
+ includeUnmappedAddressPoints: boolean;
10
+ }
11
+ export declare const parseOrdinanceToAddressPoints: ({ lines, initialState, onError, onWarning, onProcessedLine, includeUnmappedAddressPoints, }: ParseOrdinanceProps) => Promise<Municipality[]>;
4
12
  export declare const convertMunicipality: (municipality: MunicipalityWithFounder) => Municipality;
5
- export declare const getNewMunicipalityByName: (name: string) => Promise<{
6
- municipality: MunicipalityWithFounder;
7
- errors: SmdError[];
8
- }>;
9
- export declare const getNewMunicipalityByFounderId: (founderId: number) => Promise<{
10
- municipality: MunicipalityWithFounder;
11
- errors: SmdError[];
12
- }>;
13
+ export declare const getNewMunicipalityByName: (name: string) => Promise<MunicipalityWithFounderResult>;
14
+ export declare const getNewMunicipalityByFounderId: (founderId: number) => Promise<MunicipalityWithFounderResult>;
13
15
  export declare const getNewSchool: (name: string, founder: Founder | null, lineNumber: number, onError: (params: ErrorCallbackParams) => void) => Promise<School>;
14
16
  export declare const wholeLineError: (message: string, line: string) => SmdError;
17
+ export {};
@@ -15,12 +15,13 @@ import { founderToMunicipality } from "../db/types";
15
15
  import { getMunicipalityPartResult, getRestOfMunicipalityPart, getSwitchMunicipality, getWholeMunicipality, isMunicipalitySwitch, isRestOfMunicipalityLine, isRestOfMunicipalityPartLine, isRestWithNoStreetNameLine, isWholeMunicipality, } from "./municipality";
16
16
  import { parseLine } from "./smd-line-parser";
17
17
  import { isAddressPoint, } from "./types";
18
- export const parseOrdinanceToAddressPoints = (lines, initialState = {}, onError = () => { }, onWarning = () => { }, onProcessedLine = () => { }) => __awaiter(void 0, void 0, void 0, function* () {
18
+ export const parseOrdinanceToAddressPoints = ({ lines, initialState = {}, onError = () => { }, onWarning = () => { }, onProcessedLine = () => { }, includeUnmappedAddressPoints = false, }) => __awaiter(void 0, void 0, void 0, function* () {
19
19
  try {
20
20
  const state = Object.assign({ currentMunicipality: null, currentFilterMunicipality: null, currentSchool: null, rests: {
21
21
  noStreetNameSchoolIzo: null,
22
22
  municipalityParts: [],
23
23
  wholeMunicipalitySchoolIzo: null,
24
+ includeUnmappedAddressPoints,
24
25
  }, municipalities: [] }, initialState);
25
26
  let lineNumber = 1;
26
27
  for (const rawLine of lines) {
@@ -61,6 +62,7 @@ export const convertMunicipality = (municipality) => {
61
62
  return {
62
63
  municipalityName: municipality.municipalityName,
63
64
  schools: municipality.schools,
65
+ unmappedPoints: municipality.unmappedPoints,
64
66
  };
65
67
  };
66
68
  const processOneLine = (params) => __awaiter(void 0, void 0, void 0, function* () {
@@ -210,14 +212,14 @@ const processAddressPointLine = ({ line, state, lineNumber, onError, onWarning,
210
212
  }
211
213
  }
212
214
  });
213
- const addRestToSchool = (restPoints, schoolIzo, state) => __awaiter(void 0, void 0, void 0, function* () {
215
+ const addRestToSchool = (restPoints, schoolIzo, state) => {
214
216
  const addressPoints = state.currentMunicipality.schools.flatMap((school) => school.addresses);
215
217
  // filter out address points already present
216
218
  const remainingPoints = restPoints.filter((point) => !addressPoints.some((ap) => ap.address === point.address));
217
219
  // find the right school and add the remaining address points
218
220
  const schoolIndex = state.currentMunicipality.schools.findIndex((school) => school.izo === schoolIzo);
219
221
  state.currentMunicipality.schools[schoolIndex].addresses.push(...remainingPoints);
220
- });
222
+ };
221
223
  const addRests = (state) => __awaiter(void 0, void 0, void 0, function* () {
222
224
  if (state.rests.noStreetNameSchoolIzo) {
223
225
  yield addRestWithNoStreetNameToSchool(state);
@@ -228,6 +230,9 @@ const addRests = (state) => __awaiter(void 0, void 0, void 0, function* () {
228
230
  for (const rest of state.rests.municipalityParts) {
229
231
  yield addRestOfMunicipalityPart(state, rest.municipalityPartCode, rest.schoolIzo);
230
232
  }
233
+ if (state.rests.includeUnmappedAddressPoints) {
234
+ yield addRestOfMunicipalityToUnmappedPoints(state);
235
+ }
231
236
  state.rests.noStreetNameSchoolIzo = null;
232
237
  state.rests.wholeMunicipalitySchoolIzo = null;
233
238
  state.rests.municipalityParts = [];
@@ -241,18 +246,23 @@ const addRestWithNoStreetNameToSchool = (state) => __awaiter(void 0, void 0, voi
241
246
  type: state.currentMunicipality.founder.municipalityType,
242
247
  },
243
248
  });
244
- yield addRestToSchool(pointsNoStreetName, state.rests.noStreetNameSchoolIzo, state);
249
+ addRestToSchool(pointsNoStreetName, state.rests.noStreetNameSchoolIzo, state);
245
250
  });
246
251
  const addRestOfMunicipality = (state) => __awaiter(void 0, void 0, void 0, function* () {
252
+ addRestToSchool(yield getRestOfMunicipality(state), state.rests.wholeMunicipalitySchoolIzo, state);
253
+ });
254
+ const addRestOfMunicipalityToUnmappedPoints = (state) => __awaiter(void 0, void 0, void 0, function* () {
255
+ state.currentMunicipality.unmappedPoints = (yield getRestOfMunicipality(state)).map(mapAddressPointForExport);
256
+ });
257
+ const getRestOfMunicipality = (state) => __awaiter(void 0, void 0, void 0, function* () {
247
258
  // get all address points for current municipality
248
- const allPoints = yield findAddressPoints({
259
+ return yield findAddressPoints({
249
260
  type: "wholeMunicipality",
250
261
  municipality: {
251
262
  code: state.currentMunicipality.founder.cityOrDistrictCode,
252
263
  type: state.currentMunicipality.founder.municipalityType,
253
264
  },
254
265
  });
255
- yield addRestToSchool(allPoints, state.rests.wholeMunicipalitySchoolIzo, state);
256
266
  });
257
267
  const addRestOfMunicipalityPart = (state, municipalityPartCode, schoolIzo) => __awaiter(void 0, void 0, void 0, function* () {
258
268
  // get all address points for current municipality
@@ -260,7 +270,7 @@ const addRestOfMunicipalityPart = (state, municipalityPartCode, schoolIzo) => __
260
270
  type: "wholeMunicipalityPart",
261
271
  municipalityPartCode,
262
272
  });
263
- yield addRestToSchool(allPoints, schoolIzo, state);
273
+ addRestToSchool(allPoints, schoolIzo, state);
264
274
  });
265
275
  export const getNewMunicipalityByName = (name) => __awaiter(void 0, void 0, void 0, function* () {
266
276
  const { founder, errors } = yield findFounder(name);
@@ -275,6 +285,7 @@ const getNewMunicipality = (founder, errors) => ({
275
285
  municipalityName: founder ? founder.name : "Neznámá obec",
276
286
  founder,
277
287
  schools: [],
288
+ unmappedPoints: [],
278
289
  },
279
290
  errors,
280
291
  });
@@ -64,6 +64,7 @@ export interface School {
64
64
  export interface Municipality {
65
65
  municipalityName: string;
66
66
  schools: School[];
67
+ unmappedPoints: ExportAddressPoint[];
67
68
  }
68
69
  export interface DbMunicipalityResult {
69
70
  municipality: DbMunicipality;
@@ -76,6 +77,10 @@ export interface MunicipalityPartResult {
76
77
  export interface MunicipalityWithFounder extends Municipality {
77
78
  founder: Founder | null;
78
79
  }
80
+ export interface MunicipalityWithFounderResult {
81
+ municipality: MunicipalityWithFounder;
82
+ errors: SmdError[];
83
+ }
79
84
  export interface SmdState {
80
85
  currentMunicipality: MunicipalityWithFounder;
81
86
  currentFilterMunicipality: DbMunicipality;
@@ -87,6 +92,7 @@ export interface SmdState {
87
92
  schoolIzo: string;
88
93
  }[];
89
94
  wholeMunicipalitySchoolIzo: string;
95
+ includeUnmappedAddressPoints: boolean;
90
96
  };
91
97
  municipalities: Municipality[];
92
98
  }
package/package.json CHANGED
@@ -57,7 +57,7 @@
57
57
  },
58
58
  "name": "text-to-map",
59
59
  "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.",
60
- "version": "1.1.18",
60
+ "version": "1.1.19",
61
61
  "main": "dist/index.js",
62
62
  "types": "dist/index.d.ts",
63
63
  "files": [