Changeset 203 in tmcsimulator for trunk/src/atmsdriver


Ignore:
Timestamp:
10/30/2017 08:23:20 PM (9 years ago)
Author:
jdalbey
Message:

Highways.java, Station.java Updated to prettify the console output.

Location:
trunk/src/atmsdriver/model
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/atmsdriver/model/Highways.java

    r195 r203  
    480480        for (Highway hwy: highways) 
    481481        { 
     482            // Consider each route direction 
    482483            for (DIRECTION dir: DIRECTION.values()) 
    483484            { 
     485                String rowLabel = ""+String.format("%3s ",hwy.routeNumber)+dir.getLetter()+' '; 
    484486                StringBuilder lineout = new StringBuilder(); 
    485                 lineout.append(""+String.format("%3s ",hwy.routeNumber)+dir.getLetter()+' '); 
     487                // Examine every station on this highway and direction 
    486488                for (Station stat: hwy.stations) 
    487489                { 
    488                     if (stat.direction == dir) 
    489                     { 
    490                         //lineout.append("" + dir.getLetter() + stat.postmile); 
    491                         lineout.append(stat.getColorByDirection(stat.direction)); 
    492                         //lineout.append("  "); 
    493                     } 
     490                    //lineout.append("" + dir.getLetter() + stat.postmile); 
     491                    lineout.append(stat.getColorByDirection(dir)); 
     492                    //lineout.append("  "); 
    494493                } 
    495                 if (lineout.length() > 6) 
     494                // See if there were stations for this direction 
     495                String checkMe = lineout.toString().trim(); 
     496                // if any stations were colored, output the line 
     497                if (checkMe.length() > 1) 
    496498                { 
     499                    result.append(rowLabel); 
    497500                    result.append(lineout + "\n"); 
    498501                } 
  • trunk/src/atmsdriver/model/Station.java

    r191 r203  
    88/** 
    99 * A Station (LDS or Loop Detector Station) represents a group of lane detectors 
    10  * across all lanes at a particular point on a highway.  A station is 
    11  * identified by its highway number and postmile.  A station has an associated 
    12  * direction used to establish which direction is Main and which is Opposite. 
    13  * The MLTotVol and OppTotVol for a station can be dynamically updated. 
    14  * A station has other attributes: lineNum, ldsID, drop, and location which are 
    15  * used by the FEP.  A station can be compared to other stations by its postmile. 
     10 * across all lanes at a particular point on a highway. A station is identified 
     11 * by its highway number and postmile. A station has an associated direction 
     12 * used to establish which direction is Main and which is Opposite. The MLTotVol 
     13 * and OppTotVol for a station can be dynamically updated. A station has other 
     14 * attributes: lineNum, ldsID, drop, and location which are used by the FEP. A 
     15 * station can be compared to other stations by its postmile. 
    1616 * 
    1717 * @author John A. Torres 
     
    5252        this.OppTotVol = getOPPTotVol(); 
    5353    } 
    54      
     54 
    5555    /** 
    5656     * Calculates the total ML Volume. 
    57      *  
     57     * 
    5858     * @return total ML volume. 
    5959     */ 
     
    6161    { 
    6262        int mlTotVol = 0; 
    63         for(LoopDetector loop : loops) 
    64         { 
    65             if(loop.loopLocation.startsWith("ML")) 
     63        for (LoopDetector loop : loops) 
     64        { 
     65            if (loop.loopLocation.startsWith("ML")) 
    6666            { 
    6767                mlTotVol += loop.vol; 
     
    7070        return mlTotVol; 
    7171    } 
    72      
     72 
    7373    /** 
    7474     * Calculates the total OPP Volume 
    75      *  
     75     * 
    7676     * @return total OPP volume. 
    7777     */ 
     
    7979    { 
    8080        int oppTotVol = 0; 
    81         for(LoopDetector loop : loops) 
    82         { 
    83             if(loop.loopLocation.startsWith("OS")) 
     81        for (LoopDetector loop : loops) 
     82        { 
     83            if (loop.loopLocation.startsWith("OS")) 
    8484            { 
    8585                oppTotVol += loop.vol; 
     
    8888        return oppTotVol; 
    8989    } 
    90      
    91     /** Returns a string of highways data. If MetaDataOnly is true, you get a full 
    92      *  dump of the highways meta data, which does not include dynamic loop values, 
    93      *  and does include the string location names. If MetaDataOnly is false, 
    94      *  dynamic loop values are included, and unnecessary information like string 
    95      *  location values are included. 
    96      *  
    97      *  The FEPSimulator takes in the toCondensedFormat() output, with a MetaDataOnly 
    98      *  value of false, over the socket. 
    99      *  
    100      *  The MetaDataOnly flag should be used to get a full dump of the highways 
    101      *  information. This was used to get the highways_fullmap.txt output. 
    102      *  
     90 
     91    /** 
     92     * Returns a string of highways data. If MetaDataOnly is true, you get a 
     93     * full dump of the highways meta data, which does not include dynamic loop 
     94     * values, and does include the string location names. If MetaDataOnly is 
     95     * false, dynamic loop values are included, and unnecessary information like 
     96     * string location values are included. 
     97     * 
     98     * The FEPSimulator takes in the toCondensedFormat() output, with a 
     99     * MetaDataOnly value of false, over the socket. 
     100     * 
     101     * The MetaDataOnly flag should be used to get a full dump of the highways 
     102     * information. This was used to get the highways_fullmap.txt output. 
     103     * 
    103104     * @param MetaDataOnly Whether you want meta data, or a full dump for FEPSim 
    104105     * @return String, highways data in condensed format 
     
    119120        build.append(Integer.toString(loops.size())); 
    120121        build.append(" "); 
    121         if(MetaDataOnly) 
     122        if (MetaDataOnly) 
    122123        { 
    123124            build.append(this.location); 
     
    167168    } 
    168169 
    169     /** Determine which lane fields to update based on given direction 
    170      * and update all the loop detectors with the given color. 
     170    /** 
     171     * Determine which lane fields to update based on given direction and update 
     172     * all the loop detectors with the given color. 
     173     * 
    171174     * @param direction desired highway direction 
    172175     * @param dotColor desired dot color 
    173176     */ 
    174     public void updateByDirection(DIRECTION direction, DOTCOLOR dotColor)  
     177    public void updateByDirection(DIRECTION direction, DOTCOLOR dotColor) 
    175178    { 
    176179        String laneDir = "OS"; 
    177         if(direction.equals(this.direction)) 
     180        if (direction.equals(this.direction)) 
    178181        { 
    179182            laneDir = "ML"; 
    180183        } 
    181184        outputUpdateMessage(dotColor, laneDir); 
    182          
    183         for(LoopDetector loop : loops) 
    184         { 
    185             if(loop.loopLocation.startsWith(laneDir)) 
     185 
     186        for (LoopDetector loop : loops) 
     187        { 
     188            if (loop.loopLocation.startsWith(laneDir)) 
    186189            { 
    187190                // UPDATE LOOP WITH VALUES 
     
    189192            } 
    190193        } 
    191          
     194 
    192195        this.MLTotVol = getMLTotVol(); 
    193196        this.OppTotVol = getOPPTotVol(); 
    194197    } 
    195      
     198 
    196199    /** 
    197200     * Return the color for the lanes in a given direction. 
     201     * 
    198202     * @param direction 
    199      * @return character representing color of lanes in given direction 
    200      * '@' = red, '+' = yellow, '-' = green 
     203     * @return character representing color of lanes in given direction '@' = 
     204     * red, '+' = yellow, '-' = green 
    201205     */ 
    202206    public char getColorByDirection(DIRECTION direction) 
     
    205209         * TODO: Average the color in all the lanes for the given direction */ 
    206210 
    207         String laneDir = "OS"; 
    208         if(direction.equals(this.direction)) 
     211        String laneDir = ""; 
     212        if (direction.equals(this.direction)) 
    209213        { 
    210214            laneDir = "ML"; 
    211215        } 
     216        else if (direction.equals(this.direction.getOpposite())) 
     217        { 
     218            laneDir = "OS"; 
     219        } 
    212220        // Examine all the lanes in a given direction 
    213         for(LoopDetector loop : loops) 
    214         { 
    215             if(loop.loopLocation.startsWith(laneDir)) 
     221        for (LoopDetector loop : loops) 
     222        { 
     223            if (loop.loopLocation.substring(0,2).equals(laneDir)) 
    216224            { 
    217225                // Return color according to loop volume 
    218                 if (loop.vol == 1) return '@'; 
    219                 if (loop.vol == 3) return '+'; 
    220             } 
    221         } 
    222         // Default case 
    223         return '-'; 
    224                  
    225     } 
    226      
     226                if (loop.vol == 1) 
     227                { 
     228                    return '@'; 
     229                } 
     230                if (loop.vol == 3) 
     231                { 
     232                    return '+'; 
     233                } 
     234                if (loop.vol == 0) 
     235                { 
     236                    return '-'; 
     237                } 
     238            } 
     239        } 
     240        // Default case for when the route is not on this direction 
     241        return ' '; 
     242 
     243    } 
     244 
    227245    /** 
    228246     * Output for updateByDirection. Logs the update to the console. 
    229      *  
     247     * 
    230248     * @param dotcolor 
    231      * @param OPP_ML  
     249     * @param OPP_ML 
    232250     */ 
    233251    private void outputUpdateMessage(DOTCOLOR dotcolor, String OPP_ML) 
    234252    { 
    235253        System.out.printf("Updating %-3.3s %-5.5s %-3.3s lanes\t %-12.12s " 
    236                 + "at postmile %-6.6s to %-7.7s\n",  
    237                 Integer.toString(this.routeNumber), this.direction.name(),  
    238                 OPP_ML, this.location, Double.toString(this.postmile),  
     254                + "at postmile %-6.6s to %-7.7s\n", 
     255                Integer.toString(this.routeNumber), this.direction.name(), 
     256                OPP_ML, this.location, Double.toString(this.postmile), 
    239257                dotcolor.name()); 
    240258    } 
    241      
     259 
    242260    /** 
    243261     * XML tags used for toXML() method. 
     
    265283        } 
    266284    } 
    267      
     285 
    268286    /** 
    269287     * Returns the Station data in XMLFormat. 
    270      *  
     288     * 
    271289     * @param currElem The current XML <Station> element 
    272290     */ 
     
    347365        { 
    348366            return this.toString().substring(0, 1); 
     367        } 
     368 
     369        public DIRECTION getOpposite() 
     370        { 
     371            switch (this) 
     372            { 
     373                case NORTH: 
     374                    return SOUTH; 
     375                case SOUTH: 
     376                    return NORTH; 
     377                case EAST: 
     378                    return WEST; 
     379                case WEST: 
     380                    return EAST; 
     381            } 
     382            return null; 
    349383        } 
    350384 
Note: See TracChangeset for help on using the changeset viewer.