Warning: Can't use blame annotator:
svn blame failed on trunk/webapps/einotebook/scripts/LoadEvents.js: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator/trunk/webapps/einotebook/scripts/LoadEvents.js @ 434

Revision 434, 8.5 KB checked in by jdalbey, 7 years ago (diff)

LoadEvents?.js modified to show incident start, and full script edited to move GENERAL INFO to start of tag. Fixes #164

RevLine 
1/* author: jdalbey    date: 4/10/2019 */
2
3// Parse the entire Incident XML Script file
4// Extract the Incidents and Events and create lists of each
5function parseXml(response)
6{
7    // Create a parser and grab the high level tag we're interested in
8    var parser = new DOMParser();
9    var xmlDoc = parser.parseFromString(response,"text/xml");
10    var eventTags = xmlDoc.getElementsByTagName("SCRIPT_EVENT");
11    console.log("parsing incident xml file");
12    // Process each SCRIPT_EVENT tag
13    for (var i = 0; i < eventTags.length; i++)
14    {
15        var currEvt = eventTags[i];
16        // local variable declarations
17        var timeFields; var evtTime; var incidentNum; var incidentTitle; var cadProp; var telProp;
18        var proparray = new Array();
19        var evalarray = new Array();
20        // Process all the children of one event
21        for (var child = 1; child < currEvt.childNodes.length; child++)
22        {
23            // Ignore undefined nodes
24            if (currEvt.childNodes[child].localName != undefined)
25            {
26                var tagName = currEvt.childNodes[child].localName.toUpperCase();
27                // Determine the tag type and dispatch it for further processing
28                switch(tagName)
29                {
30                    case "TIME_INDEX": 
31                        timeFields = currEvt.childNodes[child].textContent.split(":"); 
32                        evtTime = new Time(Number(timeFields[0]), Number(timeFields[1]), Number(timeFields[2]));
33                        break;
34                    case "INCIDENT":
35                        incidentNum = Number(currEvt.childNodes[child].attributes["LogNum"].value);
36                        incidentTitle =  currEvt.childNodes[child].textContent;
37                        break;
38                    case "GENERAL_INFO": 
39                        /* This tag identifies a new incident.  As long as it appears before any
40                        other tags, we can use it to create a new incident. (The alternative is to
41                        have a separate function that parses xml to extract incidents before
42                        we load events.)  Creating an event (below) requires that the incident has already
43                        been created. */
44                        var desc = currEvt.childNodes[child].getElementsByTagName("TEXT")[0].textContent;
45                        var theIncident = new Incident(evtTime, incidentNum, incidentTitle, desc);
46                        incidents.add(theIncident);
47                        // Create an entry showing the Incident start description. Fixes ticket #164
48                        var result = new Array();   
49                        result.push("Description:");
50                        result.push(desc);
51                        proparray.push(new Property("Incident Start",result));
52                        break;
53                    case "CAD_DATA": 
54                        var caddata = parseCAD(currEvt.childNodes[child]); 
55                        if (caddata.length > 0)
56                        {
57                            cadProp = new Property("CHP CAD", caddata ); 
58                            proparray.push(cadProp);
59                        }
60                        break;
61                    case "TELEPHONE": 
62                        telProp = new Evaluation("TELEPHONE CONVERSATION", 
63                                 parseTelephone(currEvt.childNodes[child]) ); 
64                        evalarray.push(telProp);
65                        break;
66                    case "CHP_RADIO": 
67                        var chpradio = parseCHPradio(currEvt.childNodes[child]); 
68                        if (chpradio.length > 0)
69                        {
70                            cadProp = new Property("CHP RADIO", chpradio ); 
71                            proparray.push(cadProp);
72                        }
73                        break;
74
75                    case "TMT_RADIO": 
76                    case "MAINTENANCE_RADIO": 
77                        var result = new Array();   
78                        result.push("Details:");
79                        result.push(currEvt.childNodes[child].textContent.trim());
80                        var radProp = new Property(tagName, result ); 
81                        proparray.push(radProp);
82                        break;
83
84                    case "FACILITATOR_EVALUATION": 
85                    case "CAD_EVALUATION":
86                    case "ATMS_EVALUATION":
87                    case "ACTIVITY_LOG_EVALUATION":
88                    case "RADIO_EVALUATION":
89                        // remove the suffix
90                        var evalType = tagName.replace("_EVALUATION","");
91                        // Build the evaluation item
92                        var evalItem = new Evaluation(evalType, 
93                                 parseEvaluation(currEvt.childNodes[child]) ); 
94                        evalarray.push(evalItem);
95                        break;
96                       
97                    case "CMS_EVALUATION":
98                        var cmsEval = new Evaluation("CMS", parseCMSEvaluation(currEvt.childNodes[child]));
99                        evalarray.push(cmsEval);
100                        break;
101                }
102            }
103        }
104        //console.log(evtTime.format(), incidentNum, proparray.length, evalarray.length);
105        // Ignore Media Log incident and empty nodes
106        if (incidentNum != undefined && incidentNum != 100)
107        {
108          // Create new event with fields obtained from xml file
109          events.add(new Event(evtTime, incidents.get(incidentNum), 
110                new Properties(proparray), 
111                new Evaluations(evalarray)) );
112        }
113    }
114}
115
116function parseCAD(element)
117{
118    var result = new Array();
119    var details = element.getElementsByTagName("DETAIL");
120    if (details.length > 0)
121    {
122        for (detail in details)
123        {
124            if (details[detail].textContent != undefined)
125            {               
126                result.push("Detail:");
127                result.push(details[detail].textContent);
128            }
129        }
130    }
131    return result;
132}
133function parseTelephone(element)
134{
135    var result = new Array();
136    for (var child = 1; child < element.childNodes.length; child++)
137    {
138        if (element.childNodes[child].localName != undefined)
139        {
140            if (element.childNodes[child].localName == "INSTRUCTOR")
141            {
142                result.push(element.childNodes[child].attributes["Role"].value);
143            }
144            else
145            {
146                result.push(element.childNodes[child].localName);   
147            }
148            result.push(element.childNodes[child].textContent);
149        }
150    }
151    return result;
152}
153function parseCHPradio(element)
154{
155    var result = new Array();
156    var dialog = element.getElementsByTagName("LINE");
157    if (dialog.length > 0)
158    {
159        for (line in dialog)
160        {
161            if (dialog[line].textContent != undefined)
162            {               
163                result.push(dialog[line].attributes["Role"].value);
164                result.push(dialog[line].textContent);
165            }
166        }
167    }
168    return result;
169}
170function parseEvaluation(element)
171{
172    var result = new Array();
173    var details = element.getElementsByTagName("EXPECTED_ACTION");
174    if (details.length > 0)
175    {
176        for (detail in details)
177        {
178            if (details[detail].textContent != undefined)
179            {               
180                result.push("Expected Action:");
181                result.push(details[detail].textContent.trim());
182            }
183        }
184    }
185    return result;
186}
187function parseCMSEvaluation(element)
188{
189    var result = new Array();
190    var locations = element.getElementsByTagName("LOCATION");
191    if (locations.length > 0)
192    {
193        result.push("Sign Location:");
194        result.push(locations[0].textContent);
195    }
196    var details = element.getElementsByTagName("CMS_LINE");
197    if (details.length > 0)
198    {
199        for (detail in details)
200        {
201            if (details[detail].textContent != undefined)
202            {               
203                result.push("Sample Message:");
204                result.push(details[detail].textContent.trim());
205            }
206        }
207    }
208    return result;
209}
210// MAIN
211//console.log("starting LoadEvents");
212try {
213    // the script must be located where accessible by the web server
214    var scriptFilename = "../dynamicdata/incident_script.xml";
215    console.log("Attempting to load ", scriptFilename);
216    // Now load the Incident Script and go parse it
217    loadJSON(scriptFilename, parseXml)
218
219    } catch(e) {
220        console.log("Error attempt to parse incident script "+response)
221    }
222
223
Note: See TracBrowser for help on using the repository browser.