Map Generation¶
- access_amherst_algo.generate_map.add_event_markers(folium_map, events)¶
Add event markers to a Folium map with popups and Google Calendar links.
This function takes a Folium map and a list of event data to add interactive markers representing each event. Each marker includes a popup displaying event details (title, location, start and end times) and a link to add the event to Google Calendar.
- Parameters:
folium_map (folium.Map) -- The Folium map object where the event markers will be added.
events (list of Event) -- A list of Event objects containing event details such as title, start and end times, location, description, and map coordinates (latitude and longitude).
- Returns:
The Folium map object with added markers for each event.
- Return type:
folium.Map
Examples
>>> map_object = create_map((42.37284302722828, -72.51584816807264)) >>> events = [ >>> Event( >>> title="Literature Speaker Event", >>> start_time=datetime(2024, 11, 5, 18, 0), >>> end_time=datetime(2024, 11, 5, 19, 0), >>> location="Keefe Campus Center", >>> map_location="Amherst, MA", >>> latitude=42.37149564586236, >>> longitude=-72.51478632450079, >>> event_description="A talk on modern literature." >>> ) >>> ] >>> add_event_markers(map_object, events)
- access_amherst_algo.generate_map.create_map(center_coords, zoom_start=17)¶
Initialize a Folium map centered around the specified coordinates.
This function creates and returns a Folium map centered on the provided latitude and longitude coordinates. The zoom level can be adjusted, with a default zoom level of 17 for close-up views.
- Parameters:
center_coords (tuple of float) -- A tuple specifying the latitude and longitude (in that order) for the center of the map.
zoom_start (int, default 17) -- The initial zoom level of the map, where higher values provide a closer view.
- Returns:
A Folium map object centered on the specified coordinates and set to the defined zoom level.
- Return type:
folium.Map
Examples
>>> map_object = create_map((42.37284302722828, -72.51584816807264))
- access_amherst_algo.generate_map.generate_heatmap(events, timezone, min_hour=None, max_hour=None)¶
Generate a heatmap map object based on filtered events within a specified time range.
This function filters events based on the provided time range (specified by min_hour and max_hour, if provided) and generates a heatmap of event locations using their geographical coordinates (latitude and longitude). The heatmap is then added to a Folium map, which is returned for further use.
- Parameters:
events (QuerySet) -- A QuerySet of Event objects, each containing attributes like latitude, longitude, and start time.
timezone (pytz.timezone) -- The timezone used for filtering events based on their start times.
min_hour (int, optional) -- The minimum hour (0-23) of the day to filter events by start time. Default is None.
max_hour (int, optional) -- The maximum hour (0-23) of the day to filter events by start time. Default is None.
- Returns:
The Folium map object with a heatmap layer representing event locations within the specified time range.
- Return type:
folium.Map
Examples
>>> events = Event.objects.all() # Example QuerySet of events >>> timezone = pytz.timezone('America/New_York') >>> folium_map = generate_heatmap(events, timezone, min_hour=9, max_hour=17) >>> folium_map.save("events_heatmap.html") # Saves the map with heatmap to an HTML file