private bool CheckAggregation(int groupCount, AggerationType checkType) { int requiredCount = 1; switch (checkType) { // For year all data must be multiplied by 12 months case AggerationType.Year: requiredCount = requiredCount * 12; goto case AggerationType.Month; // For months all data must be multiplied by days in month case AggerationType.Month: // I use 30 but this depends on the given month and year requiredCount = requiredCount * 30; goto case AggerationType.Day; // For days all data need to be multiplied by 24 hour case AggerationType.Day: requiredCount = requiredCount * 24; goto case AggerationType.Hour; // For hours all data need to be multiplied by 2 (because slots of 30 minutes) case AggerationType.Hour: requiredCount = requiredCount * 2; break; } return(groupCount == requiredCount); }
private IList <Aggregate_Raw_Data> CalculateAggregation(AggerationType GroupBy, IEnumerable <Point_Measure_Fact> point_measure_fact_list_dto) { try { var Result = from t in point_measure_fact_list_dto group t by new { //Date_ID = t.Date_ID, Hour = (int)GroupBy >= (int)AggerationType.Hour ? t.Hour_ID : new DateTime(), Day = (int)GroupBy >= (int)AggerationType.Day ? t.Timestamp_From.Date : new DateTime(), Month = (int)GroupBy >= (int)AggerationType.Month ? t.Timestamp_From.Month : 0, Month_Year = (int)GroupBy >= (int)AggerationType.Month ? t.Timestamp_From.Year : 0, Year = (int)GroupBy >= (int)AggerationType.Year ? t.Timestamp_From.Year : 0, Client_ID = t.Client_ID, Point_ID = t.Point_ID } into g select new Aggregate_Raw_Data() { Hour_ID = g.Key.Hour, Date_ID = g.Key.Day, //Week_ID = g.Key. Month_ID = g.Key.Month, Month_Year_ID = g.Key.Month_Year, Year_ID = g.Key.Year, SumValue = g.Sum(m => m.Value), MinValue = g.Min(m => m.Value), MaxValue = g.Max(m => m.Value), AverageValue = g.Average(m => m.Value), Cummulative = 0, Client_ID = g.Key.Client_ID, Point_ID = g.Key.Point_ID, TotalCount = g.Count() }; return(Result.ToList()); } catch (Exception ex) { File_Log.SaveLog_ToFile(ex, Common.Enums.LoggingActions.Error, ""); return(null); } }
public IList <Data> RunQuery(AggerationType groupType, AggerationType checkType, IList <Point_Measure_Fact> point_measure_fact_list_dto) { // The actual query which does to trick var result = from d in point_measure_fact_list_dto group d by new { d.Timestamp_From.Year, Month = (int)groupType >= (int)AggerationType.Month ? d.Timestamp_From.Month : 1, Day = (int)groupType >= (int)AggerationType.Day ? d.Timestamp_From.Day : 1, Hour = (int)groupType >= (int)AggerationType.Hour ? d.Timestamp_From.Hour : 1 } into g // The where clause checks how much data needs to be in the group where CheckAggregation(g.Count(), checkType) select new Data() { Start = g.Min(m => m.Timestamp_From), End = g.Max(m => m.Timestamp_To), SumValue = g.Sum(m => m.Value) }; return(result.ToList()); }
public IList <Data> CalculateAggregation(AggerationType GroupBy, IList <Point_Measure_Fact> point_measure_fact_list_dto) { var Result = from t in point_measure_fact_list_dto group t by new { Date_ID = t.Date_ID, Hour = (int)GroupBy >= (int)AggerationType.Hour ? t.Hour_ID : System.DateTime.Now, Day = (int)GroupBy >= (int)AggerationType.Day ? t.Timestamp_From.Day : 0, Month = (int)GroupBy >= (int)AggerationType.Month ? t.Timestamp_From.Month : 0, Year = (int)GroupBy >= (int)AggerationType.Year ? t.Timestamp_From.Year : 0 } into g select new Data() { Date_ID = g.Key.Date_ID, Hour_ID = g.Key.Hour, SumValue = g.Sum(m => m.Value), MinValue = g.Min(m => m.Value), MaxValue = g.Max(m => m.Value), AverageValue = g.Average(m => m.Value), TotalCount = g.Count() }; return(Result.ToList()); }
public IList <Warehouse_DTO> Get_Data_From(long point_id, DateTime from_date, DateTime to_date, AggerationType aggregaretype) { PointMesaureFact point_measure_fact = new PointMesaureFact(); switch (aggregaretype) { case AggerationType.Hour: point_measure_fact = new PointAggHour(); break; case AggerationType.Day: point_measure_fact = new PointAggDay(); break; case AggerationType.Week: throw new NotImplementedException("The week aggregation is not implemented"); case AggerationType.Month: point_measure_fact = new PointAggMonth(); break; case AggerationType.Year: point_measure_fact = new PointAggYear(); break; default: break; } return(point_measure_fact.Get_Data_From(point_id, from_date, to_date)); }
private void Save_Aggregate_To_WareHouse(List <Aggregate_Raw_Data> _list_aggregation, AggerationType _aggerationType, long Element_ID) { if (_list_aggregation != null) { if (_list_aggregation.Any()) { try { _db_datawarehouse_context = new InnonAnalyticsWarehouseEntities(); switch (_aggerationType) { case AggerationType.Hour: _db_datawarehouse_context.Point_Agg_Hour.AddRange(Point_Agg_Hour_Convert.Convert_List_Aggregate_Raw_Data_To_Point_Agg_Hour_List(_list_aggregation)); break; case AggerationType.Day: _db_datawarehouse_context.Point_Agg_Day.AddRange(Point_Agg_Day_Convert.Convert_List_Aggregate_Raw_Data_To_Point_Agg_Day_List(_list_aggregation)); break; case AggerationType.Week: //_db_datawarehouse_context.Point_Agg_Week.AddRange(Point_Agg_Week_Convert.Convert_List_Aggregate_Raw_Data_To_Point_Agg_Week_List(_list_aggregation)); break; case AggerationType.Month: _db_datawarehouse_context.Point_Agg_Month.AddRange(Point_Agg_Month_Convert.Convert_List_Aggregate_Raw_Data_To_Point_Agg_Month_List(_list_aggregation)); break; case AggerationType.Year: _db_datawarehouse_context.Point_Agg_Year.AddRange(Point_Agg_Year_Convert.Convert_List_Aggregate_Raw_Data_To_Point_Agg_Year_List(_list_aggregation)); break; default: File_Log.SaveLog_ToFile(new Exception("Invalid AggregationType"), LoggingActions.Error, "Point_ID " + Element_ID); break; } _db_datawarehouse_context.SaveChanges(); } catch (Exception ex) { File_Log.SaveLog_ToFile(ex, LoggingActions.Error, "Aggragation Type " + _aggerationType + " Point_ID " + Element_ID); } } } }
/// <summary> /// This function calulate the aggregate on the basis of provided parameters /// </summary> /// <param name="Element_ID"></param> /// <param name="Timestamp_From"></param> /// <param name="aggregate_type">Aggregate is for Group by</param> /// <returns></returns> private List <Aggregate_Raw_Data> Get_Aggregate_Raw_Data(long Element_ID, DateTime?Timestamp_From, AggerationType aggregate_type) { try { _db_datawarehouse_context = new InnonAnalyticsWarehouseEntities(); IPoint_Measure_Fact_Service point_measure_fact_service = new Point_Measure_Fact_Service(); IList <Point_Measure_Fact> list = new List <Point_Measure_Fact>(); if (Timestamp_From.HasValue) { list = point_measure_fact_service.Get_Point_Measure_Fact_By_Element_ID_From_Date(Element_ID, Timestamp_From.GetValueOrDefault()); } else { list = point_measure_fact_service.Get_Point_Measure_Fact_By_Element_ID(Element_ID); } List <Aggregate_Raw_Data> _list_aggregation = new List <Aggregate_Raw_Data>(); _list_aggregation.AddRange(CalculateAggregation(aggregate_type, list)); return(_list_aggregation); } catch (Exception ex) { File_Log.SaveLog_ToFile(ex, Common.Enums.LoggingActions.Error, string.Format("passing parameter element_id:-{0}, Timestamp_From:- {1}, aggregate_type:- {2}", Element_ID, Timestamp_From, aggregate_type)); return(null); } }
public IList <Warehouse_DTO> Get_WareHouse_Raw_Data(AggerationType aggregation_type, int point_id, DateTime from_date, DateTime to_date) { return(_warehouse_data.Get_Data_From(point_id, from_date, to_date, aggregation_type)); }
/// <summary> /// /// </summary> /// <param name="element_id"></param> /// <param name="group_by"></param> public void Get_Aggregate(long element_id, AggerationType group_by) { // _db_datawarehouse_context = new InnonAnalyticsWarehouseEntities(); }
/// <summary> /// Get_Aggregate Returns Group By Aggregation_Type(Hour, Day, Month, Sec, Year) /// </summary> /// <param name="list_element_id"></param> /// <param name="group_by"></param> /// <param name="from_date"></param> /// <param name="to_date"></param> /// <returns></returns> public List <Aggregate_DTO_Group_By_Aggregation_Type_Value> Get_Aggregate(IEnumerable <ElementDTO_WareHouse> list_element, Rollup_Function_Option roll_up_function, Unit_Of_Measurement_DTO metric_unit, AggerationType group_by, DateTime from_date, DateTime to_date) { List <Aggregate_DTO_Group_By_Aggregation_Type_Value> _aggregate_dto = new List <Aggregate_DTO_Group_By_Aggregation_Type_Value>(); IEnumerable <long> list_element_id = list_element.Select(elementid => elementid.Element_ID); switch (group_by) { case AggerationType.Hour: _get_Aggregate_Hour(list_element, roll_up_function, metric_unit, from_date, to_date, ref _aggregate_dto); break; case AggerationType.Day: _get_Aggregate_Day(list_element, roll_up_function, metric_unit, from_date, to_date, ref _aggregate_dto); break; case AggerationType.Week: throw new NotImplementedException("The week aggregation is not implemented"); case AggerationType.Month: _get_Aggregate_Month(list_element, roll_up_function, metric_unit, from_date, to_date, ref _aggregate_dto); break; case AggerationType.Year: _get_Aggregate_Year(list_element, roll_up_function, metric_unit, from_date, to_date, ref _aggregate_dto); break; default: break; } return(_aggregate_dto); }