{ "packages": ["pandas", "networkx"], "packages_cache": "passthrough", "files": { "/Data/routes/MetroDatabase.xlsm": "./MetroDatabase.xlsm" } } import networkx as nx import json import math def dict_to_list(obj): if isinstance(obj, dict): result = [] for k, v in obj.items(): result.append([k, dict_to_list(v)]) return result elif isinstance(obj, list): return [dict_to_list(v) for v in obj] else: return obj async def init(): import pyodide_js await pyodide_js.loadPackage("micropip") import micropip await micropip.install("openpyxl") import pandas as pd # Load Excel workbook database = pd.ExcelFile('./MetroDatabase.xlsm') # Initialize Stations Dictionary stations = {} stationsData = pd.read_excel(database, sheet_name="Station") stationsData['Line'] = stationsData['Line'].ffill(axis=0) stationsData = stationsData.groupby(['Line'], sort=False) lineList = list(stationsData.groups.keys()) # Process each line for line in lineList: stations[line] = {} lineData = stationsData.get_group((line,)).copy() lineData.drop('Line', axis=1, inplace=True) lineData.set_index('Code', inplace=True) for station in lineData.index: stationName = ( f"{station} āļŠāļ–āļēāļ™āļĩ{lineData.loc[station, 'Thai']} " f"- {lineData.loc[station, 'Eng']} Station" ) stations[line][station] = stationName # Initialize Interchange Dictionary interchange = {} interchangeData = pd.read_excel( database, sheet_name="Interchange" ) interchangeDict = interchangeData.transpose().to_dict() # Process each pair for pair in interchangeDict.values(): interchange[pair['From Station']] = pair['To Station'] discount = {} for pair in interchangeDict.values(): discount[f"{pair['From Line']}-{pair['To Line']}"] = { "Adult": pair['Adult'], "Student": pair['Student'], "Child": pair['Child'], "Senior (Elder)": pair['Senior (Elder)'] } # Initialize Prices Dictionary prices = {} # Process Pricing Data for line in stations: prices[line] = {} lineData = pd.read_excel(database, sheet_name=f"{line}Price") lineData['Type'] = lineData['Type'].ffill(axis=0) lineData = lineData.groupby(['Type']) for pay in lineData.groups.keys(): prices[line][pay] = {} payData = lineData.get_group((pay,)).copy() payData.drop(['Type'], axis=1, inplace=True) payData.set_index('Station', inplace=True) payData.columns = payData.iloc[0] payData = payData.iloc[1:] payData.dropna(axis='columns', how='all', inplace=True) payData.dropna(axis='index', how='all', inplace=True) prices[line][pay] = payData.to_dict() data_json = json.dumps([ dict_to_list(stations), dict_to_list(interchange), dict_to_list(discount), dict_to_list(prices), stations, interchange, discount, prices ], ensure_ascii=False) return data_json # Helpers def find_key_in_nested_dict(ndict, target): if isinstance(ndict, dict): for key, value in ndict.items(): if key == target or value == target: return key elif isinstance(value, dict): result = find_key_in_nested_dict(value, target) if result is not None: return key elif isinstance(value, list): for elem in value: if elem == target: return key elif isinstance(elem, dict): result = find_key_in_nested_dict(elem, target) if result is not None: return key return None def clean_inf(obj): if isinstance(obj, float) and math.isinf(obj): return None elif isinstance(obj, list): return [clean_inf(x) for x in obj] elif isinstance(obj, dict): return {k: clean_inf(v) for k, v in obj.items()} return obj def find_paths_with_weight(graph, start, end, target_weight): all_paths = nx.all_simple_paths(graph, source=start, target=end) matching_paths = [] for path in all_paths: weight = sum(graph[u][v]['weight'] for u, v in zip(path[:-1], path[1:])) if weight == target_weight: matching_paths.append(path) return matching_paths # Calculate def calculate(data_str, origin, destination): data_json = json.loads(str(data_str)) stations = data_json[4] interchange = data_json[5] discount = data_json[6] prices = data_json[7] G = nx.DiGraph() def add_bidirectional_edges(prefix, first, last): for i in range(first, last): j = i + 1 if 9 >= i >=0: i = f'0{str(i)}' if 9 >= j >=0: j = f'0{str(j)}' G.add_edge(f'{prefix}{i}', f'{prefix}{j}', weight=0) G.add_edge(f'{prefix}{j}', f'{prefix}{i}', weight=0) def set_group_attribute(prefix, first, last, line_name): for i in range(first, last + 1): if 9 >= i >= 0: i = f'0{str(i)}' G.nodes[f'{prefix}{i}']['line'] = line_name # Blue Line add_bidirectional_edges('BL', 1, 38) G.add_edge('BL32', 'BL01', weight=0) G.add_edge('BL01', 'BL32', weight=0) set_group_attribute('BL', 1, 38, 'Blue') # Purple Line add_bidirectional_edges('PP', 1, 16) set_group_attribute('PP', 1, 16, 'Purple') # Yellow Line add_bidirectional_edges('YL', 1, 23) set_group_attribute('YL', 1, 23, 'Yellow') # Pink Line add_bidirectional_edges('PK', 1, 30) add_bidirectional_edges('MT', 1, 2) G.add_edge('MT01', 'PK10', weight=0) G.add_edge('PK10', 'MT01', weight=0) set_group_attribute('PK', 1, 30, 'Pink') set_group_attribute('MT', 1, 2, 'Pink') # Green Line add_bidirectional_edges('N', 1, 24) G.add_edge('N01', 'CEN', weight=0) G.add_edge('CEN', 'N01', weight=0) add_bidirectional_edges('E', 1, 23) G.add_edge('E01', 'CEN', weight=0) G.add_edge('CEN', 'E01', weight=0) add_bidirectional_edges('S', 1, 12) G.add_edge('S01', 'CEN', weight=0) G.add_edge('CEN', 'S01', weight=0) G.add_edge('W01', 'CEN', weight=0) G.add_edge('CEN', 'W01', weight=0) set_group_attribute('N', 1, 24, 'Green') set_group_attribute('E', 1, 23, 'Green') set_group_attribute('S', 1, 12, 'Green') set_group_attribute('W', 1, 1, 'Green') G.nodes['CEN']['line'] = 'Green' # Gold Line add_bidirectional_edges('G', 1, 3) set_group_attribute('G', 1, 3, 'Gold') # Red Line add_bidirectional_edges('RN', 2, 10) G.add_edge('RW01-RN01', 'RN02', weight=0) G.add_edge('RN02', 'RW01-RN01', weight=0) add_bidirectional_edges('RW', 2, 6) G.add_edge('RW01-RN01', 'RW02', weight=0) G.add_edge('RW02', 'RW01-RN01', weight=0) set_group_attribute('RN', 2, 10, 'Red') set_group_attribute('RW', 2, 6, 'Red') G.nodes['RW01-RN01']['line'] = 'Red' # ARL Line add_bidirectional_edges('A', 1, 8) set_group_attribute('A', 1, 8, 'ARL') # BRT Line add_bidirectional_edges('B', 1, 3) G.add_edge('B03', 'B03A', weight=0) G.add_edge('B03A', 'B03', weight=0) G.add_edge('B03A', 'B04', weight=0) G.add_edge('B04', 'B03A', weight=0) G.add_edge('B04', 'B04A', weight=0) G.add_edge('B04A', 'B04', weight=0) G.add_edge('B04A', 'B05', weight=0) G.add_edge('B05', 'B04A', weight=0) add_bidirectional_edges('B', 5, 12) set_group_attribute('B', 1, 12, 'BRT') G.nodes['B03A']['line'] = 'BRT' G.nodes['B04A']['line'] = 'BRT' # Cross Between Line for station in interchange: G.add_edge(station, interchange[station], weight=1) G.add_edge( interchange[station], station, weight=1) code_list = [code for line in stations.values() for code in line.keys()] best_path_1 = [] best_path_2 = [] best_path_3 = [] best_price = float('inf') best_station = float('inf') best_interchange = float('inf') if origin in code_list and destination in code_list: shortest_path = nx.dijkstra_path(G, origin, destination, weight='weight') shortest_length = nx.dijkstra_path_length(G, origin, destination, weight='weight') all_paths = find_paths_with_weight(G, origin, destination, shortest_length) calculated_path = [] for path in all_paths: path_line = {} sum_price = {'Adult': 0, 'Student': 0, 'Child': 0, 'Senior (Elder)': 0} station_count = -1 for station in path: if find_key_in_nested_dict(stations, station) not in path_line: path_line.update({find_key_in_nested_dict(stations, station) : []}) path_line[find_key_in_nested_dict(stations, station)].append(station) station_count += 1 for line in path_line: start = path_line[line][0] end = path_line[line][-1] Adult = int(prices[line]['Adult'][start][end]) Student = int(prices[line]['Student'][start][end]) Child = int(prices[line]['Child'][start][end]) Senior = int(prices[line]['Senior\n(Elder)'][start][end]) sum_price['Adult'] += Adult sum_price['Student'] += Student sum_price['Child'] += Child sum_price['Senior (Elder)'] += Senior # Calculate transfer discounts line_order = list(path_line.keys()) for i in range(len(line_order) - 1): from_line = line_order[i] to_line = line_order[i + 1] discount_key = f"{from_line}-{to_line}" discount_data = discount.get(discount_key, {}) for passenger in sum_price: sum_price[passenger] -= discount_data.get(passenger, 0) # Prevent negative fares for passenger in sum_price: sum_price[passenger] = max(0, sum_price[passenger]) final_path = {} for line in path_line: if line == "Blue": test = True for i in range(0, len(path_line[line])-1): if (path_line[line][i] == "BL32" and path_line[line][i+1] == "BL01") or (path_line[line][i] == "BL01" and path_line[line][i+1] == "BL32"): final_path["Blue1"] = path_line[line][:i+2] final_path["Blue2"] = path_line[line][i+1:] test = False if test: final_path["Blue"] = path_line[line] elif line == "Pink": MT = any(x.startswith("MT") for x in path_line[line]) PK = any(x.startswith("PK") for x in path_line[line]) if (MT and PK): for i in range(0, len(path_line[line])-1): if (path_line[line][i] == "PK10" and path_line[line][i+1] == "MT01") or (path_line[line][i] == "MT01" and path_line[line][i+1] == "PK10"): final_path["Pink1"] = path_line[line][:i+2] final_path["Pink2"] = path_line[line][i+1:] else: final_path["Pink"] = path_line[line] elif line == "Green": north = any(x.startswith("N") for x in path_line[line]) east = any(x.startswith("E") for x in path_line[line]) south = any(x.startswith("S") for x in path_line[line]) west = any(x.startswith("W") for x in path_line[line]) if (north and south) or (north and west) or (east and south) or (east and west): for i in range(0, len(path_line[line])-1): if path_line[line][i] == "CEN": if path_line[line][0][0] == "N" or path_line[line][0][0] == "E": final_path["LightGreen"] = path_line[line][:i+1] final_path["DarkGreen"] = path_line[line][i:] elif path_line[line][0][0] == "W" or path_line[line][0][0] == "S": final_path["DarkGreen"] = path_line[line][:i+1] final_path["LightGreen"] = path_line[line][i:] elif south or west: final_path["DarkGreen"] = path_line[line] elif north or east: final_path["LightGreen"] = path_line[line] elif line == "Red": RN = any(x.startswith("RN") and x != "RW01-RN01" for x in path_line[line]) RW = any(x.startswith("RW") and x != "RW01-RN01" for x in path_line[line]) if (RN and RW): for i in range(len(path_line[line])): if path_line[line][i] == "RW01-RN01": if path_line[line][0][1] == "N": final_path["DarkRed"] = path_line[line][:i+1] final_path["LightRed"] = path_line[line][i:] elif path_line[line][0][1] == "W": final_path["LightRed"] = path_line[line][:i+1] final_path["DarkRed"] = path_line[line][i:] elif RN: final_path["DarkRed"] = path_line[line] elif RW: final_path["LightRed"] = path_line[line] else: final_path[line] = path_line[line] interchange_count = len(final_path) - 1 if sum_price['Adult'] < best_price: best_price = sum_price['Adult'] if station_count < best_station: best_station = station_count if interchange_count < best_interchange: best_interchange = interchange_count calculated_path.append({ "path": final_path, "price": sum_price, "stations": station_count, "interchanges": interchange_count }) for data in calculated_path: if data['price']['Adult'] == best_price and data['stations'] == best_station and data['interchanges'] == best_interchange: best_path_1.append(data) elif data['price']['Adult'] == best_price and data['stations'] == best_station: best_path_2.append(data) elif data['stations'] == best_station and data['interchanges'] == best_interchange: best_path_2.append(data) elif data['interchanges'] == best_interchange and data['price']['Adult'] == best_price: best_path_2.append(data) elif data['price']['Adult'] == best_price: best_path_3.append(data) elif data['stations'] == best_station: best_path_3.append(data) elif data['interchanges'] == best_interchange: best_path_3.append(data) return json.dumps(clean_inf(dict_to_list([best_path_1, best_path_2, best_path_3, best_price, best_station, best_interchange]))) __export__ = ["init", "calculate"] import json import time from pyscript import window, document, when, workers, ffi t1 = time.time() main_worker = await workers["main_worker"] print("Worker ready:", round(time.time() - t1, 2), "s") t0 = time.time() cached = window.sessionStorage.getItem("pointastx-data-v2026.10.1") if not ffi.is_none(cached): data_str = str(cached) data_json = json.loads(data_str) stations = data_json[0] interchange = data_json[1] discount = data_json[2] prices = data_json[3] print("Loaded database from sessionStorage") else: data_str = await main_worker.init() data_json = json.loads(data_str) stations = data_json[0] interchange = data_json[1] discount = data_json[2] prices = data_json[3] window.sessionStorage.setItem("pointastx-data-v2026.10.1", data_str) print("Loaded database from Excel and cached it") print("Database ready:", round(time.time() - t0, 2), "s") def get_value(lst, key): for k, v in lst: if k == key: return v return None def get_path(data, path): current = data for p in path: if isinstance(p, int): current = current[p] else: current = get_value(current, p) if current is None: return None return current colorDict = { "Blue": "#233180", "Purple": "#8f3387", "Yellow": "#ffd500", "Pink": "#e66086", "LightGreen": "#78b82a", "DarkGreen": "#00817e", "Gold": "#ad8c18", "LightRed": "#d05a63", "DarkRed": "#bc1320", "ARL": "#751633", "BRT": "#dddd00", "Blue1": "#233180", "Blue2": "#233180", "Pink1": "#e66086", "Pink2": "#e66086" } nameDict = { "Blue": "MRT Blue Line", "Purple": "MRT Purple Line", "Yellow": "MRT Yellow Line", "Pink": "MRT Pink Line", "LightGreen": "BTS Light Green Line", "DarkGreen": "BTS Dark Green Line", "Gold": "BTS Gold Line", "LightRed": "SRTET Light Red Line", "DarkRed": "SRTET Dark Red Line", "ARL": "Airport Rail Link", "BRT": "Bus Rapid Transit", "Blue1": "MRT Blue Line", "Blue2": "MRT Blue Line", "Pink1": "MRT Pink Line", "Pink2": "MRT Pink Line" } originElement = document.getElementById("origin") destinationElement = document.getElementById("destination") def populateStations(element): for line in stations: if line[0] == "Green": optgroup1 = document.createElement("optgroup") optgroup1.label = nameDict["DarkGreen"] optgroup2 = document.createElement("optgroup") optgroup2.label = nameDict["LightGreen"] for item in get_path(stations, [line[0]]): code = item[0] name = item[1] if code == "CEN": for group in [optgroup1, optgroup2]: option = document.createElement("option") option.value = code option.textContent = name group.appendChild(option) elif code[0] in ("W", "S"): option = document.createElement("option") option.value = code option.textContent = name optgroup1.appendChild(option) elif code[0] in ("E", "N"): option = document.createElement("option") option.value = code option.textContent = name optgroup2.appendChild(option) element.appendChild(optgroup1) element.appendChild(optgroup2) elif line[0] == "Red": optgroup1 = document.createElement("optgroup") optgroup1.label = nameDict["DarkRed"] optgroup2 = document.createElement("optgroup") optgroup2.label = nameDict["LightRed"] for item in get_path(stations, [line[0]]): code = item[0] name = item[1] if code == "RW01-RN01": for group in [optgroup1, optgroup2]: option = document.createElement("option") option.value = code option.textContent = name group.appendChild(option) elif code[1] == "W": option = document.createElement("option") option.value = code option.textContent = name optgroup1.appendChild(option) elif code[1] == "N": option = document.createElement("option") option.value = code option.textContent = name optgroup2.appendChild(option) element.appendChild(optgroup1) element.appendChild(optgroup2) else: optgroup = document.createElement("optgroup") optgroup.label = nameDict[line[0]] for item in get_path(stations, [line[0]]): code = item[0] name = item[1] option = document.createElement("option") option.value = code option.textContent = name optgroup.appendChild(option) element.appendChild(optgroup) populateStations(originElement) populateStations(destinationElement) outputElement = document.getElementById("output") def getBoardingInfo(line_name, current_station, next_station): platform = "" if line_name == "Blue" or line_name == "Blue1" or line_name == "Blue2": if int(current_station[2:]) == 1 and int(next_station[2:]) == 2: platform = f"4" elif int(current_station[2:]) - int(next_station[2:]) == 1: platform = f"2" elif int(current_station[2:]) - int(next_station[2:]) == -1: platform = f"1" elif int(current_station[2:]) == 32 and int(next_station[2:]) == 1: platform = f"2" elif int(current_station[2:]) == 1 and int(next_station[2:]) == 33: platform = f"1" elif line_name == "Purple": if int(current_station[2:]) == 16 and int(next_station[2:]) == 15: platform = f"3" elif int(current_station[2:]) - int(next_station[2:]) == 1: platform = f"2" elif int(current_station[2:]) - int(next_station[2:]) == -1: platform = f"1" elif line_name == "Yellow": if int(current_station[2:]) - int(next_station[2:]) == 1: platform = f"2" elif int(current_station[2:]) - int(next_station[2:]) == -1: platform = f"1" elif line_name == "Pink" or line_name == "Pink1" or line_name == "Pink2": if str(current_station[:2]) == "PK" and str(next_station[:2]) == "MT": platform = f"3" elif str(current_station[:2]) == "MT" and str(next_station[:2]) == "MT" and int(current_station[2:]) - int(next_station[2:]) == 1: platform = f"4" elif str(current_station[:2]) == "MT" and str(next_station[:2]) == "MT" and int(current_station[2:]) - int(next_station[2:]) == -1: platform = f"3" elif int(current_station[2:]) - int(next_station[2:]) == 1: platform = f"2" elif int(current_station[2:]) - int(next_station[2:]) == -1: platform = f"1" elif line_name == "LightGreen" or line_name == "DarkGreen": if str(current_station) == "CEN" and str(next_station[:1]) == "E": platform = f"1" elif str(current_station) == "CEN" and str(next_station[:1]) == "N": platform = f"2" elif str(current_station) == "CEN" and str(next_station[:1]) == "W": platform = f"4" elif str(current_station) == "CEN" and str(next_station[:1]) == "S": platform = f"3" elif str(current_station[:1]) == "N" and str(next_station[:1]) == "N" and int(current_station[1:]) - int(next_station[1:]) == 1: platform = f"1" elif str(current_station[:1]) == "N" and str(next_station[:1]) == "N" and int(current_station[1:]) - int(next_station[1:]) == -1: platform = f"2" elif str(current_station[:1]) == "E" and str(next_station[:1]) == "E" and int(current_station[1:]) - int(next_station[1:]) == 1: platform = f"2" elif str(current_station[:1]) == "E" and str(next_station[:1]) == "E" and int(current_station[1:]) - int(next_station[1:]) == -1: platform = f"1" elif str(current_station[:1]) == "S" and str(next_station[:1]) == "S" and int(current_station[1:]) - int(next_station[1:]) == 1: platform = f"4" elif str(current_station[:1]) == "S" and str(next_station[:1]) == "S" and int(current_station[1:]) - int(next_station[1:]) == -1: platform = f"3" elif line_name == "Gold": if int(current_station[2:]) - int(next_station[2:]) == 1: platform = f"2" elif int(current_station[2:]) - int(next_station[2:]) == -1: platform = f"1" elif line_name == "LightRed" or line_name == "DarkRed": if str(current_station) == "RW01-RN01" and str(next_station[:2]) == "RW": platform = f"9" elif str(current_station) == "RW01-RN01" and str(next_station[:2]) == "RN": platform = f"3" elif str(current_station) == "RW08" and str(next_station[:2]) == "RN" and int(current_station[2:]) - int(next_station[2:]) == 1: platform = f"1 āđāļĨāļ° 2" elif str(current_station) == "RW08" and str(next_station[:2]) == "RN" and int(current_station[2:]) - int(next_station[2:]) == 1: platform = f"3 āđāļĨāļ° 4" elif str(current_station) == "RN10" and str(next_station[:2]) == "RN" and int(current_station[2:]) - int(next_station[2:]) == 1: platform = f"3 āđāļĨāļ° 4" elif str(current_station) == "RW06" and str(next_station[:2]) == "RW" and int(current_station[2:]) - int(next_station[2:]) == 1: platform = f"1 āđāļĨāļ° 4" elif str(current_station[:2]) == "RN" and str(next_station[:2]) == "RN" and int(current_station[2:]) - int(next_station[2:]) == 1: platform = f"2" elif str(current_station[:2]) == "RN" and str(next_station[:2]) == "RN" and int(current_station[2:]) - int(next_station[2:]) == -1: platform = f"1" elif str(current_station[:2]) == "RW" and str(next_station[:2]) == "RW" and int(current_station[2:]) - int(next_station[2:]) == 1: platform = f"2" elif str(current_station[:2]) == "RW" and str(next_station[:2]) == "RW" and int(current_station[2:]) - int(next_station[2:]) == -1: platform = f"1" elif line_name == "ARL": if int(current_station[2:]) - int(next_station[2:]) == 1: platform = f"1" elif int(current_station[2:]) - int(next_station[2:]) == -1: platform = f"2" return platform def createOutput(data, label): tab = document.createElement("input") tab.type = "radio" tab.name = "route" tab.className = "tab text-sm md:text-md" tab.ariaLabel = label outputElement.appendChild(tab) content = document.createElement("div") content.className = "tab-content !border-none" detail = document.createElement("div") detail.className = "grid grid-cols-2 grid-rows-3 p-8 gap-4" detail.innerHTML = f"āļĢāļēāļ„āļē{get_path(data, ['price', 'Adult'])} āļšāļēāļ—āļˆāļģāļ™āļ§āļ™āļŠāļ–āļēāļ™āļĩ{get_path(data, ['stations'])} āļŠāļ–āļēāļ™āļĩāļˆāļģāļ™āļ§āļ™āļāļēāļĢāđ€āļ›āļĨāļĩāđˆāļĒāļ™āļŠāļēāļĒ{get_path(data, ['interchanges'])} āļ„āļĢāļąāđ‰āļ‡" content.appendChild(detail) route = document.createElement("div") for line in get_path(data, ['path']): line = line[0] default = line if line == "Blue1" or line == "Blue2": default ="Blue" elif line == "Pink1" or line == "Pink2": default ="Pink" elif line == "DarkGreen" or line == "LightGreen": default ="Green" elif line == "DarkRed" or line == "LightRed": default ="Red" start = get_path(data, ['path', line, 0]) end = get_path(data, ['path', line, -1]) color = colorDict[line] name = nameDict[line] details = document.createElement("details") details.className = "collapse !rounded-none" head = document.createElement("summary") head.className = f"collapse-title font-semibold bg-[{color}] text-white" head.innerHTML = f"{name} | {str(get_path(prices, [default, 'Adult', start, end]))} āļšāļēāļ— | {str(len(get_path(data, ['path', line])))} āļŠāļ–āļēāļ™āļĩ" details.appendChild(head) if (len(get_path(data, ['path', line])) >= 2): number = getBoardingInfo( line, get_path(data, ['path', line])[0], get_path(data, ['path', line])[1] ) if number != "": br = document.createElement("br") head.appendChild(br) platform = document.createElement("span") platform.className = f"font-normal" platform.innerHTML = f"āļŠāļēāļ™āļŠāļēāļĨāļē {number}" head.appendChild(platform) body = document.createElement("ul") body.className = "w-[calc(200%-20px)] collapse-content text-sm pt-[1rem] timeline timeline-vertical -translate-x-[calc(50%-20px)]" for station in get_path(data, ['path', line]): dot = document.createElement("li") if station != start: hr1 = document.createElement("hr") hr1.className = f"w-[8px] h-[120%] !rounded-none bg-[{color}]" dot.appendChild(hr1) middle = document.createElement("div") middle.className = f"timeline-middle rounded-full size-[20px] bg-[{color}]" dot.appendChild(middle) text = document.createElement("div") text.className = "timeline-end m-4" text.innerHTML = get_path(stations, [default, station]) dot.appendChild(text) if station != end: hr2 = document.createElement("hr") hr2.className = f"w-[8px] h-[120%] !rounded-none bg-[{color}]" dot.appendChild(hr2) body.appendChild(dot) details.appendChild(body) route.appendChild(details) content.appendChild(route) outputElement.appendChild(content) if document.querySelector('#collapse'): document.querySelector('#collapse').open = True is_calculating = False @when("change", "#origin") async def originInput(): await handleInput() @when("change", "#destination") async def destinationInput(): await handleInput() async def handleInput(): global is_calculating if is_calculating: return is_calculating = True try: outputElement.innerHTML = "" result = await main_worker.calculate(data_str, originElement.value, destinationElement.value) file = json.loads(result) best_path_1 = file[0] best_path_2 = file[1] best_path_3 = file[2] best_price = file[3] best_station = file[4] best_interchange = file[5] if len(best_path_1) >= 1: for data in best_path_1: createOutput(data, "āđ€āļŠāđ‰āļ™āļ—āļēāļ‡āļ—āļĩāđˆāļ”āļĩāļ—āļĩāđˆāļŠāļļāļ”") elif len(best_path_2) >= 1: for data in best_path_2: if get_path(data, ['price', 'Adult']) == best_price and get_path(data, ['stations']) == best_station: createOutput(data, "āļĢāļēāļ„āļēāļ•āđˆāļģāļ—āļĩāđˆāļŠāļļāļ”āđāļĨāļ°āļĢāļ°āļĒāļ°āļ—āļēāļ‡āļŠāļąāđ‰āļ™āļ—āļĩāđˆāļŠāļļāļ”") elif get_path(data, ['stations']) == best_station and get_path(data, ['interchanges']) == best_interchange: createOutput(data, "āļĢāļ°āļĒāļ°āļ—āļēāļ‡āļŠāļąāđ‰āļ™āļ—āļĩāđˆāļŠāļļāļ”āđāļĨāļ°āđ€āļ›āļĨāļĩāđˆāļĒāļ™āļŠāļēāļĒāļ™āđ‰āļ­āļĒāļ—āļĩāđˆāļŠāļļāļ”") elif get_path(data, ['interchanges']) == best_interchange and get_path(data, ['price', 'Adult']) == best_price: createOutput(data, "āļĢāļēāļ„āļēāļ•āđˆāļģāļ—āļĩāđˆāļŠāļļāļ”āđāļĨāļ°āđ€āļ›āļĨāļĩāđˆāļĒāļ™āļŠāļēāļĒāļ™āđ‰āļ­āļĒāļ—āļĩāđˆāļŠāļļāļ”") elif len(best_path_3) >= 1: for data in best_path_3: if get_path(data, ['price', 'Adult']) == best_price: createOutput(data, "āļĢāļēāļ„āļēāļ•āđˆāļģāļ—āļĩāđˆāļŠāļļāļ”") elif get_path(data, ['stations']) == best_station: createOutput(data, "āļĢāļ°āļĒāļ°āļ—āļēāļ‡āļŠāļąāđ‰āļ™āļ—āļĩāđˆāļŠāļļāļ”") elif get_path(data, ['interchanges']) == best_interchange: createOutput(data, "āđ€āļ›āļĨāļĩāđˆāļĒāļ™āļŠāļēāļĒāļ™āđ‰āļ­āļĒāļ—āļĩāđˆāļŠāļļāļ”") if document.querySelector('input[type="radio"][name="route"]'): document.querySelector('input[type="radio"][name="route"]').checked = True finally: is_calculating = False document.getElementById("splash").classList.add("hidden")
āļ•āđ‰āļ™āļ—āļēāļ‡

āļ›āļĨāļēāļĒāļ—āļēāļ‡

Loading