|
| 1 | +OUTPUT_DIR = 'results/' |
| 2 | + |
1 | 3 | PREF_DISTANCE_THRESHOLD = 2 # Preferred threshold distance in kilometers
|
2 | 4 | ABS_DISTANCE_THRESHOLD = 7 # Absolute threshold distance in kilometers
|
3 | 5 | MIN_STUDENT_IN_CENTER = 10 # minimum number of students from a school to be assigned to a center in normal circumstances
|
|
8 | 10 | import csv
|
9 | 11 | import random
|
10 | 12 | import argparse
|
| 13 | +import os |
11 | 14 | from typing import Dict, List
|
12 | 15 |
|
13 | 16 |
|
| 17 | +def create_dir(dirPath:str): |
| 18 | + """ |
| 19 | + Create the given directory if it doesn't exists |
| 20 | + - Creates all the directories needed to resolve to the provided directory path |
| 21 | + """ |
| 22 | + if not os.path.exists(dirPath): |
| 23 | + os.makedirs(dirPath) |
| 24 | + |
14 | 25 | def haversine_distance(lat1, lon1, lat2, lon2):
|
15 | 26 | """
|
16 | 27 | Calculate the great circle distance between two points
|
@@ -142,7 +153,9 @@ def is_allocated(scode1: str, scode2:str) -> bool:
|
142 | 153 | remaining = 0 # stores count of non allocated students
|
143 | 154 | allocations = {} # to track mutual allocations
|
144 | 155 |
|
145 |
| -with open('school-center-distance.tsv', 'w') as intermediate_file, open(args.output, 'w') as a_file: |
| 156 | +create_dir(OUTPUT_DIR) # Create the output directory if not exists |
| 157 | +with open('{}school-center-distance.tsv'.format(OUTPUT_DIR), 'w', encoding='utf-8') as intermediate_file, \ |
| 158 | +open(OUTPUT_DIR + args.output, 'w', encoding='utf-8') as a_file: |
146 | 159 | writer = csv.writer(intermediate_file, delimiter="\t")
|
147 | 160 | writer.writerow(["scode", "s_count", "school_name", "school_lat", "school_long", "cscode", "center_name", "center_address", "center_capacity", "distance_km"])
|
148 | 161 |
|
|
0 commit comments