Skip to content

Commit

Permalink
fix 336
Browse files Browse the repository at this point in the history
  • Loading branch information
aspeddro committed Jan 8, 2024
1 parent 0845411 commit 0520af7
Showing 1 changed file with 13 additions and 19 deletions.
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 0520af7

Please sign in to comment.