예제 #1
0
        public void CalcTest()
        {
            WattageHourCalculator calc = new WattageHourCalculator();

              int inverter1 = 1;
              int inverter2 = 2;

              // 5 minute timespan
              var fiveMin = new TimeSpan(0, 5, 0);
              calc.AddPowerValue(inverter1, 500, fiveMin);
              calc.AddPowerValue(inverter2, 1000, fiveMin);

              var actualWh_1 = calc.GetWattageHour(inverter1);
              var actualWh_2 = calc.GetWattageHour(inverter2);

              int expected_1 = (int)Math.Round(41.66666667);
              int expected_2 = (int)Math.Round(83.33333333);

              Assert.AreEqual(expected_1, actualWh_1);
              Assert.AreEqual(expected_2, actualWh_2);
        }
예제 #2
0
        private string GetMinDayJsFileContent(DateTime dateTime, int plantId)
        {
            string dateTimeFormat = "dd.MM.yy HH:mm:ss";
              var startDate = Utils.CropHourMinuteSecond(dateTime);
              var endDate = startDate.AddDays(1);

              List<Measure> allMeasures = new List<Measure>();
              var inverters = _plantRepository.GetAllInvertersByPlant(plantId);

              // grab all measures for the requested day
              foreach (var inverter in inverters)
              {
            var inverterMeasures = _measureRepository.GetMinuteWiseMeasures(startDate, endDate, inverter.InverterId);

            //group data by 5 minute intervals
            var inverterMeasures5Min = GroupMeasuresTo5MinIntervals(plantId, inverter, inverterMeasures);

            //add measures to all measures list
            allMeasures.AddRange(inverterMeasures5Min);
              }

              if (allMeasures.Count == 0)
            return string.Empty;

              // order measures by DateTime Descending and the public inverter Id Ascending
              var orderedMeasures = allMeasures.OrderBy(x => x.DateTime).ThenBy(x => x.PublicInverterId).ToList();

              //index: public inverterId, key: wattage hours
              WattageHourCalculator calc = new WattageHourCalculator();

              // count time for calculation and string building decisions
              var countTime = orderedMeasures.First().DateTime;
              List<string> resultLines = new List<string>();
              StringBuilder builder = null;
              int measureCounter = 0;
              int inverterCount = inverters.Count();
              Measure latestMeasure = null;

              for (int i = 0; i < orderedMeasures.Count; i++)
              {

            var currentMeasure = orderedMeasures[i];

            // build a new line and append the old one
            if (latestMeasure == null || currentMeasure.DateTime != latestMeasure.DateTime)
            {
              // delete this line if not every inverter has a 5 min measure included
              if (measureCounter < inverterCount)
              {
            builder = null;
              }

              //reset measure counter
              measureCounter = 0;

              // finish last row and add it to result-lines list, if we have a stringbuilder allready
              if (builder != null)
              {
            builder.Append("\"");
            resultLines.Add(builder.ToString());
              }

              // reset string builder
              builder = new StringBuilder();

              //append dateTime and row start string
              builder.AppendFormat(@"m[mi++]=""{0}", currentMeasure.DateTime.ToString(dateTimeFormat));
            }

            //calculate wattage hour total for the current inverter where the measure is from
            calc.AddPowerValue(currentMeasure.PublicInverterId, currentMeasure.OutputWattage, new TimeSpan(0, 5, 0));
            measureCounter++;

            // append inverter Data
            builder.AppendFormat(@"|{0};{1};{2};{3};{4}", Math.Round(currentMeasure.OutputWattage),
                                                       currentMeasure.GeneratorWattage.RoundOrZero(),
                                                        calc.GetWattageHour(currentMeasure.PublicInverterId),
                                                        currentMeasure.GeneratorVoltage.RoundOrZero(),
                                                        (currentMeasure.Temperature.HasValue) ? currentMeasure.Temperature.Value : 0);

            // update count-time
            latestMeasure = currentMeasure;
              }

              // add latest row if valid
              if (measureCounter == inverterCount)
            resultLines.Add(builder.ToString());

              //reverse lines in list
              StringBuilder result = new StringBuilder();
              for (int i = resultLines.Count - 1; i >= 0; i--)
              {
            result.AppendLine(resultLines[i]);
              }

              return result.ToString();
        }