コード例 #1
0
        private static void Convert_Values(IEnumerable <ElementDTO_WareHouse> list_element_id, Unit_Of_Measurement_DTO metric_unit, List <Aggregate_DTO_Aggregation_Type_Value> _aggregate_dtos)
        {
            ElementDTO_WareHouse element_dto_warehouse;

            //Convert the value of Element if unit of measure is change from the unit of metric
            foreach (var _aggregate_dto in _aggregate_dtos)
            {
                element_dto_warehouse = list_element_id.SingleOrDefault(point => point.Element_ID == _aggregate_dto.Point_ID);
                if (element_dto_warehouse != null)
                {
                    if (element_dto_warehouse.Element_Unit.ID != 0 && element_dto_warehouse.Element_Unit.ID != metric_unit.ID)
                    {
                        _aggregate_dto.Value = Unit_Convertion.Conversion(_aggregate_dto.Value, element_dto_warehouse.Element_Unit.Unit_Name, metric_unit.Unit_Name);
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// This aggregation function used for those chart type which has mutiple metric like donut, pie etc. Always get data from the Point_Agg_Hour
        /// </summary>
        /// <param name="list_element_id"></param>
        /// <param name="rollup_function_option">AVG, MIN, MAX, SUM</param>
        /// <param name="from_date"></param>
        /// <param name="to_date"></param>
        /// <returns></returns>
        public double Get_Aggregate(IEnumerable <ElementDTO_WareHouse> list_element, Rollup_Function_Option rollup_function_option, Unit_Of_Measurement_DTO metric_unit, DateTime from_date, DateTime to_date)
        {
            //double? point_sum = (from point_measure_fact in _db_datawarehouse_context.Point_Measure_Fact
            //                     where point_measure_fact.Timestamp_From >= from_date && point_measure_fact.Timestamp_To <= to_date && list_element_id.Contains(point_measure_fact.Point_ID)
            //                     select point_measure_fact).ToList().Sum(sum_value => (double?)sum_value.Value) ?? null;

            double?            Value           = 0;
            IEnumerable <long> list_element_id = list_element.Select(elementid => elementid.Element_ID);

            List <Point_Agg_Hour> point_agg_hr = (from point_measure_fact in _db_datawarehouse_context.Point_Agg_Hour
                                                  where point_measure_fact.Hour_ID >= from_date && point_measure_fact.Hour_ID <= to_date && list_element_id.Contains(point_measure_fact.Point_ID)
                                                  select point_measure_fact).ToList();

            ElementDTO_WareHouse element_dto_warehouse;

            //Convert the value of Element if unit of measure is change from the unit of metric
            foreach (var _aggregate_dto in point_agg_hr)
            {
                element_dto_warehouse = list_element.SingleOrDefault(point => point.Element_ID == _aggregate_dto.Point_ID);
                if (element_dto_warehouse != null)
                {
                    if (element_dto_warehouse.Element_Unit.ID != 0 && element_dto_warehouse.Element_Unit.ID != metric_unit.ID)
                    {
                        _aggregate_dto.Sum_Value = Unit_Convertion.Conversion(_aggregate_dto.Sum_Value, element_dto_warehouse.Element_Unit.Unit_Name, metric_unit.Unit_Name);
                        _aggregate_dto.Avg_Value = Unit_Convertion.Conversion(_aggregate_dto.Avg_Value, element_dto_warehouse.Element_Unit.Unit_Name, metric_unit.Unit_Name);
                        _aggregate_dto.Min_Value = Unit_Convertion.Conversion(_aggregate_dto.Min_Value, element_dto_warehouse.Element_Unit.Unit_Name, metric_unit.Unit_Name);
                        _aggregate_dto.Max_Value = Unit_Convertion.Conversion(_aggregate_dto.Max_Value, element_dto_warehouse.Element_Unit.Unit_Name, metric_unit.Unit_Name);
                    }
                }
            }

            switch (rollup_function_option)
            {
            case Rollup_Function_Option.AVG:
                Value = point_agg_hr.Average(value => (double?)value.Avg_Value) ?? null;
                break;

            case Rollup_Function_Option.MAX:
                Value = point_agg_hr.Max(value => (double?)value.Max_Value) ?? null;
                break;

            case Rollup_Function_Option.MIN:
                Value = point_agg_hr.Min(value => (double?)value.Min_Value) ?? null;
                break;

            case Rollup_Function_Option.SUM:
                Value = point_agg_hr.Sum(value => (double?)value.Sum_Value) ?? null;
                break;

            default:
                throw new Exception("Invalid Rollup_Function_Option Not Implmeneted " + rollup_function_option);
            }

            if (Value == null)
            {
                throw new AggregateException(Resources.Null_Value);
            }
            else
            {
                return((double)Value);
            }
        }