Make recommendation random

This commit is contained in:
cuom1999 2022-04-24 23:25:50 -05:00
parent ebe09cf0ad
commit 81644a7415

View file

@ -1,9 +1,10 @@
import logging
import os
import shutil
from datetime import timedelta
from datetime import timedelta, datetime
from operator import itemgetter
from random import randrange
import random
from django.conf import settings
from django.contrib.auth.decorators import login_required
@ -612,26 +613,21 @@ class ProblemFeed(ProblemList):
# arr = [[], [], ..]
def merge_recommendation(self, arr):
idx = [0] * len(arr)
stop = False
seed = datetime.now().strftime("%d%m%Y")
merged_array = []
for a in arr:
merged_array += a
random.Random(seed).shuffle(merged_array)
res = []
used_pid = set()
cnt = 0
while not stop:
cnt += 1
stop = True
for i in range(len(arr)):
if idx[i] < len(arr[i]):
obj = arr[i][idx[i]]
for obj in merged_array:
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
def get_queryset(self):