Commit 01d1be71 authored by Sven Schneider's avatar Sven Schneider
Browse files

added functionality to find the data for a specific date from the aggregated data array

parent 801165ad
......@@ -24,6 +24,49 @@ function convertArray2JSON(arr) {
}
/**
*
* @param {Array} array containing dates of type Date
* @param {Date} date date to look for in array
* @returns postition of the array where the date was matched
*/
export const whereIsDateInArray = function(array, date) {
const DAY = date.getDate();
const MONTH = date.getMonth();
var pos = -1;
for (var i = 0; i < array.length; i++) {
var day = array[i].getDate();
var month = array[i].getMonth();
if (day === DAY && MONTH === month) {
pos = i;
}
}
return pos;
}
/**
* Converts the date string from DD.MM.YYYY obtained from HTML date picker to -> MM.DD.YYYY
* @param {String} selctedDate containing a date string in the format DD.MM.YYYY
* @returns {String} of the provided date in the format MM.DD.YYYY
*/
export const switchDayMonth_inDate = function(selectedDate) {
var splitedString = selectedDate.split('.');
var newDate = [];
newDate.push(splitedString[1]);
newDate.push(splitedString[0]);
newDate.push(splitedString[2]);
return newDate.join('.');;
}
/**
* Format the response from SensorThings API to make it suitable for heatmap
* @param {Array} obsArray Response from SensorThings API as array
......
......@@ -3,6 +3,8 @@
// Functions
import {
aggregateResponse,
switchDayMonth_inDate,
whereIsDateInArray,
} from "./aggregation.js";
......@@ -374,8 +376,21 @@ const activate3DTileFeaturePicking = function() {
drawHeatMapHC(formatSTAResponseForHeatMap(agg.originalFormat));
drawLineChartHC(formatSTAResponseForLineChart(agg.originalFormat));
console.log(ALLDATA.length);
var selectedDate = document.getElementById("DateSelected").value;
console.log(selectedDate);
var selectedDate = document.getElementById("DateSelected").innerHTML;
var date = new Date(
Date.parse(
switchDayMonth_inDate(selectedDate)
)
);
var p = whereIsDateInArray(ALLDATA[0].timestamp, date);
if (p == -1)
console.log('date not found in date array');
else
console.log('date found at position' + p);
console.log(date);
// alert('waiting...');
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment