public void FinalSaveToDatabase()
        {
            if (_actionEntries.Count > 0 && _calcParameters.Options.Contains(CalcOption.ActionEntries))
            {
                _idl.SaveList(_actionEntries.ConvertAll(x => (IHouseholdKey)x));
                _actionEntries.Clear();
            }

            if (_affordanceActivationEntries.Count > 0 && _calcParameters.Options.Contains(CalcOption.DeviceActivations))
            {
                _idl.SaveList(_affordanceActivationEntries.ConvertAll(x => (IHouseholdKey)x));
                _affordanceActivationEntries.Clear();
            }

            if (_columnEntries.Count > 0)
            {
                _idl.Save(_columnEntries);
                _columnEntries.Clear();
            }

            if (_locationEntries.Count > 0 && _calcParameters.Options.Contains(CalcOption.LocationsEntries))
            {
                _idl.SaveList(_locationEntries.ConvertAll(x => (IHouseholdKey)x));
                _locationEntries.Clear();
            }

            if (_transportationStatuses.Count > 0)
            {
                _idl.SaveList(_transportationStatuses.ConvertAll(x => (IHouseholdKey)x));
                _transportationStatuses.Clear();
            }

            if (_transportationEvents.Count > 0)
            {
                _idl.SaveList(_transportationEvents.ConvertAll(x => (IHouseholdKey)x));
                _transportationEvents.Clear();
            }
            if (_personStatus.Count > 0)
            {
                _idl.SaveList(_personStatus.ConvertAll(x => (IHouseholdKey)x));
                _personStatus.Clear();
            }
            if (_transportationDeviceState.Count > 0)
            {
                _idl.SaveList(_transportationDeviceState.ConvertAll(x => (IHouseholdKey)x));
                _transportationDeviceState.Clear();
            }

            if (_chargingStationStates.Count > 0)
            {
                _idl.SaveList(_chargingStationStates.ConvertAll(x => (IHouseholdKey)x));
                _chargingStationStates.Clear();
            }
            if (_variableEntries.Count > 0)
            {
                _idl.SaveList(_variableEntries.ConvertAll(x => (IHouseholdKey)x));
                _variableEntries.Clear();
            }
        }
        /*
         * private void WriteHeader([JetBrains.Annotations.NotNull] FileFactoryAndTracker fft, [JetBrains.Annotations.NotNull] HouseholdKey householdKey)
         * {
         *  StreamWriter sw;
         *  if (householdKey == Constants.TotalsKey) {
         *      sw = fft.MakeFile<StreamWriter>("TotalsPerLoadtype.csv", "Totals per load type", true,
         *          ResultFileID.Totals, Constants.TotalsKey, TargetDirectory.Reports,
         *          _calcParameters.InternalStepsize);
         *  }
         *  else {
         *      sw = fft.MakeFile<StreamWriter>("TotalsPerLoadtype." + householdKey + ".csv",
         *          "Totals per load type for " + householdKey, true, ResultFileID.TotalsPerHousehold,
         *          householdKey, TargetDirectory.Reports, _calcParameters.InternalStepsize);
         *  }
         *  _files.Add(householdKey, sw);
         *  sw.WriteLine("Load type" + _calcParameters.CSVCharacter + "Sum" +
         *               _calcParameters.CSVCharacter + "Units" +
         *               _calcParameters.CSVCharacter + "Readable" +
         *               _calcParameters.CSVCharacter + "Units" +
         *               _calcParameters.CSVCharacter + "Per Day" +
         *               _calcParameters.CSVCharacter + "Units" +
         *               _calcParameters.CSVCharacter + "Minimum Values" +
         *               _calcParameters.CSVCharacter + "Minmum Value Unit" +
         *               _calcParameters.CSVCharacter + "Maximum Values" +
         *               _calcParameters.CSVCharacter + "Maximum Value Unit" +
         *               _calcParameters.CSVCharacter + "Per Person" +
         *               _calcParameters.CSVCharacter + "Unit" +
         *               _calcParameters.CSVCharacter + "Per Person and Day" +
         *               _calcParameters.CSVCharacter + "Unit");
         * }*/
        /*
         *  private void WriteToGeneralFile(double sum, [JetBrains.Annotations.NotNull] CalcLoadTypeDto dstLoadType, double min, double max, int numberOfPersons)
         *  {
         *      var s = dstLoadType.Name + _calcParameters.CSVCharacter;
         *      s += sum + _calcParameters.CSVCharacter;
         *      s += dstLoadType.UnitOfPower + "*" + _calcParameters.InternalStepsize.TotalSeconds +
         *           " seconds" + _calcParameters.CSVCharacter;
         *      s += sum * dstLoadType.ConversionFactor + _calcParameters.CSVCharacter +
         *           dstLoadType.UnitOfSum;
         *      var totaldays =
         *          (_calcParameters.OfficialEndTime - _calcParameters.OfficialStartTime)
         *          .TotalDays;
         *      s += _calcParameters.CSVCharacter + sum * dstLoadType.ConversionFactor / totaldays +
         *           _calcParameters.CSVCharacter + dstLoadType.UnitOfSum;
         *      s += _calcParameters.CSVCharacter + min + _calcParameters.CSVCharacter +
         *           dstLoadType.UnitOfPower;
         *      s += _calcParameters.CSVCharacter + max + _calcParameters.CSVCharacter +
         *           dstLoadType.UnitOfPower;
         *      s += _calcParameters.CSVCharacter + sum * dstLoadType.ConversionFactor / numberOfPersons +
         *           _calcParameters.CSVCharacter + dstLoadType.UnitOfSum;
         *      s += _calcParameters.CSVCharacter +
         *           sum * dstLoadType.ConversionFactor / numberOfPersons / totaldays +
         *           _calcParameters.CSVCharacter + dstLoadType.UnitOfSum;
         *      _fft.GetResultFileEntry(ResultFileID.Totals, null, Constants.TotalsKey, null, null).StreamWriter?
         *          .WriteLine(s);
         *      _fft.GetResultFileEntry(ResultFileID.Totals, null, Constants.TotalsKey, null, null).StreamWriter?
         *          .Flush();
         *  }*/

        protected override void PerformActualStep(IStepParameters parameters)
        {
            LoadtypeStepParameters p = (LoadtypeStepParameters)parameters;
            var totaldays            =
                (Repository.CalcParameters.OfficialEndTime -
                 Repository.CalcParameters.OfficialStartTime).TotalDays;
            Dictionary <CalcLoadTypeDto, double> totalsPerLoadType = new Dictionary <CalcLoadTypeDto, double>();
            //CalculateTotal(energyFileRows, loadType, totalsPerLoadType, Repository.GetPersons(householdKey).Count);
            var efc = Repository.ReadEnergyFileColumns(Constants.GeneralHouseholdKey);

            RunIndividualHouseholds(p.LoadType, p.EnergyFileRows, efc, totalsPerLoadType);
            List <TotalsPerLoadtypeEntry> totals = new List <TotalsPerLoadtypeEntry>();

            foreach (HouseholdKeyEntry entry in Repository.HouseholdKeys)
            {
                if (entry.KeyType == HouseholdKeyType.General)
                {
                    continue;
                }

                HouseholdKey key          = entry.HHKey;
                int          personscount = 0;
                if (entry.KeyType == HouseholdKeyType.Household)
                {
                    personscount = Repository.GetPersons(key).Count;
                }
                foreach (KeyValuePair <CalcLoadTypeDto, double> pair in totalsPerLoadType)
                {
                    totals.Add(new TotalsPerLoadtypeEntry(key, pair.Key, pair.Value, personscount, totaldays));
                }
            }
            _inputDataLogger.SaveList(totals.ConvertAll(x => (IHouseholdKey)x));
        }
        private void MakeSumsForJson([NotNull] CalcLoadTypeDto dstLoadType,
                                     [NotNull][ItemNotNull] List <OnlineEnergyFileRow> energyFileRows,
                                     [NotNull] EnergyFileColumns efc,
                                     [NotNull] HouseholdKey key)
        {
            var calcParameters = Repository.CalcParameters;
            var dsc            = new DateStampCreator(calcParameters);

            if (!efc.ColumnEntriesByColumn.ContainsKey(dstLoadType))
            {
                return;
            }

            var cols = efc.ColumnEntriesByColumn[dstLoadType];
            var tdp  = new Dictionary <int, TotalsPerDeviceEntry>();

            foreach (var pair in cols)
            {
                var tpde = new TotalsPerDeviceEntry(key, pair.Value.CalcDeviceDto, dstLoadType);
                tdp.Add(pair.Key, tpde);
            }

            foreach (var row in energyFileRows)
            {
                if (!row.Timestep.DisplayThisStep)
                {
                    continue;
                }

                var month = dsc.MakeDateFromTimeStep(row.Timestep).Month;
                foreach (var pair in cols)
                {
                    // ReSharper disable once CompareOfFloatsByEqualityOperator
                    if (row.EnergyEntries[pair.Key] == 0)
                    {
                        continue;
                    }

                    tdp[pair.Key].AddConsumptionValue(month, row.EnergyEntries[pair.Key]);
                }
            }

            foreach (var value in tdp.Values)
            {
                value.Value          *= value.Loadtype.ConversionFactor;
                value.NegativeValues *= value.Loadtype.ConversionFactor;
                value.PositiveValues *= value.Loadtype.ConversionFactor;
            }

            _inputDataLogger.SaveList(tdp.Values.ToList().ConvertAll(x => (IHouseholdKey)x));
        }
Exemplo n.º 4
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());
        }