diff --git a/__pycache__/managers.cpython-310.pyc b/__pycache__/managers.cpython-310.pyc new file mode 100644 index 0000000..ac61974 Binary files /dev/null and b/__pycache__/managers.cpython-310.pyc differ diff --git a/__pycache__/objects.cpython-310.pyc b/__pycache__/objects.cpython-310.pyc index 3a2d340..0d781e7 100644 Binary files a/__pycache__/objects.cpython-310.pyc and b/__pycache__/objects.cpython-310.pyc differ diff --git a/__pycache__/osm.cpython-310.pyc b/__pycache__/osm.cpython-310.pyc index c64f508..f7ea589 100644 Binary files a/__pycache__/osm.cpython-310.pyc and b/__pycache__/osm.cpython-310.pyc differ diff --git a/main.py b/main.py index 8677107..8412795 100644 --- a/main.py +++ b/main.py @@ -1,8 +1,17 @@ +OFFLINE = True +from managers import ShopManager from osm import OSM -from places import Shops from publicTransport import PublicTransportAccessibility import requests +# ADVANCED: +# Get external data of shops, like website +# Get General City/Region data: average age, peace index, democrazy index, average income + +# IDEAS: +# Parks +# ATMs + # 52.9152386,,15.96z # bhv 53.51500036203292, 8.603602165157444 @@ -23,28 +32,35 @@ maxLat = round(float(lat) + areaHeightRadius, 5) requestUrl = "https://overpass-api.de/api/map" requestsUrlParams = f"?bbox={minLon},{minLat},{maxLon},{maxLat}" -print(requestUrl + requestsUrlParams) -""" # ONLINE -print("Downloading OSM-File...") -# TODO Check if banned from overpass-api MAYBE get alternative API then -r = requests.get(requestUrl + requestsUrlParams, headers={'Content-Type': 'application/xml'}) -print("Done: Downloading OSM-File") -osm = OSM(r.text) -""" -# Offline -print("Using offline file!") -file = open("mapHH", encoding="utf8") -osm = OSM(file.read()) +if OFFLINE: + print("Using offline file!") + file = open("mapHH", encoding="utf8") + osm = OSM(file.read()) +else: + print(requestUrl + requestsUrlParams) + print("Downloading OSM-File...") + # TODO Check if banned from overpass-api MAYBE get alternative API then + r = requests.get(requestUrl + requestsUrlParams, headers={'Content-Type': 'application/xml'}) + print("Done: Downloading OSM-File") + osm = OSM(r.text) pta = PublicTransportAccessibility(osm) -shops = Shops(osm) +shopManager = ShopManager(osm) -print("Bus:" + str(pta.isBusAccessible())) -print("Tram:" + str(pta.isTramAccessible())) -print("Light Rail:" + str(pta.isLightRailAccessible())) -print("Subway:" + str(pta.isSubwayAccessible())) -print("Train:" + str(pta.isTrainAccessible())) -print("Monorail:" + str(pta.isMonorailAccessible())) +print("\n--- Public Transport Accessibility ---") +print("Bus: " + str(pta.isBusAccessible())) +print("Tram: " + str(pta.isTramAccessible())) +print("Light Rail: " + str(pta.isLightRailAccessible())) +print("Subway: " + str(pta.isSubwayAccessible())) +print("Train: " + str(pta.isTrainAccessible())) +print("Monorail: " + str(pta.isMonorailAccessible())) + +print("\n--- 10 Most present shop types ---") +counter = 0 +for s in shopManager.getCountsOfTypes(): + if counter <= 10: + print(s['type'] + " : " + str(s['count']) + " times") + counter = counter + 1 + -print(shops.countOfShopTypes()) diff --git a/managers.py b/managers.py new file mode 100644 index 0000000..6a8931c --- /dev/null +++ b/managers.py @@ -0,0 +1,21 @@ +from operator import itemgetter + +class ShopManager: + def __init__(self, _osm): + self.osm = _osm + + def getCountsOfTypes(self): + countDict = [] + + def isInDict(type): + for a in countDict: + if a['type'] == type: + return True + return False + + if self.osm.shopList: + for shop in self.osm.shopList: + if not isInDict(shop.type): + countDict.append({'type': shop.type, 'count': sum(a.type == shop.type for a in self.osm.shopList)}) + + return sorted(countDict, key=itemgetter('count'), reverse=True) diff --git a/objects.py b/objects.py index 3639210..671b82c 100644 --- a/objects.py +++ b/objects.py @@ -1,3 +1,10 @@ +class Shop: + # TODO More optional details/attributes. Example: "website", "brand", "Telefone", "Owner" + def __init__(self, _nodeIds, _name, _type): + self.nodeIds = _nodeIds + self.name = _name + self.type = _type + class Node: def __init__(self, _id, _lon, _lat, _version, _timestamp, _changeset, _uid, _user): self.id = int(_id) diff --git a/osm.py b/osm.py index d4be465..4465189 100644 --- a/osm.py +++ b/osm.py @@ -1,12 +1,14 @@ -from objects import Node, NodeTag, Way, WayTag +from objects import Node, NodeTag, Way, WayTag, Shop class OSM: + # TODO Average value of "last updated" to see how up to date the data is. def __init__(self, _osmContent): self.osmContent = str(_osmContent) self.nodeList = [] self.nodeTagList = [] self.wayList = [] self.wayTagList = [] + self.shopList = [] self.parseOsmContent() def parseOsmContent(self): @@ -42,8 +44,31 @@ class OSM: wayLines = [] elif len(wayLines) > 0: wayLines.append(line) - - + + def createShop(self, lines): + # TODO Make sure shops are not duplicates. + # TODO e.g. REWE(shop) is big enough to have some "Ways" of it's own and multiple nodes, which can cause duplicates. + + nodeIds = [] + type = "" + name = "" + + for line in lines: + if '