Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Conn.php 3.1 KiB

3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
3 år sedan
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. for ($x = 0; $x <= $$pass['img_count']; $x+=1) {
  62. $enhacements[] = "-$x.png";
  63. }
  64. break;
  65. }
  66. return $enhacements;
  67. }
  68. public function getPath($id) {
  69. $query = $this->con->prepare('SELECT file_path FROM decoded_passes
  70. WHERE id = ?;');
  71. $query->bindValue(1, $id);
  72. $result = $query->execute();
  73. $image = $result->fetchArray();
  74. return $image['file_path'];
  75. }
  76. }
  77. ?>