Skip to content

fix: Dialogue log export, question time does not match on the page#2396

Merged
shaohuzhang1 merged 1 commit intomainfrom
pr@main@fix_chat_log_export
Feb 25, 2025
Merged

fix: Dialogue log export, question time does not match on the page#2396
shaohuzhang1 merged 1 commit intomainfrom
pr@main@fix_chat_log_export

Conversation

@shaohuzhang1
Copy link
Contributor

fix: Dialogue log export, question time does not match on the page

value = value.astimezone(c)
cell.value = value

output = BytesIO()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code provided appears to be part of a web application that processes and exports chat conversations into an Excel file. There are several issues and optimizations that can be suggested:

Issues / Concerns

  1. Missing Import for RegexPattern:
    The use of ILLEGAL_CHARACTERS_RE requires the import statement at the beginning:

    import re
  2. Unused Variable reference_paragraph_len:
    After filtering paragraph lists, this variable is not used again anywhere in the function or exported data.

  3. Inconsistent Time Format Output:
    In the export method, there seems to be inconsistency regarding how time is formatted. While it uses .strftime('%Y-%m-%d %H:%M:%S'), then later converts it using .astimezone() with TIME_ZONE. It might be better to consistently format all times without timezone conversion.

Optimizations

  1. Avoid Creating Unnecessary Copies:
    For readability, consider defining functions outside to_row instead of inline lambda expressions within list comprehensions.

  2. Use More Concise Data Manipulation:
    If some of the logic inside improve_paragraph_list can be extracted into separate helper functions or methods, code would become cleaner.

  3. Consistent Formatting of Time Strings:
    Ensure that all time strings in the output have the same format before exporting (e.g., 'YYYY-MM-DD HH:MM:SS') to avoid confusion.

Here's a revised version of the export_data function incorporating these suggestions:

def to_row(row: Dict) -> List[Any]:
    improve_paragraph_list = row.get('improve_paragraph_list', [])

    # Define helper functions if needed
    def format_datetime(dt: Optional[datetime.datetime]) -> str:
        if dt:
            eastern_timezone = pytz.timezone(TIME_ZONE)
            return dt.astimezone(eastern_timezone).isoformat()
        return None

    return [
        str(row.get('chat_id')),
        row.get('abstract', "").replace("\r\n", " "),  # Replace newlines for cleaner display
        row.get('problem_text', ""),
        padding_problem_text,
        row.get('answer_text', "").replace("\r\n", " "),
        {"-1": '未投票', '0': '赞同', '1': '反对'}[row.get('vote_status')],
        len([p.title() for p in improve_paragraph_list] or []),
        "\n".join([
            f"{p.title()}:\n{p.content}" if p else "" for p in improve_paragraph_list
        ]),
        str(row.get('message_tokens')) + str(row.get('answer_tokens')),  # Sum tokens directly rather than concatenating
        row.get('run_time'),
        format_datetime(row.get('create_time'))
    ]

# Rest of the code remains largely unchanged except updating comments where necessary.

This revision ensures that time strings are consistently formatted and makes the code more readable and maintainable. Make sure to test the changes thoroughly in production after deploying them.

@shaohuzhang1 shaohuzhang1 merged commit 218a247 into main Feb 25, 2025
4 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@main@fix_chat_log_export branch February 25, 2025 08:17
@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Feb 25, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Feb 25, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant