Skip to content

feat: show simple shift statistics #649

Open
crosspolar wants to merge 40 commits intomasterfrom
shift_stats
Open

feat: show simple shift statistics #649
crosspolar wants to merge 40 commits intomasterfrom
shift_stats

Conversation

@crosspolar
Copy link
Copy Markdown
Contributor

Resolves #407 .

Simple markup but I think currently sufficient. Let me know if you see it somewhere else...

@crosspolar crosspolar changed the title feat: show simple statistics per shift feat: show simple shift statistics Aug 8, 2025
Copy link
Copy Markdown
Collaborator

@Theophile-Madet Theophile-Madet left a comment

Choose a reason for hiding this comment

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

The shift detail page already has a lot of information, I don't think we should add more, especially if they are not relevant for everyday use.

I would either make a separate page for shift stats, or maybe add a button to the header with just the stats icon (material-icon calculate) that shows a popup or a tooltip.

Also we'll need tests.

@crosspolar crosspolar marked this pull request as ready for review August 12, 2025 16:19
Copy link
Copy Markdown
Collaborator

@Theophile-Madet Theophile-Madet left a comment

Choose a reason for hiding this comment

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

  • Should we show the same stats on the shift template detail page?
  • Can you try to check the amount of DB requests this creates when there are a lot of past shifts? I added a comment on tapir/shifts/views/views.py. Let me know if you need help with Silk or how to use selected_related and prefetch_related.
  • The main stats page is intended as an overview of the key stats to reach the break-even. We removed all other stats on purpose to keep the overview clear, I think it should stay as it is. We could rename the current page to "Stats for break-even" or "Key stats" and add another one called "secondary stats"? There are a few stats from the old member stats page that we removed for clarity and because they are untested, but we could move them to a secondary stats page later.

@crosspolar
Copy link
Copy Markdown
Contributor Author

Hey,

  • number of queries: I didn't keep the stats but the annotate (which seems great for aggregations) reduced number of queries from around 10 to 2.
  • I removed the overall statistics since a bit unsure where to add. Maybe we can add it on some later release again

Copy link
Copy Markdown
Collaborator

@Theophile-Madet Theophile-Madet left a comment

Choose a reason for hiding this comment

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

A few more style suggestions but I think we're getting there.

@crosspolar
Copy link
Copy Markdown
Contributor Author

@Theophile-Madet , thanks for your feedback. I really try to comply with the test-naming-style-guide, but keep forgetting sorry.
About the open comment: Maybe I misunderstood your suggestion, but I would sleep better with the current flexibility.

@Theophile-Madet
Copy link
Copy Markdown
Collaborator

Are the force push always needed? After a force push I can't use the "show differences since last review" feature.

@crosspolar
Copy link
Copy Markdown
Contributor Author

Are the force push always needed? After a force push I can't use the "show differences since last review" feature.

No, of course not. I just do rebases to update the PRs but if we squash before merge I think I don't have to

)

context = ShiftDetailView.get_past_shifts_data(shift_template)
self.assertAlmostEqual(context["total_hours"], 7.0)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this can just be a normal self.assertEqual? Is there a reason for using assertAlmostEqual?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Floating-point numbers, you know. The print(0.1+0.2 == 0.3) giving False.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

But have you actually had that problem here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, but I would say it's good practice preventing problems


@register.simple_tag
def random_shift_text(total_hours, no_of_past_shifts, first_shift_date):
texts = [
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm not sure I understand the point of this, is it not all the same sentence but formulated slightly differently?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I didn't like any text so I thought it would be nice if they change from time to time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

but I'm also not fighting for this feature

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Then I'd remove it, otherwise it's not clear why it's here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

crosspolar and others added 6 commits February 24, 2026 20:11
Co-authored-by: Théophile MADET <theo.madet@posteo.net>
Co-authored-by: Théophile MADET <theo.madet@posteo.net>
# Conflicts:
#	tapir/translations/locale/de/LC_MESSAGES/django.po

@register.simple_tag
def random_shift_text(total_hours, no_of_past_shifts, first_shift_date):
texts = [
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Then I'd remove it, otherwise it's not clear why it's here.

# Conflicts:
#	tapir/translations/locale/de/LC_MESSAGES/django.po
@crosspolar
Copy link
Copy Markdown
Contributor Author

crosspolar commented Mar 13, 2026

So without the type hint you get a warning from PyCharm? What's the warning?

mh, it's gone idk. But I leave if it it's okay since the typing is also in other files. It was something like "ShiftFactory does not have slots"

# Conflicts:
#	tapir/translations/locale/de/LC_MESSAGES/django.po
# Conflicts:
#	tapir/translations/locale/de/LC_MESSAGES/django.po
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.

Add to the shift stats page the total number of shift attendances since the beginning.

2 participants