Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Jun 6, 2024
1 parent aa90d20 commit fb51c7f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions app/Enums/StatKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ enum StatKey: string
use HasLabel;

case VOTES = 'votes';

case OBSERVERS = 'observers';
case POLLING_STATIONS = 'polling_stations';
case VISITED_POLLING_STATIONS = 'visited_polling_stations';
case STARTED_FORMS = 'started_forms';
case QUESTIONS_ANSWERED = 'questions_answered';
case FLAGGED_ANSWERS = 'flagged_answers';
case MINUTES_MONITORING = 'minutes_monitoring';
case NGOS = 'ngos';

protected function labelKeyPrefix(): ?string
{
Expand Down
10 changes: 6 additions & 4 deletions app/Jobs/FetchVoteMonitorLiveDataJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Jobs;

use App\Enums\StatKey;
use App\Models\Stat;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
Expand Down Expand Up @@ -34,18 +35,19 @@ public function handle(): void
{
$data = Http::acceptJson()
->withUserAgent(config('app.name'))
->withToken(config('services.votemonitor.apikey'))
->withHeader('x-vote-monitor-api-key', config('services.votemonitor.apikey'))
->get(config('services.votemonitor.url'))
->throw()
->json();

Stat::upsert(
collect($data)
->map(fn ($value, $key) => [
collect(StatKey::values())
->map(fn (string $key) => [
'key' => $key,
'value' => $value,
'value' => data_get($data, $key),
'updated_at' => now(),
])
->reject(fn (array $item) => blank($item['value']))
->values()
->all(),
uniqueBy: ['key'],
Expand Down
1 change: 0 additions & 1 deletion config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
'enabled' => env('VOTEMONITOR_ENABLED', false),
'url' => env('VOTEMONITOR_URL'),
'apikey' => env('VOTEMONITOR_APIKEY'),
'election_round_id' => env('VOTEMONITOR_ELECTION_ROUND_ID'),
],

];
3 changes: 3 additions & 0 deletions lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
'votes' => 'Votes',
'observers' => 'Observers on field',
'polling_stations' => 'Polling stations',
'visited_polling_stations' => 'Visited polling stations',
'started_forms' => 'Started forms',
'questions_answered' => 'Questions answered',
'flagged_answers' => 'Flagged answers',
'minutes_monitoring' => 'Minutes monitoring',
'ngos' => 'NGOs',
],

'votemonitor' => [
Expand Down

0 comments on commit fb51c7f

Please sign in to comment.