source: tmcsimulator/trunk/webapps/einotebook/script/scrollframe.js @ 551

Revision 551, 2.4 KB checked in by jdalbey, 6 years ago (diff)

Multi-file commit to implement saving evaluation ratings from einotebook to a log file and merging with unified log. Also fix defect #212. cgi-bin/saveEvals.py cgi-bin/saveRatingsToLog.py common/js/displayutils.js common/js/fileutils.js common/js/revision_number.dat common/unifiedlog.css dynamicdata/CADcomments.log dynamicdata/caddetails.csv dynamicdata cms_messages.json dynamicdata/har_messages.json dynamicdata highway_status.json dynamicdata/ratings.csv dynamicdata/unifiedlog.csv dynamicdata/unifiedlog_final.csv einotebook/roles/index.html einotebook roles/roles.js einotebook/script/index.html einotebook/script scrollframe.js einotebook/scripts/Evaluation.js einotebook/scripts/Event.js mergelogs.bash unifiedlogdisplay.html unifiedlogmonitor.html

  • Property svn:executable set to *
Line 
1/************* WARNING: THIS IS A GLOBAL VARIABLE. ********************/
2// Reference to the 'events' array in Events.js
3var events;
4
5/**
6 * Sets the events.
7 * @param theEvents Reference to the 'events' array in Events.js.
8 */
9function setEvents(theEvents)
10{
11        events = theEvents;
12}
13
14// Collect all the ratings from the events
15function collectRatings() 
16{
17    var output = ""
18    var ratingCount = 0
19    // Consider each event in the incident script
20    for (var evtidx = 0; evtidx < events.length; evtidx++)
21    {
22        // Does this event have any evaluations?
23        if (events[evtidx].evaluations.evaluations.length > 0)
24        {
25            // Examine each evaluation contained in this event
26            for (var rating=0; rating<events[evtidx].evaluations.evaluations.length; rating++ )
27            {
28                // Extract the rating assigned to this item
29                var item = events[evtidx].evaluations.evaluations[rating];
30                // If it not the default value we want to save it
31                if (item.rating > 0)
32                {   // Build a string for the log in this format:
33                    //03:01:00, Evaluation, CMS, Poor
34                    output += events[evtidx].time.format() +", Evaluation, "+item.type + ", " + item.ratingQualities[item.rating] + "\n"
35                    ratingCount += 1; 
36                }
37            }
38        }
39    }
40    submitRatings(output);
41    alert(ratingCount + " rating were saved.")
42}
43
44/* This is an alternative way to collect the ratings values by reading them directly from the radio buttons
45function collectRadios()
46{
47    var radios = document.getElementsByTagName('input');
48    var count = 0;
49    for (var j=0; j<radios.length; j++)
50    {
51        if (radios[j].type == 'radio')
52        {
53            count++;
54            if (radios[j].checked)
55            {
56                console.log(radios[j].name + " checked " + radios[j].value)                       
57            }
58        }
59    }
60    alert("counted " + count + " radios");
61}
62*/
63
64// Send the string of ratings to the server
65function submitRatings(logString)
66{
67        // Using POST to send the data
68        var xhr = new XMLHttpRequest();
69        xhr.open("POST", "/cgi-bin/saveRatingsToLog.py", true);
70        xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
71        // send the collected data
72        xhr.send("msg="+logString);
73}
Note: See TracBrowser for help on using the repository browser.