Advertisement
Guest User

Lee Gao

a guest
Aug 5th, 2009
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.97 KB | None | 0 0
  1. from userstats import Stats
  2.  
  3. """
  4. See README.txt
  5.  
  6. Using userstats.Stats
  7. ---------------------
  8. Stats.filename = filename => Creates the Stats.stats object
  9. Stats.login(username, [password]) => Logs in to the local MySQL Server
  10. Stats.run() => Saves a copy of the userstats.dat and userstats.sql file
  11. as well as updating the MySQL database
  12.  
  13. ====================================================
  14.  
  15. Getting userstats data
  16. ----------------------
  17. stats -> userstats.Stats.stats
  18. Contains all of the userstats data of the given file.
  19. ----------------------
  20. stats[usgn] => Player
  21. stats(usgn = usgn) => Player
  22. stats(name = 'Player') => [Player, Player2, ...]
  23. stats.usgn_usgn => Player
  24.  
  25. stats[usgn] Contains the following members
  26. ------------------------------------------
  27. stats[usgn].name => Name of Player
  28. stats[usgn].kills => Number of Kills
  29. stats[usgn].death => Number of Deaths
  30. stats[usgn].time => Total amount of time played
  31.  
  32. Setting userstats data
  33. ----------------------
  34. stats[usgn].name = name => Sets the name of Player to name
  35. stats[usgn].kills = kills => Sets the number of kills of Player
  36. stats[usgn].death = death => Sets the number of deaths of Player
  37. stats[usgn].time = time => Sets the total amount of time played
  38.  
  39. Managing userstats data
  40. -----------------------
  41. stats.new(usgn, [name = name,] [kills = kills,] [death = death,] [time = time]) => Creates a new Player. USGN is required
  42. stats.remove(usgn) => Removes the Player @ USGN
  43. stats.remove("name = Player") => Removes the Player[S] with name of 'Player'
  44.  
  45. stats.save([name]) => Saves the userstats.dat file as name. (name is optional)
  46.  
  47. -------------------------------------------------------------------
  48. ===================================================================
  49. -------------------------------------------------------------------
  50.  
  51. Database Models
  52. ---------------
  53. model -> userstats.Stats.model
  54. Contains the transformation functions to create SQL format representations of userstats
  55. ---------------
  56.  
  57. SQL Representation
  58. ------------------
  59. model.data => Contains auto-updated SQL representations of the userstats
  60.  
  61. Model Functions => Requires MySQLdb (Else use save() only)
  62. ----------------------------------------------------------
  63. model.create_database([root = root_user,] [password = root_password])
  64. Creates the necessary MySQL database. user, and table dependencies. Does not require root or password
  65.  
  66. model.run()
  67. Updates the MySQL database
  68.  
  69. model.flush(root, password)
  70. Clears the MySQL table
  71.  
  72. model.save([name])
  73. Saves the SQL file as name.sql
  74. """
  75.  
  76. #Parse the userstats.dat file
  77. Stats.filename = 'userstats.dat'
  78. #Log into MySQL via username = 'root' and No password
  79. Stats.login('root')
  80.  
  81. #Cache the variables. This is very convenient
  82. stats = Stats.stats
  83. model = Stats.model
  84.  
  85. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
  86.  
  87. """
  88. Example 1:
  89. Changing Player with USGN of 146's name, kills, frags, death, and time
  90. """
  91.  
  92. #stats.usgn_146.name = "New Name"
  93. #stats[146].kills = stats[146].kills + 100
  94. #stats(usgn = 146)[0].death = 1
  95. #stats.usgn_146.time = 10000
  96.  
  97. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
  98.  
  99. """
  100. Example 2:
  101. Double the number of kills for each player
  102. """
  103.  
  104. #for player in stats:
  105. #    player.kills = player.kills * 2
  106.    
  107. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
  108.  
  109. """
  110. Example 3:
  111. Prints out the average KPD of the group
  112. """
  113.  
  114. #print stats
  115.  
  116. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
  117.  
  118. """
  119. Example 4:
  120. Prints out a list of players who have a name of 'Player 2'
  121. """
  122.  
  123. #print stats(name = 'Player 2')
  124.  
  125. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
  126.  
  127. """
  128. Example 5:
  129. Changes the name of each player to his KPD
  130. """
  131.  
  132. #for player in stats:
  133. #    try:
  134. #        player.name = "KPD of %s"%str(float(player.kills/player.death))
  135. #    except:
  136. #        player.name = "KPD of %s"%str(player.kills)
  137.  
  138. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
  139.  
  140. #Uncomment to clear the MySQL table
  141. #model.flush()
  142.  
  143. #Updates and saves both the MySQL and userstats.dat Data
  144. Stats.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement