-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph_spatial_SE.html
190 lines (154 loc) · 8.08 KB
/
graph_spatial_SE.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<!doctype html>
<body>
<input type="file" id="fileInput" name="filefield" multiple="multiple">
maxObservedBlocks:<textarea id="maxObservedBlocks">100</textarea>
maxInteractedBlocks:<textarea id="maxInteractedBlocks">100</textarea>
maxObservedPositions :<textarea id="maxObservedPositions">100</textarea>
maxWalkedPositions :<textarea id="maxWalkedPositions">100</textarea>
totalSeconds :<textarea id="totalSeconds">3600</textarea>
<div id="fileDisplayArea" style="width: 400px; height: 50px;"></div>
<div style="display: flex;">
<div id="ObservedBlocksContainer" style="width: 500px; height: 400px;"></div>
<div id="InteractedBlocksContainer" style="width: 500px; height: 400px;"></div>
</div>
<div style="display: flex;">
<div id="ObservedPositionsContainer" style="width: 500px; height: 400px;"></div>
<div id="WalkedPositionsContainer" style="width: 500px; height: 400px;"></div>
</div>
<div style="display: flex;">
<div id="SecondsContainer" style="width: 500px; height: 400px;"></div>
</div>
<script src="https://cdn.anychart.com/releases/v8/js/anychart-base.min.js" type="text/javascript"></script>
<script>
// https://jsfiddle.net/b1ynb405/
var fileInput = document.getElementById('fileInput');
var fileDisplayArea = document.getElementById('fileDisplayArea');
fileInput.addEventListener('change', function(e) {
const spatialFiles = fileInput.files;
// Validate we are reading txt files
for (var i = 0; i < spatialFiles.length; i++){
var textType = /text.*/;
if(!spatialFiles[i].type.match(textType)){
fileDisplayArea.innerText = "Some text coverageFile is not supported!"
throw new Error('Some text coverageFile is not supported!');
}
}
myfunction(spatialFiles);
});
async function myfunction(spatialFiles) {
const allDataObservedBlocks = [];
const allDataInteractedBlocks = [];
const allDataObservedPositions = [];
const allDataWalkedPositions = [];
const allDataSeconds = [];
//create a line chart
var chartObservedBlocks = anychart.line();
var chartInteractedBlocks = anychart.line();
var chartObservedPositions = anychart.line();
var chartWalkedPositions = anychart.line();
var chartSeconds = anychart.line();
// set y axis max value if user indicates
var maxObservedBlocks = document.getElementById("maxObservedBlocks") === null ? "" : document.getElementById("maxObservedBlocks").value;
if(!isEmpty(maxObservedBlocks) && !isNaN(parseInt(maxObservedBlocks))) chartObservedBlocks.yScale().maximum(parseInt(maxObservedBlocks));
var maxInteractedBlocks = document.getElementById("maxInteractedBlocks") === null ? "" : document.getElementById("maxInteractedBlocks").value;
if(!isEmpty(maxInteractedBlocks) && !isNaN(parseInt(maxInteractedBlocks))) chartInteractedBlocks.yScale().maximum(parseInt(maxInteractedBlocks));
var maxObservedPositions = document.getElementById("maxObservedPositions") === null ? "" : document.getElementById("maxObservedPositions").value;
if(!isEmpty(maxObservedPositions) && !isNaN(parseInt(maxObservedPositions))) chartObservedPositions.yScale().maximum(parseInt(maxObservedPositions));
var maxWalkedPositions = document.getElementById("maxWalkedPositions") === null ? "" : document.getElementById("maxWalkedPositions").value;
if(!isEmpty(maxWalkedPositions) && !isNaN(parseInt(maxWalkedPositions))) chartWalkedPositions.yScale().maximum(parseInt(maxWalkedPositions));
var totalSeconds = document.getElementById("totalSeconds") === null ? "" : document.getElementById("totalSeconds").value;
if(!isEmpty(totalSeconds) && !isNaN(parseInt(totalSeconds))) chartSeconds.yScale().maximum(parseInt(totalSeconds));
chartObservedBlocks.title("Observed Blocks Coverage Percentage");
chartInteractedBlocks.title("Interacted Blocks Coverage Percentage");
chartObservedPositions.title("Observed Positions Coverage Percentage");
chartWalkedPositions.title("Walked Positions Coverage Percentage");
chartSeconds.title("Total Seconds");
for (var i = 0; i < spatialFiles.length; i++){
console.log(spatialFiles[i]);
const singleDataObservedBlocks = [];
const singleDataInteractedBlocks = [];
const singleDataObservedPositions = [];
const singleDataWalkedPositions = [];
const singleDataSeconds = [];
const fileReader = new SyncFileReader(spatialFiles[i]);
const arrayBuffer = await fileReader.readAsText();
// Coverage metrics created with Windows CR LF
var arrLines = arrayBuffer.split("\r\n");
for (var line = 0; line < arrLines.length; line++) {
// Skip empty line, usually at the end of the file
if(isEmpty(arrLines[line])) continue;
// Sequence | 5 | Action | 3 | existingFunctionalBlocks | 23 | observedFunctionalBlocks | 0 | 0,00 | interactedFunctionalBlocks | 0 | 0,00 | existingFloorPositions | 837 | observedFloorPositions | 30 | 9,84 | walkedFloorPositions | 7 | 0,84 | seconds | 15
singleDataObservedBlocks.push( parseFloat( arrLines[line].split(" | ")[8].replace(",",".") ) );
singleDataInteractedBlocks.push( parseFloat( arrLines[line].split(" | ")[11].replace(",",".") ) );
singleDataObservedPositions.push( parseFloat( arrLines[line].split(" | ")[16].replace(",",".") ) );
singleDataWalkedPositions.push( parseFloat( arrLines[line].split(" | ")[19].replace(",",".") ) );
singleDataSeconds.push( parseFloat( arrLines[line].split(" | ")[21].replace(",",".") ) );
}
allDataObservedBlocks.push(singleDataObservedBlocks)
allDataInteractedBlocks.push(singleDataInteractedBlocks)
allDataObservedPositions.push(singleDataObservedPositions)
allDataWalkedPositions.push(singleDataWalkedPositions)
allDataSeconds.push(singleDataSeconds)
console.log(spatialFiles[i].name);
chartObservedBlocks.line(allDataObservedBlocks[i]).name(spatialFiles[i].name);
chartInteractedBlocks.line(allDataInteractedBlocks[i]).name(spatialFiles[i].name);
chartObservedPositions.line(allDataObservedPositions[i]).name(spatialFiles[i].name);
chartWalkedPositions.line(allDataWalkedPositions[i]).name(spatialFiles[i].name);
chartSeconds.line(allDataSeconds[i]).name(spatialFiles[i].name);
}
//set the container where chart will be drawn
chartObservedBlocks.container("ObservedBlocksContainer");
chartInteractedBlocks.container("InteractedBlocksContainer");
chartObservedPositions.container("ObservedPositionsContainer");
chartWalkedPositions.container("WalkedPositionsContainer");
chartSeconds.container("SecondsContainer");
// Enable legend colours
chartObservedBlocks.legend().enabled(true)
chartInteractedBlocks.legend().enabled(true)
chartObservedPositions.legend().enabled(true)
chartWalkedPositions.legend().enabled(true)
chartSeconds.legend().enabled(true)
chartObservedBlocks.xAxis().labels().format(function() { return(parseInt(this.value)); });
chartInteractedBlocks.xAxis().labels().format(function() { return(parseInt(this.value)); });
chartObservedPositions.xAxis().labels().format(function() { return(parseInt(this.value)); });
chartWalkedPositions.xAxis().labels().format(function() { return(parseInt(this.value)); });
chartSeconds.xAxis().labels().format(function() { return(parseInt(this.value)); });
chartObservedBlocks.xAxis().title("Actions");
chartInteractedBlocks.xAxis().title("Actions");
chartObservedPositions.xAxis().title("Actions");
chartWalkedPositions.xAxis().title("Actions");
chartSeconds.xAxis().title("Actions");
//draw the chart on the page
chartObservedBlocks.draw();
chartInteractedBlocks.draw();
chartObservedPositions.draw();
chartWalkedPositions.draw();
chartSeconds.draw();
console.log('finish drawing');
}
function SyncFileReader(file) {
let self = this;
let ready = false;
let result = '';
const sleep = function (ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
self.readAsText = async function() {
while (ready === false) {
await sleep(100);
}
return result;
}
const reader = new FileReader();
reader.onloadend = function(evt) {
result = evt.target.result;
ready = true;
};
reader.readAsText(file);
}
function isEmpty(str) {
return (!str || str.length === 0 );
}
</script>
</body>
</html>