Exemplo n.º 1
0
def guest():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    numbers = random.randint(100, 99999999)
    username = "******" + str(numbers)
    taken = player.query.filter_by(username=username).first()
    if taken:
        while taken:
            numbers = random.randint(100, 99999999)
            username = "******" + numbers
            taken = player.query.filter_by(username=username).first()
    user = player(username=username,
                  registered=False,
                  totalSongsPlayed=0,
                  totalCorrectGuesses=0,
                  monthlySongsPlayed=0,
                  monthlyCorrectGuesses=0)
    db.session.add(user)
    db.session.commit()
    flash('You have been logged in as a guest')
    curr_user = player.query.filter_by(username=username).first()
    login_user(curr_user, remember=False)
    next_page = request.args.get('next')
    if not next_page or url_parse(next_page).netloc != '':
        next_page = url_for('home')
    return redirect(next_page)
Exemplo n.º 2
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = player(username=form.username.data,
                      email=form.email.data,
                      registered=True,
                      totalSongsPlayed=0,
                      totalCorrectGuesses=0,
                      monthlySongsPlayed=0,
                      monthlyCorrectGuesses=0,
                      roomID=0,
                      pointsInRoom=0)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('login'))
    return render_template('register.html', form=form, title='Register')
Exemplo n.º 3
0
    def getinfo(self, playerid):
        plist = []
        plist.append(playerid)
        req1 = requests.get(
            f'https://api.opendota.com/api/players/{playerid}/wl')
        json1 = req1.json()
        for key, value in json1.items():
            plist.append(value)
        plist.append(int(plist[1] + plist[2]))
        req2 = requests.get(
            f"https://api.opendota.com/api/players/{playerid}/totals")
        json2 = req2.json()

        #gpm calc
        for i in json2:
            if i['field'] == 'gold_per_min':
                mydict = i
                break

        l1 = []
        for key, values in mydict.items():
            l1.append(values)
        gpm = l1[2] / l1[1]
        plist.append(int(gpm))

        #xpm calc
        for i in json2:
            if i['field'] == 'xp_per_min':
                mydict = i
                break
        l1 = []
        for key, values in mydict.items():
            l1.append(values)

        xpm = l1[2] / l1[1]
        plist.append(int(xpm))  #[id,win,loss,totalmatches,gpm,xpm]

        #kda calc
        for i in json2:
            if i['field'] == 'kda':
                mydict = i
                break

        l1 = []
        for key, values in mydict.items():
            l1.append(values)

        kda = l1[2] / l1[1]
        plist.append(kda)  #[id,win,loss,totalmatches,gpm,xpm,kda]

        req3 = requests.get(f"https://api.opendota.com/api/players/{playerid}")
        json3 = req3.json()
        for key, values in json3.items():
            if key == "solo_competitive_rank":
                plist.append(
                    values)  #[id,win,loss,totalmatches,gpm,xpm,kda,mmr]

        player_user = player(pid=plist[0],
                             no_wins=plist[1],
                             no_losses=plist[2],
                             no_match=plist[3],
                             avg_gpm=plist[4],
                             avg_xpm=plist[5],
                             avg_kda=plist[6],
                             mmr=plist[7])
        db.session.add(player_user)
        db.session.commit()

        ####!!!!!!!!!!!player Performance table !!!!!!!!!!!!!#

        re1 = requests.get(
            f'https://api.opendota.com/api/players/{playerid}/rankings')
        j1 = re1.json()
        print(j1)
        id = [d['hero_id'] for d in j1]
        perc = [d['percent_rank'] for d in j1]
        size = len(id)
        print(size)

        playerdict = dict(zip(id, perc))
        print(playerdict)
        odpd = collections.OrderedDict(sorted(playerdict.items()))
        print(odpd)

        perc1 = list(odpd.values())
        print(perc1)
        id1 = list(odpd.keys())
        print(id1)
        print(len(id1))
        k = 0
        result = 0
        score = 0
        desc = []
        while k < size:
            result = perc1[k]
            print(result)
            if result <= 0.2:
                desc.append("Herald")

            elif result > 0.2 and result <= 0.3:
                desc.append("Guardian")

            elif result > 0.3 and result <= 0.4:
                desc.append("Crusader")

            elif result > 0.4 and result <= 0.5:
                desc.append("Archon")

            elif result > 0.5 and result <= 0.7:
                desc.append("Legend")

            elif result > 0.7 and result <= 0.8:
                desc.append("Ancient")

            elif result > 0.8 and result <= 0.9:
                desc.append("Divine")

            else:
                desc.append("Immortal")

            k = k + 1

        print(desc)
        names = []
        k = 0
        while k < size:
            nam = hero.query.filter_by(hid=id1[k]).all()
            for n in nam:
                nama = n.hero_name
            names.append(nama)
            k = k + 1

        print(names)

        k = 0
        while k < size:
            user = player_hero(hero_id=id1[k],
                               score=perc1[k],
                               player_id=playerid,
                               Performance=desc[k],
                               heroname=names[k])
            db.session.add(user)
            db.session.commit()
            k = k + 1
Exemplo n.º 4
0
def reset_db():
    flash(
        "Resetting database: deleting old data and repopulating with dummy data"
    )
    # clear all data from all tables
    meta = db.metadata
    for table in reversed(meta.sorted_tables):
        print('Clear table {}'.format(table))
        db.session.execute(table.delete())
    db.session.commit()

    songs = [
        # Joji
        song(id=1,
             artist='Joji',
             title="SLOW DANCING IN THE DARK",
             link="https://www.youtube.com/watch?v=K3Qzzggn--s",
             startTime=22),
        song(id=2,
             artist='Joji',
             title="TEST DRIVE",
             link="https://www.youtube.com/watch?v=PEBS2jbZce4",
             startTime=23),
        song(id=4,
             artist='Joji',
             title="ATTENTION",
             link="https://www.youtube.com/watch?v=ulMHhPHYCi0",
             startTime=31),
        song(id=5,
             artist='Joji',
             title="WANTED U",
             link="https://www.youtube.com/watch?v=z9gVoelEjws",
             startTime=15),
        song(id=6,
             artist='Joji',
             title="CAN'T GET OVER YOU",
             link="https://www.youtube.com/watch?v=zbxAB7rTpDc",
             startTime=70),
        song(id=7,
             artist='Joji',
             title="YEAH RIGHT",
             link="https://www.youtube.com/watch?v=tG7wLK4aAOE",
             startTime=21),
        song(id=8,
             artist='Joji',
             title="NO FUN",
             link="https://www.youtube.com/watch?v=8Vlej7QUGGE",
             startTime=19),
        song(id=9,
             artist='Joji',
             title="COME THRU",
             link="https://www.youtube.com/watch?v=7QrEkeXZJLg",
             startTime=50),
        song(id=10,
             artist='Joji',
             title="will he",
             link="https://www.youtube.com/watch?v=R2zXxQHBpd8",
             startTime=37),

        # Rex Orange County
        song(id=11,
             artist='Rex Orange County',
             title="Sunflower",
             link="https://www.youtube.com/watch?v=Z9e7K6Hx_rY",
             startTime=48),
        song(id=12,
             artist='Rex Orange County',
             title="Loving is Easy",
             link="https://www.youtube.com/watch?v=39IU7ADaXmQ",
             startTime=65),
        song(id=13,
             artist='Rex Orange County',
             title="BEST FRIEND",
             link="https://www.youtube.com/watch?v=OqBuXQLR4Y8",
             startTime=30),
        song(id=14,
             artist='Rex Orange County',
             title="Corduroy Dreams",
             link="https://www.youtube.com/watch?v=oSl7I8ue400",
             startTime=19),
        song(id=15,
             artist='Rex Orange County',
             title="Untitled",
             link="https://www.youtube.com/watch?v=Z4lMPWXhAr8",
             startTime=1),

        # The Gunpoets
        song(id=16,
             artist='The Gunpoets',
             title="Make You Happy",
             link="https://www.youtube.com/watch?v=XigvD9PSknk",
             startTime=14),
        song(id=17,
             artist='The Gunpoets',
             title="We Sing, We Dance",
             link="https://www.youtube.com/watch?v=1Q5HMoh6CB0",
             startTime=31),
        song(id=18,
             artist='The Gunpoets',
             title="8 Track Mind",
             link="https://www.youtube.com/watch?v=32iLMq01qi8",
             startTime=8),
        song(id=19,
             artist='The Gunpoets',
             title="In the Dark",
             link="https://www.youtube.com/watch?v=OeU2qocZ9Lc",
             startTime=14),
        song(id=20,
             artist='The Gunpoets',
             title="Action, Cameras, Lights",
             link="https://www.youtube.com/watch?v=oYSgFOqvZ9g",
             startTime=8),
        song(id=21,
             artist='The Gunpoets',
             title="Beautiful People",
             link="https://www.youtube.com/watch?v=eBAO9cANYe0",
             startTime=22),
    ]

    players = [
        player(id=1,
               username='******',
               email='*****@*****.**',
               registered=False,
               totalSongsPlayed=0,
               totalCorrectGuesses=0,
               monthlySongsPlayed=0,
               monthlyCorrectGuesses=0)
    ]

    for person in players:
        db.session.add(person)

    for music in songs:
        db.session.add(music)
    db.session.commit()
    return render_template('index.html', title='Home')