API reference¶
Pub’lish Launcher¶
Provide the main menu for the Oxford pub tracking application.
- class beer_app.run.MenuState(map_server: BackgroundMapServer | None = None, loaded_pubs: list[Pub] = <factory>)¶
Keep track of resources shared by the menu choices.
- beer_app.run.create_pub_crawl(state: MenuState) None¶
Create a crawl from the pubs currently loaded on the map.
- beer_app.run.handle_choice(choice: str, state: MenuState) bool¶
Run one menu choice and return whether the menu should stay open.
- beer_app.run.load_map_pubs(state: MenuState, choice: str) None¶
Load the selected pubs onto the running map.
- beer_app.run.main() int¶
Show the welcome menu and run the selected feature.
- beer_app.run.show_help(choice: str) bool¶
Print help when
choiceis a general or command help request.
- beer_app.run.show_stats() None¶
Open the visit statistics flow.
Generating the Pub Map¶
Run a small local web server that displays an interactive map of Oxford.
- class beer_app.oxford_map.BackgroundMapServer(server: ThreadingHTTPServer, thread: Thread, url: str, state: MapState)¶
A running map server and its background thread.
- clear_pubs() None¶
Remove all pub markers exposed to the browser map.
- stop() None¶
Stop the server and wait briefly for its thread to finish.
- class beer_app.oxford_map.MapRequestHandler(request, client_address, server)¶
Serve the map page and a lightweight health check.
- do_GET() None¶
Handle a browser request (HTTP GET request).
- do_POST() None¶
Record a visit submitted by a map popup.
- log_message(format: str, *args: object) None¶
Suppress routine browser request logs.
- class beer_app.oxford_map.MapState(pubs: list[Pub] = <factory>, version: int = 0, visited_statuses: dict[int, bool]=<factory>, lock: lock = <factory>)¶
Thread-safe pub data shared by the terminal and browser map.
- record_visit_today(pub_id: int) bool¶
Record today’s visit for a pub currently displayed on the map.
- snapshot() dict[str, int | list[dict[str, int | float | str | bool]]]¶
Return a consistent JSON-ready snapshot of the map state.
- beer_app.oxford_map.build_map_page() str¶
Return the HTML page used by the local Oxford map server.
- beer_app.oxford_map.build_parser() ArgumentParser¶
Create the command-line argument parser.
- beer_app.oxford_map.build_static_asset(filename: str) bytes¶
Return a static image asset used by the map.
- beer_app.oxford_map.build_template_asset(filename: str) bytes¶
Return a template asset used by the local Oxford map server.
- beer_app.oxford_map.main(argv: list[str] | None = None) int¶
Run the Oxford map command.
- beer_app.oxford_map.run_map_server(host: str = '127.0.0.1', port: int = 8000, open_browser: bool = True) None¶
Serve the map until the user stops the process.
- beer_app.oxford_map.start_map_server(host: str = '127.0.0.1', port: int = 8000, open_browser: bool = True) BackgroundMapServer¶
Start the map server in the background and return its controller.
Load Oxford pub data onto the interactive map.
- beer_app.pub_loader.load_pubs_onto_map(map_server: BackgroundMapServer, selection: str = 'all') list[Pub]¶
Load the selected pubs, display them on the map, and return them.
- beer_app.pub_loader.main(map_server: BackgroundMapServer | None = None, selection: str | None = None) list[Pub] | None¶
Load pubs onto the supplied map, or launch a map when run as a script.
- beer_app.pub_loader.unload_pubs_from_map(map_server: BackgroundMapServer) None¶
Remove all currently displayed pubs from the map.
Search Oxford pubs by their text fields.
- beer_app.pub_search.format_pub_values(field: str, values: Iterable[str]) str¶
Format list-command results for terminal display.
- beer_app.pub_search.is_help_query(query: str) bool¶
Return whether a query requests search guidance.
- beer_app.pub_search.list_pub_values(pubs: Iterable[Pub], field: str) list[str]¶
Return sorted unique values for a listable pub field.
- beer_app.pub_search.list_query_field(query: str) str | None¶
Return the requested field for a
--listcommand, if present.
- beer_app.pub_search.main(argv: list[str] | None = None) int¶
Search the packaged pub list from the command line.
Visiting Pubs¶
Load and save the list of pubs marked as visited.
- beer_app.visited_pubs.load_visit_history(path: str | Path | None = None) tuple[dict[int, bool], dict[int, list[str]]]¶
Return current visited statuses and visit dates from the CSV.
- beer_app.visited_pubs.main(pubs: list[Pub] | None = None) int¶
Run the interactive visit manager for the supplied or packaged pub list.
- beer_app.visited_pubs.manage_visited(pubs: list[Pub]) None¶
Show pub visit status and record each visit entered by the user.
- beer_app.visited_pubs.record_visit_today(pub_id: int, path: str | Path | None = None) bool¶
Record one visit for today, returning whether a new visit was added.
- beer_app.visited_pubs.save_visit_history(statuses: dict[int, bool], dates: dict[int, list[str]], path: str | Path | None = None) None¶
Write current status and visit dates for each pub to CSV.
Generating a Pub Crawl¶
Generate pub crawl routes.
Users specify a starting pub, an ending pub, and the number of pubs to visit.
- beer_app.pub_crawl.crawl_file_path() Path¶
Return the path used to save the latest pub crawl.
- beer_app.pub_crawl.create_pub_crawl(pubs: list[Pub], start: Pub, end: Pub, total_pubs: int, buffer_metres: float = 100) list[Pub]¶
Select intermediate pubs for a crawl.
Randomly choose the requested number of pubs within the corridor between the starting and ending pubs.
- Parameters:
pubs (list) – A list of pubs that sit in the corridor, created by pubs_in_buffer() above
start ('Pub' object) – The starting pub, specified by the user
end ('Pub' object) – The ending pub, specified by the user
total_pubs (integer) – The total number of pubs on the pub crawl, specified by the user
buffer_metres (float) – The buffer distance to create the corridor between start and end
- beer_app.pub_crawl.distance_to_line(pub: Pub, start: Pub, end: Pub) float¶
Calculate the distance between a pub and the line between start and end pub.
- beer_app.pub_crawl.find_pub(pubs: list[Pub], query: str) Pub¶
Find exactly one pub by a case-insensitive name fragment.
- beer_app.pub_crawl.main(pubs: list[Pub] | None = None) int¶
Create a crawl from the supplied pubs, or all pubs when run directly.
- beer_app.pub_crawl.pubs_in_buffer(pubs: list[Pub], start: Pub, end: Pub, buffer_metres: float = 100) list[Pub]¶
Create a list of pubs that fall within the corridor created above.
- Parameters:
pubs (list) – A list of pubs generated using pub_data.py
start (Pub object) – The starting pub, specified by the user
end (Pub object) – The ending pub, specified by the user
buffer_metres (float) – The buffer distance to create the corridor between start and end
Summary Statistics¶
Summary statistics for the uploaded pub database.
- beer_app.stats.pub_counts()¶
Return a panda dataframe including Pub ID, Name, and number of total visits.
- beer_app.stats.visited_pub_count(visited_pubs_path)¶
Count visited trips to each pub as a panda df.
- beer_app.stats.visited_pub_path()¶
Define file path for recorded pub visits.
- beer_app.stats.visited_pub_times()¶
Return list of pubs with names and dates.
Plotting Statistics¶
Visualizing Script for Pub STATS bby.
- beer_app.visualization.format_pub_chart(fig: Figure, ax: Axes, *, title: str, xlabel: str, ylabel: str) None¶
Apply the shared Pub’lish chart style to a figure and axes.
- beer_app.visualization.launch_stats_graph(target)¶
Launch the stats graph.
- beer_app.visualization.main() int¶
Prompt for and display one of the stats graphs.
- beer_app.visualization.p_visits_over_time(visited_pub_times: DataFrame) Figure¶
Plot monthly pub visits as a cozy stacked bar chart.
- beer_app.visualization.p_visits_per_pub(pub_count)¶
Plot the number of Pub’lishes per pub.
- beer_app.visualization.show_visits_over_time()¶
Plot pub visits overtime.
- beer_app.visualization.show_visits_per_pub()¶
Visit per pub.
Handling Pub Master Data¶
Load and validate Oxford pub data from CSV files.