Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tea in the rank list #414

Closed
VinceUB opened this issue Mar 5, 2024 · 6 comments
Closed

Tea in the rank list #414

VinceUB opened this issue Mar 5, 2024 · 6 comments

Comments

@VinceUB
Copy link

VinceUB commented Mar 5, 2024

Why is there no tea in the rank list:(
Would be nice if there was tea in the rank list.
(It would be the only category I actually have a chance of getting anywhere on)

@krestenlaust
Copy link
Member

Feel free to dive in. Let me know if you need more pointers!

The template file related:
https://github.com/f-klubben/stregsystemet/blob/af0efd806ae743b0e8a9639376c4a31b81d61cd2/stregsystem/templates/stregsystem/menu_userrank.html

The view procedure which does the rendering:

def menu_userrank(request, room_id, member_id):
from_date = fjule_party(datetime.datetime.today().year - 1)
to_date = datetime.datetime.now(tz=pytz.timezone("Europe/Copenhagen"))
room = Room.objects.get(pk=room_id)
member = Member.objects.get(pk=member_id, active=True)
def ranking(category_ids, from_d, to_d):
qs = (
Member.objects.filter(sale__product__in=category_ids, sale__timestamp__gt=from_d, sale__timestamp__lte=to_d)
.annotate(Count('sale'))
.order_by('-sale__count', 'username')
)
if member not in qs:
return 0, qs.count()
return list(qs).index(Member.objects.get(id=member.id)) + 1, int(qs.count())
def get_product_ids_for_category(category) -> list:
return list(
Product.objects.filter(categories__exact=Category.objects.get(name__exact=category)).values_list(
'id', flat=True
)
)
def category_per_uni_day(category_ids, from_d, to_d):
qs = Member.objects.filter(
id=member.id,
sale__product__in=category_ids,
sale__timestamp__gt=from_d,
sale__timestamp__lte=to_d,
)
if member not in qs:
return 0
else:
return "{:.2f}".format(qs.count() / ((to_d - from_d).days * 162.14 / 365)) # university workdays in 2021
# let user know when they first purchased a product
member_first_purchase = "Ikke endnu, køb en limfjordsporter!"
first_purchase = Sale.objects.filter(member=member_id).order_by('-timestamp')
if first_purchase.exists():
member_first_purchase = first_purchase.last().timestamp
form = RankingDateForm()
if request.method == "POST" and request.POST['custom-range']:
form = RankingDateForm(request.POST)
if form.is_valid():
from_date = form.cleaned_data['from_date']
to_date = form.cleaned_data['to_date'] + datetime.timedelta(days=1)
else:
# setup initial dates for form and results
form = RankingDateForm(initial={'from_date': from_date, 'to_date': to_date})
# get prod_ids for each category as dict {cat: [key1, key2])}, then flatten list of singleton
# dicts into one dict, lastly calculate member_id rating and units/weekday for category_ids
rankings = {
key: (
ranking(category_ids, from_date, to_date),
category_per_uni_day(category_ids, from_date, to_date),
)
for key, category_ids in {
k: v
for x in map(lambda x: {x: get_product_ids_for_category(x)}, list(Category.objects.all()))
for k, v in x.items()
}.items()
}
return render(request, 'stregsystem/menu_userrank.html', locals())

@JakobTopholt
Copy link
Contributor

How is it going @VinceUB ?

@VinceUB
Copy link
Author

VinceUB commented Mar 22, 2024

P4 is going...

@JakobTopholt
Copy link
Contributor

Is P4 still going @VinceUB ?

@VinceUB
Copy link
Author

VinceUB commented Apr 15, 2024

Funny story, we actually finished the entire program last Friday and are planning to go through the report a final time tomorrow before we hand in, so I'll start work after that.

I AM JOKING. P4 IS NOT OVER. IT IS STILL GOING. Funny how it takes more than a month to learn about, plan out, write, and describe an interpreter for a custom language.

@krestenlaust
Copy link
Member

Solved thanks to @BoAnd's advice
billede

Should Fuzetea (icetea) be in the category? @VinceUB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants