Campus Connect Projects

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 27

Campus Connect

Projects
Faculty In charge:

Mrs. Santhiya M
MVJCE

Submitted by:
Ashita Aggarwal-1MJ16CS026
Anand Kumar Singh-1MJ16CS015
Amritha Sharma R-1MJ16CS014

Class-6-A ‘CSE’
MVJCE
Index
1. Project 1: Word Scrambling

2. Project 2: InstaDB

3. Project 3: InstaDB Integration

4. Project 4: Bank Accounts

5. Project 5: Bank Accounts Analysis

6. Conclusion
Project 1: Word Scrambling
Description:
The word scrambling project is used to scramble the words of length more than 3 randomly using the python
module random. The words are there in a file which on execution creates a new file having the scrambled output.

Software Requirements:
Eclipse-pydev

Code:
import random
name=input("Enter the file name:\n")
fp1=open(name+".txt","r")
fp2=open(name+"Scrambled.txt","w")
l=list()
for line in fp1:
l=line.split()
for word in l:
if(len(word)<=3):
fp2.write(word+' ')
elif(word[len(word)-1]==',' or word[len(word)-1]=='!' or word[len(word)-1]=='.'):
sword=word[0]
words=(random.sample(word[1:(len(word)-2)],(len(word)-3)))
sword+=''.join(str(i) for i in words)
sword+=word[len(word)-2]
sword+=word[len(word)-1]
fp2.write(sword+' ')
else:
sword=word[0]
words=(random.sample(word[1:len(word)-1],(len(word)-2)))
sword+=''.join(str(i) for i in words)
sword+=word[len(word)-1]
fp2.write(sword+' ')
fp2.write('\n')
fp1.close()
fp2.close()

Sample Input: Sample output:


Project 2:InstaDB
Description:
The InstaDB project creates a database containing four tables and performs the quiries specified.

Software Used:
Oracle 12c version

Tables:
1.users:

create table users(userid int generated by default on null as identity,


username varchar(30)unique,
firstname varchar(30),
lastname varchar(40),
email varchar(100)unique,
primary key(userid));
2.picture

create table picture(pictureid int generated by default on null as identity,


caption varchar(100),
path varchar(100),
picdate date,
userid int,
primary key(pictureid),
foreign key(userid) references users(userid) on delete cascade);

3.likes

create table likes(pictureid int,


userid int,
primary key(pictureid,userid),
foreign key(userid) references users(userid) on delete cascade,
foreign key(pictureid) references picture(pictureid) on delete cascade);
4.tags

create table tags(pictureid int,


tagname varchar(100),
primary key(pictureid,tagname)
,foreign key(pictureid) references picture(pictureid) on delete cascade);
Database Diagram:

Data:
Users:

Picture:
Likes:

Tags:

Queries
1. Display Picture ids of pictures posted by user id "1"
select pictureid from picture where userid=01;

2. Display captions of pictures posted by "2". Display 'No caption' if caption is not having any value
select caption from picture where userid=02;
3. Which pictures (picture ids) and by which users (user ids) have been posted in last 1 year?
select pictureid,userid from picture where picdate between add_months(sysdate,-12) and sysdate;

4. Which picture/s (picture ids) has received maximum likes?


select pictureid from likes group by pictureid having count(pictureid)=(select max(pictureidcount)from(select
count(pictureid)as pictureidcount from likes group by pictureid));

5. Display all picture ids in descending order of the likes they have got. Also display total no. of likes each picture has
received
select pictureid,count(pictureid)as count from likes group by pictureid order by count(pictureid)desc;

6. Display picture ids of pictures with more than 3 likes?


select pictureid from likes having count(*)>=3 group by pictureid;

7. Who (user id) has liked the most pictures?


select userid from likes group by userid having count(userid)=(select max(useridcount)from(select count(userid)as
useridcount from likes group by userid));
8. Which day of the week users are posting the maximum no. of pictures
SELECT TO_CHAR(picdate, 'DY') day FROM picture group by TO_CHAR(picdate,'DY') having
count(TO_CHAR(picdate,'DY'))=(select max(val) from (select count(TO_CHAR(picdate,'DY')) as val from picture group by
TO_CHAR(picdate,'DY')));

9. Get the count of pictures posted during weekends


select count(pictureid) as count from picture where TO_CHAR(picdate,'DY')='SUN' or TO_CHAR(picdate,'DY')='SAT';

10. Find pictures (picture ids) with more than 3 tags.


select pictureid from tags having count(*)>=3 group by pictureid;

11. Display pictures with "London" in their caption. Do case insensitive search.
select pictureid from picture where lower(caption)=lower('”London”');

12. Which pictures (picture ids) are stored on my "D:" drive?


select pictureid from picture where path like 'D:\%';

13. Display year, pic_id of pictures posted by User id -3 in last 5 years.


select pictureid,extract (year from picdate) as year from picture where userid=03 and picdate between
add_months(sysdate,-60) and sysdate;

14. Display first and last names of all users who have either have an account on gmail or yahoo.
select firstname,lastname from users where email like '_%@yahoo.%' or email like '_%@gmail.%';

15. Add new user with user-name, his first & last name and email.
insert into users(username,firstname,lastname,email)values('jhons','jhon','mathew','[email protected]');

16. Add a like for Picture id 6 by user id 7.


insert into likes(pictureid,userid)values(06,07);

17. Delete all likes done by user id '3'.


Delete from likes where Userid=03;

18. Update last name for user id '9' to 'Kumar'.


update users set lastname='Kumar' where userid=09;
19. Update email address of User "Angella Smith"to [email protected].
update users set email='[email protected]' where firstname='Angella' and lastname='Smith';

20. Add a new tag for "Literature".


insert into tags(pictureid,tagname)values(01,'Literature');

Project 3:InstaDB Integration


Description:
The InstaDB integration is the extension of the project 2 InstaDB. This project performs the advanced queries of by
integrating the database with python. Using the python codes we can establish a connection with the database and
can query the database to get the required output. This is a menu driven program which gives users to chose among
all the options.

Software Used:
Database:Oracle 12c version

Application:Eclipse-pydev

Code:
import cx_Oracle
import datetime as dt
import os

def connection():
conn=cx_Oracle.connect('system/ashita123$$A@localhost/system')
return conn

def maxlikes():
conn=connection()
cursor=conn.cursor()
querystring="select userid from users where username ='system'"
cursor.execute(querystring)
id1=cursor.fetchone()
max1=0
picid=[]
cursor.execute("""select pictureid from picture where userid=:param1""",{'param1':id1[0]})
for pictureid in cursor:
cur=conn.cursor()

cur.execute("""select pictureid from likes where pictureid=:param1""",{'param1':pictureid[0]})


cur.fetchall()
cur.rowcount
if(max1==cur.rowcount):
max1=cur.rowcount
picid.append(pictureid[0])
elif(max1<cur.rowcount):
picid=[]
max1=cur.rowcount
picid.append(pictureid[0])
else:
continue

print("pictureid")
for p in picid:

cur.execute("""select pictureid from likes where pictureid=:param1""",{'param1':p})


for pictureid in cur.fetchmany(1):
print(" ",pictureid[0])
conn.commit()
conn.close()

def minlikes():
conn=connection()
cursor=conn.cursor()
querystring="select userid from users where username ='system'"
cursor.execute(querystring)
id1=cursor.fetchone()
min1=999
picid=[]
cursor.execute("""select pictureid from picture where userid=:param1""",{'param1':id1[0]})
for pictureid in cursor:
cur=conn.cursor()
cur.execute("""select pictureid from likes where pictureid=:param1""",{'param1':pictureid[0]})
cur.fetchall()
cur.rowcount
if(min1==cur.rowcount):
min1=cur.rowcount
picid.append(pictureid[0])
elif(min1>cur.rowcount and cur.rowcount!=0):
picid=[]
min1=cur.rowcount
picid.append(pictureid[0])
else:
continue
print("pictureid")
for p in picid:
cur.execute("""select pictureid from likes where pictureid=:param1""",{'param1':p})
for pictureid in cur.fetchmany(1):
print(" ",pictureid[0])
conn.commit()
conn.close()
def maxliked():
conn=connection()
cursor=conn.cursor()
querystring="select userid from users where username ='system'"
cursor.execute(querystring)
id1=cursor.fetchone()
max1=0
picid=[]
cursor.execute("""select pictureid from picture where userid=:param1""",{'param1':id1[0]})
dit={}
for pictureid in cursor:
cur=conn.cursor()
cur.execute("""select pictureid from likes where pictureid=:param1""",{'param1':pictureid[0]})
cur.fetchall()
picid.append(pictureid[0])

cur2=conn.cursor()
cur2.execute("select userid from users")
for userid in cur2:
u=userid[0]
dit[u]=0
for pic in picid:
cur2=conn.cursor()
cur2.execute("select userid from users")
for userid in cur2:
u=userid[0]
cur=conn.cursor()
cur.execute("""select pictureid from likes where userid=:param1 and pictureid=:param2""",(userid[0],pic))
cur.fetchall()
dit[u]=dit[u]+cur.rowcount
print("userid")
for key,value in sorted(dit.items(), key=lambda item: item[1],reverse=True):
if(max1<=dit[key]):
max1=dit[key]
print(key)

conn.commit()
conn.close()

def musicpic():
conn=connection()
cur2=conn.cursor()
cur2.execute("select pictureid from tags where tagname='music' or tagname='Music'")
for pictureid in cur2:
cur=conn.cursor()
cur.execute("""select path from picture where pictureid=:param1""",({'param1':pictureid[0]}))
for path in cur:
try:
print(path[0])
os.startfile(path[0])

except IOError:
pass
conn.commit()
conn.close()

def populartag():
conn=connection()
cursor=conn.cursor()
max1=0
picid=[]
cursor.execute("select distinct lower(tagname) from tags")
for tagname in cursor:

cur=conn.cursor()
cur.execute("""select * from tags where lower(tagname)=:param1""",{'param1':tagname[0]})
cur.fetchall()
cur.rowcount
if(max1==cur.rowcount):
max1=cur.rowcount
picid.append(tagname[0])
elif(max1<cur.rowcount):
picid=[]
max1=cur.rowcount
picid.append(tagname[0])
else:
continue
print("Most popular Tagname")
for p in picid:
print(p)
conn.commit()
conn.close()

def mostlikeduser():
conn=connection()
cur2=conn.cursor()
dit={}
cur2.execute("select userid from users")
for userid in cur2:
u=userid[0]
dit[u]=0
cur=conn.cursor()
cur.execute("""select pictureid from picture where userid=:param1""",({'param1':userid[0]}))
for pictureid in cur:
cur3=conn.cursor()
cur3.execute("""select pictureid from likes where pictureid=:param1""",({'param1':pictureid[0]}))
cur3.fetchall()
dit[u]=dit[u]+cur3.rowcount
print("userid")
max1=0
for key,value in sorted(dit.items(), key=lambda item: item[1],reverse=True):
if(max1<=dit[key]):
max1=dit[key]
print(key)

conn.commit()
conn.close()

def oldtagging():
conn=connection()
cursor=conn.cursor()
querystring="select userid from users where username ='system'"
cursor.execute(querystring)
today = dt.date.today()
id1=cursor.fetchone()
today2=today-dt.timedelta(days=3*365)
cur=conn.cursor()
tag='Old'
cur.execute("""select pictureid from picture where userid=:param1 and picdate <=:param3""",
({'param1':id1[0],'param3':today2}))
for pictureid in cur:
cur3=conn.cursor()
cur3.execute("""insert into tags values(:param1,:param2)""",(pictureid[0],tag))
print("tags updated")
conn.commit()
conn.close()
def deleteinactive():
conn=connection()
cursor=conn.cursor()
querystring="select userid from users"
cursor.execute(querystring)
today = dt.date.today()
for userid in cursor:
today2=today-dt.timedelta(days=365)
cur=conn.cursor()
cur.execute("""select userid from picture where userid=:param1 and picdate between :param2 and :param3""",
({'param1':userid[0],'param2':today2,'param3':today}))
cur.fetchall()
if(cur.rowcount==0):
cur3=conn.cursor()
cur3.execute("""delete from users where userid=:param1""",({'param1':userid[0]}))
else:
continue
print("users updated")
conn.commit()
conn.close()

while True:
print("Enter your choice\n1.Max likes\n2.Min likes\n3.Who liked most\n4.Music pictures\n5.Popilar tag\n6.Most liked
user\n7.Old tagging\n8.Delete inactive users")
choice=int(input(">>>"))
if choice==1:
maxlikes()
elif(choice==2):
minlikes()
elif(choice==3):
maxliked()
elif(choice==4):
musicpic()
elif(choice==5):
populartag()
elif(choice==6):
mostlikeduser()
elif(choice==7):
oldtagging()
elif(choice==8):
deleteinactive()
else:
print("Invalid choice!coming out of program")
exit(0)

Sample outputs:
Project 4:Bank Accounts
Description:
The project is to develop a banking application for a bank that has multiple customers spread across the country.
Savings Account -Offers interest at the rate of 7.5% per annum on your savings. Maximum 10 withdrawals are
allowed per month. No minimum balance is needed to open or maintain this account.Current Account –No interest
is offered on this account. No limit of on no. of withdrawals. A customer needs to have minimum 5K to open or
maintain this account.

A customer can do following transactions:

1. Deposit and withdraw money in his account/s


2. Transfer money to other accounts
3. Print his account statement for given range of dates

Software used:
Database: oracle 12c

Application: eclipse- pydev

Tables:
1.customer
create table customers(
customer_id number(5) primary key,
first_name varchar2(10),
last_name varchar2(10),
status varchar2(10),
login_attempts number(3),
password varchar2(20));
2.address
create table address(
customer_id number(5),
line1 varchar2(30),
line2 varchar2(30),
city varchar2(30),
state varchar2(30),
pincode number(6),
constraint fk_addr foreign key(customer_id) references customers(customer_id));
3.accounts
create table accounts(
customer_id number(5),
account_no number(5) primary key,
opened_on date,
account_type varchar2(10),
status varchar2(10),
balance number(8),
withdrawals_left number(3),
next_reset_date date,
interest_on date,
constraint fk_acc foreign key(customer_id) references customers(customer_id));
4.transactions
create table transactions(
transaction_id number(5) primary key,
account_no number(5),
type varchar2(10),
amount number(8),
balance number(8),
transaction_date date,
constraint fk_transaction_account_no foreign key(account_no) references accounts(account_no));
5.admin

create table admin(


admin_id number(5),
password varchar2(10));
6.closed_accounts
create table closed_accounts(
account_no number(5),
closed_on date,
constraint fk_closed_acc foreign key(account_no) references accounts(account_no));
Sequences
1. create sequence customer_id_sequence
start with 1
increment by 1
nocycle;
2. create sequence account_no_sequence
start with 1
increment by 1
nocycle
3. create sequence transaction_id_sequence
start with 1
increment by 1
nocycle;
Snapshots:
Option 1:

Option 2:
Option 3:

Option 4:

Sub menu-option 2:
Option 1 option 2
Option 3:

Option 4:

Option 5:
Option 6:

Option 7:

Option 0:

Sub menu -option 3


Project 5:Bank Account Analysis
Description:
The bank account analysis project is the extension of the bank database project . This has additional functionalities
of Fixed deposits and loans.

Customers can open a Fixed Deposit (FD) account with the bank:

Minimum FD balance is Rs.1000 and min deposit term is 12 months.

Customers can avail Loan from the bank:

A Customer can avail more than one loan from the bank. Loan account no. will be linked to the customer-id via
savings account of that customer. Maximum Loan Amount eligible = 2 * balance in Savings account at the time of
availing the loan.

Software Used:
Database : oracle 12c

Application: eclipse-pydev

Tables
Tables from previous project and extra tables are

1.fd

create table fd(


account_no number(5) primary key,
amount number(8),
deposit_term number(5),
constraint fk_fd_acc foreign key(account_no) references accounts(account_no));

2.loans

create table loans(


customer_account_no number(5),
loan_id number(5) primary key,
loan_amount number(8),
repay_term number(5),
constraint fk_loan_acc foreign key(customer_account_no) references accounts(account_no));

Views

1.accounts_fd

create or replace view accounts_fd as


select a.customer_id,a.account_no,fd.amount,fd.deposit_term from accounts a,fd where a.account_no =
fd.account_no;

2.accounts_loans

create or replace view accounts_loans as


select a.customer_id,a.account_no,loans.loan_id,loans.loan_amount,loans.repay_term from accounts a,loans
where a.account_no = loans.customer_account_no;

sequences

create sequence loan_id_sequence

start with 1
increment by 1
nocycle;

Snapshots:
Submenu-option 2
Option 2:
Option 2: 3

Option 8:

Submenu-option 3:
Option2:

Option 5:

Option 9:
Conclusion
The Campus Connect projects were one of the wonderful projects to get the hands
on practice for the database concepts and integration with python.

The scrambling project was useful for the list, dictionary, files and basic concepts in
python. The InstaDB and bank database helped in understanding the relations between
different table and how to create database to answer different queries.

The project 3 of InstaDB integration and project 5 of Bank analysis helped in


integration of database with python and executing advanced queries.

Thus these projects helped a lot in understanding the core concepts of python and
database.

Thank You

You might also like