Exemple #1
0
def codeListInProblem(problemIndex):
    try:
        codeListSubquery = select_recent_code(
            problemIndex=problemIndex).subquery()
        codeListSubquery = dao.query(User.nickName, codeListSubquery).\
                                join(codeListSubquery,
                                     codeListSubquery.c.userIndex == User.userIndex).subquery()

        temp = select_code(problemIndex=problemIndex).subquery()
        codeListSubquery = dao.query(codeListSubquery, temp.c.isOpen).\
                                join(temp,
                                     temp.c.codeIndex == codeListSubquery.c.leastIndex).subquery()

        scoreListSuquery = select_userInformationInProblem(
            problemIndex=problemIndex).subquery()

        codeList = dao.query(scoreListSuquery.c.score, codeListSubquery).\
                        join(codeListSubquery,
                             codeListSubquery.c.userIndex == scoreListSuquery.c.userIndex).\
                        all()

        problemName = select_problem(
            problemIndex=problemIndex).first().problemName

        return render_template('codeList_problem.html',
                               codeList=codeList,
                               problemIndex=problemIndex,
                               problemName=problemName)

    except Exception as e:
        print e

        dao.rollback()

        flash('다시 시도해주세요.')
Exemple #2
0
def allList():
    try:
        problem = select_problem().subquery()
        totalUser = select_user().subquery()

        replayData = select_dataOfMatch().subquery()
        joinedquery = dao.query(totalUser.c.nickName.label('challengerNickName'), totalUser.c.userId.label('challengerId'),
                                replayData.c.dataOfMatchIndex, replayData.c.problemIndex,
                                replayData.c.challengerIndex, replayData.c.championIndex, replayData.c.result). \
            join(replayData,
                             replayData.c.challengerIndex == totalUser.c.userIndex). \
            subquery()

        userReplayData = dao.query(totalUser.c.nickName.label('championNickName'), totalUser.c.userId.label('championId'),
                                   joinedquery). \
             join(joinedquery,
                                 joinedquery.c.championIndex == totalUser.c.userIndex). \
             subquery()

        userReplayData = dao.query(problem.c.problemName, userReplayData). \
             join(userReplayData,
                                 userReplayData.c.problemIndex == problem.c.problemIndex).all()

        return render_template('replaylist.html',
                               userReplayData=userReplayData[::-1])

    except AttributeError as e:
        print e

        return render_template('replaylist.html', userReplayData=[])

    except Exception as e:
        flash('다시 시도해주세요.')
        return redirect(url_for('.main'))
Exemple #3
0
def matchRank(problemIndex):
    try:
        userListSubquery = select_code(
            problemIndex=problemIndex,
            isCompile=True).group_by('userIndex').subquery()
        userProblemInfoSubquery = select_userInformationInProblem(
            problemIndex=problemIndex).subquery()

        topUserListSubquery = dao.query(userListSubquery.c.codeIndex, userListSubquery.c.userIndex,
                                        userListSubquery.c.problemIndex, userProblemInfoSubquery.c.score).\
                                join(userProblemInfoSubquery,
                                     userProblemInfoSubquery.c.userIndex == userListSubquery.c.userIndex).\
                                order_by(userProblemInfoSubquery.c.score.desc()).\
                                subquery()

        topUserList = dao.query(User.nickName, topUserListSubquery).\
                        join(topUserListSubquery,
                             topUserListSubquery.c.userIndex == User.userIndex).all()

        problem = select_problem(problemIndex=problemIndex).first()

        topUserList = topUserList if len(
            topUserList) < 10 else topUserList[:10]

        return render_template('userRankInProblem.html',
                               topUserList=topUserList,
                               problem=problem)

    except Exception as e:
        print e

        flash('다시 시도해주세요.')
        return redirect(url_for('.main'))
Exemple #4
0
def manageProblem():
    try:
        problemList = select_problem()
        return render_template('manageProblem.html', problemList=problemList)

    except Exception as e:
        print e
Exemple #5
0
def problemList():
    try:
        problemList = select_problem().all()

        return render_template('list.html', problemList=problemList)

    except Exception as e:
        print e

        flash('다시 시도해주세요.')
        return redirect(url_for('.main'))
Exemple #6
0
def myCodeInProblem(problemIndex):
    try:
        codeList = select_code(userIndex=session['userIndex'],
                               problemIndex=problemIndex).all()
        problemName = select_problem(
            problemIndex=problemIndex).first().problemName

        return render_template('myCodeList_problem.html',
                               codeList=codeList,
                               problemIndex=problemIndex,
                               problemName=problemName)

    except Exception as e:
        print e
        dao.rollback()

        flash('다시 시도해주세요.')
Exemple #7
0
def viewCode(codeIndex):
    tempCode = select_code(codeIndex=codeIndex).subquery()
    temp = select_language().subquery()

    code = dao.query(temp.c.language, tempCode).\
                join(tempCode,
                     tempCode.c.languageIndex == temp.c.languageIndex).first()

    userInfo = select_userInformationInProblem(
        userIndex=session['userIndex']).first()

    problem = select_problem(problemIndex=code.problemIndex).first()
    user = select_user(userIndex=session['userIndex']).first()

    return render_template('viewCode.html',
                           userInfo=userInfo,
                           code=code,
                           problem=problem,
                           user=user)
Exemple #8
0
def matchProblemList():
    try:
        userProblemSubquery = select_code(
            userIndex=session['userIndex'],
            isCompile=True).group_by('problemIndex').subquery()

        userListSubquery = select_code(isCompile=True).subquery()
        userListSubquery = dao.query(userListSubquery.c.codeIndex, userListSubquery.c.userIndex, userProblemSubquery.c.problemIndex).\
                                    join(userProblemSubquery,
                                         userProblemSubquery.c.problemIndex == userListSubquery.c.problemIndex).\
                                    group_by(userListSubquery.c.userIndex, userProblemSubquery.c.problemIndex).subquery()
        userCountSubquery = dao.query(userListSubquery.c.problemIndex, func.count(userListSubquery.c.problemIndex).label('count')).\
                                group_by(userListSubquery.c.problemIndex).subquery()

        problems = select_problem().subquery()
        userProblemListSubquery = dao.query(problems.c.problemName, userProblemSubquery.c.codeIndex,
                                            userProblemSubquery.c.problemIndex).\
                                    join(userProblemSubquery,
                                         userProblemSubquery.c.problemIndex == problems.c.problemIndex).subquery()

        userProblemList = dao.query(userCountSubquery.c.count, userProblemListSubquery).\
                            join(userProblemListSubquery,
                                 userProblemListSubquery.c.problemIndex == userCountSubquery.c.problemIndex).all()

        lastMatchTime = select_user(
            userIndex=session['userIndex']).first().lastMatchDate

        if lastMatchTime is None:
            remainingTime = 0

        else:
            remainingTime = ((lastMatchTime + timedelta(minutes=1)) -
                             datetime.now()).total_seconds()

        return render_template('matchProblemList.html',
                               userProblemList=userProblemList,
                               remainingTime=remainingTime)

    except Exception as e:
        print e

        flash('다시 시도해주세요.')
        return redirect(url_for('.main'))
Exemple #9
0
def main():
    try:
        problems = select_problem().subquery()
        topProblems = get_topProblem().subquery()

        topProblems = dao.query(problems, topProblems).\
                            join(topProblems,
                                 topProblems.c.problemIndex == problems.c.problemIndex).\
                            order_by(topProblems.c.submitCount.desc()).all()
    except AttributeError as e:
        print e
        topProblems = []

    try:
        users = select_user().subquery()
        topUsers = get_total_score_each_users().subquery()

        topUsers = dao.query(users, topUsers).\
                        join(topUsers,
                             topUsers.c.userIndex == users.c.userIndex).\
                        order_by(topUsers.c.totalScore.desc()).all()
    except AttributeError as e:
        print e
        topUsers = []

    try:
        user = select_user(userIndex=session['userIndex'])
        return render_template(
            'main.html',
            topUsers=topUsers[:3] if len(topUsers) > 3 else topUsers,
            topProblems=topProblems[:3]
            if len(topProblems) > 3 else topProblems,
            user=user)

    except Exception as e:
        return render_template(
            'main.html',
            topUsers=topUsers[:3] if len(topUsers) > 3 else topUsers,
            topProblems=topProblems[:3]
            if len(topProblems) > 3 else topProblems,
            user=None)
Exemple #10
0
def problem(problemIndex):
    thema = [
        'chrome', 'clouds', 'eclipse', 'github', 'monokai', 'textmate',
        'tomorrow'
    ]

    try:
        langQuery = select_language()
        userIndex = session['userIndex']
        problemData = select_problem(problemIndex=problemIndex).first()

        userInfoSub = select_userSetting(userIndex=userIndex).subquery()
        temp = langQuery.subquery()

        userInfo = dao.query(temp.c.language, userInfoSub).\
                        join(userInfoSub, userInfoSub.c.languageIndex == temp.c.languageIndex).first()

        language = langQuery.all()

        if userInfo is None:
            try:
                dao.add(insert_userSetting(userIndex=userIndex))
                dao.commit()

                redirect(url_for('.problem'))

            except Exception as e:
                redirect(url_for('.problem'))

        return render_template('problem.html',
                               problemData=problemData,
                               userInfo=userInfo,
                               thema=thema,
                               language=language)

    except Exception as e:
        print e

        flash('다시 시도해주세요.')
        return redirect(url_for('.main'))
Exemple #11
0
def playResult(dataOfMatchIndex):
    try:
        replayData = select_dataOfMatch(
            dataOfMatchIndex=dataOfMatchIndex).first()
        problemData = select_problem(
            problemIndex=replayData.problemIndex).first()

        positionData = ['     '] + replayData.positionData.strip().split('\n')

        boardData = []
        tempBoardData = replayData.boardData.strip().split('\n')

        positionSize = problemData.boardSize + problemData.placementPoint

        challenger = select_user(userIndex=replayData.challengerIndex).first()
        champion = select_user(userIndex=replayData.championIndex).first()

        for i in range(0, len(tempBoardData), positionSize):
            temp = []
            for j in range(i, i + positionSize):
                temp.append(
                    [int(k) for k in tempBoardData[j].strip(' ').split(' ')])

            boardData.append(temp)

        return render_template('replay.html',
                               positionData=positionData,
                               boardData=boardData,
                               challenger=challenger,
                               champion=champion,
                               positionSize=positionSize)

    except Exception as e:
        print e

        flash('다시 시도해주세요.')
        return redirect(url_for('.main'))
Exemple #12
0
def matchUserList(problemIndex):
    try:
        userIndex = session['userIndex']
        userScore = select_userInformationInProblem(
            userIndex=userIndex, problemIndex=problemIndex).first().score

        userListSubquery = select_code(
            problemIndex=problemIndex,
            isCompile=True).group_by('userIndex').subquery()
        userProblemInfoSubquery = select_userInformationInProblem(
            problemIndex=problemIndex).subquery()
        userListSubquery = dao.query(userListSubquery.c.codeIndex, userListSubquery.c.userIndex,
                                     userListSubquery.c.problemIndex, userProblemInfoSubquery.c.score).\
                                join(userProblemInfoSubquery,
                                     userProblemInfoSubquery.c.userIndex == userListSubquery.c.userIndex).subquery()

        for i in range(50):
            userList_upper_subquery = dao.query(userListSubquery).\
                                        filter(and_(userListSubquery.c.score < userScore + i*20,
                                                    userListSubquery.c.score > userScore,
                                                    userListSubquery.c.userIndex != userIndex)).subquery()

            userList_upper = dao.query(User.nickName, userList_upper_subquery). \
                                join(userList_upper_subquery,
                                     userList_upper_subquery.c.userIndex == User.userIndex). \
                                all()

            if len(userList_upper) == 3:
                break

            elif len(userList_upper) > 3:
                while len(userList_upper) > 3:
                    userList_upper.remove(random.choice(list(userList_upper)))

                break

        for i in range(50):
            userList_lower_subquery = dao.query(userListSubquery).\
                                        filter(and_(userListSubquery.c.score > userScore - i*20,
                                                    userListSubquery.c.score <= userScore,
                                                    userListSubquery.c.userIndex != userIndex)).subquery()

            userList_lower = dao.query(User.nickName, userList_lower_subquery).\
                                join(userList_lower_subquery,
                                     userList_lower_subquery.c.userIndex == User.userIndex).\
                                all()

            if len(userList_lower) == 2:
                break

            elif len(userList_lower) > 2:
                while len(userList_lower) > 2:
                    userList_lower.remove(random.choice(list(userList_lower)))

                break

        problem = select_problem(problemIndex=problemIndex).first()

        lastMatchTime = select_user(userIndex=userIndex).first().lastMatchDate

        if lastMatchTime is None:
            remainingTime = 0

        else:
            remainingTime = ((lastMatchTime + timedelta(minutes=1)) -
                             datetime.now()).total_seconds()

        return render_template('matchUserList.html',
                               userList_upper=userList_upper,
                               userList_lower=userList_lower,
                               problem=problem,
                               score=userScore,
                               remainingTime=remainingTime)

    except Exception as e:
        print e

        flash('다시 시도해주세요.')
        return redirect(url_for('.main'))
Exemple #13
0
def registerProblem():
    import json

    thisPath, _ = os.path.split(os.path.abspath(__file__))
    _thisPath, _ = os.path.split(thisPath)
    thisPath, _ = os.path.split(_thisPath)
    savePath = os.path.join(thisPath, 'problemData')

    f = request.files.getlist('zipFile')[0]
    f.save(os.path.join(savePath, f.filename))

    fileName = f.filename.split('.')[0]
    tempDir = os.path.join(savePath, fileName)
    tempZip = zipfile.ZipFile(os.path.join(savePath, f.filename))
    tempZip.extractall(tempDir)
    tempZip.close()

    fileList = os.listdir(tempDir)

    if (fileName + '.json' in fileList) and (fileName + '.pdf' in fileList):
        try:
            with open(os.path.join(tempDir, fileName + '.json')) as fp:
                data = json.load(fp)
                tempGameBoard = ''
                tempDataBoard = ''
                tempPlacementOption = ''

                for i in range(len(data['placementOption'])):
                    tempPlacementOption = tempPlacementOption + (' '.join(
                        str(j) for j in data['placementOption'][i])) + '\n'

                for i in range(len(data['gameBoard'])):
                    tempGameBoard += ' '.join(
                        str(j) for j in data['gameBoard'][i]) + '\n'
                    tempDataBoard += ' '.join(
                        str(j) for j in data['dataBoard'][i]) + '\n'

                dao.add(
                    insert_problem(problemName=fileName,
                                   placementRule=str(data['placementRule']),
                                   boardSize=data['boardSize'],
                                   placementPoint=data['placementPoint'],
                                   placementOption=tempPlacementOption,
                                   existRule=' '.join(
                                       str(i) for i in data['existRule']),
                                   existOption=' '.join(
                                       str(i) for i in data['existOption']),
                                   actionRule=str(data['actionRule']),
                                   actionOption=' '.join(
                                       str(i) for i in data['actionOption']),
                                   endingRule=str(data['endingRule']),
                                   endingOption=' '.join(
                                       str(i) for i in data['endingOption']),
                                   gameBoard=tempGameBoard,
                                   dataBoard=tempDataBoard))

                shutil.move(tempDir,
                            os.path.join(_thisPath, 'static', 'problems'))

                dao.commit()

            problemIndex = select_problem(
                problemName=fileName).first().problemIndex

            addProblem.delay(problemIndex, json.dumps(data))

            message = '문제가 등록 됐습니다.'

        except Exception as e:
            print e

            message = '다시 시도하세요.'

    else:
        message = '파일을 다시 확인해 주세요.'

    os.remove(os.path.join(savePath, f.filename))

    flash(message)
    return redirect(url_for('.admin'))