get_services.php
1.6 KB
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
<?php
include(realpath(dirname(__FILE__) . "/../php/config.php"));
include(BASE_PATH . "/php/classes/EpnTapMgr.php");
$EpnTapMgr = new EpnTapMgr;
$services = json_decode(file_get_contents(EpnTapDataPath . "/EpnTapServices.json"), TRUE);
$services_content = Array();
foreach($services as $s) {
//// -- To display columns names for each service --
// $query = "SELECT TOP 1 * FROM " . $s["schema"] . ".epn_core";
// $rows = $EpnTapMgr->request($s["accessurl"], $query);
// echo $s["schema"] . "\n\"columns\": \"" . join(',', array_keys($rows[0])) . "\"\n\n";
$query = "SELECT dataproduct_type as dp_type,
target_class as t_class,
target_name as t_name,
COUNT(granule_uid) as nb_res,
MIN(time_min) as time_min,
MAX(time_max) as time_max
FROM " . $s["schema"] . ".epn_core GROUP BY dp_type, t_class, t_name";
$rows = $EpnTapMgr->request($s["accessurl"], $query);
if($rows == NULL)
continue;
foreach ($rows as $r) {
$r['dp_type'] = $r['dp_type'];
$r['t_class'] = $r['t_class'];
$r['t_name'] = $r['t_name'];
if(!isset($services_content[$r['dp_type']]))
$services_content[$r['dp_type']] = Array();
if(!isset($services_content[$r['dp_type']][$r['t_class']]))
$services_content[$r['dp_type']][$r['t_class']] = Array();
if(!isset($services_content[$r['dp_type']][$r['t_class']][$r['t_name']]))
$services_content[$r['dp_type']][$r['t_class']][$r['t_name']] = Array();
$services_content[$r['dp_type']][$r['t_class']][$r['t_name']][$s["schema"]] = [$r['nb_res'], $r['time_min'], $r['time_max']];
}
}
fwrite(fopen(EpnTapDataPath . "metadata.json", "w+"), json_encode($services_content));
?>