Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

87 righe
3.2 KiB

  1. <?php
  2. class Conn {
  3. private $con;
  4. public function __construct() {
  5. $this->con = new SQLite3("/home/pi/raspberry-noaa/panel.db");
  6. }
  7. public function getPasses() {
  8. $today = strtotime(date('Y-m-d', time()));
  9. $query = $this->con->query("SELECT sat_name, is_active,
  10. pass_start, pass_end,
  11. max_elev FROM predict_passes
  12. WHERE (pass_start > $today) ORDER BY
  13. pass_start ASC;");
  14. $passes = [];
  15. $i = 0;
  16. while($row = $query->fetchArray()){
  17. $passes[$i] = $row;
  18. $i++;
  19. }
  20. return $passes;
  21. }
  22. public function totalPages($img_per_page) {
  23. $total_pages = $this->con->querySingle("SELECT count() from decoded_passes;");
  24. return ceil($total_pages/$img_per_page);
  25. }
  26. public function getImages($page, $img_per_page) {
  27. $query = $this->con->prepare("SELECT decoded_passes.id, predict_passes.pass_start,
  28. file_path, sat_type, predict_passes.sat_name, predict_passes.max_elev
  29. FROM decoded_passes INNER JOIN predict_passes
  30. ON predict_passes.pass_start = decoded_passes.pass_start
  31. ORDER BY decoded_passes.pass_start DESC LIMIT ? OFFSET ?;");
  32. $query->bindValue(1, $img_per_page);
  33. $query->bindValue(2, $img_per_page * ($page-1));
  34. $result = $query->execute();
  35. $images = [];
  36. $i = 0;
  37. while($row = $result->fetchArray()){
  38. $images[$i] = $row;
  39. $i++;
  40. }
  41. return $images;
  42. }
  43. public function getEnhacements($id) {
  44. $query = $this->con->prepare('SELECT daylight_pass, sat_type, img_count
  45. FROM decoded_passes WHERE id = ?;');
  46. $query->bindValue(1, $id);
  47. $result = $query->execute();
  48. $pass = $result->fetchArray();
  49. switch($pass['sat_type']) {
  50. case 0: // Meteor-M2
  51. $enhacements = ['-122-rectified.jpg'];
  52. break;
  53. case 1: // NOAA
  54. if ($pass['daylight_pass'] == 1) {
  55. $enhacements = ['-ZA.jpg','-MCIR.jpg','-MCIR-precip.jpg','-MSA.jpg','-MSA-precip.jpg','-HVC.jpg','-HVC-precip.jpg','-HVCT.jpg','-HVCT-precip.jpg'];
  56. } else {
  57. $enhacements = ['-ZA.jpg','-MCIR.jpg','-MCIR-precip.jpg'];
  58. }
  59. break;
  60. case 2: // ISS
  61. if ($pass['img_count'] == 1) {
  62. $enhacements[] = "-0.png";
  63. } else {
  64. for ($x = 0; $x <= $pass['img_count']; $x+=1) {
  65. $enhacements[] = "-$x.png";
  66. }
  67. }
  68. break;
  69. }
  70. return $enhacements;
  71. }
  72. public function getPath($id) {
  73. $query = $this->con->prepare('SELECT file_path FROM decoded_passes
  74. WHERE id = ?;');
  75. $query->bindValue(1, $id);
  76. $result = $query->execute();
  77. $image = $result->fetchArray();
  78. return $image['file_path'];
  79. }
  80. }
  81. ?>