Exemplo n.º 1
0
        public static void MakeChartsAndPDF(CalculationProfiler calculationProfiler, string resultPath)
        {
            Exception innerException = null;
            var       t = new Thread(() => {
                try
                {
                    SqlResultLoggingService srls = new SqlResultLoggingService(resultPath);
                    CalcParameterLogger cpl      = new CalcParameterLogger(srls);
                    InputDataLogger idl          = new InputDataLogger(Array.Empty <IDataSaverBase>());
                    var calcParameters           = cpl.Load();
                    Logger.Info("Checking for charting parameters");
                    if (!calcParameters.IsSet(CalcOption.MakePDF) && !calcParameters.IsSet(CalcOption.MakeGraphics))
                    {
                        Logger.Info("No charts wanted");
                        return;
                    }
                    calculationProfiler.StartPart(Utili.GetCurrentMethodAndClass() + " - Charting");

                    using (FileFactoryAndTracker fileFactoryAndTracker =
                               new FileFactoryAndTracker(resultPath, "Name", idl)) {
                        calculationProfiler.StartPart(Utili.GetCurrentMethodAndClass() + " - Chart Generator RunAll");
                        ChartCreationParameters ccp = new ChartCreationParameters(144, 1600, 1000,
                                                                                  false, calcParameters.CSVCharacter, new DirectoryInfo(resultPath));
                        var cg = new ChartGeneratorManager(calculationProfiler, fileFactoryAndTracker, ccp);
                        cg.Run(resultPath);
                        calculationProfiler.StopPart(Utili.GetCurrentMethodAndClass() + " - Chart Generator RunAll");
                        if (calcParameters.IsSet(CalcOption.MakePDF))
                        {
                            calculationProfiler.StartPart(Utili.GetCurrentMethodAndClass() + " - PDF Creation");
                            Logger.ImportantInfo(
                                "Creating the PDF. This will take a really long time without any progress report...");

                            MigraPDFCreator mpc = new MigraPDFCreator(calculationProfiler);
                            mpc.MakeDocument(resultPath, "", false, false,
                                             calcParameters.CSVCharacter, fileFactoryAndTracker);
                            calculationProfiler.StopPart(Utili.GetCurrentMethodAndClass() + " - PDF Creation");
                        }
                    }
                    Logger.Info("Finished making the charts");
                    calculationProfiler.StopPart(Utili.GetCurrentMethodAndClass() + " - Charting");
                    CalculationDurationFlameChart cdfc = new CalculationDurationFlameChart();
                    cdfc.Run(calculationProfiler, resultPath, "CalcManager");
                }
                catch (Exception ex)
                {
                    innerException = ex;
                    Logger.Exception(ex);
                }
            });

            t.SetApartmentState(ApartmentState.STA);
            t.Start();
            t.Join();
            if (innerException != null)
            {
                Logger.Error("Exception during the PDF creation!");
                Logger.Exception(innerException);
                throw innerException;
            }
        }
        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();
            }
        }
Exemplo n.º 3
0
        public void MakePlotTest()
        {
            CleanTestBase.RunAutomatically(false);
            var cs = new OxyCalculationSetup(Utili.GetCurrentMethodAndClass());

            cs.StartHousehold(2, GlobalConsts.CSVCharacter, LoadTypePriority.Mandatory,
                              configSetter: x =>
            {
                x.Enable(CalcOption.DeviceProfilesIndividualHouseholds);
                x.Enable(CalcOption.HouseholdContents);
                x.SelectedEnergyIntensity = EnergyIntensityType.EnergySavingPreferMeasured;
                x.EndDateDateTime         = new DateTime(2012, 12, 31);
            }, energyIntensity: EnergyIntensityType.EnergySavingPreferMeasured);
            using (FileFactoryAndTracker fft = new FileFactoryAndTracker(cs.DstDir, "1", cs.Wd.InputDataLogger))
            {
                fft.ReadExistingFilesFromSql();
                DeviceProfiles.DaysToMake = 365;
                CalculationProfiler     cp   = new CalculationProfiler();
                ChartCreationParameters ccps = new ChartCreationParameters(300, 4000,
                                                                           2500, false, GlobalConsts.CSVCharacter, new DirectoryInfo(cs.DstDir));
                var calcParameters = new CalcParameterLogger(cs.Wd.SqlResultLoggingService).Load();
                var aeupp          = new DeviceProfiles(ccps, fft, cp, cs.Wd.SqlResultLoggingService, calcParameters);
                Logger.Info("Making picture");
                var di  = new DirectoryInfo(cs.DstDir);
                var rfe = cs.GetRfeByFilename("DeviceProfiles.Electricity.csv");
                aeupp.MakePlot(rfe);
                Logger.Info("finished picture");
                var imagefiles = FileFinder.GetRecursiveFiles(di, "DeviceProfiles.*.png");
                imagefiles.Count.Should().BeGreaterOrEqualTo(1);
            }
            cs.CleanUp();
            CleanTestBase.RunAutomatically(true);
        }