Skip to content

info: append grade details from grades_summary.json#5

Merged
kowyo-bot merged 3 commits intoHITSZ-OpenAuto:mainfrom
kowyo-bot:feat/append-grade-details-to-info
Jan 31, 2026
Merged

info: append grade details from grades_summary.json#5
kowyo-bot merged 3 commits intoHITSZ-OpenAuto:mainfrom
kowyo-bot:feat/append-grade-details-to-info

Conversation

@kowyo-bot
Copy link
Contributor

What

When running:

hoa info <plan_id> <course_code>

the command will append grade composition details from grades_summary.json (if present).

Match order

For a given <course_code>, we select grade items in this order:

  1. year_major (tries ${year}_${major_code} first, then ${year}_${major_name} to match upstream keys like 2021_自动化)
  2. year_default (e.g. 2021_default)
  3. default

If no match is found, nothing is appended.

@gemini-code-assist
Copy link

Summary of Changes

Hello @kowyo-bot, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the hoa info command by adding the capability to display detailed grade composition for courses. It introduces logic to read grade summaries from a grades_summary.json file and intelligently match course entries based on year and major, providing a more comprehensive information output for users.

Highlights

  • New Functionality for hoa info command: The hoa info command now appends grade composition details from grades_summary.json if the file is present and a matching entry is found for the specified course.
  • Grade Summary Loading: A new private helper function, _load_grades_summary, has been introduced to safely load and parse the grades_summary.json file, returning an empty dictionary if the file is not found or an error occurs during parsing.
  • Flexible Grade Detail Matching: Another new private helper function, _print_grade_details, implements a specific matching order to find relevant grade information: first by year_major (trying both major code and name), then year_default, and finally a generic default entry.
  • Integration into get_course_info: The get_course_info function now calls _load_grades_summary once and then _print_grade_details for each found course to display the grade breakdown.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a useful feature to display grade composition details when querying for course information. The implementation is well-structured, introducing helper functions to load grade data and print the details. My review includes a couple of suggestions to enhance code quality and maintainability. Specifically, I recommend using more specific exception handling for robustness and refactoring a piece of logic to be more concise and idiomatic, which will make the code easier to read and maintain. Overall, the changes are solid and correctly implement the new functionality.

Comment on lines +19 to +20
except Exception as e:
logger.warning(f"无法读取 {path.name}: {e}")

Choose a reason for hiding this comment

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

medium

It's a good practice to catch more specific exceptions rather than the generic Exception. This prevents catching unexpected errors like KeyboardInterrupt or SystemExit and makes the error handling more robust and explicit. In this case, you could catch json.JSONDecodeError for issues with JSON parsing and OSError for file-related problems.

Suggested change
except Exception as e:
logger.warning(f"无法读取 {path.name}: {e}")
except (json.JSONDecodeError, OSError) as e:
logger.warning(f"无法读取或解析 {path.name}: {e}")

Comment on lines 57 to 65
grade_items = None
for k in year_major_keys:
if k in entry:
grade_items = entry.get(k)
break
if grade_items is None and year_default_key and year_default_key in entry:
grade_items = entry.get(year_default_key)
if grade_items is None and "default" in entry:
grade_items = entry.get("default")

Choose a reason for hiding this comment

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

medium

The logic for selecting grade_items can be significantly simplified to be more concise and Pythonic. You can build a list of keys to try in order of precedence, and then use a generator expression with next() to find the first matching item. This is more readable and maintainable than the current series of if statements and redundant checks.

    search_keys = year_major_keys + ([year_default_key] if year_default_key else []) + ["default"]
    grade_items = next((entry[key] for key in search_keys if key in entry), None)

@kowyo-bot kowyo-bot merged commit 6b4a590 into HITSZ-OpenAuto:main Jan 31, 2026
1 check passed
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.

1 participant