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:
This particular csv file has information for 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:
name
) represents the name of the character.identity
) represents the characters “identity” type. In other words, is it their secret identity? There normal identity?alignment
) represents the characters alignment (Good, Evil, Neutral)eyes
) represents eye colorhair
) represents hair colorsex
) represents the character’s sexappearances
) represents the number of appearances the character has made in the marvel universeyear
) represents the year that the character first appearedWhen 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.
When implementing, you may either process the CSV by-hand, or use the csv
python module.
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 == value
column_name != value
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:
GET hair IF name == Thor
will print out the hair color column for all character(s) whose name
is Thor
GET appearances IF eyes == Green
will print out the appearance-count for all characters that have Green
eyesGET name IF hair != Blonde
will print the names of all of the characters whose “hair color” value is not Blonde
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:
GET
IF
==
or !=
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.
Submit this to D2L by Monday, March 19, by 5:00pm.
Name the file marvel-dbms.py
.
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
$
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
$
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!