-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crude impls of some of the reputation functions
- Loading branch information
1 parent
fecd0c9
commit a5aaf1b
Showing
5 changed files
with
65 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,26 @@ | ||
import math | ||
from pods.models import User | ||
|
||
|
||
def get_reputation_from_claims(user: User()): | ||
return 100 | ||
|
||
claims = user.claims.all() | ||
if len(claims) == 0: | ||
return 100 | ||
approved_claims = 0 | ||
denied_claims = 0 | ||
pending_claims = 0 | ||
for claim in claims: | ||
if claim.is_approved(): | ||
approved_claims += 1 | ||
elif claim.is_denied(): | ||
denied_claims += 1 | ||
else: | ||
pending_claims += 1 | ||
|
||
pending_penalty = 8 # 8 points per pending claim | ||
approved_penalty = 1 | ||
denied_penalty = 20 | ||
|
||
total_penalty = pending_penalty * pending_claims + approved_penalty * approved_claims + denied_penalty * denied_claims | ||
return max(100 - total_penalty, 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,26 @@ | ||
from pods.models import User | ||
from django.utils import timezone | ||
from policies.models import Premium | ||
|
||
# | ||
|
||
def get_reputation_from_payments(user: User): | ||
return 100 | ||
all_payments: list[Premium] = user.premiums_paid.filter( | ||
due_date__lte=timezone.now() | ||
) | ||
|
||
if len(all_payments) == 0: | ||
return 100 | ||
|
||
on_time_payments = 0 | ||
late_payments = 0 | ||
for payment in all_payments: | ||
if payment.paid_on_time(): | ||
on_time_payments += 1 | ||
else: | ||
late_payments += 1 | ||
|
||
# the more late payments, the harsher the penalty | ||
fraction = late_payments / len(all_payments) | ||
return 100 - fraction * 100 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters