source: tmcsimulator/trunk/src/atmsdriver/model/TrafficEvent.java @ 184

Revision 184, 2.2 KB checked in by jtorres, 9 years ago (diff)

highways.java: converted to immutable, removed use of FEPLineLoader and added loadLines(), loadLine(), loadStation(), and loadLoop() methods. Renamed loadHighways() to configureHighways(), renamed writeHighwaysMeta() to getHighwaysMeta() which now returns a String containing metadata instead of opening a file and writing to it, which is more flexible. FEPLineLoader.java: deleted, no longer need it. FEPLine.java: converted to immutable, removed unnecessary member variables and adjusted all methods accordingly. Station.java: MLTotVol() and OppTotVol?() are now being updated at end of updateByDirection(). ATMSDriver.java: Now using one config file: highways_fullmap.txt, as opposed to the older lds.txt and loop.txt files. config/vds_data: added highways_fullmap.txt. config/atms_driver_config.properties, atms_driver_config_local.properties: updated config to reflect use of highways_fullmap.txt instead of old loop.txt and lds.txt configuration. ATMSBatchDriver.java: conformed highways initialization in constructor to reflect use of highways_fullmap.txt

Line 
1
2package atmsdriver.model;
3
4import java.text.ParseException;
5import java.text.SimpleDateFormat;
6import java.util.Date;
7import java.util.Scanner;
8import java.util.logging.Level;
9import java.util.logging.Logger;
10import tmcsim.client.ATMSBatchDriver;
11
12/**
13 * Traffic Event represents some occurrence in the traffic on
14 * a highway network.  A traffic event occurs at a particular time
15 * and belongs to a unique simulation incident.  The event occurs on
16 * a specified section of a given highway route.  Each event specifies
17 * the level of traffic congestion by a color.  Events are comparable
18 * by the time of their occurrence.
19 * @author jdalbey
20 */
21public final class TrafficEvent implements Comparable<TrafficEvent>
22{
23    public final String incident;
24    public final String eventTime;
25    public final Date eventDate;  // for convenience
26    public final int routeNumber;
27    public final LoopDetector.DOTCOLOR color;
28    public final Station.DIRECTION dir;
29    public final double postmile;
30    public final double range;
31    public final String rawString;
32    private final static SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
33
34    /** Create an event from a string as in this example:
35     * 181 00:12:30 405 S 0.6 11.0 G
36     * @param eventString
37     * @return traffic event
38     * @throws Scanner exception if string improperly formatted
39     */
40    public TrafficEvent(String eventString) throws ParseException
41    {
42        this.rawString = eventString;
43        Scanner lineScan = new Scanner(eventString);
44        this.incident = lineScan.next();
45        this.eventTime = lineScan.next(); // time field
46        // may throw parseexception
47        this.eventDate = formatter.parse(eventTime);
48        this.routeNumber = lineScan.nextInt();
49        this.dir = Station.DIRECTION.toDirection(lineScan.next());
50        this.postmile = lineScan.nextDouble();
51        this.range = lineScan.nextDouble();
52        this.color = LoopDetector.DOTCOLOR.toDotColor(lineScan.next());   
53    }
54
55    @Override
56    public int compareTo(TrafficEvent o)
57    {
58        return eventDate.compareTo(o.eventDate);
59    }
60   
61    @Override
62    public String toString()
63    {
64        return rawString;
65    }
66}
Note: See TracBrowser for help on using the repository browser.