예제 #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
        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);
            }
        }
예제 #3
0
        public void Update_Point_Dim(IList <ElementDTO> list_element_dto, IList <Tag_Type_Mapping_DTO> list_tag_type_mapping_dto)
        {
            try
            {
                _datawarehousecontext = new InnonAnalyticsWarehouseEntities();
                IEnumerable <long> point_ids = list_element_dto.Select(element => element.ID);

                IEnumerable <Point_Dim> point_dims = _datawarehousecontext.Point_Dim.Where(p_d => point_ids.Contains(p_d.Point_ID));

                string columns = Helper.ConvertIEnumerableToString(list_tag_type_mapping_dto.Select(z => z.Point_Dim_Mapping), ",");

                string str_insert_point_dim_query = "";
                string str_update_point_dim_query = "";
                string column_name = "", column_value = "";
                foreach (ElementDTO element_dto in list_element_dto)
                {
                    try
                    {
                        if (point_dims.Any(point_dim => point_dim.Point_ID == element_dto.ID))
                        {
                            str_update_point_dim_query += "update Point_Dim set ";
                            //str_update_point_dim_query += " Point_ID=" + element_dto.ID;
                            str_update_point_dim_query += " Equipment_ID=0";
                            str_update_point_dim_query += ",Site_ID=0";
                            str_update_point_dim_query += ",Client_ID=0";
                            //str_update_point_dim_query += ",Country=null";
                            //str_update_point_dim_query += ",City=null";
                            foreach (TagDTO tag in element_dto.Tags)
                            {
                                Tag_Type_Mapping_DTO dto_mapping = list_tag_type_mapping_dto.SingleOrDefault(z => z.Tag_Type == tag.Tag_Type_String);
                                str_update_point_dim_query += "," + dto_mapping.Point_Dim_Mapping + "=" + "'" + tag.Tag_Value.Trim() + "'";
                            }

                            foreach (Tag_Type_Mapping_DTO dto in list_tag_type_mapping_dto)
                            {
                                if (dto.Tag_Type != TagType.point.ToString() && dto.Tag_Type != TagType.equip.ToString() && dto.Tag_Type != TagType.site.ToString() && dto.Tag_Type != TagType.client.ToString())
                                {
                                    try
                                    {
                                        TagDTO tag = element_dto.Tags.SingleOrDefault(t => t.Tag_Type_String.Equals(dto.Tag_Type));
                                        if (tag == null)
                                        {
                                            str_update_point_dim_query += "," + dto.Point_Dim_Mapping + "=" + "null";
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Helper.WriteToFile(string.Format("Multiple tag with same tag type: Element ID : {0}, Element Name {1}, Source History Name {2}, Tag_Type: {3} ", element_dto.ID, element_dto.Element_Name, element_dto.Source_Element_Name_History, dto.Tag_Type));
                                    }
                                }
                            }
                            str_update_point_dim_query += " where Point_ID=" + element_dto.ID + ";";
                        }
                        else
                        {
                            column_name  = "insert into Point_Dim(Point_ID,Equipment_ID,Site_ID,Client_ID";
                            column_value = element_dto.ID + "," + 0 + "," + 0 + "," + 0;
                            foreach (TagDTO tag in element_dto.Tags)
                            {
                                Tag_Type_Mapping_DTO dto = list_tag_type_mapping_dto.SingleOrDefault(z => z.Tag_Type == tag.Tag_Type_String);
                                column_name  += "," + dto.Point_Dim_Mapping;
                                column_value += ",'" + tag.Tag_Value.Trim() + "'";
                            }
                            column_name  += ") Values(";
                            column_value += ");";
                            str_insert_point_dim_query += column_name + column_value;
                        }
                    }
                    catch (Exception ex)
                    {
                        Helper.WriteToFile("Error in point dim: " + ex.Message + "---" + ex.InnerException.Message);
                    }
                }

                try
                {
                    _datawarehousecontext.Database.ExecuteSqlCommand(@"" + str_insert_point_dim_query + str_update_point_dim_query);
                }
                catch (Exception ex)
                {
                    Helper.WriteToFile("Error in point dim saving: " + ex.Message + "---" + ex.InnerException.Message);
                    Helper.WriteToFile("Query " + str_insert_point_dim_query + str_update_point_dim_query);
                }
            }
            catch (Exception ex)
            {
                Helper.WriteToFile("Error in point dim: " + ex.Message + "---" + ex.InnerException.Message);
            }
        }