Skip to content

Commit

Permalink
[dbt] fix br_inep_enem.dicionario (#392)
Browse files Browse the repository at this point in the history
* fix 336

* trigger ci
  • Loading branch information
aspeddro authored Jan 9, 2024
1 parent 0845411 commit 944b46d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
1 change: 1 addition & 0 deletions models/br_inep_enem/br_inep_enem__dicionario.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
)
}}


SELECT
SAFE_CAST(id_tabela AS STRING) id_tabela,
SAFE_CAST(nome_coluna AS STRING) nome_coluna,
Expand Down
32 changes: 13 additions & 19 deletions models/br_inep_enem/code/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,17 @@ def create_intervals(years):

return intervals

def make_temporal_cov(interval):
interval_sort = list(
map(
lambda year: ""
if year == max(YEARS) or year == min(YEARS)
else str(year),
np.sort(interval),
),
)
return "(1)".join(interval_sort)

def make_ranges(key, value):
values_by_key = df.loc[
(df["chave"] == key) & (df["valor"] == value), "valor"
Expand All @@ -231,17 +242,6 @@ def make_ranges(key, value):

intervals = [list(set(interval)) for interval in create_intervals(years)]

def make_temporal_cov(interval):
interval_sort = list(
map(
lambda year: ""
if year == max(YEARS) or year == min(YEARS)
else str(year),
np.sort(interval),
),
)
return "(1)".join(interval_sort)

cobertura_temporal = [make_temporal_cov(interval) for interval in intervals]

return (str(key), ",".join(cobertura_temporal), str(values_by_key[0]))
Expand All @@ -254,14 +254,8 @@ def make_temporal_cov(interval):

dict_df = pd.DataFrame(ranges, columns=basic_cols)

unique_keys = [i for (i, v) in dict_df["chave"].value_counts().items() if v == 1]

# Drop temporal coverage if key is unique
def drop_temporal_cov(key, temporal_cov):
return None if key in unique_keys else temporal_cov

dict_df["cobertura_temporal"] = dict_df[["chave", "cobertura_temporal"]].apply(
lambda values: drop_temporal_cov(*values), axis=1
dict_df["cobertura_temporal"] = dict_df["cobertura_temporal"].apply(
lambda value: None if value == "(1)" else value
)

# Last edits
Expand Down

0 comments on commit 944b46d

Please sign in to comment.