- Timestamp:
- 10/30/2017 08:23:20 PM (9 years ago)
- Location:
- trunk/src/atmsdriver/model
- Files:
-
- 2 edited
-
Highways.java (modified) (1 diff)
-
Station.java (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/atmsdriver/model/Highways.java
r195 r203 480 480 for (Highway hwy: highways) 481 481 { 482 // Consider each route direction 482 483 for (DIRECTION dir: DIRECTION.values()) 483 484 { 485 String rowLabel = ""+String.format("%3s ",hwy.routeNumber)+dir.getLetter()+' '; 484 486 StringBuilder lineout = new StringBuilder(); 485 lineout.append(""+String.format("%3s ",hwy.routeNumber)+dir.getLetter()+' ');487 // Examine every station on this highway and direction 486 488 for (Station stat: hwy.stations) 487 489 { 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(" "); 494 493 } 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) 496 498 { 499 result.append(rowLabel); 497 500 result.append(lineout + "\n"); 498 501 } -
trunk/src/atmsdriver/model/Station.java
r191 r203 8 8 /** 9 9 * 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 is11 * identified by its highway number and postmile. A station has an associated12 * 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 are15 * used by the FEP. Astation 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. 16 16 * 17 17 * @author John A. Torres … … 52 52 this.OppTotVol = getOPPTotVol(); 53 53 } 54 54 55 55 /** 56 56 * Calculates the total ML Volume. 57 * 57 * 58 58 * @return total ML volume. 59 59 */ … … 61 61 { 62 62 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")) 66 66 { 67 67 mlTotVol += loop.vol; … … 70 70 return mlTotVol; 71 71 } 72 72 73 73 /** 74 74 * Calculates the total OPP Volume 75 * 75 * 76 76 * @return total OPP volume. 77 77 */ … … 79 79 { 80 80 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")) 84 84 { 85 85 oppTotVol += loop.vol; … … 88 88 return oppTotVol; 89 89 } 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 * 103 104 * @param MetaDataOnly Whether you want meta data, or a full dump for FEPSim 104 105 * @return String, highways data in condensed format … … 119 120 build.append(Integer.toString(loops.size())); 120 121 build.append(" "); 121 if (MetaDataOnly)122 if (MetaDataOnly) 122 123 { 123 124 build.append(this.location); … … 167 168 } 168 169 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 * 171 174 * @param direction desired highway direction 172 175 * @param dotColor desired dot color 173 176 */ 174 public void updateByDirection(DIRECTION direction, DOTCOLOR dotColor) 177 public void updateByDirection(DIRECTION direction, DOTCOLOR dotColor) 175 178 { 176 179 String laneDir = "OS"; 177 if (direction.equals(this.direction))180 if (direction.equals(this.direction)) 178 181 { 179 182 laneDir = "ML"; 180 183 } 181 184 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)) 186 189 { 187 190 // UPDATE LOOP WITH VALUES … … 189 192 } 190 193 } 191 194 192 195 this.MLTotVol = getMLTotVol(); 193 196 this.OppTotVol = getOPPTotVol(); 194 197 } 195 198 196 199 /** 197 200 * Return the color for the lanes in a given direction. 201 * 198 202 * @param direction 199 * @return character representing color of lanes in given direction 200 * '@' = red,'+' = yellow, '-' = green203 * @return character representing color of lanes in given direction '@' = 204 * red, '+' = yellow, '-' = green 201 205 */ 202 206 public char getColorByDirection(DIRECTION direction) … … 205 209 * TODO: Average the color in all the lanes for the given direction */ 206 210 207 String laneDir = " OS";208 if (direction.equals(this.direction))211 String laneDir = ""; 212 if (direction.equals(this.direction)) 209 213 { 210 214 laneDir = "ML"; 211 215 } 216 else if (direction.equals(this.direction.getOpposite())) 217 { 218 laneDir = "OS"; 219 } 212 220 // 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)) 216 224 { 217 225 // 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 227 245 /** 228 246 * Output for updateByDirection. Logs the update to the console. 229 * 247 * 230 248 * @param dotcolor 231 * @param OPP_ML 249 * @param OPP_ML 232 250 */ 233 251 private void outputUpdateMessage(DOTCOLOR dotcolor, String OPP_ML) 234 252 { 235 253 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), 239 257 dotcolor.name()); 240 258 } 241 259 242 260 /** 243 261 * XML tags used for toXML() method. … … 265 283 } 266 284 } 267 285 268 286 /** 269 287 * Returns the Station data in XMLFormat. 270 * 288 * 271 289 * @param currElem The current XML <Station> element 272 290 */ … … 347 365 { 348 366 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; 349 383 } 350 384
Note: See TracChangeset
for help on using the changeset viewer.
