Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Aaron Bosh Macsimus: Xii - C, Chinmaya Vidyalaya, Kolazhi

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

Aaron Bosh Macsimus

XII -C , CHINMAYA VIDYALAYA, KOLAZHI

Nov 25, 2020


Contents:

1 Certificate 1

2 Acknowledgement 3

3 Project Definition 5

4 Coding 7

5 Requirements 15

6 Screen Shots 17

7 Conclusion 27

8 Bibliography 29

i
Project Definition
3
The COVID-19 pandemic in India is part of the worldwide pandemic of coronavirus disease
2019 (COVID-19) caused by severe acute respiratory syndrome coronavirus 2 (SARS-CoV-
2). The first case of COVID-19 in India, which originated from China, was reported on 30
January 2020. India currently has the largest number of confirmed cases in Asia, and has the
second-highest number of confirmed cases in the world after the United States, with more
than 9 million reported cases of COVID-19 infection and more than 100 thousand deaths.
By mid of 2020, India had approached in position of conducting highest number of daily
tests in the world which subsequently translated into highest number of daily new cases in
world and has sustained highest number of daily cases spike since then.
On 22 March, India observed a 14-hour voluntary public curfew at the insistence of Prime
Minister Narendra Modi. It was followed by mandatory lockdowns in COVID-19 hotspots
and all major cities. Further, on 24 March, the prime minister ordered a nationwide lockdown
for 21 days, affecting the entire 1.3 billion population of India. On 14 April, India extended
the nationwide lockdown till 3 May which was followed by two-week extensions starting 3
and 17 May with substantial relaxations. From 1 June, the government started “unlocking”
the country (barring “containment zones”) in three unlock phases.
The project named as COVID 19 INDIA STATE WISE is to get the latest number of
confirmed, deaths, recovered and active cases of Novel Coronavirus (COVID-19) state wise.
And it uses database named as covid19 created using MySQL and contains a table statistics
which has the following structure:

Table 1: statistics
Field Type Null Key Default
cname varchar(20) NO PRI NULL
confirmed int YES NULL
recovered int YES NULL
deaths int YES NULL
active int YES NULL

5
Aaron Bosh Macsimus

Project has the following features:


1.Create Database:
The function createDb() in the program will create the database covid19 if it is not already
created, and skip the routine otherwise.
2.Open Database:
The function myCon() will establish a connection with MySQL database with proper au-
thentication and open the database covid19 and return reference for this connectivity and
MySQL cursor.
3.Close Database:
The function comit() will remove the established connection with MySQL database.
4.Create Table:
The function createTab() will create the table with table name statistics if it is not already
created with the connectivity established using myCon().
5.Add Record:
The table statistics can be populated using the function addrec() by accepting the values
as input from the corresponding text fileds provided in the dropdown menu. Or otherwise
we can call csvInsert() function to populate table statistics from .csv file. I used the
indiaCovid.csv .csv file that contains the latest details of covid 19 provided in the Internet
in respect of Indian states.
6.Delete Record:
To delete a record from the database, the function deleterec() is used. Using the state
name (cname) we locate the record since it is defined as the primary key in the table and
on successful search the corresponding record can be deleted or otherwise the system will
alert with message Record Not Found.
7.Search Record:
To search a record in the database, the function searchrec() is used. Using the state name
(cname) we search the record since it is defined as the primary key in the table and on
successful search the corresponding record can be deleted or otherwise the system will alert
with message Record Not Found.
8.Update Record:
The function updaterec() is used to update the fields confirmed, recovered and deaths
in the table statistics by locating the record using the field cname declared as primary key
in the table.
9.Display Record:
The entire records in the table statistics can be displayed using the function displayrec().

6 Chapter 3. Project Definition


Coding
4
import mysql.connector as mc
import tkinter as tk
import csv
from tkinter import *
from tkinter import ttk
from tkinter import messagebox, Tk

def create_widgets():
button=Button(text="Open Database",fg="red",command=myCon)
button.grid(row=0,column=0,sticky=W)

button2=Button(text="Close Database",command=comit)
button2.grid(row=0,column=3,sticky=W)

button2=Button(text="Create Database",command=createDb)
button2.grid(row=0,column=4,sticky=W)

button2=Button(text="Create Table",command=createTab)
button2.grid(row=0,column=5,sticky=W)

button2=Button(text="Add Record",command=addrec)
button2.grid(row=0,column=6,sticky=W)

button2=Button(text="Display Record",command=displayrec)
button2.grid(row=0,column=7,sticky=W)

button2=Button(text="Delete Record" ,command=deleterec)


button2.grid(row=0,column=8,sticky=W)

button2=Button(text="Search Record",command=searchrec)
button2.grid(row=0,column=9,sticky=W)
(continues on next page)

7
Aaron Bosh Macsimus

(continued from previous page)

button2=Button(text="Update Record",command=updaterec)
button2.grid(row=0,column=10,sticky=W)

def myCon():
mydb=mc.connect(host='localhost',user='aaron',passwd='Bosh$2346536')
mycur=mydb.cursor()
mycur.execute("use covid19")
return mycur,mydb

def comit():
mycur,mydb=myCon()
mydb.commit()
mycur.close()
mydb.close()

def createDb():
mycur,mydb=myCon()
mycur.execute("CREATE DATABASE IF NOT EXISTS covid19")
mycur.execute("use covid19")

def createTab():
mycur,mydb=myCon()
mycur.execute("create table if not exists statistics(cname varchar(20),
confirmed int, recovered int, deaths int, active int)")

def sqlq():
sql="insert into statistics(cname,confirmed,recovered,deaths,active)
values(%s,%s,%s,%s,%s)"
return sql

def addrec():
mycur,mydb=myCon()
def submit_app():
#csvInsert()
try:
mycur.execute(sqlq(),(e1.get(),e2.get(),e3.get(),
e4.get(),int(e2.get())-int(e3.get())- int(e4.get()),))
mydb.commit()
rt.destroy()
except mc.IntegrityError as e:
messagebox.showinfo("SEARCH DETAILS",
"Record already exists!!!!")
mydb.rollback()
rt.destroy()
(continues on next page)

8 Chapter 4. Coding
Aaron Bosh Macsimus

(continued from previous page)


rt=tk.Tk()
Label(rt, text="ENTER NAME OF THE STATE").grid(row=4,column=0)
Label(rt, text="ENTER NUMBER OF CONFIRMED CASES").grid(row=5,column=0)
Label(rt, text="ENTER NUMBER OF RECOVERED CASES").grid(row=6,column=0)
Label(rt, text="ENTER NUMBER OF DEATHS CASES").grid(row=7,column=0)

e1 = Entry(rt)
e1.grid(row=4,column=1)
e2 = Entry(rt)
e2.grid(row=5,column=1)
e3 = Entry(rt)
e3.grid(row=6,column=1)
e4 = Entry(rt)
e4.grid(row=7,column=1)
Button(rt,text="SUBMIT",width=25,command=submit_app).grid
(row=11,column=0,columnspan=2)
rt.mainloop()

def csvInsert():
mycur,mydb=myCon()
with open('indiaCovid.csv') as f:
reader = csv.DictReader(f, delimiter=',')
for row in reader:
cname = row['cname']
confirmed = row['confirmed']
recovered = row['recovered']
deaths= row['deaths']
active=row['active']
mycur.execute("INSERT INTO statistics (cname,confirmed,
recovered,deaths,active) VALUES
('%s ', '%s ', '%s ', '%s ','%s ')" %
(cname,confirmed,recovered,deaths,active))
mydb.commit()

def displayrec():
global root
root = Tk()
root.title('COVID 19 DETAILS INDIAN STATES')
mycur,mydb=myCon()
mycur.execute('select * from Statistics')
row=mycur.fetchall()
mydb.commit()
treeview=ttk.Treeview(root)
treeview["column"] = ["State","Confirmed","Recovered","Deaths",
"Active"]
(continues on next page)

9
Aaron Bosh Macsimus

(continued from previous page)


treeview["show"] = "headings"
for i in treeview["column"]:
treeview.heading(i, text = i)
for i in range(len(treeview["column"])):
treeview.column('#'+str(i+1), stretch=YES, minwidth=50,
width=120)
treeview.config(height=len(row))
treeview.pack()
index=0
for r in row:
treeview.insert('','end',text=str(index),values=(r[0],r[1],
r[2],r[3],r[4]))
index=+1
root.mainloop()

def deleterec():
mycur,mydb=myCon()
def submitdel():
sql='select * from statistics where cname ="%s "'%(e8.get())
mycur.execute(sql)
rec=mycur.fetchall()
if len(rec)!=0:
messagebox.showinfo("SEARCH DETAILS",
"STATE FOUND HERE")
sql1='delete from statistics where cname ="%s "
'%(e8.get())
mycur.execute(sql1)
mydb.commit()
messagebox.showinfo("DELETE DETAILS",
"ONE RECODE DELETED")
rt.destroy()
return True,rec
else:
messagebox.showinfo("SEARCH DETAILS",
"RECORD NOT FOUND HERE")
rt.destroy()
return False,"RECORD NOT FOUND HERE"

rt=tk.Tk()
Label(rt,text="STATE NAME").grid(row=10,column=6)
e8 = Entry(rt)
e8.grid(row=10,column=8)
Button(rt,text="SUBMIT",width=17,command=submitdel).grid(row=14,
column=8,columnspan=2)

(continues on next page)

10 Chapter 4. Coding
Aaron Bosh Macsimus

(continued from previous page)


def searchrec():
mycur,mydb=myCon()
def submitsch():
rt=tk.Tk()
sql='select * from statistics where cname ="%s "'%(e7.get())
mycur.execute(sql)
rec=mycur.fetchall()
if len(rec)!=0:
messagebox.showinfo("SEARCH DETAILS",
"RECORD FOUND HERE")
treeview=ttk.Treeview(rt)
treeview["column"] = ["State","Confirmed","Recovered",
"Deaths","Active"]
treeview["show"] = "headings"
for i in treeview["column"]:
treeview.heading(i, text = i)
for i in range(len(treeview["column"])):
treeview.column('#'+str(i+1), stretch=YES,
minwidth=50, width=120)
treeview.config(height=len(rec))
treeview.pack()
index=0
for r in rec:
treeview.insert('','end',text=str(index),
values=(r[0],r[1],r[2],r[3],r[4]))
index=+1
rt1.destroy()
return rec
else:
messagebox.showinfo("SEARCH DETAILS",
"RECORD NOT FOUND HERE")
rt.destroy()
rt1.destroy()
return False,"RECORD NOT FOUND HERE"

rt1=tk.Tk()
Label(rt1,text="ENTER STATE NAME TO SEARCH").grid
(row=10,column=7)
e7 = Entry(rt1)
e7.grid(row=10,column=9)

Button(rt1,text="SUBMIT",width=25,command=submitsch).grid
(row=11,column=7,columnspan=2)
rt1.mainloop()

(continues on next page)

11
Aaron Bosh Macsimus

(continued from previous page)


def updaterec():
mycur,mydb=myCon()
def submitupd():
sql='select * from statistics where cname ="%s "'%(e9.get())
mycur.execute(sql)
rec=mycur.fetchall()
if len(rec)!=0:
messagebox.showinfo("SEARCH DETAILS",
"Record Found Here.\n\n Enter respective field index\n
1. Number of Confirmed cases \n
2. Number of recovered cases\n
3. Number of deaths.")
else:
messagebox.showinfo("SEARCH DETAILS",
"Record Not Found Here!!!!")
rt.destroy()
return
rt=tk.Tk()
rt.focus_force()
Label(rt,text="ENTER STATE NAME").grid(row=10,column=7)
e9 = Entry(rt)
e9.grid(row=10,column=9)
e9.focus_set()
Label(rt,text="ENTER FIELD CHOICE: 1,2,3").grid(row=15,column=7)
e10 = Entry(rt)
e10.grid(row=15,column=9)
Label(rt,text="ENTER VALUE TO BE UPDATED").grid(row=17,column=7)
e11 = Entry(rt)
e11.grid(row=17,column=9)
def submitcor():
sql='select * from statistics where cname ="%s "'%(e9.get())
mycur.execute(sql)
rec=mycur.fetchall()
if e10.get()=="1":
try:
mycur.execute('update Statistics set confirmed=
"%s " where cname="%s "'%(e11.get(),e9.get()))
mydb.commit()
mycur.execute('update Statistics set active=
"%s " where cname="%s "'%(int(e11.get()) -
rec[0][2]-rec[0][3],e9.get()))
mydb.commit()
messagebox.showinfo("UPDATE DETAILS",
"ONE RECORD UPDATED")
except:
(continues on next page)

12 Chapter 4. Coding
Aaron Bosh Macsimus

(continued from previous page)


mydb.rollback()
messagebox.showinfo("SEARCH DETAILS",
"KEY NOT FOUND")
return False,"Record not found"
elif e10.get()=="2":
try:
mycur.execute('update Statistics set recovered=
"%s " where cname="%s "'%(e11.get(),e9.get()))
mycur.execute('update Statistics set active=
"%s " where cname="%s "'%(rec[0][1]-
int(e11.get())- rec[0][3],e9.get()))
mydb.commit()
messagebox.showinfo("UPDATE DETAILS",
"ONE RECORD UPDATED")
except:
mydb.rollback()
messagebox.showinfo("SEARCH DETAILS",
"RECORD NOT FOUND HERE ")
return False,"Record not found"
elif e10.get()=="3":
try:
mycur.execute('update Statistics set deaths=
"%s " where cname="%s "'%(e11.get(),e9.get()))
mycur.execute('update Statistics set active=
"%s " where cname="%s "'%(rec[0][1] -
int(e11.get())- rec[0][2],e9.get()))
mydb.commit()
messagebox.showinfo("UPDATE DETAILS",
"ONE RECORD UPDATED")
except:
mydb.rollback()
messagebox.showinfo("SEARCH DETAILS",
"RECORD NOT FOUND HERE")
return False,"RECORD NOT FOUND HERE"
rt.destroy()
Button(rt,text="SEARCH",width=25,command=submitupd).grid
(row=10,column=10,columnspan=2)
Button(rt,text="UPDATE",width=25,command=submitcor).grid
(row=17,column=10,columnspan=2)
rt.mainloop()

(continues on next page)

13
Aaron Bosh Macsimus

(continued from previous page)


def init():
root=tk.Tk()
frame1 = Frame(root)
root.title('COVID 19 INDIA STATEWISE DETAILS')
root.resizable(width=TRUE, height=TRUE)
root.geometry('{} x{} '.format(780, 350))
return root

def main():
root=init()
create_widgets()
root.mainloop()

if __name__=="__main__":
main()

14 Chapter 4. Coding
Requirements
5
The project is developed in the following environment:
Operating Systems: 64 bit Windows 10.
Database: MySQL 8.0, 64 bit.
MySQL is a fast, easy-to-use RDBMS being used for many small and big businesses. MySQL
is developed, marketed and supported by MySQL AB, which is a Swedish company. It is
becoming so popular because of many good reasons.
It is released under an open-source license. So we have nothing to pay to use it.
It is a very powerful program in its own right. It handles a large subset of the functionality
of the most expensive and powerful database packages.
It uses a standard form of the well-known SQL data language.
MySQL works on many operating systems and with many languages including PYTHON,
PHP, PERL, C, C++, JAVA, etc.
Programming Language: Python 3.7 64 bit
Python was developed by Guido van Rossum in the late eighties and early nineties at the Na-
tional Research Institute for Mathematics and Computer Science in the Netherlands. Python
is a high-level, interpreted, interactive and object-oriented scripting language. Python is de-
signed to be highly readable. It uses English keywords frequently whereas the other languages
use punctuations. It has fewer syntactical constructions than other languages.
Python is Interpreted: Python is processed at runtime by the interpreter. We do not need
to compile your program before executing it.
Python is Interactive: You can actually sit at a Python prompt and interact with the
interpreter directly to write your programs.
Python is Object-Oriented: Python supports Object-Oriented style or technique of program-
ming that encapsulates code within objects.

15
Aaron Bosh Macsimus

GUI: tkinter
GUI: User interfaces are what allows end users to interact with an application. An ap-
plication can be excellent, but without a good user interface, it becomes more difficult to
use, and less enjoyable. It is thus very important to design good user interfaces. Designing
user interface takes place at two different levels: the graphical level and the event level.
Graphical elements of a user interface are called widgets. Widgets are basic components like
buttons, scrollbars, etc. But user interfaces involve more than a collection of widgets placed
in a window. The application must be able to respond to mouse clicks, keyboard actions or
system events such as minimizing the window. For this to happen, events must be associated
to some pieces of code. This process is called binding. The next two chapters will cover each
level in more details, but this chapter will present an overview of Tkinter and explain why
it has become the leading GUI toolkit for the Python language.
Tkinter: is an open source, portable graphical user interface (GUI) library designed for use
in Python scripts. Tkinter relies on the Tk library, the GUI library used by Tcl/Tk and Perl,
which is in turn implemented in C. Thus, Tkinter is implemented using multiple layers.
Tkinter is the standard GUI library for Python. Python when combined with Tkinter pro-
vides a fast and easy way to create GUI applications. Tkinter provides a powerful object-
oriented interface to the Tk GUI toolkit. Creating a GUI application using Tkinter is an
easy task. All we need to do is perform the following steps:
Import the Tkinter module.
Create the GUI application main window.
Add one or more of the above-mentioned widgets to the GUI application.
Enter the main event loop to take action against each event triggered by the user.
LaTeX a document preparation system:
LaTeX is a high-quality typesetting system; it includes features designed for the production
of technical and scientific documentation. LaTeX is the de facto standard for the communi-
cation and publication of scientific documents. LaTeX is available as free software.

16 Chapter 5. Requirements
6
Screen Shots

17
Aaron Bosh Macsimus

18 Chapter 6. Screen Shots


Aaron Bosh Macsimus

19
Aaron Bosh Macsimus

20 Chapter 6. Screen Shots


Aaron Bosh Macsimus

21
Aaron Bosh Macsimus

22 Chapter 6. Screen Shots


Aaron Bosh Macsimus

23
Aaron Bosh Macsimus

24 Chapter 6. Screen Shots


Aaron Bosh Macsimus

25

You might also like