Skip to content

Instantly share code, notes, and snippets.

@tritium21
Last active June 23, 2018 11:07
Show Gist options
  • Select an option

  • Save tritium21/b7cbb2452966685b75252f99bdfa9f5f to your computer and use it in GitHub Desktop.

Select an option

Save tritium21/b7cbb2452966685b75252f99bdfa9f5f to your computer and use it in GitHub Desktop.
import datetime
import math
import sys
def main(argv):
try:
goal = int(argv[1])
current = float(argv[2])
except:
return f"Usage: {argv[0]} <goal:int> <current:int>"
total_days = (
datetime.date(datetime.date.today().year, 12, 31).timetuple().tm_yday
)
today = datetime.date.today().timetuple().tm_yday
remaining_days = total_days - today
days_per = total_days/goal
on_track = int(today/days_per)
rate = current/today
percent_completed = current/goal
projected_final = int(rate * total_days)
actual_current_delta = int(math.floor(current)) - on_track
ahead = 'ahead' if actual_current_delta >= 0 else 'behind'
projected_finish_day = int(math.ceil(goal/rate))
projected_finish_date = (
datetime.date(datetime.date.today().year, 1, 1)
+ datetime.timedelta(projected_finish_day)
)
days_til_projected = projected_finish_day - today
print("Goodreads Reading Challenge Stats Thingy")
print()
print(
f"You have read {int(math.floor(current))} out of your pledge of {goal} books.\n"
f"Your Reading Challenge is {percent_completed:.1%} complete, "
f"{actual_current_delta} books {ahead} of a scheduled {on_track}.\n"
f"At the current rate of {rate:.2} books/day, you are projected to "
f"finish your challenge\non {projected_finish_date:%B %d, %Y} "
f"({days_til_projected} days from now), and read {projected_final} "
"books by the end of the year!"
)
return
if __name__ == "__main__":
sys.exit(main(sys.argv))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment