Ejemplo n.º 1
0
        public static string GetResultArchiveDirectory([NotNull] ScenarioSliceParameters slice,
                                                       DateTime startingTime,
                                                       [NotNull] RunningConfig config,
                                                       RelativeDirectory relativeDir,
                                                       [CanBeNull] string chapter)
        {
            string date     = FilenameHelpers.CleanFileName(startingTime.ToString("yyyy-MM-dd"));
            string scenario = slice.GetFileName();

            if (slice.SmartGridEnabled)
            {
                scenario += "smart";
            }

            string resultArchiveDirectory = Path.Combine(config.Directories.ResultStorageDirectory, date, scenario, relativeDir.ToString());

            if (chapter != null)
            {
                resultArchiveDirectory = Path.Combine(config.Directories.ResultStorageDirectory,
                                                      "Abschlussbericht",
                                                      date,
                                                      "Kapitel " + chapter,
                                                      scenario);
            }

            if (!Directory.Exists(resultArchiveDirectory))
            {
                Directory.CreateDirectory(resultArchiveDirectory);
                Thread.Sleep(250);
            }

            return(resultArchiveDirectory);
        }
Ejemplo n.º 2
0
        public WorkingDirectory([NotNull] Logger logger, [NotNull] RunningConfig config) : base(logger, Stage.Preparation, nameof(WorkingDirectory))
        {
            string baseDir       = Path.Combine(config.Directories.BaseProcessingDirectory, "unittests");
            string callingMethod = GetCallingMethodAndClass();

            Info("Base dir: " + baseDir);
            Info("Calling Method: " + callingMethod);
            Dir = Path.Combine(baseDir, FilenameHelpers.CleanFileName(callingMethod));
            Info("Used Directory: " + Dir);
            DirDi = new DirectoryInfo(Dir);
            if (DirDi.Exists)
            {
                try {
                    DirDi.Delete(true);
                }
#pragma warning disable CA1031 // Do not catch general exception types
                catch (Exception ex) {
#pragma warning restore CA1031 // Do not catch general exception types
                    logger.ErrorM(ex.Message, Stage.Preparation, nameof(WorkingDirectory));
                }

                Thread.Sleep(250);
            }

            DirDi.Create();
            Thread.Sleep(250);
        }
        private void WriteSumLineToCsv([NotNull] Prosumer p, [NotNull] string trafokreis, GenerationOrLoad generationOrLoad)
        {
            string       tkFileName            = FilenameHelpers.CleanFileName(trafokreis);
            var          csvFileNameGeneration = Path.Combine(_processingResultPathForProfiles, tkFileName + "." + generationOrLoad + ".csv");
            StreamWriter sw = new StreamWriter(csvFileNameGeneration, true);

            sw.WriteLine(p.GetCSVLine());
            sw.Close();
        }
        protected override void RunActualProcess([NotNull] ScenarioSliceParameters slice)
        {
            var fnX = MakeAndRegisterFullFilename(FilenameHelpers.CleanFileName("ExportForAllProviderTypesXlsDumper") + ".xlsx", slice);

            ProcessOneSumTypeWithXls(slice, fnX, SumType.ByProvider);
            var fn = MakeAndRegisterFullFilename(FilenameHelpers.CleanFileName("ExportForAllProviderTypes") + ".xlsx", slice);

            ProcessOneSumType(slice, fn, SumType.ByProvider);
            var fn2 = MakeAndRegisterFullFilename(FilenameHelpers.CleanFileName("ExportForAllProfileSources") + ".xlsx", slice);

            ProcessOneSumType(slice, fn2, SumType.ByProfileSource);
        }
        protected override void RunActualProcess([NotNull] ScenarioSliceParameters slice)
        {
            if (!Services.RunningConfig.MakeExcelPerTrafokreis)
            {
                return;
            }

            var dbArchive = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.ProfileGeneration, slice, DatabaseCode.SummedLoadForAnalysis);
            var saHouses  = SaveableEntry <ArchiveEntry> .GetSaveableEntry(dbArchive, SaveableEntryTableType.SummedHouseProfiles, Services.Logger);

            string         currentTrafokreis = "";
            ExcelWorksheet ws;
            int            columnIdx = 1;
            ExcelPackage   p         = new ExcelPackage();

            ws = p.Workbook.Worksheets.Add("sheet1");
            foreach (var house in saHouses.ReadEntireTableDBAsEnumerable("Trafokreis"))
            {
                if (currentTrafokreis != house.Trafokreis && !string.IsNullOrWhiteSpace(currentTrafokreis))
                {
                    var fn = MakeAndRegisterFullFilename(FilenameHelpers.CleanFileName(currentTrafokreis) + ".xlsx", slice);
                    // ReSharper disable once PossibleNullReferenceException
                    p.SaveAs(new FileInfo(fn));
                    SaveToArchiveDirectory(fn, RelativeDirectory.Trafokreise, slice);
                    p.Dispose();
                    p         = new ExcelPackage();
                    ws        = p.Workbook.Worksheets.Add(currentTrafokreis);
                    columnIdx = 2;
                }

                currentTrafokreis = house.Trafokreis;
                // ReSharper disable once PossibleNullReferenceException
                ws.Cells[1, columnIdx].Value = house.Name;
                int rowIdx = 2;
                for (int i = 0; i < house.Profile.Values.Count; i++)
                {
                    ws.Cells[rowIdx, columnIdx].Value = house.Profile.Values[i];
                    rowIdx++;
                }

                columnIdx++;
            }

            var fn2 = MakeAndRegisterFullFilename(FilenameHelpers.CleanFileName(currentTrafokreis) + ".xlsx", slice);

            // ReSharper disable once PossibleNullReferenceException
            p.SaveAs(new FileInfo(fn2));
            SaveToArchiveDirectory(fn2, RelativeDirectory.Trafokreise, slice);

            p.Dispose();
        }
        protected override void RunActualProcess([NotNull] ScenarioSliceParameters slice)
        {
            var fn        = MakeAndRegisterFullFilename(FilenameHelpers.CleanFileName("SummedLoadProfileExport.xlsx"), slice);
            var dbArchive = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.ProfileGeneration, slice, DatabaseCode.SummedLoadForAnalysis);
            var saHouses  = SaveableEntry <ArchiveEntry> .GetSaveableEntry(dbArchive, SaveableEntryTableType.SummedLoadsForAnalysis, Services.Logger);

            var            dbRaw           = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Raw, Constants.PresentSlice);
            var            bkwArr          = dbRaw.Fetch <BkwProfile>();
            var            bkwjSonProfile  = bkwArr[0];
            var            entries         = saHouses.LoadAllOrMatching();
            var            providerentries = entries.Where(x => x.Key.SumType == SumType.ByProvider).ToList();
            List <Profile> profiles        = new List <Profile>();

            foreach (var providerentry in providerentries)
            {
                providerentry.Profile.Name = (providerentry.Key.ProviderType ?? throw new FlaException()) + " " + providerentry.Key.GenerationOrLoad;
                if (providerentry.Key.GenerationOrLoad == GenerationOrLoad.Load)
                {
                    profiles.Add(providerentry.Profile);
                }
                else
                {
                    profiles.Add(providerentry.Profile.MultiplyWith(-1, providerentry.Profile.Name));
                }
            }

            profiles = MergeProfiles(profiles);
            var bkwProfile = new Profile(bkwjSonProfile.Profile);

            bkwProfile.Name = "Messung 2017 [kW]";
            profiles.Add(bkwProfile);
            XlsxDumper.DumpProfilesToExcel(fn, slice.DstYear, 15, new ProfileWorksheetContent("Profiles", "Last [kW]", bkwProfile.Name, profiles));
            SaveToArchiveDirectory(fn, RelativeDirectory.Report, slice);
            SaveToPublicationDirectory(fn, slice, "4.4");
            SaveToPublicationDirectory(fn, slice, "5");
            Info("saved " + fn);
        }
Ejemplo n.º 7
0
        private void MakeChartForOneVerbrauchsart(Verbrauchsart vba,
                                                  double factor,
                                                  [NotNull] string unit,
                                                  [NotNull][ItemNotNull] List <MonthlyElectricityUsePerStandort> energyusePerStandort,
                                                  [NotNull] MyDb db)
        {
            var path = db.GetResultFullPath(SequenceNumber, Name);
            var energyUseByTarifAndMonth = new Dictionary <string, Dictionary <int, double> >();

            foreach (var perStandort in energyusePerStandort)
            {
                var dict = GetDictForVerbrauch(perStandort, vba);
                foreach (var tarifValues in dict)
                {
                    if (!energyUseByTarifAndMonth.ContainsKey(tarifValues.Key))
                    {
                        energyUseByTarifAndMonth.Add(tarifValues.Key, new Dictionary <int, double>());
                        for (var i = 1; i < 13; i++)
                        {
                            energyUseByTarifAndMonth[tarifValues.Key].Add(i, 0);
                        }
                    }

                    foreach (var monthlyValues in tarifValues.Value)
                    {
                        energyUseByTarifAndMonth[tarifValues.Key][monthlyValues.Key] += monthlyValues.Value / factor;
                    }
                }
            }

            //anzahl gebäude
            var bses    = new List <BarSeriesEntry>();
            var dstPath = Path.Combine(path, "allData." + vba + ".csv");

            using (var sw = new StreamWriter(dstPath)) {
                var sb = new StringBuilder();
                //header
                foreach (var tarifValues in energyUseByTarifAndMonth)
                {
                    sb.Append(tarifValues.Key).Append(";");
                }

                sw.WriteLine(sb);
                for (var i = 1; i < 13; i++)
                {
                    sb = new StringBuilder();
                    foreach (var tarifValues in energyUseByTarifAndMonth)
                    {
                        sb.Append(tarifValues.Value[i]).Append(";");
                    }

                    sw.WriteLine(sb);
                }

                sw.Close();
            }

            foreach (var tarifValues in energyUseByTarifAndMonth)
            {
                var bse = new BarSeriesEntry(tarifValues.Key);
                bse.Values.Add(0);
                for (var i = 0; i < 12; i++)
                {
                    bse.Values.Add(tarifValues.Value[i + 1]);
                }

                bses.Add(bse);
                var singleTarif = new List <BarSeriesEntry> {
                    bse
                };
                Services.PlotMaker.MakeBarChart(Path.Combine(path, "MonthlyUse." + vba + "." + FilenameHelpers.CleanFileName(bse.Name) + ".png"),
                                                "Strom [kWh]",
                                                singleTarif,
                                                new List <string>());
            }

            Services.PlotMaker.MakeBarChart(Path.Combine(path, "MonthlyUse." + vba + ".png"), "Strom [" + unit + "]", bses, new List <string>());
        }