-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Tyr Worker] Process poi and push to asgard s3 #4212
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import argparse | ||
import csv | ||
import json | ||
import logging | ||
|
||
|
||
def poi_to_excluded_zones(poi_file, output_dir, instance_name): | ||
tmp_path = "tmp/poi_{}".format(instance_name) | ||
import zipfile | ||
|
||
with zipfile.ZipFile(poi_file, 'r') as zip_ref: | ||
zip_ref.extractall(tmp_path) | ||
|
||
excluded_zones = {} | ||
excluded_geometries_ids = {} | ||
|
||
# get excluded zones | ||
with open(tmp_path + "/poi_properties.txt") as csvfile: | ||
reader = csv.reader(csvfile, delimiter=';', quotechar='"') | ||
for row in reader: | ||
if row[1].lower() != "excluded_zones": | ||
continue | ||
excluded_zones[row[0]] = json.loads(row[2]) | ||
|
||
# find geometry id | ||
with open(tmp_path + "/poi.txt") as csvfile: | ||
reader = csv.reader(csvfile, delimiter=';', quotechar='"') | ||
for row in reader: | ||
if row[0] not in excluded_zones: | ||
continue | ||
excluded_geometries_ids[row[0]] = row[7] | ||
|
||
if excluded_geometries_ids.keys() != excluded_zones.keys(): | ||
logger.error("not all excluded zone's pois are found in poi.txt") | ||
logger.error("excluded_geometries_ids: {}".format(excluded_geometries_ids.keys())) | ||
logger.error("excluded_zones: {}".format(excluded_zones.keys())) | ||
|
||
# read geometries | ||
geometries_shapes = {} | ||
with open(tmp_path + "/geometries.txt") as csvfile: | ||
reader = csv.reader(csvfile, delimiter=';', quotechar='"') | ||
for row in reader: | ||
geometries_shapes[row[0]] = row[1] | ||
|
||
for poi_id, zones in excluded_zones.items(): | ||
geometry_id = excluded_geometries_ids.get(poi_id) | ||
if not geometry_id: | ||
logger.error("{} could not be found in poi.txt".format(row[0])) | ||
shape = geometries_shapes.get(geometry_id) | ||
if not shape: | ||
logger.error("{} could not be found in geometries.txt".format(geometry_id)) | ||
|
||
for i, zone in enumerate(zones): | ||
output_id = "{}_{}_{}".format(poi_id, i, instance_name) | ||
output = {'id': output_id} | ||
output.update(zone) | ||
Comment on lines
+53
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can have a poi with several zones but all with the same shape ? 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeahhhhh, I admit that this was not well thought through... the need is for a given shape, we wish it could be excluded based on a list of modes and a list of ranges of date, so the ideal format in my opinion is {
"name": "poi:toto",
"shape": "POLYGON ((...))",
"excluded_on": [
{
"modes": [
"walking",
"bike"
],
"periods": [
{
"from": "20240708",
"to": "20240709"
},
{
"from": "202407010",
"to": "20240711"
}
]
},
{
"modes": [
"car"
],
"periods": [
{
"from": "202407010",
"to": "202407011"
}
]
}
]
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah ok ! you have the same shape but for different modes, or different activation periods, did I get it right ? |
||
output["shape"] = shape | ||
with open(output_dir + "/{}.json".format(output_id), "w") as output_file: | ||
json.dump(output, output_file) | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--poi', help='poi zip') | ||
args = parser.parse_args() | ||
logger = logging.getLogger(__name__) | ||
|
||
poi_to_excluded_zones(args.poi, "excluded_zones", "dummy_instance") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even though it's corrected here: https://github.com/hove-io/navitia/pull/4212/files#diff-9677996dffe09856de00ff00f281b66e799a3187047cbb83bf62efe46d434186R30, I still have to put the env var here and I have absolutely no idea why... otherwise the
aws sync
wouldn't work...