Skip to content

Commit 45528ee

Browse files
committed
Add new gridsquares by band to monthly report
Introduces per-band breakdown of new gridsquares in the monthly report, including model, controller, and view changes. The report now displays new gridsquares grouped by band, as well as improved details for new DXCCs and satellite activity breakdowns.
1 parent 4e65709 commit 45528ee

3 files changed

Lines changed: 283 additions & 90 deletions

File tree

application/controllers/Monthlyreport.php

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public function export_json()
121121
'new_countries_satellite' => $report['new_dxcc_satellite'],
122122
'new_countries_eme' => $report['new_dxcc_eme'],
123123
'new_gridsquares' => $report['new_grids'],
124+
'new_gridsquares_by_band' => $report['new_grids_by_band'],
124125
'new_gridsquares_hf' => $report['new_grids_hf'],
125126
'new_gridsquares_satellite' => $report['new_grids_satellite'],
126127
'new_gridsquares_eme' => $report['new_grids_eme'],
@@ -129,7 +130,8 @@ public function export_json()
129130
'bands_used' => $report['bands'],
130131
'continents_worked' => $report['continents'],
131132
'satellite_qsos' => $report['satellite_qsos'],
132-
'eme_qsos' => $report['eme_qsos']
133+
'eme_qsos' => $report['eme_qsos'],
134+
'satellite_breakdown' => $report['satellite_breakdown']
133135
),
134136
'statistics' => array(
135137
'qsos_per_day' => round($report['total_qsos'] / date('t', strtotime("$year-$month-01")), 2),
@@ -202,7 +204,15 @@ public function export_text()
202204
foreach ($report['new_dxcc_by_band'] as $band => $dxcc_list) {
203205
$text .= "\n{$band} (" . count($dxcc_list) . " new):\n";
204206
foreach ($dxcc_list as $dxcc) {
205-
$text .= " - {$dxcc['name']}\n";
207+
$text .= " - {$dxcc['name']}";
208+
if (!empty($dxcc['callsign'])) {
209+
$text .= " (worked {$dxcc['callsign']}";
210+
if (!empty($dxcc['mode'])) {
211+
$text .= " on {$dxcc['mode']}";
212+
}
213+
$text .= ")";
214+
}
215+
$text .= "\n";
206216
}
207217
}
208218
$text .= "\n";
@@ -212,7 +222,15 @@ public function export_text()
212222
$text .= "NEW COUNTRIES VIA SATELLITE\n";
213223
$text .= "---------------------------\n";
214224
foreach ($report['new_dxcc_satellite'] as $dxcc) {
215-
$text .= "- {$dxcc['name']}\n";
225+
$text .= "- {$dxcc['name']}";
226+
if (!empty($dxcc['callsign'])) {
227+
$text .= " (worked {$dxcc['callsign']}";
228+
if (!empty($dxcc['mode'])) {
229+
$text .= " on {$dxcc['mode']}";
230+
}
231+
$text .= ")";
232+
}
233+
$text .= "\n";
216234
}
217235
$text .= "\n";
218236
}
@@ -221,7 +239,15 @@ public function export_text()
221239
$text .= "NEW COUNTRIES VIA EME (MOONBOUNCE)\n";
222240
$text .= "----------------------------------\n";
223241
foreach ($report['new_dxcc_eme'] as $dxcc) {
224-
$text .= "- {$dxcc['name']}\n";
242+
$text .= "- {$dxcc['name']}";
243+
if (!empty($dxcc['callsign'])) {
244+
$text .= " (worked {$dxcc['callsign']}";
245+
if (!empty($dxcc['mode'])) {
246+
$text .= " on {$dxcc['mode']}";
247+
}
248+
$text .= ")";
249+
}
250+
$text .= "\n";
225251
}
226252
$text .= "\n";
227253
}
@@ -230,37 +256,27 @@ public function export_text()
230256
$text .= "NEW GRIDSQUARES THIS MONTH\n";
231257
$text .= "--------------------------\n";
232258

233-
if (count($report['new_grids_hf']) > 0) {
234-
$text .= "HF/VHF Terrestrial (" . count($report['new_grids_hf']) . "):\n";
235-
$grids_per_line = 10;
236-
$grid_list = array_column($report['new_grids_hf'], 'grid');
237-
for ($i = 0; $i < count($grid_list); $i += $grids_per_line) {
238-
$text .= implode(', ', array_slice($grid_list, $i, $grids_per_line)) . "\n";
259+
if (!empty($report['new_grids_by_band'])) {
260+
foreach ($report['new_grids_by_band'] as $band => $grids_list) {
261+
$text .= "\n{$band} (" . count($grids_list) . " new):\n";
262+
foreach ($grids_list as $grid) {
263+
$text .= " {$grid['grid']}";
264+
if (!empty($grid['callsign'])) {
265+
$text .= " ({$grid['callsign']}";
266+
if (!empty($grid['satellite'])) {
267+
$text .= " via {$grid['satellite']}";
268+
}
269+
if (!empty($grid['mode'])) {
270+
$text .= " - {$grid['mode']}";
271+
}
272+
$text .= ")";
273+
}
274+
$text .= "\n";
275+
}
239276
}
240-
$text .= "\n";
241-
}
242-
243-
if (count($report['new_grids_satellite']) > 0) {
244-
$text .= "Satellite (" . count($report['new_grids_satellite']) . "):\n";
245-
$grids_per_line = 10;
246-
$grid_list = array_column($report['new_grids_satellite'], 'grid');
247-
for ($i = 0; $i < count($grid_list); $i += $grids_per_line) {
248-
$text .= implode(', ', array_slice($grid_list, $i, $grids_per_line)) . "\n";
249-
}
250-
$text .= "\n";
251277
}
252-
253-
if (count($report['new_grids_eme']) > 0) {
254-
$text .= "EME (Moonbounce) (" . count($report['new_grids_eme']) . "):\n";
255-
$grids_per_line = 10;
256-
$grid_list = array_column($report['new_grids_eme'], 'grid');
257-
for ($i = 0; $i < count($grid_list); $i += $grids_per_line) {
258-
$text .= implode(', ', array_slice($grid_list, $i, $grids_per_line)) . "\n";
259-
}
260-
}
261-
}
262-
263-
$text .= "MODES USED\n";
278+
$text .= "\n";
279+
} $text .= "MODES USED\n";
264280
$text .= "----------\n";
265281
foreach ($report['modes'] as $mode => $count) {
266282
$text .= sprintf("%-10s %d QSOs\n", $mode, $count);
@@ -295,7 +311,15 @@ public function export_text()
295311
if ($report['satellite_qsos'] > 0) {
296312
$text .= "SATELLITE ACTIVITY\n";
297313
$text .= "------------------\n";
298-
$text .= "Total Satellite QSOs: {$report['satellite_qsos']}\n\n";
314+
$text .= "Total Satellite QSOs: {$report['satellite_qsos']}\n";
315+
316+
if (!empty($report['satellite_breakdown'])) {
317+
$text .= "\nQSOs per Satellite:\n";
318+
foreach ($report['satellite_breakdown'] as $sat) {
319+
$text .= sprintf(" %-20s %3d QSOs (%s%%)\n", $sat['satellite'], $sat['qso_count'], $sat['percentage']);
320+
}
321+
}
322+
$text .= "\n";
299323
}
300324

301325
if ($report['eme_qsos'] > 0) {

application/models/Monthlyreport_model.php

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function generate_report($logbooks_locations_array, $year, $month) {
3232
'new_dxcc_satellite' => $this->get_new_dxcc_by_prop($logbooks_locations_array, $start_date, $end_date, $prev_month_end, 'SAT'),
3333
'new_dxcc_eme' => $this->get_new_dxcc_by_prop($logbooks_locations_array, $start_date, $end_date, $prev_month_end, 'EME'),
3434
'new_grids' => $this->get_new_gridsquares($logbooks_locations_array, $start_date, $end_date, $prev_month_end),
35+
'new_grids_by_band' => $this->get_new_gridsquares_by_band($logbooks_locations_array, $start_date, $end_date, $prev_month_end),
3536
'new_grids_satellite' => $this->get_new_gridsquares_by_prop($logbooks_locations_array, $start_date, $end_date, $prev_month_end, 'SAT'),
3637
'new_grids_eme' => $this->get_new_gridsquares_by_prop($logbooks_locations_array, $start_date, $end_date, $prev_month_end, 'EME'),
3738
'new_grids_hf' => $this->get_new_gridsquares_hf($logbooks_locations_array, $start_date, $end_date, $prev_month_end),
@@ -432,6 +433,152 @@ private function get_new_dxcc_by_prop($locations, $start_date, $end_date, $prev_
432433
return $new_dxcc;
433434
}
434435

436+
/**
437+
* Get new gridsquares by band
438+
*/
439+
private function get_new_gridsquares_by_band($locations, $start_date, $end_date, $prev_month_end) {
440+
$new_grids_by_band = array();
441+
442+
// Get all bands worked this month, plus propagation mode to separate SAT/EME
443+
$this->db->distinct();
444+
$this->db->select('COL_BAND, COL_PROP_MODE');
445+
$this->db->from($this->config->item('table_name'));
446+
$this->db->where_in('station_id', $locations);
447+
$this->db->where('COL_TIME_ON >=', $start_date);
448+
$this->db->where('COL_TIME_ON <=', $end_date);
449+
$this->db->where('COL_BAND IS NOT NULL');
450+
$this->db->where('COL_BAND !=', '');
451+
$bands_query = $this->db->get();
452+
453+
foreach ($bands_query->result() as $band_row) {
454+
$band = $band_row->COL_BAND;
455+
$prop_mode = $band_row->COL_PROP_MODE;
456+
457+
// Group SAT and EME separately, not by frequency band
458+
if ($prop_mode == 'SAT') {
459+
$band_key = 'Satellite';
460+
} elseif ($prop_mode == 'EME') {
461+
$band_key = 'EME';
462+
} else {
463+
$band_key = $band;
464+
}
465+
466+
if (!isset($new_grids_by_band[$band_key])) {
467+
$new_grids_by_band[$band_key] = array();
468+
}
469+
470+
// Get all gridsquares worked on this band/prop this month
471+
$this->db->select('COL_CALL, COL_GRIDSQUARE, COL_VUCC_GRIDS, COL_TIME_ON, COL_MODE, COL_SUBMODE, COL_SAT_NAME');
472+
$this->db->from($this->config->item('table_name'));
473+
$this->db->where_in('station_id', $locations);
474+
$this->db->where('COL_TIME_ON >=', $start_date);
475+
$this->db->where('COL_TIME_ON <=', $end_date);
476+
$this->db->where('COL_BAND', $band);
477+
478+
// Filter by propagation mode
479+
if ($prop_mode) {
480+
$this->db->where('COL_PROP_MODE', $prop_mode);
481+
} else {
482+
// For terrestrial, exclude SAT and EME
483+
$this->db->where('(COL_PROP_MODE IS NULL OR (COL_PROP_MODE != "SAT" AND COL_PROP_MODE != "EME"))', NULL, FALSE);
484+
}
485+
486+
$this->db->order_by('COL_TIME_ON', 'ASC');
487+
488+
$query = $this->db->get();
489+
$grid_data = array();
490+
491+
foreach ($query->result() as $row) {
492+
$mode = !empty($row->COL_SUBMODE) ? $row->COL_SUBMODE : $row->COL_MODE;
493+
494+
// Process main gridsquare (first 4 characters only)
495+
if (!empty($row->COL_GRIDSQUARE) && strlen($row->COL_GRIDSQUARE) >= 4) {
496+
$grid_4char = strtoupper(substr($row->COL_GRIDSQUARE, 0, 4));
497+
if (!isset($grid_data[$grid_4char])) {
498+
$grid_data[$grid_4char] = array(
499+
'callsign' => $row->COL_CALL,
500+
'satellite' => !empty($row->COL_SAT_NAME) ? $row->COL_SAT_NAME : '',
501+
'mode' => $mode,
502+
'time' => $row->COL_TIME_ON
503+
);
504+
}
505+
}
506+
507+
// Process VUCC grids (first 4 characters only)
508+
if (!empty($row->COL_VUCC_GRIDS)) {
509+
$vucc_grids = explode(',', $row->COL_VUCC_GRIDS);
510+
foreach ($vucc_grids as $grid) {
511+
$grid = trim($grid);
512+
if (strlen($grid) >= 4) {
513+
$grid_4char = strtoupper(substr($grid, 0, 4));
514+
if (!isset($grid_data[$grid_4char])) {
515+
$grid_data[$grid_4char] = array(
516+
'callsign' => $row->COL_CALL,
517+
'satellite' => !empty($row->COL_SAT_NAME) ? $row->COL_SAT_NAME : '',
518+
'mode' => $mode,
519+
'time' => $row->COL_TIME_ON
520+
);
521+
}
522+
}
523+
}
524+
}
525+
}
526+
527+
// Check each grid to see if it was worked before on this band/prop
528+
foreach ($grid_data as $grid => $data) {
529+
// Check if this grid was worked before this month on this band/prop
530+
$this->db->select('COUNT(*) as count');
531+
$this->db->from($this->config->item('table_name'));
532+
$this->db->where_in('station_id', $locations);
533+
$this->db->where('COL_BAND', $band);
534+
if ($prop_mode) {
535+
$this->db->where('COL_PROP_MODE', $prop_mode);
536+
} else {
537+
$this->db->where('(COL_PROP_MODE IS NULL OR (COL_PROP_MODE != "SAT" AND COL_PROP_MODE != "EME"))', NULL, FALSE);
538+
}
539+
$this->db->where('COL_TIME_ON <', $start_date);
540+
$this->db->group_start();
541+
$this->db->where('UPPER(SUBSTR(COL_GRIDSQUARE, 1, 4)) =', $grid);
542+
$this->db->or_like('COL_VUCC_GRIDS', $grid);
543+
$this->db->group_end();
544+
545+
$prev_query = $this->db->get();
546+
$prev_row = $prev_query->row();
547+
548+
// If not worked before on this band/prop, it's new
549+
if ($prev_row->count == 0) {
550+
// Avoid duplicates in the same band_key
551+
$already_added = false;
552+
foreach ($new_grids_by_band[$band_key] as $existing) {
553+
if ($existing['grid'] == $grid) {
554+
$already_added = true;
555+
break;
556+
}
557+
}
558+
559+
if (!$already_added) {
560+
$new_grids_by_band[$band_key][] = array(
561+
'grid' => $grid,
562+
'callsign' => $data['callsign'],
563+
'satellite' => $data['satellite'],
564+
'mode' => $data['mode']
565+
);
566+
}
567+
}
568+
}
569+
}
570+
571+
// Remove bands with no new grids
572+
$new_grids_by_band = array_filter($new_grids_by_band, function($arr) {
573+
return !empty($arr);
574+
});
575+
576+
// Sort bands in proper amateur radio order
577+
$new_grids_by_band = $this->sort_bands_array($new_grids_by_band);
578+
579+
return $new_grids_by_band;
580+
}
581+
435582
/**
436583
* Get new gridsquares worked this month (first time ever) - All modes
437584
*/

0 commit comments

Comments
 (0)