Ejemplo n.º 1
0
        /// <summary>
        /// This function for the single metric and target metric controls like guage and counter
        /// </summary>
        /// <param name="chart_type"></param>
        /// <param name="chart_id"></param>
        /// <param name="from_date"></param>
        /// <param name="to_date"></param>
        /// <returns></returns>
        public Aggregate_DTO_Metric Get_Aggregate_Data_Signle_Metric(ChartType chart_type, int chart_id, DateTime from_date, DateTime to_date)
        {
            try
            {
                Aggregate_Element_Ids ElementIDs = new Aggregate_Element_Ids();
                double value        = 0.0;
                double target_value = 0.0;
                ElementIDs = _chart_rep.Get_Data_Points_By_Chart(chart_type, chart_id);
                // IEnumerable<long> Target_Element_Ids = _chart_rep.Get_Target_Data_Points_By_Chart(ChartType.Gauge, chart_id);

                value = _aggregare_data.Get_Aggregate(ElementIDs.Element_Ids, ElementIDs.Mertric_Rollup_Function, ElementIDs.Mertric_Unit, from_date, to_date);

                //For counter chart we do not have a target metric thats why we need this condtion
                if (ElementIDs.Target_Element_Ids != null)
                {
                    target_value = _aggregare_data.Get_Aggregate(ElementIDs.Target_Element_Ids, ElementIDs.Mertric_Target_Rollup_Function, ElementIDs.Target_Mertric_Unit, from_date, to_date);
                }

                Aggregate_DTO_Metric aggregate_dto_metric = new Aggregate_DTO_Metric();
                aggregate_dto_metric.Aggregate_Target_Value = target_value;
                aggregate_dto_metric.Aggregate_Value        = value;
                aggregate_dto_metric.Mertric_Unit           = ElementIDs.Mertric_Unit;
                aggregate_dto_metric.Metric_Name            = ElementIDs.Metric_Name;
                aggregate_dto_metric.Rollup_Function        = ElementIDs.Mertric_Rollup_Function;
                aggregate_dto_metric.Target_Mertric_Unit    = ElementIDs.Target_Mertric_Unit;
                aggregate_dto_metric.Target_Metric_Name     = ElementIDs.Target_Metric_Name;

                return(aggregate_dto_metric);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        public static Counter_Chart Convert_Aggregate_To_Counter_Chart(Aggregate_DTO_Metric aggregate_dto)
        {
            Counter_Chart Counter_chart = new Counter_Chart();

            Counter_chart.Metric_Name  = aggregate_dto.Metric_Name;
            Counter_chart.Mertric_Unit = aggregate_dto.Mertric_Unit;
            Counter_chart.Value        = aggregate_dto.Aggregate_Value;
            return(Counter_chart);
        }
Ejemplo n.º 3
0
        public static Gauge_Chart Convert_Aggregate_To_Gauge_Chart(Aggregate_DTO_Metric aggregate_dto)
        {
            Gauge_Chart gauge_chart = new Gauge_Chart();

            gauge_chart.Metric_Name        = aggregate_dto.Metric_Name;
            gauge_chart.Target_Metric_Name = aggregate_dto.Target_Metric_Name;

            gauge_chart.Mertric_Unit        = aggregate_dto.Mertric_Unit;
            gauge_chart.Target_Mertric_Unit = aggregate_dto.Target_Mertric_Unit;

            gauge_chart.Sum_Value        = aggregate_dto.Aggregate_Value;
            gauge_chart.Sum_Value_Target = aggregate_dto.Aggregate_Target_Value;
            return(gauge_chart);
        }
Ejemplo n.º 4
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));
        }