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

# API Python -Challenge: Part 2: VacationPy Student: <NAME>

# # VacationPy
# ----
#
# #### Note
# * Instructions have been included for each segment. You do not have to follow them exactly, but they are included to help you think through the steps.

# Dependencies and Setup
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import requests
import gmaps
import os
import json
# Import API key
url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"
from api_keys import g_key

# ### Store Part I results into DataFrame
# * Load the csv exported in Part I to a DataFrame

#Extract the new dataframe that was created in the WeatherPy challenge
cityweatherforcast = pd.read_csv("../output_data/cityweatherforcast.csv")
cityweatherforcast.head() #test succesfully data frame generated

#Eliminate duplicate columns in the Data Frame
vacationweatherforcast = cityweatherforcast[["City", "Cloudiness", "Country","Date", "Humidity",
                                             "Latitude","Longitude", "Temp", "Winds Speed"]]
vacationweatherforcast.head()#Test Succesfully Dataframe generated

# ### Humidity Heatmap
# * Configure gmaps.
# * Use the Lat and Lng as locations and Humidity as the weight.
# * Add Heatmap layer to map.

#Stablished the max variables of Humidity and locations using previouse dataframe
vacationhumidity = vacationweatherforcast["Humidity"].astype(float)
maxvacationhumidity = vacationhumidity.max()
locations = vacationweatherforcast[["Latitude","Longitude" ]]

#Generated Heat map by on gmaps, using the data frame from previouse dataframe, and give a littleformat to the heatmap
Heatmap_layer = gmaps.figure()
heat_layer = gmaps.heatmap_layer(locations, weights=vacationhumidity,dissipating=True, 
                                 max_intensity=maxvacationhumidity,point_radius=4)
Heatmap_layer.add_layer(heat_layer)
print(f"Heatmap of all the cities")
Heatmap_layer#test succesfull heatmap generated

# ### Create new DataFrame fitting weather criteria
# * Narrow down the cities to fit weather conditions.
# * Drop any rows will null values.

#Narrow the number of cities that meet the temperature, cloudiness and wind speed requirement
vacationcities = vacationweatherforcast.loc[(vacationweatherforcast["Temp"] > 70) & (vacationweatherforcast["Temp"] < 80) & (vacationweatherforcast["Cloudiness"] == 0) & (vacationweatherforcast["Winds Speed"] < 10), :]
#Eliminates null values using drpna
vacationcitiesfinal = vacationcities.dropna(how="any")
#reset the dataframe generated from the begining
vacationcitiesfinal.reset_index(inplace=True)
#delete index
del vacationcitiesfinal["index"]
vacationcitiesfinal.head(12) #test succesfully data frame generated

# ### Hotel Map
# * Store into variable named `hotel_df`.
# * Add a "Hotel Name" column to the DataFrame.
# * Set parameters to search for hotels with 5000 meters.
# * Hit the Google Places API for each city's coordinates.
# * Store the first Hotel result into the DataFrame.
# * Plot markers on top of the heatmap.

#create hotel df variable
hotels_df = []
#create a loop to track down the number of hotels from gmaps url into the Dataframe  using latitude, Longitude and locations, using try/except function
for i in range(len(vacationcitiesfinal)):
    Latitude1 = vacationcitiesfinal.loc[i]["Latitude"]
    Longitude1 = vacationcitiesfinal.loc[i]["Longitude"]
    params = {
        "location": f"{Latitude1},{Longitude1}",
        "radius": 5000,
        "types" : "hotel",
        "key": g_key
    }
    hotels = requests.get(url, params=params)
    jsn = hotels.json()
    try:
        hotels_df.append(jsn['results'][0]['name'])
    except:
        hotels_ddf.append("")
vacationcitiesfinal["Hotel Name"] = hotels_df
#Eliminates null values using drpna
vacationcitiesfinal = vacationcitiesfinal.dropna(how='any')
vacationcitiesfinal.head(13) #test succesfully new data frame generated

# Generate new data frame with just the City, Hotel Name, Humidity, Latitude and Longitude
vacationcitiesfinalf = vacationcitiesfinal[["City","Hotel Name","Humidity","Latitude","Longitude","Winds Speed"]]
vacationcitiesfinalf.head(13)#test succesfully new data frame generated

# NOTE: Do not change any of the code in this cell
# Using the template add the hotel marks to the heatmap
info_box_template = """
<dl>
<dt>Name</dt><dd>{Hotel Name}</dd>
<dt>City</dt><dd>{City}</dd>
<dt>Country</dt><dd>{Country}</dd>
</dl>
"""
# Store the DataFrame Row
# NOTE: be sure to update with your DataFrame name
hotel_info = [info_box_template.format(**row) for index, row in vacationcitiesfinal.iterrows()]
locations = vacationcitiesfinal[["Latitude","Longitude" ]]

#Track down the Hotel in the city and country from the dataframe into gmaps using markers
markers = gmaps.marker_layer(locations)
Heatmap_layer.add_layer(markers)
print(f"Hotels recommeded to stay")
Heatmap_layer #test succesfully gmaps with markers generated



StarcoderdataJupyterScriptsDedupFiltered