public HouseDeviceProfileFileProcessor([NotNull] IFileFactoryAndTracker fft,
                                        [NotNull] CalcDataRepository repository,
                                        [NotNull] ICalculationProfiler profiler) : base(repository, AutomationUtili.GetOptionList(CalcOption.DeviceProfilesHouse),
                                                                                        profiler, "House Device Profiles")
 {
     _fft = fft;
 }
        private void Run([NotNull] CalcLoadTypeDto dstLoadType, [NotNull][ItemNotNull] List <OnlineEnergyFileRow> energyFileRows,
                         [NotNull] IFileFactoryAndTracker fft)
        {
            var calcParameters     = Repository.CalcParameters;
            var dailyValues        = new Dictionary <int, Dictionary <int, double> >();
            var dailyValuesbyMonth =
                new Dictionary <int, Dictionary <int, Dictionary <int, double> > >();
            var dailyValuesbySeason =
                new Dictionary <int, Dictionary <int, double> >();
            var dayCount = new Dictionary <DayOfWeek, int>();

            var seasonDayCount = new Dictionary <int, int>();

            ReadFile(energyFileRows, dailyValues, dailyValuesbyMonth, dailyValuesbySeason, dayCount, seasonDayCount);

            var resultfile = fft.MakeFile <StreamWriter>("WeekdayProfiles." + dstLoadType.Name + ".csv",
                                                         "Averaged profiles for each weekday for " + dstLoadType.Name, true,
                                                         ResultFileID.WeekdayLoadProfileID, Constants.GeneralHouseholdKey, TargetDirectory.Reports,
                                                         calcParameters.InternalStepsize, CalcOption.WeekdayProfiles,
                                                         dstLoadType.ConvertToLoadTypeInformation());
            var valuecount = WriteNormalPart(dstLoadType, resultfile, dailyValues, dayCount);

            WriteByMonth(resultfile, dailyValuesbyMonth, valuecount);
            WriteBySeason(resultfile, valuecount, dailyValuesbySeason, seasonDayCount);
            resultfile.Flush();
            resultfile.Close();
        }
Example #3
0
 public IndividualHouseholdJsonSumProfileProcessor([NotNull] CalcDataRepository repository,
                                                   [NotNull] IFileFactoryAndTracker fft,
                                                   [NotNull] ICalculationProfiler calculationProfiler) : base(
         repository,
         AutomationUtili.GetOptionList(CalcOption.JsonHouseholdSumFiles),
         calculationProfiler,
         "Individual Household Json Sum Profiles") =>
Example #4
0
 public DurationCurveMaker([NotNull] CalcDataRepository repository,
                           [NotNull] ICalculationProfiler calculationProfiler,
                           [NotNull] IFileFactoryAndTracker fft)
     : base(repository, AutomationUtili.GetOptionList(CalcOption.DurationCurve), calculationProfiler, "Duration Curves")
 {
     _fft = fft;
 }
 public WeekdayLoadProfileMaker(
     [NotNull] IFileFactoryAndTracker fft,
     [NotNull] CalcDataRepository repository,
     [NotNull] ICalculationProfiler profiler
     ) : base(repository, AutomationUtili.GetOptionList(CalcOption.WeekdayProfiles), profiler, "Weekday Profiles")
 {
     _fft = fft;
 }
Example #6
0
 public TransportationDeviceJson([JetBrains.Annotations.NotNull] ICalculationProfiler calculationProfiler,
                                 [JetBrains.Annotations.NotNull] CalcDataRepository repository,
                                 [JetBrains.Annotations.NotNull] IFileFactoryAndTracker fft
                                 ) : base(repository, AutomationUtili.GetOptionList(CalcOption.TansportationDeviceJsons), calculationProfiler,
                                          "Transportation Device Statistics as Json", 10)
 {
     _fft = fft;
 }
Example #7
0
 public HouseSumProfilesFromDetailedDatsProcessor([NotNull] IFileFactoryAndTracker fft,
                                                  [NotNull] CalcDataRepository repository,
                                                  [NotNull] ICalculationProfiler profiler)
     : base(repository, AutomationUtili.GetOptionList(CalcOption.HouseSumProfilesFromDetailedDats),
            profiler, "Individual Sum Profiles")
 {
     _fft = fft;
 }
 public TimeOfUseMaker(
     [NotNull] CalcDataRepository repository,
     [NotNull] ICalculationProfiler profiler,
     [NotNull] IFileFactoryAndTracker fft) : base(repository,
                                                  AutomationUtili.GetOptionList(CalcOption.TimeOfUsePlot), profiler, "Time of Use Averages")
 {
     _fft = fft;
 }
 public MakeActivationsPerHour([NotNull] CalcDataRepository repository,
                               [NotNull] ICalculationProfiler profiler,
                               [NotNull] IFileFactoryAndTracker fft) : base(repository,
                                                                            AutomationUtili.GetOptionList(CalcOption.ActivationsPerHour),
                                                                            profiler,
                                                                            "Activiations per Hour", 0)
 {
     _fft = fft;
 }
Example #10
0
 public ExternalTimeResolutionMaker([NotNull] IFileFactoryAndTracker fft,
                                    [NotNull] CalcDataRepository repository,
                                    [NotNull] ICalculationProfiler calculationProfiler) : base(repository,
                                                                                               AutomationUtili.GetOptionList(CalcOption.SumProfileExternalEntireHouse, CalcOption.SumProfileExternalIndividualHouseholds,
                                                                                                                             CalcOption.DeviceProfileExternalEntireHouse, CalcOption.DeviceProfileExternalIndividualHouseholds,
                                                                                                                             CalcOption.SumProfileExternalIndividualHouseholdsAsJson), calculationProfiler, "External Time Resolution Profiles")
 {
     _fft = fft;
 }
 public ImportFileCreatorPolysun([NotNull] CalcDataRepository repository,
                                 [NotNull] ICalculationProfiler profiler,
                                 [NotNull] IFileFactoryAndTracker fft) : base(repository,
                                                                              AutomationUtili.GetOptionList(CalcOption.PolysunImportFiles),
                                                                              profiler,
                                                                              "Polysun Import Files")
 {
     _fft = fft;
 }
 public LocationStatisticsMaker([JetBrains.Annotations.NotNull] IFileFactoryAndTracker fft,
                                [JetBrains.Annotations.NotNull] CalcDataRepository repository,
                                [JetBrains.Annotations.NotNull] ICalculationProfiler profiler) : base(repository,
                                                                                                      AutomationUtili.GetOptionList(CalcOption.LocationsFile),
                                                                                                      profiler, "Location Statistics", 0)
 {
     _fft = fft;
     MakeStreamWriterFunc = GetWriter;
 }
Example #13
0
 public MakeHouseholdPlanResult(
     [NotNull] CalcDataRepository repository,
     [NotNull] ICalculationProfiler profiler,
     [NotNull] IFileFactoryAndTracker fft) : base(repository,
                                                  AutomationUtili.GetOptionList(CalcOption.HouseholdPlan),
                                                  profiler, "Household Plans", 0)
 {
     _fft = fft;
 }
 public BodilyActivityLevelsStatistics([NotNull] ICalculationProfiler calculationProfiler,
                                       [NotNull] CalcDataRepository repository,
                                       IFileFactoryAndTracker fft) : base(repository,
                                                                          AutomationUtili.GetOptionList(CalcOption.BodilyActivityStatistics), calculationProfiler,
                                                                          "Make Bodily Activity Level Counts", 10)
 {
     _repository          = repository;
     _fft                 = fft;
     _calculationProfiler = calculationProfiler;
 }
 public MakeActivationsPerFrequencies([NotNull] IFileFactoryAndTracker fft,
                                      [NotNull] CalcDataRepository repository,
                                      [NotNull] ICalculationProfiler profiler,
                                      [NotNull] IInputDataLogger logger) : base(repository,
                                                                                AutomationUtili.GetOptionList(CalcOption.ActivationFrequencies),
                                                                                profiler,
                                                                                "Activation Frequency Analysis", 0)
 {
     _dataLogger = logger;
     _fft        = fft;
 }
        /*
         * public void RunIndividualHouseholdsPolysun([JetBrains.Annotations.NotNull] CalcLoadTypeDto dstLoadType,
         *  [JetBrains.Annotations.NotNull][ItemNotNull] List<OnlineEnergyFileRow> energyFileRows, [JetBrains.Annotations.NotNull] FileFactoryAndTracker fft, [JetBrains.Annotations.NotNull] EnergyFileColumns efc)
         * {
         *  var fifteenmin = new TimeSpan(0, 15, 0);
         *  var externalfactor =
         *      (int) (fifteenmin.TotalSeconds / _calcParameters.InternalStepsize.TotalSeconds);
         *  if (externalfactor == 1) {
         *      return;
         *  }
         *  var externalFileName = fifteenmin.TotalSeconds.ToString(CultureInfo.InvariantCulture);
         *  var householdNumbers =
         *      (efc.ColumnEntriesByColumn[dstLoadType].Values.Select(entry => entry.HouseholdKey)).Distinct()
         *      .ToList();
         *  var householdNames = Repository.HouseholdKeys;
         *  Dictionary<HouseholdKey, string> householdNamesByKey = new Dictionary<HouseholdKey, string>();
         *  foreach (HouseholdKeyEntry entry in householdNames) {
         *      householdNamesByKey.Add(entry.HouseholdKey,entry.HouseholdName);
         *  }
         *  if (householdNumbers.Count > 1) {
         *      foreach (var hhnum in householdNumbers) {
         *          if (!householdNamesByKey.ContainsKey(hhnum)) {
         *              continue;
         *          }
         *          var columns =
         *          (from entry in efc.ColumnEntriesByColumn[dstLoadType].Values
         *              where entry.HouseholdKey == hhnum
         *              select entry.Column).ToList();
         *          var hhname = "." + hhnum + ".";
         *
         *          var sumfile =
         *              fft.MakeFile<StreamWriter>(
         *                  "ImportProfile_" + externalFileName + "s" + hhname + dstLoadType.Name + ".csv",
         *                  "Summed up energy profile without timestamp for " + externalFileName + "s " +
         *                  dstLoadType.Name + " and HH" + hhnum, true,
         *                  ResultFileID.PolysunImportFileHH, hhnum, TargetDirectory.Results, fifteenmin,
         *                  dstLoadType.ConvertToLoadTypeInformation());
         *          WritePolysunHeader(sumfile, householdNamesByKey[hhnum], dstLoadType);
         *          var timestepcount = 0;
         *          var ts = TimeSpan.Zero;
         *          for (var outerIndex = 0; outerIndex < energyFileRows.Count; outerIndex += externalfactor) {
         *              var efr = energyFileRows[outerIndex];
         *              if (!efr.Timestep.DisplayThisStep) {
         *                  continue;
         *              }
         *              double sum = 0;
         *
         *              for (var innerIndex = outerIndex;
         *                  innerIndex < outerIndex + externalfactor && innerIndex < energyFileRows.Count;
         *                  innerIndex++) {
         *                  var efr2 = energyFileRows[innerIndex];
         *                  sum += efr2.GetSumForCertainCols(columns);
         *                  timestepcount++;
         *                  ts = ts.Add(_calcParameters.InternalStepsize);
         *              }
         *              sum = sum * dstLoadType.ConversionFactor;
         *              var normalstr = ts.TotalSeconds + _calcParameters.CSVCharacter +
         *                              sum.ToString("N4", CultureInfo.InvariantCulture);
         *              sumfile.WriteLine(normalstr);
         *          }
         *          if (timestepcount != energyFileRows.Count) {
         *              throw new LPGException("Importfilecreator seems to be broken! Please report!");
         *          }
         *      }
         *  }
         * }*/

        public void RunPolysun([NotNull] CalcLoadTypeDto dstLoadType,
                               [NotNull][ItemNotNull] List <OnlineEnergyFileRow> energyFileRows,
                               [NotNull] IFileFactoryAndTracker fft,
                               [NotNull] string housename)
        {
            var calcParameters = Repository.CalcParameters;
            var fifteenMin     = new TimeSpan(0, 15, 0);
            var externalfactor = (int)(fifteenMin.TotalSeconds / calcParameters.InternalStepsize.TotalSeconds);

            if (externalfactor == 1)
            {
                return;
            }

            var externalFileName = fifteenMin.TotalSeconds.ToString(CultureInfo.InvariantCulture);
            var sumfile          = fft.MakeFile <StreamWriter>("ImportProfile." + externalFileName + "s." + dstLoadType.Name + ".csv",
                                                               "Sum energy profile with timestamp for import in Polysun " + externalFileName + "s " + dstLoadType.Name,
                                                               true,
                                                               ResultFileID.PolysunImportFile,
                                                               Constants.GeneralHouseholdKey,
                                                               TargetDirectory.Results,
                                                               fifteenMin, CalcOption.PolysunImportFiles,
                                                               dstLoadType.ConvertToLoadTypeInformation());
            //var count = energyFileRows[0].EnergyEntries.Count;
            var ts = TimeSpan.Zero;

            //var timestepcount = 0;
            WritePolysunHeader(sumfile, housename, dstLoadType);

            for (var outerIndex = 0; outerIndex < energyFileRows.Count; outerIndex += externalfactor)
            {
                var efrOuter = energyFileRows[outerIndex];
                if (!efrOuter.Timestep.DisplayThisStep)
                {
                    continue;
                }

                double sum = 0;
                for (var innerIndex = outerIndex; innerIndex < outerIndex + externalfactor && innerIndex < energyFileRows.Count; innerIndex++)
                {
                    var efr2 = energyFileRows[innerIndex];
                    sum += efr2.SumCached;
                    //      timestepcount++;
                }

                var sumPower  = sum * dstLoadType.ConversionFactor; // change to power
                var normalstr = ts.TotalSeconds + calcParameters.CSVCharacter + sumPower.ToString("N8", CultureInfo.InvariantCulture);
                sumfile.WriteLine(normalstr);
            }
            //  if (timestepcount != energyFileRows.Count) { //this does not consider the hidden time steps
            //    throw new LPGException("Importfilecreator seems to be broken! Please report!");
            //}
            sumfile.Flush();
        }
 public MakeTotalsPerDevice([NotNull] CalcDataRepository repository,
                            [NotNull] ICalculationProfiler profiler,
                            [NotNull] IFileFactoryAndTracker fft,
                            IInputDataLogger inputDataLogger) : base(repository,
                                                                     AutomationUtili.GetOptionList(CalcOption.TotalsPerDevice),
                                                                     profiler,
                                                                     "Totals per Device")
 {
     _inputDataLogger = inputDataLogger;
     _fft             = fft;
 }
Example #18
0
        private void Run(
            [NotNull] Dictionary <StrGuid, Dictionary <string, double> >
            energyByAffordanceByLoadTypeByHousehold, [NotNull] string householdName, [NotNull][ItemNotNull] List <CalcHouseholdPlanDto> householdPlans,
            [NotNull] IFileFactoryAndTracker fft, [NotNull] HouseholdKey householdKey,
            [NotNull] Dictionary <string, Dictionary <string, Dictionary <string, int> > > affordanceTaggingSetByPersonByTagTimeUse,
            [NotNull] Dictionary <string, Dictionary <string, Dictionary <string, int> > >
            affordanceTaggingSetByPersonByTagExecutionCount)
        {
            var fileNumberTracker =
                new Dictionary <Tuple <HouseholdKey, int>, StreamWriter>();

            RunTimePerAffordance(affordanceTaggingSetByPersonByTagTimeUse, householdName, householdPlans, fft,
                                 householdKey, fileNumberTracker);
            RunExecutionTimes(affordanceTaggingSetByPersonByTagExecutionCount, householdName, householdPlans,
                              householdKey, fileNumberTracker);
            RunEnergyPerAffordance(energyByAffordanceByLoadTypeByHousehold, householdName, householdPlans,
                                   householdKey, fileNumberTracker);
        }
Example #19
0
 public Postprocessor(
     [NotNull] ICalculationProfiler calculationProfiler,
     [NotNull] CalcDataRepository repository,
     [NotNull][ItemNotNull] ILoadTypeStep[] loadTypePostProcessingSteps,
     [NotNull][ItemNotNull] IGeneralStep[] generalPostProcessingSteps,
     [NotNull][ItemNotNull] IGeneralHouseholdStep[] generalHouseholdSteps,
     [NotNull][ItemNotNull] IHouseholdLoadTypeStep[] householdloadTypePostProcessingSteps,
     [NotNull][ItemNotNull] ILoadTypeSumStep[] loadtypeSumPostProcessingSteps,
     [NotNull] IFileFactoryAndTracker fft
     )
 {
     _loadTypeSumPostProcessingSteps = loadtypeSumPostProcessingSteps;
     _fft = fft;
     _calculationProfiler                  = calculationProfiler;
     _repository                           = repository;
     _loadTypePostProcessingSteps          = loadTypePostProcessingSteps;
     _generalPostProcessingSteps           = generalPostProcessingSteps;
     _generalHouseholdSteps                = generalHouseholdSteps;
     _householdloadTypePostProcessingSteps = householdloadTypePostProcessingSteps;
 }
 public HouseSumProfileFromOverallDatProcessor([NotNull] CalcDataRepository repository,
                                               [NotNull] IFileFactoryAndTracker fft,
                                               [NotNull] ICalculationProfiler calculationProfiler)
     : base(repository, AutomationUtili.GetOptionList(CalcOption.OverallSum), calculationProfiler,
            "Sum Profile Creation") =>
        private void Run([JetBrains.Annotations.NotNull] IFileFactoryAndTracker fft, [JetBrains.Annotations.NotNull] HouseholdKey householdKey)
        {
            var calcParameters  = Repository.CalcParameters;
            var locationEntries = Repository.LoadLocationEntries(householdKey);
            var maxTimeStep     = calcParameters.OfficalTimesteps;

            if (maxTimeStep == 0)
            {
                throw new LPGException("Timesteps was not initialized");
            }

            var distinctLocations = locationEntries.Select(x => x.LocationGuid).Distinct().ToList();
            var locLookup         = new Dictionary <StrGuid, byte>();

            for (byte i = 0; i < distinctLocations.Count; i++)
            {
                locLookup.Add(distinctLocations[i], i);
            }

            var distinctPersonGuids = locationEntries.Select(x => x.PersonGuid).Distinct().ToList();
            var locationArray       = new byte[maxTimeStep];
            var sw = MakeStreamWriterFunc(fft, householdKey, calcParameters);

            foreach (var person in distinctPersonGuids)
            {
                var  filteredEntries = locationEntries.Where(x => x.PersonGuid == person).ToList();
                byte lastLocation    = 0;
                for (var i = 0; i < maxTimeStep; i++)
                {
                    if (filteredEntries.Count > 0 && filteredEntries[0].Timestep.InternalStep == i)
                    {
                        lastLocation = locLookup[filteredEntries[0].LocationGuid];
                        filteredEntries.RemoveAt(0);
                    }

                    locationArray[i] = lastLocation;
                }

                var timeUseByLoc = new Dictionary <byte, int>();
                for (byte i = 0; i < locLookup.Count; i++)
                {
                    timeUseByLoc.Add(i, 0);
                }

                for (var i = 0; i < maxTimeStep; i++)
                {
                    timeUseByLoc[locationArray[i]]++;
                }

                sw.WriteLine("-----");
                sw.WriteLine(person);
                for (byte i = 0; i < distinctLocations.Count; i++)
                {
                    var distinctLocationGuid = distinctLocations[i];
                    var distinctLocation     = locationEntries.FirstOrDefault(x => x.LocationGuid == distinctLocationGuid)?.LocationName;
                    var s = distinctLocation + calcParameters.CSVCharacter;
                    var timestepsSpent = timeUseByLoc[i];
                    var percentage     = timestepsSpent / (double)maxTimeStep;
                    s += timestepsSpent + calcParameters.CSVCharacter;
                    s += percentage + calcParameters.CSVCharacter;
                    sw.WriteLine(s);
                }
            }

            sw.Close();
        }
 private static StreamWriter GetWriter([JetBrains.Annotations.NotNull] IFileFactoryAndTracker fft, [JetBrains.Annotations.NotNull] HouseholdKey householdKey,
                                       [JetBrains.Annotations.NotNull] CalcParameters calcParameters) => fft
 .MakeFile <StreamWriter>("LocationStatistics." + householdKey + ".csv",
                          "How much time the people are spending at each Location", true, ResultFileID.LocationStatistic,
                          householdKey, TargetDirectory.Reports, calcParameters.InternalStepsize, CalcOption.LocationsFile);
Example #23
0
        private void RunTimePerAffordance(
            [NotNull]
            Dictionary <string, Dictionary <string, Dictionary <string, int> > > affordanceTaggingSetByPersonByTagTimeUse,
            [NotNull] string householdName, [NotNull][ItemNotNull] List <CalcHouseholdPlanDto> householdPlans,
            [NotNull] IFileFactoryAndTracker fft,
            [NotNull] HouseholdKey householdKey,
            [NotNull] Dictionary <Tuple <HouseholdKey, int>, StreamWriter> fileNumberTracker)
        {
            var calcParameters = Repository.CalcParameters;
            var simduration    = calcParameters.OfficialEndTime -
                                 calcParameters.OfficialStartTime;
            var timefactor = 8760 / simduration.TotalHours;

            foreach (var calcHouseholdPlan in householdPlans)
            {
                if (householdName.StartsWith(calcHouseholdPlan.HouseholdName, StringComparison.Ordinal))
                {
                    var cleanedName = AutomationUtili.CleanFileName(calcHouseholdPlan.Name).Replace(".", "_");
                    var fileName    = "HouseholdPlan.Times." + cleanedName + "." + householdKey + ".csv";

                    var fileNumber = fileNumberTracker.Count;

                    var sw = fft.MakeFile <StreamWriter>(fileName,
                                                         "Comparison of the household plan and the reality", true,
                                                         ResultFileID.HouseholdPlanTime, householdKey, TargetDirectory.Reports,
                                                         calcParameters.InternalStepsize, CalcOption.HouseholdPlan, null, null,
                                                         calcHouseholdPlan.Name + "_" + fileNumber);

                    sw.WriteLine("##### Time per Affordance #####");

                    fileNumberTracker.Add(new Tuple <HouseholdKey, int>(householdKey, calcHouseholdPlan.ID), sw);
                    var timeByTagByPerson =
                        affordanceTaggingSetByPersonByTagTimeUse[calcHouseholdPlan.TaggingSetName];
                    foreach (var personTagList in timeByTagByPerson)
                    {
                        var personName = personTagList.Key;
                        sw.WriteLine("----- Time Use for " + personName + " -----");
                        var c = calcParameters.CSVCharacter;
                        sw.WriteLine("Tag" + c + "Time in Simulation [h]" + c + "Time in Simulation for 365d [h]" + c +
                                     "Planned time");
                        var timePerTag        = personTagList.Value;
                        var plannedTimePerTag =
                            calcHouseholdPlan.PersonTagTimeUsePlan[personName];
                        var plannedWithOthers = new Dictionary <string, TimeSpan>();
                        foreach (var keyValuePair in plannedTimePerTag)
                        {
                            plannedWithOthers.Add(keyValuePair.Key, keyValuePair.Value);
                        }

                        foreach (var keyValuePair in timePerTag)
                        {
                            if (!plannedWithOthers.ContainsKey(keyValuePair.Key))
                            {
                                plannedWithOthers.Add(keyValuePair.Key, new TimeSpan(0));
                            }
                        }

                        foreach (var keyValuePair in plannedWithOthers)
                        {
                            var    s = keyValuePair.Key + c;
                            double realValueHours = 0;
                            if (timePerTag.ContainsKey(keyValuePair.Key))
                            {
                                var minutes = timePerTag[keyValuePair.Key];
                                realValueHours = minutes / 60.0;
                            }

                            s += realValueHours + c;
                            s += realValueHours * timefactor + c;
                            s += keyValuePair.Value.TotalHours + c;
                            double percentage = -1;
                            if (Math.Abs(keyValuePair.Value.TotalHours) > Constants.Ebsilon)
                            {
                                percentage = realValueHours / keyValuePair.Value.TotalHours;
                            }

                            s += percentage;
                            if (Math.Abs(realValueHours) > Constants.Ebsilon ||
                                Math.Abs(keyValuePair.Value.TotalSeconds) > Constants.Ebsilon)
                            {
                                sw.WriteLine(s);
                            }
                        }
                    }

                    // found a plan
                }
            }
        }
        public static IContainer RegisterEverything(string resultPath, [JetBrains.Annotations.NotNull] ICalculationProfiler calculationProfiler, [JetBrains.Annotations.CanBeNull] IFileFactoryAndTracker fft)
        {
            var builder = new ContainerBuilder();

            builder.Register(_ => new SqlResultLoggingService(resultPath)).As <SqlResultLoggingService>().SingleInstance();
            //builder.Register(c =>_logFile).As<ILogFile>().SingleInstance();
            builder.Register(_ => calculationProfiler).As <ICalculationProfiler>().SingleInstance();
            builder.Register(_ => fft).As <IFileFactoryAndTracker>().SingleInstance();
            builder.RegisterType <Postprocessor>().As <Postprocessor>().SingleInstance();
            builder.RegisterType <CalcDataRepository>().As <CalcDataRepository>().SingleInstance();
            builder.RegisterType <OptionDependencyManager>().SingleInstance();

            //general processing steps
            builder.RegisterType <AffordanceTagsWriter>().As <IGeneralStep>().SingleInstance();

            //general household steps
            builder.RegisterType <MakeActivationsPerFrequencies>().As <IGeneralHouseholdStep>().SingleInstance();
            builder.RegisterType <MakeActivationsPerHour>().As <IGeneralHouseholdStep>().SingleInstance();
            builder.RegisterType <BodilyActivityLevelsStatistics>().As <IGeneralHouseholdStep>().SingleInstance();
            builder.RegisterType <MakeHouseholdPlanResult>().As <IGeneralHouseholdStep>().SingleInstance();
            builder.RegisterType <MakeBodilyActivityLevelStatistics>().As <IGeneralHouseholdStep>().SingleInstance();
            //builder.RegisterType<ActionCarpetPlot>().As<IGeneralHouseholdStep>().SingleInstance();
            builder.RegisterType <MakeActionsEachTimestep>().As <IGeneralHouseholdStep>().SingleInstance();
            builder.RegisterType <LocationStatisticsMaker>().As <IGeneralHouseholdStep>().SingleInstance();
            builder.RegisterType <AffordanceStatisticsWriter>().As <IHouseholdLoadTypeStep>().SingleInstance();
            builder.RegisterType <TransportationDeviceJson>().As <IGeneralHouseholdStep>().SingleInstance();
            //builder.RegisterType<LocationCarpetPlot>().As<IGeneralHouseholdStep>().SingleInstance();
            //builder.RegisterType<TransportationDeviceCarpetPlot>().As<IGeneralHouseholdStep>().SingleInstance();
            builder.RegisterType <TransportationStatisticsWriter>().As <IGeneralHouseholdStep>().SingleInstance();
            //builder.RegisterType<AffordanceStatisticsWriter>().As<IGeneralPostProcessingStep>().SingleInstance();

            //loadtypesteps
            builder.RegisterType <HouseSumProfileFromOverallDatProcessor>().As <ILoadTypeSumStep>().SingleInstance();
            builder.RegisterType <HouseJsonSumProfileProcessor>().As <ILoadTypeStep>().SingleInstance();
            builder.RegisterType <HouseSumProfilesFromDetailedDatsProcessor>().As <ILoadTypeStep>().SingleInstance();
            builder.RegisterType <IndividualHouseholdSumProfileProcessor>().As <IHouseholdLoadTypeStep>().SingleInstance();
            builder.RegisterType <IndividualHouseholdDeviceProfileProcessor>().As <IHouseholdLoadTypeStep>().SingleInstance();
            builder.RegisterType <IndividualHouseholdJsonSumProfileProcessor>().As <IHouseholdLoadTypeStep>().SingleInstance();
            builder.RegisterType <IndividualHouseholdDeviceProfileJsonProcessor>().As <IHouseholdLoadTypeStep>().SingleInstance();
            builder.RegisterType <HouseDeviceProfileFileProcessor>().As <ILoadTypeStep>().SingleInstance();
            //builder.RegisterType<EnergyCarpetPlotMaker>().As<ILoadTypeStep>().SingleInstance();
            builder.RegisterType <ExternalTimeResolutionMaker>().As <ILoadTypeStep>().SingleInstance();
            //builder.RegisterType<ImportFileCreatorSMA>().As<ILoadTypeStep>().SingleInstance();
            builder.RegisterType <ImportFileCreatorPolysun>().As <ILoadTypeStep>().SingleInstance();
            builder.RegisterType <TimeOfUseMaker>().As <ILoadTypeStep>().SingleInstance();
            builder.RegisterType <MakeTotalsPerLoadtype>().As <ILoadTypeStep>().SingleInstance();
            builder.RegisterType <DurationCurveMaker>().As <ILoadTypeStep>().SingleInstance();
            builder.RegisterType <MakeTotalsPerDevice>().As <IHouseholdLoadTypeStep>().SingleInstance();
            builder.RegisterType <WeekdayLoadProfileMaker>().As <ILoadTypeStep>().SingleInstance();

            //logger
            builder.RegisterType <InputDataLogger>().As <IInputDataLogger>().SingleInstance();
            builder.RegisterType <TotalsPerLoadtypeEntryLogger>().As <IDataSaverBase>().SingleInstance();
            builder.RegisterType <TotalsPerDeviceLogger>().As <IDataSaverBase>().SingleInstance();
            builder.RegisterType <BodilyActivityLevelStatisticsLogger>().As <IDataSaverBase>().SingleInstance();
            builder.RegisterType <PersonAffordanceInformationLogger>().As <IDataSaverBase>().SingleInstance();
            builder.RegisterType <SingleTimestepActionEntryLogger>().As <IDataSaverBase>().SingleInstance();
            builder.RegisterType <AffordanceEnergyUseLogger>().As <IDataSaverBase>();
            builder.RegisterType <TransportationDeviceStatisticsLogger>().As <IDataSaverBase>();
            builder.RegisterType <TransportationRouteStatisticsLogger>().As <IDataSaverBase>();
            builder.RegisterType <TransportationDeviceEventStatisticsLogger>().As <IDataSaverBase>();
            var container = builder.Build();

            return(container);
        }
        private void BuildActivationsPerHours([NotNull] IFileFactoryAndTracker fft,
                                              [NotNull] HouseholdKey householdKey,
                                              [NotNull][ItemNotNull] List <CalcAffordanceTaggingSetDto> taggingSets,
                                              [NotNull][ItemNotNull] List <ActionEntry> actionEntries)
        {
            var calcParameters       = Repository.CalcParameters;
            var activitiesPerHour    = new Dictionary <string, Dictionary <string, int[]> >();
            var activitiesPerWeekday = new Dictionary <string, Dictionary <string, int[]> >();

            foreach (ActionEntry ase in actionEntries)
            {
                if (!activitiesPerHour.ContainsKey(ase.PersonName))
                {
                    activitiesPerHour.Add(ase.PersonName, new Dictionary <string, int[]>());
                    activitiesPerWeekday.Add(ase.PersonName, new Dictionary <string, int[]>());
                }

                if (!activitiesPerHour[ase.PersonName].ContainsKey(ase.AffordanceName))
                {
                    activitiesPerHour[ase.PersonName].Add(ase.AffordanceName, new int[24]);
                    activitiesPerWeekday[ase.PersonName].Add(ase.AffordanceName, new int[7]);
                }

                var hour    = ase.DateTime.Hour;
                var weekday = (int)ase.DateTime.DayOfWeek;
                activitiesPerHour[ase.PersonName][ase.AffordanceName][hour]++;
                activitiesPerWeekday[ase.PersonName][ase.AffordanceName][weekday]++;
            }

            using (var sw = fft.MakeFile <StreamWriter>("ActivationsPerHour." + householdKey + ".csv",
                                                        "Activations per hour",
                                                        true,
                                                        ResultFileID.ActivationsPerHour,
                                                        householdKey,
                                                        TargetDirectory.Reports,
                                                        calcParameters.InternalStepsize, CalcOption.ActivationsPerHour)) {
                foreach (var person in activitiesPerHour)
                {
                    sw.WriteLine(person.Key);
                    var s = new StringBuilder();
                    s.Append("Hour").Append(calcParameters.CSVCharacter);
                    for (var i = 0; i < 24; i++)
                    {
                        s.Append(i).Append(calcParameters.CSVCharacter);
                    }

                    sw.WriteLine(s);
                    var sb = new StringBuilder();
                    foreach (var device in person.Value)
                    {
                        sb.Clear();
                        sb.Append(device.Key);
                        for (var i = 0; i < 24; i++)
                        {
                            sb.Append(calcParameters.CSVCharacter);
                            sb.Append(device.Value[i].ToString(CultureInfo.InvariantCulture));
                        }

                        sw.WriteLine(sb);
                    }
                }
            }

            using (var sw = fft.MakeFile <StreamWriter>("ExecutedActionsOverviewCount." + householdKey + ".csv",
                                                        "Overview of the executed actions",
                                                        true,
                                                        ResultFileID.ExecutedActionsOverview,
                                                        householdKey,
                                                        TargetDirectory.Reports,
                                                        calcParameters.InternalStepsize, CalcOption.ActivationsPerHour)) {
                foreach (var person in activitiesPerHour)
                {
                    sw.WriteLine("-----");
                    sw.WriteLine(person.Key);
                    var header = new StringBuilder();
                    header.Append("Actions").Append(calcParameters.CSVCharacter).Append("Times of execution in the simulation period")
                    .Append(calcParameters.CSVCharacter);
                    foreach (var weekday in Enum.GetValues(typeof(DayOfWeek)))
                    {
                        header.Append(weekday).Append(calcParameters.CSVCharacter);
                    }

                    foreach (var set in taggingSets)
                    {
                        header.Append(set.Name).Append(calcParameters.CSVCharacter);
                    }

                    sw.WriteLine(header);
                    var alllines = new List <List <string> >();
                    foreach (var device in person.Value)
                    {
                        var elements = new List <string> {
                            device.Key
                        };
                        var total = 0;
                        for (var i = 0; i < 24; i++)
                        {
                            total += device.Value[i];
                        }

                        elements.Add(total.ToString(Config.CultureInfo));
                        foreach (var weekday in Enum.GetValues(typeof(DayOfWeek)))
                        {
                            elements.Add(activitiesPerWeekday[person.Key][device.Key][(int)weekday].ToString(Config.CultureInfo));
                        }

                        foreach (var set in taggingSets)
                        {
                            elements.Add(set.AffordanceToTagDict[device.Key]);
                        }

                        alllines.Add(elements);
                    }

                    alllines.Sort(Comparison);
                    foreach (var allline in alllines)
                    {
                        var builder = new StringBuilder();
                        foreach (var s1 in allline)
                        {
                            builder.Append(s1).Append(calcParameters.CSVCharacter);
                        }

                        sw.WriteLine(builder);
                    }
                }
            }
        }
 public HouseJsonSumProfileProcessor([NotNull] CalcDataRepository repository,
                                     [NotNull] IFileFactoryAndTracker fft,
                                     [NotNull] ICalculationProfiler calculationProfiler)
     : base(repository, AutomationUtili.GetOptionList(CalcOption.JsonHouseSumFiles), calculationProfiler,
            "Json Sum Profile Creation") =>
        private void MakeTotalsPerDeviceTaggingSet([NotNull] IFileFactoryAndTracker fft,
                                                   [NotNull] CalcLoadTypeDto dstLoadType,
                                                   [ItemNotNull][NotNull] List <DeviceTaggingSetInformation> deviceTaggingSets,
                                                   [NotNull] Dictionary <string, double> deviceEnergyDict,
                                                   [NotNull] HouseholdKey hhkey)
        {
            var calcParameters = Repository.CalcParameters;

            using (var file = fft.MakeFile <StreamWriter>("DeviceTaggingSet." + dstLoadType.FileName + "." + hhkey.Key + ".csv",
                                                          "Summed up energy use into the AffordanceToCategories in the device tagging sets for " + dstLoadType.Name,
                                                          true,
                                                          ResultFileID.DeviceTaggingSetFiles,
                                                          hhkey,
                                                          TargetDirectory.Reports,
                                                          calcParameters.InternalStepsize, CalcOption.TotalsPerDevice,
                                                          dstLoadType.ConvertToLoadTypeInformation())) {
                foreach (var tagSet in deviceTaggingSets)
                {
                    file.WriteLine("-----");
                    file.WriteLine(tagSet.Name);
                    var    energyUsePerTag = new Dictionary <string, double>();
                    double sum             = 0;
                    foreach (var keyValuePair in deviceEnergyDict)
                    {
                        var device = keyValuePair.Key;
                        if (!tagSet.TagByDeviceName.ContainsKey(device))
                        {
                            tagSet.TagByDeviceName.Add(device, device);
                        }

                        var tag = tagSet.TagByDeviceName[device];
                        if (!energyUsePerTag.ContainsKey(tag))
                        {
                            energyUsePerTag.Add(tag, 0);
                        }

                        energyUsePerTag[tag] += keyValuePair.Value;
                        sum += keyValuePair.Value;
                    }

                    file.WriteLine("Tag" + calcParameters.CSVCharacter + "Energy Used [" + dstLoadType.UnitOfSum + "]" +
                                   calcParameters.CSVCharacter + "Percentage" + calcParameters.CSVCharacter + "Reference Value" +
                                   calcParameters.CSVCharacter);

                    foreach (var tag in energyUsePerTag)
                    {
                        var referenceValue = string.Empty;
                        var key            = DeviceTaggingSetInformation.MakeKey(dstLoadType.Name, tag.Key);
                        if (tagSet.ReferenceValues.ContainsKey(key))
                        {
                            referenceValue = tagSet.ReferenceValues[key].ToString(Config.CultureInfo);
                        }

                        file.WriteLine(tag.Key + calcParameters.CSVCharacter + tag.Value * dstLoadType.ConversionFactor +
                                       calcParameters.CSVCharacter + (tag.Value / sum).ToString("0.0000", Config.CultureInfo) +
                                       calcParameters.CSVCharacter + referenceValue + calcParameters.CSVCharacter);
                    }

                    file.WriteLine();
                    file.WriteLine("Sum" + calcParameters.CSVCharacter + sum * dstLoadType.ConversionFactor + calcParameters.CSVCharacter + "1" +
                                   calcParameters.CSVCharacter);
                }
            }
        }
        private void Run([NotNull] CalcLoadTypeDto dstLoadType,
                         [NotNull][ItemNotNull] List <OnlineEnergyFileRow> energyFileRows,
                         [NotNull] IFileFactoryAndTracker fft,
                         [NotNull] EnergyFileColumns efc,
                         [NotNull] Dictionary <CalcLoadTypeDto, Dictionary <StrGuid, double> > loadTypeTodeviceIDToAverageLookup,
                         [ItemNotNull][NotNull] List <DeviceTaggingSetInformation> deviceTaggingSets,
                         [NotNull] Dictionary <string, string> deviceNameToCategory,
                         [NotNull] Dictionary <string, double> deviceEnergyDict,
                         [NotNull] HouseholdKey key)
        {
            if (!efc.ColumnEntriesByColumn.ContainsKey(dstLoadType))
            {
                //for this load type for this house there are no column, so nothing to do
                return;
            }
            var calcParameters = Repository.CalcParameters;
            var rowlength      = energyFileRows[0].EnergyEntries.Count;
            var ts             = new TimeStep(0, 0, true);
            var sum            = new OnlineEnergyFileRow(ts, new List <double>(new double[rowlength]), dstLoadType);
            var curDate        = calcParameters.OfficialStartTime;
            var sumsPerMonth   = MakeSumsPerMonth(dstLoadType, energyFileRows, curDate, sum, rowlength);

            /*
             * if (Config.IsInUnitTesting && Config.ExtraUnitTestChecking) {
             *  if (!double.IsNaN(previousTotal) && Math.Abs(sum.SumFresh - previousTotal) > 0.000001) {
             *      throw new LPGException("Unknown bug while generating the device totals. Sums don't match.");
             *  }
             * }*/
            var sumPerMonthPerDeviceID = MakeSumPerMonthPerDeviceID(dstLoadType, efc, sumsPerMonth, out var columns);

            var sumsPerDeviceID  = new Dictionary <StrGuid, double>();
            var deviceNamesPerID = new Dictionary <StrGuid, string>();
            var sumPerDeviceName = new Dictionary <string, double>();

            foreach (var pair in columns)
            {
                var ce = pair.Value;
                if (!sumsPerDeviceID.ContainsKey(ce.DeviceGuid))
                {
                    sumsPerDeviceID.Add(ce.DeviceGuid, 0);
                    deviceNamesPerID.Add(ce.DeviceGuid, ce.Name);
                }

                if (!sumPerDeviceName.ContainsKey(ce.Name))
                {
                    sumPerDeviceName.Add(ce.Name, 0);
                }

                sumPerDeviceName[ce.Name]      += sum.EnergyEntries[pair.Key];
                sumsPerDeviceID[ce.DeviceGuid] += sum.EnergyEntries[pair.Key];
            }

            MakeTotalsPerDeviceTaggingSet(fft, dstLoadType, deviceTaggingSets, deviceEnergyDict, key);
            var builder = new StringBuilder();

            foreach (var calcDeviceTaggingSet in deviceTaggingSets)
            {
                if (calcDeviceTaggingSet.LoadTypesForThisSet.Any(x => x.Name == dstLoadType.Name))
                {
                    builder.Append(calcDeviceTaggingSet.Name).Append(calcParameters.CSVCharacter);
                }
            }

            var taggingsetHeader = builder.ToString();
            var devicesums       = fft.MakeFile <StreamWriter>("DeviceSums." + dstLoadType.Name + "." + key.Key + ".csv",
                                                               "Summed up " + dstLoadType.Name + " use per device and comparison with statistical values",
                                                               true,
                                                               ResultFileID.DeviceSums,
                                                               key,
                                                               TargetDirectory.Reports,
                                                               calcParameters.InternalStepsize, CalcOption.TotalsPerDevice,
                                                               dstLoadType.ConvertToLoadTypeInformation());
            var calcDuration  = calcParameters.OfficialEndTime - calcParameters.OfficialStartTime;
            var amountofYears = calcDuration.TotalDays / 365.0;
            var sb            = new StringBuilder();

            sb.Append("Device name");
            sb.Append(calcParameters.CSVCharacter);
            sb.Append("Usage sum in this simulation [").Append(dstLoadType.UnitOfSum).Append("]");
            sb.Append(calcParameters.CSVCharacter);
            sb.Append("Usage sum in this simulation linear extrapolated to 1 year [").Append(dstLoadType.UnitOfSum).Append("]");
            sb.Append(calcParameters.CSVCharacter);

            sb.Append("Comparison Value from the device entry [").Append(dstLoadType.UnitOfSum).Append("]");
            sb.Append(calcParameters.CSVCharacter);
            sb.Append("Percentage of the comparison value [1 = 100%]");
            sb.Append(calcParameters.CSVCharacter);
            sb.Append("Device Category");
            sb.Append(calcParameters.CSVCharacter);
            sb.Append(taggingsetHeader);

            devicesums.WriteLine(sb);
            double devicesum           = 0;
            double extrapolatedSum     = 0;
            double comparsionvaluessum = 0;

            foreach (var keyValuePair in sumsPerDeviceID)
            {
                var s = string.Empty;
                s += deviceNamesPerID[keyValuePair.Key];

                s         += calcParameters.CSVCharacter;
                s         += keyValuePair.Value * dstLoadType.ConversionFactor;
                devicesum += keyValuePair.Value;

                //deviceSums.AddDeviceSum(deviceNamesPerID[keyValuePair.Key],devicesum,dstLoadType);

                s += calcParameters.CSVCharacter;
                var extrapolatedValue = keyValuePair.Value * dstLoadType.ConversionFactor / amountofYears;
                s += extrapolatedValue;
                extrapolatedSum += keyValuePair.Value / amountofYears;

                s += calcParameters.CSVCharacter;
                double defaultvalue = 0;
                if (loadTypeTodeviceIDToAverageLookup.ContainsKey(dstLoadType))
                {
                    if (loadTypeTodeviceIDToAverageLookup[dstLoadType].ContainsKey(keyValuePair.Key))
                    {
                        defaultvalue = loadTypeTodeviceIDToAverageLookup[dstLoadType][keyValuePair.Key];
                    }
                }

                s += defaultvalue;
                comparsionvaluessum += defaultvalue;
                s += calcParameters.CSVCharacter;
                if (Math.Abs(defaultvalue) > Constants.Ebsilon)
                {
                    s += extrapolatedValue / defaultvalue;
                }
                else
                {
                    s += 0;
                }

                s += calcParameters.CSVCharacter;
                var devicename     = deviceNamesPerID[keyValuePair.Key];
                var deviceCategory = "(no category)";
                if (deviceNameToCategory.ContainsKey(devicename))
                {
                    deviceCategory = deviceNameToCategory[devicename];
                }

                s += deviceCategory;
                s += calcParameters.CSVCharacter;
                var tags = string.Empty;
                foreach (var calcDeviceTaggingSet in deviceTaggingSets)
                {
                    if (calcDeviceTaggingSet.LoadTypesForThisSet.Any(x => x.Name == dstLoadType.Name))
                    {
                        var deviceName = deviceNamesPerID[keyValuePair.Key];
                        if (calcDeviceTaggingSet.TagByDeviceName.ContainsKey(deviceName))
                        {
                            tags += calcDeviceTaggingSet.TagByDeviceName[deviceName] + calcParameters.CSVCharacter;
                        }
                        else
                        {
                            tags += Constants.UnknownTag + calcParameters.CSVCharacter;
                        }
                    }
                }

                devicesums.WriteLine(s + tags);
            }

            var sumstr = "Sums";

            sumstr += calcParameters.CSVCharacter;
            sumstr += devicesum * dstLoadType.ConversionFactor;
            sumstr += calcParameters.CSVCharacter;
            sumstr += extrapolatedSum * dstLoadType.ConversionFactor;
            sumstr += calcParameters.CSVCharacter;
            sumstr += comparsionvaluessum;
            devicesums.WriteLine(sumstr);
            devicesums.Flush();
            WriteMonthlyDeviceSums(fft, dstLoadType, sumPerMonthPerDeviceID, deviceNamesPerID, key);
        }
Example #29
0
 public AffordanceTagsWriter([JetBrains.Annotations.NotNull] CalcDataRepository repository, [JetBrains.Annotations.NotNull] ICalculationProfiler calculationProfiler,
                             [JetBrains.Annotations.NotNull] IFileFactoryAndTracker fft)
     : base(repository, AutomationUtili.GetOptionList(CalcOption.HouseholdContents), calculationProfiler, "Affordance Tags", 0)
 {
     _fft = fft;
 }
        private void WriteMonthlyDeviceSums([NotNull] IFileFactoryAndTracker fft,
                                            [NotNull] CalcLoadTypeDto dstLoadType,
                                            [NotNull] Dictionary <StrGuid, Dictionary <int, double> > values,
                                            [NotNull] Dictionary <StrGuid, string> deviceNamesPerID,
                                            [NotNull] HouseholdKey key)
        {
            var calcParameters = Repository.CalcParameters;
            var devicesums     = fft.MakeFile <StreamWriter>("DeviceSums_Monthly." + dstLoadType.Name + "." + key.Key + ".csv",
                                                             "Summed up " + dstLoadType.Name + " use per device per Month",
                                                             true,
                                                             ResultFileID.DeviceSumsPerMonth,
                                                             key,
                                                             TargetDirectory.Reports,
                                                             calcParameters.InternalStepsize, CalcOption.TotalsPerDevice,
                                                             dstLoadType.ConvertToLoadTypeInformation());

            var sb = new StringBuilder();

            sb.Append("Device name");
            sb.Append(calcParameters.CSVCharacter);
            var firstmonth = values.Keys.First();

            foreach (var monthAndValue in values[firstmonth])
            {
                sb.Append(monthAndValue.Key);
                sb.Append(calcParameters.CSVCharacter);
            }

            devicesums.WriteLine(sb);
            var monthSums = new Dictionary <int, double>();

            foreach (var keyValuePair in values)
            {
                var s = string.Empty;
                s += deviceNamesPerID[keyValuePair.Key];
                s += calcParameters.CSVCharacter;

                foreach (var monthValue in keyValuePair.Value)
                {
                    s += monthValue.Value * dstLoadType.ConversionFactor + calcParameters.CSVCharacter;
                    if (!monthSums.ContainsKey(monthValue.Key))
                    {
                        monthSums.Add(monthValue.Key, 0);
                    }

                    monthSums[monthValue.Key] += monthValue.Value;
                }

                devicesums.WriteLine(s);
            }

            var sumstr = "Sums" + calcParameters.CSVCharacter;

            foreach (var keyValuePair in monthSums)
            {
                sumstr += keyValuePair.Value * dstLoadType.ConversionFactor + calcParameters.CSVCharacter;
            }

            devicesums.WriteLine(sumstr);
            devicesums.Flush();
        }