Skip to content

Commit

Permalink
feat(xlsforms): created separate group verification for digitisation …
Browse files Browse the repository at this point in the history
…form (#294)

* feat: created separate group verification for digitisation form

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* feat: added free text comment at the end of verification group

* feat: updated version to current timestamp in settings

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* feat: create entity for new feature point(geopoint)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix: set the version column type to str

---------

Co-authored-by: sujanadh <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 11, 2024
1 parent ce3c352 commit 00ee868
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
58 changes: 48 additions & 10 deletions osm_fieldwork/update_form.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
from io import BytesIO

import pandas as pd
Expand All @@ -9,7 +10,7 @@
pandas_monkeypatch()


def merge_sheets(mandatory_df, custom_df, digitisation_df):
def merge_sheets(mandatory_df, custom_df, digitisation_df, is_survey_sheet=False):
# Remove rows with None in 'name' column
if "name" in mandatory_df.columns:
mandatory_df = mandatory_df.dropna(subset=["name"])
Expand All @@ -33,27 +34,52 @@ def merge_sheets(mandatory_df, custom_df, digitisation_df):
mandatory_df_filtered = mandatory_df[~mandatory_df["name"].isin(common_fields)]
digitisation_df_filtered = digitisation_df[~digitisation_df["name"].isin(common_fields)]

group_row = pd.DataFrame(
if not is_survey_sheet:
return pd.concat(
[
custom_common_df,
mandatory_df_filtered,
custom_non_common_df,
digitisation_df_filtered,
],
ignore_index=True,
)
survey_group_row = pd.DataFrame(
{
"type": ["begin group"],
"name": ["survey_questions"],
"label": ["Survey Form"],
"relevant": [
"${building_exists} = 'yes'"
"(${new_feature} = 'yes') or (${building_exists} = 'yes')"
], # Add the relevant condition to display this group only if "Yes" is selected
}
)

end_group_row = pd.DataFrame({"type": ["end group"], "name": ["end_survey_questions"], "label": ["End Survey Form"]})
survey_end_group_row = pd.DataFrame({"type": ["end group"], "name": ["end_survey_questions"], "label": ["End Survey Form"]})
digitisation_group = pd.DataFrame(
{
"type": ["begin group"],
"name": ["verification"],
"label": ["Verification Form"],
"relevant": ["(${new_feature} = 'yes') or (${building_exists} = 'yes')"],
}
)
digitisation_end_group = pd.DataFrame({"type": ["end group"], "name": ["end_verification"], "label": ["End Verification Form"]})

# Concatenate: mandatory fields at the top, custom common fields, remaining custom fields, and finally append form fields
merged_df = pd.concat(
[custom_common_df, mandatory_df_filtered, group_row, custom_non_common_df, digitisation_df_filtered, end_group_row],
return pd.concat(
[
custom_common_df,
mandatory_df_filtered,
survey_group_row,
custom_non_common_df,
survey_end_group_row,
digitisation_group,
digitisation_df_filtered,
digitisation_end_group,
],
ignore_index=True,
)

return merged_df


def update_xls_form(custom_form: BytesIO) -> BytesIO:
custom_sheets = pd.read_excel(custom_form, sheet_name=None, engine="calamine")
Expand All @@ -64,7 +90,9 @@ def update_xls_form(custom_form: BytesIO) -> BytesIO:

# Process and merge the 'survey' sheet if present in all forms
if "survey" in mandatory_sheets and "survey" in digitisation_sheets and "survey" in custom_sheets:
custom_sheets["survey"] = merge_sheets(mandatory_sheets["survey"], custom_sheets["survey"], digitisation_sheets["survey"])
custom_sheets["survey"] = merge_sheets(
mandatory_sheets["survey"], custom_sheets["survey"], digitisation_sheets["survey"], True
)

# Process and merge the 'choices' sheet if present in all forms
if "choices" in mandatory_sheets and "choices" in digitisation_sheets and "choices" in custom_sheets:
Expand All @@ -76,6 +104,16 @@ def update_xls_form(custom_form: BytesIO) -> BytesIO:
if "entities" in mandatory_sheets:
custom_sheets["entities"] = mandatory_sheets["entities"]

if "settings" in mandatory_sheets:
custom_sheets["settings"] = mandatory_sheets["settings"]
current_timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

# Set the 'version' column to the current timestamp (if 'version' column exists in 'settings')
if "version" in custom_sheets["settings"].columns:
# set column type to str
custom_sheets["settings"]["version"] = custom_sheets["settings"]["version"].astype(str)
custom_sheets["settings"].loc[:, "version"] = current_timestamp

output = BytesIO()
with pd.ExcelWriter(output, engine="openpyxl") as writer:
for sheet_name, df in custom_sheets.items():
Expand Down
Binary file modified osm_fieldwork/xlsforms/fmtm/digitisation_fields.xls
Binary file not shown.
Binary file modified osm_fieldwork/xlsforms/fmtm/mandatory_fields.xls
Binary file not shown.

0 comments on commit 00ee868

Please sign in to comment.