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
|
||||||
|
@ -612,26 +613,21 @@ class ProblemFeed(ProblemList):
|
||||||
|
|
||||||
# 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
|
|
||||||
stop = True
|
|
||||||
for i in range(len(arr)):
|
|
||||||
if idx[i] < len(arr[i]):
|
|
||||||
obj = arr[i][idx[i]]
|
|
||||||
if type(obj) == tuple:
|
if type(obj) == tuple:
|
||||||
obj = obj[1]
|
obj = obj[1]
|
||||||
elif cnt % 3 != 0: # hot problems appear less
|
|
||||||
continue
|
|
||||||
if obj not in used_pid:
|
if obj not in used_pid:
|
||||||
res.append(obj)
|
res.append(obj)
|
||||||
used_pid.add(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