public string GetHistory(string ID, string StartTime, string EndTime) { try { BllMonitor bm = new BllMonitor(); return(Utils.ToJson(bm.GetHistory(ID, StartTime, EndTime), true)); } catch (Exception) { throw new Exception("查询历史轨迹数据出错!"); } }
public string GetStopDetail(string DeviceID, string StartTime, string EndTime) { try { BllMonitor bm = new BllMonitor(); List <History> his = bm.GetHistory(DeviceID, StartTime, EndTime); List <Dictionary <string, string> > retuList = new List <Dictionary <string, string> >(); for (int i = 1; i < his.Count; i++) { History sh = his[i - 1], eh = his[i]; DateTime start = Convert.ToDateTime(sh.DeviceTime); DateTime end = Convert.ToDateTime(eh.DeviceTime); TimeSpan ts = (end - start); if (ts.TotalSeconds > Utils.StopSeconds) { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("starttime", start.ToString("yyyy-MM-dd HH:mm:ss")); dic.Add("endtime", end.ToString("yyyy-MM-dd HH:mm:ss")); dic["lon"] = Convert.ToDouble(sh.Lon).ToString("0.00000"); dic["lat"] = Convert.ToDouble(sh.Lat).ToString("0.00000"); string time = ""; if (ts.Days > 0) { time += ts.Days + "天"; } if (ts.Hours > 0) { time += ts.Hours + "时"; } if (ts.Minutes > 0) { time += ts.Minutes + "分"; } dic["time"] = time; dic["address"] = ""; retuList.Add(dic); i++; } } return(Utils.ToJson(retuList)); } catch (Exception) { return(""); } }
/// <summary> /// 获取停留折线图数据 /// </summary> /// <param name="DeviceID">设备id</param> /// <param name="Time">时间(一天)</param> /// <returns></returns> public string GetEcharts(string DeviceID, string Time) { BllMonitor bm = new BllMonitor(); History sh = new History(); sh.DeviceTime = Convert.ToDateTime(Convert.ToDateTime(Time).ToString("yyyy-MM-dd 00:00:00")).ToString(); sh.Speed = 0; History eh = new History(); eh.DeviceTime = Convert.ToDateTime(Convert.ToDateTime(Time).ToString("yyyy-MM-dd 23:59:59")).ToString();; eh.Speed = 0; List <History> his = bm.GetHistory(DeviceID, Convert.ToDateTime(Time).ToString("yyyy-MM-dd 00:00:00"), Convert.ToDateTime(Time).ToString("yyyy-MM-dd 23:59:59")); his.Insert(0, sh); his.Add(eh); List <History> dtErr = new List <History>(); List <History> conErr = new List <History>(); for (int i = 0; i < his.Count; i++) { if (Convert.ToDateTime(his[i].DeviceTime) < Convert.ToDateTime(sh.DeviceTime)) { dtErr.Add(his[i]); } if (Convert.ToDateTime(his[i].ConnectTime) < Convert.ToDateTime(sh.ConnectTime)) { conErr.Add(his[i]); } } List <Dictionary <string, string> > retuList = new List <Dictionary <string, string> >(); for (int i = 1; i < his.Count; i++) { if (Convert.ToDateTime(his[i].DeviceTime) < Convert.ToDateTime(sh.DeviceTime) || Convert.ToDateTime(his[i - 1].DeviceTime) < Convert.ToDateTime(sh.DeviceTime)) { continue; } History s = his[i - 1]; History e = his[i]; TimeSpan ts = (Convert.ToDateTime(e.DeviceTime) - Convert.ToDateTime(s.DeviceTime)); Dictionary <string, string> dic = new Dictionary <string, string>(); dic["Speed"] = s.Speed + ""; dic["DeviceTime"] = Convert.ToDateTime(s.DeviceTime).ToString(); retuList.Add(dic); if (ts.TotalSeconds > 25) { //填充数据 int seconds = (int)(ts.TotalSeconds / 10); for (int j = 0; j < seconds; j++) { dic = new Dictionary <string, string>(); dic["Speed"] = "0"; dic["DeviceTime"] = Convert.ToDateTime(s.DeviceTime).AddSeconds((j + 1) * 10).ToString("yyyy-MM-dd HH:mm:ss"); retuList.Add(dic); //i--; } } } JavaScriptSerializer js = new JavaScriptSerializer(); js.MaxJsonLength = int.MaxValue; return(js.Serialize(retuList)); }
public string GetMileage(string DeviceID, string StartTime, string EndTime) { if (string.IsNullOrWhiteSpace(DeviceID) || DeviceID == "null") { return(""); } long sticks = Convert.ToDateTime(StartTime).Ticks; long eticks = Convert.ToDateTime(EndTime).Ticks; BllMonitor bm = new BllMonitor(); try { List <History> his = bm.GetHistory(DeviceID, StartTime, EndTime); DataTable dt = new DataTable(); dt.Columns.Add("time"); dt.Columns.Add("lat"); dt.Columns.Add("lon"); int stopCount = 0; DateTime tempTime = default(DateTime); for (int i = 0; i < his.Count; i++) { History h = his[i]; if (h.Speed < Utils.SpeedFilter) { continue; } DataRow dr = dt.NewRow(); dr["time"] = h.DeviceTime; dr["lat"] = h.Lat; dr["lon"] = h.Lon; dt.Rows.Add(dr); } MgoogpsWebClient myWeb = new MgoogpsWebClient(); myWeb.RequestMethodName = "/service/getalarmhistorybydevice/?param=id," + DeviceID + "&starttime," + sticks + "&endtime," + eticks; string json = myWeb.RequestSend(); List <Dictionary <string, string> > alarmList = js.Deserialize <List <Dictionary <string, string> > >(json); Hashtable hb = new Hashtable(); Dictionary <string, string> retu = new Dictionary <string, string>(); string key = ""; for (int i = 0; i < alarmList.Count; i++) { Dictionary <string, string> dicAlarm = alarmList[i]; dicAlarm["alarmtime"] = Convert.ToDateTime(dicAlarm["alarmtime"]).ToString("yyyy-MM-dd"); key = dicAlarm["alarmtime"];// + "," + dicAlarm["alarmtype"]; if (retu.ContainsKey(key)) { retu[key] = (Convert.ToInt32(retu[key]) + 1) + ""; } else { retu[key] = "1"; } } Dictionary <string, string> rJson = new Dictionary <string, string>(); foreach (KeyValuePair <string, string> item in retu) { List <Dictionary <string, string> > points = new List <Dictionary <string, string> >(); Dictionary <string, string> alarmTypeCount = new Dictionary <string, string>(); key = item.Key.ToString(); for (int i = 0; i < dt.Rows.Count; i++) { DateTime t = Convert.ToDateTime(dt.Rows[i]["time"]);//.ToString(); if (key == t.ToString("yyyy-MM-dd")) { if (tempTime != default(DateTime)) { double stopTime = (Convert.ToDateTime(dt.Rows[i]["time"]) - Convert.ToDateTime(tempTime)).TotalSeconds; if (stopTime > Utils.StopSeconds) { stopCount++; tempTime = default(DateTime); } } tempTime = t; Dictionary <string, string> point = new Dictionary <string, string>(); point.Add("lat", dt.Rows[i]["lat"].ToString()); point.Add("lon", dt.Rows[i]["lon"].ToString()); points.Add(point); } } Dictionary <string, string> ss = new Dictionary <string, string>(); ss.Add("alarmcount", retu[key]); ss.Add("stopcount", stopCount + ""); ss.Add("points", Utils.ToJson(points)); rJson[key] = Utils.ToJson(ss); stopCount = 0; } return(Utils.ToJson(rJson)); } catch { return(""); } }