source: trunk/FACT++/scripts/Observation_class.js@ 19813

Last change on this file since 19813 was 19512, checked in by tbretz, 6 years ago
Added the nodrs and the grb flag.
File size: 4.7 KB
Line 
1'use strict';
2
3//
4// this file contains just the implementation of the
5// Observation class (I know there are no classes in javascript...)
6//
7
8function Observation(obj)
9{
10 if (typeof(obj)!='object')
11 throw new Error("Observation object can only be constructed using an object.");
12
13 if (!obj.date)
14 throw new Error("Observation object must have a 'date' parameter");
15
16 var ret = [];
17
18 // FIXME: Check transisiton from summer- and winter-time!!
19 var utc = obj.date.toString().toUpperCase()=="NOW" ? new Date() : new Date(obj.date);
20 if (isNaN(utc.valueOf()))
21 throw new Error('"'+obj.date+'" not a valid Date... try something like "2013-01-08 23:05 UTC".');
22
23 ret.start = utc;
24 ret.id = obj.id;
25
26 // If the given data is not an array, make it the first entry of an array
27 // so that we can simply loop over all entries
28 if (obj.measurements.length===undefined)
29 {
30 var cpy = obj.measurements;
31 obj.measurements = [];
32 obj.measurements[0] = cpy;
33 }
34
35 for (var i=0; i<obj.measurements.length; i++)
36 {
37 var obs = obj.measurements[i];
38
39 ret[i] = { };
40 ret[i].task = obs.task ? obs.task.toUpperCase() : "DATA";
41 ret[i].source = obs.source;
42 ret[i].ra = parseFloat(obs.ra);
43 ret[i].dec = parseFloat(obs.dec);
44 ret[i].zd = parseFloat(obs.zd);
45 ret[i].az = parseFloat(obs.az);
46 ret[i].orbit = parseFloat(obs.orbit);
47 ret[i].angle = parseFloat(obs.angle);
48 ret[i].time = parseInt(obs.time);
49 ret[i].threshold = parseInt(obs.threshold);
50 ret[i].lidclosed = obs.lidclosed;
51 ret[i].biason = obs.biason;
52 ret[i].rstype = obs.rstype ? obs.rstype : "default";
53 ret[i].sub = i;
54 ret[i].start = utc;
55 ret[i].nodrs = obs.nodrs;
56 ret[i].grb = obs.grb;
57
58
59 ret[i].toString = function()
60 {
61 var rc = this.task;
62 rc += "["+this.sub+"]";
63 if (this.source)
64 rc += ": " + this.source;
65 //rc += " ["+this.start.toUTCString()+"]";
66 return rc;
67 }
68
69 switch (ret[i].task)
70 {
71 case 'DATA':
72 if (i!=obj.measurements.length-1)
73 throw new Error("Measurement DATA [n="+i+", "+utc.toUTCString()+"] must be the last in the list of measurements [cnt="+obj.measurements.length+"]");
74 if (ret[i].source == undefined)
75 throw new Error("Measurement DATA must have a source defined");
76 // This is obsolete. We cannot check everything which is not evaluated anyways
77 //if (ret[i].lidclosed == true)
78 // throw new Error("Observation must not have 'lidclosed'==true " +
79 // "if 'task'=='data'");
80 break;
81
82 case 'SUSPEND':
83 case 'RESUME':
84 if (obj.measurements.length!=1)
85 throw new Error("Measurement "+ret[i].task+" [n="+i+", "+utc.toUTCString()+"] must be the only measurements [cnt="+obj.measurements.length+"] in an observation");
86 break;
87
88 case 'STARTUP':
89 case 'SHUTDOWN':
90 if (ret[i].source != undefined)
91 console.out("WARNING - Measurement "+ret[i].task+" has a source defined");
92 break;
93
94 case 'RATESCAN':
95 if (ret[i].source == undefined && (isNaN(ret[i].ra) || isNaN(ret[i].dec)))
96 throw new Error("Measurement RATESCAN must have either a source or 'ra' & 'dec' defined");
97 // This is obsolete. We cannot check everything which is not evaluated anyways
98 //if (ret[i].lidclosed == true)
99 // throw new Error("Observation RATESCAN must not have 'lidclosed'==true");
100 break;
101
102 case 'RATESCAN2':
103 if ((ret[i].lidclosed != true) && ret[i].source == undefined && (isNaN(ret[i].ra) || isNaN(ret[i].dec)))
104 throw new Error("Measurement RATESCAN2 ('lidclosed'==false or undefined) must have either a source or 'ra' & 'dec' defined");
105 if (ret[i].lidclosed == true && (isNaN(ret[i].az) || isNaN(ret[i].az)))
106 throw new Error("Measurement RATESCAN2 ('lidclosed'==true) must have 'zd' & 'az' defined");
107 break;
108
109 case 'CUSTOM':
110 if (isNaN(ret[i].az) || isNaN(ret[i].az) || isNaN(ret[i].time) || isNaN(ret[i].threshold))
111 throw new Error("Measurement CUSTOM must have 'zd' & 'az', 'time' and 'threshold' defined.");
112 break;
113
114 case 'SINGLEPE':
115 case 'OVTEST':
116 case 'DRSCALIB':
117 case 'IDLE':
118 case 'SLEEP':
119 break;
120
121 default:
122 throw new Error("The measurement type "+ret[i].task+" is unknown.");
123 }
124 }
125
126 return ret;
127}
Note: See TracBrowser for help on using the repository browser.