Skip to content

Commit

Permalink
process.py: Statement_id name for unflattening
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed (ODSC) committed Nov 28, 2024
1 parent 802f2e7 commit f2f74d5
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions cove_bods/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import json
import os.path
import pandas

import flattentool
from sentry_sdk import capture_exception
Expand All @@ -30,6 +31,21 @@
logger = getLogger(__name__)


def check_table_file_new(filename):
if filename.endswith(".xlxs"):
data = pandas.read_excel(filename)
if "statementID" in data.head():
return False
else:
return True
else:
with open(filename) as file:
head = file.readline()
if "statementID" in data.head():
return False
else:
return True

def create_error_file(directory: str, name: str, data: dict):
"""Create temporary error file"""
filename = os.path.join(directory, f"{name}-error.json")
Expand Down Expand Up @@ -185,11 +201,16 @@ def process(self, process_data: dict) -> dict:
# We don't know what schema version the spreadsheet is in. Use default schema.
schema = SchemaBODS()

if check_table_file_new(input_filename):
statement_id_name = "statementID"
else:
statement_id_name = "statementId"

unflatten_kwargs = {
"output_name": os.path.join(output_dir, "unflattened.json"),
"root_list_path": "there-is-no-root-list-path",
"root_id": "statementID",
"id_name": "statementID",
"root_id": statement_id_name,
"id_name": statement_id_name,
"root_is_list": True,
"input_format": get_file_type_for_flatten_tool(supplied_data_json_file),
"schema": schema.pkg_schema_url,
Expand Down

0 comments on commit f2f74d5

Please sign in to comment.