From 7d2aeccefd320505cf3e1751c63c23f6bfd7923e Mon Sep 17 00:00:00 2001 From: DB4SCW Date: Tue, 3 Sep 2024 10:46:27 +0000 Subject: [PATCH 1/7] fix and expand REG1TEST export --- application/libraries/Reg1testformat.php | 83 +++++++++++++++++++----- application/views/reg1test/export.php | 10 ++- 2 files changed, 71 insertions(+), 22 deletions(-) diff --git a/application/libraries/Reg1testformat.php b/application/libraries/Reg1testformat.php index 06b9cf5e7..bc8e6c726 100644 --- a/application/libraries/Reg1testformat.php +++ b/application/libraries/Reg1testformat.php @@ -64,27 +64,78 @@ class Reg1testformat { //return a newline as the last line for good measure return "\r\n"; } + + public function qsos($qsodata, $mylocator) + { + //get codeigniter instance + $CI = &get_instance(); + + //load QRA library + if(!$CI->load->is_loaded('Qra')) { + $CI->load->library('Qra'); + } + + //define helper variables + $locators = []; + $dxccs = []; + $exchanges = []; - public function qso($qsodata) { + //result string + $result = ""; - //Construct QSO detail - $edi_detail = ""; + //iterate through every QSO and construct detail format + foreach ($qsodata->result() as $row) { - $edi_detail .= date('ymd', strtotime($qsodata->COL_TIME_ON)) . ';'; //Date in YYMMDD format - $edi_detail .= date('H:i', strtotime($qsodata->COL_TIME_ON)) . ';'; // Time in HHMM format - $edi_detail .= substr($qsodata->COL_CALL, 0, 14) . ';'; //Callsign, maximum 14 characters - $edi_detail .= $this->reg1testmodecode($qsodata->COL_MODE) . ';'; //Mode-Code in REG1TEST format - $edi_detail .= substr($qsodata->COL_RST_SENT, 0, 3) . ';'; // Sent RST, max 3 characters - $edi_detail .= substr(str_pad($qsodata->COL_STX ?? "", 4, '0', STR_PAD_LEFT), 0, 4) . ';';; //Sent Number of QSO with definitely 4 digits with leading zeros - $edi_detail .= substr($qsodata->COL_RST_RCVD, 0, 3) . ';'; // Received RST, max 3 characters - $edi_detail .= substr(str_pad($qsodata->COL_SRX ?? "", 4, '0', STR_PAD_LEFT), 0, 4) . ';';; //Received Number of QSO with definitely 4 digits with leading zeros - $edi_detail .= substr($qsodata->COL_SRX_STRING ?? "", 0, 6) . ';'; // Received Exchange, max 6 characters - $edi_detail .= strtoupper(substr($qsodata->COL_GRIDSQUARE ?? "" , 0, 6)) . ';'; // Gridsquare max 6 characters - $edi_detail .= ';;;;' . "\r\n"; //Points and "new exchange flags" we know nothing about + $result .= date('ymd', strtotime($row->COL_TIME_ON)) . ';'; //Date in YYMMDD format + $result .= date('Hi', strtotime($row->COL_TIME_ON)) . ';'; //Time in HHMM format + $result .= substr($row->COL_CALL, 0, 14) . ';'; //Callsign, maximum 14 characters + $result .= $this->reg1testmodecode($row->COL_MODE) . ';'; //Mode-Code in REG1TEST format + $result .= substr($row->COL_RST_SENT, 0, 3) . ';'; //Sent RST, max 3 characters + $result .= substr(str_pad($row->COL_STX ?? "", 4, '0', STR_PAD_LEFT), 0, 4) . ';';; //Sent Number of QSO with definitely 4 digits with leading zeros + $result .= substr($row->COL_RST_RCVD, 0, 3) . ';'; //Received RST, max 3 characters + $result .= substr(str_pad($row->COL_SRX ?? "", 4, '0', STR_PAD_LEFT), 0, 4) . ';';; //Received Number of QSO with definitely 4 digits with leading zeros + $result .= substr($row->COL_SRX_STRING ?? "", 0, 6) . ';'; //Received Exchange, max 6 characters + $result .= strtoupper(substr($row->COL_GRIDSQUARE ?? "" , 0, 6)) . ';'; //Gridsquare max 6 characters + + //calculate or get distance in whole kilometers while determening if this is a new locator or not + if(!array_key_exists($row->COL_GRIDSQUARE, $locators)){ + $newlocator = true; + $distance = intval($CI->qra->distance($mylocator, $row->COL_GRIDSQUARE, "K")); + $locators[$row->COL_GRIDSQUARE] = $distance; + }else{ + $newlocator = false; + $distance = $locators[$row->COL_GRIDSQUARE]; + } + + $result .= $distance . ";"; //distance in whole kilometers + + //determine if the exchange is new or not + if(!in_array($row->COL_SRX_STRING, $exchanges)){ + $newexchange = true; + array_push($exchanges, $row->COL_SRX_STRING); + }else{ + $newexchange = false; + } + + $result .= ($newexchange ? 'N' : '') . ';'; //flag if exchange is new + $result .= ($newlocator ? 'N' : '') . ';'; //flag if locator is new + + //determine if DXCC is new or not + if(!in_array($row->COL_DXCC, $dxccs)){ + $newdxcc = true; + array_push($dxccs, $row->COL_DXCC); + }else{ + $newdxcc = false; + } + + $result .= ($newdxcc ? 'N' : '') . ';'; //flag if DXCC is new + + $result .= ";\r\n"; //flag for duplicate QSO. Leave empty as Wavelog does not have this. + + } //return QSO detail - return $edi_detail; - + return $result; } public function reg1testbandstring($band){ diff --git a/application/views/reg1test/export.php b/application/views/reg1test/export.php index f80be3232..5ffbba368 100644 --- a/application/views/reg1test/export.php +++ b/application/views/reg1test/export.php @@ -39,10 +39,8 @@ echo $CI->reg1testformat->header( $maxdistanceqso ); -//write QSO details while keeping track of the QSO number -foreach ($qsos->result() as $row) { - echo $CI->reg1testformat->qso($row); -} +//write QSO details +echo $CI->reg1testformat->qsos($qsos, $gridlocator); -//get footer -echo $CI->reg1testformat->footer(); +//get seperate footer if QSO details won't provide one +echo $qso_count < 1 ? $CI->reg1testformat->footer() : ''; From eaf2bf815d5e8157fde6e921424d6466cb95e9ad Mon Sep 17 00:00:00 2001 From: DB4SCW Date: Tue, 3 Sep 2024 11:43:42 +0000 Subject: [PATCH 2/7] add fields to calculate claimed points --- application/controllers/Reg1test.php | 1 + application/libraries/Reg1testformat.php | 54 +++++++++++++++--------- application/views/reg1test/export.php | 9 +++- application/views/reg1test/index.php | 5 +++ 4 files changed, 46 insertions(+), 23 deletions(-) diff --git a/application/controllers/Reg1test.php b/application/controllers/Reg1test.php index 5b08e9ed3..242ffdbe2 100644 --- a/application/controllers/Reg1test.php +++ b/application/controllers/Reg1test.php @@ -211,6 +211,7 @@ class Reg1test extends CI_Controller { $data['antenna'] = $this->input->post('antenna', true); $data['antennaheight'] = $this->input->post('antennaheight', true); $data['maxdistanceqso'] = $this->qra->getMaxDistanceQSO($station->station_gridsquare, $data['qsos'], "K"); + $data['bandmultiplicator'] = $this->input->post('bandmultiplicator', true); $data['soapbox'] = $this->input->post('soapbox', true); diff --git a/application/libraries/Reg1testformat.php b/application/libraries/Reg1testformat.php index bc8e6c726..7bb696eae 100644 --- a/application/libraries/Reg1testformat.php +++ b/application/libraries/Reg1testformat.php @@ -5,7 +5,7 @@ class Reg1testformat { public function header($contest_id, $from, $to, $callsign, $gridlocator, $contestaddress1, $contestaddress2, $categoryoperator, $band, $club, $name, $responsible_operator, $address1, $address2, $addresspostalcode, $addresscity, $addresscountry, $operatorphone, $operators, - $soapbox, $qso_count, $sentexchange, $txequipment, $power, $rxequipment, $antenna, $antennaheight, $maxdistanceqso) { + $soapbox, $qso_count, $sentexchange, $txequipment, $power, $rxequipment, $antenna, $antennaheight, $maxdistanceqso, $bandmultiplicator, $claimedpoints) { //build header $edi_header = "[REG1TEST;1]" . "\r\n"; @@ -35,8 +35,8 @@ class Reg1testformat { $edi_header .= "SRXEq=" . $rxequipment . "\r\n"; //RX Equipment description $edi_header .= "SAnte=" . $antenna . "\r\n"; //Antenna description $edi_header .= "SAntH=" . $antennaheight . "\r\n"; //Antenna height above ground - $edi_header .= "CQSOs=" . "\r\n"; //Arguments describe the claimed number of valid QSOs and the band multiplier. Leave empty. - $edi_header .= "CQSOP=" . "\r\n"; //Argument describes the claimed total number of QSO-points. Leave empty. + $edi_header .= "CQSOs=" . $qso_count . ';' . $bandmultiplicator . "\r\n"; //Arguments describe the claimed number of valid QSOs and the band multiplier. + $edi_header .= "CQSOP=" . $claimedpoints . "\r\n"; //Argument describes the claimed total number of QSO-points. $edi_header .= "CWWLs=" . "\r\n"; //Arguments describe the claimed number of WWLs worked, the number of bonus points claimed for each new WWL and the WWL multiplier. Leave empty. $edi_header .= "CWWLB=" . "\r\n"; //Argument describes the claimed total number of WWL bonus points. Leave empty. $edi_header .= "CExcs=" . "\r\n"; //Arguments describe the claimed number of Exchanges worked, the number of bonus points claimed for each new Exchange and the Exchange multiplier. Leave empty. @@ -65,7 +65,7 @@ class Reg1testformat { return "\r\n"; } - public function qsos($qsodata, $mylocator) + public function qsos($qsodata, $mylocator, $bandmultiplicator) { //get codeigniter instance $CI = &get_instance(); @@ -80,22 +80,27 @@ class Reg1testformat { $dxccs = []; $exchanges = []; - //result string - $result = ""; + //define result + $result = []; + $result['formatted_result'] = ""; + $result['totalpoints'] = 0; //iterate through every QSO and construct detail format foreach ($qsodata->result() as $row) { - $result .= date('ymd', strtotime($row->COL_TIME_ON)) . ';'; //Date in YYMMDD format - $result .= date('Hi', strtotime($row->COL_TIME_ON)) . ';'; //Time in HHMM format - $result .= substr($row->COL_CALL, 0, 14) . ';'; //Callsign, maximum 14 characters - $result .= $this->reg1testmodecode($row->COL_MODE) . ';'; //Mode-Code in REG1TEST format - $result .= substr($row->COL_RST_SENT, 0, 3) . ';'; //Sent RST, max 3 characters - $result .= substr(str_pad($row->COL_STX ?? "", 4, '0', STR_PAD_LEFT), 0, 4) . ';';; //Sent Number of QSO with definitely 4 digits with leading zeros - $result .= substr($row->COL_RST_RCVD, 0, 3) . ';'; //Received RST, max 3 characters - $result .= substr(str_pad($row->COL_SRX ?? "", 4, '0', STR_PAD_LEFT), 0, 4) . ';';; //Received Number of QSO with definitely 4 digits with leading zeros - $result .= substr($row->COL_SRX_STRING ?? "", 0, 6) . ';'; //Received Exchange, max 6 characters - $result .= strtoupper(substr($row->COL_GRIDSQUARE ?? "" , 0, 6)) . ';'; //Gridsquare max 6 characters + //result string + $qsorow = ""; + + $qsorow .= date('ymd', strtotime($row->COL_TIME_ON)) . ';'; //Date in YYMMDD format + $qsorow .= date('Hi', strtotime($row->COL_TIME_ON)) . ';'; //Time in HHMM format + $qsorow .= substr($row->COL_CALL, 0, 14) . ';'; //Callsign, maximum 14 characters + $qsorow .= $this->reg1testmodecode($row->COL_MODE) . ';'; //Mode-Code in REG1TEST format + $qsorow .= substr($row->COL_RST_SENT, 0, 3) . ';'; //Sent RST, max 3 characters + $qsorow .= substr(str_pad($row->COL_STX ?? "", 3, '0', STR_PAD_LEFT), 0, 4) . ';';; //Sent Number of QSO with 3 digits with leading zeros. If number gets greater than 999, 4 characters are used at maximum + $qsorow .= substr($row->COL_RST_RCVD, 0, 3) . ';'; //Received RST, max 3 characters + $qsorow .= substr(str_pad($row->COL_SRX ?? "", 3, '0', STR_PAD_LEFT), 0, 4) . ';';; //Received Number of QSO with 3 digits with leading zeros. If number gets greater than 999, 4 characters are used at maximum + $qsorow .= substr($row->COL_SRX_STRING ?? "", 0, 6) . ';'; //Received Exchange, max 6 characters + $qsorow .= strtoupper(substr($row->COL_GRIDSQUARE ?? "" , 0, 6)) . ';'; //Gridsquare max 6 characters //calculate or get distance in whole kilometers while determening if this is a new locator or not if(!array_key_exists($row->COL_GRIDSQUARE, $locators)){ @@ -107,7 +112,11 @@ class Reg1testformat { $distance = $locators[$row->COL_GRIDSQUARE]; } - $result .= $distance . ";"; //distance in whole kilometers + //determine QSO points and add those to the total + $qsopoints = intval(round($distance * $bandmultiplicator, 0)); + $result['totalpoints'] += $qsopoints; + + $qsorow .= $qsopoints . ";"; //qso points = distance * bandmultiplicatory //determine if the exchange is new or not if(!in_array($row->COL_SRX_STRING, $exchanges)){ @@ -117,8 +126,8 @@ class Reg1testformat { $newexchange = false; } - $result .= ($newexchange ? 'N' : '') . ';'; //flag if exchange is new - $result .= ($newlocator ? 'N' : '') . ';'; //flag if locator is new + $qsorow .= ($newexchange ? 'N' : '') . ';'; //flag if exchange is new + $qsorow .= ($newlocator ? 'N' : '') . ';'; //flag if locator is new //determine if DXCC is new or not if(!in_array($row->COL_DXCC, $dxccs)){ @@ -128,9 +137,12 @@ class Reg1testformat { $newdxcc = false; } - $result .= ($newdxcc ? 'N' : '') . ';'; //flag if DXCC is new + $qsorow .= ($newdxcc ? 'N' : '') . ';'; //flag if DXCC is new - $result .= ";\r\n"; //flag for duplicate QSO. Leave empty as Wavelog does not have this. + $qsorow .= ";\r\n"; //flag for duplicate QSO. Leave empty as Wavelog does not have this. + + //add row to overall result + $result['formatted_result'] .= $qsorow; } diff --git a/application/views/reg1test/export.php b/application/views/reg1test/export.php index 5ffbba368..26fb5215b 100644 --- a/application/views/reg1test/export.php +++ b/application/views/reg1test/export.php @@ -7,6 +7,9 @@ $CI->load->library('Reg1testformat'); header('Content-Type: text/plain; charset=utf-8'); header('Content-Disposition: attachment; filename="' . $callsign . '-' . $contest_id . '-' . date('Ymd-Hi') . '-' . $CI->reg1testformat->reg1testbandstring($band) . '.edi"'); +//calculate qso details +$qsodetails = $CI->reg1testformat->qsos($qsos, $gridlocator, $bandmultiplicator); + //get header echo $CI->reg1testformat->header( $contest_id, @@ -36,11 +39,13 @@ echo $CI->reg1testformat->header( $rxequipment, $antenna, $antennaheight, - $maxdistanceqso + $maxdistanceqso, + $bandmultiplicator, + $qsodetails['totalpoints'] ); //write QSO details -echo $CI->reg1testformat->qsos($qsos, $gridlocator); +echo $qsodetails['formatted_result']; //get seperate footer if QSO details won't provide one echo $qso_count < 1 ? $CI->reg1testformat->footer() : ''; diff --git a/application/views/reg1test/index.php b/application/views/reg1test/index.php index 77321ce92..f83cb5b73 100644 --- a/application/views/reg1test/index.php +++ b/application/views/reg1test/index.php @@ -130,6 +130,11 @@ +