Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何组织多人游戏赢家/输家报告的MySQL表_Python_Mysql - Fatal编程技术网

Python 如何组织多人游戏赢家/输家报告的MySQL表

Python 如何组织多人游戏赢家/输家报告的MySQL表,python,mysql,Python,Mysql,我使用Python解析来自游戏服务器的纯文本游戏报告,现在我想在MySQL中存储赢/输信息,但我已经阅读了几个小时,找不到一个好方法 纯文本报告如下所示: name="9" id=#000094 clienttag=W2BN type="melee" option="normal" created="Tue Jul 21 23:22:26 MSK" started="Tue Jul 21 23:23:02 MSK" ended="Tue Jul 21 23:24:32 MSK" mapfile=

我使用Python解析来自游戏服务器的纯文本游戏报告,现在我想在MySQL中存储赢/输信息,但我已经阅读了几个小时,找不到一个好方法

纯文本报告如下所示:

name="9" id=#000094
clienttag=W2BN type="melee" option="normal"
created="Tue Jul 21 23:22:26 MSK" started="Tue Jul 21 23:23:02 MSK" ended="Tue Jul 21 23:24:32 MSK"
mapfile="Garden of War.pud" mapauth="Blizzard" mapsize=256x256 tileset="Unknown"
joins=3 maxplayers=8


sh4de            DRAW    
D.StyLez         DRAW    
Player           DRAW    


On map "Garden of War.pud":


sh4de was Orc and played for 1 minute

  Overall Score 1
             1 for Units
             0 for Structures
             0 for Resources

  Units Score 1
             1 Units Produced
             0 Units Killed
             0 Units Lost

  Structures Score 0
             0 Structures Constructed
             0 Structures Razed
             0 Structures Lost

  Resources Score 0
             0 Gold Mined
             0 Lumber Harvested
             0 Oil Harvested
             0 Total Spent
,
On map "Garden of War.pud":

D.StyLez was Orc and played for 1 minute

  Overall Score 2
             1 for Units
             1 for Structures
             0 for Resources

  Units Score 1
             1 Units Produced
             0 Units Killed
             0 Units Lost

  Structures Score 1
             1 Structures Constructed
             0 Structures Razed
             0 Structures Lost

  Resources Score 0
             0 Gold Mined
             0 Lumber Harvested
             0 Oil Harvested
             0 Total Spent
,
On map "Garden of War.pud":

Player was Human and played for 1 minute

  Overall Score 1
             1 for Units
             0 for Structures
             0 for Resources

  Units Score 1
             1 Units Produced
             0 Units Killed
             0 Units Lost

  Structures Score 0
             0 Structures Constructed
             0 Structures Razed
             0 Structures Lost

  Resources Score 0
             0 Gold Mined
             0 Lumber Harvested
             0 Oil Harvested
             0 Total Spent
,
GamePlayerScore
-ID PK AutoIncrement
-PlayerID FK(Player::ID)
-GameID FK(Game::ID)
-Place Int *Number representing how well the player placed*
-PlayerClass

Score
-ID PK AutoIncrement
-GamePlayerScoreID FK(GamePlayerScore::ID)
-Type varchar(50) *Overall, units, structures, etc.*
-Value Int

ScoreStat
-ScoreID FK(Score::ID) PK
-Name varchar(50) *gold mined, lumber harvested, etc.*
-Value Int
我已经分析了整个过程,我有一些变量,比如谁赢了,谁输了,每个人在哪个类别中得到了什么分数,以及报告顶部的所有游戏信息

但是不知道如何把它放到MySQL中 目标是能够进行详细的查询,如

选择sh4de是兽人并击败d.sytelz的所有游戏

这是一个8人的游戏。我能想到的唯一一件事就是能够询问谁赢了或输了我能做的一场比赛:

从游戏报告中选择*,其中赢家1或赢家2或赢家3或赢家4或赢家5或……..=sh4de和失败者_1或失败者_2或失败者_3…=D.stylez

但我无法知道谁是获胜者,所以我无法确定他是兽人还是人类

另外,如果我这样做的话,赢家1、赢家2、赢家3每一行都将是巨大的-赢家1必须有赢家1、赢家1、赢家1、赢家单位等8个赢家、8个输家、8个平局、8张光盘


必须有一个正确的方法来做这件事,我很困惑,所以这对任何人来说都很难回答,因为我们对你到底在做什么几乎没有背景。我假设您对MySQL有基本的了解,所以我将在这里做一个粗略的概述。我只是粗略地画出表格,希望这能给你们一个起点

格式:

Table
-Column [Type] [Relation] [Notes]
您可能首先需要一个玩家表来跟踪所有玩家。如果你不在乎在游戏之间追踪玩家,你可以跳过这个

Player
-ID Int PK AutoIncrement
-Name Varchar(50)
-(Whatever other metadata you want to store about the player)
接下来,您需要一张桌子来跟踪每场比赛:

Game
-ID Int PK AutoIncrement
-Map Varchar(255)
-Time DateTime
现在你需要在游戏和玩家之间建立一种多对多的关系。为了节省空间,我将把分数包括在这个表中,但是你可能想把它分开

GamePlayerScore
-GameID FK(Game::ID) PK
-PlayerID FK(Player::ID) PK
-Score Int
-Class varchar(50)
显然,这是一个非常好的例子,你会想把事情分成更多的部分,但是你应该了解基本的想法。我不建议存储每场比赛的赢家,而是通过拉分数在代码中确定赢家。由于您也有不同的分数类型,您可能需要一个表来保存带有“type”列的每个分数

一旦设置了表,就可以使用连接正确地聚合数据,并执行您所说的那种查询

编辑:阿切尔询问如何处理球员得分较高但仍然失败的情况。在不知道如何决定胜负的情况下,我建议修改我以前的回答,如下所示:

name="9" id=#000094
clienttag=W2BN type="melee" option="normal"
created="Tue Jul 21 23:22:26 MSK" started="Tue Jul 21 23:23:02 MSK" ended="Tue Jul 21 23:24:32 MSK"
mapfile="Garden of War.pud" mapauth="Blizzard" mapsize=256x256 tileset="Unknown"
joins=3 maxplayers=8


sh4de            DRAW    
D.StyLez         DRAW    
Player           DRAW    


On map "Garden of War.pud":


sh4de was Orc and played for 1 minute

  Overall Score 1
             1 for Units
             0 for Structures
             0 for Resources

  Units Score 1
             1 Units Produced
             0 Units Killed
             0 Units Lost

  Structures Score 0
             0 Structures Constructed
             0 Structures Razed
             0 Structures Lost

  Resources Score 0
             0 Gold Mined
             0 Lumber Harvested
             0 Oil Harvested
             0 Total Spent
,
On map "Garden of War.pud":

D.StyLez was Orc and played for 1 minute

  Overall Score 2
             1 for Units
             1 for Structures
             0 for Resources

  Units Score 1
             1 Units Produced
             0 Units Killed
             0 Units Lost

  Structures Score 1
             1 Structures Constructed
             0 Structures Razed
             0 Structures Lost

  Resources Score 0
             0 Gold Mined
             0 Lumber Harvested
             0 Oil Harvested
             0 Total Spent
,
On map "Garden of War.pud":

Player was Human and played for 1 minute

  Overall Score 1
             1 for Units
             0 for Structures
             0 for Resources

  Units Score 1
             1 Units Produced
             0 Units Killed
             0 Units Lost

  Structures Score 0
             0 Structures Constructed
             0 Structures Razed
             0 Structures Lost

  Resources Score 0
             0 Gold Mined
             0 Lumber Harvested
             0 Oil Harvested
             0 Total Spent
,
GamePlayerScore
-ID PK AutoIncrement
-PlayerID FK(Player::ID)
-GameID FK(Game::ID)
-Place Int *Number representing how well the player placed*
-PlayerClass

Score
-ID PK AutoIncrement
-GamePlayerScoreID FK(GamePlayerScore::ID)
-Type varchar(50) *Overall, units, structures, etc.*
-Value Int

ScoreStat
-ScoreID FK(Score::ID) PK
-Name varchar(50) *gold mined, lumber harvested, etc.*
-Value Int
这是超快速的,可能会做得更好,但你可以看到,当你深入表格时,事情会变得更加具体。此外,您没有为每件事单独设置一个表,而是将每件事划分为类似的类别,并使用类型对每件事进行分类


此外,由于您是新加入的,我建议在编写它们时使用图像,以帮助您了解实际选择的数据。如果您还有其他问题,我们将很乐意为您提供帮助。

谢谢!这将是我的第一个关系数据库,它现在让我大吃一惊。我可能会遇到这样的问题:有人得分更高,但仍然失败,比如说他们收获了一吨金子,但他们没有建立足够的士兵,因此他们仍然被得分更低的对手击败。有没有跟踪赢家/输家/Discer/平局的想法?-我想我可以把它存储在GamePlayerCore中,你可以给我写一个快速的SQL查询示例来连接表,并找到“sh4d3”在地图上的位置击败“player”和sh4d3=“war”例如,我不确定如何确定赢家,所以我很难回答。我将编辑我的答案,并提出一个想法。报告告诉我获奖者,所以我已经知道了。。在这个例子中,然而,这是一场三方平局,所以报告说sh4de DROW D.StyLez DROW Player DROW Player,但有时会说Player 1 WIN Player 2 LOSS Player 3 DROW Player 4 DISC仍然试图让我思考如何创建一个查询,就像选择游戏,其中Player 1击败Player 2,map='war'和Player 1='human'player2='orc'..etcSo您的最后一个问题实际上需要一个子查询来提取您正在查找的数据类型。否则事情会变得非常漫长和复杂。我没有足够的空间来讨论这个问题,但我建议先从更简单的查询开始,然后再进行构建。一开始,如果你不得不进行多次查询以获取所需信息,这并不是世界上最糟糕的事情。