示例#1
0
        static int doTestCall(RTTripUpdates tripUpdate, DateTime phDate)
        {
            TimeSpan startTime  = TimeSpan.Parse(tripUpdate.start_time).Add(TimeSpan.FromSeconds(tripUpdate.delay));
            TimeSpan elapseTime = new TimeSpan(phDate.Hour, phDate.Minute, phDate.Second) - startTime;



            List <SimulVehiclePositions> svp = db.Database
                                               .SqlQuery <SimulVehiclePositions>("SimulVehiclePositionGet @route_id, @direction_id, @elapse_time",
                                                                                 new SqlParameter("@route_id", tripUpdate.route_id),
                                                                                 new SqlParameter("@direction_id", tripUpdate.direction_id),
                                                                                 new SqlParameter("@elapse_time", elapseTime))
                                               .ToList();

            if (svp.Count > 0)
            {
                RTVehiclePositions vp = new RTVehiclePositions();
                vp.route_id     = tripUpdate.route_id;
                vp.trip_id      = tripUpdate.trip_id;
                vp.direction_id = tripUpdate.direction_id;
                vp.start_date   = tripUpdate.start_date;
                vp.start_time   = tripUpdate.start_time;
                vp.latitude     = svp[0].pos_lat;
                vp.longitude    = svp[0].pos_lon;
                vp.timestamp    = (long)Functions.ToEpoch(DateTime.UtcNow);

                db.RTVehiclePositions.Add(vp);
                return(1);
            }

            return(0);
        }
示例#2
0
        public ActionResult DeleteConfirmed(int id)
        {
            RTTripUpdates rTTripUpdates = db.RTTripUpdates.Find(id);

            db.RTTripUpdates.Remove(rTTripUpdates);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#3
0
 public ActionResult Edit([Bind(Include = "id,trip_id,route_id,direction_id,delay,start_date,start_time,mobile_number")] RTTripUpdates rTTripUpdates)
 {
     if (ModelState.IsValid)
     {
         db.Entry(rTTripUpdates).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(rTTripUpdates));
 }
示例#4
0
        public ActionResult Create([Bind(Include = "id,trip_id,route_id,direction_id,delay,start_date,start_time,mobile_number")] RTTripUpdates rTTripUpdates)
        {
            if (ModelState.IsValid)
            {
                db.RTTripUpdates.Add(rTTripUpdates);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(rTTripUpdates));
        }
示例#5
0
        // GET: RTTripUpdate/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RTTripUpdates rTTripUpdates = db.RTTripUpdates.Find(id);

            if (rTTripUpdates == null)
            {
                return(HttpNotFound());
            }
            return(View(rTTripUpdates));
        }
        private string processTrip(string mobileNumber, string[] msgParts)
        {
            // START MRT3 NB 0915

            DateTime phDateTime    = DateTime.UtcNow.AddHours(8);
            DateTime startDateTime = new DateTime(phDateTime.Year, phDateTime.Month, phDateTime.Day, Convert.ToInt32(msgParts[3].Substring(0, 2)), Convert.ToInt32(msgParts[3].Substring(2, 2)), 0);

            string route_id     = "ROU" + msgParts[1];
            string trip_id      = "";
            int    direction_id = (msgParts[2] == "SB" || msgParts[2] == "EB") ? 0 : 1;
            int    delay        = Functions.ComputeDelay(startDateTime, phDateTime);
            string start_date   = startDateTime.ToString("yyyyMMdd");
            string start_time   = startDateTime.ToString("HH:mm:ss");

            if (msgParts.Length > 4)
            {
                DateTime delayStart = new DateTime(phDateTime.Year, phDateTime.Month, phDateTime.Day,
                                                   Convert.ToInt32(msgParts[4].Substring(0, 2)), Convert.ToInt32(msgParts[4].Substring(2, 2)), Convert.ToInt32(msgParts[4].Substring(4, 2)));
                delay = Functions.ComputeDelay(startDateTime, delayStart);
            }

            List <Trips> trips = db.Database
                                 .SqlQuery <Trips>("TripGetByRouteDirectionDay @route_id, @direction_id, @day_param",
                                                   new SqlParameter("@route_id", route_id),
                                                   new SqlParameter("@direction_id", direction_id),
                                                   new SqlParameter("@day_param", Functions.GetDayParam(startDateTime)))
                                 .ToList();

            if (trips.Count == 0)
            {
                throw new Exception("Trip ID not found");
            }

            trip_id = trips[0].trip_id;

            RTTripUpdates rtTrip = new RTTripUpdates();

            rtTrip.route_id      = route_id;
            rtTrip.trip_id       = trip_id;
            rtTrip.direction_id  = direction_id;
            rtTrip.delay         = delay;
            rtTrip.start_date    = start_date;
            rtTrip.start_time    = start_time;
            rtTrip.mobile_number = mobileNumber;

            db.RTTripUpdates.Add(rtTrip);

            return("success");
        }
示例#7
0
        static int doGlobeCall(string mobileNumber, string accessToken, RTTripUpdates tripUpdate)
        {
            // call globe api
            JToken jsonReturn = GlobeLabs.LocateDevice(mobileNumber, accessToken);

            string processResult = "";

            if (((JProperty)jsonReturn.First).Name == "error")
            {
                processResult = ((JProperty)jsonReturn.First).Value.ToString();
                return(0);
            }
            else if (((JProperty)jsonReturn.First).Name == "terminalLocationList")
            {
                globe_lbs lbs       = JsonConvert.DeserializeObject <globe_lbs>(jsonReturn.ToString());
                double    latitude  = Convert.ToDouble(lbs.terminalLocationList.terminalLocation.currentLocation.latitude);
                double    longitude = Convert.ToDouble(lbs.terminalLocationList.terminalLocation.currentLocation.longitude);

                ShapeHolder sh = DetermineClosestPoint(tripUpdate.trip_id, latitude, longitude);
                //ShapeHolder sh = DetermineClosestPoint(tripUpdate.trip_id, 14.58793, 121.05693);

                if (sh.shape_pt_lat > 0)
                {
                    // save data to rt vehicle position
                    RTVehiclePositions vp = new RTVehiclePositions();

                    vp.route_id     = tripUpdate.route_id;
                    vp.trip_id      = tripUpdate.trip_id;
                    vp.direction_id = tripUpdate.direction_id;
                    vp.start_date   = tripUpdate.start_date;
                    vp.start_time   = tripUpdate.start_time;
                    vp.latitude     = sh.shape_pt_lat;
                    vp.longitude    = sh.shape_pt_lon;
                    vp.timestamp    = (long)Functions.ToEpoch(DateTime.UtcNow);

                    db.RTVehiclePositions.Add(vp);
                    return(1);
                }
            }

            return(0);
        }