示例#1
0
 public ActionResult Index(int id=1,string terminal="EMMS001")
 {
     Bindddl();
     ViewBag.TerminalID = terminal;
     var result = db.EMdatas.Where(p=>p.TerminalID==terminal).Include(p=>p.Terminal).OrderBy(p=>p.Update);
     var bindColor = (IEnumerable<EMdata>)result;
     EMdata now = new EMdata();
     if (bindColor.LastOrDefault() != null)
     {
         now.Temperature = bindColor.LastOrDefault().Temperature;
         now.Pm25 = bindColor.LastOrDefault().Pm25;
         now.Luminance = bindColor.LastOrDefault().Luminance;
         now.Humidity = bindColor.LastOrDefault().Humidity;
         now.UV = bindColor.LastOrDefault().UV;
         now.GasIntensity = bindColor.LastOrDefault().GasIntensity;
         BindColor(now);
     }
     if (result.Count() == 0)
     {
         EMdata em = new EMdata();
         Terminal term = new Terminal();
         term.TerminalName = "无";
         term.TerminalAddr = "无";
         em.Terminal = term;
         em.UV = em.Pm25 = em.Luminance = em.GasIntensity = -1;
         em.Humidity = em.Temperature = -1;
         List<EMdata> emlst=new List<EMdata>();
         emlst.Add(em);
         return View(emlst);
     }
     return View(result);
 }
示例#2
0
        public ActionResult Month(string terminal = "EMMS001")
        {
            Bindddl();

            DateTime Ago24 = DateTime.Now.AddDays(-30);

            var result = db.EMdatas.Where(p => p.TerminalID == terminal && p.Update >= Ago24).Include(p => p.Terminal).OrderBy(p => p.Update);
            var bindColor = (IEnumerable<EMdata>)result;
            double TemAvg = 0, HumiAvg = 0, Pm25Avg = 0, LuminAvg = 0, UVAvg = 0;
            int count = 0;
            foreach (var item in bindColor)
            {
                TemAvg += (double)item.Temperature;
                HumiAvg += (double)item.Humidity;
                Pm25Avg += (int)item.Pm25;
                LuminAvg += (int)item.Luminance;
                UVAvg += (int)item.UV;
                count++;
            }
            TemAvg /= count;
            HumiAvg /= count;
            Pm25Avg /= count;
            LuminAvg /= count;
            UVAvg /= count;
            ViewBag.TemAvg = TemAvg;
            ViewBag.HumiAvg = HumiAvg;
            ViewBag.Pm25Avg = Pm25Avg;
            ViewBag.LuminAvg = LuminAvg;
            ViewBag.UVAvg = UVAvg;
            ViewBag.TerminalID = terminal;
            EMdata now = new EMdata();
            if (bindColor.LastOrDefault() != null)
            {
                now.Temperature = bindColor.LastOrDefault().Temperature;
                now.Pm25 = bindColor.LastOrDefault().Pm25;
                now.Luminance = bindColor.LastOrDefault().Luminance;
                now.Humidity = bindColor.LastOrDefault().Humidity;
                now.UV = bindColor.LastOrDefault().UV;
                now.GasIntensity = bindColor.LastOrDefault().GasIntensity;
                BindColor(now);
            }
            return View(result);
        }
示例#3
0
        public ActionResult Receive(string terID, double tem, double humi, int pm25, int lum, int uv, int gas, double votal)
        {
            var terminal = db.Terminals.FirstOrDefault(p => p.TerminalID == terID);
            if (terminal == null)
            {
                Response.Write("Is not exist this terminal:TerminalID=" + terID);
                return View();
            }
            EMdata newData = new EMdata();
            newData.TerminalID = terID;
            newData.Temperature = tem;
            newData.Humidity = humi;
            newData.Pm25 = pm25;
            newData.Luminance = lum;
            newData.UV = uv;
            newData.GasIntensity = gas;
            newData.Update = DateTime.Now;
            db.EMdatas.Add(newData);
            terminal.TerminalVotal = votal;
            terminal.TerminalConnect = 1;
            db.SaveChanges();

            string alarmContent = "";
            int isAlarm = 0;
            if (tem >= terminal.TemMax)
            {
                isAlarm = 1;
                alarmContent += "温度超过警戒值;  ";
            }
            if (humi >= terminal.HumiMax)
            {
                isAlarm = 1;
                alarmContent += "湿度超过警戒值;  ";
            }
            if (pm25 >= terminal.Pm25Max)
            {
                isAlarm = 1;
                alarmContent += "PM2.5超过警戒值;  ";
            }
            if (lum >= terminal.LuminMax)
            {
                isAlarm = 1;
                alarmContent += "亮度超过警戒值;  ";
            }
            if (uv >= terminal.UVMax)
            {
                isAlarm = 1;
                alarmContent += "紫外强度超过警戒值;  ";
            }
            if (gas >= terminal.GasMax)
            {
                isAlarm = 1;
                alarmContent += "可燃气体浓度超过警戒值;  ";
            }
            if (isAlarm == 1)
            {
                Alarm newAlarm = new Alarm();
                newAlarm.AlarmContent = alarmContent;
                newAlarm.AlarmTermID = terminal.TerminalID;
                newAlarm.AlarmDate = DateTime.Now;
                newAlarm.IsRead = 0;
                db.Alarms.Add(newAlarm);
                db.SaveChanges();
                Response.Write("Upload succesful.Having alarm.");
            }
            else
            {
                Response.Write("Upload succesful");
            }
            return View();
        }
示例#4
0
        public ActionResult dayChart(EmdataSearchModel model)
        {
            if (this.ModelState.IsValid)
            {
                DateTime sTime = new DateTime(model.StartTime.Year, model.StartTime.Month, model.StartTime.Day, 0, 0, 0);
                DateTime eTime = new DateTime(model.EndTime.Year, model.EndTime.Month, model.EndTime.Day, 23, 59, 59);
                var result = db.EMdatas.Where(p => p.Update >= sTime && p.Update <= eTime && p.TerminalID == model.TerminalID).Include(p => p.Terminal);
                if (result.Count() == 0)
                {
                    return View("HaveNoData");
                }
                var recent = result.OrderByDescending(p => p.Update).FirstOrDefault();
                DateTime sDate = result.FirstOrDefault().Update;
                DateTime rDate = recent.Update;
                DateTime i = sDate;
                DateTime a = sDate;
                List<EMdata> ls = new List<EMdata>();
                int count = 0;
                for (; i <= rDate; i = i.AddDays(1))
                {
                    EMdata em = new EMdata();
                    em.Update = new DateTime(i.Year, i.Month, i.Day, 12, 0, 0);
                    em.GasIntensity = em.UV = em.Luminance = em.Pm25 = 0;
                    em.Temperature = em.Humidity = 0;
                    foreach (var item in result)
                    {
                        em.TerminalID = item.TerminalID;
                        em.Terminal = item.Terminal;
                        TimeSpan ts = item.Update - i;
                        if (ts.Days >= 0 && ts.Days < 1)
                        {
                            em.Temperature += item.Temperature;
                            em.Humidity += item.Humidity;
                            em.Luminance += item.Luminance;
                            em.Pm25 += item.Pm25;
                            em.UV += item.UV;
                            em.GasIntensity += item.GasIntensity;
                            count++;
                        }
                    }
                    if (count == 0)
                    {
                        continue;
                    }
                    em.Temperature = em.Temperature / count;
                    em.Humidity = em.Humidity / count;
                    em.Luminance = em.Luminance / count;
                    em.Pm25 = em.Pm25 / count;
                    em.UV = em.UV / count;
                    em.GasIntensity = em.GasIntensity / count;
                    ls.Add(em);
                    count = 0;
                }

                ViewBag.recentData = ls.LastOrDefault();
                ViewBag.emData = ls;
            }
            else
            {
                var result = db.EMdatas.Where(p => p.TerminalID == model.TerminalID).Include(p => p.Terminal);
                var recent = result.OrderByDescending(p => p.Update).FirstOrDefault();
                DateTime sDate = result.FirstOrDefault().Update;
                DateTime rDate = recent.Update;
                DateTime i = sDate;
                DateTime a = sDate;
                List<EMdata> ls = new List<EMdata>();
                int count = 0;
                for (; i <= rDate; i = i.AddDays(1))
                {
                    EMdata em = new EMdata();
                    em.Update = new DateTime(i.Year, i.Month, i.Day, 12, 0, 0);
                    em.GasIntensity = em.UV = em.Luminance = em.Pm25 = 0;
                    em.Temperature = em.Humidity = 0;
                    foreach (var item in result)
                    {
                        em.TerminalID = item.TerminalID;
                        em.Terminal = item.Terminal;
                        TimeSpan ts = item.Update - i;
                        if (ts.Days >= 0 && ts.Days < 1)
                        {
                            em.Temperature += item.Temperature;
                            em.Humidity += item.Humidity;
                            em.Luminance += item.Luminance;
                            em.Pm25 += item.Pm25;
                            em.UV += item.UV;
                            em.GasIntensity += item.GasIntensity;
                            count++;
                        }
                    }
                    if (count == 0)
                    {
                        continue;
                    }
                    em.Temperature = em.Temperature / count;
                    em.Humidity = em.Humidity / count;
                    em.Luminance = em.Luminance / count;
                    em.Pm25 = em.Pm25 / count;
                    em.UV = em.UV / count;
                    em.GasIntensity = em.GasIntensity / count;
                    ls.Add(em);
                    count = 0;
                }

                ViewBag.recentData = ls.LastOrDefault();
                ViewBag.emData = ls;
            }
            Bindddl();
            return View(model);
        }
示例#5
0
        public ActionResult dayChart(string terId = "")
        {
            string nowTerId;
            EmdataSearchModel esm = new EmdataSearchModel();

            if (string.IsNullOrEmpty(terId))
            {
                nowTerId = db.Terminals.FirstOrDefault().TerminalID;
                var result = db.EMdatas.Where(p => p.TerminalID == nowTerId).OrderBy(p => p.Update).Include(p => p.Terminal);
                var recent = result.OrderByDescending(p => p.Update).FirstOrDefault();
                if (result.Count() == 0)
                {
                    return View("HaveNoData");
                }
                DateTime sDate = result.FirstOrDefault().Update;
                DateTime rDate = recent.Update;
                DateTime i = sDate;
                DateTime a = sDate;
                List<EMdata> ls = new List<EMdata>();
                int count = 0;
                for (; i <= rDate; i = i.AddDays(1))
                {
                    EMdata em = new EMdata();
                    em.Update = new DateTime(i.Year, i.Month, i.Day, 12, 0, 0);
                    em.GasIntensity = em.UV = em.Luminance = em.Pm25 = 0;
                    em.Temperature = em.Humidity = 0;
                    foreach (var item in result)
                    {
                        em.TerminalID = item.TerminalID;
                        em.Terminal = item.Terminal;
                        TimeSpan ts = item.Update - i;
                        if (ts.Days >= 0 && ts.Days < 1)
                        {
                            em.Temperature += item.Temperature;
                            em.Humidity += item.Humidity;
                            em.Luminance += item.Luminance;
                            em.Pm25 += item.Pm25;
                            em.UV += item.UV;
                            em.GasIntensity += item.GasIntensity;
                            count++;
                        }
                    }
                    if (count == 0)
                    {
                        continue;
                    }
                    em.Temperature = em.Temperature / count;
                    em.Humidity = em.Humidity / count;
                    em.Luminance = em.Luminance / count;
                    em.Pm25 = em.Pm25 / count;
                    em.UV = em.UV / count;
                    em.GasIntensity = em.GasIntensity / count;
                    ls.Add(em);
                    count = 0;
                }

                ViewBag.recentData = ls.LastOrDefault();
                ViewBag.emData = ls;
            }
            else
            {
                nowTerId = terId;
                var result = db.EMdatas.Include(p => p.Terminal).Where(p => p.TerminalID == terId);
                var recent = result.OrderByDescending(p => p.Update).FirstOrDefault();
                ViewBag.recentData = recent;
                ViewBag.emData = result;
            }

            esm.TerminalID = nowTerId;
            esm.StartTime = new DateTime(2010, 1, 1);
            esm.EndTime = DateTime.Now;
            Bindddl();

            return View(esm);
        }
示例#6
0
        private void BindColor(EMdata now)
        {
            if (null != now)
            {
                if (now.Temperature < 0)
                {
                    ViewBag.TemColor1 = "#188eff";
                    ViewBag.TemColor2 = "blue";
                }
                else if (now.Temperature >= 0 && now.Temperature < 10)
                {
                    ViewBag.TemColor1 = "#39fb18";
                    ViewBag.TemColor2 = "green";
                }
                else if (now.Temperature >= 10 && now.Temperature < 20)
                {
                    ViewBag.TemColor1 = "#ffe718";
                    ViewBag.TemColor2 = "yellow";
                }
                else if (now.Temperature >= 20 && now.Temperature < 30)
                {
                    ViewBag.TemColor1 = "#398a18";
                    ViewBag.TemColor2 = "orange";
                }
                else if (now.Temperature >= 30)
                {
                    ViewBag.TemColor1 = "#ff2c18";
                    ViewBag.TemColor2 = "red";
                }

                if (now.Pm25 >= 0 && now.Pm25 < 75)
                {
                    ViewBag.Pm25Color1 = "P6";
                    ViewBag.Pm25Color2 = "#3BCA18";
                    ViewBag.Pm25Level = "优";
                }
                else if (now.Pm25 >= 75 && now.Pm25 < 150)
                {
                    ViewBag.Pm25Color1 = "P5";
                    ViewBag.Pm25Color2 = "#EEDC32";
                    ViewBag.Pm25Level = "良";
                }
                else if (now.Pm25 >= 150 && now.Pm25 < 300)
                {
                    ViewBag.Pm25Color1 = "P4";
                    ViewBag.Pm25Color2 = "#DCAD43";
                    ViewBag.Pm25Level = "轻度污染";
                }
                else if (now.Pm25 >= 300 && now.Pm25 < 1050)
                {
                    ViewBag.Pm25Color1 = "P3";
                    ViewBag.Pm25Color2 = "#F2401A";
                    ViewBag.Pm25Level = "中度污染";
                }
                else if (now.Pm25 >= 1050 && now.Pm25 < 3000)
                {
                    ViewBag.Pm25Color1 = "P2";
                    ViewBag.Pm25Color2 = "#BF0841";
                    ViewBag.Pm25Level = "重度污染";
                }
                else if (now.Pm25 >= 3000)
                { 
                    ViewBag.Pm25Color1 = "P1";
                    ViewBag.Pm25Color2 = "#9B0A4D";
                    ViewBag.Pm25Level = "严重污染";
                }

                if (now.Luminance >= 0 && now.Luminance < 5) ViewBag.LuminColor = "L5";
                else if (now.Luminance >= 5 && now.Luminance < 75) ViewBag.LuminColor = "L4";
                else if (now.Luminance >= 75 && now.Luminance < 750) ViewBag.LuminColor = "L3";
                else if (now.Luminance >= 750 && now.Luminance < 7500) ViewBag.LuminColor = "L2";
                else if (now.Luminance >= 7500) ViewBag.LuminColor = "L1";

                if (now.Humidity >= 0 && now.Humidity < 20) ViewBag.HumiColor = "S5";
                else if (now.Humidity >= 20 && now.Humidity < 40) ViewBag.HumiColor = "S4";
                else if (now.Humidity >= 40 && now.Humidity < 60) ViewBag.HumiColor = "S3";
                else if (now.Humidity >= 60 && now.Humidity < 80) ViewBag.HumiColor = "S2";
                else if (now.Humidity >= 80) ViewBag.HumiColor = "S1";

                if (now.UV >= 0 && now.UV < 2) ViewBag.UVColor = "Z1";
                else if (now.UV >= 2 && now.UV < 4) ViewBag.UVColor = "Z2";
                else if (now.UV >= 4 && now.UV < 6) ViewBag.UVColor = "Z3";
                else if (now.UV >= 6 && now.UV < 9) ViewBag.UVColor = "Z4";
                else if (now.UV >= 9) ViewBag.UVColor = "Z5";

                if (now.GasIntensity >= 300) ViewBag.GasColor = "red";
                else ViewBag.GasColor = "green";

            }
        }