# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: PythonData
#     language: python
#     name: pythondata
# ---

# +
# import the dependencies
import pandas as pd
import gmaps
import requests

# import the API Key
from config import g_key
# -

# store the CSV you saved created in part one into a DataFrame
city_data_df = pd.read_csv('weather_data/cities.csv')
city_data_df.head()

city_data_df.dtypes

# configure gmaps to use your google API key
gmaps.configure(api_key=g_key)

# get the maximum temperature
max_temp = city_data_df['Max Temp']
temps=[]
for temp in max_temp:
    temps.append(max(temp,0))

# +
# heatmap of temperature
# get the latitude and longitude
locations = city_data_df[['Lat', 'Lng']]

# get the maximum temperature
max_temp = city_data_df['Max Temp']

# assign the figure variable
fig = gmaps.figure(center=(30.0, 31.0), zoom_level=1.5)

# assign the heatmap variable
heat_layer = gmaps.heatmap_layer(locations, weights=[max(temp, 0) for temp in max_temp], dissipating = False, max_intensity=300, point_radius=4)

# add the heatmap layer
fig.add_layer(heat_layer)

# call the figure to plot the data
fig

# +
# heatmap of percent humidity
# get the latitude and longitude
locations = city_data_df[['Lat', 'Lng']]

# get the maximum temperature
humidity = city_data_df['Humidity']

# assign the figure variable
fig = gmaps.figure(center=(30.0, 31.0), zoom_level=1.5)

# assign the heatmap variable
heat_layer = gmaps.heatmap_layer(locations, weights=[max(humid, 0) for humid in humidity], dissipating = False, max_intensity=300, point_radius=4)

# add the heatmap layer
fig.add_layer(heat_layer)

# call the figure to plot the data
fig

# +
# heatmap of Cloudiness
# get the latitude and longitude
locations = city_data_df[['Lat', 'Lng']]

# get the maximum temperature
clouds = city_data_df['Cloudiness']

# assign the figure variable
fig = gmaps.figure(center=(30.0, 31.0), zoom_level=1.5)

# assign the heatmap variable
heat_layer = gmaps.heatmap_layer(locations, weights=clouds, dissipating = False, max_intensity=300, point_radius=4)

# add the heatmap layer
fig.add_layer(heat_layer)

# call the figure to plot the data
fig

# +
# heatmap of wind speed
# get the latitude and longitude
locations = city_data_df[['Lat', 'Lng']]

# get the maximum temperature
windy = city_data_df['Wind Speed']

# assign the figure variable
fig = gmaps.figure(center=(30.0, 31.0), zoom_level=1.5)

# assign the heatmap variable
heat_layer = gmaps.heatmap_layer(locations, weights=windy, dissipating = False, max_intensity=300, point_radius=4)

# add the heatmap layer
fig.add_layer(heat_layer)

# call the figure to plot the data
fig
# -

# Ask the customer to add a minimum and maximum temperature value.
min_temp = float(input("What is the minimum temperature you would like for your trip? "))
max_temp = float(input("What is the maximum temperature you would like for your trip? "))

# Filter the dataset to find the cities that fit the criteria.
preferred_cities_df = city_data_df.loc[(city_data_df["Max Temp"] <= max_temp) & (city_data_df["Max Temp"] >= min_temp)]
preferred_cities_df.head(10)

preferred_cities_df.dropna()
preferred_cities_df.count()

# Create DataFrame called hotel_df to store hotel names along with city, country, max temp, and coordinates.
hotel_df = preferred_cities_df[["City", "Country", "Max Temp", "Lat", "Lng"]].copy()
hotel_df["Hotel Name"] = ""
hotel_df.head(10)

# set the parameters to search for a hotel
params = {
    'radius': 5000,
    'type': 'lodging',
    'key': g_key
}

# iterate through the dataframe
for index, row in hotel_df.iterrows():
    # get latitude, longitude
    lat = row['Lat']
    lng = row['Lng']
    
    # add latitude, longitude to location key for the params dictionary
    params['location'] = f'{lat},{lng}'
    
    # use the search term: 'lodging' and our latitude and longitude
    base_url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"
    # make a request and get the JSON data from the search
    hotels=requests.get(base_url, params=params).json()
    #grab the first hotel from the results and store the name
    try:
        hotel_df.loc[index, 'Hotel Name'] = hotels['results'][0]['name']
    except (IndexError):
        print('Hotel not found... skipping')

hotel_df.head()

# +
# Add a heatmap of temperature for the vacation spots.
locations = hotel_df[["Lat", "Lng"]]
max_temp = hotel_df["Max Temp"]
fig = gmaps.figure(center=(30.0, 31.0), zoom_level=1.5)
heat_layer = gmaps.heatmap_layer(locations, weights=max_temp, dissipating=False,
             max_intensity=300, point_radius=4)
marker_layer = gmaps.marker_layer(locations, info_box_content=hotel_info)

fig.add_layer(heat_layer)
fig.add_layer(marker_layer)
# Call the figure to plot the data.
fig
# -

info_box_template = """
<dl>
<dt>Hotel Name</dt><dd>{Hotel Name}</dd>
<dt>City</dt><dd>{City}</dd>
<dt>Country</dt><dd>{Country}</dd>
<dt>Max Temp</dt><dd>{Max Temp} °F</dd>
</dl>
"""

# Store the DataFrame Row.
hotel_info = [info_box_template.format(**row) for index, row in hotel_df.iterrows()]



StarcoderdataJupyterScriptsDedupFiltered