forked from bryce-walsh/VAFinalProject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_analysis.html
96 lines (92 loc) · 3.31 KB
/
data_analysis.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script src="https://d3js.org/d3-array.v1.min.js"></script>
<script src="https://d3js.org/d3-geo.v1.min.js"></script>
<script src="./jquery-3.4.1.js"> </script>
<script>
var static_ids = {51: 1, 52: 4, 53: 6, 54: 9, 55: 11, 56: 12, 57: 13, 58: 14, 59: 15}
var projection = d3.geo.mercator()
.scale(100000)
.center([-119.85, .1])
.translate([650 / 2, 600 / 2]);
var path = d3.geo.path()
.projection(projection);
var final_radiation = new Array
var final_uncertainty = new Array
var final_positions = new Array
var uncertaintyJson = d3.json('./close.json', function(error, uncertaintyData) {
var geoJson = d3.json('StHimarkGeo.json', function(error, mapData) {
var features = mapData.features;
d3.csv("combined_10min.csv", function(data) {
for (var i = 0; i < data.length; i++) {
time = data[i]["Timestamp"]
radiation = {time : time}
uncertainty = {time : time}
positions = {}
for (var j = 0; j < features.length; j++) {
let sum = 0
let count = 0
let sensor_ct = 0
let uncertainty_k = 0
let bounds = path.bounds(features[j].geometry)
for (var k = 1; k < 60; k++){
if (k == 10) {
continue
}
point = path.centroid({
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [data[i]["Long_"+ k], data[i]["Lat_"+ k]]
}
})
positions[[k]] = {'point' : point}
if (k <= 50) {
positions[[k]]['type'] = 'mobile'
positions[[k]]['uncertainty'] = uncertaintyData["Uncertainty"][k-1]
positions[[k]]['id'] = k
}
else {
positions[[k]]['type'] = 'static'
positions[[k]]['uncertainty'] = 0
positions[[k]]['id'] = static_ids[k]
}
if ((bounds[0][1] - 20) < point[1] && (bounds[1][1] + 20) > point[1] &&
(bounds[0][0] - 20) < point[0] && (bounds[1][0] + 20) > point[0]) {
sum += parseFloat(data[i]["Value_"+ k])
count += 1
sensor_ct += 1
if (k <= 50) {
uncertainty_k += uncertaintyData["Uncertainty"][k - 1]
}
}
}
let avg = sum / count;
neighborhood = features[j].properties.Nbrhood
radiation[[neighborhood]] = avg
let u_calc = (uncertainty_k / sensor_ct) / sensor_ct
if (sensor_ct) {
uncertainty[[neighborhood]] = Math.abs(u_calc)
}
else {
uncertainty[[neighborhood]] = 10.5
}
}
final_radiation.push(radiation)
final_uncertainty.push(uncertainty)
final_positions.push(positions)
}
console.log("radiation", final_radiation)
console.log("uncertainty", final_uncertainty)
console.log("positions", final_positions)
stringified_rad = JSON.stringify(final_radiation)
stringified_uncertainty = JSON.stringify(final_uncertainty)
stringified_positions = JSON.stringify(final_positions)
$.post('http://localhost:5000/', {'radiation': stringified_rad, 'uncertainty': stringified_uncertainty, 'positions': stringified_positions})
})
});
});
</script>
</body>