public List <DeviceSerializer> GetDeviceByWorkshop(String workshop) { List <DeviceModel> devices = _deviceDao.GetByWorkshop(workshop); List <DeviceSerializer> result = new List <DeviceSerializer>(); foreach (DeviceModel d in devices) { result.Add(new DeviceSerializer(d)); } return(result); }
/* * 地域纬度报表 */ public object GetReportByRegion(String cityName, String factoryName, DateTime startTime, DateTime endTime) { /*************************************************/ /* zxin-地域维度报表理解: * 数据返回:每个实验室中设备平均在线时间、告警次数、当前设备数量;横轴实验室 * step: * 1、根据城市、实验楼获取所有实验室list * 2、foreach每个实验室,根据城市、实验楼、实验室获取所有设备list,输出设备数量 * 3、foreach每个设备,获取设备在线时间(平均在线时间=总在线时间/设备总数,这里不考虑起止时间),根据起止时间获取设备的告警总次数, * */ List <WorkshopModel> affiliateWorkshop = this._workshopDao.GetAffiliateWorkshop(cityName, factoryName); List <String> xAxis = new List <string>(); List <float> averageOnlineTime = new List <float>(); List <int> alarmTimes = new List <int>(); List <int> deviceAmount = new List <int>(); /* * List<DeviceModel> allDevices = this._deviceDao.Get("all"); * List<AlarmInfoModel> allAlarmInfo = this._alarmInfoDao.Get("all"); */ /*new*/ //List<DeviceDailyOnlineTimeModel> dailyOnlineTime = // this._deviceDailyOnlineTimeDao.GetDeviceOnlineTimeByTime(startTime, endTime); /*new*/ foreach (WorkshopModel w in affiliateWorkshop) { /* * xAxis.Add(w.WorkshopName); * * List<DeviceModel> relatedDevices = allDevices.AsQueryable() * .Where(d => d.Workshop == w.WorkshopName) * .ToList(); * deviceAmount.Add(relatedDevices.Count); * * List<String> relatedDevicesId = new List<String>(); * foreach (DeviceModel d in relatedDevices) * { * relatedDevicesId.Add(d.HardwareDeviceId); * } * * List<AlarmInfoModel> relatedAlarmInfo = allAlarmInfo.AsQueryable() * .Where(ai => relatedDevicesId.Contains(ai.DeviceId) && ai.Timestamp >= startTime && ai.Timestamp <= endTime) * .ToList(); * alarmTimes.Add(relatedAlarmInfo.Count); * * Double total = 0; * List<DeviceDailyOnlineTimeModel> deviceDataByWorkshop = dailyOnlineTime.AsQueryable() * .Where(dot => relatedDevicesId.Contains(dot.HardwareDeviceId)) * .ToList(); * foreach (var d in deviceDataByWorkshop) * { * total += d.OnlineTime; * } * * if (deviceDataByWorkshop.Count != 0) * { * averageOnlineTime.Add(Math.Round(total / deviceDataByWorkshop.Count, 2)); * } * else * { * averageOnlineTime.Add(0); * } */ /* old * TimeSpan t = TimeSpan.Zero; * foreach (String did in relatedDevicesId) * { * List<DeviceDataModel> allDeviceData = this._deviceDataDao.Get("all"); * List<DeviceDataModel> relatedData = allDeviceData.AsQueryable() * .Where(dd => dd.DeviceId == did && dd.Timestamp >= startTime && dd.Timestamp <= endTime) * .OrderBy(dd => dd.Timestamp) * .ToList(); * if (relatedData.Count > 0) * { * var tmpTime = relatedData.Last().Timestamp - relatedData.First().Timestamp; * t += tmpTime; * } * } * averageOnlineTime.Add(t.TotalMinutes / relatedDevices.Count); */ /*zxin-修改*/ xAxis.Add(w.WorkshopName); float totalOnlineTime = 0.0F; int totalAlarmInfo = 0; List <DeviceModel> devices = _deviceDao.GetByWorkshop(cityName, factoryName, w.WorkshopName); if (devices != null) { deviceAmount.Add(devices.Count()); foreach (DeviceModel device in devices) { DeviceDataModel earliestData = this._deviceDataDao.ListByDeviceNameASC(device.DeviceName, 1).FirstOrDefault(); DeviceDataModel latestData = this._deviceDataDao.GetByDeviceName(device.DeviceName, 1).FirstOrDefault(); TimeSpan onlineTime = (earliestData != null & latestData != null) ? latestData.Timestamp - earliestData.Timestamp : TimeSpan.MinValue; totalOnlineTime = (float)(onlineTime != TimeSpan.MinValue ? totalOnlineTime + onlineTime.TotalHours : totalOnlineTime + 0.0); int alarmInfoNumber = _alarmInfoDao.GetDeviceAffiliateAlarmInfoNumber(device.HardwareDeviceId, startTime, endTime); totalAlarmInfo += alarmInfoNumber; } } alarmTimes.Add(totalAlarmInfo); averageOnlineTime.Add(totalOnlineTime / devices.Count()); } /***************************************************************/ List <object> result = new List <object>(); result.Add(new { name = "平均在线时间", data = averageOnlineTime, type = "bar", barWidth = 20 }); result.Add(new { name = "告警次数", data = alarmTimes, type = "bar", barWidth = 20 }); result.Add(new { name = "设备数量", data = deviceAmount, type = "bar", barWidth = 20 }); return(new { xAxis = xAxis, series = result }); }