Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from userstats import Stats
- """
- See README.txt
- Using userstats.Stats
- ---------------------
- Stats.filename = filename => Creates the Stats.stats object
- Stats.login(username, [password]) => Logs in to the local MySQL Server
- Stats.run() => Saves a copy of the userstats.dat and userstats.sql file
- as well as updating the MySQL database
- ====================================================
- Getting userstats data
- ----------------------
- stats -> userstats.Stats.stats
- Contains all of the userstats data of the given file.
- ----------------------
- stats[usgn] => Player
- stats(usgn = usgn) => Player
- stats(name = 'Player') => [Player, Player2, ...]
- stats.usgn_usgn => Player
- stats[usgn] Contains the following members
- ------------------------------------------
- stats[usgn].name => Name of Player
- stats[usgn].kills => Number of Kills
- stats[usgn].death => Number of Deaths
- stats[usgn].time => Total amount of time played
- Setting userstats data
- ----------------------
- stats[usgn].name = name => Sets the name of Player to name
- stats[usgn].kills = kills => Sets the number of kills of Player
- stats[usgn].death = death => Sets the number of deaths of Player
- stats[usgn].time = time => Sets the total amount of time played
- Managing userstats data
- -----------------------
- stats.new(usgn, [name = name,] [kills = kills,] [death = death,] [time = time]) => Creates a new Player. USGN is required
- stats.remove(usgn) => Removes the Player @ USGN
- stats.remove("name = Player") => Removes the Player[S] with name of 'Player'
- stats.save([name]) => Saves the userstats.dat file as name. (name is optional)
- -------------------------------------------------------------------
- ===================================================================
- -------------------------------------------------------------------
- Database Models
- ---------------
- model -> userstats.Stats.model
- Contains the transformation functions to create SQL format representations of userstats
- ---------------
- SQL Representation
- ------------------
- model.data => Contains auto-updated SQL representations of the userstats
- Model Functions => Requires MySQLdb (Else use save() only)
- ----------------------------------------------------------
- model.create_database([root = root_user,] [password = root_password])
- Creates the necessary MySQL database. user, and table dependencies. Does not require root or password
- model.run()
- Updates the MySQL database
- model.flush(root, password)
- Clears the MySQL table
- model.save([name])
- Saves the SQL file as name.sql
- """
- #Parse the userstats.dat file
- Stats.filename = 'userstats.dat'
- #Log into MySQL via username = 'root' and No password
- Stats.login('root')
- #Cache the variables. This is very convenient
- stats = Stats.stats
- model = Stats.model
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
- """
- Example 1:
- Changing Player with USGN of 146's name, kills, frags, death, and time
- """
- #stats.usgn_146.name = "New Name"
- #stats[146].kills = stats[146].kills + 100
- #stats(usgn = 146)[0].death = 1
- #stats.usgn_146.time = 10000
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
- """
- Example 2:
- Double the number of kills for each player
- """
- #for player in stats:
- # player.kills = player.kills * 2
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
- """
- Example 3:
- Prints out the average KPD of the group
- """
- #print stats
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
- """
- Example 4:
- Prints out a list of players who have a name of 'Player 2'
- """
- #print stats(name = 'Player 2')
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
- """
- Example 5:
- Changes the name of each player to his KPD
- """
- #for player in stats:
- # try:
- # player.name = "KPD of %s"%str(float(player.kills/player.death))
- # except:
- # player.name = "KPD of %s"%str(player.kills)
- #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
- #Uncomment to clear the MySQL table
- #model.flush()
- #Updates and saves both the MySQL and userstats.dat Data
- Stats.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement