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

show last saved time #559

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

show last saved time #559

wants to merge 3 commits into from

Conversation

anish-work
Copy link
Contributor

@anish-work anish-work commented Dec 11, 2024

Q/A checklist

  • If you add new dependencies, did you update the lock file?
poetry lock --no-update
  • Run tests
ulimit -n unlimited && ./scripts/run-tests.sh
  • Do a self code review of the changes - Read the diff at least twice.
  • Carefully think about the stuff that might break because of this change - this sounds obvious but it's easy to forget to do "Go to references" on each function you're changing and see if it's used in a way you didn't expect.
  • The relevant pages still run when you press submit
  • The API for those pages still work (API tab)
  • The public API interface doesn't change if you didn't want it to (check API tab > docs page)
  • Do your UI changes (if applicable) look acceptable on mobile?
  • Ensure you have not regressed the import time unless you have a good reason to do so.
    You can visualize this using tuna:
python3 -X importtime -c 'import server' 2> out.log && tuna out.log

To measure import time for a specific library:

$ time python -c 'import pandas'

________________________________________________________
Executed in    1.15 secs    fish           external
   usr time    2.22 secs   86.00 micros    2.22 secs
   sys time    0.72 secs  613.00 micros    0.72 secs

To reduce import times, import libraries that take a long time inside the functions that use them instead of at the top of the file:

def my_function():
    import pandas as pd
    ...

Legal Boilerplate

Look, I get it. The entity doing business as “Gooey.AI” and/or “Dara.network” was incorporated in the State of Delaware in 2020 as Dara Network Inc. and is gonna need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Dara Network Inc can use, modify, copy, and redistribute my contributions, under its choice of terms.

daras_ai_v2/utils.py Outdated Show resolved Hide resolved
daras_ai_v2/utils.py Outdated Show resolved Hide resolved
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Added relative timestamp display functionality for published recipes, with a new utility function for human-readable time differences.

  • Added get_relative_time() in /daras_ai_v2/utils.py to convert timestamps into human-readable formats (e.g. "2h ago")
  • Implemented _render_saved_timestamp() in /daras_ai_v2/base.py to display last saved time for non-root published runs
  • Added responsive styling to position timestamp to the right of navigation tabs
  • Note: Time calculation has limitations around month/year boundaries and lacks input validation

💡 (2/5) Greptile learns from your feedback when you react with 👍/👎!

2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

@devxpy
Copy link
Member

devxpy commented Dec 23, 2024

THRESHOLDS = [
    (timedelta(days=365), "y"),
    (timedelta(days=30), "mo"),
    (timedelta(days=1), "d"),
    (timedelta(hours=1), "h"),
    (timedelta(minutes=1), "m"),
    (timedelta(seconds=3), "s"),
]
def get_relative_time(timestamp: datetime) -> str:
    diff = timezone.now() - timestamp
    for threshold, unit in THRESHOLDS:
        if diff >= threshold:
            return f"{round(diff / threshold)}{unit} ago"
    return "Just now"

@devxpy
Copy link
Member

devxpy commented Dec 25, 2024

@anish-work

@anish-work
Copy link
Contributor Author

THRESHOLDS = [
    (timedelta(days=365), "y"),
    (timedelta(days=30), "mo"),
    (timedelta(days=1), "d"),
    (timedelta(hours=1), "h"),
    (timedelta(minutes=1), "m"),
    (timedelta(seconds=3), "s"),
]
def get_relative_time(timestamp: datetime) -> str:
    diff = timezone.now() - timestamp
    for threshold, unit in THRESHOLDS:
        if diff >= threshold:
            return f"{round(diff / threshold)}{unit} ago"
    return "Just now"

Updated @devxpy

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

This PR refactors the get_relative_time() utility function to improve code maintainability and readability while preserving its core functionality of displaying relative timestamps.

  • Introduced THRESHOLDS constant list in utils.py to replace nested if-statements with a more maintainable threshold-based approach
  • Added type hints to get_relative_time(timestamp: datetime) for better code clarity
  • Changed rounding behavior from int() to round() for more natural time representations
  • Modified seconds threshold from 2 to 3 seconds for "Just now" display

1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +17 to +18
if diff >= threshold:
return f"{round(diff / threshold)}{unit} ago"
Copy link

Choose a reason for hiding this comment

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

logic: using round() instead of int() could change behavior - e.g. 1.6 days will now show as 2d instead of 1d

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.

2 participants