Skip to content

Commit

Permalink
Save point for version with completely correct calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
joemarct committed Dec 3, 2017
1 parent 44bbcec commit 5deb21a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion venue/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def total_posts_with_sig(self, obj):
return obj.get_total_posts_with_sig()

def total_post_days(self, obj):
return round(obj.get_total_days(), 2)
return round(obj.get_total_days(), 4)

def total_points(self, obj):
return round(obj.get_total_points(), 2)
Expand Down
4 changes: 2 additions & 2 deletions venue/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class SignatureSerializer(serializers.ModelSerializer):

class Meta:
model = Signature
fields = ('id', 'name', 'forum_site', 'user_ranks', 'code', 'image', 'active', 'verification_code')
fields = ('id', 'name', 'forum_site', 'user_ranks', 'code',
'image', 'active', 'verification_code')

def inject_verification_code(sig_code, verification_code):
def repl(m):
Expand All @@ -90,7 +91,6 @@ def get_queryset(self):
if own_sigs:
my_fps = ForumProfile.objects.filter(
user_profile__user=self.request.user,
uptime_batches__active=True,
verified=True)
name_map = {}
vcode_map = {}
Expand Down
16 changes: 9 additions & 7 deletions venue/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,12 @@ def get_batch_number(self):

def get_total_posts(self):
value = 0
latest_batch = self.forum_profile.uptime_batches.last()
if latest_batch:
if latest_batch.id == self.id:
latest_check = latest_batch.regular_checks.last()
value = latest_check.total_posts
if self.forum_profile.get_total_posts_with_sig():
latest_batch = self.forum_profile.uptime_batches.last()
if latest_batch:
if latest_batch.id == self.id:
latest_check = latest_batch.regular_checks.last()
value = latest_check.total_posts
return value

def get_total_posts_with_sig(self):
Expand Down Expand Up @@ -295,8 +296,9 @@ def save(self, *args, **kwargs):
self.influence_points = 0.0
if batch.get_total_posts() and latest_gs.total_posts:
sum_total_posts = 0
for item in self.uptime_batch.forum_profile.uptime_batches.all():
sum_total_posts += item.get_total_posts()
if self.uptime_batch.forum_profile.get_total_posts_with_sig():
for item in self.uptime_batch.forum_profile.uptime_batches.all():
sum_total_posts += item.get_total_posts()
self.influence_points = decimal.Decimal(sum_total_posts * 200)
self.influence_points /= latest_gs.total_posts
# Calculate total points
Expand Down
8 changes: 5 additions & 3 deletions venue/scrapers/bitcoin_forum.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def get_total_posts(self):
return elem[2].text.split()[0]

def get_user_position(self):
position = 'No rank'
position = None
elem = self.soup.select('div.bg1 dl.left-box dd')
if elem:
try:
Expand All @@ -83,12 +83,14 @@ def get_user_position(self):
if not position:
details = {}
dt_keys = self.soup.select('div.bg1 dl.profile-details dt')
dt_values = soup.select('div.bg1 dl.profile-details dd')
dt_values = self.soup.select('div.bg1 dl.profile-details dd')
for i, dk in enumerate(dt_keys):
key = dk.text.strip().replace(':', '')
if value:
if dt_values[i]:
details[key] = dt_values[i].text.strip()
position = details['Rank']
else:
position = 'No rank'
return position

def verify_code(self, code, forum_profile_id, forum_user_id):
Expand Down
4 changes: 2 additions & 2 deletions venue/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ def get_stats(request):
fp_data['postDaysPoints'].append(int(latest_calc.post_days_points))
fp_data['totalPostDays'].append(batch.get_total_days())
fp_data['influencePoints'].append(int(latest_calc.influence_points))
fp_data['totalPoints'].append(int(latest_calc.total_points))
fp_data['VTX_Tokens'].append(int(latest_calc.get_total_tokens()))
fp_data['totalPoints'].append(round(latest_calc.total_points, 0))
fp_data['VTX_Tokens'].append(round(latest_calc.get_total_tokens(), 0))
sum_up_data = {k: '{:,}'.format(sum(v)) for k,v in fp_data.items()}
sum_up_data['User_ID'] = fp.forum_user_id
sum_up_data['forumSite'] = fp.forum.name
Expand Down

0 comments on commit 5deb21a

Please sign in to comment.