-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
119 lines (112 loc) · 4.03 KB
/
main.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
from datetime import datetime
from pathlib import Path
from typing import Set
from jinja2 import (
Environment,
select_autoescape,
FileSystemLoader,
StrictUndefined,
)
from compare.comparator import compareStops
from gtfs.osmGTFSStopsComparer import compareOSMAndGTFSStops, STOP_DISTANCE_THRESHOLD
from osm.OSMRelationAnalyzer import (
analyzeOSMRelations,
osmRefToName,
osmOperatorLinks,
disusedStop,
invalidOperatorVariants,
manyLastStops,
mismatchOSMNameRef,
missingName,
missingRouteUrl,
missingStopRef,
allOSMRefs,
unexpectedLink,
unexpectedNetwork,
unexpectedStopRef,
wtpLinkDuplicates,
)
from warsaw.wtpScraper import (
WTPLink,
wtpSeenLinks,
scrapeHomepage,
wtpMissingLastStop,
wtpMissingLastStopRefNames,
wtpStopRefs,
)
from warsaw.wtpStopMapping import wtpStopMapping
startTime = datetime.now()
def processData():
scrapeHomepage()
osmResults = analyzeOSMRelations()
compareResults = compareStops(osmResults=osmResults)
notLinkedWtpUrls: Set[str] = set()
for link in wtpSeenLinks - osmOperatorLinks:
wtpLinkParams = WTPLink.fromTuple(link)
if wtpLinkParams.line not in ["M1", "M2"]:
notLinkedWtpUrls.add(wtpLinkParams.url())
osmAndGTFSComparisonResult = compareOSMAndGTFSStops()
env = Environment(
loader=FileSystemLoader(searchpath="./templates"),
autoescape=select_autoescape(),
trim_blocks=True,
lstrip_blocks=True,
undefined=StrictUndefined,
)
endTime = datetime.now()
generationSeconds = int((endTime - startTime).total_seconds())
sharedContext = dict(
startTime=startTime.isoformat(timespec="seconds"),
generationSeconds=generationSeconds,
)
with Path("../osm-wtp/index.html").open("w") as f:
template = env.get_template("index.j2")
f.write(
template.render(
refs=compareResults.refs,
renderResults=compareResults.renderResults,
disusedStop=disusedStop,
invalidWtpVariants=invalidOperatorVariants,
wtpManyLastStops=manyLastStops,
wtpMissingLastStop=wtpMissingLastStop,
missingRouteUrl=missingRouteUrl,
notLinkedWtpUrls=sorted(list(notLinkedWtpUrls)),
unexpectedLink=unexpectedLink,
unexpectedNetwork=unexpectedNetwork,
wtpLinkDuplicates=wtpLinkDuplicates,
**sharedContext
)
)
with Path("../osm-wtp/stops.html").open("w") as f:
template = env.get_template("stops.j2")
f.write(
template.render(
farAwayStops=osmAndGTFSComparisonResult.farAwayStops,
stopDistanceThreshold=int(STOP_DISTANCE_THRESHOLD),
notUniqueOSMNames={
ref: names for ref, names in osmRefToName.items() if len(names) > 1
},
notUniqueWTPNames={
ref: names
for ref, names in compareResults.operatorRefToName.items()
if len(names) > 1
},
mismatchOSMNameRef=mismatchOSMNameRef,
missingLastStopRefNames=list(sorted(wtpMissingLastStopRefNames)),
missingName=missingName,
missingStopRef=missingStopRef,
missingRefsInOSM=[
(ref, list(compareResults.operatorRefToName[ref])[0])
for ref in sorted(wtpStopRefs - allOSMRefs)
],
unexpectedStopRef=unexpectedStopRef,
wtpStopMapping=wtpStopMapping,
osmStops=osmAndGTFSComparisonResult.osmStops,
gtfsStops=osmAndGTFSComparisonResult.gtfsStops,
osmStopRefsNotInGTFS=osmAndGTFSComparisonResult.osmStopRefsNotInGTFS,
gtfsStopRefsNotInOSM=osmAndGTFSComparisonResult.gtfsStopRefsNotInOSM,
**sharedContext
)
)
if __name__ == "__main__":
processData()