Skip to content

Commit

Permalink
addind the totals and methods to the date total command.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbrowncc committed Apr 19, 2024
1 parent b5300c6 commit 4726250
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions 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 @@ -56,6 +57,12 @@ public function handle(DayArchiveService $day_archive_service, StatementSearchSe
$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 {
Expand Down
12 changes: 12 additions & 0 deletions app/Services/StatementSearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,18 @@ public function totalsForPlatformsDate(Carbon $date): array
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 4726250

Please sign in to comment.