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 |
|
---|
8 | function 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 | // FIXME: Check transisiton from summer- and winter-time!!
|
---|
17 | var utc = new Date(obj.date);
|
---|
18 | if (isNaN(utc.valueOf()))
|
---|
19 | throw new Error(obj.date+' is not a valid Date String.'+
|
---|
20 | ' Try something like "2013-01-08 23:05 UTC" .');
|
---|
21 |
|
---|
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;
|
---|
27 |
|
---|
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;
|
---|
35 |
|
---|
36 | case 'STARTUP':
|
---|
37 | if (this.source != undefined)
|
---|
38 | console.out("warning. Observation with task='startup' also has source defined");
|
---|
39 | break;
|
---|
40 |
|
---|
41 | case 'SHUTDOWN':
|
---|
42 | if (this.source != undefined)
|
---|
43 | console.out("warning. Observation with task='shutdown' also has source defined");
|
---|
44 | break;
|
---|
45 |
|
---|
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;
|
---|
51 |
|
---|
52 | default:
|
---|
53 | throw new Error(" the task of this observation:"+this.task+
|
---|
54 | "is not implemented. use one of: DATA, STARTUP, SHUTDOWN, RATESCAN.");
|
---|
55 | }
|
---|
56 | }
|
---|
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 | }
|
---|