示例#1
0
 def setUp(self):
     self.env = BaseEnvironment()
     self.heat_storage = Mock(spec=SimulatedHeatStorage)()
     self.power_meter = Mock(spec=SimulatedPowerMeter)
     self.cu = SimulatedCogenerationUnit(1, self.env)
     self.cu.heat_storage = self.heat_storage
     self.cu.power_meter = self.power_meter
示例#2
0
    def __init__(self,
                 initial_time,
                 configurations=None,
                 code=None,
                 forward=None,
                 forecast=True):
        Thread.__init__(self)
        self.daemon = True
        demomode = Configuration.objects.get(key='system_mode').value == "demo"

        self.env = BaseEnvironment(initial_time=initial_time,
                                   forecast=forecast,
                                   step_size=DEFAULT_FORECAST_STEP_SIZE,
                                   demomode=demomode)  #get_forecast

        if configurations is None:
            configurations = DeviceConfiguration.objects.all()

        self.devices = get_initialized_scenario(self.env, configurations)

        self.measurements = MeasurementStorage(self.env, self.devices)
        self.user_function = get_user_function(self.devices, code)
        self.progress = 0.0
        self.result = None
        self.forward = forward

        if forward == None:
            self.forward = DEFAULT_FORECAST_INTERVAL

        self.next_optimization = 0.0
        self.use_optimization = get_configuration('auto_optimization')
示例#3
0
    def test_dshw_forecast(self):
        hourly_data = StatisticalForecast.make_hourly(self.dataset, 6)
        env = BaseEnvironment()
        fc = DSHWForecast(env, hourly_data, try_cache=False)

        self.assertTrue(
            len(fc.demands[0]) >= fc.input_hours,
            "the day series only contains " + str(len(fc.demands[0]) / 24) +
            " days, not " + str(fc.input_weeks * 7))
示例#4
0
    def setUp(self):
        self.env = BaseEnvironment()
        self.heat_storage = Mock(spec=SimulatedHeatStorage)
        self.power_meter = SimulatedPowerMeter(0, self.env)
        self.cu = SimulatedCogenerationUnit(1, self.env)
        self.cu.heat_storage = self.heat_storage
        self.cu.power_meter = self.power_meter

        self.cu.config['minimal_workload'] = 0.20
        self.cu.off_time = self.env.now - 1
        self.gas_input = 20.0
        self.cu.config['max_gas_input'] = self.gas_input
        self.electrical_efficiency = 0.25
        self.cu.config['electrical_efficiency'] = self.electrical_efficiency
        self.thermal_efficiency = 0.7
        self.cu.config['thermal_efficiency'] = self.thermal_efficiency
        self.total_hours_of_operation = 1
        self.cu.total_hours_of_operation = self.total_hours_of_operation
示例#5
0
    def handle_single_data(self):
        sep = os.path.sep
        path = os.path.join(
            BASE_DIR, "server" + sep + "forecasting" + sep + "devices" + sep +
            "data" + sep + "Electricity_1.1-12.6.2014.csv")
        raw_dataset = DataLoader.load_from_file(
            path, "Strom - Verbrauchertotal (Aktuell)", "\t")
        dates = [
            int(d) for d in DataLoader.load_from_file(path, "Datum", "\t")
        ]  #StatisticalForecast.make_hourly([int(d) for d in DataLoader.load_from_file(path, "Datum", "\t")],6)
        demand = StatisticalForecast.make_hourly(
            [float(val) / 1000.0 for val in raw_dataset], 6)

        start = calendar.timegm(
            datetime(year=2014, month=1, day=2).timetuple())
        start_index = approximate_index(dates, start)
        train_len = 24 * 7 * 8
        trainingdata = demand[start_index:start_index + train_len]
        test_start = start_index + train_len
        testdata = demand[test_start:test_start + 7 * 24 * 2]
        start_forecast = test_start * 3600
        end_forecast = start_forecast + len(testdata) * 3600

        electrical_forecast = DSHWForecast(BaseEnvironment(
            start_forecast, False, False),
                                           trainingdata,
                                           samples_per_hour=1)
        forecast = [
            electrical_forecast.get_forecast_at(timestamp)
            for timestamp in range(start_forecast, end_forecast, 3600)
        ]

        #(forecast, alpha, beta, smoothing) = linear(trainingdata, 24*6,alpha=0.4,beta=0.1)
        #forecast_nodaysplit, (alpha, beta, gamma), insample = multiplicative(trainingdata,24*7,len(testdata) ,optimization_type="RMSE")
        #forecast_nodaysplit, (alpha, beta, gamma, delta, autocorr), insample = double_seasonal(trainingdata,24,24*7,len(testdata) ,optimization_type="RMSE")
        #print alpha, beta, gamma, delta
        #print alpha, beta, gamma, rmse_auto, sqrt(sum([(m - n) ** 2 for m, n in zip(forecast_values_auto, testdata)]) / len(testdata))
        #print "normal", sqrt(sum([(m - n) ** 2 for m, n in zip(forecast_values_auto, testdata)]) / len(testdata))
        #print "split", sqrt(sum([(m - n) ** 2 for m, n in zip(forecast, testdata)]) / len(testdata))
        #split_testdata = DayTypeForecast.split_weekdata(testdata,samples_per_hour=1,start_date=datetime.fromtimestamp(start_forecast))
        #plot_dataset({"measured": split_testdata[5], "forecasted": electrical_forecast.forecasted_demands[5]}, 0, True)
        plot_dataset({"measured": testdata, "forecasted": forecast})
示例#6
0
    def get_warmwater_consumption_power_with_parameters(
            self,
            residents=0,
            time_in_seconds=10,
            temperature=20,
            heat_storage_base=15):
        ''' the result depends on the number of residents,
        the current time aka self.env.now
        the temperature of warm water and 
        the base_temperatur of the heat_storage'''
        self.consumer.config['residents'] = residents
        env = BaseEnvironment(initial_time=time_in_seconds, forecast=True)
        self.consumer.env = env
        self.consumer.temperature_warmwater = temperature

        heat_storage = SimulatedHeatStorage(0, env)
        heat_storage.base_temperature = heat_storage_base
        self.consumer.heat_storage = heat_storage

        return self.consumer.get_warmwater_consumption_power()
示例#7
0
    def test_split_week_data(self):
        hourly_data = StatisticalForecast.make_hourly(self.dataset, 6)
        env = BaseEnvironment()
        fc = DayTypeForecast(env, hourly_data, try_cache=False)
        self.assertTrue(
            len(fc.demands) == 7, "week_split does not contain 7 series")

        self.assertTrue(
            len(fc.demands[0]) / 24 >= fc.input_weeks,
            "the day series only contains " + str(len(fc.demands[0]) / 24) +
            " days, not " + str(fc.input_weeks) +
            " (or at least more than 50)")

        # from server.forecasting.tools import plotting
        for i in range(7):
            # plotting.Plotting.plot_dataset({"measured":fc.demands[i], "forecasted": fc.forecasted_demands[i]}, len(fc.demands[i]), block=True)
            rmse = self.rmse(self.dataset_2014[:len(fc.forecasted_demands[i])],
                             fc.forecasted_demands[i])
            self.assertTrue(
                rmse < 30.0, "MSE of " + str(rmse) + "for day" + str(i) +
                " is way too high")
示例#8
0
    def setUp(self):
        self.env = BaseEnvironment()
        self.heat_storage = Mock(spec=SimulatedHeatStorage)()
        self.power_meter = SimulatedPowerMeter(0, self.env)
        self.cu = SimulatedCogenerationUnit(1, self.env)
        self.cu.heat_storage = self.heat_storage
        self.cu.power_meter = self.power_meter

        self.max_gas_input = 19.0
        self.cu.config['max_gas_input'] = self.max_gas_input
        self.electrical_efficiency = 0.25
        self.cu.config['electrical_efficiency'] = self.electrical_efficiency
        self.thermal_efficiency = 0.6
        self.cu.config['thermal_efficiency'] = self.thermal_efficiency
        self.max_efficiency_loss = 0.10
        self.cu.max_efficiency_loss = self.max_efficiency_loss
        self.maintenance_interval_hours = 2000
        self.cu.config[
            'maintenance_interval_hours'] = self.maintenance_interval_hours
        self.minimal_workload = 0.40
        self.cu.config['minimal_workload'] = self.minimal_workload
        self.cu.config['minimal_off_time'] = 5.0 * 60.0
        self.off_time = self.env.now
        self.cu.off_time = self.off_time
        self.current_electrical_production = 0.0
        self.cu.current_electrical_production = self.current_electrical_production
        self.total_electrical_production = 0.0
        self.cu.total_electrical_production = self.total_electrical_production
        self.total_thermal_production = 0.0
        self.cu.total_thermal_production = self.total_thermal_production

        self.total_gas_consumption = 0.0
        self.cu.total_gas_consumption = self.total_gas_consumption

        self.cu.overwrite_workload = None
        self.cu.running = True

        self.heat_storage.input_energy = 0
        self.power_meter.energy_produced = 0
示例#9
0
    def test_target_temperature_simulate_consumption(self):
        '''the target temperature of the consumer should be set
        according to the daily demand'''
        daily_demand = [x for x in range(24)]

        env = BaseEnvironment(initial_time=1388530800,
                              forecast=True)  # 2014-01-01 00:00:00
        heat_storage = SimulatedHeatStorage(0, env)
        consumer = SimulatedThermalConsumer(1, env)
        consumer.heat_storage = heat_storage
        consumer.daily_demand = daily_demand

        for index, temperature in enumerate(daily_demand):
            consumer.config['target_temperature'] = 0
            consumer.simulate_consumption()

            self.assertEqual(
                consumer.config['target_temperature'], temperature,
                "current hour: {0} expected: {1} got: {2}".format(
                    index, consumer.config['target_temperature'], temperature))

            env.now += 60 * 60
        '''def test_heat_room(self):
示例#10
0
 def setUp(self):
     env = BaseEnvironment(forecast=True)
     self.consumer = SimulatedThermalConsumer(0, env)
     self.consumer.heat_storage = SimulatedHeatStorage(1, env)
示例#11
0
 def setup_forecast(self):
     hourly_data = StatisticalForecast.make_hourly(self.dataset, 6)
     self.env = BaseEnvironment()
     self.forecast = DayTypeForecast(self.env, hourly_data, 1, None,
                                     (0.0000000, 0.0, 1.0))
示例#12
0
 def setUp(self):
     self.env = BaseEnvironment()
     self.power_meter = SimulatedPowerMeter(0, env=self.env)
示例#13
0
 def setUp(self):
     self.env = BaseEnvironment()
     self.hs = SimulatedHeatStorage(0, env=self.env)