// ====================================================================================== function getSchedule() { // Get current time var start = new Date();//new Date("2013-04-07 19:00:00 UTC"); // Because Main.js could start a new observations just in the moment between 'now' // and entering the new data in the database, we have to use the unique id // in Main.js to check if the current observation should be changed (and sub resetted) start = new Date(start.getTime()-10*3600000); // ---------------------------------------------------------------------- // Connect to database var db = new Database($['schedule-database']); // Get the current schedule var rows = db.query("SELECT * FROM Schedule "+ "LEFT JOIN MeasurementType USING (fMeasurementTypeKey) "+ "LEFT JOIN Source USING (fSourceKey) "+ "WHERE fStart>'"+start.toISOString()+"' "+ "ORDER BY fStart ASC, fMeasurementID ASC"); // Close db connection db.close(); // ---------------------------------------------------------------------- var schedule = []; var entry = -1; var sub = 0; for (var i=0; i0) throw new Error("Measurement "+m.task+" not the only one in the observation (id="+id+")"); m.source = rows[i]['fSourceName']; var data = rows[i]['fData']; if (data) { var obj = JSON.parse(("{"+data+"}").replace(/\ /g, "").replace(/(\w+):/gi, "\"$1\":")); for (var key in obj) m[key] = obj[key]; } if (!schedule[entry]) schedule[entry] = { }; schedule[entry].id = id; schedule[entry].date = new Date(rows[i]['fStart']+" UTC"); if (!schedule[entry].measurements) schedule[entry].measurements = []; schedule[entry].measurements[sub] = m; } for (var i=0; i