Homework 5 Due July 26, 2015 Submissions are due by 11:59PM on the specified due date. Submissions may be made on the Blackboard course site under the Assignments tab. Late submissions will be accepted up to two days late with a 10% penalty for each day. Make sure your name and FSUID are in a comment at the top of the file. 1 stats db.py (50 points) Your task is to create a Python module called stats db.py. The stats db module provides the database interface for a statistics database for the blackjack application we’ve developed in class. Our database will be an sqlite database called statistics.db with a table called Statistics with the following columns: • name: varchar(10) – the name of the player. • wins: smallint – the number of wins in a session. • plays: smallint – the number of games played in a session. • percent: double – the percentage of games won in a session. The first thing you should do is build the statistics.db database using the sqlite3 command line tool as shown in class. Optionally, you may be interested in checking out the SQLite Manager plugin for Firefox, which provides a nice interface for building sqlite databases. Required methods of the stats db module: • top percent(): returns up to 5 records with the highest percentage of wins from the Statistics table. • insert stat(name, wins, plays): accepts as parameters the name, number of wins, and total games played in a session and inserts the information, along with the calculated percentage, into the Statistics table. Be careful to be sure that percentages are entered as a floating point value. After creating your database and stats db module, you should try to manually insert records and view the top records. Consider the example run below. >>> import stats_db >>> stats_db.insert_stat("Melina", 15, 20) >>> stats_db.top_percent() [(u’Melina’, 15, 20, 0.75), (u’Caitlin’, 3, 5, 0.6), (u’Ben’, 8, 16, 0.5)] 1 2 blackjack gui.py (50 points) The second part of this assignment is to use your stats db module to extend the functionality of the blackjack GUI we created in class. Included in hw5.tar are the following components: • blackjack gui.py - definition of BlackjackApp class, the main window of our application. • card table.py – definition of CardTable class. • blackjack.py – blackjack game logic and definition for BlackjackGame class. • card.py – definitions for Card, Hand, and Deck classes. • cards/ – subdirectory containing card images. While you need all of these components to run our blackjack application, you will only need to modify one file: blackjack gui.py. Here’s what you need to do: • Add a menu to the menu bar called ‘Game’ which contains an action called ‘Stats’. • Set a status tip for the ‘Stats’ action indicating that it allows the user to view game statistics of top players. • Upon selecting the ‘Stats’ action, a window should pop up which displays the name, number of games won, number of games played, and percentage won for up to 5 of the top winning sessions. The percentage should be rounded to two digits after the decimal point, if necessary. • Upon confirmation of a closeEvent for the main window - that is, when a user attempts to exit the program - the information of the player should be stored in the database, but only if the number of games played is greater than zero. This information is accessible through the central widget, the CardTable class instance, using self.c.player name, self.c.gamesWon, and self.c.gamesPlayed. You may modify blackjack gui.py however you’d like (and be sure to have it include your newly created stats db module), but you may not modify any of the other files. Your submission to blackboard should consist of only the modified blackjack gui.py file and stats db.py file. Screenshots of an example solution are shown below for clarity. 2 3