forked from osm-fr/osmose-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Analyser_Osmosis.py
702 lines (594 loc) · 27.5 KB
/
Analyser_Osmosis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
#-*- coding: utf-8 -*-
###########################################################################
## ##
## Copyrights Frederic Rodrigo 2011 ##
## ##
## This program is free software: you can redistribute it and/or modify ##
## it under the terms of the GNU General Public License as published by ##
## the Free Software Foundation, either version 3 of the License, or ##
## (at your option) any later version. ##
## ##
## This program is distributed in the hope that it will be useful, ##
## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##
## GNU General Public License for more details. ##
## ##
## You should have received a copy of the GNU General Public License ##
## along with this program. If not, see <http://www.gnu.org/licenses/>. ##
## ##
###########################################################################
from .Analyser import Analyser
import os
import psycopg2
import psycopg2.extensions
import re
from modules import DictCursorUnicode
from collections import defaultdict
from inspect import getframeinfo, stack
class Analyser_Osmosis(Analyser):
sql_create_highways = """
CREATE UNLOGGED TABLE {0}.highways AS
SELECT
id,
nodes,
tags,
tags->'highway' AS highway,
linestring,
ST_Transform(linestring, {1}) AS linestring_proj,
is_polygon,
tags->'highway' LIKE '%_link' AS is_link,
(tags?'junction' AND tags->'junction' = 'roundabout') AS is_roundabout,
(tags?'oneway' AND tags->'oneway' IN ('yes', 'true', '1', '-1')) AS is_oneway,
(tags?'area' AND tags->'area' != 'no') AS is_area,
tags->'highway' IN ('planned', 'proposed', 'construction') AS is_construction,
CASE tags->'highway'
WHEN 'motorway' THEN 1
WHEN 'primary' THEN 1
WHEN 'trunk' THEN 1
WHEN 'motorway_link' THEN 2
WHEN 'primary_link' THEN 2
WHEN 'trunk_link' THEN 2
WHEN 'secondary' THEN 2
WHEN 'secondary_link' THEN 2
WHEN 'tertiary' THEN 3
WHEN 'tertiary_link' THEN 3
WHEN 'unclassified' THEN 4
WHEN 'unclassified_link' THEN 4
WHEN 'residential' THEN 4
WHEN 'residential_link' THEN 4
WHEN 'living_street' THEN 5
WHEN 'track' THEN 5
WHEN 'cycleway' THEN 5
WHEN 'service' THEN 5
WHEN 'road' THEN 5
ELSE NULL
END AS level
FROM
ways
WHERE
tags != ''::hstore AND
tags?'highway' AND
tags->'highway' NOT IN ('services', 'rest_area', 'razed', 'no') AND
ST_NPoints(linestring) >= 2
;
CREATE INDEX idx_highways_linestring ON {0}.highways USING gist(linestring);
CREATE INDEX idx_highways_linestring_proj ON {0}.highways USING gist(linestring_proj);
CREATE INDEX idx_highways_id ON {0}.highways(id);
CREATE INDEX idx_highways_highway ON {0}.highways(highway);
ANALYZE {0}.highways;
"""
sql_create_highway_ends = """
CREATE UNLOGGED TABLE {0}.highway_ends AS
SELECT
id,
nodes,
linestring,
highway,
is_link,
is_roundabout,
(ends_geom(nodes, linestring)).id AS nid,
(ends_geom(nodes, linestring)).geom AS geom,
level
FROM
highways
WHERE
NOT is_area AND
NOT is_construction
;
ANALYZE {0}.highway_ends;
"""
sql_create_buildings = """
CREATE UNLOGGED TABLE {0}.buildings AS
SELECT
*,
CASE WHEN polygon_proj IS NOT NULL AND wall THEN ST_Area(polygon_proj) ELSE NULL END AS area
FROM (
SELECT DISTINCT ON (id)
id,
tags,
linestring,
CASE WHEN ST_IsValid(linestring) = 't' AND ST_IsSimple(linestring) = 't' AND ST_IsValid(ST_MakePolygon(ST_Transform(linestring, {1}))) THEN ST_MakePolygon(ST_Transform(linestring, {1})) ELSE NULL END AS polygon_proj,
(NOT tags?'wall' OR tags->'wall' != 'no') AND tags->'building' != 'roof' AS wall,
tags?'layer' AS layer,
ST_NPoints(linestring) AS npoints,
relation_members.relation_id IS NOT NULL AS relation
FROM
ways
LEFT JOIN relation_members ON
relation_members.member_type = 'W' AND
relation_members.member_id = ways.id
WHERE
tags != ''::hstore AND
tags?'building' AND
tags->'building' != 'no' AND
is_polygon
) AS t
;
CREATE INDEX idx_buildings_linestring ON {0}.buildings USING GIST(linestring);
CREATE INDEX idx_buildings_linestring_wall ON {0}.buildings USING GIST(linestring) WHERE wall;
ANALYZE {0}.buildings;
"""
def __init__(self, config, logger = None):
Analyser.__init__(self, config, logger)
self.classs = {}
self.classs_change = {}
self.explain_sql = False
self.FixTypeTable = {
self.node:"node", self.node_full:"node", self.node_new:"node", self.node_position:"node",
self.way:"way", self.way_full:"way",
self.relation:"relation", self.relation_full:"relation",
}
self.typeMapping = {'N': self.node_full, 'W': self.way_full, 'R': self.relation_full}
self.resume_from_timestamp = None
self.already_issued_objects = None
if hasattr(config, "verbose") and config.verbose:
self.explain_sql = True
def __enter__(self):
Analyser.__enter__(self)
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY)
# open database connections + output file
self.apiconn = self.config.osmosis_manager.osmosis()
self.gisconn = self.apiconn.conn()
self.giscurs = self.gisconn.cursor(cursor_factory=DictCursorUnicode.DictCursorUnicode50)
return self
def __exit__(self, exc_type, exc_value, traceback):
# close database connections + output file
self.config.osmosis_manager.osmosis_close()
Analyser.__exit__(self, exc_type, exc_value, traceback)
def timestamp(self):
return self.apiconn.timestamp()
def analyser(self):
self.init_analyser()
if self.classs != {} or self.classs_change != {}:
self.logger.log(u"run osmosis all analyser %s" % self.__class__.__name__)
self.error_file.analyser(self.timestamp(), self.analyser_version())
if hasattr(self, 'requires_tables_common'):
self.requires_tables_build(self.requires_tables_common)
if hasattr(self, 'requires_tables_full'):
self.requires_tables_build(self.requires_tables_full)
self.dump_class(self.classs)
self.dump_class(self.classs_change)
try:
self.analyser_osmosis_common()
self.analyser_osmosis_full()
finally:
self.error_file.analyser_end()
def analyser_deferred_clean(self):
if hasattr(self, 'requires_tables_common'):
self.requires_tables_clean(self.requires_tables_common)
if hasattr(self, 'requires_tables_full'):
self.requires_tables_clean(self.requires_tables_full)
def analyser_change(self):
self.init_analyser()
if self.classs != {}:
self.logger.log(u"run osmosis base analyser %s" % self.__class__.__name__)
self.error_file.analyser(self.timestamp(), self.analyser_version())
if hasattr(self, 'requires_tables_common'):
self.requires_tables_build(self.requires_tables_common)
self.dump_class(self.classs)
try:
self.analyser_osmosis_common()
finally:
self.error_file.analyser_end()
if self.classs_change != {}:
self.logger.log(u"run osmosis touched analyser %s" % self.__class__.__name__)
self.error_file.analyser(self.timestamp(), self.analyser_version(), change=True)
try:
if hasattr(self, 'requires_tables_diff'):
self.requires_tables_build(self.requires_tables_diff)
self.dump_class(self.classs_change)
self.dump_delete()
self.analyser_osmosis_diff()
finally:
self.error_file.analyser_end()
def analyser_change_deferred_clean(self):
if self.classs != {}:
if hasattr(self, 'requires_tables_common'):
self.requires_tables_clean(self.requires_tables_common)
if self.classs_change != {}:
if hasattr(self, 'requires_tables_diff'):
self.requires_tables_clean(self.requires_tables_diff)
def analyser_resume(self, timestamp, already_issued_objects):
if not self.resume_from_timestamp or self.resume_from_timestamp != timestamp:
self.db_setup_resume_from_timestamp(timestamp)
self.resume_from_timestamp = timestamp
self.already_issued_objects = already_issued_objects
self.analyser_change()
def analyser_resume_deferred_clean(self):
self.analyser_change_deferred_clean()
def requires_tables_build(self, tables):
for table in tables:
self.giscurs.execute("SELECT 1 FROM pg_tables WHERE schemaname = '{0}' AND tablename = '{1}'".format(self.config.db_schema.split(',')[0], table))
if not self.giscurs.fetchone():
self.logger.log(u"requires table {0}".format(table))
if table == 'highways':
self.giscurs.execute(self.sql_create_highways.format(self.config.db_schema.split(',')[0], self.config.options.get("proj")))
elif table == 'touched_highways':
self.requires_tables_build(["highways"])
self.create_view_touched('highways', 'W')
elif table == 'not_touched_highways':
self.requires_tables_build(["highways"])
self.create_view_not_touched('highways', 'W')
elif table == 'highway_ends':
self.requires_tables_build(["highways"])
self.giscurs.execute(self.sql_create_highway_ends.format(self.config.db_schema.split(',')[0]))
elif table == 'touched_highway_ends':
self.requires_tables_build(["highway_ends"])
self.create_view_touched('highway_ends', 'W')
elif table == 'buildings':
self.giscurs.execute(self.sql_create_buildings.format(self.config.db_schema.split(',')[0], self.config.options.get("proj")))
elif table == 'touched_buildings':
self.requires_tables_build(["buildings"])
self.create_view_touched('buildings', 'W')
elif table == 'not_touched_buildings':
self.requires_tables_build(["buildings"])
self.create_view_not_touched('buildings', 'W')
else:
raise Exception('Unknow table name %s' % (table, ))
self.giscurs.execute('COMMIT')
self.giscurs.execute('BEGIN')
def requires_tables_clean(self, tables):
for table in tables:
self.logger.log(u"requires table clean {0}".format(table))
self.giscurs.execute('DROP TABLE IF EXISTS {0}.{1} CASCADE'.format(self.config.db_schema.split(',')[0], table))
self.giscurs.execute('COMMIT')
self.giscurs.execute('BEGIN')
def db_setup_resume_from_timestamp(self, timestamp):
self.giscurs.execute("SELECT tstamp_action FROM metainfo")
tstamp_action = self.giscurs.fetchone()[0]
if tstamp_action != timestamp:
self.logger.log("osmosis resume post scripts")
osmosis_resume_post_scripts = [ # Scripts to run each time the database is updated
"/osmosis/ActionFromTimestamp.sql",
"/osmosis/CreateTouched.sql",
]
for script in osmosis_resume_post_scripts: #self.config.analyser_conf.osmosis_resume_post_scripts:
self.giscurs.execute(open('./' + script, 'r').read().replace(':timestamp', timestamp))
self.giscurs.execute('COMMIT')
self.giscurs.execute('BEGIN')
def init_analyser(self):
if len(set(self.classs.keys()) & set(self.classs_change.keys())) > 0:
self.logger.log(u"Warning: duplicate class in %s" % self.__class__.__name__)
self.giscurs.execute("SET search_path TO %s,public;" % (self.config.db_schema_path or self.config.db_schema))
def dump_class(self, classs):
for id_ in classs:
data = classs[id_]
self.error_file.classs(
id = id_,
item = data['item'],
level = data['level'],
tags = data.get('tags'),
title = data.get('title'),
detail = data.get('detail'),
fix = data.get('fix'),
trap = data.get('trap'),
example = data.get('example'),
source = data.get('source'),
resource = data.get('resource'),
)
def analyser_osmosis_common(self):
"""
Run check not supporting diff mode.
"""
pass
def analyser_osmosis_full(self):
"""
Run check supporting diff mode. Full data check.
Alternative method of analyser_osmosis_diff().
"""
pass
def analyser_osmosis_diff(self):
"""
Run check supporting diff mode. Checks only on data changed from last run.
Alternative method of analyser_osmosis_full().
"""
pass
def dump_delete(self):
if self.already_issued_objects:
# Resume
types = {'N': 'node', 'W': 'way', 'R': 'relation'}
for t, ids in self.already_issued_objects.items():
if ids:
sql = "SELECT v.id, l.id FROM (VALUES ({0})) AS v(id) LEFT JOIN {1}s AS l ON v.id = l.id WHERE l.id IS NULL;".format('),('.join(map(str, ids)), types[t])
self.giscurs.execute(sql)
for res in self.giscurs.fetchall():
self.error_file.delete(types[t], res[0])
else:
# Change
for t in ["node", "way", "relation"]:
sql = "(SELECT id FROM actions WHERE data_type='{0}' AND action='D') UNION ALL (SELECT id FROM touched_{1}s) EXCEPT (SELECT id FROM actions WHERE data_type='{0}' AND action='C')".format(t[0].upper(), t)
self.giscurs.execute(sql)
for res in self.giscurs.fetchall():
self.error_file.delete(t, res[0])
def create_view_touched(self, table, type, id = 'id'):
"""
@param type in 'N', 'W', 'R'
"""
sql = """
CREATE OR REPLACE TEMPORARY VIEW touched_{0} AS
SELECT
{0}.*
FROM
{0}
JOIN transitive_touched ON
transitive_touched.data_type = '{1}' AND
{0}.{2} = transitive_touched.id
"""
self.giscurs.execute(sql.format(table, type, id))
def create_view_not_touched(self, table, type, id = 'id'):
"""
@param type in 'N', 'W', 'R'
"""
sql = """
CREATE OR REPLACE TEMPORARY VIEW not_touched_{0} AS
SELECT
{0}.*
FROM
{0}
LEFT JOIN transitive_touched ON
transitive_touched.data_type = '{1}' AND
{0}.{2} = transitive_touched.id
WHERE
transitive_touched.id IS NULL
"""
self.giscurs.execute(sql.format(table, type, id))
def run00(self, sql, callback = None):
if self.explain_sql:
self.logger.log(sql.strip())
if self.explain_sql and (sql.strip().startswith("SELECT") or sql.strip().startswith("CREATE UNLOGGED TABLE")) and not ';' in sql[:-1] and " AS " in sql:
sql_explain = "EXPLAIN " + sql.split(";")[0]
self.giscurs.execute(sql_explain)
for res in self.giscurs.fetchall():
self.logger.log(res[0])
try:
self.giscurs.execute(sql)
except:
self.logger.err(u"sql=%s" % sql)
raise
if callback:
while True:
many = self.giscurs.fetchmany(1000)
if not many:
break
for res in many:
ret = None
try:
ret = callback(res)
except:
self.logger.err("res=%s" % str(res))
self.logger.err("ret=%s" % str(ret))
raise
def run0(self, sql, callback = None):
caller = getframeinfo(stack()[1][0])
self.logger.log(u"%s:%d sql" % (os.path.basename(caller.filename), caller.lineno))
self.run00(sql, callback)
def run(self, sql, callback = None):
def callback_package(res):
ret = callback(res)
if ret and ret.__class__ == dict:
if "self" in ret:
res = ret["self"](res)
if "data" in ret:
self.geom = defaultdict(list)
for (i, d) in enumerate(ret["data"]):
if d is not None:
d(res[i])
ret["fixType"] = list(map(lambda datai: self.FixTypeTable[datai] if datai is not None and datai in self.FixTypeTable else None, ret["data"]))
self.error_file.error(
ret["class"],
ret.get("subclass"),
ret.get("text"),
res,
ret.get("fixType"),
ret.get("fix"),
self.geom)
caller = getframeinfo(stack()[1][0])
if callback:
self.logger.log(u"%s:%d xml generation" % (os.path.basename(caller.filename), caller.lineno))
self.run00(sql, callback_package)
else:
self.logger.log(u"%s:%d sql" % (os.path.basename(caller.filename), caller.lineno))
self.run00(sql)
def node(self, res):
self.geom["node"].append({"id":res, "tag":{}})
def node_full(self, res):
self.geom["node"].append(self.apiconn.NodeGet(res))
def node_position(self, res):
node = self.apiconn.NodeGet(res)
if node:
self.geom["position"].append({'lat': str(node['lat']), 'lon': str(node['lon'])})
def node_new(self, res):
pass
def way(self, res):
self.geom["way"].append({"id":res, "nd":[], "tag":{}})
def way_full(self, res):
self.geom["way"].append(self.apiconn.WayGet(res))
def relation(self, res):
self.geom["relation"].append({"id":res, "member":[], "tag":{}})
def relation_full(self, res):
self.geom["relation"].append(self.apiconn.RelationGet(res))
def any_full(self, res):
self.typeMapping[res[0]](int(res[1:]))
def array_full(self, res):
for type, id in map(lambda r: (r[0], r[1:]), res):
self.typeMapping[type](int(id))
re_points = re.compile(r"[\(,][^\(,\)]*[\),]")
def get_points(self, text):
pts = []
for r in self.re_points.findall(text):
lon, lat = r[1:-1].split(" ")
pts.append({"lat":lat, "lon":lon})
return pts
def positionAsText(self, res):
if res is None:
self.logger.err("NULL location provided")
return []
for loc in self.get_points(res):
self.geom["position"].append(loc)
# def positionWay(self, res):
# self.geom["position"].append()
# def positionRelation(self, res):
# self.geom["position"].append()
###########################################################################
from .Analyser import TestAnalyser
class TestAnalyserOsmosis(TestAnalyser):
@classmethod
def teardown_class(cls):
cls.clean()
@classmethod
def load_osm(cls, osm_file, dst, analyser_options=None, skip_db=False):
import modules.OsmOsisManager
(conf, analyser_conf) = cls.init_config(osm_file, dst, analyser_options)
if not skip_db:
import pytest
osmosis_manager = modules.OsmOsisManager.OsmOsisManager(conf, conf.db_host, conf.db_user, conf.db_password, conf.db_base, conf.db_schema or conf.country, conf.db_persistent, cls.logger)
if not osmosis_manager.check_database():
pytest.skip("database not present")
osmosis_manager.init_database(conf)
# create directory for results
import os
for i in ["normal", "diff_empty", "diff_full"]:
dirname = os.path.join(os.path.dirname(dst), i)
try:
os.makedirs(dirname)
except OSError:
if os.path.isdir(dirname):
pass
else:
raise
cls.conf = conf
cls.xml_res_file = dst
analyser_conf.osmosis_manager = osmosis_manager
analyser_conf.db_schema = conf.db_schema
analyser_conf.db_schema_path = conf.db_schema_path
return analyser_conf
@classmethod
def clean(cls):
# clean database
import modules.OsmOsisManager
osmosis_manager = modules.OsmOsisManager.OsmOsisManager(cls.conf, cls.conf.db_host, cls.conf.db_user, cls.conf.db_password, cls.conf.db_base, cls.conf.db_schema or cls.conf.country, cls.conf.db_persistent, cls.logger)
osmosis_manager.clean_database(cls.conf, False)
# clean results file
import os
try:
os.remove(cls.xml_res_file)
except OSError:
pass
class Test(TestAnalyserOsmosis):
from modules import config
default_xml_res_path = config.dir_tmp + "/tests/osmosis/"
@classmethod
def setup_class(cls):
TestAnalyserOsmosis.setup_class()
cls.analyser_conf = cls.load_osm("tests/osmosis.test.osm",
cls.default_xml_res_path + "osmosis.test.xml",
{"test": True,
"addr:city-admin_level": "8,9",
"driving_side": "left",
"proj": 2969})
import modules.OsmOsisManager
cls.conf.osmosis_manager = modules.OsmOsisManager.OsmOsisManager(cls.conf, cls.conf.db_host, cls.conf.db_user, cls.conf.db_password, cls.conf.db_base, cls.conf.db_schema or cls.conf.country, cls.conf.db_persistent, cls.logger)
def test(self):
# run all available osmosis analysers, for basic SQL check
import importlib, inspect, os, sys
for fn in os.listdir("analysers/"):
if not fn.startswith("analyser_osmosis_") or not fn.endswith(".py"):
continue
analyser = importlib.import_module("analysers." + fn[:-3], package=".")
for name, obj in inspect.getmembers(analyser):
if (inspect.isclass(obj) and obj.__module__ == ("analysers." + fn[:-3]) and
(name.startswith("Analyser") or name.startswith("analyser"))):
self.analyser_conf.dst = (self.default_xml_res_path +
"normal/%s.xml" % name)
self.xml_res_file = self.analyser_conf.dst
with obj(self.analyser_conf, self.logger) as analyser_obj:
analyser_obj.analyser()
self.root_err = self.load_errors()
self.check_num_err(min=0, max=5)
def test_change_empty(self):
# run all available osmosis analysers, for basic SQL check
import importlib, inspect, os, sys
self.conf.osmosis_manager.set_pgsql_schema()
for script in self.conf.osmosis_change_init_post_scripts:
self.conf.osmosis_manager.psql_f(script)
self.conf.osmosis_manager.psql_c("TRUNCATE TABLE actions")
for script in self.conf.osmosis_change_post_scripts:
self.conf.osmosis_manager.psql_f(script)
for fn in os.listdir("analysers/"):
if not fn.startswith("analyser_osmosis_") or not fn.endswith(".py"):
continue
analyser = importlib.import_module("analysers." + fn[:-3], package=".")
for name, obj in inspect.getmembers(analyser):
if (inspect.isclass(obj) and obj.__module__ == ("analysers." + fn[:-3]) and
(name.startswith("Analyser") or name.startswith("analyser"))):
self.analyser_conf.dst = (self.default_xml_res_path +
"diff_empty/%s.xml" % name)
self.xml_res_file = self.analyser_conf.dst
with obj(self.analyser_conf, self.logger) as analyser_obj:
analyser_obj.analyser_change()
self.root_err = self.load_errors()
self.check_num_err(min=0, max=5)
def test_change_full(self):
# run all available osmosis analysers, after marking all elements as new
import importlib, inspect, os, sys
self.conf.osmosis_manager.set_pgsql_schema()
for script in self.conf.osmosis_change_init_post_scripts:
self.conf.osmosis_manager.psql_f(script)
self.conf.osmosis_manager.psql_c("TRUNCATE TABLE actions;"
"INSERT INTO actions (SELECT 'R', 'C', id FROM relations);"
"INSERT INTO actions (SELECT 'W', 'C', id FROM ways);"
"INSERT INTO actions (SELECT 'N', 'C', id FROM nodes);")
for script in self.conf.osmosis_change_post_scripts:
self.conf.osmosis_manager.psql_f(script)
for fn in os.listdir("analysers/"):
if not fn.startswith("analyser_osmosis_") or not fn.endswith(".py"):
continue
analyser = importlib.import_module("analysers." + fn[:-3], package=".")
for name, obj in inspect.getmembers(analyser):
if (inspect.isclass(obj) and obj.__module__ == ("analysers." + fn[:-3]) and
(name.startswith("Analyser") or name.startswith("analyser"))):
self.analyser_conf.dst = (self.default_xml_res_path +
"diff_full/%s.xml" % name)
self.xml_res_file = self.analyser_conf.dst
with obj(self.analyser_conf, self.logger) as analyser_obj:
analyser_obj.analyser_change()
self.root_err = self.load_errors()
self.check_num_err(min=0, max=5)
def test_cmp_normal_change(self):
# compare results between normal and change_full
# must be run after both test() and test_change_full()
import importlib, inspect, os, sys
for fn in os.listdir("analysers/"):
if not fn.startswith("analyser_osmosis_") or not fn.endswith(".py"):
continue
analyser = importlib.import_module("analysers." + fn[:-3], package=".")
for name, obj in inspect.getmembers(analyser):
if (inspect.isclass(obj) and obj.__module__ == ("analysers." + fn[:-3]) and
(name.startswith("Analyser") or name.startswith("analyser"))):
normal_xml = (self.default_xml_res_path +
"normal/%s.xml" % name)
change_xml = (self.default_xml_res_path +
"diff_full/%s.xml" % name)
print(normal_xml, change_xml)
self.compare_results(normal_xml, change_xml, convert_checked_to_normal=True)