-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
86 changed files
with
2,415 additions
and
929 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Actions; | ||
|
||
class CheckRecordHasIssues | ||
{ | ||
public function checkTurnout(array $record): bool | ||
{ | ||
$computedTotal = collect(['LP', 'LC', 'LS', 'UM']) | ||
->map(fn (string $key) => $record[$key]) | ||
->sum(); | ||
|
||
if ($computedTotal !== $record['LT']) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public function checkRecord(array $record): bool | ||
{ | ||
if ($record['a'] != $record['a1'] + $record['a2']) { | ||
return true; | ||
} | ||
|
||
if ($record['a1'] < $record['b1']) { | ||
return true; | ||
} | ||
|
||
if ($record['a2'] < $record['b2']) { | ||
return true; | ||
} | ||
|
||
if ($record['b'] != $record['b1'] + $record['b2'] + $record['b3']) { | ||
return true; | ||
} | ||
|
||
if ($record['c'] < $record['d'] + $record['e'] + $record['f']) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Actions; | ||
|
||
use Illuminate\Support\Str; | ||
|
||
class CheckVotable | ||
{ | ||
private function getIndependentCandidatePrefix(): string | ||
{ | ||
return config('import.independent_candidate_prefix'); | ||
} | ||
|
||
public function isIndependentCandidate(string $name): bool | ||
{ | ||
return Str::startsWith($name, $this->getIndependentCandidatePrefix()); | ||
} | ||
|
||
public function getName(string $name): string | ||
{ | ||
return Str::afterLast($name, $this->getIndependentCandidatePrefix()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Actions; | ||
|
||
use App\Enums\Time; | ||
use App\Models\Candidate; | ||
use App\Models\Party; | ||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\Support\Str; | ||
|
||
class GenerateMappedVotablesList | ||
{ | ||
public function votables(array $header): Collection | ||
{ | ||
return Cache::remember( | ||
hash('xxh128', implode(',', $header)), | ||
Time::MINUTE_IN_SECONDS, | ||
fn () => collect($header) | ||
->filter(fn (string $column) => $this->hasVotesSuffix($column)) | ||
->mapWithKeys(fn (string $column) => [ | ||
$column => $this->getCandidateOrParty($column), | ||
]) | ||
); | ||
} | ||
|
||
protected function getVotesSuffix(): string | ||
{ | ||
return config('import.candidate_votes_suffix'); | ||
} | ||
|
||
protected function hasVotesSuffix(string $column): bool | ||
{ | ||
return Str::endsWith($column, $this->getVotesSuffix()); | ||
} | ||
|
||
protected function getCandidateOrParty(string $name): array | ||
{ | ||
$name = Str::before($name, $this->getVotesSuffix()); | ||
|
||
$votable = Party::query() | ||
->where('name', $name) | ||
->firstOr( | ||
fn () => Candidate::query() | ||
->where('name', $name) | ||
->first() | ||
); | ||
|
||
if (blank($votable)) { | ||
throw new \Exception("Votable not found for column: {$name}"); | ||
} | ||
|
||
return [ | ||
'votable_type' => $votable?->getMorphClass(), | ||
'votable_id' => $votable?->id, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Concerns; | ||
|
||
use App\Enums\DataLevel; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Tpetry\QueryExpressions\Language\Alias; | ||
use Tpetry\QueryExpressions\Value\Value; | ||
|
||
trait CanGroupByDataLevel | ||
{ | ||
public function scopeForDataLevel(Builder $query, DataLevel $level, ?string $country = null, ?int $county = null, ?int $locality = null, bool $aggregate = false): Builder | ||
{ | ||
if ($level->is(DataLevel::TOTAL)) { | ||
$query->groupByTotal(); | ||
} | ||
|
||
if ($level->is(DataLevel::DIASPORA)) { | ||
$query->whereNotNull('country_id'); | ||
|
||
if (filled($country)) { | ||
$query->where('country_id', $country); | ||
} | ||
|
||
if (! $aggregate) { | ||
$query->groupByCountry(); | ||
} | ||
} | ||
|
||
if ($level->is(DataLevel::NATIONAL)) { | ||
$query->whereNull('country_id'); | ||
|
||
if (filled($locality)) { | ||
$query->where('locality_id', $locality) | ||
->groupByLocality(); | ||
} elseif (filled($county)) { | ||
$query->where('county_id', $county); | ||
|
||
if ($aggregate) { | ||
$query->groupByCounty(); | ||
} else { | ||
$query->groupByLocality(); | ||
} | ||
} else { | ||
$query->whereNotNull('locality_id') | ||
->whereNotNull('county_id'); | ||
|
||
if ($aggregate) { | ||
$query->groupByTotal(); | ||
} else { | ||
$query->groupByCounty(); | ||
} | ||
} | ||
} | ||
|
||
return $query; | ||
} | ||
|
||
public function scopeGroupByCountry(Builder $query): Builder | ||
{ | ||
return $query->groupBy('country_id') | ||
->addSelect(new Alias('country_id', 'place')); | ||
} | ||
|
||
public function scopeGroupByCounty(Builder $query): Builder | ||
{ | ||
return $query->groupBy('county_id') | ||
->addSelect(new Alias('county_id', 'place')); | ||
} | ||
|
||
public function scopeGroupByLocality(Builder $query): Builder | ||
{ | ||
return $query->groupBy('locality_id') | ||
->addSelect(new Alias('locality_id', 'place')); | ||
} | ||
|
||
public function scopeGroupByTotal(Builder $query): Builder | ||
{ | ||
return $query->addSelect(new Alias(new Value(1), 'place')); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Contracts; | ||
|
||
interface HasDisplayName | ||
{ | ||
public function getDisplayName(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Enums; | ||
|
||
use App\Concerns\Enums\Arrayable; | ||
use App\Concerns\Enums\Comparable; | ||
use Filament\Support\Contracts\HasLabel; | ||
|
||
enum Part: int implements HasLabel | ||
{ | ||
use Arrayable; | ||
use Comparable; | ||
|
||
case PROV = 0; | ||
case PART = 1; | ||
case FINAL = 2; | ||
|
||
public function getLabel(): ?string | ||
{ | ||
return match ($this) { | ||
self::PROV => __('app.part.prov'), | ||
self::PART => __('app.part.part'), | ||
self::FINAL => __('app.part.final'), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Enums; | ||
|
||
enum Time: int | ||
{ | ||
case MINUTE_IN_SECONDS = 60; | ||
case HOUR_IN_SECONDS = 60 * 60; | ||
case DAY_IN_SECONDS = 60 * 60 * 24; | ||
case WEEK_IN_SECONDS = 60 * 60 * 24 * 7; | ||
case MONTH_IN_SECONDS = 60 * 60 * 24 * 7 * 30; | ||
case YEAR_IN_SECONDS = 60 * 60 * 24 * 7 * 30 * 365; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.