def generate_area_cumulative_trade_redis(child, accumulated_trades): results = {"areaName": child.name} area_data = accumulated_trades[child.name] results["bars"] = [] # Producer entries if abs(area_data["produced"]) > FLOATING_POINT_TOLERANCE: results["bars"].append( {"energy": round_floats_for_ui(area_data["produced"]), "targetArea": child.name, "energyLabel": f"{child.name} sold " f"{str(round_floats_for_ui(abs(area_data['produced'])))} kWh", "priceLabel": f"{child.name} earned " f"{str(round_floats_for_ui(area_data['earned']))} cents"} ) # Consumer entries for producer, energy in area_data["consumedFrom"].items(): money = round_floats_for_ui(area_data["spentTo"][producer]) tag = "external sources" if producer == child.parent.name else producer results["bars"].append({ "energy": round_floats_for_ui(energy), "targetArea": producer, "energyLabel": f"{child.name} bought " f"{str(round_floats_for_ui(energy))} kWh from {tag}", "priceLabel": f"{child.name} spent " f"{str(round_floats_for_ui(money))} cents on energy from {tag}", }) return results
def _external_trade_entries(child, accumulated_trades): results = {"areaName": "External Trades"} area_data = accumulated_trades[child.name] results["bars"] = [] incoming_energy = 0 spent = 0 # External Trades entries if "consumedFromExternal" in area_data: for k, v in area_data["consumedFromExternal"].items(): incoming_energy += round_floats_for_ui(area_data["consumedFromExternal"][k]) spent += round_floats_for_ui(area_data["spentToExternal"][k]) results["bars"].append({ "energy": incoming_energy, "targetArea": child.name, "energyLabel": f"External sources sold " f"{abs(round_floats_for_ui(incoming_energy))} kWh", "priceLabel": f"External sources earned {abs(round_floats_for_ui(spent))} cents" }) if "producedForExternal" in area_data: for k, v in area_data["producedForExternal"].items(): outgoing_energy = round_floats_for_ui(area_data["producedForExternal"][k]) earned = round_floats_for_ui(area_data["earnedFromExternal"][k]) results["bars"].append({ "energy": outgoing_energy, "targetArea": k, "energyLabel": f"External sources bought {abs(outgoing_energy)} kWh " f"from {k}", "priceLabel": f"{child.name} spent {earned} cents." }) return results
def cumulative_bills(self): return { uuid: { "name": results["name"], "spent_total": round_floats_for_ui(results['spent_total']), "earned": round_floats_for_ui(results['earned']), "penalties": round_floats_for_ui(results['penalties']), "total": round_floats_for_ui(results['total']) } for uuid, results in self.cumulative_bills_results.items() }
def _calc_results(area, baseline_value, energy_profile, direction_key): # as this is mainly a frontend feature, # the numbers are rounded for both local and redis results peak_percentage = \ round_floats_for_ui(max(energy_profile.values(), default=0.0) / baseline_value * 100) if direction_key == "import": baseline_peak_energy_kWh = round_floats_for_ui( area.baseline_peak_energy_import_kWh) else: baseline_peak_energy_kWh = round_floats_for_ui( area.baseline_peak_energy_export_kWh) return { "peak_percentage": peak_percentage, "baseline_peak_energy_kWh": baseline_peak_energy_kWh, }
def _convert_output_format(self, price_energy, csv_output, redis_output): for node, trade_rates in price_energy.items(): if node.name not in csv_output: csv_output[node.name] = { "price-currency": "Euros", "load-unit": "kWh", "price-energy-day": [] } csv_output[node.name]["price-energy-day"] = [ { "time": timeslot, "av_price": round_floats_for_ui(mean(trades) if len(trades) > 0 else 0), "min_price": round_floats_for_ui(min(trades) if len(trades) > 0 else 0), "max_price": round_floats_for_ui(max(trades) if len(trades) > 0 else 0), } for timeslot, trades in trade_rates.items() ] redis_output[node.uuid] = deepcopy(csv_output[node.name])
def round_energy_trade_profile(profile): for k in profile.keys(): for sold_bought in ("sold_energy", "bought_energy"): if sold_bought not in profile[k]: continue for dev in profile[k][sold_bought].keys(): for target in profile[k][sold_bought][dev].keys(): for timestamp in profile[k][sold_bought][dev][target].keys(): profile[k][sold_bought][dev][target][timestamp] = round_floats_for_ui( profile[k][sold_bought][dev][target][timestamp]) return profile
def _round_child_bill_results(cls, results): results['bought'] = round_floats_for_ui(results['bought']) results['sold'] = round_floats_for_ui(results['sold']) results['spent'] = round_floats_for_ui(results['spent']) results['earned'] = round_floats_for_ui(results['earned']) results['total_energy'] = round_floats_for_ui(results['total_energy']) results['total_cost'] = round_floats_for_ui(results['total_cost']) if "market_fee" in results: results["market_fee"] = round_floats_for_ui(results['market_fee']) return results
def _round_energy_trade_profile(cls, profile): for k in profile.keys(): for sold_bought in ['sold_energy', 'bought_energy']: for dev in profile[k][sold_bought].keys(): for target in profile[k][sold_bought][dev].keys(): for timestamp in profile[k][sold_bought][dev][ target].keys(): profile[k][sold_bought][dev][target][ timestamp] = round_floats_for_ui( profile[k][sold_bought][dev][target] [timestamp]) return profile
def _calc_transformer_results(self, area, direction_key): if direction_key == "import": capacity_kWh = round_floats_for_ui(area.import_capacity_kWh) else: capacity_kWh = round_floats_for_ui(area.export_capacity_kWh) return {"capacity_kWh": capacity_kWh}
def _calc_peak_energy_results(self, energy_profile): return { "peak_energy_kWh": round_floats_for_ui(max(energy_profile.values(), default=0.0)) }