HW 4: An Online Community Web Site [due: 3/10, midnight]

Printable Version


Introduction

This assignment intends to show how effectively databases can be used to drive real-world applications. You have to create an online community Web site, similar to Orkut. In the process, we expect you to learn the main challenges involved in providing such a service, and appreciate the importance of database technology in today's data-driven world.

This assignment is broken into two phases. In the first phase you will plan your implementation strategy at a high level, and submit documentation that describes the major design decisions you have made. The first phase permits the TA's to evaluate your progress at an early stage and provide feedback. In the second phase you will proceed to implement your community Web site. At the end you are to give a live, interactive demonstration of your Web site in front of a TA.

For this assignment, you can work in groups of three. Phase I is due on Monday, 26 February at 3pm. Details about the Phase II submission will be handed out later.

Features

Your community Web site must support the following features:

Setup

A Web server with PhP support has already been set up for you. To access it, you should log into your account (the one you used for HW 0) and type the following commands:
$ cd $HOME
$ mkdir www
$ chmod 705 www
The www directory will then be accessible via the url http://<machine-name>/~<andrew-id>/ For example, http://euterpe.datanium.cs.cmu.edu/~shashank/hw4/test.php

Deliverables

Phase I [10%] -- To begin with, you need to just create a design of the Web site on paper. You must submit a typed report to Wean 8303 (slip it under the door if it is closed). Phase I is intended as a way for us to help you, rather than evaluate you. The more specific and detailed you are, the more feedback we will be able to give you, and the easier Phase II will be. Your report should include: Phase II [90%] -- Phase II has two deliverables:
  1. The PHP and HTML files [40%]
  2. A live demonstration of your Web site [50%]
When you submit your PHP and HTML files, please remove unused/temporary files to make grading easier. Also, be sure to include extensive documentation and commenting. Unreadable code will not receive a good grade, even if it works perfectly fine. For your demonstration, plan on a 5-10 minute interactive session with a TA. (You will receive an email regarding scheduling of your demo.) During your demonstration you will be asked to do the following:

Documentation

PHP is relatively easy to learn and use, even if you have little or no experience with server-side scripting or HTML. This assignment is not focused on teaching you PHP, but you will of course need some PHP know-how to complete the assignment successfully. PHP documentation is available at http://www.php.net/manual/en/.

PHP has very straighforward and intuitive functions to connect and query a Postgres database. Documentation for this part is available at http://us3.php.net/pgsql. The most important functions you will need to use are pg_connect, pg_query, pg_fetch_row, pg_free_result, pg_close, but we recommend that you browse the list of available functions at least once before you start writing PHP scripts.

FAQs

I am having trouble connecting to the Postgres database from my PHP code

These are the steps to be followed to let PHP gracefully connect to your Postgres server:
Step 1:
------
Start an instance of the Postgres server at a unique port. First check if you already have an instance running from the previous homework. Type 'ps -ef' at the command line and see if you can find a process labelled '/usr/bin/postmaster -D /home/stu415_s06/<your-andrewid>/data -i -p <your-portnum>' If yes, then note down the port that the process is using and directly jump to step 2, otherwise read on.
Execute the following commands
Step 2:
------
In your php code, wherever you want to connect to the database server, type in the following:
$dbConn = pg_connect ("dbname=hw4 user=<your-andrewid> port=<your-portnum> host=localhost");

The user should also be able to view "friends of friends", "friends of friends of friends", and so on ...'
You can simplify this feature as follows:
  1. Implement a browse-only solution: To begin with the user can see only his own friends. When he clicks on a particular person, he can see that person's friends and so on. So effectively, the user has to browse to locate "friends of friends of .... friends." All your system has to do is to display the friend's list of a single person, where the person is the user himself or someone that the user clicked on.
  2. Implement a depth-wise solution: This is more difficult, but doable and will earn you more credit. Take as input an integer, and show all friends upto that distance from the user. If I am your friend, we are at a distance 1 from each other.

How do I implement the "finding paths connecting different users" feature?
There are (at least) two possible simplifications:
  1. Show paths only for browsing and not for search. E.g., if I am John, and I click on Smith in my friends list, and then click on Tom in Smith's friends list, I can easily determine that one path connecting me to Tom is "Me > Smith > Tom". It is good enough to show only this path for browsing, and avoid showing paths for search. This will involve some way of tracking the user's browsing path (through the url, sessions or the database itself.)
  2. Limit the length of paths to some number like 4. And then for each user in your database, precompute all people at a distance <= 4 from him (using breadth-first search). Store these distances in a relation, and at runtime, simply query this relation to find if there is a path between any two people. Of course, you will need to take care to keep this relation uptodate when new friends are added by a user.
There could be more such simplifications. If you plan to do any of them, just email me and I will let you know if its reasonable.

Final Sumbission, Demos (Tue 3/21, Wed 3/22 in WeH 8303)