public CalcEnergyStorage([NotNull] IOnlineDeviceActivationProcessor odap,
                                 [NotNull] CalcLoadTypeDto loadType,
                                 double maximumStorageRate, double maximumWithdrawRate, double minimumStorageRate,
                                 double minimumWithdrawRate,
                                 double initialFill, double storageCapacity, [CanBeNull] EnergyStorageLogfile elf,
                                 [NotNull] CalcDeviceDto deviceDto)
            : base(deviceDto.Name, deviceDto.Guid)
        {
            //_devProcessorKey = new OefcKey(householdKey, OefcDeviceType.Storage, guid, "-1", loadType.Guid,"Energy Storage");
            _odap            = odap;
            _inputLoadType   = loadType;
            _deviceDto       = deviceDto;
            _devProcessorKey = _odap.RegisterDevice(_inputLoadType, deviceDto);

            _maximumStorageRate  = maximumStorageRate;
            _maximumWithdrawRate = maximumWithdrawRate;
            _minimumStorageRate  = minimumStorageRate;
            _minimumWithdrawRate = minimumWithdrawRate;
            var correctInitialFill = initialFill / _inputLoadType.ConversionFactor;

            PreviousFillLevel = correctInitialFill;
            _storageCapacity  = storageCapacity / _inputLoadType.ConversionFactor;
            _currentFillLevel = correctInitialFill;
            _elf = elf;
            var capacity = storageCapacity + " " + loadType.UnitOfSum + " - initial fill " + initialFill + " " +
                           loadType.UnitOfSum;

            _headerEntry = new EnergyStorageHeaderEntry(Name, capacity, _inputLoadType.FileName);

            _elf?.RegisterStorage(Name, _headerEntry);
        }
예제 #2
0
        public void OnlineDeviceActivationProcessorArrayTest()
        {
            var rnd = new Random(1);
            var nr  = new NormalRandom(0, 1, rnd);

            using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) {
                wd.InputDataLogger.AddSaver(new ColumnEntryLogger(wd.SqlResultLoggingService));
                wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService));
                wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService));
                var calcParameters = CalcParametersFactory.MakeGoodDefaults().EnableShowSettlingPeriod();
                //calcParameters.Enable(CalcOption.ActionsLogfile);
                calcParameters.Enable(CalcOption.DeviceProfilesIndividualHouseholds);
                calcParameters.Enable(CalcOption.DetailedDatFiles);
                using (var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "hh1", wd.InputDataLogger)) {
                    //SqlResultLoggingService srls = new SqlResultLoggingService(Path.Combine(wd.WorkingDirectory, "results.sqlite"));
                    var dsc = new DateStampCreator(calcParameters);

                    using (IOnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, calcParameters)) {
                        var hhkey = new HouseholdKey("HH1");
                        fft.RegisterHousehold(Constants.GeneralHouseholdKey, "generalhousehold", HouseholdKeyType.General, "Description", null, null);
                        fft.RegisterHousehold(hhkey, "hh1", HouseholdKeyType.Household, "Description", null, null);
                        var odap         = new OnlineDeviceActivationProcessor(old, calcParameters, fft);
                        var deviceGuid   = "devguid".ToStrGuid();
                        var locationGuid = "locationGuid".ToStrGuid();
                        var loadtypeGuid = "ltguid".ToStrGuid();
                        var cdd          = new CalcDeviceDto("devicename", "devcatguid".ToStrGuid(), hhkey, OefcDeviceType.Device, "devcatname", "",
                                                             deviceGuid, locationGuid, "loc");

                        var key = new OefcKey(cdd, loadtypeGuid);
                        var clt = new CalcLoadType("lt1", "W", "kWh", 1, true, loadtypeGuid);
                        odap.RegisterDevice(clt.ConvertToDto(), cdd);
                        double[] stepValues = { 1.0, 0 };
                        var      valueList  = new List <double>(stepValues);
                        var      cp         = new CalcProfile("myCalcProfile", Guid.NewGuid().ToStrGuid(), valueList, ProfileType.Absolute, "synthetic");
                        var      ts1        = new TimeStep(1, 0, false);
                        var      cdl        = new CalcDeviceLoad("", 1, clt, 0, 0);
                        var      sv         = StepValues.MakeStepValues(cp, 10, RandomValueProfile.MakeStepValues(cp.StepValues.Count, nr, 0), cdl);
                        odap.AddNewStateMachine(ts1, clt.ConvertToDto(), "name1", "p1", key, cdd, sv);
                        double[] resultValues = { 0, 10.0, 0, 0, 0, 0, 0, 0, 0, 0 };

                        for (var i = 0; i < 10; i++)
                        {
                            var ts       = new TimeStep(i, 0, true);
                            var filerows = odap.ProcessOneTimestep(ts);
                            filerows.Count.Should().Be(1);
                            filerows[0].EnergyEntries.Count.Should().Be(1);
                            Logger.Info(filerows[0].EnergyEntries[0].ToString(CultureInfo.CurrentCulture));
                            resultValues[i].Should().Be(filerows[0].EnergyEntries[0]);
                            foreach (var fileRow in filerows)
                            {
                                fileRow.Save(odap.BinaryOutStreams[fileRow.LoadType]);
                            }
                        }
                    }
                }

                Logger.Info(wd.WorkingDirectory);
                wd.CleanUp();
            }
        }
        public void ProcessOneTimestepTestVariableFactor()
        {
            var calcParameters = CalcParametersFactory.MakeGoodDefaults();

            using var wd = new WorkingDir(Utili.GetCurrentMethodAndClass());
            wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService));
            wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService));
            wd.InputDataLogger.AddSaver(new ColumnEntryLogger(wd.SqlResultLoggingService));
            using var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "name", wd.InputDataLogger);
            fft.RegisterGeneralHouse();
            using var old = new OnlineLoggingData(new DateStampCreator(calcParameters), wd.InputDataLogger, calcParameters);
            var odap    = new OnlineDeviceActivationProcessor(old, calcParameters, fft);
            var clt     = new CalcLoadType("clt1", "W", "kWh", 1, true, Guid.NewGuid().ToStrGuid());
            var devguid = Guid.NewGuid().ToStrGuid();
            var locguid = Guid.NewGuid().ToStrGuid();
            var cdd     = new CalcDeviceDto("dev1", "devcatguid".ToStrGuid(), new HouseholdKey("HH1"), OefcDeviceType.Device, "devcatname", "", devguid, locguid,
                                            "loc");
            var key = new OefcKey(cdd, clt.Guid);

            odap.RegisterDevice(clt.ConvertToDto(), cdd);
            double[]       timestepValues = { 0, 5, 10.0, 20, 30, 40, 0 };
            var            cp             = new CalcProfile("myCalcProfile", Guid.NewGuid().ToStrGuid(), timestepValues.ToList(), ProfileType.Absolute, "synthetic");
            var            ts1            = new TimeStep(1, 0, true);
            CalcDeviceLoad cdl            = new CalcDeviceLoad("", 1, clt, 0, 0);
            var            sv             = StepValues.MakeStepValues(cp, 1, RandomValueProfile.MakeStepValues(cp.StepValues.Count, NormalRandom, 0), cdl);

            odap.AddNewStateMachine(ts1, clt.ConvertToDto(), "name1", "p1", key, cdd, sv);
            double[] resultValues = { 0, 0, 5, 10.0, 20, 30, 40, 0 };
            //double[] resultValuesRow1 = {0, 0, 5, 10, 200, 3000, 4000, 0};
            var ctd  = new CalcTransformationDevice(odap, -1, 080, -1000, 1000, cdd, clt);
            var clt2 = new CalcLoadType("clt2", "W2", "kWh2", 1, true, Guid.NewGuid().ToStrGuid());

            ctd.AddOutputLoadType(clt2, 2, TransformationOutputFactorType.Interpolated);

            ctd.AddDatapoint(10, 1);
            ctd.AddDatapoint(20, 10);
            ctd.AddDatapoint(30, 100);
            for (var i = 0; i < resultValues.Length; i++)
            {
                var ts       = new TimeStep(i, calcParameters);
                var filerows = odap.ProcessOneTimestep(ts);
                filerows.Count.Should().Be(2);
                filerows[0].EnergyEntries.Count.Should().Be(1);
                var sb = new StringBuilder("row0 before:");
                sb.Append(filerows[0].EnergyEntries[0]);
                sb.Append(" row1 before:");
                sb.Append(filerows[1].EnergyEntries[0]);
                Assert.Equal(resultValues[i], filerows[0].EnergyEntries[0]);
                Assert.Equal(0, filerows[1].EnergyEntries[0]);
                ctd.ProcessOneTimestep(filerows, null);
                //(filerows[1].EnergyEntries[0]).Should().Be(resultValuesRow1[i]);
                sb.Append(" row0 after:");
                sb.Append(filerows[0].EnergyEntries[0]);
                sb.Append(" row1 after:");
                sb.Append(filerows[1].EnergyEntries[0]);
                Logger.Info(Utili.GetCurrentMethodAndClass() + " " + sb);
            }
        }
예제 #4
0
        public void OnlineDeviceStateMachineTest()
        {
            var            startdate      = new DateTime(2018, 1, 1);
            var            enddate        = startdate.AddMinutes(200);
            CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults()
                                            .SetStartDate(startdate).SetEndDate(enddate).SetSettlingDays(0).EnableShowSettlingPeriod();
            var values = new double[10];

            for (var i = 0; i < values.Length; i++)
            {
                values[i] = i + 1;
                Logger.Info(values[i].ToString(CultureInfo.CurrentCulture));
            }

            var valueList     = new List <double>(values);
            var r             = new Random(1);
            var nr            = new NormalRandom(0, 1, r);
            var devGuid       = Guid.NewGuid().ToStrGuid();
            var locGuid       = Guid.NewGuid().ToStrGuid();
            var clt           = new CalcLoadType("lt", "kWh", "W", 1, true, Guid.NewGuid().ToStrGuid());
            var calcDeviceDto = new CalcDeviceDto("device", devGuid, new HouseholdKey("hh1"), OefcDeviceType.Device,
                                                  "mycategory", "", devGuid, locGuid, "locname");
            var            key  = new OefcKey(calcDeviceDto, locGuid);
            var            cp   = new CalcProfile("mycalcprofile", Guid.NewGuid().ToStrGuid(), valueList, ProfileType.Absolute, "bla");
            TimeStep       ts   = new TimeStep(5, 0, false);
            CalcDeviceLoad cdl  = new CalcDeviceLoad("", 1, clt, 0, 0);
            StepValues     sv   = StepValues.MakeStepValues(cp, 1, RandomValueProfile.MakeStepValues(cp.StepValues.Count, nr, 0), cdl);
            var            odsm = new OnlineDeviceStateMachine(ts, clt.ConvertToDto(), "device", key, "affordance",
                                                               calcParameters, sv, 0);

            calcParameters.SetDummyTimeSteps(0);
            odsm.CalculateOfficialEnergyUse().Should().Be(55); // all
            calcParameters.SetDummyTimeSteps(6);
            odsm.CalculateOfficialEnergyUse().Should().Be(54); // not the first
            //_calcParameters.InternalTimesteps = 20;
            calcParameters.SetDummyTimeSteps(15);
            odsm.CalculateOfficialEnergyUse().Should().Be(0);  // none
            calcParameters.SetDummyTimeSteps(14);
            odsm.CalculateOfficialEnergyUse().Should().Be(10); // only the last
            Logger.Info(odsm.CalculateOfficialEnergyUse().ToString(CultureInfo.CurrentCulture));
            startdate = new DateTime(2018, 1, 1);
            enddate   = startdate.AddMinutes(10);
            calcParameters.DisableShowSettlingPeriod();
            calcParameters.SetStartDate(startdate).SetEndDate(enddate)
            .SetDummyTimeSteps(5);
            odsm.CalculateOfficialEnergyUse().Should().Be(15); // only the first 5
            //_calcParameters.InternalTimesteps = 10; // only 5
            calcParameters.SetDummyTimeSteps(9);
            var val = odsm.CalculateOfficialEnergyUse();

            val.Should().Be(5); // only #5

            Logger.Info(odsm.CalculateOfficialEnergyUse().ToString(CultureInfo.CurrentCulture));
        }
예제 #5
0
 public CalcGenerator([NotNull] IOnlineDeviceActivationProcessor odap,
                      [NotNull] CalcLoadType loadType,
                      [NotNull] List <double> values,
                      [NotNull] CalcParameters calcParameters, [NotNull] CalcDeviceDto calcDeviceDto) : base(calcDeviceDto.Name, calcDeviceDto.Guid)
 {
     //_devProcessorKey = new OefcKey(householdKey, OefcDeviceType.Generator, guid, "-1", loadType.Guid, "Generator");
     _odap            = odap;
     _loadType        = loadType;
     _values          = values;
     _devProcessorKey = _odap.RegisterDevice(_loadType.ConvertToDto(), calcDeviceDto);
     if (values.Count != calcParameters.InternalTimesteps)
     {
         throw new LPGException("Not enough values in the generator to fill the entire period!");
     }
 }
        public void ProcessOneEnergyStorageTimestepTest()
        {
            using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass()))
            {
                wd.InputDataLogger.AddSaver(new ColumnEntryLogger(wd.SqlResultLoggingService));
                wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService));
                wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService));
                CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults();
                calcParameters.ShowSettlingPeriodTime = true;
                using (OnlineLoggingData old = new OnlineLoggingData(new DateStampCreator(calcParameters), wd.InputDataLogger, calcParameters))
                {
                    using (FileFactoryAndTracker fft = new FileFactoryAndTracker(wd.WorkingDirectory, "name", wd.InputDataLogger))
                    {
                        fft.RegisterGeneralHouse();
                        var           odap         = new OnlineDeviceActivationProcessor(old, calcParameters, fft);
                        var           clt          = new CalcLoadType("clt1", "W", "kWh", 1, true, Guid.NewGuid().ToStrGuid());
                        var           deviceGuid   = Guid.NewGuid().ToStrGuid();
                        HouseholdKey  hhkey        = new HouseholdKey("HH1");
                        var           locationGuid = Guid.NewGuid().ToStrGuid();
                        CalcDeviceDto cdd          = new CalcDeviceDto("dev1", "devcatguid".ToStrGuid(),
                                                                       hhkey, OefcDeviceType.Device, "devcatname", "", deviceGuid, locationGuid, "loc");
                        var key = new OefcKey(cdd, clt.Guid);
                        odap.RegisterDevice(clt.ConvertToDto(), cdd);
                        double[] timestepValue  = { 1.0, 0 };
                        var      timestepValues = new List <double>(timestepValue);
                        var      cp             = new CalcProfile("myCalcProfile", Guid.NewGuid().ToStrGuid(), timestepValues,
                                                                  ProfileType.Absolute, "synthetic");
                        CalcDeviceLoad cdl1 = new CalcDeviceLoad("", -10, clt, 0, 0);
                        var            rvp  = RandomValueProfile.MakeStepValues(cp.StepValues.Count, NormalRandom, 0);
                        StepValues     sv1  = StepValues.MakeStepValues(cp, 1, rvp, cdl1);
                        odap.AddNewStateMachine(new TimeStep(1, 0, true),
                                                clt.ConvertToDto(), "name1", "p1", key, cdd, sv1);
                        CalcDeviceLoad cdl2 = new CalcDeviceLoad("", -100, clt, 0, 0);
                        StepValues     sv2  = StepValues.MakeStepValues(cp, 1, rvp, cdl2);
                        odap.AddNewStateMachine(new TimeStep(3, 0, true),
                                                clt.ConvertToDto(), "name2", "syn", key, cdd, sv2);
                        CalcDeviceLoad cdl3 = new CalcDeviceLoad("", -10, clt, 0, 0);
                        StepValues     sv3  = StepValues.MakeStepValues(cp, 1, rvp, cdl3);
                        odap.AddNewStateMachine(new TimeStep(5, 0, true),
                                                clt.ConvertToDto(), "name3", "syn", key, cdd, sv3);
                        CalcDeviceLoad cdl4 = new CalcDeviceLoad("", 100, clt, 0, 0);
                        StepValues     sv4  = StepValues.MakeStepValues(cp, 1, rvp, cdl4);
                        odap.AddNewStateMachine(new TimeStep(7, 0, true),
                                                clt.ConvertToDto(), "name4", "syn", key, cdd, sv4);
                        double[] resultValues = { 0, -10.0, 0, -100, 0, 10, 0, 100, 0, 0 };
                        var      ces          = new CalcEnergyStorage(odap, clt.ConvertToDto(),
                                                                      100, 7, 0, 0, 5, 20, null,
                                                                      cdd);
                        List <OnlineEnergyFileRow> rawRows = new List <OnlineEnergyFileRow>();
                        int keyidx = 0;
                        foreach (var keys in odap.Oefc.ColumnEntriesByLoadTypeByDeviceKey.Values)
                        {
                            foreach (KeyValuePair <OefcKey, ColumnEntry> pair in keys)
                            {
                                Logger.Info("Key " + keyidx + " " + pair.Key.ToString() + " - " + pair.Value);
                                keyidx++;
                            }
                        }
                        for (var i = 0; i < 10; i++)
                        {
                            TimeStep ts       = new TimeStep(i, 0, true);
                            var      filerows = odap.ProcessOneTimestep(ts);
                            rawRows.Add(filerows[0]);
                            filerows.Count.Should().Be(1);
                            filerows[0].EnergyEntries.Count.Should().Be(1);
                            var sb = new StringBuilder("row0 before:");
                            sb.Append(filerows[0].EnergyEntries[0]);
                            sb.Append(" : ");
                            //sb.Append(filerows[0].EnergyEntries[1]);
                            //filerows[0].EnergyEntries[0].Should().Be(resultValues[i]);
                            for (var j = 0; j < 5; j++)
                            {
                                ces.ProcessOneTimestep(filerows, ts, null);
                            }

                            sb.Append(" row0 after:");
                            sb.Append(filerows[0].EnergyEntries[0]);
                            sb.Append(" : ");
                            //sb.Append(filerows[0].EnergyEntries[1]);
                            sb.Append(" :StorageLevel ");
                            sb.Append(ces.PreviousFillLevel);
                            sb.Append(" :Expected ");
                            sb.Append(resultValues[i]);
                            Logger.Info(sb.ToString());
                        }
                        rawRows.Count.Should().Be(10);
                    }
                }
                wd.CleanUp();
            }
        }