Commit 0dbe384469f406e9ac32590a288cfca824f284e4

Authored by Hacene SI HADJ MOHAND
2 parents 18df425f 6d5299c8

merge with remote

js/app/views/PlotComponents/PlotBaseSerieForm.js
... ... @@ -104,8 +104,8 @@ Ext.define('amdaPlotComp.PlotBaseSerieForm', {
104 104 this.addStandardFieldSet('Lines', 'serie-lines-activated', this.addStandardLineItems('serie-lines')),
105 105 this.addStandardFieldSet('Symbols', 'serie-symbols-activated', this.addStandardSymbolsItems('serie-symbols')),
106 106 this.addStandardFieldSet('Time ticks', 'serie-timetick-activated', this.getTimeTickItems()),
107   - this.addStandardFieldSet('Interval ticks', 'serie-intervaltick-activated', this.getIntervalTickItems()),
108   - this.addStandardFieldSet('Spike Filtering', 'filtering-activated', this.getFilteringItems())
  107 + this.addStandardFieldSet('Interval ticks', 'serie-intervaltick-activated', this.getIntervalTickItems()),
  108 + this.addStandardFieldSet('Spike Filtering ( ! Experimental ! )', 'filtering-activated', this.getFilteringItems())
109 109 ];
110 110 }
111 111 });
... ...
js/app/views/PlotComponents/PlotSpectroForm.js
... ... @@ -43,13 +43,13 @@ Ext.define('amdaPlotComp.PlotSpectroForm', {
43 43 this.addStandardCheck('spectro-log0-as-min', 'Show 0 values as Min Values in log scale', function(name, value, oldValue) {
44 44 me.object.set('spectro-log0-as-min', value);
45 45 }),
46   - this.addStandardCombo('spectro-normalization', 'Normalization', amdaPlotObj.PlotObjectConfig.availableSpectroNormalization, function(name, value, oldValue) {
  46 + this.addStandardCombo('spectro-normalization', 'Normalization', amdaPlotObj.PlotObjectConfig.availableSpectroNormalization, function(name, value, oldValue) {
47 47 if (me.object.get('spectro-normalization') != value)
48 48 {
49 49 me.object.set('spectro-normalization', value);
50 50 }
51 51 }),
52   - this.addStandardFieldSet('Spike Filtering', 'filtering-activated', this.getFilteringItems())
  52 + this.addStandardFieldSet('Spike Filtering ( ! Experimental ! )', 'filtering-activated', this.getFilteringItems())
53 53 ];
54 54 }
55 55 });
... ...
php/classes/AmdaStats.php
... ... @@ -6,8 +6,8 @@
6 6  
7 7 class AmdaStats {
8 8  
9   - public $statXml;
10   - public $tasks = array('plot', 'mining', 'print', 'statistic');
  9 + public $statsFilePath;
  10 + public $tasks = array('plot', 'mining', 'print', 'statistics');
11 11 public $tasksWs = array('ws_print', 'ws_plot');
12 12 public $tasksAdd = array('ttoper', 'samp', 'upload', 'create', 'images');
13 13 public $usersToExclude = array('bouchemit');
... ... @@ -17,92 +17,139 @@ class AmdaStats {
17 17 'getparameter'=>'ws_print', 'getdataset' => 'ws_print', 'getorbites' => 'ws_print', 'getplot' => 'ws_plot');
18 18  
19 19 public function __construct($user) {
20   -
21   - $this->statXml = new DomDocument('1.0','UTF-8');
22   - $this->statXml->preserveWhiteSpace = false;
23   - $this->statXml->formatOutput = true;
24   -
25   - if (!defined("StatsXml")){
26   - $thisYear = date("Y");
27   - if (!$user){
28   - // general - to read
29   - // define('StatsXml',DATAPATH.'Statistics/Stats.xml');
30   - define("StatsXml",DATAPATH."Statistics/Stats$thisYear.xml");
31   - // if (file_exists(StatsXml)) unlink(StatsXml);
32   - }
33   - else {
34   - // individual - to write
35   - // define("StatsXml", USERPATH."/".$user."/Stats.xml");
36   - define("StatsXml", USERPATH.$user."/Stats$thisYear.xml");
37   - $this->user = $user;
38   - }
  20 + if (!is_dir(DATAPATH.'Statistics')) {
  21 + if (!mkdir(DATAPATH.'Statistics', 0775)) $this->success = false; //return -1;
  22 + if (!chgrp(DATAPATH.'Statistics', APACHE_USER)) $this->success = false; // return -1;
39 23 }
40 24  
41   - if (!file_exists(StatsXml)) {
42   - if (!is_dir(DATAPATH.'Statistics')) {
43   - if (!mkdir(DATAPATH.'Statistics', 0775)) $this->success = false; //return -1;
44   - if (!chgrp(DATAPATH.'Statistics', APACHE_USER)) $this->success = false; // return -1;
45   - }
  25 + $this->statsFilePath = $this->getStatsFilePath($user);
  26 + }
46 27  
47   - $status = $this->generateXml();
48   - if (!$status) {
49   - error_log('Cannot create Stats.xml: Fatal Error '.$user,1,email);
50   - $this->success = false;
51   - }
  28 + public function addTask($user, $task, $vars) {
  29 + $this->concurrentAccessGuestFile(array($this,'_addTask'),array('user' => $user, 'task' => $task, 'vars' => $vars));
  30 + }
  31 +
  32 + public function getModulesStat($start, $stop, $update) {
  33 + return $this->concurrentAccessGuestFile(array($this,'_getModulesStat'), array('start' => $start, 'stop' => $stop, 'update' => $update));
  34 + }
  35 +
  36 + public function mergeXml($year) {
  37 + return $this->concurrentAccessGuestFile(array($this,'_mergeXml'), array('year' => $year));
  38 + }
  39 +
  40 + public function getDataStat($index, $start, $stop, $update) {
  41 + return $this->concurrentAccessGuestFile(array($this,'_getDataStat'), array('index' => $index, 'start', $start, 'stop' => $stop, 'update' => $update));
  42 + }
  43 +
  44 + public function mergeStats($inXml) {
  45 + return $this->concurrentAccessGuestFile(array($this,'_mergeStats'), array('inXml' => $inXml));
  46 + }
  47 +
  48 + private function getStatsFilePath($user) {
  49 + $thisYear = date("Y");
  50 + if (empty($user)){
  51 + return DATAPATH."Statistics/Stats$thisYear.xml";
52 52 }
53   - else {
54   - $status = $this->statXml->load(StatsXml);
55   - if (!$status) {
56   - $status = $this->generateXml();
57   - $msg = $status ? 'Cannot load Stats.xml. New Stats.xml was created' :
58   - 'Cannot load Stats.xml. Cannot create Stats.xml: Fatal Error ';
59   -
60   - error_log($msg.$user,1,email);
61   -
62   - if (!$status)
63   - $this->success = false;
  53 + return USERPATH.$user."/Stats$thisYear.xml";
  54 + }
  55 +
  56 + private function concurrentAccessGuestFile($callback, $options) {
  57 + $lockFile = $this->statsFilePath.".lockfile";
  58 +
  59 + $fp = fopen($lockFile, "w+");
  60 +
  61 + if ($fp === false) {
  62 + return false;
  63 + }
  64 +
  65 + $res = true;
  66 +
  67 + if (flock($fp, LOCK_EX))
  68 + {
  69 + $newFile = FALSE;
  70 + if (!file_exists($this->statsFilePath)) {
  71 + $res = $this->_generateXml();
64 72 }
65   - else {
66   - $allTasks = array_merge($this->tasks, $this->tasksAdd, $this->tasksWs);
67   - $newTask = FALSE;
68   - foreach ($allTasks as $task) {
69   - $items = $this->statXml->getElementsByTagName($task);
70   - if ($items->length == 0) {
71   - //add missing task
72   - $element = $this->statXml->createElement("$task");
73   - $this->statXml->documentElement->appendChild($element);
74   - $newTask = TRUE;
  73 +
  74 + if ($res) {
  75 + $dom = new DomDocument("1.0","UTF-8");
  76 + $dom->preserveWhiteSpace = false;
  77 + $dom->formatOutput = true;
  78 + $res = $dom->load($this->statsFilePath);
  79 + if (!$newFile) {
  80 + // add missing tasks if needed
  81 + $allTasks = array_merge($this->tasks, $this->tasksAdd, $this->tasksWs);
  82 + $newTask = FALSE;
  83 + foreach ($allTasks as $task) {
  84 + $items = $dom->getElementsByTagName($task);
  85 + if ($items->length == 0) {
  86 + //add missing task
  87 + $element = $dom->createElement("$task");
  88 + $dom->documentElement->appendChild($element);
  89 + $newTask = TRUE;
  90 + }
75 91 }
  92 + if ($newTask) {
  93 + $dom->save($this->statsFilePath);
  94 + }
76 95 }
77   - if ($newTask) {
78   - $this->statXml->save(StatsXml);
  96 + if ($res) {
  97 + $func_res = call_user_func($callback,$dom, $options);
79 98 }
80 99 }
81   - }
  100 + }
  101 + else
  102 + $res = false;
  103 +
  104 + fclose($fp);
  105 +
  106 + if ($res)
  107 + return $func_res;
  108 +
  109 + return false;
  110 + }
  111 +
  112 + private function _generateXml() {
  113 + $dom = new DomDocument("1.0","UTF-8");
  114 + $dom->preserveWhiteSpace = false;
  115 + $dom->formatOutput = true;
  116 +
  117 + $rootElement = $dom->createElement('stats');
  118 +
  119 + $allTasks = array_merge($this->tasks, $this->tasksAdd, $this->tasksWs);
  120 +
  121 + foreach ($allTasks as $task) {
  122 + $element = $dom->createElement("$task");
  123 + $rootElement->appendChild($element);
  124 + }
  125 +
  126 + $dom->appendChild($rootElement);
  127 +
  128 + return $dom->save($this->statsFilePath);
82 129 }
83 130  
84 131 /*
85 132 * Merge individual User Stats.xml into one generique Stats.xml
86 133 */
87   - public function mergeXml($year) {
  134 + private function _mergeXml($dom, $options) {
88 135 // long procedure
89 136 ini_set('max_execution_time', 600);
90 137  
91 138 $allTasks = array_merge($this->tasks, $this->tasksAdd, $this->tasksWs);
92 139  
93 140 $userDoc = new DomDocument("1.0");
94   - if ($year == null) $year = date("Y");
  141 + if ($options['year'] == null) $options['year'] = date("Y");
95 142  
96 143 $users=glob(USERPATH."*");
97 144 foreach ($users as $user) {
98   - $userXmlPath = $user."/Stats$year.xml";
  145 + $userXmlPath = $user."/Stats".$options['year'].".xml";
99 146  
100 147 if (!file_exists($userXmlPath)) continue;
101 148  
102 149 $userDoc->load($userXmlPath);
103 150  
104 151 foreach ($allTasks as $task) {
105   - $globalTaskItems = $this->statXml->getElementsByTagName($task);
  152 + $globalTaskItems = $dom->getElementsByTagName($task);
106 153 if ($globalTaskItems->length == 0)
107 154 continue;
108 155 $globalTaskItem = $globalTaskItems->item(0);
... ... @@ -113,7 +160,7 @@ class AmdaStats {
113 160 $userItems = $userTaskItem->getElementsByTagName("item");
114 161 if ($userItems->length > 0) {
115 162 foreach ($userItems as $userItem) {
116   - $globalItem = $this->statXml->importNode($userItem, true);
  163 + $globalItem = $dom->importNode($userItem, true);
117 164 $globalTaskItem->appendChild($globalItem);
118 165 }
119 166 }
... ... @@ -121,98 +168,79 @@ class AmdaStats {
121 168 }
122 169  
123 170 // write task statistics as json
124   - $this->getModulesStat(null,null,true);
  171 + $this->_getModulesStat($dom, array('start' => null, 'stop' => null, 'update' => TRUE));
125 172 // write data statistics as json
126   - $this->getDataStat(0,null,null,true);
  173 + $this->_getDataStat($dom, array('index' => 0, 'start', null, 'stop' => null, 'update' => true));
127 174  
128   - return $this->statXml->save(StatsXml);
  175 + return $dom->save($this->statsFilePath);
129 176 }
130 177  
131   - private function generateXml() {
132   -
133   - $rootElement = $this->statXml->createElement('stats');
134   -
135   - $allTasks = array_merge($this->tasks, $this->tasksAdd, $this->tasksWs);
136   -
137   - foreach ($allTasks as $task) {
138   - $element = $this->statXml->createElement("$task");
139   - $rootElement->appendChild($element);
140   - }
141   -
142   - $this->statXml->appendChild($rootElement);
143   -
144   - return $this->statXml->save(StatsXml);
145   - }
146   -
147   - public function addTask($user, $task, $vars) {
148   -
149   -// if (!$this->user) {
150   -// error_log('User is null', 1, email);
151   -// return;
152   -// }
153   - if ($task == 'killplot')
154   - return;
  178 + private function _addTask($dom, $options) {
  179 + if ($options['task'] == 'killplot')
  180 + return FALSE;
155 181  
156   - if ($vars)
157   - $realTask = $this->task[$task];
  182 + if ($options['vars'])
  183 + $realTask = $this->task[$options['task']];
158 184 else
159   - $realTask = $task;
  185 + $realTask = $options['task'];
160 186  
161   - if (!in_array($user, $this->usersToExclude)) {
162   - $taskElementNode = $this->statXml->getElementsByTagName("$realTask");
  187 + if (!in_array($options['user'], $this->usersToExclude)) {
  188 + $taskElementNode = $dom->getElementsByTagName("$realTask");
163 189  
164 190 if ($taskElementNode->length < 1)
165 191 return;
166 192  
167 193 $taskElement = $taskElementNode->item(0);
168 194 if (is_object($taskElement)) {
169   - $newTask = $this->statXml->createElement('item');
  195 + $newTask = $dom->createElement('item');
170 196 $newTask->setAttribute('date', date('Y-m-d'));
171   - $newTask->setAttribute('user', $user);
  197 + $newTask->setAttribute('user', $options['user']);
172 198  
173   - if ($vars) {
  199 + if ($options['vars']) {
174 200 $ID = array();
175 201  
176   - foreach ($vars as $var) {
  202 + foreach ($options['vars'] as $var) {
177 203 $ID[] = $var;
178 204 }
179 205  
180 206 $ID = array_unique($ID);
181 207  
182 208 foreach ($ID as $id) {
183   - $datasetElement = $this->statXml->createElement('dataset', $id);
  209 + $datasetElement = $dom->createElement('dataset', $id);
184 210 $newTask->appendChild($datasetElement);
185 211 }
186 212 }
187 213  
188 214 $taskElement->appendChild($newTask);
189   - $this->statXml->save(StatsXml);
  215 + return $dom->save($this->statsFilePath);
190 216 }
191 217 else
192   - error_log('Check Stats.xml - no task element '.$task, 1, email);
  218 + error_log('Check Stats.xml - no task element '.$options['task'], 1, email);
193 219 }
  220 +
  221 + return FALSE;
194 222 }
195 223  
196 224 /*
197 225 * Show Statistics
198 226 */
199   - public function getModulesStat($start, $stop, $update){
  227 + private function _getModulesStat($dom, $options){
200 228  
201   - if (!$update && file_exists(DATAPATH.'Statistics/tasks.json')) {
202   - return file_get_contents(DATAPATH.'Statistics/tasks.json');
  229 + if (!$options['update'] && file_exists(DATAPATH.'Statistics/tasks.json')) {
  230 + return file_get_contents(DATAPATH.'Statistics/tasks.json');
203 231 }
204 232  
205 233 $taskArray = array();
206 234  
207 235 foreach (array_merge($this->tasks,$this->tasksAdd, $this->tasksWs) as $task) {
208   - $taskItems = $this->statXml->getElementsByTagName($task);
  236 + $taskItems = $dom->getElementsByTagName($task);
209 237 if ($taskItems->length < 1)
210 238 return;
211 239 $theTask = $taskItems->item(0);
212 240 $items = $theTask->getElementsByTagName('item');
213 241 $hints = $items->length;
214 242  
215   - $startStop = $this->getStartStop($items, $start, $stop);
  243 + $startStop = $this->getStartStop($items, $options['start'], $options['stop']);
216 244  
217 245 $taskArray[] = array('task' => $task, 'number' => $hints,
218 246 'start' => $startStop[0], 'stop' => $startStop[1]);
... ... @@ -228,9 +256,9 @@ class AmdaStats {
228 256 /*
229 257 * Show Statistics
230 258 */
231   - public function getDataStat($index, $start, $stop, $update){
  259 + private function _getDataStat($dom, $options){
232 260  
233   - if (!$update && file_exists(DATAPATH.'Statistics/data.json')) {
  261 + if (!$options['update'] && file_exists(DATAPATH.'Statistics/data.json')) {
234 262 $GENERALarray = json_decode(file_get_contents(DATAPATH.'Statistics/data.json'));
235 263 }
236 264 else {
... ... @@ -243,7 +271,7 @@ class AmdaStats {
243 271 $dataTasks = array_merge($this->tasks, $this->tasksWs);
244 272  
245 273 foreach ($dataTasks as $task) {
246   - $taskItems = $this->statXml->getElementsByTagName($task);
  274 + $taskItems = $dom->getElementsByTagName($task);
247 275 if ($taskItems->length < 1)
248 276 continue;
249 277 $theTask = $taskItems->item(0);
... ... @@ -258,10 +286,15 @@ class AmdaStats {
258 286 foreach ($VIs as $VI) {
259 287 $id = $VI->nodeValue;
260 288 if ($id) {
261   -
  289 + if (!in_array($id, $usersArray)) {
  290 + $usersArray[$id] = array();
  291 + }
  292 + if (!in_array($user, $usersArray[$id])) {
  293 + $usersArray[$id][$user] = 0;
  294 + }
262 295 $usersArray[$id][$user]++;
263 296  
264   - if ($TASKarray[$id]) {
  297 + if (array_key_exists($id, $TASKarray)) {
265 298 $TASKarray[$id]++;
266 299 $TOTALarray[$id]++;
267 300 if ($STARTarray[$id] > $time)
... ... @@ -270,7 +303,7 @@ class AmdaStats {
270 303 $STOParray[$id] = $time;
271 304 }
272 305 else {
273   - if (!$TOTALarray[$id]) {
  306 + if (!array_key_exists($id,$TOTALarray)) {
274 307 $STARTarray[$id] = $time;
275 308 $STOParray[$id] = $time;
276 309 $TOTALarray[$id] = 1;
... ... @@ -298,17 +331,20 @@ class AmdaStats {
298 331 foreach ($TOTALarray as $key => $value) {
299 332 $viStart = $STARTarray[$key];
300 333 $viStop = $STOParray[$key];
301   - $plot = $VIarray['plot'][$key];
302   - $mining = $VIarray['mining'][$key];
303   - $print = $VIarray['print'][$key];
304   - $stat = $VIarray['statistics'][$key];
  334 + $plot = (empty($VIarray['plot']) || empty($VIarray['plot'][$key])) ? 0 : $VIarray['plot'][$key];
  335 + $mining = (empty($VIarray['mining']) || empty($VIarray['mining'][$key])) ? 0 : $VIarray['mining'][$key];
  336 + $print = (empty($VIarray['print']) || empty($VIarray['print'][$key])) ? 0 : $VIarray['print'][$key];
  337 + $stat = (empty($VIarray['statistics']) || empty($VIarray['statistics'][$key])) ? 0 : $VIarray['statistics'][$key];
  338 + $ws_print = (empty($VIarray['ws_print']) || empty($VIarray['ws_print'][$key])) ? 0 : $VIarray['ws_print'][$key];
  339 + $ws_plot = (empty($VIarray['ws_plot']) || empty($VIarray['ws_plot'][$key])) ? 0 : $VIarray['ws_plot'][$key];
305 340 $uniqueUsers = count($usersArray[$key]);
306 341  
307 342 if ($key != 'undefined')
308 343 {
309 344 $GENERALarray[] = array('id' => $key, 'number' => $value, 'percent' => $value,
310 345 'plot' => $plot, 'mining' => $mining,
311   - 'print' => $print,'statistics' => $stat,
  346 + 'print' => $print,'statistics' => $stat,
  347 + 'ws_print' => $ws_print, 'ws_plot' => $ws_plot,
312 348 'start' => $viStart, 'stop' => $viStop, 'unique' => $uniqueUsers);
313 349  
314 350 $Ntotal += $value;
... ... @@ -325,8 +361,8 @@ class AmdaStats {
325 361  
326 362 $Nmax = count($GENERALarray);
327 363  
328   - $length = $index + 20 > $Nmax ? $Nmax - $index + 1 : 20;
329   - $objToReturn = array('stats' => array_reverse(array_slice($GENERALarray, $index, $length)));
  364 + $length = $options['index'] + 20 > $Nmax ? $Nmax - $options['index'] + 1 : 20;
  365 + $objToReturn = array('stats' => array_reverse(array_slice($GENERALarray, $options['index'], $length)));
330 366  
331 367 file_put_contents(DATAPATH.'Statistics/data.json',json_encode($GENERALarray));
332 368  
... ... @@ -355,32 +391,29 @@ class AmdaStats {
355 391 return array(min($date), max($date));
356 392 }
357 393  
358   - public function mergeStats($inXml) {
  394 + private function _mergeStats($dom, $options) {
359 395  
360   - if (!file_exists(StatsXml)) return 0;
361   - if (!file_exists($inXml)) return 0;
  396 + if (!file_exists($options['inXml'])) return 0;
362 397  
363 398 $tags = array_merge($this->tasks,$this->tasksAdd, $this->tasksWs);
364 399  
365   - $doc1 = new DomDocument("1.0");
366 400 $doc2 = new DomDocument("1.0");
367 401  
368   - if (!$doc1->load(StatsXml)) return 0;
369   - if (!$doc2->load($inXml)) return 0;
  402 + if (!$doc2->load($options['inXml'])) return 0;
370 403  
371 404 foreach ($tags as $tag){
372   - $tag1 = $doc1->getElementsByTagName($tag)->item(0);
  405 + $tag1 = $dom->getElementsByTagName($tag)->item(0);
373 406 $tag2 = $doc2->getElementsByTagName($tag)->item(0);
374 407 $items2 = $tag2->getElementsByTagName("item");
375 408 if ($items2->length > 0) {
376 409 foreach ($items2 as $item2) {
377   - $item1 = $doc1->importNode($item2, true);
  410 + $item1 = $dom->importNode($item2, true);
378 411 $tag1->appendChild($item1);
379 412 }
380 413 }
381 414 }
382 415  
383   - return $doc1->save(StatsXml);
  416 + return $dom->save($this->statsFilePath);
384 417 }
385 418 }
386 419 ?>
... ...