public ActionResult Test() { var time = DateTime.Now; var time1 = time.AddDays(-1); TimeCheck span = new TimeCheck(); span.CheckTicks(time1, time); return(View()); }
public object StaMainpq(DateTime currtime, DateTime begtime, string sid) { var checktime = check.CheckTicks(currtime, begtime); var query = dal.QueryWhere(d => d.DateTime >= begtime && d.DateTime <= currtime); string sql = "select * from AP_Centrifuge_History where DateTime>='" + begtime + "'and DateTime<='" + currtime + "'and StationID='" + sid + "'and Id%100<=25 and Id%100>0"; if (checktime[1] <= 24) { //var res = dal.QueryNoParams(sql).Select(s => new //{ // mainp = s.Outlet_P, // mainq = s.ePower, // staid = s.EquipID //}).GroupBy(g => g.staid); var res = dal.QueryWhere(d => d.StationID == sid && d.DateTime >= begtime && d.DateTime <= currtime && d.Id % 100 <= 25 && d.Id % 100 > 0).Select(s => new { mainp = s.Outlet_P, mainq = s.ePower, staid = s.EquipID }).GroupBy(g => g.staid).ToList(); //var res = dal.QueryWhere(d => d.StationID == sid && d.DateTime >= begtime && d.DateTime <= currtime).Select(s => new //{ // mainp = s.Outlet_P, // mainq = s.ePower, // staid = s.EquipID //}).ToList();//看个数 //var rres= dal.QueryWhere(d => d.StationID == sid && d.DateTime >= begtime && d.DateTime <= currtime&&d.Id%50<=25&&d.Id%50>0).Select(s => new //{ // mainp = s.Outlet_P, // mainq = s.ePower, // staid = s.EquipID //}).ToList();//看个数 return(res); } else { int b = (int)checktime[1] / 12 * 25 * 2; var res = dal.QueryWhere(d => d.StationID == sid && d.DateTime >= begtime && d.DateTime <= currtime && d.Id % b <= 25 && d.Id % b > 0).Select(s => new { mainp = s.Outlet_P, mainq = s.ePower, staid = s.EquipID }).GroupBy(g => g.staid).ToList(); return(res); } }
public List <decimal[]> CenlossSer(DateTime currtime, DateTime begtime, double[] arr) { var checktime = check.CheckTicks(begtime, currtime); //查历史表全部时间间隔内小于200分钟 if (checktime[2] < 200) { int b = (int)checktime[2] / 10 * 25 - 25; var res = redal.QueryWhere(d => d.DateTime >= begtime && d.DateTime <= currtime && d.Id % b <= 25 && d.Id % b > 0).Select(s => new { loss = s.LossRatio, staid = s.StationID, eqid = s.EquipID }).GroupBy(g => new { g.staid, g.eqid }).ToList(); List <decimal[]> allres = new List <decimal[]>(); foreach (var item in res) { int[] arr1 = new int[arr.Length]; foreach (var ite in item) { for (int i = 0; i < arr.Length - 1; i++) { if (ite.loss >= (decimal)arr[i] && ite.loss < (decimal)arr[i + 1]) { arr1[i]++; } else if (ite.loss >= (decimal)arr[arr.Length - 1]) { arr1[arr.Length - 1]++; } } } decimal[] dearr = new decimal[arr.Length]; int sum = arr1.Sum(); for (int i = 0; i < arr.Length; i++) { dearr[i] = Math.Round((decimal)arr1[i] / sum * 100, 2); } allres.Add(dearr); } return(allres); } //大于200分钟取值统计分钟表 else if (checktime[2] >= 200 && checktime[2] < 6000) { int b = (int)checktime[2] / 100 * 25 - 25; var res = dal.QueryWhere(d => d.DateTime >= begtime && d.DateTime <= currtime && d.YMDH.Equals("F") && d.Id % b <= 25 && d.Id % b > 0).Select(s => new { loss = s.LossRatio, staid = s.StationID, eqid = s.EquipID }).GroupBy(g => new { g.staid, g.eqid }).ToList(); List <decimal[]> allres = new List <decimal[]>(); foreach (var item in res) { int[] arr1 = new int[arr.Length]; foreach (var ite in item) { for (int i = 0; i < arr.Length - 1; i++) { if (ite.loss >= (decimal)arr[i] && ite.loss < (decimal)arr[i + 1]) { arr1[i]++; } else if (ite.loss >= (decimal)arr[arr.Length - 1]) { arr1[arr.Length - 1]++; } } } decimal[] dearr = new decimal[arr.Length]; int sum = arr1.Sum(); for (int i = 0; i < arr.Length; i++) { dearr[i] = Math.Round((decimal)arr1[i] / sum * 100, 2); } allres.Add(dearr); } return(allres); } //大于6000分钟100小时 else { if (checktime[1] < 2400) { int b = (int)checktime[1] / 100; if (b >= 3) { int c = b * 25 - 25; var res = dal.QueryWhere(d => d.DateTime >= begtime && d.DateTime <= currtime && d.YMDH.Equals("H") && d.Id % c <= 25 && d.Id % c > 0).Select(s => new { loss = s.LossRatio, staid = s.StationID, eqid = s.EquipID }).GroupBy(g => new { g.staid, g.eqid }).ToList(); List <decimal[]> allres = new List <decimal[]>(); foreach (var item in res) { int[] arr1 = new int[arr.Length]; foreach (var ite in item) { for (int i = 0; i < arr.Length - 1; i++) { if (ite.loss >= (decimal)arr[i] && ite.loss < (decimal)arr[i + 1]) { arr1[i]++; } else if (ite.loss >= (decimal)arr[arr.Length - 1]) { arr1[arr.Length - 1]++; } } } decimal[] dearr = new decimal[arr.Length]; int sum = arr1.Sum(); for (int i = 0; i < arr.Length; i++) { dearr[i] = Math.Round((decimal)arr1[i] / sum * 100, 2); } allres.Add(dearr); } return(allres); } else { var res = dal.QueryWhere(d => d.DateTime >= begtime && d.DateTime <= currtime && d.YMDH.Equals("H") && d.Id % 25 <= 25 && d.Id % 25 > 0).Select(s => new { loss = s.LossRatio, staid = s.StationID, eqid = s.EquipID }).GroupBy(g => new { g.staid, g.eqid }).ToList(); List <decimal[]> allres = new List <decimal[]>(); foreach (var item in res) { int[] arr1 = new int[arr.Length]; foreach (var ite in item) { for (int i = 0; i < arr.Length - 1; i++) { if (ite.loss >= (decimal)arr[i] && ite.loss < (decimal)arr[i + 1]) { arr1[i]++; } else if (ite.loss >= (decimal)arr[arr.Length - 1]) { arr1[arr.Length - 1]++; } } } decimal[] dearr = new decimal[arr.Length]; int sum = arr1.Sum(); for (int i = 0; i < arr.Length; i++) { dearr[i] = Math.Round((decimal)arr1[i] / sum * 100, 2); } allres.Add(dearr); } return(allres); } } //大于100天 else { int b = (int)checktime[0] / 100; if (b >= 3) { int c = b * 25 - 25; var res = dal.QueryWhere(d => d.DateTime >= begtime && d.DateTime <= currtime && d.YMDH.Equals("D") && d.Id % c <= 25 && d.Id % c > 0).Select(s => new { loss = s.LossRatio, staid = s.StationID, eqid = s.EquipID }).GroupBy(g => new { g.staid, g.eqid }).ToList(); List <decimal[]> allres = new List <decimal[]>(); foreach (var item in res) { int[] arr1 = new int[arr.Length]; foreach (var ite in item) { for (int i = 0; i < arr.Length - 1; i++) { if (ite.loss >= (decimal)arr[i] && ite.loss < (decimal)arr[i + 1]) { arr1[i]++; } else if (ite.loss >= (decimal)arr[arr.Length - 1]) { arr1[arr.Length - 1]++; } } } decimal[] dearr = new decimal[arr.Length]; int sum = arr1.Sum(); for (int i = 0; i < arr.Length; i++) { dearr[i] = Math.Round((decimal)arr1[i] / sum * 100, 2); } allres.Add(dearr); } return(allres); } else { var res = dal.QueryWhere(d => d.DateTime >= begtime && d.DateTime <= currtime && d.YMDH.Equals("D") && d.Id % 25 <= 25 && d.Id % 25 > 0).Select(s => new { loss = s.LossRatio, staid = s.StationID, eqid = s.EquipID }).GroupBy(g => new { g.staid, g.eqid }).ToList(); List <decimal[]> allres = new List <decimal[]>(); foreach (var item in res) { int[] arr1 = new int[arr.Length]; foreach (var ite in item) { for (int i = 0; i < arr.Length - 1; i++) { if (ite.loss >= (decimal)arr[i] && ite.loss < (decimal)arr[i + 1]) { arr1[i]++; } else if (ite.loss >= (decimal)arr[arr.Length - 1]) { arr1[arr.Length - 1]++; } } } decimal[] dearr = new decimal[arr.Length]; int sum = arr1.Sum(); for (int i = 0; i < arr.Length; i++) { dearr[i] = Math.Round((decimal)arr1[i] / sum * 100, 2); } allres.Add(dearr); } return(allres); } } } }
public object LossSer(DateTime currtime, DateTime begtime, double[] arr) { var checktime = check.CheckTicks(begtime, currtime); var query = dal.QueryWhere(d => d.DateTime >= begtime && d.DateTime <= currtime); if (checktime[1] <= 24) { query = query.Where(x => x.Id % 2 == 1); } else { int b = (int)checktime[1] / 12; query = query.Where(x => x.Id % b == 1); } var res = query.Select(s => new { loss = s.LossRatio }).ToList(); //最大值 double Max = (double)res.Max(r => r.loss); //最小值 double Min = (double)res.Min(r => r.loss); //分成10份差值 double Dvalue = (Max - Min) / 10; string str = "" + Dvalue; string[] strarr = str.Split(new char[] { '.' }); int slength = strarr[1].Length; int MinInt = (int)Min; int Count = 0; List <double> douarr = new List <double>(); for (int i = 0; i < 20; i++) { double listvalue = Math.Round(MinInt + i * Dvalue, slength); douarr.Add(listvalue); if (listvalue >= Max) { Count = i; break; } } int[] arr1 = new int[douarr.Count]; foreach (var item in res) { for (int i = 0; i < douarr.Count - 1; i++) { if (item.loss >= (decimal)douarr[i] && item.loss < (decimal)douarr[i + 1]) { arr1[i]++; } else if (item.loss >= (decimal)douarr[douarr.Count - 1]) { arr1[douarr.Count - 1]++; } } } decimal[] dearr = new decimal[arr1.Length]; var sum = arr1.Sum(); for (int i = 0; i < arr1.Length; i++) { dearr[i] = Math.Round((decimal)arr1[i] / sum * 100, 2); } var tranres = new { a = dearr, x = douarr, ca = Dvalue, l = slength }; return(tranres); }
public object StaProduce(DateTime currtime, DateTime begtime, int[] arr, string sid) { var checktime = check.CheckTicks(begtime, currtime); var tranres = new object(); List <decimal[]> alllist = new List <decimal[]>(); var query = dal.QueryWhere(d => d.DateTime >= begtime && d.DateTime <= currtime); if (checktime[1] <= 24) { query = query.Where(d => d.Id % 8 <= 4 && d.Id % 8 > 0); } else { int b = (int)checktime[1] / 12 * 4; query = query.Where(d => d.Id % b <= 4 && d.Id % b > 0); } var res = query.Where(x => x.StationID == sid).Select(s => new { staid = s.StationID, mainq = s.Main_Q }).GroupBy(g => g.staid).ToList(); foreach (var item in res) { int Max = (int)item.Max(r => r.mainq); int Min = (int)item.Min(r => r.mainq); string MaxStr = (Convert.ToInt32(Max.ToString().Substring(0, 2))).ToString(); string MinStr = (Convert.ToInt32(Min.ToString().Substring(0, 2))).ToString(); for (int i = 0; i < Max.ToString().Length - 2; i++) { MaxStr += "0"; } for (int i = 0; i < Min.ToString().Length - 2; i++) { MinStr += "0"; } int MaxInt = Convert.ToInt32(MaxStr); int MinInt = Convert.ToInt32(MinStr); int Dvalue = MaxInt - MinInt; int Divide = Dvalue / 10; int Count = 0; List <int> testarr = new List <int>(); for (int i = 0; i < 20; i++) { int test = MinInt + i * Divide; testarr.Add(test); if (test >= Max) { Count = i; break; } } int[] arr1 = new int[testarr.Count]; foreach (var it in item) { for (int i = 0; i < arr1.Length - 1; i++) { if (it.mainq >= testarr[i] && it.mainq < testarr[i + 1]) { arr1[i]++; } else if (it.mainq >= testarr[testarr.Count - 1]) { arr1[arr1.Length - 1]++; } } } double[] dearr = new double[arr1.Length]; double sum = arr1.Sum(); for (int i = 0; i < arr1.Length; i++) { dearr[i] = Math.Round(arr1[i] / sum * 100, 2); } double dsum = (double)dearr.Sum(); tranres = new { a = dearr, x = testarr, ca = Divide }; } return(tranres); }
public ActionResult PressDesignConList(int limit = 3, int curr = 1) { //获取数据 List <Model.AP_PressDesign_Conclusion> res = pressconSer.PressDesignConJson(limit, curr); //总数 int count = pressconSer.AllCount(); //负载 string[] strarr = new string[4] { "基础负载", "二级负载", "三级负载", "四级负载" }; //时间集合 List <string> timelist = new List <string>(); List <double> upilist = new List <double>(); List <List <double> > doubleGetlist = new List <List <double> >(); List <List <double> > doubleSetlist = new List <List <double> >(); #region 循环处理 foreach (var item in res) { //将获得的压力值分组 string[] resarr = item.Conclusion.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); //当前时间 string time = DateTime.Parse("" + item.Time).ToString("yyyy-MM-dd HH:mm:ss"); //获取Upi平均值 //获取上一行的时间 DateTime currenttime = Convert.ToDateTime(item.Time); DateTime beforetime = Convert.ToDateTime(pressconSer.Find(new object[] { item.Id - 1 }).Time); //获取两个时间段的upi平均值 TimeCheck ddtime = new TimeCheck(); List <long> checktime = ddtime.CheckTicks(currenttime, beforetime); double upires = Math.Round(factoryHisSer.PressDesignUPISer(currenttime, beforetime.AddHours(-4), (int)checktime[1]) * 1000, 2); timelist.Add(time); upilist.Add(upires); //空压站1压力集合 List <double> doublelist1 = new List <double>(); //空压站2压力集合 List <double> doublelist2 = new List <double>(); //空压站3压力集合 List <double> doublelist3 = new List <double>(); //空压站4压力集合 List <double> doublelist4 = new List <double>(); //将获取值加入四组中 for (int i = 0; i < 7; i++) { if (i < 6) { doublelist1.Add(Convert.ToDouble(resarr[i])); doublelist2.Add(Convert.ToDouble(resarr[i + 6])); doublelist3.Add(Convert.ToDouble(resarr[i + 12])); doublelist4.Add(Convert.ToDouble(resarr[i + 18])); } else { doublelist4.Add(Convert.ToDouble(resarr[i + 18])); } } #region 四个空压站去重分组 List <double> list1 = doublelist1.Distinct().ToList(); int count1 = list1.Count(); if (list1.Count() < 4) { for (int i = 0; i < 4 - count1; i++) { list1.Add(0); } } list1.Sort(); list1.Reverse(); var list2 = doublelist2.Distinct().ToList(); int count2 = list2.Count(); if (list2.Count() < 4) { for (int i = 0; i < 4 - count2; i++) { list2.Add(0); } } list2.Sort(); list2.Reverse(); var list3 = doublelist3.Distinct().ToList(); int count3 = list3.Count(); if (list3.Count() < 4) { for (int i = 0; i < 4 - count3; i++) { list3.Add(0); } } list3.Sort(); list3.Reverse(); var list4 = doublelist4.Distinct().ToList(); int count4 = list4.Count(); if (list4.Count() < 4) { for (int i = 0; i < 4 - count4; i++) { list4.Add(0); } } list4.Sort(); list4.Reverse(); #endregion #region 四个空压站压力设定值集合 //四个空压站压力设定值集合 List <double> fourpressSetlist = new List <double>(); for (var i = 0; i < 16; i++) { if (i < 4) { fourpressSetlist.Add(list1[i]); } else if (i < 8 && i >= 4) { fourpressSetlist.Add(list2[i - 4]); } else if (i < 12 && i >= 8) { fourpressSetlist.Add(list3[i - 8]); } else { fourpressSetlist.Add(list4[i - 12]);; } } #endregion #region 四个空压站压力获取值集合 //四个空压站压力获取值集合 List <double> fourpressGetlist = new List <double>(); for (var i = 0; i < 25; i++) { if (i < 6) { fourpressGetlist.Add(doublelist1[i]); } else if (i < 12 && i >= 6) { fourpressGetlist.Add(doublelist2[i - 6]); } else if (i < 18 && i >= 12) { fourpressGetlist.Add(doublelist3[i - 12]); } else { fourpressGetlist.Add(doublelist4[i - 18]); } } #endregion doubleGetlist.Add(fourpressGetlist); doubleSetlist.Add(fourpressSetlist); } #endregion Model.ViewObject.PressDesign press = new Model.ViewObject.PressDesign() { ListGet = doubleGetlist, ListSet = doubleSetlist, pressarr = strarr, Time = timelist, upiarr = upilist }; var intarr = new { Count = count, Curr = curr, Limit = limit }; ViewBag.Count = JsonConvert.SerializeObject(intarr); return(View(press)); }
/// <summary> /// 压力设定实时记录表6S刷新 /// </summary> /// <returns></returns> public ActionResult SixSecond() { DateTime now = DateTime.Now; //获取id最大的一条 AP_PressDesign_Conclusion res = pressconSer.Find(new object[] { pressconSer.QueryWhere().Max(x => x.Id) }); //获取数据库时间 DateTime checktime = DateTime.Parse("" + res.Time); string restime = checktime.ToString("yyyy/MM/dd HH:mm:ss"); string rescon = res.Conclusion; TimeCheck second = new TimeCheck(); //获得秒差 var check = second.CheckTicks(now, checktime); //小于6秒说明有更新 if (check[3] < 6) { //上一条时间 DateTime beforetime = Convert.ToDateTime(pressconSer.Find(new object[] { res.Id - 1 }).Time); DateTime fixtime = DateTime.Parse("2019-06-27 00:00:00"); int dvalue = (checktime - fixtime).Days; DateTime currtime = checktime; beforetime = currtime.AddHours(-5); double resupi = Math.Round(factoryHisSer.PressDesignUPISer(currtime, beforetime, 5) * 1000, 2);//单位转换 string[] resarr = rescon.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); List <double> doublelist1 = new List <double>(); List <double> doublelist2 = new List <double>(); List <double> doublelist3 = new List <double>(); List <double> doublelist4 = new List <double>(); for (int i = 0; i < 7; i++) { if (i < 6) { doublelist1.Add(Convert.ToDouble(resarr[i])); doublelist2.Add(Convert.ToDouble(resarr[i + 6])); doublelist3.Add(Convert.ToDouble(resarr[i + 12])); doublelist4.Add(Convert.ToDouble(resarr[i + 18])); } else { doublelist4.Add(Convert.ToDouble(resarr[i + 18])); } } List <double> dlist1 = doublelist1.Where(x => x.ToString() != "0").ToList(); List <double> dlist2 = doublelist2.Where(x => x.ToString() != "0").ToList(); List <double> dlist3 = doublelist3.Where(x => x.ToString() != "0").ToList(); List <double> dlist4 = doublelist4.Where(x => x.ToString() != "0").ToList(); var list1 = dlist1.Distinct().ToList(); int count1 = list1.Count(); if (list1.Count() < 4) { for (int i = 0; i < 4 - count1; i++) { list1.Add(0); } } list1.Sort(); list1.Reverse(); var list2 = dlist2.Distinct().ToList(); int count2 = list2.Count(); if (list2.Count() < 4) { for (int i = 0; i < 4 - count2; i++) { list2.Add(0); } } list2.Sort(); list2.Reverse(); var list3 = dlist3.Distinct().ToList(); int count3 = list3.Count(); if (list3.Count() < 4) { for (int i = 0; i < 4 - count3; i++) { list3.Add(0); } } list3.Sort(); list3.Reverse(); var list4 = dlist4.Distinct().ToList(); int count4 = list4.Count(); if (list4.Count() < 4) { for (int i = 0; i < 4 - count4; i++) { list4.Add(0); } } list4.Sort(); list4.Reverse(); List <List <double> > sortlist = new List <List <double> >(); sortlist.Add(list1); sortlist.Add(list2); sortlist.Add(list3); sortlist.Add(list4); sortlist.Add(doublelist1); sortlist.Add(doublelist2); sortlist.Add(doublelist3); sortlist.Add(doublelist4); string[] strarr = new string[4] { "基础负载", "二级负载", "三级负载", "四级负载" }; return(Json(new { mess = "有", value = sortlist, str = strarr, time = restime, upi = resupi }, JsonRequestBehavior.AllowGet)); } //大于6秒没有查到更新 else { return(Json(new { mess = "无", value = "", str = "" }, JsonRequestBehavior.AllowGet)); } }