You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.5 KiB
JavaScript
67 lines
2.5 KiB
JavaScript
var data = [];
|
|
const day_cache = {};
|
|
var is_loaded = false;
|
|
|
|
function getForDay(day, month, year){
|
|
if(!is_loaded) return [];
|
|
var key = day + "-" + month + "-" + year;
|
|
if(day_cache[key]) return day_cache[key];
|
|
const ts = new Date().getTime();
|
|
const targetDateStart = new Date(`${year}-${month<10?"0":""}${month}-${day<10? "0":""}${day}`)
|
|
const targetDateEnd = new Date(`${year}-${month<10?"0":""}${month}-${day<10? "0":""}${day}`);
|
|
targetDateEnd.setDate(targetDateEnd.getDate() + 1);
|
|
const timestamp_start = targetDateStart.getTime();
|
|
const timestamp_end = targetDateEnd.getTime();
|
|
var result = (data)
|
|
.filter(function(coords){
|
|
if(coords[1]>6000){return false}
|
|
const timestamp = coords[0]
|
|
//console.log(timestamp_start, timestamp, timestamp_end, timestamp <=timestamp_end && timestamp >= timestamp_start);
|
|
return timestamp <=timestamp_end && timestamp >= timestamp_start
|
|
})
|
|
const te = new Date().getTime();
|
|
day_cache[key] = result;
|
|
return result;
|
|
}
|
|
|
|
function newData(text){
|
|
const lines = text.split("\n");
|
|
// measure("map to floats", ()=>lines.map(function(line){
|
|
// var coords = line.split(",").map(parseFloat)
|
|
// var d = new Date(coords[0]);
|
|
// //(coords[0] / 3600) % 24
|
|
// //dateParser.hours(coords[0])
|
|
// //var hour = d.getHours() + d.getMinutes()/60;
|
|
// //coords.push(hour)
|
|
// }));
|
|
|
|
data = text.split("\n")
|
|
.map(function(line){
|
|
// maps to [timestamp, production, hour, datetime]
|
|
var coords = line.split(",").map(parseFloat)
|
|
var d = new Date(coords[0]);
|
|
//var hour = d.getHours() + d.getMinutes()/60;
|
|
//coords.push(hour)
|
|
coords.push(0);
|
|
// d.setDate(1);
|
|
// d.setMonth(1);
|
|
// d.setYear(1990); // so two dates always nicely overlap in comparison view
|
|
coords.push(d)
|
|
return coords;
|
|
})
|
|
is_loaded = true;
|
|
}
|
|
|
|
WorkerScript.onMessage = function(message) {
|
|
if(message.type === "newdata"){
|
|
newData(message.data);
|
|
WorkerScript.sendMessage({id: message.id, data});
|
|
}
|
|
if(message.type === "get-for-day"){
|
|
WorkerScript.sendMessage({id: message.id, data: getForDay(message.data.day, message.data.month, message.data.year)})
|
|
}
|
|
if(message.type === "set-timeout"){
|
|
WorkerScript.sendMessage({id: message.id})
|
|
}
|
|
}
|