Skip to content

Commit

Permalink
Update excel approach to group metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ajparsons committed Aug 20, 2024
1 parent b113190 commit 041db69
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/data_common/dataset/resource_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -1101,18 +1101,15 @@ def build_coversheet(

# sort sheets in order

ws.write_url(row, 2, f"internal:data_description!A1", string="Data description")
ws.write(row, 4, "Field descriptions and metadata for each sheet")
row += 1

for r in self.resources().values():
if r.slug not in allowed_sheets:
continue
desc = r.get_resource()
metadata_sheet = f"{r.slug}_metadata"[-31:]
ws.write_url(row, 2, f"internal:{r.slug}!A1", string=desc["title"])
ws.write_url(
row,
3,
f"internal:{metadata_sheet}!A1",
string="View column information",
)
ws.write(row, 4, desc["description"])
row += 1

Expand Down Expand Up @@ -1180,10 +1177,21 @@ def build_excel(self, is_geodata: bool = False):

sheets: dict[str, pd.DataFrame] = {}

metadata_sheets: list[pd.DataFrame] = []

for slug, resource in self.resources().items():
if slug in allowed_resource_slugs:
mdf = resource.get_metadata_df()
mdf["resource"] = slug
metadata_sheets.append(mdf)

metadata_df = pd.concat(metadata_sheets)

sheets["data_description"] = metadata_df

for slug, resource in self.resources().items():
if slug in allowed_resource_slugs:
sheets[slug] = resource.get_df()
sheets[slug + "_metadata"] = resource.get_metadata_df()

excel_path = self.build_path() / f"{self.slug}.xlsx"

Expand Down

0 comments on commit 041db69

Please sign in to comment.