Skip to content

Commit

Permalink
🚀 Release 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aislandener committed May 17, 2022
1 parent 594b4b9 commit f1dde55
Show file tree
Hide file tree
Showing 15 changed files with 211 additions and 17 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
## 0.5.0
* Create migration for Position.
* Create model for Position.
* Command for populate Position.
* Relationships Asset <---> Position
* Relationships Driver <---> Position

## 0.4.2

* Relationship adjustment between tables
* Relationship adjustment between tables.

## 0.4.1

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "aislandener/mix-telematics-laravel",
"description": "MiX Telematics Communication API with Laravel",
"type": "library",
"version": "0.4.2",
"version": "0.5.0",
"require": {
"php": "^8.0",
"jumbojett/openid-connect-php": "^0.9.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateDriversTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down Expand Up @@ -37,4 +37,4 @@ public function down()
{
Schema::dropIfExists('drivers');
}
}
};
6 changes: 3 additions & 3 deletions database/migrations/2022_01_13_011344_create_assets_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAssetsTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand All @@ -26,7 +26,7 @@ public function up()
$table->bigInteger('FmVehicleId');
$table->bigInteger('DefaultDriverId');
$table->float('TargetFuelConsumption')->nullable();
$table->string('Country');
$table->string('Country')->nullable();
$table->string('CreatedBy');
$table->string('UserState');
$table->text('AssetImageUrl');
Expand Down Expand Up @@ -59,4 +59,4 @@ public function down()
{
Schema::dropIfExists('assets');
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAssetsDriversTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand All @@ -28,4 +28,4 @@ public function down()
{
Schema::dropIfExists('assets_drivers');
}
}
};
4 changes: 2 additions & 2 deletions database/migrations/2022_02_03_005728_create_groups_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateGroupsTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down Expand Up @@ -32,4 +32,4 @@ public function down()
{
Schema::dropIfExists('groups');
}
}
};
51 changes: 51 additions & 0 deletions database/migrations/2022_05_17_020230_create_positions_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('positions', function (Blueprint $table) {
$table->id();
$table->bigInteger('PositionId')->index();
$table->bigInteger('AssetId');
$table->bigInteger('DriverId');
$table->timestamp('Timestamp');
$table->double('Latitude')->nullable();
$table->double('Longitude')->nullable();
$table->double('SpeedKilometresPerHour')->nullable();
$table->double('SpeedLimit')->nullable();
$table->double('AltitudeMetres')->nullable();
$table->double('Heading')->nullable();
$table->double('NumberOfSatellites')->nullable();
$table->double('Hdop')->nullable();
$table->double('Vdop')->nullable();
$table->double('Pdop')->nullable();
$table->double('AgeOfReadingSeconds')->nullable();
$table->double('DistanceSinceReadingKilometres')->nullable();
$table->double('OdometerKilometres')->nullable();
$table->string('FormattedAddress')->nullable();
$table->string('Source')->nullable();
$table->boolean('IsAvl')->nullable();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('positions');
}
};
22 changes: 20 additions & 2 deletions src/Command/UpdateDataCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Aislandener\MixTelematicsLaravel\Facades\MixTelematics;
use Aislandener\MixTelematicsLaravel\Models\Driver;
use Carbon\Carbon;
use Carbon\CarbonImmutable;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

Expand All @@ -13,14 +15,15 @@ class UpdateDataCommand extends Command
protected $signature = "mix-telematics:populate
{--d|driver : Populate to Driver}
{--a|asset : Populate to Asset}
{--g|group : Populate to Group}
{--g|group : Populate to Group}
{--p|position : Populate to Position}
{--A|all : Populate all tables}";

protected $description = 'Collect data in MiX Telematics and save in database';

public function handle()
{
if(!(collect($this->options())->only(['all', 'driver', 'asset', 'group'])->some(true))) {
if(!(collect($this->options())->only(['all', 'driver', 'asset', 'group', 'position'])->some(true))) {
$this->error("Need some parameter");
return;
}
Expand All @@ -37,6 +40,10 @@ public function handle()
if($this->option('group') || $this->option('all')) {
$this->populateGroup();
}

if($this->option('position') || $this->option('all')) {
$this->populatePosition();
}
$this->info("Finish collect data...");
}

Expand Down Expand Up @@ -67,4 +74,15 @@ private function populateGroup()
$this->info("Finish populate 'Group' table");
}

private function populatePosition()
{
$this->alert("Start populate 'Position' table");

$since = CarbonImmutable::now()->startOfDay()->format('YmdHis') . '000';

MixTelematics::positions()->getPositions(sinceToken: $since,command: $this);

$this->info("Finish populate 'Position' table");
}

}
2 changes: 2 additions & 0 deletions src/Facades/MixTelematics.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
use Aislandener\MixTelematicsLaravel\Services\AssetService;
use Aislandener\MixTelematicsLaravel\Services\DriversService;
use Aislandener\MixTelematicsLaravel\Services\GroupService;
use Aislandener\MixTelematicsLaravel\Services\PositionService;
use Illuminate\Support\Facades\Facade;

/**
* @method static DriversService drivers()
* @method static ActiveEventsService activeEvents()
* @method static AssetService assets()
* @method static GroupService groups()
* @method static PositionService positions()
*/
class MixTelematics extends Facade
{
Expand Down
16 changes: 13 additions & 3 deletions src/MixTelematicsLaravelService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Aislandener\MixTelematicsLaravel\Services\AssetService;
use Aislandener\MixTelematicsLaravel\Services\DriversService;
use Aislandener\MixTelematicsLaravel\Services\GroupService;
use Aislandener\MixTelematicsLaravel\Services\PositionService;
use Carbon\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Http;
Expand All @@ -20,16 +21,20 @@ class MixTelematicsLaravelService
private DriversService $driversService;
private AssetService $assetService;
private GroupService $groupService;
private PositionService $positionService;

public function __construct(ActiveEventsService $activeEventsService,
DriversService $driversService,
AssetService $assetService,
GroupService $groupService)
DriversService $driversService,
AssetService $assetService,
GroupService $groupService,
PositionService $positionService,
)
{
$this->driversService = $driversService;
$this->activeEventsService = $activeEventsService;
$this->assetService = $assetService;
$this->groupService = $groupService;
$this->positionService = $positionService;
}

/**
Expand Down Expand Up @@ -64,5 +69,10 @@ public function groups(): GroupService
return $this->groupService;
}

public function positions(): PositionService
{
return $this->positionService;
}


}
4 changes: 3 additions & 1 deletion src/MixTelematicsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Aislandener\MixTelematicsLaravel\Services\AssetService;
use Aislandener\MixTelematicsLaravel\Services\DriversService;
use Aislandener\MixTelematicsLaravel\Services\GroupService;
use Aislandener\MixTelematicsLaravel\Services\PositionService;
use Illuminate\Support\ServiceProvider;

class MixTelematicsServiceProvider extends ServiceProvider
Expand Down Expand Up @@ -42,7 +43,8 @@ private function injectDependency(): void
GroupService::class,
DriversService::class,
AssetService::class,
ActiveEventsService::class
ActiveEventsService::class,
PositionService::class,
];
$this->app->when($services)
->needs('$clientName')
Expand Down
6 changes: 6 additions & 0 deletions src/Models/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

class Asset extends Model
{
Expand Down Expand Up @@ -65,4 +66,9 @@ public function group(): BelongsTo
return $this->belongsTo(Group::class,'SiteId','GroupId');
}

public function position() : HasOne
{
return $this->hasOne(Position::class, 'AssetId', 'AssetId');
}

}
6 changes: 6 additions & 0 deletions src/Models/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Laravel\Sanctum\HasApiTokens;

class Driver extends Model
Expand Down Expand Up @@ -46,4 +47,9 @@ public function group():BelongsTo
{
return $this->belongsTo(Group::class,'SiteId', 'GroupId');
}

public function position() : HasOne
{
return $this->hasOne(Position::class, 'DriverId', 'DriverId');
}
}
57 changes: 57 additions & 0 deletions src/Models/Position.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Aislandener\MixTelematicsLaravel\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Position extends Model
{
protected $table = 'positions';

protected $fillable = [
'PositionId',
'AssetId',
'DriverId',
'Timestamp',
'Latitude',
'Longitude',
'SpeedKilometresPerHour',
'SpeedLimit',
'AltitudeMetres',
'Heading',
'NumberOfSatellites',
'Hdop',
'Vdop',
'Pdop',
'AgeOfReadingSeconds',
'DistanceSinceReadingKilometres',
'OdometerKilometres',
'FormattedAddress',
'Source',
'IsAvl',
];

protected $casts = [
'IsAvl' => 'boolean',
'Timestamp' => 'timestamp'
];

/**
* @return BelongsTo
*/
public function asset() : BelongsTo
{
return $this->belongsTo(Asset::class, 'AssetId', 'AssetId');
}

/**
* @return BelongsTo
*/
public function driver() : BelongsTo
{
return $this->belongsTo(Driver::class, 'DriverId', 'DriverId');
}


}
Loading

0 comments on commit f1dde55

Please sign in to comment.