Exemplo n.º 1
0
def userpicks_test(request):
    start = timezone.now()-timedelta(days=7)
    end = timezone.now()
    if request.method == "POST":
        f = DateRangeForm(request.POST)

        if f.is_valid():
	    start_str = request.POST.get('start_date','')
	    start_str = start_str + " 00:00:01"
	    end_str = request.POST.get('end_date','')
	    end_str = end_str + " 23:59:59"
	    start = datetime.datetime.strptime(start_str, '%m/%d/%Y %H:%M:%S')
	    end = datetime.datetime.strptime(end_str, '%m/%d/%Y %H:%M:%S')

    else:
        f = DateRangeForm()
        args = {}
        args.update(csrf(request))
        args['form'] = f




    


    return render(request, 'bets/userpicks.html', {
        'form': f, 'start':start,'end':end
    })
Exemplo n.º 2
0
def user_picks(request, username):
    start = timezone.now()-timedelta(days=7)
    end = timezone.now()
    if request.method == "POST":
        f = DateRangeForm(request.POST)

        if f.is_valid():
            start_str = request.POST.get('start_date','')
            end_str = request.POST.get('end_date','')
    	    start_str = start_str + " 00:00:00"
    	    end_str = end_str + " 23:59:59"
            start = datetime.datetime.strptime(start_str, '%m/%d/%Y %H:%M:%S')
            end = datetime.datetime.strptime(end_str, '%m/%d/%Y %H:%M:%S')

    else:
        f = DateRangeForm()
        args = {}
        args.update(csrf(request))
        args['form'] = f

      
    sum_value = 0
    sum_live = 0
    sum_live_to_win=0
    if username == "All":
	if request.user.is_staff:
	    userlist = User.objects.all().filter(is_staff = False)  	
    	else:
	    username = request.user.username
 	    userlist =  User.objects.all().filter(username = username)
    else:
	userlist =  User.objects.all().filter(username = username)
           
    for user in userlist:
        profile = UserProfile.objects.all().filter(user = user)
	if profile:
            userprofile = profile[0]
	else:
	    userprofile = UserProfile(user = user)
	    userprofile.save()
        bets = Userbets.objects.all().filter(user = user, date__gt=start, date__lt=end).order_by('-date')[:100]
        total_live_wager = Decimal('0.00') 
        total_live_payout = Decimal('0.00')
        user_account = Decimal('0.00')
        wins = Decimal('0.00')
        losses  = Decimal('0.00')
        for bet in bets:
            if bet.winner_loser() == "winner":
                if bet.bet_type =="ML":
                    wins = Decimal(wins) +  Decimal(bet.payout_lines)
                else:
		    wins = Decimal(wins) + Decimal(bet.payout_simple)
            elif bet.winner_loser() == "loss":
	        losses = Decimal(losses) + Decimal(bet.wager)
            elif bet.winner_loser() == "push":
		pass
	    elif bet.winner_loser() == "INVALID":    
	        pass
	    else:
	        total_live_wager = Decimal(total_live_wager) + bet.betslip.wager
                if bet.bet_type =="ML":
                    total_live_payout = Decimal(total_live_payout) + Decimal(bet.payout_lines)
                else:
		    total_live_payout = Decimal(total_live_payout) + Decimal(bet.payout_simple)
        user_account = wins - losses
        userprofile.account_value = user_account
	userprofile.live_value = total_live_wager
        userprofile.live_to_win = total_live_payout
        userprofile.wins = wins
	userprofile.losses = losses        
        userprofile.save()
    accounts = []
    for user in userlist:
	accounts.append(UserProfile.objects.get(user = user))
    totalusers = User.objects.all()
    last20bets = Userbets.objects.all().filter(date__gt= start, date__lt=end).order_by('-date')[:100]
    last20bets = sorted(last20bets, key=lambda a: (a.matchup.date, a.date), reverse=True)
    for account in accounts:
        sum_value = sum_value + account.account_value
        sum_live = sum_live + account.live_value
	sum_live_to_win = sum_live_to_win + account.live_to_win
    return render(request, 'bets/userpicks.html', {'sum_live_to_win':sum_live_to_win,'sum_live':sum_live,'sum_value':sum_value,'last20bets':last20bets,'totalusers':totalusers,'accounts':accounts,'username':username, 'userlist': userlist,'bets' : bets, 'wins':wins, 'losses':losses,'user_account':user_account, 'total_live_wager':total_live_wager,'total_live_payout':total_live_payout, 'form': f, 'start':start,'end':end })