I would like to have an array with timestamp as keys and numbers as values. This way I want to track how many cars have entered or left a parking lot as well as how many cars have parked in the parking lot simultaneously.
Basics: - Get the list of parking actions with enter date and exit date for each transaction - Get all those dates into an array with timestamp as key and += 1 if enter date and -=1 for exit date - Sort by date - Go through sorted array and add to a counter, track if new maximum is reached
var result = [];
var counter = 0;
var max = 0;
//SELECT enterTS, exitTS FROM parking;
// validated, that works
while (!rs.eof) {
var es = rs.fields(1).toString();
var dd = rs.fields(2).toString();
result[es] += 1; //might happen at the same time with exit or other entries
result[dd] -= 1;
alert('Start' + es); //correct timestamp
alert('Array' + result[es]); //shows NaN
}
result.sort();
for (var key in result) {
counter += result[key];
if(counter > max){
max = counter;
}
}
Thanks for any help. I know this is not a working code snippet, but without the data connection this is tricky. I already tried the associative arrays, but was not able to understand how I can use in this example.
Thanks again, fj