public void EnergyStorageSignalTests2()
        {
            CalcParameters cp = CalcParameters.GetNew();

            cp.DummyCalcSteps = 0;
            //CalcLoadType clt = new CalcLoadType("clt",  "power", "sum", 1, true, Guid.NewGuid().ToStrGuid());
            CalcVariable cv = new CalcVariable("myvariable", Guid.NewGuid().ToStrGuid(), 0, "House", Guid.NewGuid().ToStrGuid(),
                                               Constants.HouseKey);
            CalcEnergyStorageSignal cess   = new CalcEnergyStorageSignal("blub", 100, 50, 2, cv, Guid.NewGuid().ToStrGuid());
            List <double>           values = new List <double>();
            int i = 0;

            TestCess(cess, new TimeStep(i++, cp), 100, 100, values);
            TestCess(cess, new TimeStep(i++, cp), 100, 5, values);
            TestCess(cess, new TimeStep(i++, cp), 100, 100, values);
            TestCess(cess, new TimeStep(i++, cp), 100, 5, values);
            TestCess(cess, new TimeStep(i++, cp), 100, 100, values);
            TestCess(cess, new TimeStep(i++, cp), 100, 5, values);
            TestCess(cess, new TimeStep(i++, cp), 100, 100, values);
            TestCess(cess, new TimeStep(i++, cp), 100, 5, values);
            TestCess(cess, new TimeStep(i++, cp), 100, 100, values);
            TestCess(cess, new TimeStep(i++, cp), 100, 5, values);
            TestCess(cess, new TimeStep(i++, cp), 100, 100, values);
            TestCess(cess, new TimeStep(i++, cp), 100, 5, values);
            TestCess(cess, new TimeStep(i++, cp), 100, 100, values);
            TestCess(cess, new TimeStep(i, cp), 100, 5, values);
        }
        public void CalcAffordanceVariableTestSet()
        {
            var deviceCategoryGuid = Guid.NewGuid().ToStrGuid();
            //var r = new Random(0);
            //var nr = new NormalRandom(0, 0.1, r);
            const int stepcount = 150;

            Config.IsInUnitTesting = true;
            DateTime startdate = new DateTime(2018, 1, 1);
            DateTime enddate   = startdate.AddMinutes(stepcount);
            //_calcParameters.InitializeTimeSteps(startdate, enddate, new TimeSpan(0, 1, 0), 3, false);
            CalcParameters calcParameters =
                CalcParametersFactory.MakeGoodDefaults().SetStartDate(startdate).SetEndDate(enddate);
            var timeStep = new TimeSpan(0, 1, 0);
            var cp       = new CalcProfile("profile", Guid.NewGuid().ToStrGuid(), timeStep, ProfileType.Absolute, "blub");

            cp.AddNewTimepoint(new TimeSpan(0), 100);
            cp.AddNewTimepoint(new TimeSpan(0, 10, 0), 0);
            cp.ConvertToTimesteps();
            var variables    = new List <CalcAffordanceVariableOp>();
            var variableReqs = new List <VariableRequirement>();
            var loc          = new CalcLocation("loc", Guid.NewGuid().ToStrGuid());
            CalcVariableRepository calcVariableRepository = new CalcVariableRepository();
            var          variableGuid = Guid.NewGuid().ToStrGuid();
            HouseholdKey key          = new HouseholdKey("hh1");
            CalcVariable cv           = new CalcVariable("varname", variableGuid, 0, loc.Name, loc.Guid, key);

            calcVariableRepository.RegisterVariable(cv);
            variables.Add(new CalcAffordanceVariableOp(cv.Name, 1, loc, VariableAction.SetTo,
                                                       VariableExecutionTime.Beginning, variableGuid));
            BitArray     isBusy = new BitArray(100, false);
            Random       rnd    = new Random();
            NormalRandom nr     = new NormalRandom(0, 1, rnd);

            using CalcRepo calcRepo = new CalcRepo(calcParameters: calcParameters, odap: new Mock <IOnlineDeviceActivationProcessor>().Object, normalRandom: nr, rnd: rnd);
            var aff = new CalcAffordance("bla", cp, loc, false, new List <CalcDesire>(), 0, 99,
                                         PermittedGender.All, false, 0.1, new ColorRGB(0, 0, 0), "bla", false, false, variables, variableReqs,
                                         ActionAfterInterruption.GoBackToOld, "bla", 100, false, "", Guid.NewGuid().ToStrGuid(),
                                         calcVariableRepository,
                                         new List <CalcAffordance.DeviceEnergyProfileTuple>(), isBusy, BodilyActivityLevel.Low, calcRepo);
            var lt       = new CalcLoadType("load", "unit1", "unit2", 1, true, Guid.NewGuid().ToStrGuid());
            var cdl      = new CalcDeviceLoad("cdl", 1, lt, 1, 0.1);
            var devloads = new List <CalcDeviceLoad> {
                cdl
            };
            CalcDeviceDto cdd = new CalcDeviceDto("device", deviceCategoryGuid, key,
                                                  OefcDeviceType.Device, "category", string.Empty,
                                                  Guid.NewGuid().ToStrGuid(), loc.Guid, loc.Name);
            var cd = new CalcDevice(devloads, loc,
                                    cdd, calcRepo);

            //loc.Variables.Add("Variable1", 0);
            aff.AddDeviceTuple(cd, cp, lt, 0, timeStep, 10, 1);
            TimeStep ts = new TimeStep(0, 0, false);

            aff.IsBusy(ts, loc, "name");
            //var variableOperator = new VariableOperator();
            aff.Activate(ts, "blub", loc, out var _);
            calcVariableRepository.GetValueByGuid(variableGuid).Should().Be(1);
        }
Exemplo n.º 3
0
 public CalcEnergyStorageSignal([NotNull] string pName, double triggerOff, double triggerOn, double value,
                                CalcVariable calcVariable, StrGuid guid) : base(pName, guid)
 {
     _triggerOffPercent = triggerOff;
     _triggerOnPercent  = triggerOn;
     _value             = value;
     _calcVariable      = calcVariable;
 }
Exemplo n.º 4
0
        public void AddCondition([NotNull] string name,
                                 [NotNull] CalcVariable variable, double minValue, double maxValue, StrGuid guid)
        {
            var cond =
                new CalcTransformationCondition(name, variable, minValue, maxValue, guid);

            _conditions.Add(cond);
        }
Exemplo n.º 5
0
 public CalcTransformationCondition([NotNull] string pName,
                                    [NotNull] CalcVariable calcVariable, double minValue,
                                    double maxValue, StrGuid guid) : base(pName, guid)
 {
     _minValue     = minValue;
     _maxValue     = maxValue;
     _calcVariable = calcVariable;
 }
        private void SetEnergyStoragesOnHouse([NotNull][ItemNotNull] List <CalcEnergyStorageDto> energyStorages,
                                              [NotNull] HouseholdKey householdKey,
                                              [NotNull] CalcHouse calchouse, CalcVariableRepository calcVariableRepository
                                              ) //, List<CalcDeviceTaggingSet> deviceTaggingSets)
        {
            var cess           = new List <CalcEnergyStorage>();
            var esCategoryGuid = Guid.NewGuid().ToStrGuid();
            var esLocGuid      = Guid.NewGuid().ToStrGuid();

            foreach (var es in energyStorages)
            {
                //foreach (DeviceTaggingSet set in deviceTaggingSets) {
                //set.AddTag(es.Name,"House Device");
                //}
                var           lti       = _ltDict.GetCalcLoadTypeByLoadtype(es.InputLoadType).ConvertToDto();
                CalcDeviceDto deviceDto = new CalcDeviceDto(es.Name, esCategoryGuid, householdKey, OefcDeviceType.Storage,
                                                            "Energy Storage", "", es.Guid, esLocGuid, "Energy Storages");
                var ces = new CalcEnergyStorage(_calcRepo.Odap,
                                                lti,
                                                es.MaximumStorageRate,
                                                es.MaximumWithdrawRate,
                                                es.MinimumStorageRate,
                                                es.MinimumWithdrawRate,
                                                es.InitialFill,
                                                es.StorageCapacity,
                                                _calcRepo.Logfile.EnergyStorageLogfile,
                                                deviceDto
                                                );
                foreach (var signal in es.Signals)
                {
                    CalcVariable cv     = calcVariableRepository.GetVariableByGuid(signal.CalcVariableDto.Guid);
                    var          cessig = new CalcEnergyStorageSignal(signal.Name,
                                                                      signal.TriggerOffPercent,
                                                                      signal.TriggerOnPercent,
                                                                      signal.Value,
                                                                      cv,
                                                                      signal.Guid);
                    ces.AddSignal(cessig);
                }

                cess.Add(ces);
                if (ces.Signals.Count != es.Signals.Count)
                {
                    throw  new LPGException("Signal not initialized correctly");
                }
            }

            var calcEnergyStorages = cess; //,deviceTaggingSets);

            calchouse.SetStorages(calcEnergyStorages);
            //return calcEnergyStorages;
        }
        public void VariableLogfileTests1()
        {
            using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass()))
            {
                wd.InputDataLogger.AddSaver(new VariableEntryLogger(wd.SqlResultLoggingService));
                wd.InputDataLogger.AddSaver(new HouseholdKeyLogger(wd.SqlResultLoggingService));
                wd.InputDataLogger.AddSaver(new ResultFileEntryLogger(wd.SqlResultLoggingService));
                CalcParameters calcParameters = CalcParametersFactory.MakeGoodDefaults().EnableShowSettlingPeriod();
                using (var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "blub", wd.InputDataLogger))
                {
                    HouseholdKey key = new HouseholdKey("hh1");
                    fft.RegisterGeneralHouse();
                    fft.RegisterHousehold(key, "householdname", HouseholdKeyType.Household, "desc", null, null);
                    DateStampCreator dsc = new DateStampCreator(calcParameters);
                    using (IOnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, calcParameters))
                    {
                        CalcVariableRepository cvr = new CalcVariableRepository();
                        //using (LogFile lf = new LogFile(calcParameters,fft, old,wd.SqlResultLoggingService, true))
                        CalcLocation cloc = new CalcLocation("loc1", Guid.NewGuid().ToStrGuid());
                        CalcVariable cv   = new CalcVariable("mycalcvar", Guid.NewGuid().ToStrGuid(),
                                                             0, cloc.Name, cloc.Guid, key);
                        cvr.RegisterVariable(cv);
                        TimeStep ts = new TimeStep(0, calcParameters);
                        old.AddVariableStatus(new CalcVariableEntry(cv.Name, cv.Guid, 1, cv.LocationName, cv.LocationGuid,
                                                                    cv.HouseholdKey, ts));
                        old.AddVariableStatus(new CalcVariableEntry(cv.Name, cv.Guid, 2, cv.LocationName, cv.LocationGuid,
                                                                    cv.HouseholdKey, ts));
                        old.AddVariableStatus(new CalcVariableEntry(cv.Name, cv.Guid, 3, cv.LocationName, cv.LocationGuid,
                                                                    cv.HouseholdKey, ts));
                        old.FinalSaveToDatabase();
                    }
                    VariableEntryLogger vel = new VariableEntryLogger(wd.SqlResultLoggingService);
                    var varEntries          = vel.Read(key);
                    foreach (CalcVariableEntry entry in varEntries)
                    {
                        Logger.Info(entry.Value.ToString(CultureInfo.InvariantCulture));
                    }
                    varEntries[0].Value.Should().Be(1);
                    varEntries[1].Value.Should().Be(2);
                    varEntries[2].Value.Should().Be(3);
                }

                /*old.
                 * cloc.Add();
                 * cloc[0].Variables.Add("trig1", 1.0);
                 * tlf.WriteLine(0, cloc);
                 * cloc[0].Variables["trig1"] = 2.0;
                 * tlf.WriteLine(1, cloc);
                 * lf.Close(null);*/
                wd.CleanUp();
            }
        }
Exemplo n.º 8
0
        public void CheckResultingProfile()
        {
            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));
            DateTime       startdate             = new DateTime(2018, 1, 1);
            DateTime       enddate               = startdate.AddMinutes(100);
            CalcParameters calculationParameters = CalcParametersFactory.MakeGoodDefaults().SetStartDate(startdate).SetEndDate(enddate).EnableShowSettlingPeriod();
            var            profile               = new CalcProfile("profile", Guid.NewGuid().ToStrGuid(), new TimeSpan(0, 1, 0), ProfileType.Relative, "blub");

            profile.AddNewTimepoint(new TimeSpan(0), 0.01);
            profile.AddNewTimepoint(new TimeSpan(1, 0, 0), 0.01);
            profile.ConvertToTimesteps();
            var cloadtype = new CalcLoadType("loadtype", "power", "sum", 1, true, Guid.NewGuid().ToStrGuid());
            var loads     = new List <CalcDeviceLoad>();
            var cdl       = new CalcDeviceLoad("cdevload", 100, cloadtype, 100, 0.1);

            loads.Add(cdl);
            var          r   = new Random(5);
            HouseholdKey key = new HouseholdKey("hh1");
            var          nr  = new NormalRandom(0, 1, r);

            using var fft = new FileFactoryAndTracker(wd.WorkingDirectory, "householdname", wd.InputDataLogger);
            fft.RegisterHousehold(key, "hh1", HouseholdKeyType.Household, "desc", null, null);
            fft.RegisterHousehold(Constants.GeneralHouseholdKey, "general", HouseholdKeyType.General, "desc", null, null);

            //SqlResultLoggingService srls = new SqlResultLoggingService(wd.WorkingDirectory);
            DateStampCreator dsc = new DateStampCreator(calculationParameters);

            using OnlineLoggingData old = new OnlineLoggingData(dsc, wd.InputDataLogger, calculationParameters);
            var odap = new OnlineDeviceActivationProcessor(old, calculationParameters, fft);

            using CalcRepo calcRepo = new CalcRepo(odap: odap, normalRandom: nr, calcParameters: calculationParameters);
            var location = new CalcLocation("calcloc", Guid.NewGuid().ToStrGuid());
            CalcVariableRepository crv = new CalcVariableRepository();
            var          variableGuid  = Guid.NewGuid().ToStrGuid();
            CalcVariable cv            = new CalcVariable("varname", variableGuid, 0, location.Name, location.Guid, key);

            crv.RegisterVariable(cv);
            VariableRequirement vreq = new VariableRequirement(cv.Name, 0, location.Name, location.Guid,
                                                               VariableCondition.Equal, crv, variableGuid);
            List <VariableRequirement> requirements = new List <VariableRequirement>
            {
                vreq
            };
            var           deviceCategoryGuid = Guid.NewGuid().ToStrGuid();
            CalcDeviceDto cdd = new CalcDeviceDto("autodevnamename", deviceCategoryGuid, key,
                                                  OefcDeviceType.AutonomousDevice, "device category", "", Guid.NewGuid().ToStrGuid(),
                                                  location.Guid, location.Name);
            var cad = new CalcAutoDev(profile, cloadtype, loads,
                                      0.8, 1, location,
                                      requirements, cdd, calcRepo);

            for (var i = 0; i < 100; i++)
            {
                TimeStep ts = new TimeStep(i, calculationParameters);
                if (!cad.IsBusyDuringTimespan(ts, 1, 0.7, cloadtype))
                {
                    cad.Activate(ts);
                }
                var rows = odap.ProcessOneTimestep(ts);
                foreach (var energyFileRow in rows)
                {
                    foreach (var energyEntry in energyFileRow.EnergyEntries)
                    {
                        Logger.Info(energyEntry.ToString(CultureInfo.CurrentCulture));
                    }
                }
            }
        }