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

port/MycroftAI/lingua-franca/pull/232 #27

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

NeonJarbas
Copy link

@NeonJarbas NeonJarbas commented Jun 21, 2022

port MycroftAI#232

(note, basque was already localized in #3 )

Summary by CodeRabbit

  • New Features

    • Introduced nice_relative_time function for generating human-readable time differences in the app.
  • Documentation

    • Updated notes in the nice_relative_time_eu function to specify time reporting limitations.
  • Tests

    • Added test cases for nice_relative_time to validate various time differentials.

Improve nice_relative_time tests

- Add more variations
- Remove import from mycroft-core
- Remove reference to local time to ensure deterministic outcome

Ensure relative datetimes are compared in the same timezone.

All comparisons are made in UTC to prevent issues of the two datetimes
passed in having different timezone info.

Remove unnecessary duplicate function

The nice_relative_time function is already defined in the top level format.py
hence it isn't needed in format_en.py.

This convention may change in the future.

Added general nice_relative_time_en

Added test for function nice_relative_time

Added function nice_relative_time (used in skill-alarm but not localized)
@JarbasAl JarbasAl added the enhancement New feature or request label Jun 21, 2022
@codecov
Copy link

codecov bot commented Jun 21, 2022

Codecov Report

❗ No coverage uploaded for pull request base (dev@392cc37). Click here to learn what that means.
The diff coverage is n/a.

@@          Coverage Diff          @@
##             dev     #27   +/-   ##
=====================================
  Coverage       ?   0.00%           
=====================================
  Files          ?      65           
  Lines          ?   16367           
  Branches       ?       0           
=====================================
  Hits           ?       0           
  Misses         ?   16367           
  Partials       ?       0           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 392cc37...e2fa1d9. Read the comment docs.

Copy link
Member

@NeonDaniel NeonDaniel left a comment

Choose a reason for hiding this comment

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

I'm not sure I agree with always rounding to one unit; if I request something in "2 hours and 15 minutes" replying with "in 2 hours" would indicate to me that the "and 15 minutes" was mis-transcribed..

Maybe this could optionally accept a "precision" param? Caller could specify 'hours'/'minutes'/'seconds', etc.

lingua_franca/format.py Outdated Show resolved Hide resolved
@ChanceNCounter
Copy link

Maybe this could optionally accept a "precision" param? Caller could specify 'hours'/'minutes'/'seconds', etc.

Unported work from mycroft.util.lang introduced the relevant enum, but I don't think anyone ever used it

@krisgesling
Copy link

I'm not sure I agree with always rounding to one unit; if I request something in "2 hours and 15 minutes" replying with "in 2 hours" would indicate to me that the "and 15 minutes" was mis-transcribed..

Maybe this could optionally accept a "precision" param? Caller could specify 'hours'/'minutes'/'seconds', etc.

Yeah, I think the current implementation is the simplest format that might be useful, but it still depends on the specific use case. Definitely lots of room for improvement here.

I'm also interested to look at how this relates to nice_duration() which takes a number of seconds as input but is in some ways another end of the same spectrum - it allows you to get a very specific representation of a period of time. Maybe a precision param provides that nice middle ground?

@NeonDaniel
Copy link
Member

Unported work from mycroft.util.lang introduced the relevant enum, but I don't think anyone ever used it

Didn't think to look, but I do see that now..
https://github.com/MycroftAI/mycroft-core/blob/1b67bf33e08541c34c331e7980ce0d6b4bc9c708/mycroft/util/format.py#L53

I'm also interested to look at how this relates to nice_duration() which takes a number of seconds as input but is in some ways another end of the same spectrum - it allows you to get a very specific representation of a period of time. Maybe a precision param provides that nice middle ground?

nice_relative_time, nice_duration

Maybe it would make sense to deal with total seconds and some default format in both cases? Something like:

def _get_spoken_duration(total_seconds: int, precision: TimeResolution):
    # Do formatting here

def nice_relative_time(when: datetime, relative_to: datetime):
    if relative_to:
        now = relative_to
    else:
        now = now_local()
    delta = to_local(when) - now
    if delta.total_seconds() < 1:
        return "now"

    if delta.total_seconds() < 90:
        if delta.total_seconds() == 1:
            return "one second"
        else:
            return _get_spoken_duration(delta.total_seconds(), TimeResolution.SECONDS
    ...
    
def nice_duration(duration, lang='', speech=True, precision: TimeResolution=TimeResolution.SECONDS):
    days = int(duration // 86400)
    hours = int(duration // 3600 % 24)
    minutes = int(duration // 60 % 60)
    seconds = int(duration % 60)

    if speech:
        out = ""
        if days > 0 and precision>=TimeResolution.DAYS:
    ...

@OpenVoiceOS OpenVoiceOS deleted a comment from coderabbitai bot Jul 17, 2024
@OpenVoiceOS OpenVoiceOS deleted a comment from coderabbitai bot Jul 17, 2024
@JarbasAl
Copy link
Member

@coderabbitai review

Copy link

coderabbitai bot commented Jul 17, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

coderabbitai bot commented Jul 17, 2024

Warning

Rate limit exceeded

@JarbasAl has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 33 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between e2fa1d9 and b6a8a8c.

Walkthrough

A new function nice_relative_time has been added to the lingua_franca module to generate human-readable descriptions of the time difference between two datetime values. Test cases have been included to validate its output. Additionally, a note regarding period limitations has been added to the nice_relative_time_eu function in the lingua_franca/lang/format_eu.py file.

Changes

File Path Change Summary
lingua_franca/format.py Added nice_relative_time function to create human-readable relative time descriptions.
lingua_franca/lang/format_eu.py Added a note specifying that only periods up to days are reported, ignoring weeks and months.
test/unittests/test_format_en.py Added TestNiceRelativeTime class with various test cases for the nice_relative_time function.

Poem

In the realm of time's embrace,
A new function finds its place. ⏳
Seconds, minutes, hours in flight,
Human-readable, a delight. ✨
Test cases bolster its might,
Making sure it's always right. 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 392cc37 and e2fa1d9.

Files selected for processing (3)
  • lingua_franca/format.py (2 hunks)
  • lingua_franca/lang/format_eu.py (1 hunks)
  • test/unittests/test_format_en.py (2 hunks)
Additional context used
Ruff
lingua_franca/format.py

601-604: Use ternary operator now = relative_to if relative_to else now_local() instead of if-else-block

Replace if-else-block with now = relative_to if relative_to else now_local()

(SIM108)

Additional comments not posted (2)
lingua_franca/lang/format_eu.py (1)

336-337: Clarification added to nice_relative_time_eu function is clear and informative.

The note explaining the limitation of the nice_relative_time_eu function to days is crucial for setting the correct expectations for the function's users. This is a good addition for clarity.

test/unittests/test_format_en.py (1)

538-571: Comprehensive tests for nice_relative_time function.

The tests cover various scenarios, ensuring that the function behaves as expected across different time differentials. This is a well-implemented test suite that should effectively catch regressions or errors in the nice_relative_time function.

lingua_franca/format.py Outdated Show resolved Hide resolved
lingua_franca/format.py Outdated Show resolved Hide resolved
JarbasAl and others added 2 commits July 17, 2024 14:19
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants