Difference between revisions of "Module 6"

From CSE330 Wiki
Jump to navigationJump to search
Line 1: Line 1:
−
__NOTOC__  
+
__NOTOC__
−
Module 6 builds upon the JavaScript skills you learned in Module 5.
+
In Module 6, you will learn the fundamentals of Python, a popular scripting language, and Regular Expressions, which give you power in text processing.
 +
 
 +
This article contains your assignments for Module 6.
 +
 
 +
== Using the Wiki ==
 +
{{RequiredInstructions|content=
 +
Text enclosed by <syntaxhighlight lang="bash" inline><</syntaxhighlight> and <syntaxhighlight lang="bash" inline>></syntaxhighlight> should be replaced by content unique to you.
 +
 
 +
'''Example'''
 +
 
 +
<source lang="bash">
 +
$ sudo useradd -r -m -c "<My Full Name>" <usernameHere>
 +
</source>
 +
becomes
 +
<source lang="bash">
 +
$ sudo useradd -r -m -c "Zach Cohn" zcohn
 +
</source>
 +
}}
 +
 
  
 
== Reading ==
 
== Reading ==
Line 6: Line 24:
 
The following articles on the online class wiki textbook contain information that will help you complete the assignments.
 
The following articles on the online class wiki textbook contain information that will help you complete the assignments.
  
−
* [[Node.JS]]
+
* [[Python]]
−
* [[Socket.IO]]
+
* [[Regular Expressions]]
 
* [[FAQ - Mod 6]]
 
* [[FAQ - Mod 6]]
  
 
== Individual Assignments ==
 
== Individual Assignments ==
  
−
=== Install Node.JS ===
+
=== Learn Python and Regular Expressions ===
  
−
Install Node.JS from Apt or Yum according to the instructions in the [[Node.JS]] guide.
+
Up to this point in CSE 330, you have used only one programming language: PHP.  In Module 4, you will learn a new language: Python. Before starting this assignment, you should look over the [[Python|online textbook article about Python]].  You should be using version 3 (or greater) of Python. Additionally, you may find it helpful to look over the [[Regular Expressions|online textbook article about Regular Expressions]].
  
−
=== Static File Server in Node.JS ===
+
=== Write some Regular Expressions ===
  
−
The individual portion of Module 6 is short in order to give you enough time to complete the group portion.
+
Please write regular expressions that do each of the following:
  
−
# Copy the example code from the Node.JS guide into a file called ''static_server.js'' or something of that nature.  Save it on your EC2 instance (but not in a place that Apache can serve!).
+
# Match the substring "hello world" in a string.
−
#: Ensure that you understand what the static file server script is doing…
+
# Match all character strings in an input string that contain three or more consecutive vowels. The regex should match strings containing three or more consecutive vowels, regardless of whether the letters are uppercase, lowercase, or a mixture of both.
−
# Make a directory parallel to ''static_server.js'' named ''static''.
+
# Match an input string that is '''entirely''' a flight code, of the format AA####, where '''AA''' is a two-letter uppercase airline code, and '''####''' is a three- or four-digit flight number.
−
# Change "<STATIC DIRECTORY NAME>" on line 11 of the static fileserver example code to reflect the name of the directory you just made.
+
Examples:
−
# Save the following files in your ''static'' directory:
+
  Note: text in ''[[red]]'' is matched by the regular expression. Please note that each line is a '''separate''' test input string. For Regex 3, '''six''' separate test cases are given.
−
#* ''hello.txt'', a text file containing "Hello World"
+
  Regex 1:  Programmers will often write ''[[hello world]]'' as their first project with a programming language.
−
#* ''brookings.jpg'', an image file you can download from here: http://classes.engineering.wustl.edu/cse330/content/brookings.jpg
+
  Regex 2:  The ''[[gooey]]'' peanut butter and jelly sandwich was a ''[[beauty]]''.
−
#* ''college.html'', an HTML document based on the [[HTML and CSS#Quick and Easy Page Layout|Quick and Easy HTML Layout]] containing an image tag pointing to ''brookings.jpg''
+
  Regex 3:  ''[[AA312]]''
−
#* ''phpinfo.php'', a PHP file containing the phpinfo command that generates a diagnostic page of the server:
+
            ''[[AA1298]]''
−
#: <source lang="php"><?php  phpinfo();  ?></source>
+
            ''[[NW1234]]''
−
# Boot up your Node.JS static fileserver, and from your browser, load all four of the files you created in step 4.
+
            ''[[US443]]''
−
#: Which ones work and which ones don't?  Why might this be the case?
+
            US31344
 +
            AA123 extratext
  
−
== Group Project ==
+
           
  
−
In the group portion of Module 6 you will create a multi-room chat server using Node.JS and Socket.IO. This project must be completed using Node.JS.
+
Save your regexes to text files – one each.
  
−
This chat service will contain a main lobby where users sign on with a nickname and can communicate with each other.  Users may also create chat rooms for other to join.  The entire app should be displayed on a single webpage, listing the room you are in, all available rooms, and the users in the current room.
+
=== Baseball Stats Counter ===
  
−
The single room chat server and client are provided here: [[Socket.IO]]
+
The St. Louis Cardinals are the most legendary baseball team in the national league.  In this exercise, you will be creating a Python script that reads box scores from a file and computes the Cardinals' players' batting averages in a particular season.
  
−
== Grading ==
+
==== Tips and Instructions ====
 +
 
 +
* You should write a Python script file to solve this problem.
 +
* You should use a regular expression to parse players' names, at-bats, hits, and runs from the input file.
 +
* You may want to create a class to hold and compute information about each player.
 +
* Your file should take one command-line argument: the path to an input file.  If no path is given, your program should print a usage message.
 +
 
 +
==== Input ====
 +
 
 +
Sample input files may be found here: http://classes.engineering.wustl.edu/cse330/content/cardinals/
 +
 
 +
The top of the file contains a citation, and what follows is an entire season of Cardinals Baseball box scores.  Each game starts with a title; for example:
 +
 
 +
=== St.Louis Cardinals vs. Chicago Cubs, 1940-04-19 ===
 +
 
 +
What follows are the performance of each player in that game.  The format of each line is as follows:
 +
 
 +
XXX batted # times with # hits and # runs
 +
 
 +
where '''XXX''' is the player's name (you may assume that the name is unique), and each '''#''' are integers representing the number of "at bats", the number of "hits", and the number of "runs", respectively.
 +
 
 +
==== Output ====
 +
 
 +
Your script needs to output all players' batting average across the season.  A player's batting average is that player's total hits divided by that player's total at-bats throughout the entire season.  For example, Johnny Hopp was at bat 149 times in 1940, and he had 41 hits, so his batting average was 0.275.
 +
 
 +
Each line in the output should have the format:
 +
 
 +
XXX: #.###
 +
 
 +
where '''XXX''' is the player's name, and '''#.###''' is the player's batting average, '''rounded''' (not truncated) to three decimal places.
 +
 
 +
The players should be sorted by batting average, with the highest batting average on top.  If two players have the exact same batting average (before rounding occurs), the order between those two players is unimportant.
  
−
We will be grading the following aspects of your work. There are 75 points total.
+
For example, the correct output for the 1940 season is:
 +
<!-- Jimmy Brown was 0.280 and Ira Hutchinson was 0.125 -->
 +
<source lang="text">
 +
Pepper Martin: 0.316
 +
Walker Cooper: 0.316
 +
Johnny Mize: 0.314
 +
Ernie Koy: 0.310
 +
Enos Slaughter: 0.306
 +
Joe Medwick: 0.304
 +
Terry Moore: 0.304
 +
Joe Orengo: 0.286
 +
Jimmy Brown: 0.280
 +
Marty Marion: 0.279
 +
Don Gutteridge: 0.276
 +
Johnny Hopp: 0.275
 +
Creepy Crespi: 0.273
 +
Mickey Owen: 0.265
 +
Bill DeLancey: 0.250
 +
Don Padgett: 0.242
 +
Stu Martin: 0.238
 +
Eddie Lake: 0.222
 +
Hal Epps: 0.214
 +
Lon Warneke: 0.209
 +
Harry Walker: 0.185
 +
Max Lanier: 0.179
 +
Bill McGee: 0.178
 +
Carl Doyle: 0.174
 +
Mort Cooper: 0.157
 +
Clyde Shoun: 0.145
 +
Carden Gillenwater: 0.130
 +
Bob Bowman: 0.067
 +
</source>
  
−
'''Assignments (including code) must be committed to Github by the end of class on the due date (commit early and often). Failing to commit by the end of class on the due date will result in a 0. '''
+
== Grading ==
  
−
'''Additionally, for this module, the TA should be able to simply download your repo and start up your file server, without having to copy files or create additional subdirectories.  This applies to both the individual and the creative portion'''
+
We will be grading the following aspects of your work.  There are 50 points total.
  
−
_________
+
'''Assignments (including code) must be committed to Github by the end of class on the due date (commit early and often). Failing to commit by the end of class on the due date will result in a 0. '''
  
−
# '''Individual Portion (25 Points):'''
+
Upload your baseball code and a file with your Regular expressions.
−
#* Node.JS is installed on your EC2 instance (5 points)
 
−
#*: ''Take a screenshot of your browser visiting your EC2 instance serving up the college.html web page on port 3456, make sure the URL is visible in the screenshot.''
 
−
#* The ''hello.txt'', ''brookings.jpg'', and ''college.html'' files all load successfully (4 points each)
 
−
#* Visiting a file that does not exist inside the ''static'' directory results in a 404 (4 points)
 
−
#* Discuss in the README.md why ''phpinfo.php'' behaves the way it does when loaded through Node.JS (4 points)
 
−
#* Make sure all of your individual portion files are pushed to Github (include your node.js files, hello.txt, brookings.jpg, college.html, and phpinfo.php)
 
  
−
# '''Multi-room Chat Server (50 Points):'''
+
# '''Regular Expressions (15 Points):'''
−
#* '''''Administration of user created chat rooms (25 Points):'''''
+
#* '''Your regex files should contain your regex (with no delimiters or flags) and nothing else.'''
−
#** Users can create chat rooms with an arbitrary room name(5 points)
+
#* Regular Expression 1 Correct and saved in a file named <code>regex1.txt</code> (5 points)
−
#** Users can join an arbitrary chat room (5 points)
+
#* Regular Expression 2 Correct and saved in a file named <code>regex2.txt</code>(5 points)
−
#** The chat room displays all users currently in the room (5 points)
+
#* Regular Expression 3 Correct and saved in a file named <code>regex3.txt</code>(5 points)
−
#** A private room can be created that is password protected (5 points)
+
# '''Baseball Stats Counter (35 Points):'''
−
#** Creators of chat rooms can temporarily kick others out of the room (3 points)
+
#* Solution is written entirely in Python and saved in a file named <code>baseball.py</code> (8 points)
−
#** Creators of chat rooms can permanently ban users from joining that particular room (2 points)
+
#*: ''Note: Failing to write your code in Python 3 will result in losing, at a minimum, points for this category.''
−
#* '''''Messaging (5 Points):'''''
+
#* Correct usage of one or more regular expressions to parse and extract data from each line of the input file (8 points)
−
#** A user's message shows their username and is sent to everyone in the room (1 point)
+
#*: ''Note: You should not be using <code>str.split</code> to extract data.''
−
#** Users can send private messages to another user in the same room (4 points)
+
#* Script prints a usage message if a command line argument is not present (4 points)
−
#* '''''Best Practices (5 Points):'''''
+
#*: ''Note: For an example of a usage message, see [https://en.wikipedia.org/wiki/Usage_message#Examples this link.]''
−
#** Code is well formatted and easy to read, with proper commenting (2 points)
+
#* Output is correct for all test cases (15 points)
−
#** Code passes HTML validation (2 points)
+
#*: ''This includes sorting and rounding.''
−
#** node_modules folder is ignored by version control (1 points)
 
−
#* '''''Usability (5 Points):'''''
 
−
#** Communicating with others and joining rooms is easy and intuitive (4 points)
 
−
#** Site is visually appealing (1 point)
 
−
#* '''Creative Portion (10 Points)'''
 
−
<!-- #** Make sure to create a README.md file pointing to your server -->
 
  
 
[[Category:Module 6]]
 
[[Category:Module 6]]
 
[[Category:Modules]]
 
[[Category:Modules]]

Revision as of 17:14, 10 January 2026

In Module 6, you will learn the fundamentals of Python, a popular scripting language, and Regular Expressions, which give you power in text processing.

This article contains your assignments for Module 6.

Using the Wiki

Text enclosed by < and > should be replaced by content unique to you.

Example

$ sudo useradd -r -m -c "<My Full Name>" <usernameHere>

becomes

$ sudo useradd -r -m -c "Zach Cohn" zcohn


Reading

The following articles on the online class wiki textbook contain information that will help you complete the assignments.

Individual Assignments

Learn Python and Regular Expressions

Up to this point in CSE 330, you have used only one programming language: PHP. In Module 4, you will learn a new language: Python. Before starting this assignment, you should look over the online textbook article about Python. You should be using version 3 (or greater) of Python. Additionally, you may find it helpful to look over the online textbook article about Regular Expressions.

Write some Regular Expressions

Please write regular expressions that do each of the following:

  1. Match the substring "hello world" in a string.
  2. Match all character strings in an input string that contain three or more consecutive vowels. The regex should match strings containing three or more consecutive vowels, regardless of whether the letters are uppercase, lowercase, or a mixture of both.
  3. Match an input string that is entirely a flight code, of the format AA####, where AA is a two-letter uppercase airline code, and #### is a three- or four-digit flight number.

Examples:

  Note: text in red is matched by the regular expression. Please note that each line is a separate test input string. For Regex 3, six separate test cases are given.
  Regex 1:  Programmers will often write hello world as their first project with a programming language.
  Regex 2:  The gooey peanut butter and jelly sandwich was a beauty.
  Regex 3:  AA312
            AA1298
            NW1234
            US443
            US31344
            AA123 extratext


Save your regexes to text files – one each.

Baseball Stats Counter

The St. Louis Cardinals are the most legendary baseball team in the national league. In this exercise, you will be creating a Python script that reads box scores from a file and computes the Cardinals' players' batting averages in a particular season.

Tips and Instructions

  • You should write a Python script file to solve this problem.
  • You should use a regular expression to parse players' names, at-bats, hits, and runs from the input file.
  • You may want to create a class to hold and compute information about each player.
  • Your file should take one command-line argument: the path to an input file. If no path is given, your program should print a usage message.

Input

Sample input files may be found here: http://classes.engineering.wustl.edu/cse330/content/cardinals/

The top of the file contains a citation, and what follows is an entire season of Cardinals Baseball box scores. Each game starts with a title; for example:

=== St.Louis Cardinals vs. Chicago Cubs, 1940-04-19 ===

What follows are the performance of each player in that game. The format of each line is as follows:

XXX batted # times with # hits and # runs

where XXX is the player's name (you may assume that the name is unique), and each # are integers representing the number of "at bats", the number of "hits", and the number of "runs", respectively.

Output

Your script needs to output all players' batting average across the season. A player's batting average is that player's total hits divided by that player's total at-bats throughout the entire season. For example, Johnny Hopp was at bat 149 times in 1940, and he had 41 hits, so his batting average was 0.275.

Each line in the output should have the format:

XXX: #.###

where XXX is the player's name, and #.### is the player's batting average, rounded (not truncated) to three decimal places.

The players should be sorted by batting average, with the highest batting average on top. If two players have the exact same batting average (before rounding occurs), the order between those two players is unimportant.

For example, the correct output for the 1940 season is:

Pepper Martin: 0.316
Walker Cooper: 0.316
Johnny Mize: 0.314
Ernie Koy: 0.310
Enos Slaughter: 0.306
Joe Medwick: 0.304
Terry Moore: 0.304
Joe Orengo: 0.286
Jimmy Brown: 0.280
Marty Marion: 0.279
Don Gutteridge: 0.276
Johnny Hopp: 0.275
Creepy Crespi: 0.273
Mickey Owen: 0.265
Bill DeLancey: 0.250
Don Padgett: 0.242
Stu Martin: 0.238
Eddie Lake: 0.222
Hal Epps: 0.214
Lon Warneke: 0.209
Harry Walker: 0.185
Max Lanier: 0.179
Bill McGee: 0.178
Carl Doyle: 0.174
Mort Cooper: 0.157
Clyde Shoun: 0.145
Carden Gillenwater: 0.130
Bob Bowman: 0.067

Grading

We will be grading the following aspects of your work. There are 50 points total.

Assignments (including code) must be committed to Github by the end of class on the due date (commit early and often). Failing to commit by the end of class on the due date will result in a 0.

Upload your baseball code and a file with your Regular expressions.

  1. Regular Expressions (15 Points):
    • Your regex files should contain your regex (with no delimiters or flags) and nothing else.
    • Regular Expression 1 Correct and saved in a file named regex1.txt (5 points)
    • Regular Expression 2 Correct and saved in a file named regex2.txt(5 points)
    • Regular Expression 3 Correct and saved in a file named regex3.txt(5 points)
  2. Baseball Stats Counter (35 Points):
    • Solution is written entirely in Python and saved in a file named baseball.py (8 points)
      Note: Failing to write your code in Python 3 will result in losing, at a minimum, points for this category.
    • Correct usage of one or more regular expressions to parse and extract data from each line of the input file (8 points)
      Note: You should not be using str.split to extract data.
    • Script prints a usage message if a command line argument is not present (4 points)
      Note: For an example of a usage message, see this link.
    • Output is correct for all test cases (15 points)
      This includes sorting and rounding.