def read_hospitals(self, filename): # Read hospitals from a headered CSV into a pandas dataframe hospital_headers = ["latitude", "longitude"] hospitals_df = parse_headered_csv(filename, hospital_headers) # Generate list of models from dataframe latitudes = [] longitudes = [] for index, row in hospitals_df.iterrows(): latitudes.append(row["latitude"]) longitudes.append(row["longitude"]) return latitudes, longitudes
def read_cases(self): # Read cases from CSV into a pandas dataframe cases_df = parse_headered_csv(self.filename, self.headers) # TODO -- Pass in dict or find another way to generalize ordering of headers id_key = self.headers[0] timestamp_key = self.headers[1] latitude_key = self.headers[2] longitude_key = self.headers[3] priority_key = self.headers[4] if len(self.headers) > 3 else None # Generate list of models from dataframe cases = [] for index, row in cases_df.iterrows(): case = RandomCase(id=row[id_key], date_recorded=datetime.strptime(row[timestamp_key], '%Y-%m-%d %H:%M:%S.%f'), incident_location=Point(row[latitude_key], row[longitude_key]), event_generator=self.event_generator, priority=row[priority_key] if priority_key is not None else None) cases.append(case)
def read(self, filename): # Read ambulance from a headered CSV into a pandas dataframe ambulances_df = parse_headered_csv(filename, self.headers) # TODO -- generalize id_key = self.headers[0] b_latitude_key = self.headers[1] b_longitude_key = self.headers[2] capability_key = self.headers[3] # Generate list of models from dataframe a = [] for index, row in ambulances_df.iterrows(): base = Point(row[b_latitude_key], row[b_longitude_key]) ambulance = Ambulance(id=row[id_key], base=base, capability=Capability[row[capability_key]]) a.append(ambulance) return a
def read_cases(self): # Read cases from CSV into a pandas dataframe case_headers = ["id", "latitud", "longitud", "fecha", "dia_semana", "hora_llamada", "vprioridad"] cases_df = parse_headered_csv(self.filename, case_headers) # Aggregates columms 'date' and 'time' to produce a column for datetime objects # TODO -- SLOW OPERATION - find a better way to parse date and time to datetime object cases_df["datetime"] = pd.to_datetime(cases_df.fecha + ' ' + cases_df.hora_llamada) # Sorts all cases by their datetimes (REQUIRED BY SIMULATOR) cases_df = cases_df.sort_values('datetime', ascending=True) cases_df = cases_df[:100] # Generate list of models from dataframe cases = [] for index, row in cases_df.iterrows(): case = RandomCase(id=row["id"], date_recorded=row["datetime"], incident_location=Point(row["latitud"], row["longitud"]), event_generator=self.event_generator, priority=row["vprioridad"]) cases.append(case)
def read_cases(self, filename): # Read cases from CSV into a pandas dataframe case_headers = [ "Fecha", "No_unidad", "Dia_semana", "Latitud salida", "Longitud salida", "Hora_salida", "Latitud llegada incidente", "Longitud llegada incidente", "Hora_llegada incidente", "Latitud salida al hospital", "Longitud salida al hospital", "Hora_salida al hospital", "Latitud arribo al hospital", "Longitud arribo al hospital", "Hora_arribo al hospital", "Tiempo_base_incidente", "Tiempo dando atencion pre-hospitalaria ", "Tiempo_incidente_hospital", "tiempo_total base-hospital" ] cases_df = parse_headered_csv(filename, case_headers) # Datetime format dt_format = "%m/%d/%Y %H:%M:%S" # Generate list of models from dataframe cases = [] for index, row in cases_df.iterrows(): ### Datetimes # Create strings for dates; used to convert to datetimes base_depart_dt_str = row["Fecha"] + " " + row["Hora_salida"] incident_arrival_dt_str = row["Fecha"] + " " + row[ "Hora_llegada incidente"] incident_depart_dt_str = row["Fecha"] + " " + row[ "Hora_salida al hospital"] hospital_arrival_dt_str = row["Fecha"] + " " + row[ "Hora_arribo al hospital"] # Generate datetimes base_depart_dt = datetime.strptime(base_depart_dt_str, dt_format) incident_arrival_dt = datetime.strptime(incident_arrival_dt_str, dt_format) incident_depart_dt = datetime.strptime(incident_depart_dt_str, dt_format) hospital_arrival_dt = datetime.strptime(hospital_arrival_dt_str, dt_format) ### Events events = [] # Event capturing ambulance travelling from base to incident base_to_incident_event = Event( destination=Point(latitude=row["Latitud llegada incidente"], longitude=row["Longitud llegada incidente"]), event_type=EventType.TO_INCIDENT, duration=incident_arrival_dt - base_depart_dt) events.append(base_to_incident_event) if row["Latitud salida al hospital"] != 0: # Event capturing patient pickup # TODO -- When there is no patient to bring to hospital, no information provided on incident departure at_incident_event = Event(destination=Point( latitude=row["Latitud llegada incidente"], longitude=row["Longitud llegada incidente"]), event_type=EventType.AT_INCIDENT, duration=incident_depart_dt - incident_arrival_dt) events.append(at_incident_event) # Event capturing ambulance travelling from incident to hospital incident_to_hospital_event = Event( destination=Point( latitude=row["Latitud arribo al hospital"], longitude=row['Longitud arribo al hospital']), event_type=EventType.TO_HOSPITAL, duration=hospital_arrival_dt - incident_depart_dt) events.append(incident_to_hospital_event) # Event capturing ambulance travelling from hospital to base hospital_to_base_event = Event(destination=Point( latitude=row["Latitud salida"], longitude=row["Longitud salida"]), event_type=EventType.TO_BASE) events.append(hospital_to_base_event) else: # Event capturing ambulance travelling from incident to base incident_to_base_event = Event(destination=Point( latitude=row["Latitud salida"], longitude=row["Longitud salida"]), event_type=EventType.TO_BASE) events.append(incident_to_base_event) # Generate a case from events case = DefinedCase( id=index, date_recorded=base_depart_dt, incident_location=Point( latitude=row["Latitud llegada incidente"], longitude=row["Longitud llegada incidente"]), events=events) cases.append(case) # Sort all cases by the departure time from base cases.sort(key=lambda case: case.date_recorded) return cases