EventReporter
This project builds on the lessons learned in EventManager and is focused on practicing fundamental Ruby style/concepts.
This project is open source. If you notice errors, typos, or have questions/suggestions, please submit them to the project on Github.
Learning & Practice Goals
- Achieve functional comfort with implementing classes and methods
- Demonstrate understanding of variable scope and lifecycle
- Create multiple coordinating methods
- Use default and named parameters
- Utilize effective debugging techniques
Abstract
Let’s take EventManager to the next level. Based on the same data file, build an interactive query and reporting tool which fulfills the expectations below. It is assumed that you will re-use data cleaning procedures from the original EventManager to handle dirty input and generate beautiful output.
Data Supplied
- Source data file: event_attendees.csv
Base Expectations
As a user launching the program, I’m provided a command prompt where I can issue one of several commands, described below. After each command completes, the prompt returns, waiting for another instruction.
The program has a concept called the "queue". The queue holds the stored results from a previous search. As a user, I issue a search command to find records, then later issue another command to do something with those results. The queue is not cleared unless the user runs the command queue clear or a new find command.
Command Prompt Instructions
The program must respond to the following commands:
load <filename>
Erase any loaded data and parse the specified file. If no filename is given, default to event_attendees.csv.
help
Output a listing of the available individual commands
help <command>
Output a description of how to use the specific command. For example:
1 2 | |
queue count
Output how many records are in the current queue
queue clear
Empty the queue
queue print
Print out a tab-delimited data table with a header row following this format:
1
| |
queue print by <attribute>
Print the data table sorted by the specified attribute like zipcode.
queue save to <filename.csv>
Export the current queue to the specified filename as a CSV. The file should should include data and headers for last name, first name, email, zipcode, city, state, address, and phone number.
find <attribute> <criteria>
Load the queue with all records matching the criteria for the given attribute. Example usages:
find zipcode 20011find last_name Johnsonfind state VA
The comparison should:
- Be insensitive to case, so
"Mary"and"mary"would be found in the same search - Be insensitive to internal whitespace, but not external:
"John"and"John "are considered matches"John Paul"and"Johnpaul"are not matches
- Not do substring matches, so a
find first_name Marydoes not find a record with first name"marybeth"
Test Cases for Base Expectations
Your program must handle the following scenarios correctly:
A. Happy Path
load event_attendees.csvqueue countshould return0find first_name Johnqueue countshould return63queue clearqueue countshould return0helpshould list the commandshelp queue countshould explain the queue count functionhelp queue printshould explain the printing function
B. Let’s Try Printing
loadqueue countshould return0find first_name Johnfind first_name Maryqueue printshould print out the 16 attendeesqueue print by last_nameshould print the same attendees sorted alphabetically by last namequeue countshould return16
C. Saving
loadfind city Salt Lake Cityqueue printshould display 13 attendeesqueue save to city_sample.csv- Open the CSV and inspect that it has correct headers and the data rows from step 3.
find state DCqueue print by last_nameshould print them alphabetically by last namequeue save to state_sample.csv- Open the CSV and inspect that it has the headers, the data from step 7, but not the data previously found in step 2.
D. Reading Your Data
loadfind state MDqueue save to state_sample.csvquit
Restart the program and continue…
load state_sample.csvfind first_name Johnqueue countshould return4
E. Emptiness
Note that this set intentionally has no call to load:
find last_name Johnsonqueue countshould return0queue printshould not print any attendee dataqueue clearshould not return an errorqueue print by last_nameshould not print any dataqueue save to empty.csvshould output a file with only headersqueue countshould return0
Extensions
Improving queue print
- Modify your
queue printcommand so it prints in left-aligned columns where the size of each column is determined by the longest entry in the column. - If the queue is more than 10 lines, pause after ten until the user hits either the spacebar or enter keys.
- Add a status line that reads like "Showing Matches 20-30 of 80"
Improving find
- Modify your
findinstruction so all searches are case insensitive - Modify your
findinstruction to allow compound searches using a singleandsuch as:
1
| |
Improving queue save to
- Modify the instruction to respect the filename extension so that:
csvgenerates comma-separated valuestxtgenerates tab-delimited valuesjsongenerates valid, parsable JSONxmlgenerates valid, parsable XML
Implementing Queue Math
Assuming I have results currently in the queue, implement queue math like this:
1 2 | |
That would find me all entries for DC that are not in 20011. Similarly:
1 2 | |
Would load the queue with all entries from DC or the 22182 zipcode.
Nightmare-Mode find
Modify your find method to allow multiple attribute values in parentheses like this:
1
| |
Support an or operation:
1
| |
And support find only within the queue:
1 2 | |
Which would find only the Johnsons in 20011 or 22182.
Test Cases for Extensions
For the extensions to pass the evaluation, it must handle the following scenarios correctly.
A. Improved queue print
loadfind first_name sarahqueue print
Observe the first two screens of output similar to this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |
Noting that it has…
- Aligned columns
- 10 entries per screen
- A status bar displaying total records
But, the exact number of records may differ if the program does not implement the "improved find" with case-insensitive search.
B. Improved find
loadfind first_name sarah and state CA- Observe that there should only be four records in the queue
C. Improved queue save to
loadfind first_name Sarahqueue save to sarah.xmlqueue save to sarah.jsonqueue save to sarah.txt- Inspect the three output files for completeness and structure.
D. Queue Math
loadfind zipcode 20011subtract first_name williamadd zipcode 20010- Observe that there are 8 records in the queue.
E. Nightmare-Mode Find
loadfind state (DC, VA, MD) and last_name johnson- Observe that there are three records in the queue.
loadfind state dc or last_name smith- Observe that there are 270 records in the queue
queue find first_name alicia- Observe that only 3 records remain in the queue
Evaluation Criteria
These projects will be peer assessed using test scripts and the following rubric:
- Correctness
- 4: All results are correct
- 3: One script resulted in incorrect results or an error
- 2: Two or three scripts generated incorrect results or errors
- 1: More than three scripts generate errors
- 0: Program will not run
- Style
- 4: Source code consistently uses strong code style including lines under 80 characters, methods under 13 lines of code, and correct indentation.
- 3: Source code uses good code style, but breaks the above criteria in two or fewer spots
- 2: Source code uses mixed style, with three to five style breaks
- 1: Source code is generally messy with six to ten issues
- 0: Source code is unacceptable, containing more than 10 style issues
- Effort
- 5: Program fulfills all Base Expectations and five Extensions
- 4: Program fulfills all Base Expectations and two Extensions
- 3: Program fulfills all Base Expectations
- 2: Program fulfills Base Expectations except for one or two features
- 1: Program fulfills several Base Expectations, but more than two features are missing
- 0: Program does not fulfill any of the Base Expectations
Test scripts
Follow the instruction sequences listed in the Test Cases sections above, and compare the expected output to the actual output. Any Ruby exceptions are an automatic failure for that script.
Resources
- Source data file: event_attendees.csv
- Check line length and some other formatting issues with the Cane gem: https://github.com/square/cane