Campus Connect Projects
Campus Connect Projects
Campus Connect Projects
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
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()
Software Used:
Oracle 12c version
Tables:
1.users:
3.likes
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;
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;
11. Display pictures with "London" in their caption. Do case insensitive search.
select pictureid from picture where lower(caption)=lower('”London”');
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]');
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()
print("pictureid")
for p in picid:
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.
Software used:
Database: oracle 12c
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
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:
Customers can open a Fixed Deposit (FD) account with 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
2.loans
Views
1.accounts_fd
2.accounts_loans
sequences
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.
Thus these projects helped a lot in understanding the core concepts of python and
database.
Thank You