Skip to content

Commit

Permalink
good coding pratices, come aboard!
Browse files Browse the repository at this point in the history
  • Loading branch information
kauevestena committed Oct 18, 2024
1 parent 71e9edc commit 6d828bb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 62 deletions.
15 changes: 0 additions & 15 deletions dashboard/statistics_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,18 +408,3 @@ def create_rev_date(row):
}

global_exclusions = [{"points": ["<style>", "</style>"], "multiline": True}]


# it needs to be here rather than in the main script:
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"]:

if os.path.exists(paths_dict["versioning"].get(category)):
updating_dicts[category] = pd.read_json(versioning_dict[category])
else:
updating_dicts[category] = pd.DataFrame()
51 changes: 5 additions & 46 deletions dashboard/statistics_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

single_chart = args.single

# data adaptation
# loading the data:
gdfs_dict = get_gdfs_dict(include_all_data_dummy=True)

# data adaptation (preprocessing)
for category in gdfs_dict:
# creating the folder if it does not exist
create_folder_if_not_exists(os.path.join(statistics_basepath, category))
Expand All @@ -23,57 +26,13 @@

# creating a ref to improve readability
cat_gdf = gdfs_dict[category]
update_df = updating_dicts[category]

print("Adaptations for:", category)

# creating additional fields

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")

# uncertain about polygon cases
# elif (:
# geom_type_dict[category] == "Polygon"
# or geom_type_dict[category] == "MultiPolygon"
# ):
# 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)
# )

# 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)

# # 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["age_years"] = (
# pd.Timestamp(datetime.today()) - update_df["rev_date_obj"]
# ).dt.days / 365.25

cat_gdf["category"] = category

Expand All @@ -86,7 +45,7 @@

# 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()
charts_specs = get_charts_specs(gdfs_dict=gdfs_dict)

for category in charts_specs:
generated_list_dict[category] = []
Expand Down
2 changes: 1 addition & 1 deletion dashboard/statistics_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


# to avoid issues with circular imports it was encapsulated in a function:
def get_charts_specs():
def get_charts_specs(gdfs_dict):
return {
"sidewalks": {
"sidewalks_smoothness_x_surface": {
Expand Down

0 comments on commit 6d828bb

Please sign in to comment.