public ResultRealLine DeviceRealChart(RealQuery query) { var pAction = new ExecuteProcess(); try { var result = new ResultRealLine { series = new List<EneryAnalyseSeries>(), Unit = "kwh" }; //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; if (query.QueryType == EnergyAnalyseQueryType.Default) { model.Starttime = Convert.ToDateTime(System.DateTime.Now.ToString("yyyy-MM-dd")); model.Endtime = Convert.ToDateTime(System.DateTime.Now.ToString("yyyy-MM-dd")); } else if (query.QueryType == EnergyAnalyseQueryType.MonthCompare) { model.Starttime = Convert.ToDateTime(System.DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd")); model.Endtime = Convert.ToDateTime(System.DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd")); } else if (query.QueryType == EnergyAnalyseQueryType.YearCompare) { model.Starttime = Convert.ToDateTime(System.DateTime.Now.AddYears(-1).ToString("yyyy-MM-dd")); model.Endtime = Convert.ToDateTime(System.DateTime.Now.AddYears(-1).ToString("yyyy-MM-dd")); } var itemList = new BLL.Itemcode().GetItemcodeList(" and ItemCodeNumber='" + model.ItemCode + "'", " order by ItemcodeID")[0]; result.Unit = itemList.Unit;//by added wxy 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; } } List<decimal> dat = new List<decimal>(); foreach (var e in eneryDataList) { dat.Add(e.Value); } EneryAnalyseSeries eas = new EneryAnalyseSeries(); eas.data = dat; result.series.Add(eas); pAction.Success = true; result.ActionInfo = pAction; return result; } catch (Exception ex) { pAction.Success = false; pAction.ExceptionMsg = ex.Message; return new ResultRealLine() { ActionInfo = pAction }; } }
public ResultRealLine IndexElectricityRealLine(DateTime startTime, DateTime endTime) { var pAction = new ExecuteProcess(); try { var result = new ResultRealLine { series = new List<EneryAnalyseSeries>(), Unit = "kwh" }; var eneryDataList = new Dictionary<string, decimal>(); var model = new BaseQueryModel(); var objectList = new NTS.WEB.BLL.BaseLayerObject().GetBaseFuncLayerObjectList(string.Format(" and LayerObjectParentID={0}", 0), " order by LayerObjectID"); model.IsDevice = 0; model.ObjectList = (from p in objectList select p.LayerObjectID).ToList<int>(); model.ItemCode = "01000"; model.Unit = ChartUnit.unit_hour; model.Starttime = startTime; model.Endtime = endTime; var resList = _reportBll.GetBaseEneryDataList(model,true); foreach (var d in objectList.SelectMany(o => resList.BaseLayerObjectResults[o.LayerObjectID.ToString(CultureInfo.InvariantCulture)].Datas)) { if (!eneryDataList.ContainsKey(d.DatePick)) { eneryDataList.Add(d.DatePick, d.DataValue); } else { eneryDataList[d.DatePick] += d.DataValue; } } List<decimal> dat = new List<decimal>(24);//modified by wxy for (int i = 0; i < 24; i++) dat.Add(0); foreach (var e in eneryDataList) { DateTime dt = DateTime.Parse(e.Key);//dat.Add(e.Value); dat[dt.Hour] = e.Value; } List<decimal> dat1 = new List<decimal>(); EneryAnalyseSeries eas = new EneryAnalyseSeries(); decimal rightValue = 0;//modified by wxy decimal leftValue = 0; for (int i = 0; i <= DateTime.Now.Hour; i++) { if (dat[i].CompareTo(-1) == 0) { int tempIndex = i; while (--i >= 0) { if (dat[i].CompareTo(-1) >= 0) { rightValue = dat[i]; break; } } i = tempIndex; while (++i < 24) { if (dat[i].CompareTo(-1) >= 0) { leftValue = dat[i]; break; } } i = tempIndex; decimal meanValue = (rightValue + leftValue)/2; dat1.Add( Math.Round(meanValue, 2) ); } else dat1.Add(dat[i]); } eas.data = dat1; result.series.Add(eas); pAction.Success = true; result.ActionInfo = pAction; return result; } catch (Exception ex) { pAction.Success = false; pAction.ExceptionMsg = ex.Message; return new ResultRealLine() { ActionInfo = pAction }; } }