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

Revision 386, 7.8 KB checked in by jdalbey, 7 years ago (diff)

Updated LoadEvents?.js to parse all event types except CMS_EVALUATION. Modified build.xml to write svn revision number to webapps/common/js so the revision number can be included in the web page title of our apps. Write ShowRevision? function in displayutils.js to do that.

Line 
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                        break;
48                    case "CAD_DATA": 
49                        var caddata = parseCAD(currEvt.childNodes[child]); 
50                        if (caddata.length > 0)
51                        {
52                            cadProp = new Property("CHP CAD", caddata ); 
53                            proparray.push(cadProp);
54                        }
55                        break;
56                    case "TELEPHONE": 
57                        telProp = new Evaluation("TELEPHONE CONVERSATION", 
58                                 parseTelephone(currEvt.childNodes[child]) ); 
59                        evalarray.push(telProp);
60                        break;
61                    case "CHP_RADIO": 
62                        var chpradio = parseCHPradio(currEvt.childNodes[child]); 
63                        if (chpradio.length > 0)
64                        {
65                            cadProp = new Property("CHP RADIO", chpradio ); 
66                            proparray.push(cadProp);
67                        }
68                        break;
69
70                    case "TMT_RADIO": 
71                    case "MAINTENANCE_RADIO": 
72                        var result = new Array();   
73                        result.push("Details:");
74                        result.push(currEvt.childNodes[child].textContent.trim());
75                        var radProp = new Property(tagName, result ); 
76                        proparray.push(radProp);
77                        break;
78
79                    case "FACILITATOR_EVALUATION": 
80                    case "CAD_EVALUATION":
81                    case "ATMS_EVALUATION":
82                    case "ACTIVITY_LOG_EVALUATION":
83                    case "RADIO_EVALUATION":
84                        // remove the suffix
85                        var evalType = tagName.replace("_EVALUATION","");
86                        // Build the evaluation item
87                        var facEval = new Evaluation(evalType, 
88                                 parseEvaluation(currEvt.childNodes[child]) ); 
89                        evalarray.push(facEval);
90                        break;
91                       
92                    case "CMS_EVALUATION":
93                        // TODO: Complete this partial implementation
94                        var result = new Array();   
95                        result.push("Expected Action:");
96                        result.push("Action will appear here.");
97                        var cmsEval = new Evaluation("CMS", result);
98                        evalarray.push(cmsEval);
99                        break;
100                }
101            }
102        }
103        //console.log(evtTime.format(), incidentNum, proparray.length, evalarray.length);
104        // Ignore Media Log incident and empty nodes
105        if (incidentNum != undefined && incidentNum != 100)
106        {
107          // Create new event with fields obtained from xml file
108          events.add(new Event(evtTime, incidents.get(incidentNum), 
109                new Properties(proparray), 
110                new Evaluations(evalarray)) );
111        }
112    }
113}
114
115function parseCAD(element)
116{
117    var result = new Array();
118    var details = element.getElementsByTagName("DETAIL");
119    if (details.length > 0)
120    {
121        for (detail in details)
122        {
123            if (details[detail].textContent != undefined)
124            {               
125                result.push("Detail:");
126                result.push(details[detail].textContent);
127            }
128        }
129    }
130    return result;
131}
132function parseTelephone(element)
133{
134    var result = new Array();
135    for (var child = 1; child < element.childNodes.length; child++)
136    {
137        if (element.childNodes[child].localName != undefined)
138        {
139            if (element.childNodes[child].localName == "INSTRUCTOR")
140            {
141                result.push(element.childNodes[child].attributes["Role"].value);
142            }
143            else
144            {
145                result.push(element.childNodes[child].localName);   
146            }
147            result.push(element.childNodes[child].textContent);
148        }
149    }
150    return result;
151}
152function parseCHPradio(element)
153{
154    var result = new Array();
155    var dialog = element.getElementsByTagName("LINE");
156    if (dialog.length > 0)
157    {
158        for (line in dialog)
159        {
160            if (dialog[line].textContent != undefined)
161            {               
162                result.push(dialog[line].attributes["Role"].value);
163                result.push(dialog[line].textContent);
164            }
165        }
166    }
167    return result;
168}
169function parseEvaluation(element)
170{
171    var result = new Array();
172    var details = element.getElementsByTagName("EXPECTED_ACTION");
173    if (details.length > 0)
174    {
175        for (detail in details)
176        {
177            if (details[detail].textContent != undefined)
178            {               
179                result.push("Expected Action:");
180                result.push(details[detail].textContent.trim());
181            }
182        }
183    }
184    return result;
185}
186
187// MAIN
188console.log("starting LoadEvents");
189try {
190    // the script must be located where accessible by the web server
191    var scriptFilename = "../dynamicdata/incident_script.xml";
192    console.log("Attempting to load", scriptFilename);
193    // Now load the Incident Script and go parse it
194    loadJSON(scriptFilename, parseXml)
195
196    } catch(e) {
197        console.log("Error attempt to parse incident script "+response)
198    }
199
200
Note: See TracBrowser for help on using the repository browser.