Skip to content
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

update output path for folders #41

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions school_center.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def center_to_dict(c, distance):

def sort_key(c):
# intent: sort by preference score DESC then by distance_km ASC
# leaky abstraction - sorted requires a single numberic value for each element
# leaky abstraction - sorted requires a single numeric value for each element
return c['distance_km'] * random.uniform(1,5) - get_pref(school['scode'], c['cscode'])*100

school_lat = school.get('lat')
Expand All @@ -68,7 +68,7 @@ def sort_key(c):
return []

within_distance = []
nearest_distance = None;
nearest_distance = None
nearest_center = None
for c in centers:
distance = haversine_distance(float(school_lat), float(school_long), float(c.get('lat')), float(c.get('long')))
Expand Down Expand Up @@ -143,6 +143,13 @@ def is_allocated(scode1: str, scode2:str) -> bool:
else:
return False

def update_output_path(filename):
split_path = filename.split("/")
if split_path[-1].endswith(".tsv"):
filename = split_path[-1]
output_dir = "/".join(split_path[:-1]) + "/"
return filename, output_dir

parser = argparse.ArgumentParser(
prog='center randomizer',
description='Assigns centers to exam centers to students')
Expand All @@ -160,9 +167,16 @@ def is_allocated(scode1: str, scode2:str) -> bool:
remaining = 0 # stores count of non allocated students
allocations = {} # to track mutual allocations

if (len(args.output.split("/")) > 1):
file_path, mod_output_dir = update_output_path(args.output)
OUTPUT_DIR += mod_output_dir
output_file_path = OUTPUT_DIR + file_path
else:
output_file_path = OUTPUT_DIR + args.output

create_dir(OUTPUT_DIR) # Create the output directory if not exists
with open('{}school-center-distance.tsv'.format(OUTPUT_DIR), 'w', encoding='utf-8') as intermediate_file, \
open(OUTPUT_DIR + args.output, 'w', encoding='utf-8') as a_file:
open(output_file_path, 'w', encoding='utf-8') as a_file:
writer = csv.writer(intermediate_file, delimiter="\t")
writer.writerow(["scode", "s_count", "school_name", "school_lat", "school_long", "cscode", "center_name", "center_address", "center_capacity", "distance_km"])

Expand Down