From 190afd4669c7c4fc3cfe82b7825913b07f27643b Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Mon, 7 Aug 2023 11:56:41 +0000 Subject: [PATCH 1/6] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index fdcf0ceedf1f..e6a1ff356143 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -585,6 +585,7 @@ * [Hardy Ramanujanalgo](maths/hardy_ramanujanalgo.py) * [Hexagonal Number](maths/hexagonal_number.py) * [Integration By Simpson Approx](maths/integration_by_simpson_approx.py) + * [Interquartile Range](maths/interquartile_range.py) * [Is Int Palindrome](maths/is_int_palindrome.py) * [Is Ip V4 Address Valid](maths/is_ip_v4_address_valid.py) * [Is Square Free](maths/is_square_free.py) From 2a3f2876ef658387a0369810fe2d0ff092bf56f1 Mon Sep 17 00:00:00 2001 From: CaedenPH Date: Wed, 16 Aug 2023 16:42:38 +0100 Subject: [PATCH 2/6] fix(get-top-billionaires): Handle timestamp before epoch --- pyproject.toml | 1 - ...naires.py.disabled => get_top_billionaires.py} | 15 ++++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) rename web_programming/{get_top_billionaires.py.disabled => get_top_billionaires.py} (80%) diff --git a/pyproject.toml b/pyproject.toml index f9091fb8578d..0e268c644b3f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -103,7 +103,6 @@ max-complexity = 17 # default: 10 "machine_learning/linear_discriminant_analysis.py" = ["ARG005"] "machine_learning/sequential_minimum_optimization.py" = ["SIM115"] "matrix/sherman_morrison.py" = ["SIM103", "SIM114"] -"other/l*u_cache.py" = ["RUF012"] "physics/newtons_second_law_of_motion.py" = ["BLE001"] "project_euler/problem_099/sol1.py" = ["SIM115"] "sorts/external_sort.py" = ["SIM115"] diff --git a/web_programming/get_top_billionaires.py.disabled b/web_programming/get_top_billionaires.py similarity index 80% rename from web_programming/get_top_billionaires.py.disabled rename to web_programming/get_top_billionaires.py index 6a8054e26270..e1d487d7f6ab 100644 --- a/web_programming/get_top_billionaires.py.disabled +++ b/web_programming/get_top_billionaires.py @@ -3,7 +3,7 @@ This works for some of us but fails for others. """ -from datetime import datetime +from datetime import UTC, datetime, timedelta import requests from rich import box @@ -20,7 +20,7 @@ ) -def calculate_age(unix_date: int) -> str: +def calculate_age(unix_date: float) -> str: """Calculates age from given unix time format. Returns: @@ -31,7 +31,16 @@ def calculate_age(unix_date: int) -> str: >>> calculate_age(46915200000) '51' """ - birthdate = datetime.fromtimestamp(unix_date / 1000).date() + # Convert date from milliseconds to seconds + unix_date /= 1000 + + if unix_date < 0: + # Handle timestamp before epoch + epoch = datetime.fromtimestamp(0, tz=UTC) + seconds_since_epoch = (datetime.now(tz=UTC) - epoch).seconds + birthdate = (epoch - timedelta(seconds=unix_date - seconds_since_epoch)).date() + else: + birthdate = datetime.fromtimestamp(unix_date, tz=UTC).date() return str( TODAY.year - birthdate.year From 69dde7015fa3d3296af0ca3ab84422721361b34e Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Wed, 16 Aug 2023 15:42:58 +0000 Subject: [PATCH 3/6] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 8d1567465fbc..bcac340f3ce2 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -1220,6 +1220,7 @@ * [Get Amazon Product Data](web_programming/get_amazon_product_data.py) * [Get Imdb Top 250 Movies Csv](web_programming/get_imdb_top_250_movies_csv.py) * [Get Imdbtop](web_programming/get_imdbtop.py) + * [Get Top Billionaires](web_programming/get_top_billionaires.py) * [Get Top Hn Posts](web_programming/get_top_hn_posts.py) * [Get User Tweets](web_programming/get_user_tweets.py) * [Giphy](web_programming/giphy.py) From 0431171af4fa8e5f1f360ad5b9a253614e02d3e8 Mon Sep 17 00:00:00 2001 From: CaedenPH Date: Wed, 16 Aug 2023 16:46:20 +0100 Subject: [PATCH 4/6] revert(pyproject): Re-implement ignore lru_cache --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 0e268c644b3f..f9091fb8578d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -103,6 +103,7 @@ max-complexity = 17 # default: 10 "machine_learning/linear_discriminant_analysis.py" = ["ARG005"] "machine_learning/sequential_minimum_optimization.py" = ["SIM115"] "matrix/sherman_morrison.py" = ["SIM103", "SIM114"] +"other/l*u_cache.py" = ["RUF012"] "physics/newtons_second_law_of_motion.py" = ["BLE001"] "project_euler/problem_099/sol1.py" = ["SIM115"] "sorts/external_sort.py" = ["SIM115"] From 01fd82484eb01abbcf96ad37abea2b927b3cfd78 Mon Sep 17 00:00:00 2001 From: CaedenPH Date: Wed, 16 Aug 2023 16:49:12 +0100 Subject: [PATCH 5/6] fix(age): Update age to current year --- web_programming/get_top_billionaires.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/web_programming/get_top_billionaires.py b/web_programming/get_top_billionaires.py index e1d487d7f6ab..7b01e5295253 100644 --- a/web_programming/get_top_billionaires.py +++ b/web_programming/get_top_billionaires.py @@ -27,9 +27,9 @@ def calculate_age(unix_date: float) -> str: Age as string >>> calculate_age(-657244800000) - '73' + '74' >>> calculate_age(46915200000) - '51' + '52' """ # Convert date from milliseconds to seconds unix_date /= 1000 @@ -38,7 +38,9 @@ def calculate_age(unix_date: float) -> str: # Handle timestamp before epoch epoch = datetime.fromtimestamp(0, tz=UTC) seconds_since_epoch = (datetime.now(tz=UTC) - epoch).seconds - birthdate = (epoch - timedelta(seconds=unix_date - seconds_since_epoch)).date() + birthdate = ( + epoch - timedelta(seconds=abs(unix_date) - seconds_since_epoch) + ).date() else: birthdate = datetime.fromtimestamp(unix_date, tz=UTC).date() return str( From bfad09e36754629a748062760a6c174821d6107b Mon Sep 17 00:00:00 2001 From: CaedenPH Date: Fri, 18 Aug 2023 13:44:28 +0200 Subject: [PATCH 6/6] fix(doctest): Make years since dynamic --- web_programming/get_top_billionaires.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/web_programming/get_top_billionaires.py b/web_programming/get_top_billionaires.py index 7b01e5295253..6f986acb9181 100644 --- a/web_programming/get_top_billionaires.py +++ b/web_programming/get_top_billionaires.py @@ -26,10 +26,12 @@ def calculate_age(unix_date: float) -> str: Returns: Age as string - >>> calculate_age(-657244800000) - '74' - >>> calculate_age(46915200000) - '52' + >>> from datetime import datetime, UTC + >>> years_since_create = datetime.now(tz=UTC).year - 2022 + >>> int(calculate_age(-657244800000)) - years_since_create + 73 + >>> int(calculate_age(46915200000)) - years_since_create + 51 """ # Convert date from milliseconds to seconds unix_date /= 1000