From 313c7745cc342e15a297029ae12c576fccb36b72 Mon Sep 17 00:00:00 2001 From: Andreas Kristiansen <6977712+AndreasK79@users.noreply.github.com> Date: Thu, 3 Jul 2025 12:24:03 +0200 Subject: [PATCH] Added bandedges migration and usage in model --- application/config/migration.php | 2 +- application/migrations/247_add_bandedges.php | 68 ++++++++++++++++++++ application/models/Dxcluster_model.php | 64 +++++++----------- 3 files changed, 94 insertions(+), 40 deletions(-) create mode 100644 application/migrations/247_add_bandedges.php diff --git a/application/config/migration.php b/application/config/migration.php index 6d3d840bb..44ea379b0 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE; | */ -$config['migration_version'] = 246; +$config['migration_version'] = 247; /* |-------------------------------------------------------------------------- diff --git a/application/migrations/247_add_bandedges.php b/application/migrations/247_add_bandedges.php new file mode 100644 index 000000000..53275ff23 --- /dev/null +++ b/application/migrations/247_add_bandedges.php @@ -0,0 +1,68 @@ +db->table_exists('bandedges')) { + // Create the bandedges table + $this->dbforge->add_field([ + 'id' => [ + 'type' => 'INT', + 'constraint' => 11, + 'unsigned' => TRUE, + 'auto_increment' => TRUE, + ], + 'userid' => [ + 'type' => 'INT', + 'constraint' => 11, + ], + 'frequencyfrom' => [ + 'type' => 'BIGINT', + 'constraint' => 20, + ], + 'frequencyto' => [ + 'type' => 'BIGINT', + 'constraint' => 20, + ], + 'mode' => [ + 'type' => 'VARCHAR', + 'constraint' => 20, + ], + ]); + + $this->dbforge->add_key('id', TRUE); + $this->dbforge->create_table('bandedges'); + + // Insert initial data (for all users: userid = -1) + $data = [ + ['userid' => -1, 'frequencyfrom' => 1800000, 'frequencyto' => 1840000, 'mode' => 'cw'], + ['userid' => -1, 'frequencyfrom' => 3500000, 'frequencyto' => 3600000, 'mode' => 'cw'], + ['userid' => -1, 'frequencyfrom' => 3700000, 'frequencyto' => 4000000, 'mode' => 'phone'], + ['userid' => -1, 'frequencyfrom' => 5350000, 'frequencyto' => 5367000, 'mode' => 'cw'], + ['userid' => -1, 'frequencyfrom' => 7000000, 'frequencyto' => 7040000, 'mode' => 'cw'], + ['userid' => -1, 'frequencyfrom' => 7100000, 'frequencyto' => 7300000, 'mode' => 'phone'], + ['userid' => -1, 'frequencyfrom' => 10100000, 'frequencyto' => 10130000, 'mode' => 'cw'], + ['userid' => -1, 'frequencyfrom' => 14000000, 'frequencyto' => 14070000, 'mode' => 'cw'], + ['userid' => -1, 'frequencyfrom' => 14125000, 'frequencyto' => 14350000, 'mode' => 'phone'], + ['userid' => -1, 'frequencyfrom' => 14070000, 'frequencyto' => 14125000, 'mode' => 'digi'], + ]; + + $this->db->insert_batch('bandedges', $data); + } + } + + public function down() + { + $this->dbforge->drop_table('bandedges'); + } +} + diff --git a/application/models/Dxcluster_model.php b/application/models/Dxcluster_model.php index 7a8dd1eec..7343a843c 100644 --- a/application/models/Dxcluster_model.php +++ b/application/models/Dxcluster_model.php @@ -3,6 +3,17 @@ use Wavelog\Dxcc\Dxcc; class Dxcluster_model extends CI_Model { + + protected $bandedges = []; + + public function __construct() { + + // Load bandedges into a class property + $this->db->where('userid', -1); + $query = $this->db->get('bandedges'); + $this->bandedges = $query->result_array(); // or ->result() if you want objects + } + public function dxc_spotlist($band = '20m', $maxage = 60, $de = '', $mode = 'All') { $this->load->helper(array('psr4_autoloader')); @@ -137,47 +148,22 @@ class Dxcluster_model extends CI_Model { return false; } -function isFrequencyInMode($frequency, $mode) { - $bandMap = [ - ['mode' => 'cw', 'range' => [1800, 1840]], - ['mode' => 'phone', 'range' => [1840, 2000]], - ['mode' => 'cw', 'range' => [3500, 3600]], - ['mode' => 'phone', 'range' => [3700, 4000]], - ['mode' => 'cw', 'range' => [5350, 5367]], - ['mode' => 'phone', 'range' => [5350, 5367]], - ['mode' => 'digi', 'range' => [5350, 5367]], - ['mode' => 'cw', 'range' => [7000, 7040]], - ['mode' => 'phone', 'range' => [7100, 7300]], - ['mode' => 'cw', 'range' => [10100, 10130]], - ['mode' => 'digi', 'range' => [10100, 10130]], - ['mode' => 'cw', 'range' => [14000, 14070]], - ['mode' => 'phone', 'range' => [14125, 14350]], - ['mode' => 'cw', 'range' => [18068, 18096]], - ['mode' => 'phone', 'range' => [18110, 18168]], - ['mode' => 'cw', 'range' => [21000, 21070]], - ['mode' => 'phone', 'range' => [21125, 21450]], - ['mode' => 'cw', 'range' => [24890, 24910]], - ['mode' => 'phone', 'range' => [24930, 24990]], - ['mode' => 'cw', 'range' => [28000, 28070]], - ['mode' => 'phone', 'range' => [28125, 29700]], - ['mode' => 'cw', 'range' => [50000, 50109]], - ['mode' => 'phone', 'range' => [50110, 52000]], - ]; - - foreach ($bandMap as $entry) { - if ($entry['mode'] === $mode) { - [$low, $high] = $entry['range']; - if ($frequency >= $low && $frequency < $high) { - return true; - } - } - } - - return false; -} - + public function isFrequencyInMode($frequency, $mode) { + // Ensure frequency is in Hz if input is in kHz + if ($frequency < 1_000_000) { + $frequency *= 1000; + } + foreach ($this->bandedges as $band) { + if (strtolower($band['mode']) === strtolower($mode)) { + if ($frequency >= $band['frequencyfrom'] && $frequency < $band['frequencyto']) { + return true; + } + } + } + return false; + } public function dxc_qrg_lookup($qrg, $maxage = 120) { $this->load->helper(array('psr4_autoloader'));