Commit 0475d3cb932a792d6339e0ab486f6e8d11ee784c
1 parent
f82d19f1
Exists in
master
and in
112 other branches
Remove EpnTapMgr, now useless
Showing
1 changed file
with
0 additions
and
92 deletions
Show diff stats
php/classes/EpnTapMgr.php deleted
@@ -1,92 +0,0 @@ | @@ -1,92 +0,0 @@ | ||
1 | -<?php | ||
2 | -/** @class EpnTapMgr | ||
3 | -* @brief Manager to communicates with EPN-TAP services. | ||
4 | -*/ | ||
5 | - | ||
6 | -class EpnTapMgr { | ||
7 | - private $logEpnTap; | ||
8 | - | ||
9 | - private function dateToJD($gregorian_date) { | ||
10 | - list($day, $month, $year, $hours, $minutes, $seconds) = preg_split('/[\s\/:]+/', $gregorian_date); | ||
11 | - return GregorianToJD($month, $day, $year) + $hours/24 + $minutes/(24*60) + $seconds/(24*60*60); | ||
12 | - } | ||
13 | - | ||
14 | - public function JDTodate($jd) { | ||
15 | - if(!is_numeric($jd)) { | ||
16 | - return ''; | ||
17 | - } | ||
18 | - list($month, $day, $year) = preg_split('/[\s\/:]+/', JDToGregorian(intval($jd))); | ||
19 | - $date = sprintf('%04d', $year) . '/' . sprintf('%02d', $month) . '/' . sprintf('%02d', $day); | ||
20 | - return ($date == '0000/00/00') ? '' : $date; | ||
21 | - } | ||
22 | - | ||
23 | - public function createFilter($targetName, $productTypes, $timeMin, $timeMax) { | ||
24 | - $filter = array(); | ||
25 | - if($targetName) { | ||
26 | - array_push($filter, "target_name = '$targetName'"); | ||
27 | - } | ||
28 | - if($productTypes) { | ||
29 | - array_push($filter, "dataproduct_type IN ('" . join("', '", $productTypes) . "')"); | ||
30 | - } | ||
31 | - if($timeMin) { | ||
32 | - array_push($filter, "time_min >= " . $this->dateToJD($timeMin)); | ||
33 | - } | ||
34 | - if($timeMax) { | ||
35 | - array_push($filter, "time_max <= " . $this->dateToJD($timeMax)); | ||
36 | - } | ||
37 | - return (count($filter) > 0 ? ' WHERE ' . join(' AND ', $filter) : ''); | ||
38 | - } | ||
39 | - | ||
40 | - public function request($access_url, $query) { | ||
41 | - $votMgr = new VOTableMgr; | ||
42 | - $params = 'FORMAT=votable&LANG=ADQL&REQUEST=doQuery'; | ||
43 | - $url = $access_url . '/sync?' . $params . '&QUERY=' . urlencode(preg_replace('/\s+/', ' ', $query)); // remove also multiple whitespaces | ||
44 | - | ||
45 | - $votMgr->load($url); | ||
46 | - | ||
47 | - $result = $votMgr->parseStream(); | ||
48 | - return $votMgr->getVotableError() ? array('error' => $votMgr->getVotableError()) : $result; | ||
49 | - } | ||
50 | - | ||
51 | - /* filter order: product type, target name, time min, time max */ | ||
52 | - public function getGranules($table_name, $access_url, $filter, $limit, $offset) { | ||
53 | - | ||
54 | - $query = "SELECT TOP {$limit} * FROM {$table_name} " . $this->createFilter($filter[0], $filter[1], $filter[2], $filter[3]) . " OFFSET {$offset}"; | ||
55 | - $result = $this->request($access_url, $query); | ||
56 | - | ||
57 | - $result_path = EpnTapDataPath . "test_result.json"; | ||
58 | - $servicesJsonFile = fopen($result_path, "w"); | ||
59 | - | ||
60 | - if(array_key_exists("error", $result)) { | ||
61 | - return $result; | ||
62 | - } | ||
63 | - | ||
64 | - $non_empty_values = Array(); | ||
65 | - for ($i = 0 ; $i < count($result) ; $i++) { | ||
66 | - $result[$i]['num'] = $i + $offset + 1; | ||
67 | - $result[$i]['time_min'] = $this->JDTodate($result[$i]['time_min']); | ||
68 | - $result[$i]['time_max'] = $this->JDTodate($result[$i]['time_max']); | ||
69 | - | ||
70 | - foreach($result[$i] as $key => $value) { | ||
71 | - $non_empty_values[$key] = (array_key_exists($key, $non_empty_values) ? $non_empty_values[$key] : False) || $value === '' || $value === 'NAN'; | ||
72 | - } | ||
73 | - } | ||
74 | - | ||
75 | - $non_null_cols = array_keys(array_filter($non_empty_values)); | ||
76 | - for ($i = 0 ; $i < count($result) ; $i++) { | ||
77 | - $result[$i] = array_diff_key($result[$i], array_flip($non_null_cols)); | ||
78 | - } | ||
79 | - // error_log('Query result: ' . json_encode($result)); | ||
80 | - return $result; | ||
81 | - } | ||
82 | - | ||
83 | - public function getNbResults($url, $tableName, $targetName, $productTypes, $timeMin, $timeMax) { | ||
84 | - $query = "SELECT COUNT(*) AS nb_rows FROM $tableName" . $this->createFilter($targetName, $productTypes, $timeMin, $timeMax); | ||
85 | - // error_log('Query: ' . $query); | ||
86 | - $result = $this->request($url, $query)[0]['nb_rows']; | ||
87 | - // error_log('Query result: ' . json_encode($result)); | ||
88 | - return $result; | ||
89 | - } | ||
90 | - | ||
91 | -} | ||
92 | -?> |