|
19 | 19 | }, |
20 | 20 | "outputs": [], |
21 | 21 | "source": [ |
22 | | - "import pandas as pd\n", |
23 | | - "import matplotlib.pyplot as plt" |
| 22 | + "import pandas as pd" |
24 | 23 | ] |
25 | 24 | }, |
26 | 25 | { |
|
120 | 119 | "for one_day in tqdm(daterange(start_date, end_date)):\n", |
121 | 120 | " params = {\n", |
122 | 121 | " \"access_key\": \"12925396bddce38222e47eed53e76e6c\",\n", |
123 | | - " #\"dep_iata\": \"BEY\",\n", |
124 | | - " 'arr_iata': 'BEY',\n", |
| 122 | + " # \"dep_iata\": \"BEY\",\n", |
| 123 | + " \"arr_iata\": \"BEY\",\n", |
125 | 124 | " \"limit\": \"100\",\n", |
126 | 125 | " # To get the next 100 flights we need to change the offset\n", |
127 | 126 | " \"offset\": \"100\",\n", |
|
221 | 220 | " HoverTool,\n", |
222 | 221 | " Label,\n", |
223 | 222 | " Span,\n", |
224 | | - " Panel,\n", |
225 | 223 | " Tabs,\n", |
226 | | - " TabPanel\n", |
| 224 | + " TabPanel,\n", |
227 | 225 | ")\n", |
228 | 226 | "from bokeh.palettes import Spectral6\n", |
229 | 227 | "\n", |
|
242 | 240 | " df_reindexed = df_reindexed.reset_index().rename(columns={\"index\": \"flight_date\"})\n", |
243 | 241 | "\n", |
244 | 242 | " df[\"total_flights\"] = df.groupby(\"flight_date\")[\"iata_arr\"].transform(\"sum\")\n", |
245 | | - " if acled_events_daily['nrEvents'].max()<500:\n", |
| 243 | + " if acled_events_daily[\"nrEvents\"].max() < 500:\n", |
246 | 244 | " max_flight = acled_events_daily[\"nrEvents\"].max() + 50\n", |
247 | 245 | " else:\n", |
248 | 246 | " max_flight = acled_events_daily[\"nrEvents\"].max() + 200\n", |
|
256 | 254 | " height=600,\n", |
257 | 255 | " width=800,\n", |
258 | 256 | " title=title,\n", |
259 | | - " toolbar_location='above',\n", |
| 257 | + " toolbar_location=\"above\",\n", |
260 | 258 | " tools=\"pan,box_zoom,reset,save\",\n", |
261 | 259 | " x_axis_label=\"Flight Date\",\n", |
262 | 260 | " y_axis_label=\"Nr Flights\",\n", |
|
346 | 344 | " span = Span(\n", |
347 | 345 | " location=event_timestamp,\n", |
348 | 346 | " dimension=\"height\",\n", |
349 | | - " line_color='#C6C6C6',\n", |
| 347 | + " line_color=\"#C6C6C6\",\n", |
350 | 348 | " line_width=2,\n", |
351 | | - " line_dash=(4, 4)\n", |
| 349 | + " line_dash=(4, 4),\n", |
352 | 350 | " )\n", |
353 | 351 | " p.renderers.append(span)\n", |
354 | 352 | "\n", |
355 | 353 | " # Determine a base y position for the label\n", |
356 | | - " base_y = max_flight - (max_flight/5) # Adjust for visibility above the plot\n", |
| 354 | + " base_y = max_flight - (\n", |
| 355 | + " max_flight / 5\n", |
| 356 | + " ) # Adjust for visibility above the plot\n", |
357 | 357 | " y_position = base_y # Default position\n", |
358 | 358 | "\n", |
359 | 359 | " # Adjust y_position if it overlaps with previous labels\n", |
|
398 | 398 | " pd.read_csv(\"../../data/aviation/aviationstack_bey_25082024_01012024_dep2.csv\"),\n", |
399 | 399 | " pd.read_csv(\"../../data/aviation/aviationstack_bey_15082024_07102024_dep.csv\"),\n", |
400 | 400 | " pd.read_csv(\"../../data/aviation/aviationstack_bey_15082024_07102024_dep2.csv\"),\n", |
401 | | - " pd.read_csv('../../data/aviation/aviationstack_bey_07102024_23102024_dep.csv'),\n", |
402 | | - " pd.read_csv('../../data/aviation/aviationstack_bey_07102024_23102024_dep2.csv')\n", |
| 401 | + " pd.read_csv(\"../../data/aviation/aviationstack_bey_07102024_23102024_dep.csv\"),\n", |
| 402 | + " pd.read_csv(\"../../data/aviation/aviationstack_bey_07102024_23102024_dep2.csv\"),\n", |
403 | 403 | " ]\n", |
404 | 404 | ")\n", |
405 | 405 | "departures.drop(columns=\"Unnamed: 0\", inplace=True)\n", |
|
696 | 696 | "# '2024-06-07', '2024-06-08', '2024-06-09', '2024-09-02']\n", |
697 | 697 | "\n", |
698 | 698 | "events = {\n", |
699 | | - " #\"2024-06-09\":\"Airline data\\nnot available\",\n", |
700 | | - " \"2024-04-14\": \"Temporary shutdown of\\nLebanese airspace between\\n7AM and 1PM\",\n", |
701 | | - " \"2024-08-25\":\"Israeli strikes in\\nSouthern Lebanon\",\n", |
702 | | - " \"2024-09-23\":\"Start of the full blown conflict\"\n", |
703 | | - " }" |
| 699 | + " # \"2024-06-09\":\"Airline data\\nnot available\",\n", |
| 700 | + " \"2024-04-14\": \"Temporary shutdown of\\nLebanese airspace between\\n7AM and 1PM\",\n", |
| 701 | + " \"2024-08-25\": \"Israeli strikes in\\nSouthern Lebanon\",\n", |
| 702 | + " \"2024-09-23\": \"Start of the full blown conflict\",\n", |
| 703 | + "}" |
704 | 704 | ] |
705 | 705 | }, |
706 | 706 | { |
|
1102 | 1102 | " \"Most Changed Departures\": most_changed_departures,\n", |
1103 | 1103 | " \"Most Cancelled Departures\": most_cancelled_departures,\n", |
1104 | 1104 | " \"Most Scheduled Departures\": most_scheduled_departures,\n", |
1105 | | - " \"Most Diverted Departures\": most_diverted_departures\n", |
| 1105 | + " \"Most Diverted Departures\": most_diverted_departures,\n", |
1106 | 1106 | "}\n", |
1107 | 1107 | "\n", |
1108 | 1108 | "# Initialize an empty list to store the tabs\n", |
|
1118 | 1118 | " source = ColumnDataSource(data)\n", |
1119 | 1119 | "\n", |
1120 | 1120 | " # Create a figure for each dataset\n", |
1121 | | - " p = figure(y_range=data['airportcity'], width=600, height=400, title=title + \" in 2024\", tools=\"save\", toolbar_location=\"above\")\n", |
1122 | | - " p.hbar(y='airportcity', right='count', height=0.5, color=color, alpha=0.7, source=source)\n", |
| 1121 | + " p = figure(\n", |
| 1122 | + " y_range=data[\"airportcity\"],\n", |
| 1123 | + " width=600,\n", |
| 1124 | + " height=400,\n", |
| 1125 | + " title=title + \" in 2024\",\n", |
| 1126 | + " tools=\"save\",\n", |
| 1127 | + " toolbar_location=\"above\",\n", |
| 1128 | + " )\n", |
| 1129 | + " p.hbar(\n", |
| 1130 | + " y=\"airportcity\",\n", |
| 1131 | + " right=\"count\",\n", |
| 1132 | + " height=0.5,\n", |
| 1133 | + " color=color,\n", |
| 1134 | + " alpha=0.7,\n", |
| 1135 | + " source=source,\n", |
| 1136 | + " )\n", |
1123 | 1137 | "\n", |
1124 | 1138 | " # Add text inside the bars (5 points inside the bar)\n", |
1125 | | - " p.text(x='count', y='airportcity', text='count', source=source, \n", |
1126 | | - " x_offset=-5, # This places the text 5 units inside the bar\n", |
1127 | | - " y_offset=-3, # Vertical alignment\n", |
1128 | | - " text_align='right', text_baseline='middle', text_color=\"black\", text_font_size=\"10pt\")\n", |
| 1139 | + " p.text(\n", |
| 1140 | + " x=\"count\",\n", |
| 1141 | + " y=\"airportcity\",\n", |
| 1142 | + " text=\"count\",\n", |
| 1143 | + " source=source,\n", |
| 1144 | + " x_offset=-5, # This places the text 5 units inside the bar\n", |
| 1145 | + " y_offset=-3, # Vertical alignment\n", |
| 1146 | + " text_align=\"right\",\n", |
| 1147 | + " text_baseline=\"middle\",\n", |
| 1148 | + " text_color=\"black\",\n", |
| 1149 | + " text_font_size=\"10pt\",\n", |
| 1150 | + " )\n", |
1129 | 1151 | "\n", |
1130 | 1152 | " # Customize plot (optional)\n", |
1131 | 1153 | " p.xaxis.visible = False\n", |
1132 | 1154 | " p.ygrid.visible = False\n", |
1133 | 1155 | " p.xgrid.visible = False\n", |
1134 | 1156 | " p.yaxis.major_tick_line_color = None # No major ticks\n", |
1135 | 1157 | " p.yaxis.minor_tick_line_color = None # No minor ticks\n", |
1136 | | - " p.yaxis.axis_line_color = None \n", |
| 1158 | + " p.yaxis.axis_line_color = None\n", |
1137 | 1159 | " p.outline_line_color = None\n", |
1138 | 1160 | "\n", |
1139 | | - " subtitle = Div(text=f\"<p style='font-size:12px; color:gray;'>Source: AviationStack. Acessed October 7th 2024.</p>\", width=600)\n", |
| 1161 | + " subtitle = Div(\n", |
| 1162 | + " text=\"<p style='font-size:12px; color:gray;'>Source: AviationStack. Acessed October 7th 2024.</p>\",\n", |
| 1163 | + " width=600,\n", |
| 1164 | + " )\n", |
1140 | 1165 | "\n", |
1141 | 1166 | " layout = column(p, subtitle)\n", |
1142 | 1167 | "\n", |
|
1149 | 1174 | "# Arrange the tabs in a Tabs layout\n", |
1150 | 1175 | "tabs_layout = Tabs(tabs=tabs)\n", |
1151 | 1176 | "\n", |
1152 | | - "main_title = Div(text=\"<h2>Top 10 Destinations with Changes in Departures from BEY in 2024</h2>\", width=800)\n", |
| 1177 | + "main_title = Div(\n", |
| 1178 | + " text=\"<h2>Top 10 Destinations with Changes in Departures from BEY in 2024</h2>\",\n", |
| 1179 | + " width=800,\n", |
| 1180 | + ")\n", |
1153 | 1181 | "\n", |
1154 | 1182 | "# Use column layout to stack the title on top of the tabs\n", |
1155 | 1183 | "layout = column(main_title, tabs_layout)\n", |
|
1270 | 1298 | " pd.read_csv(\"../../data/aviation/aviationstack_bey_26082024_01012024_arr.csv\"),\n", |
1271 | 1299 | " pd.read_csv(\"../../data/aviation/aviationstack_bey_15082024_07102024_arr.csv\"),\n", |
1272 | 1300 | " pd.read_csv(\"../../data/aviation/aviationstack_bey_15082024_07102024_arr2.csv\"),\n", |
1273 | | - " pd.read_csv('../../data/aviation/aviationstack_bey_07102024_23102024_arr.csv'),\n", |
1274 | | - " pd.read_csv('../../data/aviation/aviationstack_bey_07102024_23102024_arr2.csv')\n", |
| 1301 | + " pd.read_csv(\"../../data/aviation/aviationstack_bey_07102024_23102024_arr.csv\"),\n", |
| 1302 | + " pd.read_csv(\"../../data/aviation/aviationstack_bey_07102024_23102024_arr2.csv\"),\n", |
1275 | 1303 | " ]\n", |
1276 | 1304 | ")\n", |
1277 | 1305 | "arrivals.drop(columns=\"Unnamed: 0\", inplace=True)\n", |
|
1771 | 1799 | " \"Most Changed Arrivals\": most_changed_arrivals,\n", |
1772 | 1800 | " \"Most Cancelled Arrivals\": most_cancelled_arrivals,\n", |
1773 | 1801 | " \"Most Scheduled Arrivals\": most_scheduled_arrivals,\n", |
1774 | | - " \"Most Diverted Arrivals\": most_diverted_arrivals\n", |
| 1802 | + " \"Most Diverted Arrivals\": most_diverted_arrivals,\n", |
1775 | 1803 | "}\n", |
1776 | 1804 | "\n", |
1777 | 1805 | "# Initialize an empty list to store the tabs\n", |
|
1787 | 1815 | " source = ColumnDataSource(data)\n", |
1788 | 1816 | "\n", |
1789 | 1817 | " # Create a figure for each dataset\n", |
1790 | | - " p = figure(y_range=data['airportcity'], width=600, height=400, title=title + \" in 2024\", tools=\"save\", toolbar_location=\"above\")\n", |
1791 | | - " p.hbar(y='airportcity', right='count', height=0.5, color=color, alpha=0.7, source=source)\n", |
| 1818 | + " p = figure(\n", |
| 1819 | + " y_range=data[\"airportcity\"],\n", |
| 1820 | + " width=600,\n", |
| 1821 | + " height=400,\n", |
| 1822 | + " title=title + \" in 2024\",\n", |
| 1823 | + " tools=\"save\",\n", |
| 1824 | + " toolbar_location=\"above\",\n", |
| 1825 | + " )\n", |
| 1826 | + " p.hbar(\n", |
| 1827 | + " y=\"airportcity\",\n", |
| 1828 | + " right=\"count\",\n", |
| 1829 | + " height=0.5,\n", |
| 1830 | + " color=color,\n", |
| 1831 | + " alpha=0.7,\n", |
| 1832 | + " source=source,\n", |
| 1833 | + " )\n", |
1792 | 1834 | "\n", |
1793 | 1835 | " # Add text inside the bars (5 points inside the bar)\n", |
1794 | | - " p.text(x='count', y='airportcity', text='count', source=source, \n", |
1795 | | - " x_offset=-5, # This places the text 5 units inside the bar\n", |
1796 | | - " y_offset=-3, # Vertical alignment\n", |
1797 | | - " text_align='right', text_baseline='middle', text_color=\"black\", text_font_size=\"10pt\")\n", |
| 1836 | + " p.text(\n", |
| 1837 | + " x=\"count\",\n", |
| 1838 | + " y=\"airportcity\",\n", |
| 1839 | + " text=\"count\",\n", |
| 1840 | + " source=source,\n", |
| 1841 | + " x_offset=-5, # This places the text 5 units inside the bar\n", |
| 1842 | + " y_offset=-3, # Vertical alignment\n", |
| 1843 | + " text_align=\"right\",\n", |
| 1844 | + " text_baseline=\"middle\",\n", |
| 1845 | + " text_color=\"black\",\n", |
| 1846 | + " text_font_size=\"10pt\",\n", |
| 1847 | + " )\n", |
1798 | 1848 | "\n", |
1799 | 1849 | " # Customize plot (optional)\n", |
1800 | 1850 | " p.xaxis.visible = False\n", |
1801 | 1851 | " p.ygrid.visible = False\n", |
1802 | 1852 | " p.xgrid.visible = False\n", |
1803 | 1853 | " p.yaxis.major_tick_line_color = None # No major ticks\n", |
1804 | 1854 | " p.yaxis.minor_tick_line_color = None # No minor ticks\n", |
1805 | | - " p.yaxis.axis_line_color = None \n", |
| 1855 | + " p.yaxis.axis_line_color = None\n", |
1806 | 1856 | " p.outline_line_color = None\n", |
1807 | 1857 | "\n", |
1808 | | - " subtitle = Div(text=f\"<p style='font-size:12px; color:gray;'>Source: AviationStack. Acessed October 7th 2024.</p>\", width=600)\n", |
| 1858 | + " subtitle = Div(\n", |
| 1859 | + " text=\"<p style='font-size:12px; color:gray;'>Source: AviationStack. Acessed October 7th 2024.</p>\",\n", |
| 1860 | + " width=600,\n", |
| 1861 | + " )\n", |
1809 | 1862 | "\n", |
1810 | 1863 | " layout = column(p, subtitle)\n", |
1811 | 1864 | "\n", |
1812 | 1865 | " # Create a panel with the plot and the corresponding title\n", |
1813 | 1866 | " tab = TabPanel(child=layout, title=title)\n", |
1814 | | - " \n", |
| 1867 | + "\n", |
1815 | 1868 | " # Append the panel to the list of tabs\n", |
1816 | 1869 | " tabs.append(tab)\n", |
1817 | 1870 | "\n", |
1818 | 1871 | "# Arrange the tabs in a Tabs layout\n", |
1819 | 1872 | "tabs_layout = Tabs(tabs=tabs)\n", |
1820 | 1873 | "\n", |
1821 | | - "main_title = Div(text=\"<h2>Top 10 Destinations with Changes in Arrivals to BEY in 2024</h2>\", width=800)\n", |
| 1874 | + "main_title = Div(\n", |
| 1875 | + " text=\"<h2>Top 10 Destinations with Changes in Arrivals to BEY in 2024</h2>\",\n", |
| 1876 | + " width=800,\n", |
| 1877 | + ")\n", |
1822 | 1878 | "\n", |
1823 | 1879 | "# Use column layout to stack the title on top of the tabs\n", |
1824 | 1880 | "layout = column(main_title, tabs_layout)\n", |
|
0 commit comments