Пример #1
0
        public ResultItemCode RealChart(RealQuery query)
        {
            ResultItemCode result = new ResultItemCode();
            result.Dept = new List<string>();
            result.Enery = new Dictionary<string, List<decimal>>();
            result.ObjectName = new List<string>();
            // var result = new ResultIndexLineChart { DatePick = new List<string>(), DatePickEnery = new List<decimal>() };
            var eneryDataList = new Dictionary<string, decimal>();
            var model = new BaseQueryModel();
            var objectList = new NTS.WEB.BLL.BaseLayerObject().GetDeviceObjectList(string.Format(" and deviceid={0}", query.ObjectId), " order by deviceid");
            model.IsDevice = 1;
            model.ObjectList = (from p in objectList select p.DeviceID).ToList<int>();
            model.ItemCode = objectList[0].ItemCodeID;
            model.Unit = ChartUnit.unit_hour;
            model.Starttime = Convert.ToDateTime(System.DateTime.Now.ToString("yyyy-MM-dd"));
            model.Endtime = Convert.ToDateTime(System.DateTime.Now.ToString("yyyy-MM-dd"));
            var itemList = new BLL.Itemcode().GetItemcodeList(" and ItemCodeNumber='" + model.ItemCode + "'", " order by ItemcodeID")[0];

            var resList = _reportBll.GetBaseEneryDataList(model);
            foreach (var d in objectList.SelectMany(o => resList.BaseLayerObjectResults[o.DeviceID.ToString(CultureInfo.InvariantCulture)].Datas))
            {
                if (!eneryDataList.ContainsKey(d.DatePick))
                {
                    eneryDataList.Add(d.DatePick, d.DataValue);
                }
                else
                {
                    eneryDataList[d.DatePick] += d.DataValue;
                }
            }
            result.Enery.Add(objectList[0].DeviceID.ToString(CultureInfo.InvariantCulture), eneryDataList.Values.ToList());
            foreach (var e in eneryDataList)
            {
                result.Dept.Add(itemList.Unit);
                result.ObjectName.Add(e.Key);

            }
            return result;
        }
Пример #2
0
 public ResultItemCode IndexAvgElectricityLineChart(DateTime startTime, DateTime endTime)
 {
     var realLine = IndexElectricityLineChart(startTime, startTime);
     var resultList = new ResultItemCode();
     resultList.Dept = new List<string>();
     resultList.ObjectName = new List<string>();
     resultList.Enery = new Dictionary<string, List<decimal>>();
     var oldStartTime = Convert.ToDateTime(startTime.AddMonths(-1).ToString("yyyy-MM-1"));
     var oldEndTime = oldStartTime.AddMonths(1);
     var dayLine = new decimal[24];
     while (oldStartTime < oldEndTime)
     {
         var result = IndexElectricityLineChart(oldStartTime, oldStartTime);
         for (var i = 0; i < result.DatePickEnery.Count; i++)
         {
             dayLine[i] += result.DatePickEnery[i];
         }
         oldStartTime = oldStartTime.AddDays(1);
     }
     int Count = oldStartTime.AddDays(-1).Subtract(Convert.ToDateTime(oldStartTime.AddDays(-1).ToString("yyyy-MM-1"))).Days + 1;
     for (var l = 0; l < dayLine.Length; l++)
     {
         dayLine[l] = dayLine[l] / Count;
         resultList.Dept.Add("kwh");
     }
     foreach (var real in realLine.DatePick)
     {
         resultList.ObjectName.Add(real);
     }
     resultList.Enery.Add("上月平均", dayLine.ToList());
     resultList.Enery.Add("实时消耗", realLine.DatePickEnery);
     return resultList;
 }