Skip to content

Commit

Permalink
crude impls of some of the reputation functions
Browse files Browse the repository at this point in the history
  • Loading branch information
daxaxelrod committed Dec 16, 2023
1 parent fecd0c9 commit a5aaf1b
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 10 deletions.
5 changes: 5 additions & 0 deletions pods/reputation/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@


def get_reputation_from_background(user: User, linkedin_profile: Person):
education = user.education.all()
experience = user.experience.all()
interests = user.interests.all()
region_info = user.region_info.all()

return 100
23 changes: 22 additions & 1 deletion pods/reputation/claims.py
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)
23 changes: 22 additions & 1 deletion pods/reputation/payments.py
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

11 changes: 3 additions & 8 deletions pods/reputation/reputation.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,13 @@ def determine_reputation_for_user(user):
except ReputationDetails.DoesNotExist:
pass

linkedin_profile = scrape_linkedin_profile(user.linkedin_url)
# linkedin_profile = scrape_linkedin_profile(user.linkedin_url)

payments = get_reputation_from_payments(user)
claims = get_reputation_from_claims(user)
background = get_reputation_from_background(user, linkedin_profile)
background = get_reputation_from_background(user)
activity = get_reputation_from_activity(user)
lifestyle = get_reputation_from_lifestyle(user, linkedin_profile)

import pdb; pdb.set_trace()

with open('./profile.json', 'w') as file:
json.dump(linkedin_profile.to_dict(), file)
lifestyle = get_reputation_from_lifestyle(user)


total_score = (payments + claims + background + activity + lifestyle) / 5
Expand Down
13 changes: 13 additions & 0 deletions policies/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ def short_description(self):

def __str__(self) -> str:
return f"Premium for {self.policy.name} paid by {self.payer}, due on {self.due_date}"

def paid_on_time(self):
return self.paid_date <= self.due_date


class PolicyCloseout(models.Model):
Expand Down Expand Up @@ -355,6 +358,16 @@ def is_approved(self):
return (approved_count / all_approvals_count) >= (
self.policy.claim_approval_threshold_percentage / 100
)

def is_denied(self):
all_approvals_count = self.approvals.count()
denied_count = self.approvals.filter(approved=False).count()
if all_approvals_count == 0:
# approvals not created for some reason, shouldnt happen
return False
return (denied_count / all_approvals_count) >= (
(100 - self.policy.claim_approval_threshold_percentage) / 100
)

def has_evidence(self):
return self.evidence.count() > 0
Expand Down

0 comments on commit a5aaf1b

Please sign in to comment.