second
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
import math
|
||||
from pathlib import Path
|
||||
import json
|
||||
|
||||
import pandas as pd
|
||||
|
||||
# set year
|
||||
year = json.load(open('year.json', 'r', encoding='utf-8'))['year']
|
||||
filename = f"{year}"
|
||||
|
||||
def haversine(lat1, lon1, lat2, lon2):
|
||||
R = 6371.0 # Earth radius in km
|
||||
@@ -41,8 +45,8 @@ def _infer_coords(df, name_col, lat_col, lon_col):
|
||||
|
||||
|
||||
def main():
|
||||
demand = _read_csv_flexible("data/DemandLocation.csv")
|
||||
factory = _read_csv_flexible("data/FactoryLocation.csv")
|
||||
demand = _read_csv_flexible(f"data/{filename}/DemandLocation.csv")
|
||||
factory = _read_csv_flexible(f"data/{filename}/FactoryLocation.csv")
|
||||
|
||||
# Demand: assume first column name, last two numeric
|
||||
demand_coords = _infer_coords(demand, demand.columns[0], demand.columns[-2], demand.columns[-1])
|
||||
@@ -56,7 +60,7 @@ def main():
|
||||
rows.append({"demand_city": drow["name"], "factory": frow["name"], "distance_km": dist})
|
||||
|
||||
df = pd.DataFrame(rows)
|
||||
out_path = Path("data") / "distance_matrix.csv"
|
||||
out_path = Path("data") / filename / "distance_matrix.csv"
|
||||
df.to_csv(out_path, index=False, encoding="utf-8-sig")
|
||||
print(f"Saved {len(df)} rows to {out_path}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user