示例#1
0
def user_pg(request):
    name = request.user.username
    user = Users.objects.get(user_id = name)
    display = user.user_name
    owner_key = user.token
    owner_secret = user.token_secret
    auth = fitbit.Fitbit(FITAPP_CONSUMER_KEY, FITAPP_CONSUMER_SECRET, resource_owner_key = owner_key, resource_owner_secret = owner_secret)
    profile = auth.user_profile_get(name)
    groupname = user.group

    agiexp = user.user_agility
    strexp = user.user_strength
    willexp = user.user_willpower

    strlevel, agilevel,willlevel = Exp.calcLvl(strexp, agiexp, willexp)
    constitution = user.user_constitution
    avatar = profile.get('user').get('avatar')
    exist = user.group


    try:
        creator = Challenge.objects.get(challenger = name)

    except Challenge.DoesNotExist:
        creator = None
        challenge = Challenge.objects.all()
        for i in challenge:
            if i.challengee == name:
                creator = i
                break

    #print(creator)
   # print(exist)



    if exist != 'None' and creator != None:
        groupname = user.group
        return render_to_response('userpage.html', {"name" : display,
                                                 "avatar" : avatar,
                                                 "groupname" : groupname,
                                                 "challenge" : "You are currently in a challenge! Visit the challenge page to see the details!",
                                                 "agilevel" : agilevel,
                                                 "strlevel" : strlevel,
                                                 "willlevel" : willlevel,
                                                 "constitution" : constitution})
    elif exist == 'None' and creator != None:
        groupname = user.group
        return render_to_response('userpage.html', {"name" : display,
                                                 "avatar" : avatar,
                                                 "groupname" : groupname,
                                                 "challenge" : "You are currently in a challenge! Visit the challenge page to see the details!",
                                                 "agilevel" : agilevel,
                                                 "strlevel" : strlevel,
                                                 "willlevel" : willlevel,
                                                 "constitution" : constitution})
    elif exist != 'None' and creator == None:
        groupname = user.group
        return render_to_response('userpage.html', {"name" : display,
                                                 "avatar" : avatar,
                                                 "groupname" : groupname,
                                                 "challenge" : "You are not currently challenging anybody!  Fix this on the challenge page!",
                                                 "agilevel" : agilevel,
                                                 "strlevel" : strlevel,
                                                 "willlevel" : willlevel,
                                                 "constitution" : constitution})
    else:

        return render_to_response('userpage.html', {"name" : display,
                                                 "avatar" : avatar,
                                                 "groupname" : "You are not currently in a group!",
                                                "challenge" : "You are currently not challenging anyone.",
                                                 "agilevel" : agilevel,
                                                 "strlevel" : strlevel,
                                                 "willlevel" : willlevel,
                                                 "constitution" : constitution})
示例#2
0
def calculateExp(request):
    #day_of_year = datetime.now().timetuple().tm_yday


    user = Users.objects.get(user_id = request.user.username)

    #if user.last_login == day_of_year:

    owner_key = user.token
    owner_secret = user.token_secret
    now = '2015-12-08'
    print(now)
    auth = fitbit.Fitbit(FITAPP_CONSUMER_KEY, FITAPP_CONSUMER_SECRET, resource_owner_key = owner_key, resource_owner_secret = owner_secret)
    activity_stats = auth._COLLECTION_RESOURCE('activities', now, request.user.username)

    print(activity_stats)

    distgoal = activity_stats.get('goals').get('distance')
    floorgoal = activity_stats.get('goals').get('floors')
    stepgoal = activity_stats.get('goals').get('steps')



    calories = activity_stats.get('summary').get('activityCalories')
    print(calories)
    dist = activity_stats.get('summary').get('distances')[0]['distance']
    print(dist)
    steps = activity_stats.get('summary').get('steps')
    print(steps)
    floors = activity_stats.get('summary').get('floors')
    print(floors)

    fairlyactive =  activity_stats.get('summary').get('fairlyActiveMinutes')
    veryactive =  activity_stats.get('summary').get('veryActiveMinutes')

    activity_sum = fairlyactive + veryactive
    strxp, agixp, willxp, con_mult = Exp.calcExp(dist, distgoal, calories, floors, floorgoal, steps, stepgoal, activity_sum, 1.0,1)

    expTotal = strxp + agixp + willxp


    curr_str = user.user_strength
    curr_agi = user.user_agility
    curr_will = user.user_willpower


    new_str, new_agil, new_will = Exp.add_exp(curr_str, curr_agi, curr_will,strxp, agixp, willxp)


    user.user_strength = new_str
    user.user_agility = new_agil
    user.user_willpower = new_will
    user.user_constitution = con_mult
    user.save()

    str_level, agil_level, will_level = Exp.calcLvl(new_str, new_agil, new_will)

    try:
        creator = Challenge.objects.get(challenger = request.user.username)
    except Challenge.DoesNotExist:
        creator = None
        gee = None
        challenge = Challenge.objects.all()
        for i in challenge:
            if i.challengee == request.user.username:
                gee = i
                break

    if creator != None:
        string = "You are currently in a challenge! Visit the challenge page to see the details!"
        creator.gerExp += expTotal
        creator.save()

    elif creator == None and gee != None:
        string = "You are currently in a challenge! Visit the challenge page to see the details!"
        gee.geeExp += expTotal
        gee.save()

    if creator == None and gee == None:
        string = "You are currently not in a challenge!"


    profile = auth.user_profile_get(request.user.username)
    username = profile.get('user').get('displayName')


    groupname = user.group
    if groupname == 'None':
        string2 = "You are not currently in a group!  Go join one!"
    else:
        string2 = "You are currently in a group!  Go check it out at the group page!"

    avatar = profile.get('user').get('avatar')


    return render_to_response('userpage.html', {"name" : username,
                                                 "avatar" : avatar,
                                                 "groupname" : string2,
                                                "challenge" : string,
                                                 "agilevel" : agil_level,
                                                 "strlevel" : str_level,
                                                 "willlevel" : will_level,
                                                 "constitution" : con_mult})