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);
        }
        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);
            }
        }