Commit f85c1d376551ab554d777c1e96a18e0f4d5621e8

Authored by Nathanael Jourdane
1 parent a89a2fea

Update the metadata downloader.

Showing 2 changed files with 44 additions and 52 deletions   Show diff stats
php/get_services.php deleted
... ... @@ -1,52 +0,0 @@
1   -<?php
2   -include(realpath(dirname(__FILE__) . "/config.php"));
3   -include(CLASSPATH . "EpnTapMgr.php");
4   -$EpnTapMgr = new EpnTapMgr;
5   -
6   -$registryURL = "http://dc.zah.uni-heidelberg.de/tap";
7   -// $registryURL = "http://gavo.aip.de/tap";
8   -// $registryURL = "http://reg.g-vo.org/tap";
9   -$columns = ['short_name', 'res_title', 'ivoid', 'access_url', 'table_name', 'content_type', 'creator_seq', 'content_level', 'reference_url', 'created', 'updated'];
10   -
11   -$getServicesQuery = "SELECT DISTINCT " . implode(', ', $columns) . " FROM rr.resource
12   - NATURAL JOIN rr.res_schema NATURAL JOIN rr.res_table NATURAL JOIN rr.interface NATURAL JOIN rr.res_detail NATURAL JOIN rr.capability
13   - WHERE standard_id='ivo://ivoa.net/std/tap' AND intf_type='vs:paramhttp' AND detail_xpath='/capability/dataModel/@ivo-id'
14   - AND 1=ivo_nocasematch(detail_value, 'ivo://vopdc.obspm/std/EpnCore%') AND table_name LIKE '%.epn_core' ORDER BY short_name, table_name";
15   -
16   -$services = $EpnTapMgr->request($registryURL, $getServicesQuery);
17   -
18   -$services_info = array();
19   -
20   -foreach($services as $service) {
21   - $service_id = str_replace(['ivo://', '.epn_core'], '', $service['ivoid'] . '/' . $service['table_name']);
22   -
23   - $query = "SELECT dataproduct_type as dp_type,
24   - target_class as t_class,
25   - target_name as t_name,
26   - COUNT(granule_uid) as nb_res,
27   - MIN(time_min) as time_min,
28   - MAX(time_max) as time_max
29   - FROM " . $service['table_name'] . " GROUP BY dp_type, t_class, t_name";
30   -
31   - $result = $EpnTapMgr->request($service['access_url'], $query);
32   - if(! array_key_exists("error", $result)) {
33   - $service['content'] = array_map('format_result', $result);
34   - // TODO: expected format: ["pr", "planet", "Mars", "spicam", 1232, "13/01/2004", "10/04/2006"]
35   - }
36   - $services_info[$service_id] = $service;
37   -}
38   -
39   -$servicesJsonFile = fopen(EpnTapDataPath . "new_services.json", "w");
40   -fwrite($servicesJsonFile, json_encode(array('services' => $services_info), JSON_PARTIAL_OUTPUT_ON_ERROR));
41   -fclose($servicesJsonFile);
42   -
43   -$json_error = json_last_error();
44   -if($json_error != 0) {
45   - print("json error: " . $json_error);
46   -}
47   -
48   -function format_result($result) {
49   - global $EpnTapMgr;
50   - return Array($result['dp_type'], $result['t_class'], $result['t_name'], $result['nb_res'], $EpnTapMgr->JDTodate($result['time_min']), $EpnTapMgr->JDTodate($result['time_max']));
51   -}
52   -?>
php/update_metadata.php 0 → 100755
... ... @@ -0,0 +1,44 @@
  1 +<?php
  2 +include(realpath(dirname(__FILE__) . "/config.php"));
  3 +include(CLASSPATH . "EpnTapMgr.php");
  4 +$metadata_json_path = EpnTapDataPath . "metadata.json";
  5 +$EpnTapMgr = new EpnTapMgr;
  6 +
  7 +$services = $EpnTapMgr->getServices();
  8 +if(array_key_exists('error', $services)) {
  9 + error_log('Can not get services: ' . $services['error']);
  10 + exit(1);
  11 +}
  12 +
  13 +$metadata = Array();
  14 +foreach($services as $service) {
  15 +
  16 + $query = "SELECT dataproduct_type as dp_type,
  17 + target_class as t_class,
  18 + target_name as t_name,
  19 + COUNT(granule_uid) as nb_res,
  20 + MIN(time_min) as time_min,
  21 + MAX(time_max) as time_max
  22 + FROM " . $service['table_name'] . " GROUP BY dp_type, t_class, t_name";
  23 +
  24 + $service_results = $EpnTapMgr->request($service['access_url'], $query);
  25 + if(! array_key_exists('error', $service_results)) {
  26 + $current_service_id = $EpnTapMgr->generateServiceId($service);
  27 + $metadata = $metadata + array_map('format_metadata', $service_results);
  28 + }
  29 +}
  30 +
  31 +$servicesJsonFile = fopen($metadata_json_path, "w");
  32 +fwrite($servicesJsonFile, json_encode($metadata, JSON_PARTIAL_OUTPUT_ON_ERROR));
  33 +fclose($servicesJsonFile);
  34 +
  35 +$json_error = json_last_error();
  36 +if($json_error != 0) {
  37 + error_log("json error: " . $json_error);
  38 +}
  39 +
  40 +function format_metadata($serv) {
  41 + global $EpnTapMgr, $current_service_id;
  42 + return Array($serv['dp_type'], $serv['t_class'], $serv['t_name'], $current_service_id, $serv['nb_res'], $EpnTapMgr->JDTodate($serv['time_min']), $EpnTapMgr->JDTodate($serv['time_max']));
  43 +}
  44 +?>
... ...