-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstat.php
More file actions
136 lines (121 loc) · 4.45 KB
/
stat.php
File metadata and controls
136 lines (121 loc) · 4.45 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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<html>
<head>
<style>
table {border-collapse: collapse}
td { border:solid 1px grey}
</style>
</head>
<body>
<?php
error_reporting( E_ALL );
function getindexedrecords(){
$json='{
"size": 0,
"aggs": {
"dataCenterStats": {
"terms": {
"field": "dataCenterFacet",
"size": 64
}
}
}
}';
$url='https://ws.pangaea.de/es/dataportal-gfbio/pansimple/_search';
$options = array(
'http' => array(
'method' => 'POST',
'content' => $json,
'header'=> "Content-Type: application/json\r\n" .
"Accept: application/json\r\n"
)
);
$context = stream_context_create( $options );
$result = file_get_contents( $url, false, $context );
$response = json_decode( $result );
$buckets=$response->aggregations->dataCenterStats->buckets;
foreach($buckets as $bucket){
$noindexed[$bucket->key]=$bucket->doc_count;
}
return $noindexed;
}
$touched=false;
if(isset($_GET['dsa'])){
$dsa=$_GET['dsa'];
}
if(isset($_GET['deldsa'])){
$deldsa=$_GET['deldsa'];
}
if(isset($_GET['date'])){
$datestr=$_GET['date'];
if(strtotime($datestr)!==false){
$date=strtotime($datestr);
}else $date=time();
}else $date=time();
$stat=false;
if(isset($_GET['stat'])) $stat=true;
$abcdrootdir='ABCD';
$archivejson=json_decode(file_get_contents($abcdrootdir.'/archives.txt'));
foreach($archivejson as $aid=>$json){
if($json->dsa==$dsa){
$archivejson[$aid]->harvest_time=date('c',$date);
$archivejson[$aid]->new_archive=1;
$touched=true;
echo '<br>Touched '.$dsa.' new date for <b>'.$json->dataset.'</b> is: '.date('c',$date);
}elseif($json->dsa==$deldsa){
$archivejson[$aid]->harvest_time=date('c',$date);
$archivejson[$aid]->harvest_status='delete';
}
}
if($touched===true){
$upd=file_put_contents($abcdrootdir.'/archives.txt',json_encode($archivejson));
if($upd!==false) echo '<br>Update saved..';
else echo '<br>Update failed..';
}
$archivesinfo=json_decode(file_get_contents($abcdrootdir.'/archives.txt'),true);
$ai=1;
echo'<table style="border:1px solid grey"><tr><th></th><th>Provider</th><th>DSA</th><th>Title</th><th>Records</th><th>ZIP Date</th><th>Harvest Date</th><th>Harvest Status</th><th>No (files)</th><th></tr></tr>';
foreach($archivesinfo as $aiid=>$archive){
if($stat===true){#&&$archive['provider_datacenter']=='Data Center DSMZ'){
$abcddir=$abcdrootdir.'/'.$archive['archive_folder'];
$files = scandir($abcddir);
$archivesinfo[$aiid]['nounits']=1;
foreach($files as $file){
if(strpos($file,'.xml')){
#$xml=simplexml_load_file($file);
$xmlstr=file_get_contents($abcddir.'/'.$file);
$xml=simplexml_load_string($xmlstr);
if(sizeof($xml->children('http://www.tdwg.org/schemas/abcd/2.06')->DataSet)>0){
$dataset=$xml->children('http://www.tdwg.org/schemas/abcd/2.06');
}
else{
$dataset=$xml->children('http://www.tdwg.org/schemas/abcd/2.1');
}
$archivesinfo[$aiid]['nounits']+=sizeof($dataset->DataSet->Units->Unit);
if(isset($nounits[$archive['provider_datacenter']]))
$nounits[$archive['provider_datacenter']]+=sizeof($dataset->DataSet->Units->Unit);
else
$nounits[$archive['provider_datacenter']]=sizeof($dataset->DataSet->Units->Unit)+1;
}
}
}
echo'<tr><td>'.$ai.'</td><td>'.$archive['provider_datacenter'].'</td><td>'.$archive['archive_folder'].'</td><td>'.$archive['dataset'].'</td><td>'.$archive['nounits'].'</td><td>'.substr($archive['zip_time'],0,10).
'</td><td>'.substr($archive['harvest_time'],0,10).'</td><td>'.$archive['harvest_status'].'</td><td>'.$archive['file_number'].'</td><td><a href="?dsa='.$archive['dsa'].'">touch</a></td></tr>';
$ai++;
}
echo'</table>';
$noindexed=getindexedrecords();
if($stat===true){
echo 'saving..';
echo file_put_contents($abcdrootdir.'/archives.txt',json_encode($archivesinfo));
echo ' bytes..';
echo'<br><table><tr><th>datacenter</th><th>No (units)</th><th>No (indexed records)</th></tr>';
foreach($nounits as $arch=>$nounit){
echo'<tr><td>'.$arch.'</td><td>'.$nounit.'</td><td>';
foreach($noindexed as $inarch=>$innounit)
if($inarch==$arch) echo $innounit;
echo'</td></tr>';
}
echo'</table>';
}
?>
</body>