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 @ 202

Revision 202, 5.5 KB checked in by jtorres, 9 years ago (diff)

Further progress on condensed format reader, not all green dots showing

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