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

Change For Dynamic Table Output #79

Merged

Conversation

daralynnrhode
Copy link
Contributor

Making the output table be dynamic with sizing

Overview

Making changes to the _print_query_results_table() so the sizing of the table can be dynamic based on the query_results received.

Closes #53

New Dependencies

New Files

Deleted Files

Updated Files

  • cli.py

Testing

@daralynnrhode daralynnrhode requested a review from a team August 15, 2024 15:06
@daralynnrhode daralynnrhode self-assigned this Aug 15, 2024
@daralynnrhode daralynnrhode requested review from bourque, sdhoyt, maxinelasp and anamanica and removed request for a team August 15, 2024 15:06
Copy link

@sdhoyt sdhoyt left a comment

Choose a reason for hiding this comment

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

Looks good to me. I was tried querying with your changes and everything looked good. Great work!

imap_data_access/cli.py Outdated Show resolved Hide resolved
Copy link
Contributor

@bourque bourque left a comment

Choose a reason for hiding this comment

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

Thanks for making this fix! It looks good. I just had one non-blocking suggestion if you wanted to try it out. But it is also fine as is.

imap_data_access/cli.py Show resolved Hide resolved
Comment on lines 64 to 97
# Calculate the maximum width for each column based on the header and the data
column_widths = {
"Instrument": max(
len("Instrument"),
*(len(str(item.get("instrument", ""))) for item in query_results),
),
"Data Level": max(
len("Data Level"),
*(len(str(item.get("data_level", ""))) for item in query_results),
),
"Descriptor": max(
len("Descriptor"),
*(len(str(item.get("descriptor", ""))) for item in query_results),
),
"Start Date": max(
len("Start Date"),
*(len(str(item.get("start_date", ""))) for item in query_results),
),
"Repointing": max(
len("Repointing"),
*(len(str(item.get("repointing", ""))) for item in query_results),
),
"Version": max(
len("Version"),
*(len(str(item.get("version", ""))) for item in query_results),
),
"Filename": max(
len("Filename"),
*(
len(os.path.basename(item.get("file_path", "")))
for item in query_results
),
),
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I was trying to think of a clever way to avoid duplicated code. Does something like this work?

Suggested change
# Calculate the maximum width for each column based on the header and the data
column_widths = {
"Instrument": max(
len("Instrument"),
*(len(str(item.get("instrument", ""))) for item in query_results),
),
"Data Level": max(
len("Data Level"),
*(len(str(item.get("data_level", ""))) for item in query_results),
),
"Descriptor": max(
len("Descriptor"),
*(len(str(item.get("descriptor", ""))) for item in query_results),
),
"Start Date": max(
len("Start Date"),
*(len(str(item.get("start_date", ""))) for item in query_results),
),
"Repointing": max(
len("Repointing"),
*(len(str(item.get("repointing", ""))) for item in query_results),
),
"Version": max(
len("Version"),
*(len(str(item.get("version", ""))) for item in query_results),
),
"Filename": max(
len("Filename"),
*(
len(os.path.basename(item.get("file_path", "")))
for item in query_results
),
),
}
column_widths = {}
for header in headers[:-1]:
column_width[header] = max(len(header), *(len(str(item.get(header.lower(), ""))) for item in query_results)
# Calculate the maximum width for each column based on the header and the data
column_widths["Filename"] = max(len("Filename"), *(len(os.path.basename(item.get("file_path", ""))) for item in query_results)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It produces the same results

@bourque
Copy link
Contributor

bourque commented Aug 19, 2024

@daralynnrhode It looks like this PR is ready to go, so I am going to merge this now so that it can be included in today's release.

@bourque bourque merged commit 82e73ce into IMAP-Science-Operations-Center:main Aug 19, 2024
13 checks passed
@daralynnrhode daralynnrhode deleted the dynamic_table branch August 28, 2024 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix output table formatting to be Dynamic instead of Static
3 participants