Make recommendation random
This commit is contained in:
parent
ebe09cf0ad
commit
81644a7415
1 changed files with 17 additions and 21 deletions
|
@ -1,9 +1,10 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
from datetime import timedelta
|
from datetime import timedelta, datetime
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from random import randrange
|
from random import randrange
|
||||||
|
import random
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
|
@ -161,7 +162,7 @@ class ProblemDetail(ProblemMixin, SolvedProblemMixin, CommentedDetailView):
|
||||||
template_name = 'problem/problem.html'
|
template_name = 'problem/problem.html'
|
||||||
|
|
||||||
def get_comment_page(self):
|
def get_comment_page(self):
|
||||||
return 'p:%s' % self.object.code
|
return 'p:%s' % self.object.code
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(ProblemDetail, self).get_context_data(**kwargs)
|
context = super(ProblemDetail, self).get_context_data(**kwargs)
|
||||||
|
@ -611,27 +612,22 @@ class ProblemFeed(ProblemList):
|
||||||
orphans=orphans, allow_empty_first_page=allow_empty_first_page, **kwargs)
|
orphans=orphans, allow_empty_first_page=allow_empty_first_page, **kwargs)
|
||||||
|
|
||||||
# arr = [[], [], ..]
|
# arr = [[], [], ..]
|
||||||
def merge_recommendation(self, arr):
|
def merge_recommendation(self, arr):
|
||||||
idx = [0] * len(arr)
|
seed = datetime.now().strftime("%d%m%Y")
|
||||||
stop = False
|
merged_array = []
|
||||||
|
for a in arr:
|
||||||
|
merged_array += a
|
||||||
|
random.Random(seed).shuffle(merged_array)
|
||||||
|
|
||||||
res = []
|
res = []
|
||||||
used_pid = set()
|
used_pid = set()
|
||||||
cnt = 0
|
|
||||||
while not stop:
|
for obj in merged_array:
|
||||||
cnt += 1
|
if type(obj) == tuple:
|
||||||
stop = True
|
obj = obj[1]
|
||||||
for i in range(len(arr)):
|
if obj not in used_pid:
|
||||||
if idx[i] < len(arr[i]):
|
res.append(obj)
|
||||||
obj = arr[i][idx[i]]
|
used_pid.add(obj)
|
||||||
if type(obj) == tuple:
|
|
||||||
obj = obj[1]
|
|
||||||
elif cnt % 3 != 0: # hot problems appear less
|
|
||||||
continue
|
|
||||||
if obj not in used_pid:
|
|
||||||
res.append(obj)
|
|
||||||
used_pid.add(obj)
|
|
||||||
idx[i] += 1
|
|
||||||
stop = False
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
|
|
Loading…
Reference in a new issue