MCPcopy Create free account
hub / github.com/Rello/analytics / read

Method read

lib/Controller/DatasourceController.php:273–381  ·  view source on GitHub ↗

* Get the data from a data source; * * @param int $datasourceId * @param $datasetMetadata * @param bool $allowCacheValidation * @return array|NotFoundException */

(int $datasourceId, $datasetMetadata, bool $allowCacheValidation = true)

Source from the content-addressed store, hash-verified

271 * @return array|NotFoundException
272 */
273 #[NoAdminRequired]
274 public function read(int $datasourceId, $datasetMetadata, bool $allowCacheValidation = true) {
275 if (!$this->getDatasources()[$datasourceId]) {
276 $result['error'] = $this->l10n->t('Data source not available anymore');
277 return $result;
278 }
279
280 $option = array();
281 // before 3.1.0, the options were in another format. as of 3.1.0 the standard option array is used
282 if ($datasetMetadata['link'][0] !== '{') {
283 $option['link'] = $datasetMetadata['link'];
284 } else {
285 $option = json_decode($datasetMetadata['link'], true);
286 }
287 unset($option['cacheKey']);
288 $option['user_id'] = $datasetMetadata['user_id'];
289 if (isset($option['link']) && in_array($datasourceId, [
290 self::DATASET_TYPE_LOCAL_CSV,
291 self::DATASET_TYPE_LOCAL_SPREADSHEET,
292 self::DATASET_TYPE_LOCAL_JSON,
293 ], true)) {
294 $option['link'] = $this->VariableService->replaceDatasourceText((string)$option['link']);
295 }
296 if ($allowCacheValidation && isset($datasetMetadata['cacheKey']) && $datasetMetadata['cacheKey'] !== '') {
297 $option['cacheKey'] = $datasetMetadata['cacheKey'];
298 }
299
300 try {
301 // read the data from the source
302 $result = $this->getDatasources()[$datasourceId]->readData($option);
303 if (isset($result['cache']['notModified']) && $result['cache']['notModified'] === true) {
304 return $result;
305 }
306
307 // if data source should be timestamped/snapshoted
308 if (isset($option['timestamp']) && ($option['timestamp'] === 'true' || $option['timestamp'] === 'filename')) {
309 $timestamp = $this->getDatasourceTimestamp($option);
310 if ($timestamp === null) {
311 return [
312 'error' => $this->l10n->t('No valid timestamp found in datasource filename'),
313 'data' => [],
314 'status' => 'nodata',
315 ];
316 }
317
318 $result['data'] = array_map(function ($tag) use ($timestamp) {
319 $columns = count($tag);
320 if ($columns > 1) {
321 // shift values by one dimension and stores date in second column
322 return array($tag[$columns - 2], $timestamp, $tag[$columns - 1]);
323 } else {
324 // just return 2 columns if the original data only has one column
325 return array($timestamp, $tag[$columns - 1]);
326 }
327 }, $result['data']);
328 }
329
330 \OCA\Analytics\Service\PanoramaFilterService::validateDimensions(

Callers 1

jsonContentMethod · 0.95

Calls 10

getDatasourcesMethod · 0.95
filterDataMethod · 0.95
aggregateDataMethod · 0.95
replaceDatasourceTextMethod · 0.80
validateDimensionsMethod · 0.80
countFunction · 0.50
tMethod · 0.45
readDataMethod · 0.45

Tested by

no test coverage detected