public static BusCheckin Create(string data) { if (!String.IsNullOrEmpty (data)) { BusCheckin checkin = new BusCheckin (); string[] parts = data.Split (','); DateTime checkinTime; int busId; if (DateTime.TryParse (parts [1] + "/" + DateTime.Today.Year.ToString () + " " + parts [0], out checkinTime) && Int32.TryParse (parts [2], out busId)) { checkin.CheckinTime = new BusDateTime { Year = checkinTime.Year, Mon = checkinTime.Month, Day = checkinTime.Day, Hour = checkinTime.Hour, Min = checkinTime.Minute, Sec = checkinTime.Second }; checkin.RawData = data; checkin.RouteLookedUp = false; checkin.BusId = busId; string[] loc = parts [3].Split ('/'); string lat = loc [0]; string lon = loc [1]; checkin.Location = new Location { Lat = lat.Substring (0, lat.Length - 7) + "." + lat.Substring (lat.Length - 7), Lon = lon.Substring (0, lon.Length - 7) + "." + lon.Substring (lon.Length - 7) }; checkin.LocationValid = parts [4] == "V"; checkin.Adherence = Int32.Parse (parts [5]); checkin.AdherenceValid = parts [6] == "V"; int route; if (parts.Length > 7 && Int32.TryParse (parts [7], out route)) { checkin.HasRoute = true; checkin.Route = route; checkin.Direction = Int32.Parse (parts [8]); int stopId; checkin.StopId = Int32.TryParse (parts [9], out stopId) ? stopId : -1; } else { checkin.HasRoute = false; checkin.Route = -1; checkin.Direction = -1; checkin.StopId = -1; } return checkin; } } return null; }
public bool BusCheckinExists(BusCheckin checkin) { var key = String.Format("[{0},{1},{2},{3},{4},{5},{6}]", checkin.BusId, checkin.CheckinTime.Year, checkin.CheckinTime.Mon, checkin.CheckinTime.Day, checkin.CheckinTime.Hour, checkin.CheckinTime.Min, checkin.CheckinTime.Sec); var response = Request(_dbUrl + HRT_DB_NAME + "/_design/checkins/_view/by_busid_date?key=" + key, "GET", null); var summary = (Dictionary<string, object>)_serializer.DeserializeObject(response); if(((object[])summary["rows"]).Length == 0) return false; else return true; }
public BusCheckinDoc(BusCheckin c) { CheckinTime = c.CheckinTime; BusId = c.BusId; Location = c.Location; LocationValid = c.LocationValid; Adherence = c.Adherence; AdherenceValid = c.AdherenceValid; HasRoute = c.HasRoute; RouteLookedUp = c.RouteLookedUp; Route = c.Route; Direction = c.Direction; StopId = c.StopId; RawData = c.RawData; _id = Guid.NewGuid().ToString(); }