Compare commits
4 Commits
85f52fc735
...
8efce77062
Author | SHA1 | Date |
---|---|---|
Lukáš Kucharczyk | 8efce77062 | |
Lukáš Kucharczyk | 89be0c031b | |
Lukáš Kucharczyk | 4e67735de8 | |
Lukáš Kucharczyk | 869e0e0fe0 |
|
@ -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
|
||||
|
|
16
Makefile
16
Makefile
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 %}
|
|
@ -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)
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue