Example #1
0
        private void StatMongoData(DateTime date)
        {
            AppendLog("开始更新" + date.ToShortDateString() + "的数据\r\n");

            int count = GetDataCount(date);

            if (count > 0)
            {
                AppendLog("当日已存在统计数据,不再重复统计\r\n"); return;
            }

            DateTime nextDate = date.AddDays(1);

            string sDate = (DateTime.Parse(date.ToString("yyyy-MM-dd"))).ToString("u");

            string sNDate = (DateTime.Parse(nextDate.ToString("yyyy-MM-dd"))).ToString("u");

            var m_list = GetMaxMinAvgStat(sDate, sNDate);

            List <CabinetData> datas = new List <CabinetData>();

            foreach (var item in m_list)
            {
                MaxMinAvgStat stat = JsonConvert.DeserializeObject <MaxMinAvgStat>(item.ToJson());

                CabinetData data = new CabinetData(date);
                data.ClientCode         = stat._id.Client;
                data.DeviceCode         = stat._id.Device;
                data.MaxHumidity        = Convert.ToDecimal(stat.maxHum);
                data.MinHumidity        = Convert.ToDecimal(stat.minHum);
                data.AverageHumidity    = Convert.ToDecimal(Math.Round(stat.avgHum, 2));
                data.MaxTemperature     = Convert.ToDecimal(stat.maxTem);
                data.MinTemperature     = Convert.ToDecimal(stat.minTem);
                data.AverageTemperature = Convert.ToDecimal(Math.Round(stat.avgTem, 2));

                datas.Add(data);
            }

            var a_list = GetAlarmStat(sDate, sNDate);

            foreach (var item in a_list)
            {
                AlarmStat stat = JsonConvert.DeserializeObject <AlarmStat>(item.ToJson());

                CabinetData data = datas.Where(q => q.ClientCode.Equals(stat._id.Client) && q.DeviceCode.Equals(stat._id.Device)).FirstOrDefault();

                if (data == null)
                {
                    continue;
                }

                data.HumidityAlarm    = stat.HumAlarm;
                data.TemperatureAlarm = stat.TemAlarm;
            }

            AppendLog("获取数据" + datas.Count + " 条,准备推送到数据库\r\n");
            UpdateSql(datas);
        }
Example #2
0
        private ArrayList getCabinetsDataByDay(DateTime startDate, DateTime endDate, string stationCode, List <string> devices)
        {
            List <CabinetData> datas = _context.CabinetData.Where(q => q.ClientCode.Equals(stationCode) &&
                                                                  q.CreateTime > startDate && q.CreateTime < endDate).ToList();

            TimeSpan span = endDate - startDate;

            ArrayList array = new ArrayList();

            foreach (var item in devices)
            {
                Pchart _chart = new Pchart(item);

                for (int i = 0, length = span.Days; i < length; i++)
                {
                    DateTime _date = startDate.AddDays(i);
                    _chart.XAxis.Add(_date.ToShortDateString());
                    CabinetData _data = datas.Where(q => q.DeviceCode.Equals(item) && q.Year == _date.Year &&
                                                    q.Month == _date.Month && q.Day == _date.Day).FirstOrDefault();
                    if (_data == null)
                    {
                        _chart.Temperature.Add(null);
                        _chart.Humidity.Add(null);
                    }
                    else
                    {
                        _chart.Temperature.Add(_data.AverageTemperature);
                        _chart.Humidity.Add(_data.AverageHumidity);
                    }
                }

                array.Add(_chart);
            }

            return(array);
        }