Changeset 18713 for trunk/FACT++/scripts


Ignore:
Timestamp:
01/06/17 11:56:10 (8 years ago)
Author:
tbretz
Message:
The conversion key to name is now done directly with the query by joining the tables (the results are not that big anyways), added a sanity check for the new suspend/resume feature
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/scripts/getSchedule.js

    r18173 r18713  
    33function getSchedule()
    44{
    5     // List of all available measurement types (see also Observation_class.js)
    6     var measurementType = [ "STARTUP", "IDLE", "DRSCALIB", "SINGLEPE", "DATA", "RATESCAN", "SHUTDOWN", "OVTEST", "RATESCAN2", "SLEEP", "CUSTOM" ];
    7 
    85    // Get current time
    96    var start = new Date();//new Date("2013-04-07 19:00:00 UTC");
     
    1916    var db = new Database($['schedule-database']);
    2017
    21     // get all sources from database
    22     var sources = db.query("SELECT * from Source");
    23 
    2418    // Get the current schedule
    25     var rows = db.query("SELECT * FROM Schedule WHERE fStart>'"+start.toISOString()+"' ORDER BY fStart, fMeasurementID");
     19    var rows = db.query("SELECT * FROM Schedule "+
     20                        "LEFT JOIN MeasurementType USING (fMeasurementTypeKey) "+
     21                        "LEFT JOIN Source USING (fSourceKey) "+
     22                        "WHERE fStart>'"+start.toISOString()+"' "+
     23                        "ORDER BY fStart, fMeasurementID");
    2624
    2725    // Close db connection
     
    3634    for (var i=0; i<rows.length; i++)
    3735    {
     36        var id  = rows[i]['fScheduleID'];
    3837        var sub = rows[i]['fMeasurementID'];
    3938        if (sub==0)
     
    4241        var m = { }
    4342
    44         var task = rows[i]['fMeasurementTypeKey'];
    45         m.task = measurementType[task];
     43        m.task = rows[i]['fMeasurementTypeName'];
     44        if (!m.task)
     45            throw new Error("No valid measurement type for id=("+id+":"+sub+")");
    4646
    47         var src = rows[i]['fSourceKey'];
    48         if (src)
    49         {
    50             // Convert SourceKey to SourceName
    51             var arr = sources.filter(function(e) { return e['fSourceKEY']==src; });
    52             if (arr.length==0)
    53                 throw new Error("SourceKey "+src+" unknown.");
     47        // For simplicity, measurements suspend and resume must be unique in an observation
     48        if ((m.task=="suspend" || m.task=="resume") && sub>0)
     49            throw new Error("Measurement "+m.task+" not the only one in the observation (id="+id+")");
    5450
    55             m.source = arr[0]['fSourceName'];
    56         }
     51        m.source = rows[i]['fSourceName'];
    5752
    5853        var data = rows[i]['fData'];
     
    6762            schedule[entry] = { };
    6863
    69         schedule[entry].id   = rows[i]['fScheduleID'];
     64        schedule[entry].id   = id;
    7065        schedule[entry].date = new Date(rows[i]['fStart']+" UTC");
    7166
Note: See TracChangeset for help on using the changeset viewer.