def update_battery_data(efficiency, timeInterval, chargeSpecs, dischargeSpecs,
                        energySpecs, initialEnergy, selfDischargeRate):
    supply = SupplySide()
    data = supply.updateBatteryData(efficiency, timeInterval, chargeSpecs,
                                    dischargeSpecs, energySpecs, initialEnergy,
                                    selfDischargeRate)
    return json.dumps(data)
def addPV(area, emax, angle, location):
    supply = SupplySide()
    solar_energy = pv((int)(area), (int)(emax), (int)(angle), location)
    data = supply.addPV(solar_energy)
    if (data == 101):
        return {"success": True}
    return {"success": False}
def addWind(ra, location):
    supply = SupplySide()
    wind_energy = wind((int)(ra), location)
    data = supply.addWind(wind_energy)
    if (data == 101):
        return {"success": True}
    return {"success": False}
def addBattery(efficiency, timeInterval, chargeSpecs, dischargeSpecs,
               energySpecs, initialEnergy, selfDischargeRate):
    supply = SupplySide()
    battery = Battery((float)(efficiency), (int)(timeInterval),
                      (int)(chargeSpecs), (int)(dischargeSpecs),
                      (int)(energySpecs), (int)(initialEnergy),
                      (float)(selfDischargeRate))
    data = supply.addBattery(battery)
    if (data == 101):
        return {"success": True}
    return {"success": False}
def get_wind_current_energy():
    supply = SupplySide()
    data = supply.getCurrentWindEnergyGenerationData()
    return str(data)
def supplySideInitialise():
    supply = SupplySide()
    if "wind" in request.forms:
        windData = json.loads(request.forms.get('wind'))
        for i in range(0, len(windData)):
            wind_energy = wind((int)(windData[i]["ra"]), windData[i]["city"])
            supply.addWind(wind_energy)
    else:
        wind_energy = wind(6, "Stuttgart")
        supply.addWind(wind_energy)
    if "pv" in request.forms:
        pvData = json.loads(request.forms.get('pv', None))
        for i in range(0, len(pvData)):
            solar_energy = pv((int)(pvData[i]["area"]),
                              (int)(pvData[i]["emax"]),
                              (int)(pvData[i]["angle"]), pvData[i]["location"])
            supply.addPV(solar_energy)
    else:
        solar_energy = pv(20, 75, 60, "Stuttgart")
        supply.addPV(solar_energy)
    if "battery" in request.forms:
        batteryData = json.loads(request.forms.get('battery', None))
        for i in range(0, len(batteryData)):
            battery = Battery((float)(batteryData[i]["efficiency"]),
                              (int)(batteryData[i]["timeInterval"]),
                              (int)(batteryData[i]["chargeSpecs"]),
                              (int)(batteryData[i]["dischargeSpecs"]),
                              (int)(batteryData[i]["energySpecs"]),
                              (int)(batteryData[i]["initialEnergy"]),
                              (float)(batteryData[i]["selfDischargeRate"]))
            supply.addBattery(battery)
    else:
        battery = Battery(0.55, 1, 10, 5, 400, 0, 0.2)
        supply.addBattery(battery)
def get_history():
    supply = SupplySide()
    data = supply.getHistoricalEnergyData()
    return json.dumps(data)
def update_battery_states(charge, state):
    supply = SupplySide()
    data = supply.updateBatteryStates(charge, state)
    return json.dumps(data)
def update_battery_data(charge):
    supply = SupplySide()
    data = supply.updateBatteryCharge(charge)
    return json.dumps(data)
def getSolarEnergyData():
    supply = SupplySide()
    pv_data = list(supply.getAllSolarEnergyData())
    return json.dumps(pv_data[0:len(pv_data) - 1])
def get_total_forecast_energy():
    supply = SupplySide()
    data = supply.getForecastEnergyGenerationData()
    return data
def get_pv_forecast_energy():
    supply = SupplySide()
    data = supply.getForecastSolarEnergyGenerationData()
    return data
def get_wind_forecast_energy():
    supply = SupplySide()
    data = supply.getForecastWindEnergyGenerationData()
    return data
def get_total_current_energy():
    supply = SupplySide()
    data = supply.getCurrentEnergyGenerationData()
    return str(data)
def get_pv_current_energy():
    supply = SupplySide()
    data = supply.getCurrentSolarEnergyGenerationData()
    return str(data)
def get_battery_data():
    supply = SupplySide()
    data = supply.getCurrentBatteryData()
    return json.dumps(data)
def getWindEnergyData():
    supply = SupplySide()
    wind_data = list(supply.getAllWindEnergyData())
    return json.dumps(wind_data[0:len(wind_data) - 1])