Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
chore: aviod global variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
d116626 committed Feb 20, 2024
1 parent 52f6505 commit 6ce768a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 75 deletions.
79 changes: 5 additions & 74 deletions app/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ def treat_data(response):
)

cameras_identifications_explode["timestamp"] = pd.to_datetime(
cameras_identifications_explode["timestamp"]
cameras_identifications_explode["timestamp"], format="ISO8601"
).dt.tz_convert("America/Sao_Paulo")

cameras_identifications_explode["snapshot_timestamp"] = pd.to_datetime(
cameras_identifications_explode["snapshot_timestamp"]
cameras_identifications_explode["snapshot_timestamp"], format="ISO8601"
).dt.tz_convert("America/Sao_Paulo")

cameras_identifications_explode = (
Expand Down Expand Up @@ -418,6 +418,8 @@ def display_camera_details(row, cameras_identifications_df):
cameras_identifications_df["id"] == camera_id
] # noqa

# st.dataframe(camera_identifications)

camera_identifications = camera_identifications.reset_index(drop=True)

camera_identifications[""] = camera_identifications["label"].apply(
Expand Down Expand Up @@ -454,8 +456,7 @@ def display_camera_details(row, cameras_identifications_df):
i = 0
markdown = ""
for _, row in camera_identifications.iterrows():
critic_level = classify_label(translate_back_to_english(row["Classificação"]))

critic_level = get_icon_color(row["Classificação"])
# if critic_level = green, make classificacao have the color green and all capital letters
if critic_level == "green":
classificacao = f'<span style="color: green; text-transform: uppercase;">{row["Classificação"].upper()}</span>'
Expand All @@ -469,7 +470,6 @@ def display_camera_details(row, cameras_identifications_df):
classificacao = row["Classificação"].upper()
# capitalize the identificador
identificador = row["Identificador"].capitalize()

# if i is even and not the last row
if i % 2 == 0 and i != len(camera_identifications) - 1:
markdown += f"""
Expand Down Expand Up @@ -595,72 +595,3 @@ def create_order_column(table):
)

return table


def translate_back_to_english(label):
tradutor = {
"image_corrupted": "imagem corrompida",
"image_description": "descrição da imagem",
"rain": "chuva",
"water_level": "nível da água",
"traffic": "tráfego",
"road_blockade": "bloqueio de estrada",
"false": "falso",
"true": "verdadeiro",
"null": "nulo",
"low": "baixo",
"medium": "médio",
"high": "alto",
"easy": "fácil",
"moderate": "moderado",
"difficult": "difícil",
"impossible": "impossível",
"free": "livre",
"partially": "parcialmente",
"totally": "totalmente",
}

# if label in tradutor.values, label = key
if label in tradutor.values():
label = list(tradutor.keys())[list(tradutor.values()).index(label)]
return label


def classify_label(label):
if label in [
"major",
"totally_blocked",
"impossible",
"impossibe",
"poor",
"true",
"flodding",
"high",
"totally",
]: # noqa
return "red"

elif label in [
"minor",
"partially_blocked",
"difficult",
"puddle",
"medium",
"moderate",
"partially",
]:
return "orange"
elif label in [
"normal",
"free",
"easy",
"clean",
"false",
"low_indifferent",
"low",
]:
return "green"
else:
if type == "emoji":
return "⚫"
return "grey"
2 changes: 1 addition & 1 deletion data/temp/mock_api_data.json

Large diffs are not rendered by default.

0 comments on commit 6ce768a

Please sign in to comment.