コード例 #1
0
        public IList <Aggregate_DTO_Group_By_Aggregation_Type> Get_Aggregate_Data_By_Metric_GroupBy(ChartType chart_type, int chart_id, DateTime from_date, DateTime to_date)
        {
            Combine_Enum_Tag_Aggregation Group_By = _chart_rep.Get_Group_By(chart_type, chart_id);


            ICollection <tblMetric> chart_metrics = _chart_rep.Get_Metric_By_Chart(chart_type, chart_id);

            IList <Aggregate_DTO_Group_By_Aggregation_Type> aggregate_dtos = new List <Aggregate_DTO_Group_By_Aggregation_Type>();
            Aggregate_DTO_Group_By_Aggregation_Type         aggregate_dto;// = new Aggregate_DTO_Group_By_Aggregation_Type();
            Aggregate_Metric_Elements Metric_ElementIds;



            if (Group_By.Tage_Type != 0)
            {
                Tag_Type_Mapping_DTO tag_type_mapping = _tag_rep.Get_Tag_Type_Mapping_By_Tag_Type(Group_By.Tage_Type);
                foreach (tblMetric metric in chart_metrics)
                {
                    Metric_ElementIds = _chart_rep.Get_Data_Points_By_Metric(metric);
                    aggregate_dto     = new Aggregate_DTO_Group_By_Aggregation_Type();

                    aggregate_dto.Metric_Name     = Metric_ElementIds.Metric_Name;
                    aggregate_dto.Mertric_Unit    = Metric_ElementIds.Mertric_Unit;
                    aggregate_dto.Rollup_Function = Metric_ElementIds.Mertric_Rollup_Function;

                    if (Metric_ElementIds.Elements.Element_Ids.Count() > 0)
                    {
                        aggregate_dto.Aggregate_Value = _aggregare_data.Get_Aggregate(Metric_ElementIds.Elements.Element_Ids, Metric_ElementIds.Mertric_Rollup_Function, Metric_ElementIds.Mertric_Unit, tag_type_mapping.Point_Dim_Mapping, from_date, to_date);
                    }
                    aggregate_dtos.Add(aggregate_dto);
                }
            }
            else
            {
                foreach (tblMetric metric in chart_metrics)
                {
                    Metric_ElementIds             = _chart_rep.Get_Data_Points_By_Metric(metric);
                    aggregate_dto                 = new Aggregate_DTO_Group_By_Aggregation_Type();
                    aggregate_dto.Metric_Name     = Metric_ElementIds.Metric_Name;
                    aggregate_dto.Mertric_Unit    = Metric_ElementIds.Mertric_Unit;
                    aggregate_dto.Rollup_Function = Metric_ElementIds.Mertric_Rollup_Function;
                    if (Metric_ElementIds.Elements.Element_Ids.Count() > 0)
                    {
                        if (Group_By.Aggregation_Type != 0)
                        {
                            aggregate_dto.Aggregate_Value = _aggregare_data.Get_Aggregate(Metric_ElementIds.Elements.Element_Ids, Metric_ElementIds.Mertric_Rollup_Function, Metric_ElementIds.Mertric_Unit, Group_By.Aggregation_Type, from_date, to_date);
                        }
                        else
                        {
                            aggregate_dto.Aggregate_Value = _aggregare_data.Get_Aggregate(Metric_ElementIds.Elements.Element_Ids, Metric_ElementIds.Mertric_Rollup_Function, Metric_ElementIds.Mertric_Unit, AggerationType.Day, from_date, to_date);
                        }
                    }
                    aggregate_dtos.Add(aggregate_dto);
                }
            }

            return(aggregate_dtos);
        }
コード例 #2
0
        /// <summary>
        /// this is temporary solution for the heat map. generate proper method for group by hour
        /// </summary>
        /// <param name="chart_id"></param>
        /// <param name="from_date"></param>
        /// <param name="to_date"></param>
        /// <returns></returns>
        public Aggregate_DTO_Group_By_Aggregation_Type Get_Aggregate_Data_Raw(int chart_id, DateTime from_date, DateTime to_date)
        {
            try
            {
                Aggregate_Element_Ids ElementIDs = new Aggregate_Element_Ids();

                ElementIDs = _chart_rep.Get_Data_Points_By_Chart(ChartType.HeatMap, chart_id);
                List <Aggregate_DTO_Group_By_Aggregation_Type_Value> _raw_aggregate_data = _aggregare_data.Get_Aggregate(ElementIDs.Element_Ids, ElementIDs.Mertric_Rollup_Function, ElementIDs.Mertric_Unit, AggerationType.Hour, from_date, to_date);

                Aggregate_DTO_Group_By_Aggregation_Type aggregate_data = new Aggregate_DTO_Group_By_Aggregation_Type();
                aggregate_data.Aggregate_Value = _raw_aggregate_data;
                aggregate_data.Metric_Name     = ElementIDs.Metric_Name;
                aggregate_data.Mertric_Unit    = ElementIDs.Mertric_Unit;

                aggregate_data.Rollup_Function = ElementIDs.Mertric_Rollup_Function;
                return(aggregate_data);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #3
0
        public Aggregate_DTO_Group_By_Aggregation_Type Get_Aggregate_Data(ChartType chart_type, int chart_id, DateTime from_date, DateTime to_date)
        {
            Combine_Enum_Tag_Aggregation Group_By = _chart_rep.Get_Group_By(chart_type, chart_id);

            Aggregate_Element_Ids ElementIds = _chart_rep.Get_Data_Points_By_Chart(chart_type, chart_id);

            Aggregate_DTO_Group_By_Aggregation_Type aggregate_dto = new Aggregate_DTO_Group_By_Aggregation_Type();

            aggregate_dto.Metric_Name        = ElementIds.Metric_Name;
            aggregate_dto.Target_Metric_Name = ElementIds.Target_Metric_Name;

            aggregate_dto.Mertric_Unit        = ElementIds.Mertric_Unit;
            aggregate_dto.Target_Mertric_Unit = ElementIds.Target_Mertric_Unit;

            //If there is no group by than default group by is day
            if (Group_By.Tage_Type != 0)
            {
                Tag_Type_Mapping_DTO tag_type_mapping = _tag_rep.Get_Tag_Type_Mapping_By_Tag_Type(Group_By.Tage_Type);

                aggregate_dto.Aggregate_Value        = _aggregare_data.Get_Aggregate(ElementIds.Element_Ids, ElementIds.Mertric_Rollup_Function, ElementIds.Mertric_Unit, tag_type_mapping.Point_Dim_Mapping, from_date, to_date);
                aggregate_dto.Aggregate_Target_Value = _aggregare_data.Get_Aggregate(ElementIds.Target_Element_Ids, ElementIds.Mertric_Target_Rollup_Function, ElementIds.Target_Mertric_Unit, tag_type_mapping.Point_Dim_Mapping, from_date, to_date);

                return(aggregate_dto);
            }
            else if (Group_By.Aggregation_Type != 0)
            {
                aggregate_dto.Aggregate_Value        = _aggregare_data.Get_Aggregate(ElementIds.Element_Ids, ElementIds.Mertric_Rollup_Function, ElementIds.Mertric_Unit, Group_By.Aggregation_Type, from_date, to_date);
                aggregate_dto.Aggregate_Target_Value = _aggregare_data.Get_Aggregate(ElementIds.Target_Element_Ids, ElementIds.Mertric_Target_Rollup_Function, ElementIds.Target_Mertric_Unit, Group_By.Aggregation_Type, from_date, to_date);
                return(aggregate_dto);
            }
            else
            {
                aggregate_dto.Aggregate_Value        = _aggregare_data.Get_Aggregate(ElementIds.Element_Ids, ElementIds.Mertric_Rollup_Function, ElementIds.Mertric_Unit, AggerationType.Day, from_date, to_date);
                aggregate_dto.Aggregate_Target_Value = _aggregare_data.Get_Aggregate(ElementIds.Target_Element_Ids, ElementIds.Mertric_Target_Rollup_Function, ElementIds.Target_Mertric_Unit, AggerationType.Day, from_date, to_date);
                return(aggregate_dto);
            }
        }
コード例 #4
0
ファイル: ChartsDTO.cs プロジェクト: leodeveloper/Analytics
        public static Heapmap_Chart Aggregate_DTO_Group_By_Aggregation_Type_Value_Heatmap_Chart(Aggregate_DTO_Group_By_Aggregation_Type list_aggregate_dto, DateTime _fromDate, DateTime _toDate)
        {
            DateTime _datetime;

            //This variable used for to get min nad max date
            List <DateTime> _datetime_min_max = new List <DateTime>();

            Heapmap_Chart _heatmap_chart = new Heapmap_Chart();

            if (list_aggregate_dto.Aggregate_Value.Count > 0)
            {
                foreach (Aggregate_DTO_Group_By_Aggregation_Type_Value aggregate_dto in list_aggregate_dto.Aggregate_Value)
                {
                    try
                    {
                        if (DateTime.TryParse(aggregate_dto.Group_By, out _datetime))
                        {
                            _datetime_min_max.Add(_datetime);

                            _heatmap_chart.Categories.Add(aggregate_dto.Group_By);
                            _heatmap_chart.Json_String.Add(string.Format("{0},{1},{2}", _datetime.ToString("yyyy-MM-dd"), _datetime.ToString("HH"), aggregate_dto.Value));
                        }
                        else
                        {
                            throw new Exception("Invalid date and time");
                        }
                    }
                    catch { }
                }


                _heatmap_chart.MinValue = list_aggregate_dto.Aggregate_Value.Min(value => value.Value_String);
                _heatmap_chart.MaxValue = list_aggregate_dto.Aggregate_Value.Max(value => value.Value_String);
            }

            _heatmap_chart.metric_name    = list_aggregate_dto.Metric_Name;
            _heatmap_chart.unit_name      = list_aggregate_dto.Mertric_Unit.Unit_Name;
            _heatmap_chart.unit_symbol    = list_aggregate_dto.Mertric_Unit.Unit_Symbol;
            _heatmap_chart.MinValue_YAxis = _fromDate;
            _heatmap_chart.MaxValue_YAxis = _toDate;



            return(_heatmap_chart);
        }
コード例 #5
0
ファイル: ChartsDTO.cs プロジェクト: leodeveloper/Analytics
        public static Fixed_Placement_Column_Chart Fixed_Placement_Chart_Convert_To_Fixed_Placement(Aggregate_DTO_Group_By_Aggregation_Type aggregate_dto)
        {
            double pointPadding1   = 0.4;
            double pointPlacement1 = -0.2;

            double pointPadding2   = 0.3;
            double pointPlacement2 = -0.2;

            Fixed_Placement_Column_Chart fixed_placement_chart = new Fixed_Placement_Column_Chart();

            List <Json_Class_Fixed> _j_class = new List <Json_Class_Fixed>();

            //First we need to aad the target than the value
            _j_class.Add(new Json_Class_Fixed {
                name = aggregate_dto.Target_Metric_Name, pointPadding = pointPadding2, pointPlacement = pointPlacement2
            });
            _j_class.Add(new Json_Class_Fixed {
                name = aggregate_dto.Metric_Name, pointPadding = pointPadding1, pointPlacement = pointPlacement1
            });


            #region Y-Axis
            if (!fixed_placement_chart.Y_Axis.Any(g_by => g_by.Equals(aggregate_dto.Mertric_Unit.Unit_Symbol)))
            {
                fixed_placement_chart.Y_Axis.Add(aggregate_dto.Mertric_Unit.Unit_Symbol);
            }

            if (!fixed_placement_chart.Y_Axis.Any(g_by => g_by.Equals(aggregate_dto.Target_Mertric_Unit.Unit_Symbol)))
            {
                fixed_placement_chart.Y_Axis.Add(aggregate_dto.Target_Mertric_Unit.Unit_Symbol);
            }
            #endregion

            Aggregate_DTO_Group_By_Aggregation_Type_Value _aggregate_value;
            Aggregate_DTO_Group_By_Aggregation_Type_Value _aggregate_value_target;
            foreach (Aggregate_DTO_Group_By_Aggregation_Type_Value aggregate_value in aggregate_dto.Aggregate_Value)
            {
                try
                {
                    fixed_placement_chart.Categories.Add(aggregate_value.Group_By);

                    _aggregate_value = aggregate_dto.Aggregate_Value.SingleOrDefault(d => d.Group_By.Equals(aggregate_value.Group_By));

                    _aggregate_value_target = aggregate_dto.Aggregate_Target_Value.SingleOrDefault(d => d.Group_By.Equals(aggregate_value.Group_By));

                    if (_aggregate_value != null)
                    {
                        _j_class[1].data.Add(_aggregate_value.Value);
                    }
                    else
                    {
                        _j_class[1].data.Add(0);
                    }

                    if (_aggregate_value_target != null)
                    {
                        _j_class[0].data.Add(_aggregate_value_target.Value);
                    }
                    else
                    {
                        _j_class[0].data.Add(0);
                    }
                }
                catch (Exception ex)
                {
                }
            }

            fixed_placement_chart.Json_Data.AddRange(_j_class);

            return(fixed_placement_chart);
        }
コード例 #6
0
ファイル: ChartsDTO.cs プロジェクト: leodeveloper/Analytics
        public static Basic_Column_Chart Basic_Column_Chart_Convert_To_Column_Basic(Aggregate_DTO_Group_By_Aggregation_Type aggregate_dto)
        {
            Basic_Column_Chart basic_column_chart = new Basic_Column_Chart();

            List <Json_Class> _j_class = new List <Json_Class>();

            _j_class.Add(new Json_Class {
                name = aggregate_dto.Metric_Name
            });
            _j_class.Add(new Json_Class {
                name = aggregate_dto.Target_Metric_Name
            });

            #region Y-Axis
            if (!basic_column_chart.Y_Axis.Any(g_by => g_by.Equals(aggregate_dto.Mertric_Unit.Unit_Symbol)))
            {
                basic_column_chart.Y_Axis.Add(aggregate_dto.Mertric_Unit.Unit_Symbol);
            }

            if (!basic_column_chart.Y_Axis.Any(g_by => g_by.Equals(aggregate_dto.Target_Mertric_Unit.Unit_Symbol)))
            {
                basic_column_chart.Y_Axis.Add(aggregate_dto.Target_Mertric_Unit.Unit_Symbol);
            }
            #endregion


            Aggregate_DTO_Group_By_Aggregation_Type_Value _aggregate_value;
            Aggregate_DTO_Group_By_Aggregation_Type_Value _aggregate_value_target;
            foreach (Aggregate_DTO_Group_By_Aggregation_Type_Value aggregate_value in aggregate_dto.Aggregate_Value)
            {
                try
                {
                    basic_column_chart.Categories.Add(aggregate_value.Group_By);


                    _aggregate_value = aggregate_dto.Aggregate_Value.SingleOrDefault(d => d.Group_By.Equals(aggregate_value.Group_By));

                    _aggregate_value_target = aggregate_dto.Aggregate_Target_Value.SingleOrDefault(d => d.Group_By.Equals(aggregate_value.Group_By));

                    if (_aggregate_value != null)
                    {
                        _j_class[0].data.Add(_aggregate_value.Value);
                    }
                    else
                    {
                        _j_class[0].data.Add(0);
                    }

                    if (_aggregate_value_target != null)
                    {
                        _j_class[1].data.Add(_aggregate_value_target.Value);
                    }
                    else
                    {
                        _j_class[1].data.Add(0);
                    }
                }
                catch (Exception ex)
                {
                }
            }

            basic_column_chart.Json_Data.AddRange(_j_class);

            return(basic_column_chart);
        }
コード例 #7
0
        public async Task <IHttpActionResult> Get_Data_By_Chart(string chart_type, int chart_id, DateTime from_date, DateTime to_date)
        {
            if (Request.Method != HttpMethod.Options)
            {
                try
                {
                    ChartType _chart_type;
                    if (!Enum.TryParse(chart_type, out _chart_type))
                    {
                        return(BadRequest(string.Format(Resources.Invalid_Chart_Type + " {0}", chart_type)));
                    }

                    if (_chart_type == ChartType.Gauge)
                    {
                        Aggregate_DTO_Metric aggregate_dto = _aggregateRepository.Get_Aggregate_Data_Signle_Metric(ChartType.Gauge, chart_id, from_date, to_date);
                        return(Ok(new APIResponseWrapper()
                        {
                            Data = await Task.Factory.StartNew(() => Gauge_Chart_Convert.Convert_Aggregate_To_Gauge_Chart(aggregate_dto)),
                            Errors = null,
                            Message = null
                        }));
                    }
                    else if (_chart_type == ChartType.Counter)
                    {
                        Aggregate_DTO_Metric aggregate_dto = _aggregateRepository.Get_Aggregate_Data_Signle_Metric(ChartType.Counter, chart_id, from_date, to_date);
                        return(Ok(new APIResponseWrapper()
                        {
                            Data = await Task.Factory.StartNew(() => Counter_Chart_Convert.Convert_Aggregate_To_Counter_Chart(aggregate_dto)),
                            Errors = null,
                            Message = null
                        }));
                    }
                    else if (_chart_type == ChartType.Pie)
                    {
                        List <Aggregate_Metric_Elements_Value> list_metric_value = _aggregateRepository.Get_Aggregate_Data_By_Metrics(_chart_type, chart_id, from_date, to_date);
                        return(Ok(new APIResponseWrapper()
                        {
                            Data = await Task.Factory.StartNew(() => Pie_Chart_Convert.Pie_Chart_Convert_Aggregate_Metric_To_Pie_Chart_DTO(list_metric_value)),
                            Errors = null,
                            Message = null
                        }));
                    }
                    else if (_chart_type == ChartType.Donut)
                    {
                        List <Aggregate_Metric_Elements_Value> list_metric_value = _aggregateRepository.Get_Aggregate_Data_By_Metrics(_chart_type, chart_id, from_date, to_date);
                        return(Ok(new APIResponseWrapper()
                        {
                            Data = await Task.Factory.StartNew(() => Pie_Chart_Convert.Pie_Chart_Convert_Aggregate_Metric_To_Pie_Chart_DTO(list_metric_value)),
                            Errors = null,
                            Message = null
                        }));
                    }
                    else if (_chart_type == ChartType.Stacked)
                    {
                        IList <Aggregate_DTO_Group_By_Aggregation_Type> agre = _aggregateRepository.Get_Aggregate_Data_By_Metric_GroupBy(_chart_type, chart_id, from_date, to_date);


                        return(Ok(new APIResponseWrapper()
                        {
                            Data = await Task.Factory.StartNew(() => Stacked_Column_Chart_Convert.Aggregate_Convert_To_Stacked_Chart(agre)),
                            Errors = null,
                            Message = null
                        }));
                    }
                    else if (_chart_type == ChartType.Line)
                    {
                        IList <Aggregate_DTO_Group_By_Aggregation_Type> agre = _aggregateRepository.Get_Aggregate_Data_By_Metric_GroupBy(_chart_type, chart_id, from_date, to_date);


                        return(Ok(new APIResponseWrapper()
                        {
                            Data = await Task.Factory.StartNew(() => Line_Column_Chart_Convert.Aggregate_Convert_To_Line_Chart(agre)),
                            Errors = null,
                            Message = null
                        }));
                    }
                    else if (_chart_type == ChartType.HeatMap)
                    {
                        Aggregate_DTO_Group_By_Aggregation_Type aggregate = _aggregateRepository.Get_Aggregate_Data_Raw(chart_id, from_date, to_date);

                        return(Ok(new APIResponseWrapper()
                        {
                            Data = await Task.Factory.StartNew(() => Aggregate_DTO_Group_By_Aggregation_Type_Value_Convert.Aggregate_DTO_Group_By_Aggregation_Type_Value_Heatmap_Chart(aggregate, from_date, to_date)),
                            Errors = null,
                            Message = null
                        }));
                    }
                    else if (_chart_type == ChartType.TreeMap)
                    {
                        Aggregate_DTO_Group_By_Aggregation_Type aggregate_dto_Group_By = _aggregateRepository.Get_Aggregate_Data(_chart_type, chart_id, from_date, to_date);

                        return(Ok(new APIResponseWrapper()
                        {
                            Data = await Task.Factory.StartNew(() => Convert_Aggregate_DTO_Group_By_To_Tree_Map_Aggregate_DTO.Convert(aggregate_dto_Group_By)),
                            Errors = null,
                            Message = null
                        }));
                    }
                    else if (_chart_type == ChartType.Bar || _chart_type == ChartType.BarFixedPlacement)
                    {
                        Aggregate_DTO_Group_By_Aggregation_Type agre = _aggregateRepository.Get_Aggregate_Data(_chart_type, chart_id, from_date, to_date);

                        if (_chart_type == ChartType.Bar)
                        {
                            return(Ok(new APIResponseWrapper()
                            {
                                Data = await Task.Factory.StartNew(() => Basic_Column_Chart_Convert.Basic_Column_Chart_Convert_To_Column_Basic(agre)),
                                Errors = null,
                                Message = null
                            }));
                        }
                        else if (_chart_type == ChartType.BarFixedPlacement)
                        {
                            return(Ok(new APIResponseWrapper()
                            {
                                Data = await Task.Factory.StartNew(() => Fixed_Placement_Chart_Convert.Fixed_Placement_Chart_Convert_To_Fixed_Placement(agre)),
                                Errors = null,
                                Message = null
                            }));
                        }
                        else
                        {
                            return(Ok(new APIResponseWrapper()
                            {
                                Data = null,
                                Errors = "Invalid Chart Type",
                                Message = null
                            }));
                        }
                    }
                    else
                    {
                        return(Ok(new APIResponseWrapper()
                        {
                            Data = null,
                            Errors = "Invalid Chart Type",
                            Message = null
                        }));
                    }
                }
                catch (ArgumentNullException argEx)
                {
                    return(BadRequest(argEx.Message));
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Message));
                }
            }
            return(Ok(HttpStatusCode.OK));
        }