Skip to content

Commit

Permalink
2.59.3 Added Channels mode for CLE admins
Browse files Browse the repository at this point in the history
  • Loading branch information
classaxe committed Oct 5, 2023
1 parent ba901a9 commit 556f6d3
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 2 deletions.
82 changes: 82 additions & 0 deletions src/Controller/Web/Channels/Channels.php
@@ -0,0 +1,82 @@
<?php
namespace App\Controller\Web\Channels;

use App\Controller\Web\Base;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; // Required for annotations

/**
* Class Logs
* @package App\Controller\Web
*/
class Channels extends Base
{
/**
* @Route(
* "/{_locale}/{system}/channels",
* requirements={
* "system": "reu|rna|rww"
* },
* name="channels"
* )
* @param $_locale
* @param $system
*
* @return Response
*/
public function channels(
$_locale,
$system
) {
$i18n = $this->translator;
$minDate = '2023-01-01';
$minTimes = 5;
$regions = $this->regionRepository->getAllOptions(false, false);
$regionCodes = array_values($regions);
$groupedSlots = [];
foreach ($regionCodes as $r) {
$groupedSlots[$r] = 0;
}
$data = $this->statsRepository->getChannels($minDate, $minTimes);
$grouped = [];
foreach ($data as $row) {
if (!isset($grouped[$row['khz']])) {
$grouped[$row['khz']] = $groupedSlots;
}
$grouped[$row['khz']][$row['region']] = $row['stations'];
}
$table = "
<table border='1' class='channels' style='border-collapse: collapse'>
<thead>
<tr>
<th>KHz</th>";
foreach ($regions as $label => $value) {
$table .= "<th>" . $label . "</th>";
}
$table .= "
</tr>
</thead>
<tbody>";
foreach ($grouped as $khz => $stations) {
$table .= "<tr>\n <th>" . (0 + $khz) . "</th>";
foreach ($regionCodes as $regionCode) {
$table .= "<td>" . ($stations[$regionCode] ? $stations[$regionCode] : "") . "</td>";
}
$table .= "</tr>";
}
$table .= "</tbody>\n</table>";

$parameters = [
'_locale' => $_locale,
'mode' => $i18n->trans('Channels'),
'system' => $system,
'minTimes' => $minTimes,
'minDate' => $minDate,
'table' => $table
];
$parameters = array_merge($parameters, $this->parameters);
return $this->render('channels/channels.html.twig', $parameters);

}

}
4 changes: 2 additions & 2 deletions src/Repository/RegionRepository.php
Expand Up @@ -34,10 +34,10 @@ public function getOne($code)
return $this->cacheOne[$code];
}

public function getAllOptions($withUnknown = true)
public function getAllOptions($withUnknown = true, $withAny = true)
{
$regions = $this->getRegions();
$out = ['(Any Region)' => ''];
$out = $withAny ? ['(Any Region)' => ''] : [];
foreach ($regions as $row) {
if ($withUnknown === false && $row->getRegion() === 'xx') {
continue;
Expand Down
37 changes: 37 additions & 0 deletions src/Repository/StatsRepository.php
Expand Up @@ -30,6 +30,43 @@ public function __construct(
$this->connection = $connection;
}

public function getChannels($minDate = false, $minTimes = 0)
{
$sql = "
SELECT
s.khz,
l.region,
COUNT(distinct s.id) as stations
FROM
signals s
INNER JOIN logs l on
l.signalID = s.id
WHERE
s.active = 1 -- Is active
AND s.type = 0 -- Is NDB
AND s.khz >= 190 -- Is 190 KHz and up
AND s.khz <= 1720 -- Is 1720 KHz and below
AND s.id in( -- Has been heard this year
SELECT
ls.signalId
from
logs ls
" . ($minDate ? "WHERE ls.date >= '" . $minDate ."'" : "") . "
group by
ls.signalId
" . ($minTimes ? "HAVING COUNT(*) >= " . $minTimes : "") ."
)
GROUP BY
khz, region
ORDER BY
khz, region";

/** @var Doctrine\DBAL\Driver\Statement $stmt */
$stmt = $this->connection->prepare($sql);
$stmt->execute();
return $stmt->fetchAllAssociative();
}

public function getStats()
{
if ($this->cache === null) {
Expand Down
26 changes: 26 additions & 0 deletions templates/channels/channels.html.twig
@@ -0,0 +1,26 @@
{% extends 'main.html.twig' %}
{% block body %}
<style>
table.channels {
font-size: 80%;
width: auto;
}
table.channels thead th {
background: #ccc;
width: 5em;
padding: 0.25em;
}
table.channels tbody th,
table.channels tbody td {
text-align: right;
padding: 0.25em;
}
</style>
<div class="main">
<h1>Channels</h1>
<p>Showing NDB channel usage by region for signals received at least {{ minTimes }} time(s)
since {{ minDate }}</p>

{{ table | raw }}
</div>
{% endblock %}

0 comments on commit 556f6d3

Please sign in to comment.