Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. def swiss(request):
  2. args = {}
  3. args.update(csrf(request))
  4. index = Bill.objects.all()
  5. nov_por = Bill.objects.filter().order_by('-bill_mat_ozh')
  6.  
  7. a = nov_por.count() // 2
  8. nov_por_1 = (nov_por[:a])
  9. nov_por_2 = (nov_por[a:])
  10.  
  11. res_1 = [(nov_por_1[n].bill_fio) for n in range(nov_por_1.count()) if nov_por_1[n] in nov_por_1]
  12. res_2 = [(nov_por_2[n].bill_fio) for n in range(nov_por_2.count()) if nov_por_2[n] in nov_por_2]
  13. players = zip_longest(res_1, res_2)
  14.  
  15. return render_to_response('swiss.html', {'players':players, 'index':index},
  16. context_instance=RequestContext(request))
  17.  
  18. def first_step(request):
  19. game_data = request.POST
  20. print(game_data)
  21. for key, value in game_data.items():
  22.  
  23. if key == 'csrfmiddlewaretoken':
  24. pass
  25.  
  26. elif value == 'no':
  27. split_player = key.split(', ')
  28.  
  29. for player in split_player:
  30. player_name = re.sub(r'[^ws-]+', r'', player).strip()
  31.  
  32. standoff = Bill.objects.get(bill_fio = player_name)
  33. standoff.swiss_bill_score = standoff.swiss_bill_score + 0.5
  34. standoff.save()
  35.  
  36. else:
  37. bill = Bill.objects.get(bill_fio = value)
  38. bill.swiss_bill_score = bill.swiss_bill_score + 1
  39. bill.save()
  40.  
  41. for key, value in game_data.items():
  42. if key == 'csrfmiddlewaretoken':
  43. pass
  44. else:
  45. spisok = []
  46. if 'None' in key:
  47. pass
  48. else:
  49. wr_split_player = key.split(', ')
  50. for rw_player in wr_split_player:
  51. rw_player_name = re.sub(r'[^ws-]+', r'', rw_player).strip()
  52.  
  53. rw_player_id = Bill.objects.get(bill_fio = rw_player_name).id
  54. spisok.append(rw_player_id)
  55. spisok.sort()
  56.  
  57.  
  58. length = len(spisok)
  59. if length == 2:
  60. rival_1 = Bill.objects.get(id = spisok[0])
  61. rival_2 = Bill.objects.get(id = spisok[1])
  62. rival_1.swiss_rivel = spisok[1]
  63. rival_2.swiss_rivel = spisok[0]
  64. rival_1.save()
  65. rival_2.save()
  66. else:
  67. pass
  68.  
  69.  
  70.  
  71. swiss_players = Bill.objects.all().order_by('-swiss_bill_score')
  72. new_game = swiss_players.count() // 2
  73. new_group_1 = (swiss_players[:new_game])
  74. new_group_2 = (swiss_players[new_game:])
  75.  
  76. id_new_group_1 = []
  77. id_new_group_2 = []
  78.  
  79. for n1 in new_group_1:
  80. igrok = Bill.objects.get(bill_fio = n1)
  81. id_igrok = igrok.id
  82. id_new_group_1.append(id_igrok)
  83.  
  84. for n2 in new_group_2:
  85. igrok = Bill.objects.get(bill_fio = n2)
  86. id_igrok = igrok.id
  87. id_new_group_2.append(id_igrok)
  88.  
  89.  
  90. result_finish = []
  91.  
  92. for single_id in id_new_group_1:
  93. result = [single_id, random.choice(id_new_group_2)]
  94. print(request)
  95.  
  96. if Bill.objects.get(id=result[0]).swiss_rivel is not None:
  97. while str(result[1]) in Bill.objects.get(id=result[0]).swiss_rivel:
  98. result = [single_id, random.choice(id_new_group_2)]
  99. break
  100. else:
  101. result = [single_id, random.choice(id_new_group_2)]
  102.  
  103. id_new_group_2.remove(result[1])
  104. result_2 = [Bill.objects.get(id=result[0]), Bill.objects.get(id=result[1])]
  105.  
  106. result_finish.append(result_2)
  107.  
  108. if id_new_group_2 != None:
  109. end_player = [None, Bill.objects.get(id=id_new_group_2[0])]
  110. result_finish.append(end_player)
  111.  
  112.  
  113.  
  114. return render_to_response('swiss_result.html', {'swiss_players':swiss_players, 'result_finish':result_finish},
  115. context_instance=RequestContext(request))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement