get_services.php 1.6 KB
<?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));
?>