Exemplo n.º 1
0
        public void RunPostProcessing()
        {
            _calculationProfiler.StartPart(Utili.GetCurrentMethodAndClass());
            _calculationProfiler.StartPart(Utili.GetCurrentMethodAndClass() + " - Preparation");
            if (_repository.CalcParameters.CSVCharacter.Length != 1)
            {
                throw new DataIntegrityException(
                          "The length of the CSV-Character is not 1. Please enter a single, valid character in the settings.");
            }

            /*    var deviceNamesToCategory = new Dictionary<string, string>();
             * //  foreach (var calcDevice in _repository.GetDevices().Devices)
             *  {
             *      if (!deviceNamesToCategory.ContainsKey(calcDevice.Name))
             *      {
             *          deviceNamesToCategory.Add(calcDevice.Name, calcDevice.DeviceCategoryName);
             *      }
             *  }*/
            if (_repository.HouseholdKeys.Count == 0)
            {
                throw new LPGException("No household Numbers!");
            }
            _calculationProfiler.StopPart(Utili.GetCurrentMethodAndClass() + " - Preparation");
            _calculationProfiler.StartPart(Utili.GetCurrentMethodAndClass() + " - EndOfSimulationProcessing");
            ActualFunctionCaller(_repository.CalcParameters.LoadtypesToPostprocess);
            //repository.CalculationResult.RandomSeed = _randomSeed;
            _calculationProfiler.StopPart(Utili.GetCurrentMethodAndClass() + " - EndOfSimulationProcessing");
            _calculationProfiler.StopPart(Utili.GetCurrentMethodAndClass());
        }
        public void MakeDocument([JetBrains.Annotations.NotNull] string pdfDstPath, [JetBrains.Annotations.NotNull] string calcObjectName, bool startpdf,
                                 bool requireAll, [JetBrains.Annotations.NotNull] string csvCharacter, [JetBrains.Annotations.NotNull] FileFactoryAndTracker fft)
        {
            // Create a MigraDoc document
            _calculationProfiler.StartPart(Utili.GetCurrentMethodAndClass() + " - PDF Layout");
            var document = CreateDocument(pdfDstPath, requireAll, csvCharacter);

            _calculationProfiler.StopPart(Utili.GetCurrentMethodAndClass() + " - PDF Layout");
            _calculationProfiler.StartPart(Utili.GetCurrentMethodAndClass() + " - PDF Render");
#pragma warning disable 618
            var renderer = new PdfDocumentRenderer(true, PdfFontEmbedding.Always)
#pragma warning restore 618
            {
                Document = document
            };
            Logger.ImportantInfo("Rendering the PDF. This will take a really long time without any progress report...");

            renderer.RenderDocument();
            _calculationProfiler.StopPart(Utili.GetCurrentMethodAndClass() + " - PDF Render");
            _calculationProfiler.StartPart(Utili.GetCurrentMethodAndClass() + " - PDF Cleanup");
            // Save the document...
            if (!Directory.Exists(pdfDstPath))
            {
                Directory.CreateDirectory(pdfDstPath);
            }
            var filename    = "Overview." + AutomationUtili.CleanFileName(calcObjectName) + ".pdf";
            var dstFullName = Path.Combine(pdfDstPath, filename);
            if (File.Exists(dstFullName))
            {
                File.Delete(dstFullName);
            }
            Logger.ImportantInfo("----");
            Logger.ImportantInfo(dstFullName);
            Logger.ImportantInfo("----");
            Logger.ImportantInfo("Saving the PDF...");
            renderer.PdfDocument.Save(dstFullName);
            GC.WaitForPendingFinalizers();
            GC.Collect();
            // ...and start a viewer.
            if (startpdf)
            {
                Process.Start(dstFullName);
            }
            fft.RegisterFile(filename, "Overview of all results", true, ResultFileID.PDF, Constants.GeneralHouseholdKey, TargetDirectory.Root, CalcOption.MakePDF);
            _calculationProfiler.StopPart(Utili.GetCurrentMethodAndClass() + " - PDF Cleanup");
            //return new ResultFileEntry("Overview", filename, dstFullName, true);
        }
        public FileProcessingResult MakePlot(HouseholdKeyEntry hhkey)
        {
            _calculationProfiler.StartPart(StepName);
            var result = MakeOnePlot(hhkey);

            _calculationProfiler.StopPart(StepName);
            return(result);
        }
        public FileProcessingResult MakePlot(ResultFileEntry srcResultFileEntry)
        {
            _calculationProfiler.StartPart(StepName);
            var result = MakeOnePlot(srcResultFileEntry);

            _calculationProfiler.StopPart(StepName);
            return(result);
        }
Exemplo n.º 5
0
        /*
         * [SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
         * [SuppressMessage("ReSharper", "ConvertIfStatementToSwitchStatement")]
         * private FileProcessingResult ProcessFile([JetBrains.Annotations.NotNull] ResultFileEntry entry, DirectoryInfo basisPath, string csv,
         *  FileFactoryAndTracker fft, )
         * {
         *  if (entry.LoadTypeInformation != null) {
         *      if (!entry.LoadTypeInformation.ShowInCharts) {
         *          return FileProcessingResult.NoFilesTocreate; //discard everything where the loadtype shouldnt be shown.
         *      }
         *  }
         *
         *  switch (entry.ResultFileID)
         *  {
         *
         *
         *      _calculationProfiler.StartPart(Utili.GetCurrentMethodAndClass() + " - " + ResultFileID.DeviceProfileCSV);
         *      var dp = new DeviceProfiles(parameters);
         *      if (entry.LoadTypeInformation == null)
         *      {
         *          throw new LPGException("Entry was null");
         *      }
         *      var fpr = dp.MakePlot(entry, "Device Profiles " + entry.HouseholdNumberString + " " + entry.LoadTypeInformation.Name, basisPath);
         *      _calculationProfiler.StopPart(Utili.GetCurrentMethodAndClass() + " - " + ResultFileID.DeviceProfileCSV);
         *      return fpr;
         *
         *
         *
         *
         *
         *
         *
         *      case ResultFileID.TimeOfUseEnergy:
         *          _calculationProfiler.StartPart(Utili.GetCurrentMethodAndClass() + " - " + ResultFileID.TimeOfUseEnergy);
         *          var touEnergy = new TimeOfUse(parameters,true);
         *          if (entry.LoadTypeInformation == null)
         *          {
         *              throw new LPGException("LoadTypeInformation was null");
         *          }
         *          touEnergy.MakePlot(entry, "Time of Energy Use " + entry.HouseholdNumberString + " " + entry.LoadTypeInformation.Name, basisPath);
         *          _calculationProfiler.StopPart(Utili.GetCurrentMethodAndClass() + " - " + ResultFileID.TimeOfUseEnergy);
         *          return FileProcessingResult.ShouldCreateFiles;
         *
         *
         *
         *
         *
         *      case ResultFileID.DeviceSumsPerMonth:
         *          _calculationProfiler.StartPart(Utili.GetCurrentMethodAndClass() + " - " + ResultFileID.DeviceSumsPerMonth);
         *          var ds = new DeviceSums(parameters);
         *          if (entry.LoadTypeInformation == null)
         *          {
         *              throw new LPGException("LoadTypeInformation was null");
         *          }
         *          ds.MakePlotMonthly(entry, "Device Sums Monthly" + entry.HouseholdNumberString + " " + entry.LoadTypeInformation.Name, basisPath);
         *          _calculationProfiler.StopPart(Utili.GetCurrentMethodAndClass() + " - " + ResultFileID.DeviceSumsPerMonth);
         *          return FileProcessingResult.ShouldCreateFiles;
         *
         *      case ResultFileID.SumProfileForHouseholds:
         *          _calculationProfiler.StartPart(Utili.GetCurrentMethodAndClass() + " - " + ResultFileID.SumProfileForHouseholds);
         *          var sumProfileForHouseholds = new SumProfiles(parameters);
         *          if (entry.LoadTypeInformation == null)
         *          {
         *              throw new LPGException("LoadTypeInformation was null");
         *          }
         *          sumProfileForHouseholds.MakePlot(entry, "Sum Profile for " + entry.HouseholdNumberString + " " + entry.LoadTypeInformation.Name, basisPath);
         *          _calculationProfiler.StopPart(Utili.GetCurrentMethodAndClass() + " - " + ResultFileID.SumProfileForHouseholds);
         *          return FileProcessingResult.ShouldCreateFiles;
         *      case ResultFileID.TotalsPerHousehold:
         *          return FileProcessingResult.NoFilesTocreate;
         *      case ResultFileID.ExternalSumsForHouseholds:
         *          _calculationProfiler.StartPart(Utili.GetCurrentMethodAndClass() + " - " + ResultFileID.ExternalSumsForHouseholds);
         *          var sumProfilesExternal = new SumProfilesExternal(parameters);
         *          if (entry.LoadTypeInformation == null)
         *          {
         *              throw new LPGException("LoadTypeInformation was null");
         *          }
         *          sumProfilesExternal.MakePlot(entry, "Sum Profile for " + entry.HouseholdNumberString + " " + entry.LoadTypeInformation.Name, basisPath);
         *          _calculationProfiler.StopPart(Utili.GetCurrentMethodAndClass() + " - " + ResultFileID.ExternalSumsForHouseholds);
         *          return FileProcessingResult.ShouldCreateFiles;
         *
         *      default:
         *          throw new LPGException("Failure to process file " + entry.ResultFileID + ": " + entry.FileName);
         *  }
         * }*/

        public void RunAll([JetBrains.Annotations.NotNull] string directoryName)
        {
            _calculationProfiler.StartPart(Utili.GetCurrentMethodAndClass());

            List <ResultFileEntry> entriesToProcess = _fft.ResultFileList.ResultFiles.Values.ToList();

            if (entriesToProcess.Count == 0)
            {
                throw new LPGException("Not a single file to process was found.");
            }
            foreach (var entry in entriesToProcess)
            {
                var start     = DateTime.Now;
                int prevCount = _fft.ResultFileList.ResultFiles.Count;
                // find the proper chart maker step, making sure only a single chart maker applies
                var makerStep = _chartMakerSteps.Single(x => x.IsEnabled(entry));
                //make the chart
                var result = makerStep.MakePlot(entry);
                //var processingResult =  ProcessFile(entry, di, csvCharacter,fft);
                int newcount = _fft.ResultFileList.ResultFiles.Count;
                if (result == FileProcessingResult.ShouldCreateFiles && prevCount == newcount)
                {
                    throw new LPGException("No pictures created:" + Environment.NewLine + entry.ResultFileID + Environment.NewLine + entry.FullFileName);
                }
                if (entry.Name == null)
                {
                    throw new LPGException("Name was null");
                }
                Logger.Info(
                    "Chart for " + entry.Name.PadRight(60) + "(" +
                    (DateTime.Now - start).TotalSeconds.ToString("N1", CultureInfo.CurrentCulture) + "s)");
            }

            var databases     = _srls.LoadDatabases();
            var householdKeys = _repository.HouseholdKeys;

            foreach (var db in databases)
            {
                var tables  = _srls.LoadTables(db.Key);
                var hhentry = householdKeys.Single(x => x.HHKey == db.Key);
                foreach (var table in tables)
                {
                    foreach (ISqlChartMakerStep chartMakerStep in _sqlChartMakerSteps)
                    {
                        if (chartMakerStep.IsEnabled(hhentry, table))
                        {
                            chartMakerStep.MakePlot(hhentry);
                        }
                    }
                }
            }

            _calculationProfiler.StopPart(Utili.GetCurrentMethodAndClass());
        }
        protected override void PerformActualStep(IStepParameters parameters)
        {
            var calcParameters          = _repository.CalcParameters;
            HouseholdStepParameters hhp = (HouseholdStepParameters)parameters;
            var entry = hhp.Key;

            if (entry.KeyType != HouseholdKeyType.Household)
            {
                return;
            }

            var householdKey = entry.HHKey;

            _calculationProfiler.StartPart(Utili.GetCurrentMethodAndClass());


            Logger.Info("Starting to complete list of heat gains by human activity at each time step...");

            var singletimestepEntries = _repository.ReadSingleTimestepActionEntries(householdKey)
                                        .OrderBy(x => x.TimeStep)
                                        .ToList();

            if (singletimestepEntries.Count == 0)
            {
                throw new LPGException("No file for actions each time step found");
            }
            var actionEntries = _repository.ReadActionEntries(householdKey);

            if (actionEntries.Count == 0)
            {
                throw new LPGException("");
            }
            var actionEntryDict = new Dictionary <StrGuid, ActionEntry>();

            foreach (var ae in actionEntries)
            {
                actionEntryDict.Add(ae.ActionEntryGuid, ae);
            }

            BodilyActivityLevelStatistics bals = new BodilyActivityLevelStatistics(householdKey);

            foreach (BodilyActivityLevel level in Enum.GetValues(typeof(BodilyActivityLevel)))
            {
                bals.ActivityLevels.Add(level, new List <double>(new double[calcParameters.OfficalTimesteps]));
            }
            foreach (var actionEntry in singletimestepEntries)
            {
                var ae = actionEntryDict[actionEntry.ActionEntryGuid];
                var ts = actionEntry.TimeStep;
                bals.ActivityLevels[ae.BodilyActivityLevel][ts] += 1;
            }
            _inputDataLogger.Save(householdKey, bals);
            _calculationProfiler.StopPart(Utili.GetCurrentMethodAndClass());
        }
        public void Run([JetBrains.Annotations.NotNull] string resultPath)
        {
            _calculationProfiler.StartPart(Utili.GetCurrentMethodAndClass() + " - Post Processing");
            var container = RegisterEverything(resultPath, _calculationProfiler, _fft);

            using (var scope = container.BeginLifetimeScope())
            {
                Postprocessor ps = scope.Resolve <Postprocessor>();
                ps.RunPostProcessing();
            }
            _calculationProfiler.StopPart(Utili.GetCurrentMethodAndClass() + " - Post Processing");
        }
Exemplo n.º 8
0
        public void Run([JetBrains.Annotations.NotNull] string resultPath)
        {
            _calculationProfiler.StartPart(Utili.GetCurrentMethodAndClass() + " - Post Processing");
            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 <FileFactoryAndTracker>().SingleInstance();
            builder.Register(_ => _srls).As <SqlResultLoggingService>().SingleInstance();
            builder.Register(_ => _chartCreationParameters).As <ChartCreationParameters>().SingleInstance();
            builder.RegisterType <ChartGenerator>().As <ChartGenerator>().SingleInstance();
            builder.RegisterType <CalcDataRepository>().As <CalcDataRepository>().SingleInstance();

            //general file processing steps
            builder.RegisterType <ActivityFrequenciesPerMinute>().As <IChartMakerStep>().SingleInstance();
            builder.RegisterType <ActivityPercentage>().As <IChartMakerStep>().SingleInstance();
            builder.RegisterType <AffordanceEnergyUse>().As <IChartMakerStep>().SingleInstance();
            builder.RegisterType <AffordanceTaggingSet>().As <IChartMakerStep>().SingleInstance();
            builder.RegisterType <AffordanceTimeUse>().As <IChartMakerStep>().SingleInstance();
            builder.RegisterType <CriticalThresholdViolations>().As <IChartMakerStep>().SingleInstance();
            builder.RegisterType <Desires>().As <IChartMakerStep>().SingleInstance();
            builder.RegisterType <DeviceDurationCurves>().As <IChartMakerStep>().SingleInstance();
            builder.RegisterType <DeviceProfiles>().As <IChartMakerStep>().SingleInstance();
            builder.RegisterType <DeviceProfilesExternal>().As <IChartMakerStep>().SingleInstance();
            builder.RegisterType <DeviceSums>().As <IChartMakerStep>().SingleInstance();
            builder.RegisterType <DeviceTaggingSet>().As <IChartMakerStep>().SingleInstance();
            builder.RegisterType <DurationCurve>().As <IChartMakerStep>().SingleInstance();
            builder.RegisterType <ExecutedActionsOverviewCount>().As <IChartMakerStep>().SingleInstance();
            builder.RegisterType <LocationStatistics>().As <IChartMakerStep>().SingleInstance();
            builder.RegisterType <HouseholdPlan>().As <IChartMakerStep>().SingleInstance();
            builder.RegisterType <SumProfiles>().As <IChartMakerStep>().SingleInstance();
            builder.RegisterType <SumProfilesExternal>().As <IChartMakerStep>().SingleInstance();
            builder.RegisterType <Temperatures>().As <IChartMakerStep>().SingleInstance();
            builder.RegisterType <TimeOfUse>().As <IChartMakerStep>().SingleInstance();
            builder.RegisterType <VariableLogFileChart>().As <IChartMakerStep>().SingleInstance();
            builder.RegisterType <WeekdayProfiles>().As <IChartMakerStep>().SingleInstance();
            builder.RegisterType <NoOpChart>().As <IChartMakerStep>().SingleInstance();

            //sql steps
            builder.RegisterType <AffordanceEnergyUsePerPerson>().As <ChartBaseSqlStep>().SingleInstance();
            var container = builder.Build();

            using (var scope = container.BeginLifetimeScope())
            {
                ChartGenerator ps = scope.Resolve <ChartGenerator>();
                ps.RunAll(resultPath);
            }
            _calculationProfiler.StopPart(Utili.GetCurrentMethodAndClass() + " - Post Processing");
        }
Exemplo n.º 9
0
        protected override void PerformActualStep(IStepParameters parameters)
        {
            var calcParameters          = _repository.CalcParameters;
            HouseholdStepParameters hhp = (HouseholdStepParameters)parameters;
            var entry = hhp.Key;

            if (entry.KeyType != HouseholdKeyType.Household)
            {
                return;
            }

            var householdKey = entry.HHKey;

            _calculationProfiler.StartPart(Utili.GetCurrentMethodAndClass());


            Logger.Info("Starting to complete list of actions for each person at each time step for statistical analysis...");
            var displayNegativeTime = calcParameters.ShowSettlingPeriodTime;

            var activitiesPerPerson = ReadActivities(householdKey);

            //var fileIdx = 0;
            if (activitiesPerPerson.Count == 0)
            {
                throw new LPGException("There were no activities for any person in the household " + householdKey.Key);
            }

            List <SingleTimestepActionEntry> allSteps = new List <SingleTimestepActionEntry>();

            foreach (var personActivities in activitiesPerPerson)
            {
                Logger.Info("Starting to generate the carpet plot for " + personActivities.Key.Name + "...");
                var times = MakeTimeArray(displayNegativeTime, personActivities.Value);
                allSteps.AddRange(times);
            }
            _inputDataLogger.SaveList(allSteps.ConvertAll(x => (IHouseholdKey)x));
            _calculationProfiler.StopPart(Utili.GetCurrentMethodAndClass());
        }
        protected override void PerformActualStep(IStepParameters parameters)
        {
            HouseholdStepParameters hhp = (HouseholdStepParameters)parameters;
            var entry = hhp.Key;

            if (entry.KeyType != HouseholdKeyType.Household)
            {
                return;
            }

            var householdKey = entry.HHKey;

            _calculationProfiler.StartPart(Utili.GetCurrentMethodAndClass());


            Logger.Info("Starting to complete list of actions for each person at each time step for statistical analysis...");

            var activitiesPerPerson = ReadActivities(householdKey);

            //var fileIdx = 0;
            if (activitiesPerPerson.Count == 0)
            {
                throw new LPGException("There were no activities for any person in the household " + householdKey.Key);
            }

            var affs           = ReadActivities(householdKey);
            var sactionEntries = _repository.ReadSingleTimestepActionEntries(householdKey);
            Dictionary <BodilyActivityLevel, List <int> > personCountByActivity = new Dictionary <BodilyActivityLevel, List <int> >();

            foreach (BodilyActivityLevel bal in Enum.GetValues(typeof(BodilyActivityLevel)))
            {
                personCountByActivity.Add(bal, new List <int>(new int[_repository.CalcParameters.OfficalTimesteps]));
            }
            foreach (var singleTimestepActionEntry in sactionEntries)
            {
                var aff = affs[singleTimestepActionEntry.ActionEntryGuid];
                personCountByActivity[aff.BodilyActivityLevel][singleTimestepActionEntry.TimeStep]++;
            }

            foreach (var pair in personCountByActivity)
            {
                JsonSumProfile jsp = new JsonSumProfile("Person Count for Activity Level " + pair.Key.ToString() + " " + householdKey.Key,
                                                        Repository.CalcParameters.InternalStepsize, Repository.CalcParameters.OfficialStartTime,
                                                        "Person Count for  - " + pair.Key.ToString(), "",
                                                        null, hhp.Key);
                foreach (var val in pair.Value)
                {
                    jsp.Values.Add(val);
                }

                var sumfile = _fft.MakeFile <StreamWriter>("BodilyActivityLevel." + pair.Key + "." + householdKey.Key + ".json",
                                                           "Bodily Activity Level for " + pair.Key + " in the household " + householdKey.Key,
                                                           true, ResultFileID.BodilyActivityJsons, householdKey,
                                                           TargetDirectory.Results, Repository.CalcParameters.InternalStepsize, CalcOption.BodilyActivityStatistics, null, null,
                                                           pair.Key.ToString());
                sumfile.Write(JsonConvert.SerializeObject(jsp, Formatting.Indented));
                sumfile.Flush();
            }

            _calculationProfiler.StopPart(Utili.GetCurrentMethodAndClass());
        }