瑞士轮小工具

UI

import easygui as ui
from Learn.ruishilun import PlayCenter


class Brain:

    def __init__(self):
        ui.msgbox("请选择参赛选手文件,文件包含三个字段:id,name,score")
        # FileName = ui.fileopenbox("选手文件")
        FileName = r'D:\work\2023\month11\date20\epoch.xlsx'
        self.PLAY = PlayCenter(FileName)
        self.currentScore = self.PLAY.printScore()
        self.currentMsg = self.currentScore
        self.MainLoop()
        # MainWindows =ui.

    def MainLoop(self):
        while True:
            reply = ui.buttonbox(msg=self.currentMsg, title="main", choices=["开始一轮比赛", "结束对局"])
            if reply == "开始一轮比赛":
                self.StartOneRound()
                self.WriteAmidithion()
            elif reply == "结束对局":
                self.endCurrentRound()
            elif not reply:
                break

    def StartOneRound(self):
        self.currentMsg = self.PLAY.oneRound()
        self.currentBattleList = self.currentMsg.split('\n')
        if(self.currentBattleList[-1] == ''): self.currentBattleList.remove('')

    def endCurrentRound(self):
        reply = self.PLAY.save()
        ui.msgbox(reply)

    def WriteAmidithion(self):

        while True:
            # inputText = ui.enterbox(self.currentMsg,"填写对战记录")
            inputText = ui.multenterbox("请输入战绩", "战绩登记", self.currentBattleList)
            if (inputText):
                self.PLAY.addScore(inputText)
                self.currentMsg = self.PLAY.printScore()
                break

    def ShowCurrentRank(self):
        ui.msgbox(self.PLAY.printScore(), title="当前战绩", ok_button="确定")


if __name__ == '__main__':
    #ui.egdemo()
    brain = Brain()
    pass

瑞士轮广场

import random
import time

import pandas as pd
from enum import Enum


#乱序工具:random.shuffle(my_list)

# 积分原则
# 胜利3分 双败0分

#比赛场地、积分记录与赛事记录
class PlayCenter:
    def __init__(self,FileName):
        #比赛开始
        self.FileName = FileName
        self.df = pd.read_excel(FileName, engine='openpyxl',sheet_name=0)
        self.Init()
        self.SortDf()
        self.printScore()
        print("初始化完成!可开始比赛!")


    def Init(self):
        self.df["score"] = self.df["score"].astype("int")

    def SortDf(self):
        #排序并重新编号
        self.df.sort_values(by='score', ascending=False, inplace=True,kind='stable')
        self.df.reset_index(inplace=True)
        self.df.drop('index',axis=1,inplace=True)

    def printScore(self):
        text = ''
        rank = 1
        for index,line in self.df.iterrows():
            #print("名次:{0}--{2}--积分:{3}".format(rank,line["id"],line["name"],line["score"]))
            text += "名次:{0}--{2}--积分:{3}".format(rank,line["id"],line["name"],line["score"]) + "\n"
            rank += 1
        return text

    def oneRound(self):
        # 输出对战表
        sublists = []
        for i in range(0, len(self.df), 2):
            sublist = list(self.df.index)[i:i + 2]
            sublists.append(sublist)
        text = ''
        for epoch in sublists:
            if(len(epoch)>1):
                text += "ID:{0} 姓名:{1} vs  ID:{2} 姓名:{3}".format(self.df.iloc[epoch[0]]["id"], self.df.iloc[epoch[0]]["name"],
                                                      self.df.iloc[epoch[1]]["id"],
                                                      self.df.iloc[epoch[1]]["name"]) + '\n'
                # print("{0}:{1}--VS--{2}:{3}".format(self.df.iloc[epoch[0]]["id"], self.df.iloc[epoch[0]]["name"],
                #                                     self.df.iloc[epoch[1]]["id"], self.df.iloc[epoch[1]]["name"]))
            else:
                text += "ID:{0} 姓名:{1} vs 轮空".format(self.df.iloc[epoch[0]]["id"], self.df.iloc[epoch[0]]["name"]) + '\n'
                #print("轮空--{}:{}".format(self.df.iloc[epoch[0]]["id"], self.df.iloc[epoch[0]]["name"]))
        return text

    def addScore(self,WinIDList):
        '''

        :return:
        '''

        WinIDList = list(set(WinIDList))
        if(WinIDList.__contains__('')): WinIDList.remove('')
        WinIDList = [int(x) for x in WinIDList]

        for index,line in self.df.iterrows():
            if(line["id"] in WinIDList):
                line["score"] += 3
                self.df.loc[index] = line
        self.SortDf()

    def save(self):
        '''
        保存表格
        :return:
        '''
        curTime = time.strftime("%m月%d日 %H时%M分%S秒", time.localtime())
        with pd.ExcelWriter(self.FileName,mode='a',engine='openpyxl') as writer:
            self.df.to_excel(writer, sheet_name="{}".format(curTime),
                             index=False)
            writer.save()
        #print("输出完成:{}".format(self.FileName))
        return "输出完成,页名:{}".format(curTime)


if __name__ == '__main__':

    FileName = r'D:\work\2023\month11\date20\epoch.xlsx'

    Play = PlayCenter(FileName)

    #Swiss(userID)

    pass

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值