Changeset 248 in tmcsimulator for trunk/src


Ignore:
Timestamp:
02/09/2019 08:18:35 AM (7 years ago)
Author:
jdalbey
Message:

TrafficModelManager?: multi-file commit to enhance Traffic Mgr to output highway status to json file for viewing in Google Map.

Location:
trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/atmsdriver/ATMSDriver.java

    r190 r248  
    88import tmcsim.common.SimulationException; 
    99 
    10 /** 
     10/** "Super Old" 
    1111 * ATMS Driver reads the current simulation traffic conditions from the 
    1212 * EXCHANGE.XML file and constructs the Highway Network status info in the 
  • trunk/src/atmsdriver/GoogleMapAnimator.java

    r245 r248  
    3333     * Error logger. 
    3434     */ 
    35     private final static Logger logger = Logger.getLogger("trafficmodeleventdriver"); 
     35    private final static Logger logger = Logger.getLogger("mapanimator"); 
    3636 
    3737    /** 
     
    195195    public static void main(String[] args) throws RemoteException, SimulationException 
    196196    { 
    197         JFrame frame = new JFrame("Traffic Events Animator"); 
     197        JFrame frame = new JFrame("Google Map Animator"); 
    198198        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    199199        frame.setSize(1050,450); 
  • trunk/src/atmsdriver/model/Highways.java

    r243 r248  
    545545        for (Highway hwy: highways) 
    546546        { 
    547             // Consider each route direction 
    548             //for (DIRECTION dir: DIRECTION.values()) 
    549             // TODO: Needs fixing so proper direction is displayed 
    550             Station.DIRECTION dir = Station.DIRECTION.SOUTH; 
    551             if (hwy.routeNumber == 55) 
    552                 dir = Station.DIRECTION.SOUTH; 
    553             if (hwy.routeNumber == 405) 
    554                 dir = Station.DIRECTION.NORTH; 
    555             { 
    556                 String rowLabel = ""+String.format("%3s ",hwy.routeNumber)+dir.getLetter()+' '; 
     547            // For json output we don't care about listing all the stations 
     548            // in order by direction because we are just outputting points not lines. 
     549            { 
     550                // Examine every station on this highway and direction 
    557551                StringBuilder lineout = new StringBuilder(); 
    558                 // Examine every station on this highway and direction 
    559552                for (Station stat: hwy.stations) 
    560553                { 
    561                     String pmID = "" + hwy.routeNumber + " " + stat.postmile; 
     554                    String pmID = "" + hwy.routeNumber + " "  
     555                            + stat.direction.getLetter() + " "  
     556                            + stat.postmile; 
    562557                    PostmileCoords.Postmile currentPM = pmList.find(pmID); 
    563558                    if (currentPM != null) 
     
    566561                    //lineout.append(stat.getColorByDirection(dir)); 
    567562                    String outString = currentPM.toJson(); 
     563                    // replace the color code with the color name 
    568564                    String colorName=""; 
    569                     switch (stat.getColorByDirection(dir)) 
     565                    switch (stat.getColorByDirection(stat.direction)) 
    570566                    { 
    571567                        case '@': colorName = "red";break; 
     
    579575                    } 
    580576                } 
    581                                 // See if there were stations for this direction 
    582                 String checkMe = lineout.toString().trim(); 
    583                 // if any stations were colored, output the line 
    584                 if (checkMe.length() > 1) 
    585                 { 
    586                     //result.append(rowLabel); 
    587                     result.append(lineout + "\n"); 
    588                 } 
     577                //result.append(rowLabel); 
     578                result.append(lineout + "\n"); 
    589579 
    590580            } 
  • trunk/src/atmsdriver/model/PostmileCoords.java

    r244 r248  
    5454        { 
    5555            String[] fields = item.split(","); 
    56             Postmile pm = new Postmile(fields[0],fields[1],fields[2]); 
     56            String[] nameparts = fields[0].split(" "); 
     57            String statepm = nameparts[2]; 
     58            // some postmiles come with a prefix, which we ignore 
     59            if (Character.isLetter(statepm.charAt(0))) 
     60            { 
     61                statepm = statepm.substring(1); 
     62            }   
     63            String revisedpm = nameparts[0] + " " + nameparts[1] + " " + statepm; 
     64            Postmile pm = new Postmile(revisedpm,fields[1],fields[2]); 
    5765            postmileList.add(pm); 
    5866        } 
     
    6977    final static class Postmile   
    7078    { 
    71         String name;  // the postmile name or id 
     79        String name;  // the postmile name (Route,Direction,State postmile) 
    7280        String latitude; // the latitude coordinate for this postmile 
    7381        String longitude; // the longitude coordinate for this postmile 
  • trunk/src/tmcsim/application.properties

    r246 r248  
    1 #Thu, 07 Feb 2019 15:47:33 -0800 
     1#Sat, 09 Feb 2019 09:41:52 -0800 
    22 
    3 Application.revision=242 
     3Application.revision=247 
    44 
    55Application.buildnumber=91 
  • trunk/src/tmcsim/cadsimulator/managers/TrafficModelManager.java

    r228 r248  
    11package tmcsim.cadsimulator.managers; 
    22 
     3import atmsdriver.GoogleMapAnimator; 
    34import atmsdriver.model.Highways; 
    45import atmsdriver.model.LoopDetector; 
     
    89import java.io.FileInputStream; 
    910import java.io.FileNotFoundException; 
     11import java.io.PrintWriter; 
    1012import java.rmi.RemoteException; 
    1113import java.text.ParseException; 
     
    208210            wtConsole.start(); 
    209211        } 
     212        // Always write to json for google map display 
     213        Thread wtJson = new WriteToJsonThread(); 
     214        wtJson.start(); 
    210215    } 
    211216    /** Accessor to event queue 
     
    403408            while (true) 
    404409            { 
    405                  // Write the highway network status to the FEP Simulator 
     410                 // Write the highway network status to the Console 
    406411                 System.out.println(highways.toString()); 
    407  
    408                 // Wait for FEP Sim to process the data we just sent 
     412                // Output the highway model  
     413                String geojson = highways.toJson(); 
     414                //System.out.println(geojson); // diagnostic 
     415                PrintWriter out; 
     416                try 
     417                { 
     418                    out = new PrintWriter("highways.json"); 
     419                    out.print(geojson); 
     420                    out.close(); 
     421                } 
     422                catch (FileNotFoundException ex) 
     423                { 
     424                    Logger.getLogger(GoogleMapAnimator.class.getName()).log(Level.SEVERE, null, ex); 
     425                } 
     426                // Wait for Google Map to process the data we just sent 
    409427                try 
    410428                { 
    411429                    Thread.sleep(5000); 
     430                } 
     431                catch (InterruptedException ie) 
     432                { 
     433                    ie.printStackTrace(); 
     434                } 
     435            } 
     436 
     437        } 
     438    } 
     439    /** Writes the highway model to a GeoJson file for reading 
     440     *  by Google Maps. 
     441     */ 
     442    class WriteToJsonThread extends Thread 
     443    { 
     444 
     445        public void run() 
     446        { 
     447            System.out.println("WriteToJson Thread starting."); 
     448            // Run indefinitely 
     449            while (true) 
     450            { 
     451                 // Write the highway network status to Json 
     452                String geojson = highways.toJson(); 
     453                PrintWriter out; 
     454                try 
     455                { 
     456                    // currently writes to local file 
     457                    out = new PrintWriter("highways.json"); 
     458                    out.print(geojson); 
     459                    out.close(); 
     460                } 
     461                catch (FileNotFoundException ex) 
     462                { 
     463                    Logger.getLogger(GoogleMapAnimator.class.getName()).log(Level.SEVERE, null, ex); 
     464                } 
     465                // Wait for Google Map to process the data we just sent 
     466                try 
     467                { 
     468                    Thread.sleep(30000); 
    412469                } 
    413470                catch (InterruptedException ie) 
Note: See TracChangeset for help on using the changeset viewer.