Compare commits

..

4 Commits

Author SHA1 Message Date
Lukáš Kucharczyk 8efce77062
Improve newcomer experience
continuous-integration/drone/push Build is passing Details
2023-01-05 17:15:14 +01:00
Lukáš Kucharczyk 89be0c031b
Fix errors with empty database 2023-01-05 17:14:34 +01:00
Lukáš Kucharczyk 4e67735de8
Fix negative playtimes being considered positive 2023-01-05 17:13:45 +01:00
Lukáš Kucharczyk 869e0e0fe0
Run all python Makefile commands via poetry 2023-01-05 17:12:57 +01:00
6 changed files with 27 additions and 12 deletions

View File

@ -1,4 +1,7 @@
## Unreleased
* Improve the newcomer experience by guiding through each step
* Fix errors with empty database
* Fix negative playtimes being considered positive
* Add %d for days to common.util.time.format_duration
* Set up tests, add tests for common.util.time
* Display total hours played on homepage

View File

@ -16,28 +16,28 @@ css-dev: css
npx tailwindcss -i ./src/input.css -o ./src/web/tracker/static/base.css --watch
makemigrations:
python src/web/manage.py makemigrations
poetry run python src/web/manage.py makemigrations
migrate: makemigrations
python src/web/manage.py migrate
poetry run python src/web/manage.py migrate
dev: migrate
python src/web/manage.py runserver
TZ=Europe/Prague poetry run python src/web/manage.py runserver
dumptracker:
python src/web/manage.py dumpdata --format yaml tracker --output tracker_fixture.yaml
poetry run python src/web/manage.py dumpdata --format yaml tracker --output tracker_fixture.yaml
loadplatforms:
python src/web/manage.py loaddata platforms.yaml
poetry run python src/web/manage.py loaddata platforms.yaml
loadsample:
python src/web/manage.py loaddata sample.yaml
poetry run python src/web/manage.py loaddata sample.yaml
createsuperuser:
python src/web/manage.py createsuperuser
poetry run python src/web/manage.py createsuperuser
shell:
python src/web/manage.py shell
poetry run python src/web/manage.py shell
poetry.lock: pyproject.toml
poetry install

View File

@ -23,6 +23,9 @@ def format_duration(
hour_seconds = 60 * minute_seconds
day_seconds = 24 * hour_seconds
seconds_total = int(duration.total_seconds())
# timestamps where end is before start
if seconds_total < 0:
seconds_total = 0
days, remainder = divmod(seconds_total, day_seconds)
hours, remainder = divmod(remainder, hour_seconds)
minutes, seconds = divmod(remainder, minute_seconds)

View File

@ -6,8 +6,12 @@
<div class="text-slate-300 mx-auto max-w-screen-lg text-center">
{% if session_count > 0 %}
You have played a total of {{ session_count }} sessions for a total of {{ total_duration }}.
{% elif not game_available or not platform_available %}
There are no games in the database. Start by clicking "New Game" and "New Platform".
{% elif not purchase_available %}
There are no owned games. Click "New Purchase" at the top.
{% else %}
Start by clicking the links at the top. To track playtime, you need to have at least 1 owned game.
You haven't played any games yet. Click "New Session" to add one now.
{% endif %}
</div>
{% endblock content %}

View File

@ -104,12 +104,12 @@ def add_platform(request):
def index(request):
context = {}
if Session.objects.count() == 0:
duration_value = 0
duration: str = ""
else:
result = Session.objects.all().aggregate(Sum("duration_calculated"))
context["total_duration"] = format_duration(
duration = format_duration(
result["duration_calculated__sum"], "%H hours %m minutes"
)
context["total_duration"] = duration_value
context["total_duration"] = duration
context["title"] = "Index"
return render(request, "index.html", context)

View File

@ -51,3 +51,8 @@ class FormatDurationTest(unittest.TestCase):
self.assertEqual(
result, "50 days, 10 hours, 34 minutes, 24 seconds, 4358064 total seconds"
)
def test_negative(self):
delta = timedelta(hours=-2)
result = format_duration(delta, "%H hours")
self.assertEqual(result, "0 hours")