CSc 250: Assignment 9

This assignment is all python. You should only use python features that we have discussed up to this point. If you have questions about whether or not a particular feature can/should be used, ask the instructors!

When grading your assignments, each problem/script/function will be thoroughly tested with many types of input, so make sure you test your scripts/functions well!

The python in this assignment will be graded using python 3.6, and tests will be run on a Mac machine. In general python works well cross-platform, but if you want to be absolutely sure your program works as expected, test on a mac! Any python version 3.4 or newer should suffice though.

All of your scripts should be well-formatted and easy for the graders to read. Each script should have a header comment at the top that has the following format:

#
# Author: Student Name
# Description:
#    A short description of what this program / script / set of functions does!
# 

Each function in your script(s) should have a descriptive comment above it. If any part of your scripts are particularly complex, you should put documentation comments above those lines of code.

MarvelDBMS (100 Points)

In this assignment, you will be implementing a very simple Database Management System (DBMS). This DBMS will give the user access to a database of Marvel comic characters, and should be called marvel-dbms.py Specifically, the DBMS will read and access the data in a csv file like this one:

marvel-data.csv

This particular csv file has information about 1000 of the most-mentioned marvel comic characters. The first few lines of this CSV file look roughly like:

Spider-Man,Secret,Good,Hazel,Brown,Male,4043,1962
Captain America,Public,Good,Blue,White,Male,3360,1941
Wolverine,Public,Neutral,Blue,Black,Male,3061,1974
Iron Man,Public,Good,Blue,Black,Male,2961,1963
Thor,No Dual,Good,Blue,Blond,Male,2258,1950
...

Each row represents a single marvel character. As for the columns:

When run, marvel-dbms.py will ask the user for a command which will specify which information the user wants from the database.

We may test your program on multiple different marvel-data.csv files. The format will be exactly the same, but the number of entries may be different. So you should not assume the input file will always have exactly 1000 rows.

Commands

The commands that marvel-dbms takes will have the following form:

GET X IF Y

X will be the name of one of the columns of the CSV file. Y will be a condition to check for each of the rows. A row will only be printed in the results if Y is true for the particular column. The Y part of the command will look like one of these:

column_name should be one of the names of the columns on the database. value should be some hard-coded value. value may have spaces in it.

If the operator in the middle is ==, you will be checking that the value of the specific column is equal to value. If the operator in the middle is !=, you will be checking that the value of the specific column is not equal to value. All three of these comparisons are string comparisons, even if a column appears to be numeric/integer.

Here are few example commands, with explanations:

When writing your program, you may assume that a correctly-formed query is always entered. You do not need to do any error checking. Thus, you can assume:

User Interface

When run, the program should print out the following lines:

MARVEL: Welcome to the DBMS.
MARVEL: Enter a command:

At this point, a user should enter a command with the format just described, and then hit Enter. Once entered, the program will print

MARVEL: Command results:

Followed by all of the results from the data set. Several complete examples are shown in the next section.

Running some commands

Lets run through a few real examples. Say that marvel-data.csv has exactly these contents:

Captain America,Public,Good,Blue,White,Male,3360,1941
Benjamin Grimm,Public,Good,Blue,No,Male,2255,1961
Iron Man,Public,Good,Blue,Black,Male,2961,1963
Reed Richards,Public,Good,Brown,Brown,Male,2072,1961
Hulk,Public,Good,Brown,Brown,Male,2017,1962
Spider-Man,Secret,Good,Hazel,Brown,Male,4043,1962
Scott Summers,Public,Neutral,Brown,Brown,Male,1955,1963
Jonathan Storm,Public,Good,Blue,Blond,Male,1934,1961
Henry McCoy,Public,Good,Blue,Blue,Male,1825,1963
Thor,No Dual,Good,Blue,Blond,Male,2258,1950
Susan Storm,Public,Good,Blue,Blond,Female,1713,1961
Ororo Munroe,Public,Good,Blue,White,Female,1512,1975
Wolverine,Public,Neutral,Blue,Black,Male,3061,1974
Clinton Barton,Public,Good,Blue,Blond,Male,1394,1964

Below are a few example runs, given this data set:

$ python3 marvel-dbms.py
MARVEL: Welcome to the DBMS.
MARVEL: Enter a command:
GET eyes IF hair == Brown
MARVEL: Command results:
Brown
Brown
Hazel
Brown
$
$ python3 marvel-dbms.py
MARVEL: Welcome to the DBMS.
MARVEL: Enter a command:
GET name IF hair == Brown
MARVEL: Command results:
Reed Richards
Hulk
Spider-Man
Scott Summers
$
$ python3 marvel-dbms.py
MARVEL: Welcome to the DBMS.
MARVEL: Enter a command:
GET name IF hair == Black
MARVEL: Command results:
Iron Man
Wolverine
$
$ python3 marvel-dbms.py
MARVEL: Welcome to the DBMS.
MARVEL: Enter a command:
GET appearances IF sex == Female
MARVEL: Command results:
1713
1512
$
$ python3 marvel-dbms.py
MARVEL: Welcome to the DBMS.
MARVEL: Enter a command:
GET appearances IF sex != Female
MARVEL: Command results:
3360
2255
2961
2072
2017
4043
1955
1934
1825
2258
3061
1394
$
$ python3 marvel-dbms.py
MARVEL: Welcome to the DBMS.
MARVEL: Enter a command:
GET name IF name != Thor
MARVEL: Command results:
Captain America
Benjamin Grimm
Iron Man
Reed Richards
Hulk
Spider-Man
Scott Summers
Jonathan Storm
Henry McCoy
Susan Storm
Ororo Munroe
Wolverine
Clinton Barton
$
$ python3 marvel-dbms.py
MARVEL: Welcome to the DBMS.
MARVEL: Enter a command:
GET hair IF year == 1963
MARVEL: Command results:
Black
Brown
Blue
$
$ python3 marvel-dbms.py
MARVEL: Welcome to the DBMS.
MARVEL: Enter a command:
get year if name == Hulk
MARVEL: Command results:
1962
$

EXTRA CREDIT (10 points)

As previously described, the second part of the user-command is the column to be printed. You can get up to 10 points of extra credit if you also support the “special” column-name all. If all is specified, all of the columns will be printed for each of the rows that match the condition.

Here are a few examples using the same shortened input file from above:

$ python3 marvel-dbms.py
MARVEL: Welcome to the DBMS.
MARVEL: Enter a command:
GET all IF hair == Black
MARVEL: Command results:
Iron Man, Public, Good, Blue, Black, Male, 2961, 1963
Wolverine, Public, Neutral, Blue, Black, Male, 3061, 1974
$
$ python3 marvel-dbms.py
MARVEL: Welcome to the DBMS.
MARVEL: Enter a command:
GET all if eyes == Blue
MARVEL: Command results:
Captain America, Public, Good, Blue, White, Male, 3360, 1941
Benjamin Grimm, Public, Good, Blue, No, Male, 2255, 1961
Iron Man, Public, Good, Blue, Black, Male, 2961, 1963
Jonathan Storm, Public, Good, Blue, Blond, Male, 1934, 1961
Henry McCoy, Public, Good, Blue, Blue, Male, 1825, 1963
Thor, No Dual, Good, Blue, Blond, Male, 2258, 1950
Susan Storm, Public, Good, Blue, Blond, Female, 1713, 1961
Ororo Munroe, Public, Good, Blue, White, Female, 1512, 1975
Wolverine, Public, Neutral, Blue, Black, Male, 3061, 1974
Clinton Barton, Public, Good, Blue, Blond, Male, 1394, 1964
$

Testing for correctness

This assignment requires printing out precise text messages and notifications. As already mentioned, it is important to be precise when doing these printouts.

We will only take minimal points off for very minor differences (for example, minor character spacing issues). However, we will take points off for any non-trivial differences, so try to be as precise as you can!

Submission and grading

This problem will be graded out of 100 points.

This was assigned on Friday, March 24, 2017. It is due Saturday, April 1, 2017, at 6:00pm.

Turn-in instructions:

Following these turn-in instructions closely is very important, because our grading scripts will depend on some of the details. You may lose points if these instructions are not followed precisely!