This repository has been archived by the owner on Mar 3, 2019. It is now read-only.
/
ajax_endpoints.php
78 lines (72 loc) · 2.72 KB
/
ajax_endpoints.php
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
<?php
header("Content-Type: text/json");
require_once "libs/easyrdf-0.8.0/lib/EasyRdf.php";
$config = require_once("config.inc.php");
// This is the official endpoint
$endpoint = $config->defaultEndpoint;
/*
prefix sq: <http://sparqlscore.net/Score#>
prefix sd: <http://www.w3.org/ns/sparql-service-description#>
prefix git: <http://www.w3.org/ns/git#>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
*/
EasyRdf_Namespace::set('sq', 'http://sparqlscore.net/Score#');
EasyRdf_Namespace::set('sd', 'http://www.w3.org/ns/sparql-service-description#');
EasyRdf_Namespace::set('git', 'http://www.w3.org/ns/git#');
EasyRdf_Namespace::set('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
EasyRdf_Namespace::set('xsd', 'http://www.w3.org/2001/XMLSchema#');
$sparql = new EasyRdf_Sparql_Client($endpoint);
// Retrieve the graphs containing a test suite
$result = $sparql->query("
SELECT ?graph ?serverName ?serverVersion ?score ?total ?lastDate ?testerName ?testerVersion
WHERE {
GRAPH ?graph {
?service a sd:Service ;
sd:server ?server ;
sd:testedBy ?tester ;
sd:testedDate ?lastDate.
?server git:name ?serverName ;
git:describeTag ?serverVersion ;
git:describe ?serverVersionBuild .
?tester git:name ?testerName ;
git:describeTag ?testerVersion .
?service sq:scoreTest ?score .
?service sq:totalTest ?total .
}
{
SELECT ?serverName ?serverVersion (Max(?date) AS ?lastDate)
WHERE {
GRAPH ?graph {
?service a sd:Service ;
sd:server ?server ;
sd:testedDate ?date .
?server git:name ?serverName ;
git:describeTag ?serverVersion .
}
} GROUP BY ?serverName ?serverVersion
}
}
ORDER BY DESC(?score) ?date ?serverName
");
$prevEntry = null;
$graphs = array();
foreach ($result as $row) {
$graph = new stdClass();
$graph->graphName = $row->graph->getUri();
$graph->serverName = $row->serverName->getValue();
$graph->serverVersion = $row->serverVersion->getValue();
$graph->testerName = $row->testerName->getValue();
$graph->testerVersion = $row->testerVersion->getValue();
$graph->score = $row->score->getValue();
$graph->total = $row->total->getValue();
$graph->testDate = $row->lastDate->getValue();
// Only add the new entry if it is different from the previous one, because multiple tests can test the same database
// ORDER BY ensure the latest test arrives first
if($prevEntry == null || $prevEntry->serverName != $graph->serverName || $prevEntry->serverVersion != $graph->serverVersion
|| $prevEntry->testerName != $graph->testerName || $prevEntry->testerVersion != $graph->testerVersion) {
$graphs[]= $graph;
}
$prevEntry = $graph;
}
print json_encode($graphs);