Я постараюсь сделать мою проблему максимально простой. Сводка этого сценария выглядит следующим образом:
Начните с нового файла py, который принимает в качестве входных данных 3 вещи:
- один список столбцов текущих студентов - который может меняться на протяжении всего semester
- «предыдущие рецензии»: список списков, где каждый внутренний список [student_being_reviewed, student_doing_review, assignment]
- new_assignment_name (для которого мы назначаем одноранговые узлы)
Затем сценарий создаст в качестве вывода:
- список списков, где каждый внутренний список представляет собой [student_being_reviewed, student_doing_review, new_assignment_name]
И условия:
- Если X проверяет Y, X никогда не проверяет Y снова, а Y никогда не проверяет X (поэтому нам нужны предыдущие экспертные оценки)
- По данному заданию триплет не существует, если X рассматривает Y и Y рассматривает Z и Z рассматривает X.
- Каждый учащийся, получивший оценку, проверяется двумя разными сверстниками для каждого задания - * 10 26 *
#this will help us meet our requirement of each student being reviewed
#by exactly 2 different peeers
def count_reviewed_by(dic, student):
count = 0
for key in dic:
if student in dic[key]:
count+=1
return count
#now we are going to write a helper function that will tell us if there's
#a cycle.
#a cycle is X reviews Y and Y reviews Z and Z reviews X.
#so this detects if there's a triplet for student x
#reviewing student y.
def detect_cycle(dic, x, y):
if(dic.get(y) == None):
return False
for z in dic[y]:
if(dic.get(z) == None):
continue
if x in dic[z]:
return True
return False
#so this is our function where we are going to generate the new review
#setup.
def generate_new_dic(dic, current_students):
newdic = {}
#okay, the problem is we need to reverse it
#this is gonig to be the person being reviewed
for student in current_students:
newdic[student] = []
#this is the person reviewing them
for other_student in current_students:
#a student can't review themselves
if(student == other_student):
continue
#this student has reviewed other student student in the past
if (other_student in dic[student]):
continue
#other student has reviewed this student
if(student in dic[other_student]):
continue
#triplet found
if(detect_cycle(newdic, other_student, student)):
continue
#none of the above conditions were met so we can
#use this student.
newdic[student].append(other_student)
#if we've found 2 students for this person to review so we can stop looking
if(len(newdic[student]) == 2):
break
return newdic
def peer_review(current_students, previous_reviews, new_assignment):
#we want to loop over the elements of current students
#our goal is a dictionary, of students where each key is the student
#and each value is the list of students they have reviewed
reviewed = {}
for i in range(0, len(current_students)):
#so this just inits the dictionary for every student
reviewed[current_students[i]] = []
for review in previous_reviews:
if not review[0] in reviewed[review[1]]:
reviewed[review[1]].append(review[0])
newdic = generate_new_dic(reviewed, current_students)
#now we just have to generate the list of lists in the proper format
print()
print()
for key in newdic:
print(key + " : " + str(newdic[key]))
print()
print()
new_reviews = []
for reviewee in newdic:
for reviewer in newdic[reviewee]:
new_reviews.append([reviewee, reviewer, new_assignment])
return new_reviews
all_students = [
'A','B','C','D','E','F','G','H','I','J','K','L','M'
]
print()
print()
l = peer_review(all_students, [], "Assignment One")
for i in l:
print(i)
print()
print("Reviewee,Reviewer,Assignment")
print()
print()
l = peer_review(all_students, [], "Assignment Two")
for i in l:
print(i)
print()
print("Reviewee,Reviewer,Assignment")
Я провел первоначальный тест, состоящий только из букв, чтобы напоминать студентов для отладки.
Вывод только для одного назначения был следующим:
A : ['B', 'C']
B : ['A', 'D']
C : ['A', 'D']
D : ['A', 'E']
E : ['A', 'D']
F : ['A', 'D']
G : ['A', 'D']
H : ['A', 'D']
I : ['A', 'D']
J : ['A', 'D']
K : ['A', 'D']
L : ['A', 'D']
M : ['A', 'D']
['A', 'B', 'Assignment One']
['A', 'C', 'Assignment One']
['B', 'A', 'Assignment One']
['B', 'D', 'Assignment One']
['C', 'A', 'Assignment One']
['C', 'D', 'Assignment One']
['D', 'A', 'Assignment One']
['D', 'E', 'Assignment One']
['E', 'A', 'Assignment One']
['E', 'D', 'Assignment One']
['F', 'A', 'Assignment One']
['F', 'D', 'Assignment One']
['G', 'A', 'Assignment One']
['G', 'D', 'Assignment One']
['H', 'A', 'Assignment One']
['H', 'D', 'Assignment One']
['I', 'A', 'Assignment One']
['I', 'D', 'Assignment One']
['J', 'A', 'Assignment One']
['J', 'D', 'Assignment One']
['K', 'A', 'Assignment One']
['K', 'D', 'Assignment One']
['L', 'A', 'Assignment One']
['L', 'D', 'Assignment One']
['M', 'A', 'Assignment One']
['M', 'D', 'Assignment One']
Как видите, он не соответствует указанным условиям. Любая помощь будет принята с благодарностью.