public void AddNewStateMachine(TimeStep startTimeStep, CalcLoadTypeDto loadType, string affordanceName, string activatorName, OefcKey oefckey, [NotNull] CalcDeviceDto calcDeviceDto, [NotNull] StepValues sv) { Oefc.IsDeviceRegistered(loadType, oefckey); //OefcKey oefckey = new OefcKey(householdKey, deviceType, deviceID, locationID, loadType.ID); // this is for logging the used time profiles which gets dumped to the time profile log ProfileActivationEntry.ProfileActivationEntryKey key = new ProfileActivationEntry.ProfileActivationEntryKey(calcDeviceDto.Name, sv.Name, sv.DataSource, loadType.Name); if (!_profileEntries.ContainsKey(key)) { ProfileActivationEntry entry = new ProfileActivationEntry(calcDeviceDto.Name, sv.Name, sv.DataSource, loadType.Name, _calcParameters); _profileEntries.Add(entry.GenerateKey(), entry); } _profileEntries[key].ActivationCount++; // do the device activiation var columnNumber = Oefc.GetColumnNumber(loadType, oefckey); var dsm = new OnlineDeviceStateMachine(startTimeStep, loadType, calcDeviceDto.Name, oefckey, affordanceName, _calcParameters, sv, columnNumber); //_statemachines.Add(dsm); _stateMachinesByLoadtype[loadType].Add(dsm); // log the affordance energy use. if (_calcParameters.IsSet(CalcOption.DeviceActivations)) { double totalPowerSum = dsm.CalculateOfficialEnergyUse(); double totalEnergysum = loadType.ConversionFactor * totalPowerSum; var entry = new DeviceActivationEntry(dsm.AffordanceName, dsm.LoadType, totalEnergysum, activatorName, sv.Values.Count, startTimeStep, calcDeviceDto); // dsm.StepValues.ToArray(), _old.RegisterDeviceActivation(entry); } }
public void CalcParameterLoggerTest() { CalcParameters cp = CalcParameters.GetNew(); cp.SetStartDate(2017, 1, 1); cp.SetEndDate(2018, 1, 1); cp.Enable(CalcOption.ActivationsPerHour); using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass())) { SqlResultLoggingService srls = new SqlResultLoggingService(wd.WorkingDirectory); CalcParameterLogger cpl = new CalcParameterLogger(srls); cpl.Run(Constants.GeneralHouseholdKey, cp); GC.Collect(); GC.WaitForPendingFinalizers(); CalcParameters cp2 = cpl.Load(); GC.Collect(); GC.WaitForPendingFinalizers(); string s1 = JsonConvert.SerializeObject(cp, Formatting.Indented); string s2 = JsonConvert.SerializeObject(cp2, Formatting.Indented); s1.Should().Be(s2); cp2.IsSet(CalcOption.ActivationsPerHour).Should().BeTrue(); Assert.NotNull(cp2); wd.CleanUp(); } }
public override void Run(HouseholdKey key, object o) { TemperatureProfile tp = (TemperatureProfile)o; var tempProfile = tp.GetTemperatureArray(_calcParameters.InternalStartTime, _calcParameters.OfficialEndTime, _calcParameters.InternalStepsize); DateStampCreator dsc = new DateStampCreator(_calcParameters); if (!_calcParameters.IsSet(CalcOption.TemperatureFile)) { return; } // var allTemperatures = new List<UsedTemperatures>(); SaveableEntry se = new SaveableEntry(key, ResultTableDefinition); se.AddField("Timestep", SqliteDataType.Integer); se.AddField("DateTime", SqliteDataType.Text); se.AddField("Temperature", SqliteDataType.Double); for (var i = 0; i < _calcParameters.OfficalTimesteps; i++) { string timestamp = dsc.MakeDateStringFromTimeStep(new TimeStep(i, 0, false)); se.AddRow(RowBuilder.Start("Timestep", i).Add("DateTime", timestamp).Add("Temperature", tempProfile[i]).ToDictionary()); } _srls.SaveResultEntry(se); }
public void AddPersonStatus(PersonStatus ps) { if (!_calcParameters.IsSet(CalcOption.PersonStatus)) { return; } _personStatus.Add(ps); }
public MyColumn([JetBrains.Annotations.NotNull] string name, int column, [CanBeNull] DeviceTaggingSetInformation taggingSet, [JetBrains.Annotations.NotNull] DirectoryInfo basisPath, [JetBrains.Annotations.NotNull] FileFactoryAndTracker fft, CalcParameters parameters) { Tag = ""; RawName = name; Column = column; if (name.Contains(" [")) { var deviceWithRoom = name.Substring(name.IndexOf(" - ", StringComparison.Ordinal) + 3); deviceWithRoom = deviceWithRoom.Substring(0, deviceWithRoom.IndexOf(" [", StringComparison.Ordinal)).Trim(); var device = deviceWithRoom.Substring(deviceWithRoom.IndexOf(" - ", StringComparison.Ordinal) + 3).Trim(); try { if (taggingSet == null) { throw new LPGException("Tagging set was null"); } if (parameters.IsSet(CalcOption.HouseholdContents) && !taggingSet.TagByDeviceName.ContainsKey(device)) { var fileName = Path.Combine(basisPath.FullName, "missingCategories.txt"); if (!fft.CheckForFile(ResultFileID.MissingTags, Constants.GeneralHouseholdKey)) { fft.RegisterFile(fileName, "Devices that are missing device tags", false, ResultFileID.MissingTags, Constants.GeneralHouseholdKey, TargetDirectory.Root, CalcOption.HouseholdContents); } taggingSet.TagByDeviceName.Add(device, "Other"); using (var sw = new StreamWriter(fileName, true)) { sw.WriteLine(device); } Logger.Error("Missing entry in the device tagging set " + taggingSet.Name + " for the device " + device); } } catch (Exception ex) { Logger.Error( "Couldn't write to missing categories file: " + basisPath + " Error message was:" + ex.Message); Logger.Exception(ex); } if (taggingSet == null) { throw new LPGException("Tagging set was null"); } Tag = taggingSet.TagByDeviceName[device]; } }