public void RunTest()
        {
            using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass()))
            {
                HouseholdKeyLogger    ael    = new HouseholdKeyLogger(wd.SqlResultLoggingService);
                HouseholdKey          key    = new HouseholdKey("hhkey");
                List <IDataSaverBase> savers = new List <IDataSaverBase>
                {
                    ael
                };
                InputDataLogger   idl = new InputDataLogger(savers.ToArray());
                HouseholdKeyEntry ae1 = new HouseholdKeyEntry(key, "hhname", HouseholdKeyType.House, "desc", null, null);
                idl.Save(ae1);

                List <HouseholdKeyEntry> aes = new List <HouseholdKeyEntry>
                {
                    ae1
                };
                var res = ael.Load();
                var s1  = JsonConvert.SerializeObject(aes, Formatting.Indented);
                var s2  = JsonConvert.SerializeObject(res, Formatting.Indented);
                s1.Should().Be(s2);
                wd.CleanUp();
            }
        }
 public bool IsEnabled(HouseholdKeyEntry householdKey, ResultTableDefinition resultTableDefinition)
 {
     if (ValidResultTableIds.Contains(resultTableDefinition.ResultTableID))
     {
         return(true);
     }
     return(false);
 }
        public FileProcessingResult MakePlot(HouseholdKeyEntry hhkey)
        {
            _calculationProfiler.StartPart(StepName);
            var result = MakeOnePlot(hhkey);

            _calculationProfiler.StopPart(StepName);
            return(result);
        }
 public JsonSumProfile(string name, TimeSpan timeResolution, DateTime startTime, string loadTypeName, string unit, LoadTypeInformation?loadTypeDefinition, [NotNull] HouseholdKeyEntry houseKey)
 {
     Name               = name;
     TimeResolution     = timeResolution;
     StartTime          = startTime;
     LoadTypeName       = loadTypeName;
     Unit               = unit;
     LoadTypeDefinition = loadTypeDefinition;
     HouseKey           = houseKey;
 }
        public void AddSavedEntry([NotNull] HouseholdKeyEntry entry)
        {
            if (_householdKeys.Contains(entry.HHKey))
            {
                throw new LPGException("Key was already registered: " + entry.HHKey);
            }

            _householdKeys.Add(entry.HHKey);
            //_householdEntries.Add(entry);
        }
        public void RegisterHousehold([NotNull] HouseholdKey key, [NotNull] string name, HouseholdKeyType type, [NotNull] IInputDataLogger idl, [NotNull] string description,
                                      [CanBeNull] string houseName, [CanBeNull] string houseDescription)
        {
            if (_householdKeys.Contains(key))
            {
                return;
                //throw new LPGException("Key was already registered: " + key.Key);
            }

            HouseholdKeyEntry hhke = new HouseholdKeyEntry(key, name, type, description, houseName, houseDescription);

            _householdKeys.Add(key);
            //_householdEntries.Add(hhke);
            idl.Save(hhke);
        }
Ejemplo n.º 7
0
        protected override FileProcessingResult MakeOnePlot(HouseholdKeyEntry hhkey)
        {
            CalculationProfiler.StartPart(Utili.GetCurrentMethodAndClass());
            var entries       = CalcDataRepository.LoadAffordanceEnergyUses(hhkey.HHKey);
            var usedLoadtypes = entries.Select(x => x.LoadTypeGuid).Distinct().ToList();
            var loadTypeInfos = CalcDataRepository.LoadTypes;

            foreach (StrGuid loadtypeGuid in usedLoadtypes)
            {
                var lti = loadTypeInfos.Single(x => x.Guid == loadtypeGuid);

                List <AffordanceEnergyUseEntry> filteredEntries = entries.Where(x => x.LoadTypeGuid == loadtypeGuid).ToList();
                var persons = filteredEntries.Select(x => x.PersonName).Distinct().ToList();
                PrepareData(filteredEntries, out var energyUsesPerPersonByAffordance, persons);
                DrawChart(hhkey, energyUsesPerPersonByAffordance, persons, lti);
            }

            CalculationProfiler.StopPart(Utili.GetCurrentMethodAndClass());
            return(FileProcessingResult.ShouldCreateFiles);
        }
Ejemplo n.º 8
0
 public HouseholdStepParameters([NotNull] HouseholdKeyEntry key) => Key = key;
Ejemplo n.º 9
0
        private void DrawChart([JetBrains.Annotations.NotNull] HouseholdKeyEntry hhkey,
                               [JetBrains.Annotations.NotNull] Dictionary <string, List <double> > energyUsesPerPersonByAfforcance,
                               [ItemNotNull][JetBrains.Annotations.NotNull] List <string> persons,
                               [JetBrains.Annotations.NotNull] CalcLoadTypeDto lti)
        {
            string plotName   = "Affordance Energy Use Per Person " + hhkey.HHKey.Key + " " + lti.Name;
            var    plotModel1 = new PlotModel {
                // general
                LegendBorderThickness = 0,
                LegendOrientation     = LegendOrientation.Horizontal,
                LegendPlacement       = LegendPlacement.Outside,
                LegendPosition        = LegendPosition.BottomCenter,
                LegendMargin          = 10,
                LegendItemAlignment   = HorizontalAlignment.Left
            };
            var labelfontsize = 14;

            if (Config.MakePDFCharts)
            {
                plotModel1.DefaultFontSize = Parameters.PDFFontSize;
                plotModel1.LegendFontSize  = 16;
                labelfontsize = 18;
            }

            if (Parameters.ShowTitle)
            {
                plotModel1.Title = plotName;
            }

            // axes
            var categoryAxis1 = new CategoryAxis {
                MinorStep = 1,
                GapWidth  = 1,
                Position  = AxisPosition.Left
            };
            OxyPalette p;

            if (energyUsesPerPersonByAfforcance.Count > 1)
            {
                p = OxyPalettes.HueDistinct(energyUsesPerPersonByAfforcance.Count);
            }
            else
            {
                p = OxyPalettes.Hue64;
            }

            foreach (var personName in persons)
            {
                categoryAxis1.Labels.Add(ChartLocalizer.Get().GetTranslation(personName));
            }

            plotModel1.Axes.Add(categoryAxis1);
            string s2 = lti.Name + " in " + lti.UnitOfSum;

            var linearAxis1 = new LinearAxis {
                AbsoluteMinimum = 0,
                MaximumPadding  = 0.03,
                MinimumPadding  = 0,
                MinorTickSize   = 0,
                Position        = AxisPosition.Bottom,
                Title           = ChartLocalizer.Get().GetTranslation(s2)
            };

            plotModel1.Axes.Add(linearAxis1);
            // generate plot
            var count = 0;
            Dictionary <int, double> colSums2 = new Dictionary <int, double>();
            Dictionary <int, double> colSums  = new Dictionary <int, double>();

            for (int i = 0; i < persons.Count; i++)
            {
                colSums.Add(i, 0);
                colSums2.Add(i, 0);
            }

            foreach (var pair in energyUsesPerPersonByAfforcance)
            {
                // main columns
                var columnSeries2 = new BarSeries {
                    IsStacked       = true,
                    StackGroup      = "1",
                    StrokeThickness = 0.1,
                    StrokeColor     = OxyColors.White,
                    Title           = pair.Key, //affordance name
                    LabelPlacement  = LabelPlacement.Middle,
                    FillColor       = p.Colors[count++]
                };
                var col = 0;
                foreach (var d in pair.Value)
                {
                    //energy use values
                    var coli = new BarItem(d);
                    colSums2[col] += d;
                    columnSeries2.Items.Add(coli);
                    col++;
                }

                plotModel1.Series.Add(columnSeries2);
            }

            foreach (var pair in energyUsesPerPersonByAfforcance)
            {
                var col = 0;
                foreach (var d in pair.Value)
                {
                    if (d / colSums2[col] > 0.2)
                    {
                        {
                            var textAnnotation1 = new RectangleAnnotation();
                            var shortendName    = pair.Key;
                            if (shortendName.Length > 30)
                            {
                                shortendName = shortendName.Substring(0, 30) + "...";
                            }

                            textAnnotation1.Text     = shortendName;
                            textAnnotation1.MinimumX = colSums[col];
                            textAnnotation1.MaximumX = colSums[col] + d;
                            textAnnotation1.MinimumY = col + 0.35;
                            textAnnotation1.MaximumY = col + 0.45;
                            textAnnotation1.TextHorizontalAlignment = HorizontalAlignment.Left;
                            textAnnotation1.TextVerticalAlignment   = VerticalAlignment.Middle;
                            textAnnotation1.FontSize        = labelfontsize;
                            textAnnotation1.StrokeThickness = 0;
                            textAnnotation1.Fill            = OxyColors.White;
                            plotModel1.Annotations.Add(textAnnotation1);
                        }
                        {
                            var textAnnotation2 = new RectangleAnnotation {
                                Text = d.ToString("N1", CultureInfo.CurrentCulture) + " " + lti.UnitOfSum,
                                TextHorizontalAlignment = HorizontalAlignment.Left,
                                TextVerticalAlignment   = VerticalAlignment.Middle,
                                MinimumX        = colSums[col],
                                MaximumX        = colSums[col] + d,
                                MinimumY        = col + 0.25,
                                MaximumY        = col + 0.35,
                                Fill            = OxyColors.White,
                                FontSize        = labelfontsize,
                                StrokeThickness = 0
                            };

                            plotModel1.Annotations.Add(textAnnotation2);
                        }
                    }

                    colSums[col] += d;
                    col++;
                }
            }

            Save(plotModel1, plotName, "AffordanceEnergyUsePerPerson." + hhkey.HHKey + "." + lti.FileName + ".png", Parameters.BaseDirectory, CalcOption.AffordanceEnergyUse);
        }
 protected abstract FileProcessingResult MakeOnePlot([JetBrains.Annotations.NotNull] HouseholdKeyEntry hhkey);