Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Shiny App to use the API once Michael deploys to Ferrlyland #26

Open
SamEdwardes opened this issue Jul 24, 2024 · 0 comments
Open
Assignees
Labels
enhancement New feature or request

Comments

@SamEdwardes
Copy link
Contributor

@reactive.calc
@time_function
def predict_delay() -> float:
"""
The delay model is hosted on Posit Connect at this URL:
https://connect.posit.it/content/823c479e-3d5e-4898-8801-a5c2cec97bb5
"""
# Based on the selected vessel name, get all of the data related to that
# vessel.
selected_vessel_data = (
vessel_verbose.filter(pl.col("VesselName") == input.selected_vessel_name())
.to_dicts()[0]
)
# Some of the vessels have not been rebuilt. When this applies, impute
# the current year as the year rebuilt.
if selected_vessel_data["YearRebuilt"]:
year_rebuilt = selected_vessel_data["YearRebuilt"].year
else:
year_rebuilt = datetime.datetime.now().year
# TODO: after Michael published the API to Ferryland bring this code
# back into the fold
prediction_input_data = {
"Departing": get_starting_and_ending_terminal()[0],
"Arriving": get_starting_and_ending_terminal()[1],
"Month": input.selected_date().month,
"Weekday": input.selected_date().weekday(),
"Hour": input.selected_hour(),
"ClassName": selected_vessel_data["ClassName"],
"SpeedInKnots": selected_vessel_data["SpeedInKnots"],
"EngineCount": selected_vessel_data["EngineCount"],
"Horsepower": selected_vessel_data["Horsepower"],
"MaxPassengerCount": selected_vessel_data["MaxPassengerCount"],
"PassengerOnly": None, # selected_vessel_data["PassengerOnly"],
"FastFerry": None, # selected_vessel_data["FastFerry"],
"PropulsionInfo": selected_vessel_data["PropulsionInfo"],
"YearBuilt": selected_vessel_data["YearBuilt"].year,
"YearRebuilt": year_rebuilt,
"departing_weather_code": int(input.selected_weather_code()),
"departing_temperature_2m": input.selected_temperature(),
"departing_precipitation": None, # input.selected_precipitation(),
"departing_cloud_cover": input.selected_cloud_cover(),
"departing_wind_speed_10m": input.selected_wind_speed(),
"departing_wind_direction_10m": int(input.selected_wind_direction()),
"departing_wind_gusts_10m": input.selected_wind_gust(),
"arriving_weather_code": int(input.selected_weather_code()),
"arriving_temperature_2m": input.selected_temperature(),
"arriving_precipitation": None, # input.selected_precipitation(),
"arriving_cloud_cover": input.selected_cloud_cover(),
"arriving_wind_speed_10m": input.selected_wind_speed(),
"arriving_wind_direction_10m": int(input.selected_wind_direction()),
"arriving_wind_gusts_10m": input.selected_wind_gust(),
}
# Make the prediction
# prediction_results_df = predict(
# vetiver_endpoint(
# "https://connect.posit.it/content/823c479e-3d5e-4898-8801-a5c2cec97bb5/predict"
# ),
# pd.DataFrame.from_records([prediction_input_data]),
# headers={"Authorization": f'Key {os.environ["CONNECT_API_KEY"]}'},
# )
# prediction_results_value = prediction_results_df.iloc[0, 0]
# return round(float(prediction_results_value), 2) # type: ignore
# TEMPORARY - return a random number as the prediction
return random.randint(-3, 23)

@SamEdwardes SamEdwardes added the enhancement New feature or request label Jul 24, 2024
@SamEdwardes SamEdwardes self-assigned this Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant