Changeset 15084


Ignore:
Timestamp:
03/15/13 13:57:21 (12 years ago)
Author:
tbretz
Message:
Adapted to new style of writing a schedule.
File:
1 edited

Legend:

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

    r15028 r15084  
    1414        throw new Error("Observation object must have a 'date' parameter");
    1515
     16    var ret = [];
     17
    1618    // FIXME: Check transisiton from summer- and winter-time!!
    1719    var utc = new Date(obj.date);
     
    1921        throw new Error(obj.date+' is not a valid Date String.'+
    2022                        ' Try something like "2013-01-08 23:05 UTC" .');
     23    ret.start = utc;
    2124
    22     this.start  = utc;
    23     this.task   = obj.task ? obj.task.toUpperCase() : "DATA";
    24     this.source = obj.source;
    25     this.ra     = obj.ra;
    26     this.dec    = obj.dec;
     25    // If the given data is not an array, make it the first entry of an array
     26    // so that we can simply loop over all entries
     27    if (obj.measurements.length===undefined)
     28    {
     29        var cpy = obj.measurements;
     30        obj.measurements = [];
     31        obj.measurements[0] = cpy;
     32    }
     33
     34    for (var i=0; i<obj.measurements.length; i++)
     35    {
     36        var obs = obj.measurements[i];
     37
     38        ret[i] = { };
     39        ret[i].task   = obs.task ? obs.task.toUpperCase() : "DATA";
     40        ret[i].source = obs.source;
     41        ret[i].ra     = obs.ra;
     42        ret[i].dec    = obs.dec;
     43        ret[i].sub    = i;
     44        ret[i].start  = utc;
     45
     46        ret[i].toString = function()
     47        {
     48            var rc = this.task;
     49            rc += "["+this.sub+"]";
     50            if (this.source)
     51                rc += ": " + this.source;
     52            //rc += " ["+this.start.toUTCString()+"]";
     53            return rc;
     54        }
    2755   
    28     switch (this.task)
    29     {
    30     case 'DATA':
    31         if (this.source == undefined)
    32             throw new Error("Observation must have either 'source' or 'task' " +
    33                             "if 'task' == 'data' it must have also have 'source' ");
    34         break;
     56        switch (ret[i].task)
     57        {
     58        case 'DATA':
     59            if (i!=obj.measurements.length-1)
     60                throw new Error("DATA must be the last in the list of measurements");
     61            if (ret[i].source == undefined)
     62                throw new Error("Observation must have either 'source' or 'task' " +
     63                                "if 'task' == 'data' it must have also have 'source' ");
     64            break;
    3565
    36     case 'STARTUP':
    37         if (this.source != undefined)
    38             console.out("warning. Observation with task='startup' also has source defined");
    39         break;
     66        case 'STARTUP':
     67            if (ret[i].source != undefined)
     68                console.out("warning. Observation with task='startup' also has source defined");
     69            break;
    4070
    41     case 'SHUTDOWN':
    42         if (this.source != undefined)
    43             console.out("warning. Observation with task='shutdown' also has source defined");
    44         break;
     71        case 'SHUTDOWN':
     72            if (ret[i].source != undefined)
     73                console.out("warning. Observation with task='shutdown' also has source defined");
     74            break;
    4575
    46     case 'RATESCAN':
    47         if (this.source == undefined && (this.ra == undefined || this.dec == undefined))
    48             throw new Error("Observation must have either 'source' or 'ra' & 'dec' " +
    49                             "if 'task' == 'ratescan'");
    50         break;
     76        case 'RATESCAN':
     77            if (ret[i].source == undefined && (ret[i].ra == undefined || ret[i].dec == undefined))
     78                throw new Error("Observation must have either 'source' or 'ra' & 'dec' " +
     79                                "if 'task' == 'ratescan'");
     80            break;
    5181
    52     default:
    53         throw new Error(" the task of this observation:"+this.task+
    54                         "is not implemented. use one of: DATA, STARTUP, SHUTDOWN, RATESCAN.");
     82        default:
     83            throw new Error(" the task of this observation:"+this.task+
     84                            "is not implemented. use one of: DATA, STARTUP, SHUTDOWN, RATESCAN.");
     85        }
    5586    }
     87
     88    return ret;
    5689}
    57 
    58 // method toString()
    59 Observation.prototype.toString = function()
    60 {
    61     if (this.source)
    62         return this.task + "  " + this.source+" ["+this.start+"]" ;
    63     else
    64         return this.task + " ["+this.start+"]" ;
    65 }
Note: See TracChangeset for help on using the changeset viewer.