Warning: Can't use blame annotator:
svn blame failed on trunk/src/atmsdriver/model/LoopDetector.java: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator/trunk/src/atmsdriver/model/LoopDetector.java @ 186

Revision 186, 6.3 KB checked in by jtorres, 9 years ago (diff)

Highways.java, FEPLine.java, LoopDetector?.java, Station.java: reconfigured the getHighwaysMeta() function to a toCondensedFormat(boolean MetaDataOnly?) method. By specifying MetaDataOnly? as true, you get the same output as the previous getHighwaysMeta() function. By specifying MetaDataOnly? as false, you get the new condensed format needed to send to the FEPSim over the socket. This allows us to use the same function to get a meta data dump, as well as get the highways data format needed for FEPSim socket. HighwaysParser?.cpp: removed the old tinyxml code, set up skeleton for new parser. NetworkReader?.h: deleted, and added HighwaysParser?.h. LoadSadDotsTest?.java and StationTest?.java: configured to use new toCondensedFormat method instead of getHighwaysMeta.

RevLine 
1package atmsdriver.model;
2
3import java.util.ArrayList;
4import java.util.List;
5import org.w3c.dom.Document;
6import org.w3c.dom.Element;
7
8/**
9 *  A LoopDetector represents a single detector for a single lane in a network.
10 *
11 *  A LoopDetector contains static meta data, and three dynamic attributes: vol,
12 *  occ, and spd.
13 *
14 * @author John A. Torres
15 * @version 09/10/2017
16 */
17public class LoopDetector 
18{
19    /* static data */
20    final public int loopID;
21    final public String loopLocation;
22    final public int laneNum;
23   
24    /* dynamic data */
25    public int vol;
26    public float occ;
27    private int spd;
28   
29    /**
30     * Constructs a LoopDetector from loopID, loopLocation, and laneNum
31     *
32     * @param loopID
33     * @param loopLocation
34     * @param laneNum
35     */
36    public LoopDetector(int loopID, String loopLocation, int laneNum)
37    {
38        /* Set static data */
39        this.loopID = loopID;
40        this.loopLocation = loopLocation;
41        this.laneNum = laneNum;
42       
43        /* Init dynamic data */
44        this.vol = 0;
45        this.spd = 0;
46        this.occ = 0;
47    }
48   
49    /**
50     * XML tags used for toXML() method.
51     */
52    private static enum XML_TAGS
53    {
54        LOOP_ID("Loop_ID"),
55        LOOP_LOCATION("Loop_Location"),
56        LANE_NUM("Lane_Num"),
57        VOL("Vol"),
58        SPD("Spd"),
59        OCC("Occ"),
60        LOOP("Loop");
61       
62        String tag;
63       
64        private XML_TAGS(String n)
65        {
66            tag = n;
67        }
68    }
69   
70    /** Returns a string of highways data. If MetaDataOnly is true, you get a full
71     *  dump of the highways meta data, which does not include dynamic loop values,
72     *  and does include the string location names. If MetaDataOnly is false,
73     *  dynamic loop values are included, and unnecessary information like string
74     *  location values are included.
75     *
76     *  The FEPSimulator takes in the toCondensedFormat() output, with a MetaDataOnly
77     *  value of false, over the socket.
78     *
79     *  The MetaDataOnly flag should be used to get a full dump of the highways
80     *  information. This was used to get the highways_fullmap.txt output.
81     *
82     * @param MetaDataOnly Whether you want meta data, or a full dump for FEPSim
83     * @return String, highways data in condensed format
84     */
85    public String toCondensedFormat(boolean MetaDataOnly)
86    {
87        StringBuilder build = new StringBuilder();
88        build.append(Integer.toString(this.loopID));
89        build.append(" ");
90        build.append(Integer.toString(this.laneNum));
91        build.append(" ");
92        if(!MetaDataOnly)
93        {
94            build.append(" ");
95            build.append(this.occ);
96            build.append(" ");
97            build.append(this.vol);
98            build.append(" ");
99            build.append(this.spd);
100        }
101        else
102        {
103            build.append(this.loopLocation);
104        }
105        build.append("\n");
106        return build.toString();
107    }
108   
109    /**
110     * Updates loop detector dynamic attributes.
111     * @param vol volume
112     * @param occ occupancy
113     * @param spd speed
114     */
115    public void updateLoop(int vol, float occ, int spd)
116    {
117        this.vol = vol;
118        this.occ = occ;
119        this.spd = spd;
120    }
121
122    /**
123     * Returns the LoopDetector data in XMLFormat
124     *
125     * @param currElem The current XML <LoopDetector> element
126     */
127    public void toXML(Element currElem)
128    {
129        Document theDoc = currElem.getOwnerDocument();
130       
131        Element loopElement = theDoc.createElement(XML_TAGS.LOOP.tag);
132        currElem.appendChild(loopElement);
133       
134        Element loopIDElement = theDoc.createElement(XML_TAGS.LOOP_ID.tag);
135        loopIDElement.appendChild(theDoc.createTextNode(String.valueOf(this.loopID)));
136        loopElement.appendChild(loopIDElement);
137       
138        Element loopLocElement = theDoc.createElement(XML_TAGS.LOOP_LOCATION.tag);
139        loopLocElement.appendChild(theDoc.createTextNode(this.loopLocation));
140        loopElement.appendChild(loopLocElement);
141       
142        Element laneNumElement = theDoc.createElement(XML_TAGS.LANE_NUM.tag);
143        laneNumElement.appendChild(theDoc.createTextNode(String.valueOf(this.laneNum)));
144        loopElement.appendChild(laneNumElement);
145       
146        Element volElement = theDoc.createElement(XML_TAGS.VOL.tag);
147        volElement.appendChild(theDoc.createTextNode(String.valueOf(this.vol)));
148        loopElement.appendChild(volElement);
149       
150        Element occElement = theDoc.createElement(XML_TAGS.OCC.tag);
151        occElement.appendChild(theDoc.createTextNode(String.valueOf(this.occ)));
152        loopElement.appendChild(occElement);
153       
154        Element spdElement = theDoc.createElement(XML_TAGS.SPD.tag);
155        spdElement.appendChild(theDoc.createTextNode(String.valueOf(this.spd)));
156        loopElement.appendChild(spdElement);
157    }
158   
159    /**
160     * Enum for highway status dot colors. Each color has associated volume
161     * and occupancy constants.
162     *
163     * @author John A. Torres, jdalbey
164     * @version 10/11/2017
165     */
166    public static enum DOTCOLOR {
167
168        RED(1, 0.06f),    // "Stopped" is less than 25mph
169        YELLOW(3,0.059f), // speed = 26
170        GREEN(0,0);
171       
172        // All the first letters of the values, in order.
173        public static String allLetters = "RYG";
174       
175        private int vol;  /* volume */
176        private float occ;  /* occupancy */     
177       
178        private DOTCOLOR(int v, float o)
179        {
180            vol = v;
181            occ = o;
182        }
183        /**
184         * Return the first letter of this enum.
185         *
186         * @return String first letter of this enum.
187         */
188        public String getLetter() {
189            return this.toString().substring(0, 1);
190        }
191
192        public int volume()
193        {
194            return vol;
195        }
196        public float occupancy()
197        {
198            return occ;
199        }
200        /**
201         * Returns a dot color given its first character.
202         *
203         * @param letter the first character of a dot color
204         * @return dot color corresponding to letter
205         * @pre letter must be one of allLetters
206         */
207        public static DOTCOLOR toDotColor(String letter) {
208            return values()[allLetters.indexOf(letter.charAt(0))];
209        }
210    } 
211   
212}
Note: See TracBrowser for help on using the repository browser.