Skip to content

Commit

Permalink
All data charts category is here!!
Browse files Browse the repository at this point in the history
  • Loading branch information
kauevestena committed Oct 17, 2024
1 parent 557e239 commit 71e9edc
Show file tree
Hide file tree
Showing 5 changed files with 730 additions and 445 deletions.
6 changes: 5 additions & 1 deletion dashboard/statistics_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,11 @@ def create_rev_date(row):


# it needs to be here rather than in the main script:
gdfs_dict = get_gdfs_dict()
gdfs_dict = get_gdfs_dict(include_all_data_dummy=True)

# # for the inclusion of all data:
# gdfs_dict["all_data"] = None

updating_dicts = {}
for category in paths_dict["data"]:

Expand Down
62 changes: 33 additions & 29 deletions dashboard/statistics_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
create_folder_if_not_exists(os.path.join(statistics_basepath, category))
create_folder_if_not_exists(os.path.join(statistcs_specs_path, category))

if category == "all_data":
continue

# creating a ref to improve readability
cat_gdf = gdfs_dict[category]
update_df = updating_dicts[category]
Expand All @@ -28,9 +31,9 @@

if "LineString" in geom_type_dict[category]:
create_length_field(cat_gdf)
create_weblink_field(cat_gdf)
elif "Point" in geom_type_dict[category]:
create_weblink_field(cat_gdf, "Point")
# create_weblink_field(cat_gdf)
# elif "Point" in geom_type_dict[category]:
# create_weblink_field(cat_gdf, "Point")

# uncertain about polygon cases
# elif (:
Expand All @@ -40,42 +43,41 @@
# create_weblink_field(gdfs_dict[category])

if "survey:date" in cat_gdf.columns:

cat_gdf["Year of Survey"] = cat_gdf["survey:date"].apply(get_year_surveydate)

# updating info:
update_df["month_year"] = (
update_df["rev_month"].map("{:02d}".format)
+ "_"
+ update_df["rev_year"].astype(str)
)
# # updating info:
# update_df["month_year"] = (
# update_df["rev_month"].map("{:02d}".format)
# + "_"
# + update_df["rev_year"].astype(str)
# )

update_df["year_month"] = (
update_df["rev_year"].astype(str)
+ "_"
+ update_df["rev_month"].map("{:02d}".format)
)
# update_df["year_month"] = (
# update_df["rev_year"].astype(str)
# + "_"
# + update_df["rev_month"].map("{:02d}".format)
# )

update_df.sort_values("year_month", inplace=True)
# update_df.sort_values("year_month", inplace=True)

# Fill missing values with a default (e.g., 1 for month or day) TODO: move to data adaptation script
update_df["rev_year"] = (
update_df["rev_year"].fillna(default_missing_year).astype(int)
)
update_df["rev_month"] = (
update_df["rev_month"].fillna(default_missing_month).astype(int)
)
update_df["rev_day"] = update_df["rev_day"].fillna(default_missing_day).astype(int)
# # Fill missing values with a default (e.g., 1 for month or day) TODO: move to data adaptation script
# update_df["rev_year"] = (
# update_df["rev_year"].fillna(default_missing_year).astype(int)
# )
# update_df["rev_month"] = (
# update_df["rev_month"].fillna(default_missing_month).astype(int)
# )
# update_df["rev_day"] = update_df["rev_day"].fillna(default_missing_day).astype(int)

update_df["rev_date_obj"] = update_df.apply(create_rev_date, axis=1)
# update_df["rev_date_obj"] = update_df.apply(create_rev_date, axis=1)

update_df["age_years"] = (
pd.Timestamp(datetime.today()) - update_df["rev_date_obj"]
).dt.days / 365.25
# update_df["age_years"] = (
# pd.Timestamp(datetime.today()) - update_df["rev_date_obj"]
# ).dt.days / 365.25

cat_gdf["category"] = category

# creating a meta-category "all_data" for all data:
# # creating a meta-category "all_data" for all data:
gdfs_dict["all_data"] = pd.concat(gdfs_dict.values(), ignore_index=True)

# storing chart infos:
Expand All @@ -84,6 +86,8 @@

# generating the charts by using the specifications
with open(os.path.join(statistics_basepath, "failed_gen.txt"), "w+") as error_report:
charts_specs = get_charts_specs()

for category in charts_specs:
generated_list_dict[category] = []
for chart_spec in charts_specs[category]:
Expand Down
Loading

0 comments on commit 71e9edc

Please sign in to comment.