| Conditions | 107 |
| Paths | > 20000 |
| Total Lines | 486 |
| Code Lines | 369 |
| Lines | 147 |
| Ratio | 30.25 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 913 | public function addOldStats() { |
||
| 914 | global $globalArchiveMonths, $globalArchive, $globalArchiveYear, $globalDBdriver; |
||
| 915 | $Common = new Common(); |
||
| 916 | $Connection = new Connection(); |
||
| 917 | date_default_timezone_set('UTC'); |
||
| 918 | $last_update = $this->getLastStatsUpdate('last_update_stats'); |
||
| 919 | //print_r($last_update); |
||
| 920 | $flightsbymonth = $this->getStats('flights_by_month'); |
||
| 921 | if (empty($last_update) && empty($flightsbymonth)) { |
||
| 922 | // Initial update |
||
| 923 | $Spotter = new Spotter($this->db); |
||
| 924 | $alldata = $Spotter->countAllMonths(); |
||
| 925 | $lastyear = false; |
||
| 926 | View Code Duplication | foreach ($alldata as $number) { |
|
|
1 ignored issue
–
show
|
|||
| 927 | if ($number['year_name'] != date('Y')) $lastyear = true; |
||
| 928 | $this->addStat('flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
||
| 929 | } |
||
| 930 | $alldata = $Spotter->countAllMilitaryMonths(); |
||
| 931 | $lastyear = false; |
||
| 932 | View Code Duplication | foreach ($alldata as $number) { |
|
|
1 ignored issue
–
show
|
|||
| 933 | if ($number['year_name'] != date('Y')) $lastyear = true; |
||
| 934 | $this->addStat('military_flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
||
| 935 | } |
||
| 936 | $alldata = $Spotter->countAllMonthsOwners(); |
||
| 937 | View Code Duplication | foreach ($alldata as $number) { |
|
|
1 ignored issue
–
show
|
|||
| 938 | $this->addStat('owners_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
||
| 939 | } |
||
| 940 | $alldata = $Spotter->countAllMonthsPilots(); |
||
| 941 | View Code Duplication | foreach ($alldata as $number) { |
|
|
1 ignored issue
–
show
|
|||
| 942 | $this->addStat('pilots_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
||
| 943 | } |
||
| 944 | $alldata = $Spotter->countAllMonthsAirlines(); |
||
| 945 | View Code Duplication | foreach ($alldata as $number) { |
|
|
1 ignored issue
–
show
|
|||
| 946 | $this->addStat('airlines_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
||
| 947 | } |
||
| 948 | $alldata = $Spotter->countAllMonthsAircrafts(); |
||
| 949 | View Code Duplication | foreach ($alldata as $number) { |
|
|
1 ignored issue
–
show
|
|||
| 950 | $this->addStat('aircrafts_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
||
| 951 | } |
||
| 952 | $alldata = $Spotter->countAllMonthsRealArrivals(); |
||
| 953 | View Code Duplication | foreach ($alldata as $number) { |
|
|
1 ignored issue
–
show
|
|||
| 954 | $this->addStat('realarrivals_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
||
| 955 | } |
||
| 956 | $this->deleteStatFlight('month'); |
||
| 957 | $alldata = $Spotter->countAllDatesLastMonth(); |
||
| 958 | foreach ($alldata as $number) { |
||
| 959 | $this->addStatFlight('month',$number['date_name'],$number['date_count']); |
||
| 960 | } |
||
| 961 | $previousdata = $this->countAllDates(); |
||
| 962 | $this->deleteStatFlight('date'); |
||
| 963 | $alldata = $Common->array_merge_noappend($previousdata,$Spotter->countAllDates()); |
||
| 964 | $values = array(); |
||
| 965 | foreach ($alldata as $cnt) { |
||
| 966 | $values[] = $cnt['date_count']; |
||
| 967 | } |
||
| 968 | array_multisort($values,SORT_DESC,$alldata); |
||
| 969 | array_splice($alldata,11); |
||
| 970 | foreach ($alldata as $number) { |
||
| 971 | $this->addStatFlight('date',$number['date_name'],$number['date_count']); |
||
| 972 | } |
||
| 973 | $this->deleteStatFlight('hour'); |
||
| 974 | $alldata = $Spotter->countAllHours('hour'); |
||
| 975 | foreach ($alldata as $number) { |
||
| 976 | $this->addStatFlight('hour',$number['hour_name'],$number['hour_count']); |
||
| 977 | } |
||
| 978 | if ($lastyear) { |
||
| 979 | $monthsSinceLastYear = date('n'); |
||
| 980 | $alldata = $Spotter->countAllAircraftTypes(false,$monthsSinceLastYear); |
||
| 981 | foreach ($alldata as $number) { |
||
| 982 | $this->addStatAircraft($number['aircraft_icao'],$number['aircraft_icao_count'],$number['aircraft_name']); |
||
| 983 | } |
||
| 984 | $alldata = $Spotter->countAllAirlines(false,$monthsSinceLastYear); |
||
| 985 | foreach ($alldata as $number) { |
||
| 986 | $this->addStatAirline($number['airline_icao'],$number['airline_count'],$number['airline_name']); |
||
| 987 | } |
||
| 988 | View Code Duplication | if ($Connection->tableExists('countries')) { |
|
|
1 ignored issue
–
show
|
|||
| 989 | $alldata = $Spotter->countAllFlightOverCountries(false,$monthsSinceLastYear); |
||
| 990 | foreach ($alldata as $number) { |
||
| 991 | $this->addStatCountry($number['flight_country_iso2'],$number['flight_country_iso3'],$number['flight_country'],$number['flight_count']); |
||
| 992 | } |
||
| 993 | } |
||
| 994 | $alldata = $Spotter->countAllOwners(false,$monthsSinceLastYear); |
||
| 995 | foreach ($alldata as $number) { |
||
| 996 | $this->addStatOwner($number['owner_name'],$number['owner_count']); |
||
| 997 | } |
||
| 998 | $alldata = $Spotter->countAllPilots(false,$monthsSinceLastYear); |
||
| 999 | foreach ($alldata as $number) { |
||
| 1000 | $this->addStatPilot($number['pilot_id'],$number['pilot_count']); |
||
| 1001 | } |
||
| 1002 | $previous_year = date('Y'); |
||
| 1003 | $previous_year--; |
||
| 1004 | $this->addStat('aircrafts_byyear',$this->getStatsAircraftTotal(),$previous_year.'-01-01 00:00:00'); |
||
| 1005 | $this->addStat('airlines_byyear',$this->getStatsAirlineTotal(),$previous_year.'-01-01 00:00:00'); |
||
| 1006 | $this->addStat('owner_byyear',$this->getStatsOwnerTotal(),$previous_year.'-01-01 00:00:00'); |
||
| 1007 | $this->addStat('pilot_byyear',$this->getStatsPilotTotal(),$previous_year.'-01-01 00:00:00'); |
||
| 1008 | |||
| 1009 | View Code Duplication | if (isset($globalArchiveYear) && $globalArchiveYear) { |
|
|
1 ignored issue
–
show
|
|||
| 1010 | if ($globalArchive) { |
||
| 1011 | $query = "INSERT INTO spotter_archive_output SELECT * FROM spotter_output WHERE spotter_output.date < '".date('Y')."-01-01 00:00:00'"; |
||
| 1012 | //echo $query; |
||
| 1013 | try { |
||
| 1014 | $sth = $this->db->prepare($query); |
||
|
1 ignored issue
–
show
|
|||
| 1015 | $sth->execute(); |
||
| 1016 | } catch(PDOException $e) { |
||
| 1017 | return "error : ".$e->getMessage().' - query : '.$query."\n"; |
||
| 1018 | } |
||
| 1019 | } |
||
| 1020 | $query = "DELETE FROM spotter_output WHERE spotter_output.date < '".date('Y')."-01-01 00:00:00'"; |
||
| 1021 | try { |
||
| 1022 | $sth = $this->db->prepare($query); |
||
|
1 ignored issue
–
show
|
|||
| 1023 | $sth->execute(); |
||
| 1024 | } catch(PDOException $e) { |
||
| 1025 | return "error : ".$e->getMessage().' - query : '.$query."\n"; |
||
| 1026 | } |
||
| 1027 | } |
||
| 1028 | } |
||
| 1029 | if (!isset($globalArchiveMonths) || $globalArchiveMonths == '') $globalArchiveMonths = 2; |
||
| 1030 | if ($globalArchiveMonths > 0) { |
||
| 1031 | $alldata = $Spotter->countAllAircraftTypes(false,$globalArchiveMonths); |
||
| 1032 | foreach ($alldata as $number) { |
||
| 1033 | $this->addStatAircraft($number['aircraft_icao'],$number['aircraft_icao_count'],$number['aircraft_name']); |
||
| 1034 | } |
||
| 1035 | $alldata = $Spotter->countAllAirlines(false,$globalArchiveMonths); |
||
| 1036 | foreach ($alldata as $number) { |
||
| 1037 | $this->addStatAirline($number['airline_icao'],$number['airline_count'],$number['airline_name']); |
||
| 1038 | } |
||
| 1039 | $alldata = $Spotter->countAllAircraftRegistrations(false,$globalArchiveMonths); |
||
| 1040 | foreach ($alldata as $number) { |
||
| 1041 | $this->addStatAircraftRegistration($number['registration'],$number['aircraft_registration_count'],$number['aircraft_icao']); |
||
| 1042 | } |
||
| 1043 | $alldata = $Spotter->countAllCallsigns(false,$globalArchiveMonths); |
||
| 1044 | foreach ($alldata as $number) { |
||
| 1045 | $this->addStatCallsign($number['callsign_icao'],$number['callsign_icao_count'],$number['airline_icao']); |
||
| 1046 | } |
||
| 1047 | $alldata = $Spotter->countAllOwners(false,$globalArchiveMonths); |
||
| 1048 | foreach ($alldata as $number) { |
||
| 1049 | $this->addStatOwner($number['owner_name'],$number['owner_count']); |
||
| 1050 | } |
||
| 1051 | View Code Duplication | if ($Connection->tableExists('countries')) { |
|
|
1 ignored issue
–
show
|
|||
| 1052 | $alldata = $Spotter->countAllFlightOverCountries(false,$globalArchiveMonths); |
||
| 1053 | foreach ($alldata as $number) { |
||
| 1054 | $this->addStatCountry($number['flight_country_iso2'],$number['flight_country_iso3'],$number['flight_country'],$number['flight_count']); |
||
| 1055 | } |
||
| 1056 | } |
||
| 1057 | $alldata = $Spotter->countAllPilots(false,$globalArchiveMonths); |
||
| 1058 | foreach ($alldata as $number) { |
||
| 1059 | $this->addStatPilot($number['pilot_id'],$number['pilot_count']); |
||
| 1060 | } |
||
| 1061 | $pall = $Spotter->countAllDepartureAirports(false,$globalArchiveMonths); |
||
| 1062 | $dall = $Spotter->countAllDetectedDepartureAirports(false,$globalArchiveMonths); |
||
| 1063 | $alldata = array(); |
||
| 1064 | foreach ($pall as $value) { |
||
| 1065 | $icao = $value['airport_departure_icao']; |
||
| 1066 | $alldata[$icao] = $value; |
||
| 1067 | } |
||
| 1068 | foreach ($dall as $value) { |
||
| 1069 | $icao = $value['airport_departure_icao']; |
||
| 1070 | if (isset($alldata[$icao])) { |
||
| 1071 | $alldata[$icao]['airport_departure_icao_count'] = $alldata[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count']; |
||
| 1072 | } else $alldata[$icao] = $value; |
||
| 1073 | } |
||
| 1074 | $count = array(); |
||
| 1075 | foreach ($alldata as $key => $row) { |
||
| 1076 | $count[$key] = $row['airport_departure_icao_count']; |
||
| 1077 | } |
||
| 1078 | array_multisort($count,SORT_DESC,$alldata); |
||
| 1079 | |||
| 1080 | //print_r($alldate); |
||
| 1081 | View Code Duplication | foreach ($alldata as $number) { |
|
|
1 ignored issue
–
show
|
|||
| 1082 | $this->addStatDepartureAirports($number['airport_departure_icao'],$number['airport_departure_name'],$number['airport_departure_city'],$number['airport_departure_country'],$number['airport_departure_icao_count']); |
||
| 1083 | } |
||
| 1084 | $pdata = $Spotter->countAllArrivalAirports(false,$globalArchiveMonths); |
||
| 1085 | $dall = $Spotter->countAllDetectedArrivalAirports(false,$globalArchiveMonths); |
||
| 1086 | $alldata = array(); |
||
| 1087 | foreach ($pdata as $value) { |
||
| 1088 | $icao = $value['airport_arrival_icao']; |
||
| 1089 | $alldata[$icao] = $value; |
||
| 1090 | } |
||
| 1091 | foreach ($dall as $value) { |
||
| 1092 | $icao = $value['airport_arrival_icao']; |
||
| 1093 | if (isset($alldata[$icao])) { |
||
| 1094 | $alldata[$icao]['airport_arrival_icao_count'] = $alldata[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count']; |
||
| 1095 | } else $alldata[$icao] = $value; |
||
| 1096 | } |
||
| 1097 | $count = array(); |
||
| 1098 | foreach ($alldata as $key => $row) { |
||
| 1099 | $count[$key] = $row['airport_arrival_icao_count']; |
||
| 1100 | } |
||
| 1101 | array_multisort($count,SORT_DESC,$alldata); |
||
| 1102 | View Code Duplication | foreach ($alldata as $number) { |
|
|
1 ignored issue
–
show
|
|||
| 1103 | $this->addStatArrivalAirports($number['airport_arrival_icao'],$number['airport_arrival_name'],$number['airport_arrival_city'],$number['airport_arrival_country'],$number['airport_arrival_icao_count']); |
||
| 1104 | } |
||
| 1105 | $this->addStat('aircrafts_byyear',$this->getStatsAircraftTotal(),date('Y').'-01-01 00:00:00'); |
||
| 1106 | $this->addStat('airlines_byyear',$this->getStatsAirlineTotal(),date('Y').'-01-01 00:00:00'); |
||
| 1107 | $this->addStat('owner_byyear',$this->getStatsOwnerTotal(),date('Y').'-01-01 00:00:00'); |
||
| 1108 | $this->addStat('pilot_byyear',$this->getStatsPilotTotal(),date('Y').'-01-01 00:00:00'); |
||
| 1109 | |||
| 1110 | View Code Duplication | if ($globalArchive) { |
|
|
1 ignored issue
–
show
|
|||
| 1111 | if ($globalDBdriver == 'mysql') { |
||
| 1112 | $query = "INSERT INTO spotter_archive_output SELECT * FROM spotter_output WHERE spotter_output.date < DATE_FORMAT(UTC_TIMESTAMP() - INTERVAL ".$globalArchiveMonths." MONTH, '%Y/%m/01')"; |
||
| 1113 | } else { |
||
| 1114 | $query = "INSERT INTO spotter_archive_output SELECT * FROM spotter_output WHERE spotter_output.date < CAST(to_char(CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveMonths." MONTHS', 'YYYY/mm/01') AS TIMESTAMP)"; |
||
| 1115 | } |
||
| 1116 | try { |
||
| 1117 | $sth = $this->db->prepare($query); |
||
|
1 ignored issue
–
show
|
|||
| 1118 | $sth->execute(); |
||
| 1119 | } catch(PDOException $e) { |
||
| 1120 | return "error : ".$e->getMessage().' - query : '.$query."\n"; |
||
| 1121 | } |
||
| 1122 | } |
||
| 1123 | |||
| 1124 | //$query = 'DELETE FROM spotter_output WHERE spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$globalArchiveMonths.' MONTH)'; |
||
| 1125 | if ($globalDBdriver == 'mysql') { |
||
| 1126 | $query = "DELETE FROM spotter_output WHERE spotter_output.date < DATE_FORMAT(UTC_TIMESTAMP() - INTERVAL ".$globalArchiveMonths." MONTH, '%Y/%m/01')"; |
||
| 1127 | } else { |
||
| 1128 | $query = "DELETE FROM spotter_output WHERE spotter_output.date < CAST(to_char(CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveMonths." MONTHS, 'YYYY/mm/01') AS TIMESTAMP)"; |
||
| 1129 | } |
||
| 1130 | try { |
||
| 1131 | $sth = $this->db->prepare($query); |
||
|
1 ignored issue
–
show
|
|||
| 1132 | $sth->execute(); |
||
| 1133 | } catch(PDOException $e) { |
||
| 1134 | return "error : ".$e->getMessage().' - query : '.$query."\n"; |
||
| 1135 | } |
||
| 1136 | } |
||
| 1137 | $this->addLastStatsUpdate('last_update_stats',date('Y-m-d G:i:s')); |
||
| 1138 | } else { |
||
| 1139 | echo 'Update stats !'."\n"; |
||
| 1140 | if (isset($last_update[0]['value'])) { |
||
| 1141 | $last_update_day = $last_update[0]['value']; |
||
| 1142 | } else $last_update_day = '2012-12-12 12:12:12'; |
||
| 1143 | $Spotter = new Spotter($this->db); |
||
| 1144 | $alldata = $Spotter->countAllAircraftTypes(false,0,$last_update_day); |
||
| 1145 | foreach ($alldata as $number) { |
||
| 1146 | $this->addStatAircraft($number['aircraft_icao'],$number['aircraft_icao_count'],$number['aircraft_name']); |
||
| 1147 | } |
||
| 1148 | $alldata = $Spotter->countAllAirlines(false,0,$last_update_day); |
||
| 1149 | foreach ($alldata as $number) { |
||
| 1150 | $this->addStatAirline($number['airline_icao'],$number['airline_count'],$number['airline_name']); |
||
| 1151 | } |
||
| 1152 | $alldata = $Spotter->countAllAircraftRegistrations(false,0,$last_update_day); |
||
| 1153 | foreach ($alldata as $number) { |
||
| 1154 | $this->addStatAircraftRegistration($number['registration'],$number['aircraft_registration_count'],$number['aircraft_icao']); |
||
| 1155 | } |
||
| 1156 | $alldata = $Spotter->countAllCallsigns(false,0,$last_update_day); |
||
| 1157 | foreach ($alldata as $number) { |
||
| 1158 | $this->addStatCallsign($number['callsign_icao'],$number['callsign_icao_count'],$number['airline_icao']); |
||
| 1159 | } |
||
| 1160 | $alldata = $Spotter->countAllOwners(false,0,$last_update_day); |
||
| 1161 | foreach ($alldata as $number) { |
||
| 1162 | $this->addStatOwner($number['owner_name'],$number['owner_count']); |
||
| 1163 | } |
||
| 1164 | $alldata = $Spotter->countAllPilots(false,0,$last_update_day); |
||
| 1165 | foreach ($alldata as $number) { |
||
| 1166 | $this->addStatPilot($number['pilot_id'],$number['pilot_count']); |
||
| 1167 | } |
||
| 1168 | $pall = $Spotter->countAllDepartureAirports(false,0,$last_update_day); |
||
| 1169 | $dall = $Spotter->countAllDetectedDepartureAirports(false,0,$last_update_day); |
||
| 1170 | $alldata = array(); |
||
| 1171 | foreach ($pall as $value) { |
||
| 1172 | $icao = $value['airport_departure_icao']; |
||
| 1173 | $alldata[$icao] = $value; |
||
| 1174 | } |
||
| 1175 | foreach ($dall as $value) { |
||
| 1176 | $icao = $value['airport_departure_icao']; |
||
| 1177 | if (isset($alldata[$icao])) { |
||
| 1178 | $alldata[$icao]['airport_departure_icao_count'] = $alldata[$icao]['airport_departure_icao_count'] + $value['airport_departure_icao_count']; |
||
| 1179 | } else $alldata[$icao] = $value; |
||
| 1180 | } |
||
| 1181 | $count = array(); |
||
| 1182 | foreach ($alldata as $key => $row) { |
||
| 1183 | $count[$key] = $row['airport_departure_icao_count']; |
||
| 1184 | } |
||
| 1185 | array_multisort($count,SORT_DESC,$alldata); |
||
| 1186 | |||
| 1187 | View Code Duplication | foreach ($alldata as $number) { |
|
|
1 ignored issue
–
show
|
|||
| 1188 | $this->addStatDepartureAirports($number['airport_departure_icao'],$number['airport_departure_name'],$number['airport_departure_city'],$number['airport_departure_country'],$number['airport_departure_icao_count']); |
||
| 1189 | } |
||
| 1190 | $pall = $Spotter->countAllArrivalAirports(false,0,$last_update_day); |
||
| 1191 | $dall = $Spotter->countAllDetectedArrivalAirports(false,0,$last_update_day); |
||
| 1192 | $alldata = array(); |
||
| 1193 | foreach ($pall as $value) { |
||
| 1194 | $icao = $value['airport_arrival_icao']; |
||
| 1195 | $alldata[$icao] = $value; |
||
| 1196 | } |
||
| 1197 | foreach ($dall as $value) { |
||
| 1198 | $icao = $value['airport_arrival_icao']; |
||
| 1199 | if (isset($alldata[$icao])) { |
||
| 1200 | $alldata[$icao]['airport_arrival_icao_count'] = $alldata[$icao]['airport_arrival_icao_count'] + $value['airport_arrival_icao_count']; |
||
| 1201 | } else $alldata[$icao] = $value; |
||
| 1202 | } |
||
| 1203 | $count = array(); |
||
| 1204 | foreach ($alldata as $key => $row) { |
||
| 1205 | $count[$key] = $row['airport_arrival_icao_count']; |
||
| 1206 | } |
||
| 1207 | array_multisort($count,SORT_DESC,$alldata); |
||
| 1208 | View Code Duplication | foreach ($alldata as $number) { |
|
|
1 ignored issue
–
show
|
|||
| 1209 | $this->addStatArrivalAirports($number['airport_arrival_icao'],$number['airport_arrival_name'],$number['airport_arrival_city'],$number['airport_arrival_country'],$number['airport_arrival_icao_count']); |
||
| 1210 | } |
||
| 1211 | View Code Duplication | if ($Connection->tableExists('countries')) { |
|
|
1 ignored issue
–
show
|
|||
| 1212 | $SpotterArchive = new SpotterArchive(); |
||
| 1213 | $alldata = $SpotterArchive->countAllFlightOverCountries(false,0,$last_update_day); |
||
| 1214 | foreach ($alldata as $number) { |
||
| 1215 | $this->addStatCountry($number['flight_country_iso2'],$number['flight_country_iso3'],$number['flight_country'],$number['flight_count']); |
||
| 1216 | } |
||
| 1217 | } |
||
| 1218 | |||
| 1219 | |||
| 1220 | // Add by month using getstat if month finish... |
||
| 1221 | |||
| 1222 | //if (date('m',strtotime($last_update_day)) != date('m')) { |
||
| 1223 | $Spotter = new Spotter($this->db); |
||
| 1224 | $alldata = $Spotter->countAllMonths(); |
||
| 1225 | $lastyear = false; |
||
| 1226 | View Code Duplication | foreach ($alldata as $number) { |
|
|
1 ignored issue
–
show
|
|||
| 1227 | if ($number['year_name'] != date('Y')) $lastyear = true; |
||
| 1228 | $this->addStat('flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
||
| 1229 | } |
||
| 1230 | $alldata = $Spotter->countAllMilitaryMonths(); |
||
| 1231 | View Code Duplication | foreach ($alldata as $number) { |
|
|
1 ignored issue
–
show
|
|||
| 1232 | $this->addStat('military_flights_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
||
| 1233 | } |
||
| 1234 | $alldata = $Spotter->countAllMonthsOwners(); |
||
| 1235 | View Code Duplication | foreach ($alldata as $number) { |
|
|
1 ignored issue
–
show
|
|||
| 1236 | $this->addStat('owners_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
||
| 1237 | } |
||
| 1238 | $alldata = $Spotter->countAllMonthsPilots(); |
||
| 1239 | View Code Duplication | foreach ($alldata as $number) { |
|
|
1 ignored issue
–
show
|
|||
| 1240 | $this->addStat('pilots_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
||
| 1241 | } |
||
| 1242 | $alldata = $Spotter->countAllMonthsAirlines(); |
||
| 1243 | View Code Duplication | foreach ($alldata as $number) { |
|
|
1 ignored issue
–
show
|
|||
| 1244 | $this->addStat('airlines_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
||
| 1245 | } |
||
| 1246 | $alldata = $Spotter->countAllMonthsAircrafts(); |
||
| 1247 | View Code Duplication | foreach ($alldata as $number) { |
|
|
1 ignored issue
–
show
|
|||
| 1248 | $this->addStat('aircrafts_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
||
| 1249 | } |
||
| 1250 | $alldata = $Spotter->countAllMonthsRealArrivals(); |
||
| 1251 | View Code Duplication | foreach ($alldata as $number) { |
|
|
1 ignored issue
–
show
|
|||
| 1252 | $this->addStat('realarrivals_bymonth',$number['date_count'],date('Y-m-d H:i:s',mktime(0,0,0,$number['month_name'],1,$number['year_name']))); |
||
| 1253 | } |
||
| 1254 | echo 'Airports data...'."\n"; |
||
| 1255 | echo '...Departure'."\n"; |
||
| 1256 | $this->deleteStatAirport('daily'); |
||
| 1257 | $pall = $Spotter->getLast7DaysAirportsDeparture(); |
||
| 1258 | $dall = $Spotter->getLast7DaysDetectedAirportsDeparture(); |
||
| 1259 | $alldata = array(); |
||
| 1260 | foreach ($pall as $value) { |
||
| 1261 | $icao = $value['departure_airport_icao']; |
||
| 1262 | $alldata[$icao] = $value; |
||
| 1263 | } |
||
| 1264 | foreach ($dall as $value) { |
||
| 1265 | $icao = $value['departure_airport_icao']; |
||
| 1266 | if (isset($alldata[$icao])) { |
||
| 1267 | $alldata[$icao]['departure_airport_count'] = $alldata[$icao]['departure_airport_count'] + $value['departure_airport_count']; |
||
| 1268 | } else $alldata[$icao] = $value; |
||
| 1269 | } |
||
| 1270 | $count = array(); |
||
| 1271 | foreach ($alldata as $key => $row) { |
||
| 1272 | $count[$key] = $row['departure_airport_count']; |
||
| 1273 | } |
||
| 1274 | array_multisort($count,SORT_DESC,$alldata); |
||
| 1275 | foreach ($alldata as $number) { |
||
| 1276 | $this->addStatDepartureAirportsDaily($number['date'],$number['departure_airport_icao'],$number['departure_airport_name'],$number['departure_airport_city'],$number['departure_airport_country'],$number['departure_airport_count']); |
||
| 1277 | } |
||
| 1278 | echo '...Arrival'."\n"; |
||
| 1279 | $pall = $Spotter->getLast7DaysAirportsArrival(); |
||
| 1280 | $dall = $Spotter->getLast7DaysDetectedAirportsArrival(); |
||
| 1281 | $alldata = array(); |
||
| 1282 | foreach ($pall as $value) { |
||
| 1283 | $icao = $value['arrival_airport_icao']; |
||
| 1284 | $alldata[$icao] = $value; |
||
| 1285 | } |
||
| 1286 | foreach ($dall as $value) { |
||
| 1287 | $icao = $value['arrival_airport_icao']; |
||
| 1288 | if (isset($alldata[$icao])) { |
||
| 1289 | $alldata[$icao]['arrival_airport_icao_count'] = $alldata[$icao]['arrival_airport_count'] + $value['arrival_airport_count']; |
||
| 1290 | } else $alldata[$icao] = $value; |
||
| 1291 | } |
||
| 1292 | $count = array(); |
||
| 1293 | foreach ($alldata as $key => $row) { |
||
| 1294 | $count[$key] = $row['arrival_airport_count']; |
||
| 1295 | } |
||
| 1296 | array_multisort($count,SORT_DESC,$alldata); |
||
| 1297 | |||
| 1298 | foreach ($alldata as $number) { |
||
| 1299 | $this->addStatArrivalAirportsDaily($number['date'],$number['arrival_airport_icao'],$number['arrival_airport_name'],$number['arrival_airport_city'],$number['arrival_airport_country'],$number['arrival_airport_count']); |
||
| 1300 | } |
||
| 1301 | |||
| 1302 | echo 'Flights data...'."\n"; |
||
| 1303 | $this->deleteStatFlight('month'); |
||
| 1304 | echo '-> countAllDatesLastMonth...'."\n"; |
||
| 1305 | $alldata = $Spotter->countAllDatesLastMonth(); |
||
| 1306 | foreach ($alldata as $number) { |
||
| 1307 | $this->addStatFlight('month',$number['date_name'],$number['date_count']); |
||
| 1308 | } |
||
| 1309 | echo '-> countAllDates...'."\n"; |
||
| 1310 | $previousdata = $this->countAllDates(); |
||
| 1311 | $this->deleteStatFlight('date'); |
||
| 1312 | $alldata = $Common->array_merge_noappend($previousdata,$Spotter->countAllDates()); |
||
| 1313 | $values = array(); |
||
| 1314 | foreach ($alldata as $cnt) { |
||
| 1315 | $values[] = $cnt['date_count']; |
||
| 1316 | } |
||
| 1317 | array_multisort($values,SORT_DESC,$alldata); |
||
| 1318 | array_splice($alldata,11); |
||
| 1319 | foreach ($alldata as $number) { |
||
| 1320 | $this->addStatFlight('date',$number['date_name'],$number['date_count']); |
||
| 1321 | } |
||
| 1322 | |||
| 1323 | $this->deleteStatFlight('hour'); |
||
| 1324 | echo '-> countAllHours...'."\n"; |
||
| 1325 | $alldata = $Spotter->countAllHours('hour'); |
||
| 1326 | foreach ($alldata as $number) { |
||
| 1327 | $this->addStatFlight('hour',$number['hour_name'],$number['hour_count']); |
||
| 1328 | } |
||
| 1329 | if ($lastyear) { |
||
| 1330 | echo 'Data from last year...'."\n"; |
||
| 1331 | // SUM all previous month to put as year |
||
| 1332 | $previous_year = date('Y'); |
||
| 1333 | $previous_year--; |
||
| 1334 | $this->addStat('aircrafts_byyear',$this->getSumStats('aircrafts_bymonth',$previous_year),$previous_year.'-01-01 00:00:00'); |
||
| 1335 | $this->addStat('airlines_byyear',$this->getSumStats('airlines_bymonth',$previous_year),$previous_year.'-01-01 00:00:00'); |
||
| 1336 | $this->addStat('owner_byyear',$this->getSumStats('owner_bymonth',$previous_year),$previous_year.'-01-01 00:00:00'); |
||
| 1337 | $this->addStat('pilot_byyear',$this->getSumStats('pilot_bymonth',$previous_year),$previous_year.'-01-01 00:00:00'); |
||
| 1338 | |||
| 1339 | View Code Duplication | if (isset($globalArchiveYear) && $globalArchiveYear) { |
|
|
1 ignored issue
–
show
|
|||
| 1340 | if ($globalArchive) { |
||
| 1341 | $query = "INSERT INTO spotter_archive_output SELECT * FROM spotter_output WHERE spotter_output.date < '".date('Y')."-01-01 00:00:00'"; |
||
| 1342 | try { |
||
| 1343 | $sth = $this->db->prepare($query); |
||
|
1 ignored issue
–
show
|
|||
| 1344 | $sth->execute(); |
||
| 1345 | } catch(PDOException $e) { |
||
| 1346 | return "error : ".$e->getMessage().' - query : '.$query."\n"; |
||
| 1347 | } |
||
| 1348 | } |
||
| 1349 | echo 'Delete old data'."\n"; |
||
| 1350 | $query = "DELETE FROM spotter_output WHERE spotter_output.date < '".date('Y')."-01-01 00:00:00'"; |
||
| 1351 | try { |
||
| 1352 | $sth = $this->db->prepare($query); |
||
|
1 ignored issue
–
show
|
|||
| 1353 | $sth->execute(); |
||
| 1354 | } catch(PDOException $e) { |
||
| 1355 | return "error : ".$e->getMessage().' - query : '.$query."\n"; |
||
| 1356 | } |
||
| 1357 | } |
||
| 1358 | } |
||
| 1359 | if ($globalArchiveMonths > 0) { |
||
| 1360 | View Code Duplication | if ($globalArchive) { |
|
|
1 ignored issue
–
show
|
|||
| 1361 | echo 'Archive old data...'."\n"; |
||
| 1362 | if ($globalDBdriver == 'mysql') { |
||
| 1363 | //$query = "INSERT INTO spotter_archive_output SELECT * FROM spotter_output WHERE spotter_output.date < DATE_FORMAT(UTC_TIMESTAMP() - INTERVAL ".$globalArchiveMonths." MONTH, '%Y/%m/01')"; |
||
| 1364 | $query = "INSERT INTO spotter_archive_output (spotter_id,flightaware_id,ident,registration,airline_name,airline_icao,airline_country,airline_type,aircraft_icao,aircraft_name,aircraft_manufacturer,departure_airport_icao,departure_airport_name,departure_airport_city,departure_airport_country,departure_airport_time,arrival_airport_icao,arrival_airport_name,arrival_airport_city,arrival_airport_country,arrival_airport_time,route_stop,date,latitude,longitude,waypoints,altitude,heading,ground_speed,highlight,squawk,ModeS,pilot_id,pilot_name,owner_name,verticalrate,format_source,source_name,ground,last_ground,last_seen,last_latitude,last_longitude,last_altitude,last_ground_speed,real_arrival_airport_icao,real_arrival_airport_time,real_departure_airport_icao,real_departure_airport_time) |
||
| 1365 | SELECT spotter_id,flightaware_id,ident,registration,airline_name,airline_icao,airline_country,airline_type,aircraft_icao,aircraft_name,aircraft_manufacturer,departure_airport_icao,departure_airport_name,departure_airport_city,departure_airport_country,departure_airport_time,arrival_airport_icao,arrival_airport_name,arrival_airport_city,arrival_airport_country,arrival_airport_time,route_stop,date,latitude,longitude,waypoints,altitude,heading,ground_speed,highlight,squawk,ModeS,pilot_id,pilot_name,owner_name,verticalrate,format_source,source_name,ground,last_ground,last_seen,last_latitude,last_longitude,last_altitude,last_ground_speed,real_arrival_airport_icao,real_arrival_airport_time,real_departure_airport_icao,real_departure_airport_time |
||
| 1366 | FROM spotter_output WHERE spotter_output.date < DATE_FORMAT(UTC_TIMESTAMP() - INTERVAL ".$globalArchiveMonths." MONTH, '%Y/%m/01')"; |
||
| 1367 | } else { |
||
| 1368 | $query = "INSERT INTO spotter_archive_output (spotter_id,flightaware_id,ident,registration,airline_name,airline_icao,airline_country,airline_type,aircraft_icao,aircraft_name,aircraft_manufacturer,departure_airport_icao,departure_airport_name,departure_airport_city,departure_airport_country,departure_airport_time,arrival_airport_icao,arrival_airport_name,arrival_airport_city,arrival_airport_country,arrival_airport_time,route_stop,date,latitude,longitude,waypoints,altitude,heading,ground_speed,highlight,squawk,ModeS,pilot_id,pilot_name,owner_name,verticalrate,format_source,source_name,ground,last_ground,last_seen,last_latitude,last_longitude,last_altitude,last_ground_speed,real_arrival_airport_icao,real_arrival_airport_time,real_departure_airport_icao,real_departure_airport_time) |
||
| 1369 | SELECT |
||
| 1370 | spotter_id,flightaware_id,ident,registration,airline_name,airline_icao,airline_country,airline_type,aircraft_icao,aircraft_name,aircraft_manufacturer,departure_airport_icao,departure_airport_name,departure_airport_city,departure_airport_country,departure_airport_time,arrival_airport_icao,arrival_airport_name,arrival_airport_city,arrival_airport_country,arrival_airport_time,route_stop,date,latitude,longitude,waypoints,altitude,heading,ground_speed,highlight,squawk,ModeS,pilot_id,pilot_name,owner_name,verticalrate,format_source,source_name,ground,last_ground,last_seen,last_latitude,last_longitude,last_altitude,last_ground_speed,real_arrival_airport_icao,real_arrival_airport_time,real_departure_airport_icao,real_departure_airport_time |
||
| 1371 | FROM spotter_output WHERE spotter_output.date < CAST(to_char(CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveMonths." MONTHS', 'YYYY/mm/01') AS TIMESTAMP)"; |
||
| 1372 | } |
||
| 1373 | try { |
||
| 1374 | $sth = $this->db->prepare($query); |
||
|
1 ignored issue
–
show
|
|||
| 1375 | $sth->execute(); |
||
| 1376 | } catch(PDOException $e) { |
||
| 1377 | return "error : ".$e->getMessage(); |
||
| 1378 | } |
||
| 1379 | } |
||
| 1380 | echo 'Deleting old data...'."\n"; |
||
| 1381 | //$query = 'DELETE FROM spotter_output WHERE spotter_output.date < DATE_SUB(UTC_TIMESTAMP(), INTERVAL '.$globalArchiveMonths.' MONTH)'; |
||
| 1382 | if ($globalDBdriver == 'mysql') { |
||
| 1383 | $query = "DELETE FROM spotter_output WHERE spotter_output.date < DATE_FORMAT(UTC_TIMESTAMP() - INTERVAL ".$globalArchiveMonths." MONTH, '%Y/%m/01')"; |
||
| 1384 | } else { |
||
| 1385 | $query = "DELETE FROM spotter_output WHERE spotter_output.date < CAST(to_char(CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalArchiveMonths." MONTHS', 'YYYY/mm/01') AS TIMESTAMP)"; |
||
| 1386 | } |
||
| 1387 | try { |
||
| 1388 | $sth = $this->db->prepare($query); |
||
|
1 ignored issue
–
show
|
|||
| 1389 | $sth->execute(); |
||
| 1390 | } catch(PDOException $e) { |
||
| 1391 | return "error : ".$e->getMessage(); |
||
| 1392 | } |
||
| 1393 | } |
||
| 1394 | echo 'Insert last stats update date...'."\n"; |
||
| 1395 | date_default_timezone_set('UTC'); |
||
| 1396 | $this->addLastStatsUpdate('last_update_stats',date('Y-m-d G:i:s')); |
||
| 1397 | } |
||
| 1398 | } |
||
| 1399 | } |
||
| 1401 | ?> |
||
|
1 ignored issue
–
show
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.