Skip to content
Snippets Groups Projects
Commit fe7a7210 authored by Rodrigo Goncalves's avatar Rodrigo Goncalves
Browse files

Unit conversion for ingress from TikiWiki

parent 3056b8c3
No related branches found
No related tags found
2 merge requests!23Resolve "SI Units for Ingress data from TikiWiki",!22Resolve "Unstructured SmartDataContext storage"
......@@ -7,6 +7,7 @@ use Exception;
use Ingress\Command\BaseCommand;
use Ingress\Services\Logger;
use Ingress\Services\smartdataapi\SmartDataContextApiClient;
use Ingress\Services\smartdataapi\SmartDataUnits;
use Ingress\Services\tikiwiki\TikiWIkiConfig;
use Ingress\Services\tikiwiki\TikiWikiDB;
......@@ -118,8 +119,8 @@ class ImportCommand extends BaseCommand
];
private static function convertKM($value) {
// TODO implement conversion to SI
return ["value" => $value];
// Convert the kilometers values to meters
return ["valueI32" => $value * 1000, "unit" => SmartDataUnits::METER];
}
private static function convertOwnerCount($value) {
......@@ -127,13 +128,13 @@ class ImportCommand extends BaseCommand
}
private static function convertDate($value) {
// TODO implement conversion to SI
return ["value" => $value];
// Saves the epoch value as a time
return ["valueI64" => $value, "unit" => SmartDataUnits::TIME];
}
private static function convertKMLiter($value) {
// TODO implement conversion to SI
return ["value" => $value];
// Convert KM/L to M/L
return ["valueD32" => $value, "unit" => SmartDataUnits::METER];
}
private static function convertValueMap($value, $map) {
......@@ -158,8 +159,13 @@ class ImportCommand extends BaseCommand
private static function convertServiceFrequency($key, $value)
{
// TODO calculate frequency
return ["kind" => $key, 'internal' => ['value' => $value]];
$numericValue = preg_replace('/\D/', '', $value);
if (str_contains($value, "km")) {
return ["kind" => $key, 'internal' => ['unit' => SmartDataUnits::METER, 'valueI32' => $numericValue * 1000]];
} else {
return ["kind" => $key, 'internal' => ['unit' => SmartDataUnits::TIME, 'valueI32' => $numericValue * SmartDataUnits::MONTH_TO_TIME_MULTIPLIER]];
}
}
private static function persistMaintenanceReport($tikiwikiid, $api, $data)
......
<?php
namespace Ingress\Services\smartdataapi;
class SmartDataUnits
{
public const METER = 0x84964924;
public const TIME = 0x84925924;
public const MONTH_TO_TIME_MULTIPLIER = 1 * 30 * 24 * 3600;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment