def load_locations(self): """ Reads information on individual suburbs from locations.csv. """ cast = Cast("Location") self.locations = {} csv_helper = CSVHelper("data", "locations.csv") for row in csv_helper.data: uid = cast.to_positive_int(row[0], "Uid") cast.uid = uid name = row[2] longitude = cast.to_float(row[3], "Longitude") latitude = cast.to_float(row[4], "Latitude") population = cast.to_positive_int(row[5], "Population") commute_mean = cast.to_positive_float(row[6], "Commute mean") commute_std_dev = cast.to_positive_float(row[7], "Commute std dev") occupant_distribution \ = cast.to_positive_int_list(row[8], "Occupant distribution") occupant_values \ = cast.to_positive_int_list(row[9], "Occupant values") pv_capacity_mean \ = cast.to_positive_float(row[10], "PV capacity mean") pv_capacity_std_dev \ = cast.to_positive_float(row[11], "PV capacity std dev") battery_capacity_mean \ = cast.to_positive_float(row[12], "Battery capacity mean") battery_capacity_std_dev\ = cast.to_positive_float(row[13], "Battery capacity std dev") loc = Location(uid, name, longitude, latitude, population, commute_mean, commute_std_dev, occupant_distribution, occupant_values, pv_capacity_mean, pv_capacity_std_dev, battery_capacity_mean, battery_capacity_std_dev) # add public charger self.cpm.add_company(loc) self.locations[loc.uid] = loc
def get_parameter(self, parameter_name, parameter_type): """ Returns a parameter from self.parameter as a requested type. Parameters ---------- parameter_name : string Name of the parameter requested. parameter_type : string Type the parameter is requested in. Currently supported: float, positive_float, int, positive_int, string, boolean. Returns ------- <Type as requested in parameter_type> Well the parameter request casted as the type requested """ if parameter_name not in self.parameters: sys.exit("No parameter called " + parameter_name \ + " is defined in parameters.csv") value_str = self.parameters[parameter_name] cast = Cast("Get Parameter") if parameter_type == "float": return cast.to_float(value_str, parameter_name) elif parameter_type == "positive_float": return cast.to_positive_float(value_str, parameter_name) elif parameter_type == "int": return cast.to_int(value_str, parameter_name) elif parameter_type == "positive_int": return cast.to_positive_int(value_str, parameter_name) elif parameter_type == "string": return value_str elif parameter_type == "boolean": return cast.to_boolean(value_str, parameter_name) else: sys.exit("Type '" + parameter_type + "' for parameter " \ + parameter_name + " is not recognised")
def load_electricity_plans(self, parameters, clock): """ Loads all electricity plans from electricity_plans.csv. Parameters ---------- clock : Clock required for time_step parameter Returns ------- None. """ cast = Cast("Electricity Plan") self.electricity_plans = dict() csv_helper = CSVHelper("data", "electricity_plans.csv") for row in csv_helper.data: uid = cast.to_positive_int(row[0], "Uid") cast.uid = uid classification = row[1] if not classification in ["res", "com"]: sys.exit("Classification of electricity plan " + str(uid) \ + " is ill-defined!") is_commercial_plan = classification == "com" base = cast.to_float(row[2], "Base") feed_in_tariff = parameters.get_parameter("feed_in_tariff", "float") # create tariff structure tariff_str = row[3] tariff = self.extract_tariffs_from_string(tariff_str) ep = ElectricityPlan(uid, is_commercial_plan, base, feed_in_tariff, tariff, clock.time_step) self.electricity_plans[uid] = ep if ep.is_commercial_plan: self.commercial_plan_uids.append(ep.uid) else: self.residential_plan_uids.append(ep.uid)
for it, slcted_col in enumerate(slcted_cols): string = row[slcted_col] if slcted_col_types[it] == "date": # remove excess characters for char in remove_char_from_Date: string = string.replace(char, '') # remove seconds string = string[:-2] # store data_point.append(string) elif slcted_col_types[it] == "int": data_point.append( str(cast.to_int(string, slcted_col_names[it]))) elif slcted_col_types[it] == "float": data_point.append( str(cast.to_float(string, slcted_col_names[it]))) else: sys.exit("Data type '" + slcted_col_types[it] \ + "' not implemented.") data.append(data_point) """ SECTION 2: Store unprocessed data """ if store_raw_data == True: print("Store raw data!") with open('solar_irradiance.csv', mode='w', newline='') as output_file: output_file = csv.writer(output_file, delimiter=',', quotechar='"',