Commit dd0fbc6d authored by Sven Schneider's avatar Sven Schneider
Browse files

continued but not finished working on getting data from several buildings

parent 01d1be71
Showing with 154 additions and 19 deletions
+154 -19
"use strict"; "use strict";
// Functions // Functions
import { import {
aggregateResponse, aggregateResponse,
...@@ -29,6 +30,7 @@ import { ...@@ -29,6 +30,7 @@ import {
} from "./appChart.js"; } from "./appChart.js";
var ALLDATA = []; var ALLDATA = [];
var bld = 0;
Cesium.Ion.defaultAccessToken = Cesium.Ion.defaultAccessToken =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyODgxYzJlNi1kNDZiLTQ3ZmQtYmUxYy0yMWI0OGM3NDA5MzAiLCJpZCI6NDczOSwic2NvcGVzIjpbImFzciIsImdjIl0sImlhdCI6MTU0MTUyMzU0MX0.shj2hM3pvsvcmE_wMb2aBDuk_cKWmFmbolltInGImwU"; "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyODgxYzJlNi1kNDZiLTQ3ZmQtYmUxYy0yMWI0OGM3NDA5MzAiLCJpZCI6NDczOSwic2NvcGVzIjpbImFzciIsImdjIl0sImlhdCI6MTU0MTUyMzU0MX0.shj2hM3pvsvcmE_wMb2aBDuk_cKWmFmbolltInGImwU";
...@@ -251,6 +253,8 @@ const activate3DTileFeaturePicking = function() { ...@@ -251,6 +253,8 @@ const activate3DTileFeaturePicking = function() {
selected.feature.color = selected.originalColor; selected.feature.color = selected.originalColor;
selected.feature = undefined; selected.feature = undefined;
} }
ALLDATA = [];
cnt = 0;
// Pick a new feature // Pick a new feature
const pickedFeature = viewer.scene.pick(movement.position); const pickedFeature = viewer.scene.pick(movement.position);
if (!Cesium.defined(pickedFeature)) { if (!Cesium.defined(pickedFeature)) {
...@@ -324,7 +328,8 @@ const activate3DTileFeaturePicking = function() { ...@@ -324,7 +328,8 @@ const activate3DTileFeaturePicking = function() {
const BUILDING_STREAM_ID = [75, 76, 77, 78, 79, 80]; const BUILDING_STREAM_ID = [75, 76, 77, 78, 79, 80];
const BUILDING_ID = ["101", "102", "107", "112, 118", "125", "225"]; const BUILDING_ID = ["101", "102", "107", "112, 118", "125", "225"];
// ALLDATA = []; // ALLDATA = [];
var bld = 0; var cnt = 0;
for (bld = 0; bld < BUILDING_STREAM_ID.length; bld++) { for (bld = 0; bld < BUILDING_STREAM_ID.length; bld++) {
...@@ -353,9 +358,9 @@ const activate3DTileFeaturePicking = function() { ...@@ -353,9 +358,9 @@ const activate3DTileFeaturePicking = function() {
combinedObservations.push(...dataArrays); combinedObservations.push(...dataArrays);
}); });
// DEBUG: Check total number of observations // DEBUG: Check total number of observations
console.log(combinedObservations.length); // console.log(combinedObservations.length);
// DEBUG: Print the array of observations // DEBUG: Print the array of observations
console.log(combinedObservations); // console.log(combinedObservations);
return combinedObservations; return combinedObservations;
}) })
...@@ -366,31 +371,34 @@ const activate3DTileFeaturePicking = function() { ...@@ -366,31 +371,34 @@ const activate3DTileFeaturePicking = function() {
.then((observationArr) => { .then((observationArr) => {
var agg = aggregateResponse(observationArr, 0, 'mean'); var agg = aggregateResponse(observationArr, 0, 'mean');
var tmpObj = { var tmpObj = {
id: BUILDING_ID[bld], BldID: BUILDING_ID[cnt],
streamID: BUILDING_STREAM_ID[bld], streamID: BUILDING_STREAM_ID[cnt],
timestamp: agg.aggDates, timestamp: agg.aggDates,
data: agg.aggVals, data: agg.aggVals,
}; };
ALLDATA.push(tmpObj); ALLDATA.push(tmpObj);
// console.log(agg); // console.log(agg);
drawHeatMapHC(formatSTAResponseForHeatMap(agg.originalFormat)); drawHeatMapHC(formatSTAResponseForHeatMap(agg.originalFormat));
drawLineChartHC(formatSTAResponseForLineChart(agg.originalFormat)); drawLineChartHC(formatSTAResponseForLineChart(agg.originalFormat));
console.log(ALLDATA.length);
var selectedDate = document.getElementById("DateSelected").innerHTML;
var date = new Date( if (ALLDATA.length == 6) {
Date.parse( var selectedDate = document.getElementById("DateSelected").innerHTML;
switchDayMonth_inDate(selectedDate)
)
);
var p = whereIsDateInArray(ALLDATA[0].timestamp, date); var date = new Date(
if (p == -1) Date.parse(
console.log('date not found in date array'); switchDayMonth_inDate(selectedDate)
else )
console.log('date found at position' + p); );
console.log(date); var p = whereIsDateInArray(ALLDATA[0].timestamp, date);
const DATA = getDataForAllBuildingsPerDate(p);
colorBlds(DATA);
console.log(date);
}
console.log(ALLDATA.length);
cnt++
// alert('waiting...'); // alert('waiting...');
}); });
...@@ -399,8 +407,135 @@ const activate3DTileFeaturePicking = function() { ...@@ -399,8 +407,135 @@ const activate3DTileFeaturePicking = function() {
} }
}, Cesium.ScreenSpaceEventType.LEFT_CLICK); }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
}; };
activate3DTileFeaturePicking(); activate3DTileFeaturePicking();
\ No newline at end of file
function goon(ALLDATA) {
if (ALLDATA.length > 0) {
var selectedDate = document.getElementById("DateSelected").innerHTML;
var date = new Date(
Date.parse(
switchDayMonth_inDate(selectedDate)
)
);
var p = whereIsDateInArray(ALLDATA[0].timestamp, date);
const DATA = getDataForAllBuildingsPerDate(p);
colorBlds(DATA);
console.log(date);
}
}
// /**
// *
// * @param {Number} datePos
// */
export const getDataForAllBuildingsPerDate = function(datePos) {
var dataObjPerBld = [];
var dataArray = [];
for (var i = 0; i < ALLDATA.length; i++) {
var tmp = {
BldId: ALLDATA[i].BldID,
dateVal: ALLDATA[i].timestamp[datePos],
dataVal: ALLDATA[i].data[datePos]
};
dataArray.push(tmp.dataVal);
dataObjPerBld.push(tmp);
}
return {
dataPerBld: dataObjPerBld,
dataArray: dataArray
};
}
export const colorBlds = function(bldInfo) {
// see: https://github.com/PimpTrizkit/PJs/wiki/12.-Shade,-Blend-and-Convert-a-Web-Color-(pSBC.js)
const RGB_Linear_Blend = (p, c0, c1) => {
var i = parseInt,
r = Math.round,
P = 1 - p,
[a, b, c, d] = c0.split(","),
[e, f, g, h] = c1.split(","),
x = d || h,
j = x ? "," + (!d ? h : !h ? d : r((parseFloat(d) * P + parseFloat(h) * p) * 1000) / 1000 + ")") : ")";
return "rgb" + (x ? "a(" : "(") + r(i(a[3] == "a" ? a.slice(5) : a.slice(4)) * P + i(e[3] == "a" ? e.slice(5) : e.slice(4)) * p) + "," + r(i(b) * P + i(f) * p) + "," + r(i(c) * P + i(g) * p) + d;
}
// get the gradient colors between the two defined colors;
const c1 = "rgb(255,64,0)";
const c2 = "rgb(63,131,163)";
var L = bldInfo.dataArray.length;
var offset = 1 / (L - 1);
var colorsForBld = [];
var p = 0;
for (var i = 0; i < L; i++) {
var cnew = RGB_Linear_Blend(p, c1, c2);
cnew = cnew.replace('undefined', ')');
colorsForBld.push(cnew);
p += offset;
console.log(p);
}
var numbers = bldInfo.dataArray,
ma = numbers.reduce(function(a, b) { return Math.max(a, b); }),
mi = numbers.reduce(function(a, b) { return Math.min(a, b); }),
dif = ma - mi,
l = numbers.length,
i;
for (i = 0; i < l; i++) {
numbers[i] = (numbers[i] - mi) / dif;
}
function sortWithIndeces(toSort) {
for (var i = 0; i < toSort.length; i++) {
toSort[i] = [toSort[i], i];
}
toSort.sort(function(left, right) {
return left[0] < right[0] ? -1 : 1;
});
toSort.sortIndices = [];
for (var j = 0; j < toSort.length; j++) {
toSort.sortIndices.push(toSort[j][1]);
toSort[j] = toSort[j][0];
}
return toSort;
}
sortWithIndeces(numbers);
// alert(numbers.sortIndices.join(","));
var sortedIndices = numbers.sortIndices;
// convert object to array
var i = 0,
arr = [];
for (var ob in inputObj)
arr[i++] = ob;
// numbers = (6)[0.37684400819550146, 0, 0.5862015830883935, 1, 0.444816858861194, 0.9179110359561272],
console.log(numbers);
// assign the color to the buildings based on their id
// var sortedValues = bldInfo.dataArray.sort
// if (!Cesium.defined(name)) {
// name = pickedFeature.getProperty("id");
// }
}
\ No newline at end of file
Supports Markdown
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