Last active
November 7, 2022 19:16
-
-
Save randyphoa/88cdb45493ff92dc1704bec3045de9ec to your computer and use it in GitHub Desktop.
Mapping actions to functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ACTIONS_MAPPING = { | |
"GET_ACCIDENT_DATA": get_accident_data, | |
"GET_ACCIDENT_DETAILS": get_accident_details, | |
"GET_CLUSTERS": get_clusters, | |
"GET_CLUSTERS_DETAILS": get_cluster_details, | |
"SAVE_CLUSTERS_RESULTS": save_clusters_results, | |
"GET_PREDICTIONS": get_predictions, | |
"GET_MODELS": get_models, | |
"GET_PREDICT_INPUT_FILES": get_predict_input_files, | |
} | |
def score(payload): | |
req = payload["input_data"][0]["values"][0] | |
action = req["ACTION"] | |
params = req["PARAMS"] | |
if action in ACTIONS_MAPPING: | |
df = ACTIONS_MAPPING[action](params) | |
return {"predictions": [{"fields": df.columns.tolist(), "values": df.values.tolist()}]} | |
return {"predictions": [{"values": ["NO ACTION"]}]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment