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

Improve build-schema and metadata_template generator #382

Merged
merged 9 commits into from
Feb 7, 2025
Merged
5 changes: 3 additions & 2 deletions relecov_tools/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,11 +706,12 @@ def pipeline_manager(input, template, output, config, folder_names):
is_flag=True,
help="Prints a changelog/diff between the base and incoming versions of the schema.",
)
@click.option("--version", help="Specify the schema version.")
@click.option("-o", "--out_dir", type=click.Path(), help="Path to save output file/s")
def build_schema(input_file, schema_base, draft_version, diff, out_dir):
def build_schema(input_file, schema_base, draft_version, diff, out_dir, version):
"""Generates and updates JSON Schema files from Excel-based database definitions."""
schema_update = relecov_tools.build_schema.SchemaBuilder(
input_file, schema_base, draft_version, diff, out_dir
input_file, schema_base, draft_version, diff, out_dir, version
)
try:
schema_update.handle_build_schema()
Expand Down
44 changes: 36 additions & 8 deletions relecov_tools/assets/schema_utils/metadatalab_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,41 @@ def excel_formater(df, writer, sheet, out_file, have_index=True, have_header=Tru
workbook = writer.book
worksheet = writer.sheets[sheet]

# setup excel format
# Set up general column width
worksheet.set_column(0, len(df.columns), 30)

# General header format
header_formater = workbook.add_format(
{
"bold": True,
"text_wrap": False,
"valign": "top",
"fg_color": "#ADD8E6",
"fg_color": "#B9DADE", # Light blue
"border": 1,
"locked": True,
}
)

# Custom header format for METADATA_LAB (red text starting from column 2)
red_header_formater = workbook.add_format(
{
"bold": True,
"text_wrap": False,
"valign": "top",
"fg_color": "#B9DADE", # Light blue background
"color": "#E05959", # Red text color
"border": 1,
"locked": True,
}
)

# First column format
first_col_formater = workbook.add_format(
{
"bold": True,
"text_wrap": False,
"valign": "center",
"fg_color": "#ADD8E6",
"fg_color": "#B9DADE", # Light blue
"border": 1,
"locked": True,
}
Expand All @@ -107,7 +124,7 @@ def excel_formater(df, writer, sheet, out_file, have_index=True, have_header=Tru
# Write the column headers with the defined format.
for col_num, value in enumerate(df.columns.values):
try:
worksheet.write(0, col_num + 1, value, header_formater)
worksheet.write(0, col_num, value, header_formater)
except Exception as e:
stderr.print(f"Error writing header at column {col_num + 1}: {e}")

Expand All @@ -124,10 +141,10 @@ def excel_formater(df, writer, sheet, out_file, have_index=True, have_header=Tru
# Write the column headers with the defined format.
for col_num in range(0, len(df.columns)):
for row_num in range(0, len(df)):
if row_num < 3:
if row_num < 4:
try:
worksheet.write(
row_num + 1,
row_num,
col_num + 1,
df.iloc[row_num, col_num],
header_formater,
Expand All @@ -136,11 +153,22 @@ def excel_formater(df, writer, sheet, out_file, have_index=True, have_header=Tru
stderr.print(
f"Error writing first column at row {row_num}: {e}"
)

if row_num == 0 and col_num >= 1 and sheet == "METADATA_LAB":
try:
worksheet.write(
row_num,
col_num,
df.iloc[row_num, col_num],
red_header_formater, # Aplicar formato
Aberdur marked this conversation as resolved.
Show resolved Hide resolved
)
except Exception as e:
stderr.print(
f"Error writing first row at column {col_num}: {e}"
)
# Write the first column with the defined format.
for index_num, index_val in enumerate(df.index):
try:
worksheet.write(index_num + 1, 0, index_val, first_col_formater)
worksheet.write(index_num, 0, index_val, first_col_formater)
except Exception as e:
stderr.print(f"Error writing first column at row {row_num}: {e}")
except Exception as e:
Expand Down
Loading
Loading