//, Type dateType) /// <summary> /// Creates a Table by a given "Sorted Measure List" with one date time column and one column for each inverter. /// </summary> /// <param name="kwhTable">Creates google data table compatible conent</param> /// <param name="yMode">Use Euro or kwh as y-axis</param> /// <param name="xMode">type of x-axis</param> /// <returns>Google DataTable content</returns> public string BuildGoogleDataTable(SortedKwhTable kwhTable, E_EurKwh yMode, E_TimeMode xMode) { //create datatable and add time column System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add("Zeit", typeof(string)).Caption = "Zeit"; //add one column for each inverter ID foreach (var inverterInfo in kwhTable.KnownInverters) { string caption = GetRowName(inverterInfo.Value); dt.Columns.Add(caption, typeof(System.Double)).Caption = caption; } //Add the data foreach (var row in kwhTable.Rows.Values) { //create a new row and add the time first (key) var rowToAdd = dt.NewRow(); rowToAdd[0] = GetTimeCaption(row.Index, xMode); //add the values foreach inverter foreach (var measure in row.kwhValues) { rowToAdd[GetRowName(measure.PublicInverterId)] = measure.Value * GetPerEuroFactor(yMode, measure.PublicInverterId); } //add the new row to the datatable dt.Rows.Add(rowToAdd); } GoogleDataTable gdt = new Bortosky.Google.Visualization.GoogleDataTable(dt); return gdt.GetJson(); }
//DatatableConverter dtConverter = new DatatableConverter(); internal string GoogleDataTableContent(DateTime startDate, DateTime endDate, int plantId, E_EurKwh yMode, E_TimeMode xMode) { //Get kwhdays from database var dailyResult = _kwhRepository.GetDayKwhByDateRange(startDate, endDate, plantId); //Fill up the month for the chart data var kwhTable = KwhCalculator.SummarizeKwh(dailyResult, startDate, endDate, xMode, true); // calculate roi if neccesary and convert to Google Data Table return GenerateGoogleDataTableContent(plantId, yMode, kwhTable, xMode); }
private string GenerateGoogleDataTableContent(int plantId, E_EurKwh yMode, SortedKwhTable kwhTable, E_TimeMode xMode) { DatatableConverter dtConverter = new DatatableConverter(); //include money per kwh mapping if neccessary if (yMode == E_EurKwh.money) { IncludeEuroPerKwhMapping(plantId, dtConverter); } //create google data table content string return dtConverter.BuildGoogleDataTable(kwhTable, yMode, xMode); }
internal KwhEurResult GetkwhAndMoneyPerTimeFrame(DateTime startDate, DateTime endDate, int plantId, E_TimeMode xMode) { //Get kwhdays from database var dailyResult = _kwhRepository.GetDayKwhByDateRange(startDate, endDate, plantId); //Fill up the month for the chart data var kwhTable = KwhCalculator.SummarizeKwh(dailyResult, startDate, endDate, xMode, true); KwhEurResult result = new KwhEurResult() { Kwh = GetCumulatedKwh(kwhTable), Euro = GetCumulatedEuro(kwhTable, _plantRepository.GetAllInvertersByPlant(plantId)) }; return result; }
/// <summary> /// Initializes the resultlist. It can be chosen wether we want to fill gaps or not. /// This is important for the "kwh by day" calculation because if we would fill gaps there, kwh_days would be /// deleted when there is no more measurement data for the timeframe /// </summary> /// <param name="measures"></param> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <param name="timeMode"></param> /// <param name="systemID"></param> /// <param name="fillGaps"></param> /// <returns></returns> private static SortedKwhTable InitializeResultList(SortedKwhTable measures , DateTime startDate, DateTime endDate , E_TimeMode timeMode , bool fillGaps) { //init day sum list for the hole time frame SortedKwhTable result = new SortedKwhTable(); // Initialize the result with empty values first var countDate = startDate; while (countDate < endDate) { foreach (var inverterInfo in measures.KnownInverters) { if (fillGaps || ContainsMeasuresForThisTimePoint(measures, countDate, timeMode, inverterInfo.Value)) { MeasureKwH dummy = new MeasureKwH(); dummy.DateTime = countDate; dummy.PrivateInverterId = inverterInfo.Key; dummy.PublicInverterId = inverterInfo.Value; dummy.Value = 0; result.AddMeasure(dummy); } } //increase countdate countDate = IncreaseCountDate(timeMode, countDate); } return result; }
/// <summary> /// Increases the countdate depending on the requested stepping. /// </summary> /// <param name="timeMode"></param> /// <param name="countDate"></param> /// <returns></returns> private static DateTime IncreaseCountDate(E_TimeMode timeMode, DateTime countDate) { if (timeMode == E_TimeMode.day) countDate = countDate.AddDays(1); else if (timeMode == E_TimeMode.month) countDate = countDate.AddMonths(1); else if (timeMode == E_TimeMode.year) countDate = countDate.AddYears(1); return countDate; }
private static DateTime GetTimePointByMode(E_TimeMode timeMode, DateTime currentDateTime) { DateTime currentTimePoint; switch (timeMode) { case E_TimeMode.day: currentTimePoint = new DateTime(currentDateTime.Year, currentDateTime.Month, currentDateTime.Day); break; case E_TimeMode.month: currentTimePoint = new DateTime(currentDateTime.Year, currentDateTime.Month, 1); break; case E_TimeMode.year: currentTimePoint = new DateTime(currentDateTime.Year, 1, 1); break; default: throw new ApplicationException(); } return currentTimePoint; }
/// <summary> /// Crops the datetime that we can compare it. If the timemode is "Day" than all information of the hour will be /// set to 0. If the timemode is "Month" all information below day will be set to 1 or 0. /// </summary> /// <param name="dateTime"></param> /// <param name="timeMode"></param> /// <returns></returns> private static DateTime GetCompareableDate(DateTime dateTime, E_TimeMode timeMode) { switch (timeMode) { case E_TimeMode.hour: return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, 0, 0); case E_TimeMode.day: return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0); case E_TimeMode.month: return new DateTime(dateTime.Year, dateTime.Month, 1, 0, 0, 0); case E_TimeMode.year: return new DateTime(dateTime.Year, 1, 0, 0, 0, 0); default: throw new ApplicationException(); } }
/// <summary> /// Returns true if we have a measure which falls into the countdate timeframe /// </summary> /// <param name="measures"></param> /// <param name="countDate"></param> /// <param name="timeMode"></param> /// <param name="publicInverterID"></param> /// <returns></returns> private static bool ContainsMeasuresForThisTimePoint(SortedKwhTable measures, DateTime countDate, E_TimeMode timeMode, int publicInverterID) { foreach (var row in measures.Rows) { //datetime contains measure for this inverter ID if (measures.ContainsMeasureForPublicInverterId(row.Key, publicInverterID)) { DateTime comparabledate = GetCompareableDate(row.Key, timeMode); if (countDate == comparabledate) return true; } } return false; }
/// <summary> /// Summarizes kwh values from hourly up to yearly. At first it initializes a result list, which is then filled with cumulated data from the input. /// </summary> /// <param name="measures">Kwh table for an undefined time range</param> /// <param name="startDate">The startDate Parameter can be used to crop /// unwanted kwh values at the beginning</param> /// <param name="endDate">The endDate Parameter crops all unwanted tailing kwh /// values</param> /// <param name="timeMode">The timeMode defines the target kwh stepping. /// Stepping includes from hourly up to yearly.</param> /// <param name="fillGaps"></param> /// <returns>The summarized kwh table</returns> public static SortedKwhTable SummarizeKwh(SortedKwhTable measures, DateTime startDate, DateTime endDate, E_TimeMode timeMode, bool fillGaps) { //setup start and enddate startDate = GetTimePointByMode(timeMode, startDate); endDate = GetTimePointByMode(timeMode, endDate); //Initialize result list SortedKwhTable result; result = InitializeResultList(measures, startDate, endDate, timeMode, fillGaps); //Build the sum for the measures by each timepoint, depending on the timeMode foreach (var item in measures.ToList()) { // get target time point where the current kwh should be added to DateTime currentTimePoint = GetTimePointByMode(timeMode, item.DateTime); //add the kwh of this hour for the inverter if (currentTimePoint >= startDate && currentTimePoint < endDate) { result.GetKwh(currentTimePoint, item.PublicInverterId).Value += item.Value; } else { Logger.Log(new ApplicationException(), SeverityLevel.Warning, "kwh value is out of the specified startDate and endate"); } } return result; }
// Type dateType) /// <summary> /// Get the caption for the x-axis. Datetime is used for googledatatable, where the /// real datetime value is needed. /// Otherwise use month name, or year number /// </summary> /// <param name="dateTime"></param> /// <param name="xMode"></param> /// <param name="dateType"></param> /// <returns></returns> private object GetTimeCaption(DateTime dateTime, E_TimeMode xMode) { object time; //if (dateType == typeof(DateTime)) //{ // time = dateTime; //} //else //{//evaluate x-axis text switch (xMode) { case E_TimeMode.hour: time = dateTime.ToShortTimeString(); break; case E_TimeMode.day: time = dateTime.Day.ToString(); break; case E_TimeMode.month: time = dateTime.ToString("MMM"); break; case E_TimeMode.year: time = dateTime.Year.ToString(); break; default: throw new ApplicationException("Could not get Time Caption"); } return time; }