-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsparql.html
48 lines (47 loc) · 2.38 KB
/
sparql.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
<html>
<head>
<script src="js/jquery-1.11.0.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
var query = `SELECT ?obs ?componentProperty ?obsValue FROM <http://labs.turnguard.com/scuba> WHERE {
?obs a qb:Observation;
qb:dataSet/qb:structure/qb:component/qb:componentProperty ?componentProperty .
?obs ?componentProperty ?obsValue
} ORDER BY ?obs ?componentProperty`;
$(function() {
$.ajax({
'async': false,
'global': false,
'url': 'http://sparql.turnguard.com/sparql?query='+encodeURIComponent(query),
'dataType': "json",
'success': function (data) {
var minimums = data.results.bindings.map(
binding => {
switch(binding.obsValue.datatype){
case "http://www.w3.org/2001/XMLSchema#integer":
obsValue = parseInt(binding.obsValue.value);
break;
case "http://www.w3.org/2001/XMLSchema#double":
obsValue = parseFloat(binding.obsValue.value);
break;
case "http://www.w3.org/2001/XMLSchema#dateTime":
obsValue = Date.parse(binding.obsValue.value);
break;
}
return { [binding.componentProperty.value]:obsValue }
}
).reduce( (a,b) => {
var componentProperty = Object.keys(b)[0];
if(a[componentProperty]===undefined || b[componentProperty]<a[componentProperty]){
a[componentProperty] = b[componentProperty];
}
return a;
},{});
console.log(minimums);
}
});
});
</script>
</body>
</html>