Skip to content

Commit

Permalink
Final upload
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitraka committed Mar 9, 2020
0 parents commit 30574f0
Show file tree
Hide file tree
Showing 37 changed files with 2,034 additions and 0 deletions.
Binary file added Instructions.pdf
Binary file not shown.
75 changes: 75 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# postgraDB

##### *NOTE: Ubuntu(16/18) usage is strongly recommended*

#### A) Package Dependencies:
- python3.X
- pip (reference Python package manager)

Linux:

`> python3 -m pip install --user --upgrade pip`

Windows:

`> py -m pip --version`
- venv (*should be already installed with python3*)

1. Inside app folder create a pyton3 virtual enviornment: `> python3 -m venv env`

2. Activate your virtual environment: `> source env/bin/activate`

#### B1) Virtual envionment dependencies:
In order to run *db.py* you need to install:

1. Flask : `pip3 install flask`

2. sqlalchemy: `pip3 install sqlalchemy`

3. mysqlclient: `pip3 install mysqlclient`

__*Note:*__ In case B1 fails you can follow **B2** on which some added dependencies are installed.

#### B2) Virtual envionment dependencies (<u>Warning</u>: Execute this step only in case B1 fails completely):
1. After sourcing your virtual environment execute:

pip3 install -r requirements.txt


#### C) Skip this section if no errors came up from section B

- If you got an error `Failed building wheel for sqlalchemy` at step 2 you should run `pip3 install wheel` and then try again from step 2.

- If you got an error `Failed building wheel for mysqlclient` at step 3 then run the following commands:

- Install the Python and MySQL development headers and libraries: `sudo apt-get install python-dev default-libmysqlclient-dev`
- If you are using python3 then you need to install python3-dev using the following command:
`sudo apt-get install python3-dev`
- Install from PyPI: `pip install mysqlclient`
- Then continue to section D



#### D) Execute:
0. **Important:** Execute *postgradb.sql* file on your local mysql server in order to install postgraDB as a database on your computer

`mysql> source /you_path_to_postgradb_sql_file/postgradb.sql`

1. **Important:** Open *db.py* script and modify `mysql:url` (line:6) by inserting your <u>username</u> and <u>password</u> that you use on your local mysql server:

`create_engine("mysql://<you_username_here>:<your_password_here>@localhost/postgradb?host=localhost?port=3306")`

2. Run `python3 db.py`
3. Open you browser
4. Type `127.0.0.1:5000/`

---

#### Extra: Use case scenarios

a) In search page user can search universities by uni_id like ("ETH, auth, Duth etc.")

b) In search page user can search available programs (by domain) using any keyword. Typing "psyc" for example will output "psychology" programs.



163 changes: 163 additions & 0 deletions db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
from flask import Flask, redirect, url_for, request, render_template
from sqlalchemy import create_engine

app = Flask(__name__)

engine = create_engine("mysql://admin:password@localhost/postgradb?host=localhost?port=3306")
conn = engine.connect()


@app.route('/', methods=['GET'])
def root():
return redirect(url_for('home'))

@app.route('/home', methods=['GET'])
def home():
return render_template('home.html')


@app.route('/search_page', methods=['GET'])
def search_page():
return render_template('search.html')


@app.route('/search_uni',methods = ['POST', 'GET'])
def search_uni():
if request.method == 'POST':
uni = request.form['uni']
#domain = request.form['domain']
result = conn.execute("SELECT * FROM University WHERE universityID='" + uni +"'").fetchall()
#print(result)
if(len(result)==0):
return redirect(url_for('search_page'))
return redirect(url_for('universities', name=result[0].universityID))
else:
uni = request.args.get('uni')
domain = request.args.get('domain')
return redirect(url_for('universities',name = uni))




@app.route('/universities/<name>')
def universities(name):

#load data
uni = conn.execute("SELECT * FROM University WHERE universityID='" + name +"'").fetchall()
uni_programs= conn.execute("SELECT * FROM programs_by_unis WHERE universityID='" + name +"'").fetchall()


#parse uni data
uni_name = uni[0].name
uni_rank = uni[0].ranking
uni_city = uni[0].city
uni_country = uni[0].country


programs = [None] *len(uni_programs)
temp_ids = [None] * len(uni_programs)
ids = [None] * len(uni_programs)


#parse uni_programs data
for msc in range(len(uni_programs)):
programs[msc]=uni_programs[msc].Msc


for program_ids in range(len(uni_programs)):
join_dept_program="SELECT Program.name, Department.university_id, Program.programID FROM postgradb.Program join postgradb.Department on department_id= departmentID"
program_name_to_id="SELECT q1.programID FROM (%s)as q1 where q1.university_id='%s' and q1.name ='%s'" %(join_dept_program, name, programs[program_ids])
temp_ids[program_ids]= conn.execute(program_name_to_id).first()


#convet program ids (from sqlalchemy.row.proxy type) in str
for i in range(len(uni_programs)):
ids[i]=(temp_ids[i][0])

print(ids[0])

return render_template('university.html', uni_country=uni_country ,uni_name=uni_name, uni_rank=uni_rank, uni_city=uni_city, programs=programs, program_ids=ids )


@app.route('/search_domain',methods = ['POST', 'GET'])
def search_domain():
if request.method == 'POST':
domain = request.form['domain']
result = conn.execute("SELECT * FROM programs_by_unis WHERE Msc like'%%"+domain+"%%'").fetchall()
#result = conn.execute("SELECT * FROM University WHERE universityID='" + uni +"'").fetchall()

programs = [None] *len(result)
program_plus_uni=[None] *len(result)
uni_id=[None] *len(result)
temp_ids = [None] * len(result)
ids = [None] * len(result)


#parse uni_programs data
for msc in range(len(result)):
programs[msc]=result[msc].Msc
program_plus_uni[msc]=programs[msc]+" at "+ result[msc].University
uni_id[msc]=result[msc].universityID

for program_ids in range(len(result)):
join_dept_program="SELECT Program.name, Department.university_id, Program.programID FROM postgradb.Program join postgradb.Department on department_id= departmentID"
program_name_to_id="SELECT q1.programID FROM ("+join_dept_program+") as q1 where q1.university_id='"+uni_id[program_ids]+"' and q1.name like '%%"+domain+"%%'"
temp_ids[program_ids]= conn.execute(program_name_to_id).first()

for i in range(len(result)):
ids[i]=(temp_ids[i][0])


print(type(program_plus_uni))
#print(" !!!!!!!!!!!!!!!!!!!!!!! \n"+ result[0].Msc)
return render_template('domain_programs.html', programs=program_plus_uni, program_ids=ids )
#return redirect(url_for('domains', name=result[0].universityID))



@app.route('/motivation_page', methods=['GET'])
def motivation_page():
return render_template('motivation.html')

@app.route('/developers', methods=['GET'])
def developers():
return render_template('developers.html')

@app.route('/programs/<program>', methods=['GET'])
def programs(program):
program = conn.execute("SELECT * FROM Program WHERE programID='" + program +"'").fetchall()


#parse program data
program_name=program[0].name
duration=program[0].duration
num_of_students=program[0].number_of_students
deadline=program[0].applications_deadline
fees=program[0].fees
description=program[0].description
attendancy=program[0].attendancy

print(program_name)

#get Univeristy from Department table
join_dept_program="SELECT Department.university_id, Program.programID FROM postgradb.Program join postgradb.Department on department_id= departmentID"

query="select q1.university_id from (%s) as q1 where q1.programID='%s'" %(join_dept_program, program[0].programID)
program_university=conn.execute(query).first()

uni_id= program_university[0]

uni_query="SELECT name,city FROM postgradb.University where universityID='%s'; "%(uni_id)
uni=conn.execute(uni_query).first()

uni_name=uni[0]
uni_city=uni[1]


#print(program_name)
return render_template('program.html', prog_name=program_name, dur=duration, num_of_students=num_of_students, deadline=deadline , fees=fees, description=description , uni_name=uni_name, uni_city=uni_city, attendancy=attendancy)



if __name__ == '__main__':
app.run(debug = True)
Loading

0 comments on commit 30574f0

Please sign in to comment.