Skip to content

Commit

Permalink
Merge branch 'sandbox' into main
Browse files Browse the repository at this point in the history
* sandbox:
  addind the totals and methods to the date total command.
  add the platform aggregates tot he date total command.
  • Loading branch information
robertbrowncc committed Apr 19, 2024
2 parents ddd98d7 + 4726250 commit 9b64e24
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/Console/Commands/StatementsDateTotal.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Symfony\Component\VarDumper\VarDumper;
use Throwable;

class StatementsDateTotal extends Command
Expand Down Expand Up @@ -54,8 +55,15 @@ public function handle(DayArchiveService $day_archive_service, StatementSearchSe
$this->info('Source Percentage: ' . $source_percentage . '%');
$this->info('Source Difference DB Percentage: ' . floor(($source_diff / $db_diff) * 100) . '%');
$this->info('Source Difference OS Percentage: ' . floor(($source_diff / $os_total) * 100) . '%');

$this->info('statements:index-date ' . $date_string);
$totals = $statement_search_service->totalsForPlatformsDate($date);
$methods = $statement_search_service->methodsByPlatformsDate($date);
foreach ($totals as $index => $total) {
$totals[$index]['API'] = $methods[$total['platform_id']]['API'] ?? 0;
$totals[$index]['API_MULTI'] = $methods[$total['platform_id']]['API_MULTI'] ?? 0;
$totals[$index]['FORM'] = $methods[$total['platform_id']]['FORM'] ?? 0;
}
$this->table(array_keys($totals[0]), $totals);

} else {
$this->info('Could not find the first or last ids: ' . $first_id . ' :: ' . $last_id);
Expand Down
18 changes: 18 additions & 0 deletions app/Services/StatementSearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,24 @@ public function totalForPlatformDate(Platform $platform, Carbon $date): int
]);
}

public function totalsForPlatformsDate(Carbon $date): array
{
$aggregates = $this->processDateAggregate($date, ['platform_id']);
return $aggregates['aggregates'];
}

public function methodsByPlatformsDate(Carbon $date): array
{
$query = "SELECT COUNT(*), method, platform_id FROM statement_index WHERE received_date = '" . $date->format('Y-m-d') . " 00:00:00' GROUP BY platform_id, method";
$results = $this->runSql($query);
$rows = $results['datarows'];
$out = [];
foreach ($rows as $row) {
$out[$row[2]][$row[1]] = $row[0];
}
return $out;
}

public function receivedDateRangeCondition(Carbon $start, Carbon $end): string
{
return "received_date BETWEEN '" . $start->format('Y-m-d') . "' AND '" . $end->format('Y-m-d') . "'";
Expand Down

0 comments on commit 9b64e24

Please sign in to comment.