Commit 5177e498635aceeb6ad768a29f359fdf7fb0a076
Exists in
master
and in
72 other branches
Merge branch 'amdadev'
Showing
4 changed files
with
222 additions
and
141 deletions
Show diff stats
js/app/views/CatalogUI.js
... | ... | @@ -153,25 +153,51 @@ Ext.define('amdaUI.CatalogUI', { |
153 | 153 | var stops= []; |
154 | 154 | if (this.TTGrid.getStore().getTotalCount() <= 0) |
155 | 155 | return; |
156 | - Ext.Array.each(this.TTGrid.getStore().data.first.value, function (item, index) { | |
157 | - starts[index] = (item.raw.start); | |
158 | - stops[index] = (item.raw.stop); | |
156 | + reqObj = { | |
157 | + 'typeTT': 'catalog', | |
158 | + } | |
159 | + AmdaAction.readCacheIntervals(reqObj, function(result, e) | |
160 | + { | |
161 | + if (!result) { | |
162 | + myDesktopApp.errorMsg(e.message); | |
163 | + Ext.defer(function () { | |
164 | + Ext.Msg.toFront() | |
165 | + }, 10); | |
166 | + | |
167 | + return; | |
168 | + } else if (!result.success) | |
169 | + { | |
170 | + if (result.message) | |
171 | + myDesktopApp.errorMsg(result.message); | |
172 | + else | |
173 | + myDesktopApp.errorMsg('Unknown error during catalog survey dates update'); | |
174 | + | |
175 | + Ext.defer(function () { | |
176 | + Ext.Msg.toFront() | |
177 | + }, 10); | |
178 | + | |
179 | + return; | |
180 | + } | |
181 | + Ext.Array.each(result.intervals, function (item, index) { | |
182 | + starts[index] = (item.start); | |
183 | + stops[index] = (item.stop); | |
159 | 184 | }); |
160 | 185 | if(starts.length !== 0 || stops.length !== 0) { |
161 | 186 | |
162 | - starts.sort(); | |
163 | - stops.sort(); | |
164 | - s = new Date(starts[0]); | |
165 | - e = new Date(stops[stops.length - 1]); | |
166 | - if(! ttObj.get('surveyStart') ){ | |
187 | + starts.sort(); | |
188 | + stops.sort(); | |
189 | + s = new Date(starts[0]); | |
190 | + e = new Date(stops[stops.length - 1]); | |
191 | + if(! ttObj.get('surveyStart') ){ | |
167 | 192 | ttObj.set('surveyStart', s); |
168 | 193 | this.status.isModified = true; |
169 | - } | |
170 | - if(! ttObj.get('surveyStop') ){ | |
194 | + } | |
195 | + if(! ttObj.get('surveyStop') ){ | |
171 | 196 | ttObj.set('surveyStop', e); |
172 | 197 | this.status.isModified = true; |
198 | + } | |
173 | 199 | } |
174 | - } | |
200 | + }); | |
175 | 201 | }, |
176 | 202 | |
177 | 203 | createTT: function (catId) { |
... | ... | @@ -183,7 +209,7 @@ Ext.define('amdaUI.CatalogUI', { |
183 | 209 | descr = 'Generated by CDPP/Amda Catalog Module \n' + 'From Catalog: ' + this.object.get('name') + '\nOn: ' + date + '\n'; |
184 | 210 | ttObj.set('description', descr + this.object.get('description')); |
185 | 211 | ttObj.set('contact', this.object.get('contact')); |
186 | - this.updateSurveyDates(ttObj); | |
212 | + //this.updateSurveyDates(ttObj); | |
187 | 213 | timeTabNode.set('object', ttObj); |
188 | 214 | var explorerTree = Ext.getCmp(amdaUI.ExplorerUI.RESRC_TAB.TREE_ID); |
189 | 215 | var ttRootNode = explorerTree.getRootNode().findChild('id', 'timeTable-treeRootNode', true); |
... | ... | @@ -619,7 +645,6 @@ Ext.define('amdaUI.CatalogUI', { |
619 | 645 | loadObject: function () { |
620 | 646 | // load object into form |
621 | 647 | this.object.set('created', this.convertUTCDateToLocalDate(this.object.get('created'))); |
622 | - this.updateSurveyDates(this.object); | |
623 | 648 | this.formPanel.getForm().loadRecord(this.object); |
624 | 649 | |
625 | 650 | this.status = null; |
... | ... | @@ -721,7 +746,7 @@ Ext.define('amdaUI.CatalogUI', { |
721 | 746 | if (this.TTGrid.getStore().getTotalCount() > 0) |
722 | 747 | { |
723 | 748 | // update TimeTable object which the content of form |
724 | - this.updateSurveyDates(this.object); | |
749 | + | |
725 | 750 | basicForm.updateRecord(this.object); |
726 | 751 | var me = this; |
727 | 752 | this.checkIntervalsStatusForSave(function () { | ... | ... |
php/classes/AmdaAction.php
... | ... | @@ -255,6 +255,10 @@ class AmdaAction |
255 | 255 | else |
256 | 256 | $info = $units; |
257 | 257 | } |
258 | + else { | |
259 | + if ($child->hasAttribute('description')) | |
260 | + $info = $child->getAttribute('description'); | |
261 | + } | |
258 | 262 | |
259 | 263 | if ($child->tagName == 'parameter') { |
260 | 264 | $isParameter = true; | ... | ... |
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 | ?> | ... | ... |
php/classes/TimeTableMgr.php
... | ... | @@ -87,10 +87,29 @@ class TimeTableMgr extends AmdaObjectMgr |
87 | 87 | if ($attribute->tagName != 'intervals') { |
88 | 88 | $attributesToReturn[$attribute->tagName] = $attribute->nodeValue; |
89 | 89 | } else { |
90 | - $nbInt++; | |
90 | + | |
91 | + // get 'surveyStart' and | |
92 | + if($attributesToReturn['surveyStart'] == "" || $attributesToReturn['surveyStop'] == "" ){ | |
93 | + if($nbInt == 0){ | |
94 | + foreach ($attribute->childNodes as $ch ){ | |
95 | + if($ch->tagName == 'start') $start = $ch->nodeValue; | |
96 | + if($ch->tagName == 'stop') $stop = $ch->nodeValue; | |
97 | + } | |
98 | + }else{ | |
99 | + foreach ($attribute->childNodes as $ch ){ | |
100 | + if($ch->tagName == 'start' && $start > $ch->nodeValue) $start = $ch->nodeValue; | |
101 | + if($ch->tagName == 'stop' && $stop < $ch->nodeValue) $stop = $ch->nodeValue; | |
102 | + } | |
103 | + } | |
104 | + } | |
105 | + $nbInt++; | |
91 | 106 | } |
92 | 107 | } |
93 | 108 | } |
109 | + if($attributesToReturn['surveyStart'] == "") | |
110 | + $attributesToReturn['surveyStart'] = $start; | |
111 | + if($attributesToReturn['surveyStop'] == "" ) | |
112 | + $attributesToReturn['surveyStop'] = $stop; | |
94 | 113 | $attributesToReturn['nbIntervals'] = $nbInt; |
95 | 114 | |
96 | 115 | return $attributesToReturn; | ... | ... |