Project 2 - Pedometer Data Entry
Due 10pm Tuesday April 29

Our goal in this project is to build a Web site that we will be able to use to enter data from our pedometers, and store it in a .csv spreadsheet on the server. We'll take one of our solutions and use it to actually collect data for analysis; we'll make a Web interface for the analysis in the next project.

We'll begin with the simple working code that Jesse provided (thank you, Jesse!). It is on SmartSite, in his notes from the discussion section on the 18th, along with instructions for getting it set up on your server.

We'd like something a bit fancier. First, instead of just a number of steps, we'd like to store a userID, a date, and the number of steps. To add this extra information, you'll need to make several modifications to htmlClass.py. You'll need to make the output for index.html be a Web page with a form with all these fields. Then you'll need to change the output for addData.html to collect this new data and write it out to the .csv file.

Second, we want to put only good data into our file. For instance, if the number of steps is "1039084" or "6.7" or "cow", we should reject the entry, and ask the user to try again. Similary, the date should be a valid date, after April 14 but before tomorrow (whatever tomorrow is; you can use the Python "date" class from the "datetime" module to find out what today is). Handling user input errors will require generating a new Web page; let's call it "redo.html" putting error messages into add_data.html instead of the usual Web page text. I suggest making the result look similar to index.html, but also show the data the user entered (using the "value" attribtue of the html form element) and an error message explaing what was wrong with it.

Next, make these Web pages look good. Add a single style sheet, "stepcount.css", and have all your output html pages link to it. This should give you a consistent "look and feel". You can use "id=" or "class=" attributes in your HMTL to customize individual elements, for instance, the error messages. Feel free to include images or backgrounds.

One final detail; when you get a url that is not one of "index.html", "addData.html", or "report.html", instead of making a Web page that says "bad url", set the status code in the HTTP header to 404 Not Found, and send back a nicer Web page.

Harness:

In case this is useful...here is a little Python program you can use to test out your hw2.wsgi program, including your htmlClass.py, without having to upload it to the server every time. It's called harness.py. Change the name of hw2.wsgi to hw2.py, so it can import it as a module. It asks for a url; and it writes out the resulting Web page, which you can open in the browser if you want.

Resetting the server:

We've found that after a server program crashes, older, cached versions of the Web pages appear, even after the server program has been fixed. We therefore now recommend that after each server crash, you run the command:

sudo /usr/bin/systemctl restart httpd.service

It will ask for your password. This resets the server.

Handing in the assignment

Please hand in all your source files using SmartSite.

References: