def gen_rand_strat(player, posn, sess): amounts = []; for i in range(1, posn): amt = random.randint(1, 100) amounts.append(amt) sum = 0 for i in range(posn, 5): no = random.randint(1, 20) sum += no amt = no amounts.append(amt) amounts.append(100-sum) Strategy.newStrategy(sess, posn, player, amounts)
def set_allocation(request): session = GlobalSettings.objects.get().current_session player = Profile.objects.get(user__username=request.user) amounts = [int(request.POST.get('val1')), int(request.POST.get('val2')), int(request.POST.get('val3')), int(request.POST.get('val4'))] posn = int(request.POST.get('pos')) sum = 0 for i in range(posn - 1, 4): sum += amounts[i] amounts.insert(posn-1,100 - sum) try: Strategy.newStrategy(session, posn, player, amounts) except Exception: return HttpResponse("0") return HttpResponse("")
def get_allocation(request): session = GlobalSettings.objects.get().current_session player = Profile.objects.get(user__username=request.user.username) alloc_dict = Strategy.getHisAlloc(session, player) return json_response(alloc_dict)