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

Revision 242, 5.7 KB checked in by jtorres, 8 years ago (diff)

LoopDetector?.java: added loopLocationID to toCondensedFormat method.

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