Rewrote WAS (Worked All States) to the same design as DXCC And IOTA.

这个提交包含在:
AndreasK79 2020-03-29 00:36:18 +01:00
父节点 37f9439089
当前提交 cde55ab338
共有 4 个文件被更改,包括 255 次插入86 次删除

查看文件

@ -276,9 +276,41 @@ class Awards extends CI_Controller {
public function was() { public function was() {
$this->load->model('was'); $this->load->model('was');
$data['was'] = $this->was->show_stats();
$data['worked_bands'] = $this->was->get_worked_bands(); $data['worked_bands'] = $this->was->get_worked_bands();
if ($this->input->post('band') != NULL) { // Band is not set when page first loads.
if ($this->input->post('band') == 'All') { // Did the user specify a band? If not, use all bands
$bands = $data['worked_bands'];
}
else {
$bands[] = $this->input->post('band');
}
}
else {
$bands = $data['worked_bands'];
}
$data['bands'] = $bands; // Used for displaying selected band(s) in the table in the view
if($this->input->method() === 'post') {
$postdata['lotw'] = $this->input->post('lotw');
$postdata['qsl'] = $this->input->post('qsl');
$postdata['worked'] = $this->input->post('worked');
$postdata['confirmed'] = $this->input->post('confirmed');
$postdata['notworked'] = $this->input->post('notworked');
$postdata['band'] = $this->input->post('band');
}
else { // Setting default values at first load of page
$postdata['lotw'] = 1;
$postdata['qsl'] = 1;
$postdata['worked'] = 1;
$postdata['confirmed'] = 1;
$postdata['notworked'] = 1;
$postdata['band'] = 'All';
}
$data['was_array'] = $this->was->get_was_array($bands, $postdata);
// Render Page // Render Page
$data['page_title'] = "Awards - WAS (Worked all states)"; $data['page_title'] = "Awards - WAS (Worked all states)";
$this->load->view('interface_assets/header', $data); $this->load->view('interface_assets/header', $data);

查看文件

@ -258,6 +258,7 @@ class Logbook_model extends CI_Model {
$this->db->where('COL_STATE', $state); $this->db->where('COL_STATE', $state);
$this->db->where_in('COL_DXCC', ['291', '6', '110']); $this->db->where_in('COL_DXCC', ['291', '6', '110']);
if($band != "SAT") { if($band != "SAT") {
$this->db->where('COL_BAND !=', 'SAT');
$this->db->where('COL_BAND', $band); $this->db->where('COL_BAND', $band);
} else { } else {
$this->db->where('COL_PROP_MODE', "SAT"); $this->db->where('COL_PROP_MODE', "SAT");

查看文件

@ -2,6 +2,8 @@
class was extends CI_Model { class was extends CI_Model {
public $stateString = 'AK,AL,AR,AZ,CA,CO,CT,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VA,VT,WA,WI,WV,WY';
public $bandslots = array("160m"=>0, public $bandslots = array("160m"=>0,
"80m"=>0, "80m"=>0,
"60m"=>0, "60m"=>0,
@ -36,22 +38,17 @@ class was extends CI_Model {
$CI->load->model('Stations'); $CI->load->model('Stations');
$station_id = $CI->Stations->find_active(); $station_id = $CI->Stations->find_active();
// get all bands where we have worked states, need to filter on correct dxcc and state (as Cloudlog aren't always setting correct dxcc on import) // get all worked slots from database
$data = $this->db->query( $data = $this->db->query(
"SELECT distinct LOWER(`COL_BAND`) as `COL_BAND` FROM `".$this->config->item('table_name')."` WHERE COL_DXCC in ('291', '6', '110') "SELECT distinct LOWER(`COL_BAND`) as `COL_BAND` FROM `".$this->config->item('table_name')."` WHERE station_id = ".$station_id." AND COL_PROP_MODE != \"SAT\""
and COL_STATE in ('AK','AL','AR','AZ','CA','CO','CT','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VA','VT','WA','WI','WV','WY')
and station_id = ".$station_id." AND COL_PROP_MODE != \"SAT\""
); );
$worked_slots = array(); $worked_slots = array();
foreach($data->result() as $row){ foreach($data->result() as $row){
array_push($worked_slots, $row->COL_BAND); array_push($worked_slots, $row->COL_BAND);
} }
$SAT_data = $this->db->query( $SAT_data = $this->db->query(
"SELECT distinct LOWER(`COL_PROP_MODE`) as `COL_PROP_MODE` FROM `".$this->config->item('table_name')."` WHERE COL_DXCC in ('291', '6', '110') "SELECT distinct LOWER(`COL_PROP_MODE`) as `COL_PROP_MODE` FROM `".$this->config->item('table_name')."` WHERE station_id = ".$station_id." AND COL_PROP_MODE = \"SAT\""
and COL_STATE in ('AK','AL','AR','AZ','CA','CO','CT','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VA','VT','WA','WI','WV','WY')
and station_id = ".$station_id." AND COL_PROP_MODE = \"SAT\""
); );
foreach($SAT_data->result() as $row){ foreach($SAT_data->result() as $row){
@ -65,71 +62,154 @@ class was extends CI_Model {
array_push($results, $slot); array_push($results, $slot);
} }
} }
return $results; return $results;
} }
function show_stats(){ function get_was_array($bands, $postdata) {
$CI =& get_instance(); $CI =& get_instance();
$CI->load->model('Stations'); $CI->load->model('Stations');
$station_id = $CI->Stations->find_active(); $station_id = $CI->Stations->find_active();
$data = $this->db->query( $stateArray = explode(',', $this->stateString);
"select COL_STATE, COL_MODE, lcase(COL_BAND) as COL_BAND, count(COL_STATE) as cnt
from ".$this->config->item('table_name')."
where station_id = ".$station_id." AND COL_PROP_MODE != \"SAT\"
and COL_DXCC in ('291', '6', '110')
and COL_STATE in ('AK','AL','AR','AZ','CA','CO','CT','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VA','VT','WA','WI','WV','WY')
group by COL_STATE, COL_MODE, COL_BAND"
);
$results = array(); $states = array(); // Used for keeping track of which states that are not worked
$last_state = "";
foreach($data->result() as $row){ foreach ($bands as $band) {
if ($last_state != $row->COL_STATE){ foreach ($stateArray as $state) { // Generating array for use in the table
// new row $bandWas[$state][$band] = '-'; // Sets all to dash to indicate no result
$results[$row->COL_STATE] = $this->bandslots; $states[$state]['count'] = 0; // Inits each state's count
$last_state = $row->COL_STATE;
} }
// update stats if ($postdata['worked'] != NULL) {
if (!isset($results[$row->COL_STATE])) $wasBand = $this->getWasWorked($station_id, $band, $postdata);
$results[$row->COL_STATE] = []; foreach ($wasBand as $line) {
$bandWas[$line->col_state][$band] = '<div class="alert-danger"><a href=\'was_details?State="' . str_replace("&", "%26", $line->col_state) . '"&Band="' . $band . '"\'>W</a></div>';
if (!isset($results[$row->COL_STATE][$row->COL_BAND])) $states[$line->col_state]['count']++;
$results[$row->COL_STATE][$row->COL_BAND] = 0; }
}
$results[$row->COL_STATE][$row->COL_BAND] += $row->cnt; if ($postdata['confirmed'] != NULL) {
} $wasBand = $this->getWasConfirmed($station_id, $band, $postdata);
foreach ($wasBand as $line) {
// Satellite WAS $bandWas[$line->col_state][$band] = '<div class="alert-success"><a href=\'was_details?State="' . str_replace("&", "%26", $line->col_state) . '"&Band="' . $band . '"\'>C</a></div>';
$satellite_data = $this->db->query( $states[$line->col_state]['count']++;
"select COL_STATE, COL_PROP_MODE as COL_PROP_MODE, count(COL_STATE) as cnt }
from ".$this->config->item('table_name')."
where station_id = ".$station_id." AND COL_PROP_MODE = \"SAT\"
and COL_DXCC in ('291', '6', '110')
and COL_STATE in ('AK','AL','AR','AZ','CA','CO','CT','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VA','VT','WA','WI','WV','WY')
group by COL_STATE"
);
foreach($satellite_data->result() as $row){
if ($last_state != $row->COL_STATE){
// new row
$results[$row->COL_STATE] = $this->bandslots;
$last_state = $row->COL_STATE;
} }
// update stats
if (!isset($results[$row->COL_STATE]))
$results[$row->COL_STATE] = [];
if (!isset($results[$row->COL_STATE][$row->COL_PROP_MODE]))
$results[$row->COL_STATE][$row->COL_PROP_MODE] = 0;
$results[$row->COL_STATE][$row->COL_PROP_MODE] += $row->cnt;
} }
return $results; // We want to remove the worked states in the list, since we do not want to display them
if ($postdata['worked'] == NULL) {
$wasBand = $this->getWasWorked($station_id, $postdata['band'], $postdata);
foreach ($wasBand as $line) {
unset($bandWas[$line->col_state]);
}
}
// We want to remove the confirmed states in the list, since we do not want to display them
if ($postdata['confirmed'] == NULL) {
$wasBand = $this->getWasConfirmed($station_id, $postdata['band'], $postdata);
foreach ($wasBand as $line) {
unset($bandWas[$line->col_state]);
}
}
if ($postdata['notworked'] == NULL) {
foreach ($stateArray as $state) {
if ($states[$state]['count'] == 0) {
unset($bandWas[$state]);
};
}
}
if (isset($bandWas)) {
return $bandWas;
}
else {
return 0;
}
}
/*
* Function returns all worked, but not confirmed states
* $postdata contains data from the form, in this case Lotw or QSL are used
*/
function getWasWorked($station_id, $band, $postdata) {
$sql = "SELECT distinct col_state FROM " . $this->config->item('table_name') . " thcv
where station_id = " . $station_id;
$sql .= $this->addStateToQuery();
$sql .= $this->addBandToQuery($band);
$sql .= " and not exists (select 1 from ". $this->config->item('table_name') .
" where station_id = ". $station_id .
" and col_state = thcv.col_state";
$sql .= $this->addBandToQuery($band);
$sql .= $this->addQslToQuery($postdata);
$sql .= $this->addStateToQuery();
$sql .= ")";
$query = $this->db->query($sql);
return $query->result();
}
/*
* Function returns all confirmed states on given band and on LoTW or QSL
* $postdata contains data from the form, in this case Lotw or QSL are used
*/
function getWasConfirmed($station_id, $band, $postdata) {
$sql = "SELECT distinct col_state FROM " . $this->config->item('table_name') . " thcv
where station_id = " . $station_id;
$sql .= $this->addStateToQuery();
$sql .= $this->addBandToQuery($band);
$sql .= $this->addQslToQuery($postdata);
$query = $this->db->query($sql);
return $query->result();
}
function addQslToQuery($postdata) {
$sql = '';
if ($postdata['lotw'] != NULL and $postdata['qsl'] == NULL) {
$sql .= " and col_lotw_qsl_rcvd = 'Y'";
}
if ($postdata['qsl'] != NULL and $postdata['lotw'] == NULL) {
$sql .= " and col_qsl_rcvd = 'Y'";
}
if ($postdata['qsl'] != NULL && $postdata['lotw'] != NULL) {
$sql .= " and (col_qsl_rcvd = 'Y' or col_lotw_qsl_rcvd = 'Y')";
}
return $sql;
}
function addBandToQuery($band) {
$sql = '';
if ($band != 'All') {
if ($band == 'SAT') {
$sql .= " and col_prop_mode ='" . $band . "'";
} else {
$sql .= " and col_prop_mode !='SAT'";
$sql .= " and col_band ='" . $band . "'";
}
}
return $sql;
}
function addStateToQuery() {
$sql = '';
$sql .= " and COL_DXCC in ('291', '6', '110')";
$sql .= " and COL_STATE in ('AK','AL','AR','AZ','CA','CO','CT','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MO','MS','MT','NC','ND','NE','NH','NJ','NM','NV','NY','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VA','VT','WA','WI','WV','WY')";
return $sql;
} }
} }
?> ?>

查看文件

@ -5,36 +5,92 @@
<!-- Sub Nav for Awards --> <!-- Sub Nav for Awards -->
<?php $this->load->view("awards/nav_bar")?> <?php $this->load->view("awards/nav_bar")?>
<form class="form" action="<?php echo site_url('awards/was'); ?>" method="post" enctype="multipart/form-data">
<fieldset>
<table class="table table-striped table-hover"> <!-- Multiple Checkboxes (inline) -->
<div class="form-group row">
<div class="col-md-2" for="checkboxes">Worked / confirmed</div>
<div class="col-md-10">
<div class="form-check-inline">
<input class="form-check-input" type="checkbox" name="worked" id="worked" value="1" <?php if ($this->input->post('worked') || $this->input->method() !== 'post') echo ' checked="checked"'; ?> >
<label class="form-check-label" for="worked">Show worked</label>
</div>
<div class="form-check-inline">
<input class="form-check-input" type="checkbox" name="confirmed" id="confirmed" value="1" <?php if ($this->input->post('confirmed') || $this->input->method() !== 'post') echo ' checked="checked"'; ?> >
<label class="form-check-label" for="confirmed">Show confirmed</label>
</div>
<div class="form-check-inline">
<input class="form-check-input" type="checkbox" name="notworked" id="notworked" value="1" <?php if ($this->input->post('notworked') || $this->input->method() !== 'post') echo ' checked="checked"'; ?> >
<label class="form-check-label" for="notworked">Show not worked</label>
</div>
</div>
</div>
<div class="form-group row">
<div class="col-md-2">QSL / LoTW</div>
<div class="col-md-10">
<div class="form-check-inline">
<input class="form-check-input" type="checkbox" name="qsl" value="1" id="qsl" <?php if ($this->input->post('qsl') || $this->input->method() !== 'post') echo ' checked="checked"'; ?> >
<label class="form-check-label" for="qsl">QSL</label>
</div>
<div class="form-check-inline">
<input class="form-check-input" type="checkbox" name="lotw" value="1" id="lotw" <?php if ($this->input->post('lotw') || $this->input->method() !== 'post') echo ' checked="checked"'; ?> >
<label class="form-check-label" for="lotw">LoTW</label>
</div>
</div>
</div>
<!-- Select Basic -->
<div class="form-group row">
<label class="col-md-2 control-label" for="band">Band</label>
<div class="col-md-2">
<select id="band2" name="band" class="form-control">
<option value="All" <?php if ($this->input->post('band') == "All" || $this->input->method() !== 'post') echo ' selected'; ?> >Every band</option>
<?php foreach($worked_bands as $band) {
echo '<option value="' . $band . '"';
if ($this->input->post('band') == $band) echo ' selected';
echo '>' . $band . '</option>'."\n";
} ?>
</select>
</div>
</div>
<!-- Button (Double) -->
<div class="form-group row">
<label class="col-md-2 control-label" for="button1id"></label>
<div class="col-md-10">
<button id="button2id" type="reset" name="button2id" class="btn btn-danger">Reset</button>
<button id="button1id" type="submit" name="button1id" class="btn btn-success btn-primary">Show</button>
</div>
</div>
</fieldset>
</form>
<?php
if ($was_array) {
echo '
<table class="table table-bordered table-hover table-striped table-condensed text-center">
<thead> <thead>
<tr> <tr>
<td style="width:225px">WAS (<?php echo count($was)?>)</td> <td>State</td>';
<?php foreach($bands as $band) {
foreach ($worked_bands as $slot) { echo '<td>' . $band . '</td>';
echo " <td>$slot</td>\n";
} }
?> echo '</tr>
</tr>
</thead> </thead>
<tbody> <tbody>';
<?php foreach ($was_array as $was => $value) { // Fills the table with the data
foreach($was as $state=>$val){ echo '<tr>
print("<tr><td>$state</td>"); <td>'. $was .'</td>';
foreach($val as $band=>$count){ foreach ($value as $key) {
if (in_array($band, $worked_bands)) { echo '<td style="text-align: center">' . $key . '</td>';
if ($count == 0){
print("<td>&nbsp;</td>");
}else{
printf("<td><a href='was_details?State=\"%s\"&Band=\"%s\"'>%d</a></td>", str_replace("&", "%26", $state), $band, $count);
}
}
} }
print("</tr>"); echo '</tr>';
} }
echo '</tfoot></table></div>';
?> }
</tbody> else {
echo '<div class="alert alert-danger" role="alert"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>Nothing found!</div>';
</table> }
</div>