Lecture 60: Survey Project

posted May 20, 2013, 5:42 AM by Samuel Konstantinovich   [ updated May 20, 2013, 5:45 AM ]
You have 2 class lab days to complete this project. It should be completed no later than Friday. 

In this project you will create a website where users can register with a name/password, fill out a survey and get the results. 
Here is an example of what you might end up with: http://149.89.150.100/~jdyrlandweaver/form-html/vote1.html

1. Link this on your home.html page.

2. Your website should have the following functionality:
  • Registering to vote (You should be done with this already, use your prior registration code! )
    • People should be able to enter a username and password and write that information to a file with all the registered users.
    • If a username is already taken, display a message saying they must pick a different name and do nothing else
  • Voting
    • People should be able to enter their username/password, answer the questions inside the survey and then submit their votes.
    • Once the form is submitted, the votes for each questions should be written to a file, the username should also be written to a file containing the names of everyone that has already voted. Then display all of the voting results, showing the totals for each answer. (For example, you could display a bar graph, or just print out the totals).
    • If a username has not been registered, display a message saying so and do nothing else.
    • If a username has already been used to vote, display a message saying so and do nothing else.
3. Technical details. What files should you have and what should they do?
  • Text files
    • You'll need 3 text files to keep track of all the information for this website, all of them will need to have write permissions.
      • registered-voters.txt
        • Contains a list of all the usernames/passwords.
        • You should have it hashed from the last assignment. If you do not, I will assume you didn't complete that assignment.
        • You can optionally include the email address in the registration.
        • Each line should follow this format: username:password
          • Example line: khan:12345
          • Example line (hashed): khan:01AC9B32F3EE04920F200
      • voters.txt
        • Contains a list of all the usernames that have already voted
        • You just need one line in this file, where each name is separated by commas.
          • Example line: dw,zamansky,brooks,konstans,leem
      • votes.txt
        • Contains all of the survey questions and their results
        • Each line should follow this format: question id:question:result0,result1
          • Example line: 0,How awesome is Mr Dw?,9001,3,2,9001,3,3,5,5
          • Notice that every time a new vote is registered, a new comma and value should be added to the end of the line (you don't have to split to do this)
      • Create each file before doing any other work. voters.txt and registered-voters.txt should be empty to start. votes.txt should have all the question ids and questions entered, but no vote values to start
  • HTML Form
    • Your form must have the following fields
      • Username
        • text field
      • Password
        • password field
      • Register button
        • submit
      • Questions
        • You must have at least 2 questions
        • You can use any field type, but radio buttons would be the easiest to work with.
      • Submit button
        • submit
    • Note that the register and submit buttons will be the same input type, make sure you use different names and values for each so you can differentiate them in your python program.
    • Make sure you have text that identifies/describes each input element.
    • You may add more features to the HTML page if you'd like
  • Python program
    • The program needs to be able to:
      • Register new users
      • Save survey results
      • Display survey results
      • Check if a user is registered
      • Check if a user has already voted
    • Things to look out for:
      • Make sure that you do not try to access a form element if the user did not enter anything for it
      • If there are any places where the user can enter text, make sure they can't break your page.

4. Challenges:
  • If you have finished all the requirements above, try some of these
  • DO NOT TRY THEM UNLESS YOU HAVE EVERYTHING ABOVE WORKING!
    • I would prefer a fully working project that has fewer features than a broken one that tries (and fails) to do extra things.
  • When someone goes to vote a second time, instead of just displaying a message, show the current results.
  • Instead of having a separate html form and python file, just have a single py file do all the work
  • Try using different input elements instead of radio buttons
    • Not all input elements behave the same way
  • Present the survey results in more interesting ways
Comments