Revert "Merge pull request #584 from AndreasK79/longest_streak"
This reverts commitae11d17ff0, reversing changes made toccac7f1828.
这个提交包含在:
		
							父节点
							
								
									7663684ba7
								
							
						
					
					
						当前提交
						f8b6a6e83a
					
				
					共有  3 个文件被更改,包括 2 次插入 和 91 次删除
				
			
		|  | @ -18,7 +18,6 @@ class Dayswithqso extends CI_Controller { | ||||||
|         $data['page_title'] = "Number of days with QSOs each year"; |         $data['page_title'] = "Number of days with QSOs each year"; | ||||||
| 
 | 
 | ||||||
|         $data['result'] = $this->dayswithqso_model->getDaysWithQso(); |         $data['result'] = $this->dayswithqso_model->getDaysWithQso(); | ||||||
|         $data['streaks'] = $this->dayswithqso_model->getLongestStreak(); |  | ||||||
| 
 | 
 | ||||||
|         $this->load->view('interface_assets/header', $data); |         $this->load->view('interface_assets/header', $data); | ||||||
|         $this->load->view('dayswithqso/index'); |         $this->load->view('dayswithqso/index'); | ||||||
|  |  | ||||||
|  | @ -15,6 +15,8 @@ class Dayswithqso_model extends CI_Model | ||||||
|         $CI->load->model('Stations'); |         $CI->load->model('Stations'); | ||||||
|         $station_id = $CI->Stations->find_active(); |         $station_id = $CI->Stations->find_active(); | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|         $sql = "select year(COL_TIME_ON) Year, COUNT(DISTINCT TO_DAYS(COL_TIME_ON)) as Days from " |         $sql = "select year(COL_TIME_ON) Year, COUNT(DISTINCT TO_DAYS(COL_TIME_ON)) as Days from " | ||||||
|             .$this->config->item('table_name'). " thcv
 |             .$this->config->item('table_name'). " thcv
 | ||||||
|             where station_id = " . $station_id . " and COL_TIME_ON is not null group by year";
 |             where station_id = " . $station_id . " and COL_TIME_ON is not null group by year";
 | ||||||
|  | @ -24,69 +26,4 @@ class Dayswithqso_model extends CI_Model | ||||||
|         return $query->result(); |         return $query->result(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /* |  | ||||||
|      * Function returns the 10 longest streaks of QSOs based on all QSO dates in the log on active station profile |  | ||||||
|      */ |  | ||||||
|     function getLongestStreak() { |  | ||||||
|         $dates = $this->getDates(); |  | ||||||
|         $streak = 1;        // A day with a qso will always be a streak
 |  | ||||||
|         $dateprev = date_create('1900-01-01'); // init variable with an old date
 |  | ||||||
|         $i = 0; |  | ||||||
| 
 |  | ||||||
|         foreach($dates as $date) {      // Loop through the result set
 |  | ||||||
|             $datecurr = date_create($date->date); |  | ||||||
|             if ($dateprev == date_create('1900-01-01')) { // If first run
 |  | ||||||
|                 $dateprev = $datecurr; |  | ||||||
|             } |  | ||||||
|             else { |  | ||||||
|                 $diff = $dateprev->diff($datecurr)->format("%a"); // Getting date difference between current date and previous date in array
 |  | ||||||
|                 if ($diff == 1) {   // If diff = 1, means that we are on a streak
 |  | ||||||
|                     $streak++; |  | ||||||
|                     $endstreak = $datecurr; // As long as the streak continues, we update the end date
 |  | ||||||
|                 } else { |  | ||||||
|                     if ($streak > 1) { |  | ||||||
|                         $streaks[$i]['highstreak'] = $streak; |  | ||||||
|                         $streaks[$i]['endstreak'] = $endstreak->format('Y-m-d'); |  | ||||||
|                         $streaks[$i]['beginstreak'] = $endstreak->sub(new DateInterval('P'.($streak-1).'D'))->format('Y-m-d'); |  | ||||||
|                         $i++; |  | ||||||
|                     } |  | ||||||
|                     $streak = 1; |  | ||||||
|                 } |  | ||||||
|                 $dateprev = date_create($date->date); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         if (isset($streaks) && is_array($streaks)) { |  | ||||||
|             usort($streaks, array($this,'compareStreak'));      // Sort array, highest streak first
 |  | ||||||
|             $streaks_trimmed = array_slice($streaks, 0,10);  // We only want top 10, so we trim the array
 |  | ||||||
|             return $streaks_trimmed; |  | ||||||
|         } else { |  | ||||||
|             return null; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /* |  | ||||||
|      * Used for sorting the arraym highest streak first |  | ||||||
|      */ |  | ||||||
|     function compareStreak($a, $b) { |  | ||||||
|         return strnatcmp($b['highstreak'], $a['highstreak']); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /* |  | ||||||
|      * Returns all distinct dates from db on active profile |  | ||||||
|      */ |  | ||||||
|     function getDates() { |  | ||||||
|         $CI =& get_instance(); |  | ||||||
|         $CI->load->model('Stations'); |  | ||||||
|         $station_id = $CI->Stations->find_active(); |  | ||||||
| 
 |  | ||||||
|         $sql = "select distinct cast(col_time_on as date) as date from " |  | ||||||
|             .$this->config->item('table_name'). " thcv
 |  | ||||||
|             where station_id = " . $station_id . " order by col_time_on asc";
 |  | ||||||
| 
 |  | ||||||
|         $query = $this->db->query($sql); |  | ||||||
| 
 |  | ||||||
|         return $query->result(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| } | } | ||||||
|  | @ -30,29 +30,4 @@ | ||||||
|     } |     } | ||||||
|     ?>
 |     ?>
 | ||||||
|     <canvas id="myChartDiff" width="400" height="150"></canvas> |     <canvas id="myChartDiff" width="400" height="150"></canvas> | ||||||
|     <h2>Longest streak with QSOs in the log</h2> |  | ||||||
|     <?php |  | ||||||
|     if (is_array($streaks)) { |  | ||||||
|         echo '<div id="streaks" class="table-responsive"><table class="qsotable table table-bordered table-hover table-striped table-condensed">'; |  | ||||||
| 
 |  | ||||||
|             echo '<tr>'; |  | ||||||
|                 echo '<th style=\'text-align: center\'>Streak (Continues days with QSOs)</th>'; |  | ||||||
|                 echo '<th style=\'text-align: center\'>Begin date</th>'; |  | ||||||
|                 echo '<th style=\'text-align: center\'>End date</th>'; |  | ||||||
|                 echo '</tr>'; |  | ||||||
| 
 |  | ||||||
|             foreach ($streaks as $streak) { |  | ||||||
|                 echo '<tr>'; |  | ||||||
|                 echo '<td style=\'text-align: center\'>' . $streak['highstreak'] . '</td>'; |  | ||||||
|                 echo '<td style=\'text-align: center\'>' . $streak['beginstreak'] . '</td>'; |  | ||||||
|                 echo '<td style=\'text-align: center\'>' . $streak['endstreak'] . '</td>'; |  | ||||||
|                 echo '</tr>'; |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             echo '</table></div>'; |  | ||||||
|     } |  | ||||||
|     else { |  | ||||||
|         echo '<div class="alert alert-danger" role="alert"><a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>No streak found!</div>'; |  | ||||||
|     } |  | ||||||
|     ?>
 |  | ||||||
| </div> | </div> | ||||||
|  |  | ||||||
		正在加载…
	
		在新工单中引用