public ActionResult GetTraffic() { Reader reader = new DatDocumentReader(); InputParser <Traffic> trafficInput = new TrafficParser(); List <string> trafficData = reader.GetData(Server.MapPath("~/DataFiles/traffic.dat")); List <Traffic> result = trafficInput.ParseInput(trafficData); return(Json(result, JsonRequestBehavior.AllowGet)); }
static void Main() { var key = KeyParser.GetKeyString(FString.KEY_PATH); Console.WriteLine("Key: " + key); var l = TrafficParser .GetTrafficList( HttpGet.Get( Url.SERVER_ID_TRAFFIC(7269), FString.HTTPGET_HEADER_KEY, key, 10000, FString.USER_AGENT) .ToJObject()); long countIn = 0; long countOut = 0; foreach (var i in l) { Console.WriteLine("=============================="); Console.WriteLine("Date: " + i.Date); Console.WriteLine("In : " + i.In); Console.WriteLine("Out : " + i.Out); Console.WriteLine("EFR : " + 100.0 * i.EFR + "%"); countIn += i.In; countOut += i.Out; } Console.WriteLine("=============================="); Console.WriteLine("Total In : " + countIn); Console.WriteLine("Total Out: " + countOut); Console.WriteLine("Avg. EFR : " + 100.0 * countOut / countIn + "%"); Console.WriteLine("=============================="); Console.WriteLine("Finished! Press any key to exit..."); Console.ReadKey(); }
public static void AggregateTrafficModel(string filePath) { TrafficParser trafficParser = new TrafficParser(filePath); AddToDatabase <TrafficDataModel>(trafficParser.RealTrafficModel, "traffic"); }
public static Routing.RoutingNetwork BuildNetwork(ref Carpools.CarpoolParser CParser, ref Traffic.TrafficParser TParser, List <Carpooler> CarPoolers, List <TrafficReport> TrafficReport, double TrafficPropagationMaxDistance, int CarpoolingMaxConnectionsPerTNode) { Routing.RoutingNetwork routingNetwork = null; string Path = System.IO.Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory + ConfigurationManager.AppSettings["dataPath"] + "\\" + ConfigurationManager.AppSettings["NetworkFileName"]); if (!File.Exists(Path)) { log.Info("Routing network bin file not exist: " + Path + " The road network will be generated from the osm map"); // Construct the road network. string OSMXMLMapFilePath = System.IO.Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory + ConfigurationManager.AppSettings["dataPath"] + ConfigurationManager.AppSettings["OSMXMLMapFile"]); log.Info("Parsing " + OSMXMLMapFilePath + " OSM."); routingNetwork = new Routing.RoutingNetwork(); OSM.XMLParser Parser = new OSM.XMLParser(); Parser.LoadOSMMap(OSMXMLMapFilePath, ref routingNetwork); // Construct the transportation network. log.Info("Parsing GTFS."); GTFS.DBParser GTFSParser = new GTFS.DBParser(); if (CarPoolers != null) { routingNetwork.CarpoolingMaxConnectionsPerTNode = CarpoolingMaxConnectionsPerTNode; } GTFSParser.LoadTransportationNetwork(ref routingNetwork); log.Info("Attaching GTFS."); routingNetwork.ConnectTransportation(); /* Add data to the Stops Carpooling connections */ routingNetwork.CreateNetworkForCarpoolingRides(); //routingNetwork.Serialize(); } else { log.Info("Routing network: " + Path); log.Info("DeSrializing Netwrok."); routingNetwork = Routing.RoutingNetwork.DeSerialize(); } /* Construct Carpooling network */ if (CarPoolers != null) { log.Info("Constructing Carpooling network (" + CarPoolers.Count + " rides)"); CParser = new CarpoolParser(routingNetwork, CarPoolers); //CParser.BuildCarpoolRoutesFromXML(); //CParser.BuildCarpoolRoutesFromJson(); CParser.ConnectWithRoadNetwork(); } /* Update the network considering the traffic reports */ if (TrafficReport != null) { routingNetwork.TrafficPropagationMaxDistance = TrafficPropagationMaxDistance; log.Info("Updating the network considering the traffic reports (" + TrafficReport.Count + " reports)"); TParser = new TrafficParser(routingNetwork, TrafficReport); TParser.UpdateNetworkWithTrafficReport(); } return(routingNetwork); }
void updateTrafficNetwork(TrafficDataVersioned TrafficTmp) { TrafficParser TParserTmp = null; //Just for testing: simulate a new data version //TrafficTmp.Version.version++; if ((Program.Traffic.Version != null) && (TrafficTmp.Version != null) && (TrafficTmp.Version.version != Program.Traffic.Version.version)) { log.Info("New Traffic data are available (prevVersion:" + Program.Traffic.Version.version + ", newVersion:" + TrafficTmp.Version.version + ")"); /* Get the traffic reports from the backend web service */ TrafficTmp.TrafficReport = HTTPRequests.getTrafficDataFromBackend(productionRoutingNetwork.MinPoint, productionRoutingNetwork.MaxPoint, productionRoutingNetwork.TrafficPropagationMaxDistance); /* Get differences between the old version and the new one */ TrafficDiff TrafficDiff = TrafficParser.checkDifferences(Program.Traffic.TrafficReport, TrafficTmp.TrafficReport); if ((TrafficDiff.ElementsToRemove.Count > 0) || (TrafficDiff.ElementsToAdd.Count > 0)) { /* Update the network only when there are no pending threads (Monitor.Wait) */ lock (_ActiveWorkersLock) { while (_CountOfActiveWorkers > 0) { Monitor.Wait(_ActiveWorkersLock); } log.Info("Updating the production network with the traffic reports"); /* Remove the OLD Traffic reports from the network */ if (TrafficDiff.ElementsToRemove.Count > 0) { log.Info("Removing " + TrafficDiff.ElementsToRemove.Count + " deleted traffic reports from the processNetwork"); int i = 1; foreach (TrafficReport el in TrafficDiff.ElementsToRemove) { productionRoutingNetwork.RemoveTrafficReport(el); /* Update the original TrafficParser */ Program.TParser.TrafficReport.Remove(el); i++; } log.Info("ProcessNetwork updated! (" + TrafficDiff.ElementsToRemove.Count + " old traffic reports deleted)"); /* Force the network update before processing the next request */ updateRN = true; } /* Add the NEW Traffic reports to the network */ if (TrafficDiff.ElementsToAdd.Count > 0) { /* Add to each connection the traffic report */ log.Info("Adding the new " + TrafficDiff.ElementsToAdd.Count + " traffic connections to the processNetwork"); TParserTmp = new TrafficParser(productionRoutingNetwork, TrafficDiff.ElementsToAdd); TParserTmp.UpdateNetworkWithTrafficReport(); /* Update the original TParser and Traffic report classes */ foreach (TrafficReport el in TrafficDiff.ElementsToAdd) { Program.TParser.TrafficReport.Add(el); } log.Info("Processnetwork updated! (" + TrafficDiff.ElementsToAdd.Count + " new traffic reports added)"); /* Force the network update before processing the next request */ updateRN = true; } log.Info("Production network updated with the traffic reports"); } } /* If there are no modifications too, just update the version number (this happens for example if the driver quickly * enable and disable a ride, so the version number changes but the content doesn't) */ /* Update the traffic report version */ Program.Traffic.Version = new TrafficVersion(TrafficTmp.Version.version, TrafficTmp.Version.timestampVersion, TrafficTmp.Version.nameSite); } else { if (TrafficTmp.Version != null) { //log.Info("Traffic version not changed: version=" + TrafficTmp.Version.version + " timestamp=" + TrafficTmp.Version.timestampVersion); } } }