Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add row to calculate coordinates of additional entity #312

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions osm_fieldwork/update_xlsform.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,6 @@ def append_select_one_from_file_row(df: pd.DataFrame, entity_name: str) -> pd.Da

# Find the row index after 'feature' row
row_index_to_split_on = select_one_from_file_index[0] + 1
# Strip the 's' from the end for singular form
if entity_name.endswith("s"):
# Plural to singular
entity_name = entity_name[:-1]

additional_row = pd.DataFrame(
{
Expand All @@ -175,10 +171,22 @@ def append_select_one_from_file_row(df: pd.DataFrame, entity_name: str) -> pd.Da
}
)

# Prepare the row for calculating coordinates based on the additional entity
coordinates_row = pd.DataFrame(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's quite nice having the field in code like this.

It's verbose, but we can then use source control.

Do you think we should remove the mandatory fields xls file and build the dataframe here instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we tried that initially when we were writing this function to append fields. But it looked so messy and complex so we decided to use a file instead, updating the form seemed easier during that time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for being my memory 😆

It probably did look messy! But we could clean it up a bit, either using functions or different files to split it up nicely.

I'm leaning more in favour of putting it all in code so it's source controlled and easily visible what we change.

Not high priority to do right now if it's going to take some time. But do you think it's a good idea in the long run? Or we just keep it simple with the file?

{
"type": ["calculate"],
"name": ["additional_geometry"],
"calculation": [f"instance('{entity_name}')/root/item[name=${entity_name}]/geometry"],
"label::English(en)": ["additional_geometry"],
"label::Swahili(sw)": ["additional_geometry"],
"label::French(fr)": ["additional_geometry"],
"label::Spanish(es)": ["additional_geometry"],
}
)
# Insert the new row into the DataFrame
top_df = df.iloc[:row_index_to_split_on]
bottom_df = df.iloc[row_index_to_split_on:]
return pd.concat([top_df, additional_row, bottom_df], ignore_index=True)
return pd.concat([top_df, additional_row, coordinates_row, bottom_df], ignore_index=True)


async def append_mandatory_fields(
Expand Down
Loading