Skip to content

Commit

Permalink
Aggiunta dashboard Admin
Browse files Browse the repository at this point in the history
  • Loading branch information
giuseppericcio committed Aug 25, 2022
1 parent efec63c commit 9b33c72
Show file tree
Hide file tree
Showing 35 changed files with 8,393 additions and 0 deletions.
2 changes: 2 additions & 0 deletions data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## Dati
In questa directory sarà presente il dataset di progetto e altri file utili per la preparazione del dataset.
5,435 changes: 5,435 additions & 0 deletions data/data.csv

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions data/data_preparation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## Preparazione dei dati
In questa directory saranno presenti statistiche, immagini, text utili sui dati.
106 changes: 106 additions & 0 deletions data/data_preparation/data_preparation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#######################################
# 4.3 Preparazione dei dati
#######################################

# Librerie utili per l'analisi dei dati
import pandas as pd
import numpy as np
import matplotlib
import seaborn as sns
from numpy.random.mtrand import seed

# Configurazione dello stile dei grafici
sns.set(context='notebook', style='darkgrid', palette='colorblind', font='sans-serif', font_scale=1, rc=None)
matplotlib.rcParams['figure.figsize'] =[8,8]
matplotlib.rcParams.update({'font.size': 15})
matplotlib.rcParams['font.family'] = 'sans-serif'


# Configurazione del dataset e suddivisione dei dati in training e test set
def data_split(data, ratio):
np.random.seed(42)
shuffled = np.random.permutation(len(data))
test_set_size = int(len(data) * ratio)
test_indices = shuffled[:test_set_size]
train_indices = shuffled[test_set_size:]
return data.iloc[train_indices], data.iloc[test_indices]

# main
if __name__== "__main__":

# Lettura dei dati e suddivisione dei dati con ratio 0.2
covid = pd.read_csv('data/data.csv')
train, test = data_split(covid, 0.2)
X_train = train[['Breathing Problem', 'Fever', 'Dry Cough', 'Sore throat',
'Running Nose', 'Asthma', 'Chronic Lung Disease', 'Headache',
'Heart Disease', 'Diabetes', 'Hyper Tension', 'Fatigue ',
'Gastrointestinal ', 'Abroad travel', 'Contact with COVID Patient',
'Attended Large Gathering', 'Visited Public Exposed Places',
'Family working in Public Exposed Places', 'Wearing Masks',
'Sanitization from Market']].to_numpy()

X_test = test[['Breathing Problem', 'Fever', 'Dry Cough', 'Sore throat',
'Running Nose', 'Asthma', 'Chronic Lung Disease', 'Headache',
'Heart Disease', 'Diabetes', 'Hyper Tension', 'Fatigue ',
'Gastrointestinal ', 'Abroad travel', 'Contact with COVID Patient',
'Attended Large Gathering', 'Visited Public Exposed Places',
'Family working in Public Exposed Places', 'Wearing Masks',
'Sanitization from Market']].to_numpy()

Y_train = train[['COVID-19']].to_numpy().reshape(4348,)
Y_test = test[['COVID-19']].to_numpy().reshape(1086,)

# Stampa delle informazioni del dataframe, inclusi l'indice dtype e le colonne, i valori non null e l'utilizzo della memoria.
# Scrittura delle informazioni su file.txt
with open('data/data_preparation/info.txt', 'w') as f:
covid.info(buf=f)

# Genera statistiche descrittive
covid.describe().to_csv("data/data_preparation/dataset_statics.csv") # salvataggio su un file.csv per renderlo leggibile


## 4.3.1 Pulizia dei dati ##
# Verifica dei dati mancanti
missing_values=covid.isnull().sum() # valori mancanti
percent_missing = covid.isnull().sum()/covid.shape[0]*100 # valori mancanti %
value = {
'missing_values ':missing_values,
'percent_missing %':percent_missing
}
frame=pd.DataFrame(value)
frame.to_csv('data/data_preparation/missing_value.csv') # salvataggio su un file.csv per renderlo leggibile



## 4.3.2 Visualizzazione dei dati ##
# - Il codice è commentato per evitare la sovrascrittura dei file -

# COVID-19
# sns_plot = sns.countplot(x='COVID-19', data=covid)
# figure = sns_plot.get_figure()
# figure.savefig('data/data_preparation/data_viz/COVID-19.png', dpi = 400)

# Breathing Problem
# sns_breathing = sns.countplot(x='Breathing Problem',hue='COVID-19',data=covid)
# figure1 = sns_breathing.get_figure()
# figure1.savefig('data/data_preparation/data_viz/BreathingProblem.png', dpi = 400)

# Fever
# sns_fever = sns.countplot(x='Fever', hue='COVID-19', data=covid)
# figure2 = sns_fever.get_figure()
# figure2.savefig('data/data_preparation/data_viz/Fever.png', dpi = 400)

# Dry Cough
# sns_dry = sns.countplot(x='Dry Cough',hue='COVID-19',data=covid)
# figure3 = sns_dry.get_figure()
# figure3.savefig('data/data_preparation/data_viz/dry.png', dpi = 400)

# Sore Throat
# sns_sore = sns.countplot(x='Sore throat',hue='COVID-19',data=covid)
# figure4 = sns_sore.get_figure()
# figure4.savefig('data/data_preparation/data_viz/sore.png', dpi = 400)





Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/data_preparation/data_viz/COVID-19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/data_preparation/data_viz/Fever.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/data_preparation/data_viz/dry.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/data_preparation/data_viz/sore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions data/data_preparation/dataset_statics.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
,Breathing Problem,Fever,Dry Cough,Sore throat,Running Nose,Asthma,Chronic Lung Disease,Headache,Heart Disease,Diabetes,Hyper Tension,Fatigue ,Gastrointestinal ,Abroad travel,Contact with COVID Patient,Attended Large Gathering,Visited Public Exposed Places,Family working in Public Exposed Places,Wearing Masks,Sanitization from Market,COVID-19
count,5434.0,5434.0,5434.0,5434.0,5434.0,5434.0,5434.0,5434.0,5434.0,5434.0,5434.0,5434.0,5434.0,5434.0,5434.0,5434.0,5434.0,5434.0,5434.0,5434.0,5434.0
mean,0.6661759293338241,0.7863452337136547,0.7926021347073978,0.7274567537725433,0.5432462274567538,0.4626426205373574,0.47202797202797203,0.5034965034965035,0.4642988590357011,0.4762605815237394,0.49006256900993744,0.5191387559808612,0.4694516010305484,0.45104895104895104,0.5016562384983437,0.4619065145380935,0.5189547294810453,0.41626794258373206,0.0,0.0,0.8065881486934119
std,0.4716211327739574,0.4099235665965471,0.40548026751388566,0.44530878904756294,0.49817209342489355,0.4986483574853146,0.4992628934027898,0.5000337861645077,0.4987696953792399,0.4994820831364206,0.4999472415983911,0.49967955300634165,0.4991118498366407,0.49764381725600054,0.5000432695898289,0.4985926537423099,0.4996865689546946,0.49298444924353374,0.0,0.0,0.39500939378839356
min,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0
25%,0.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0
50%,1.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,1.0
75%,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0
max,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,1.0
28 changes: 28 additions & 0 deletions data/data_preparation/info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 5434 entries, 0 to 5433
Data columns (total 21 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Breathing Problem 5434 non-null int64
1 Fever 5434 non-null int64
2 Dry Cough 5434 non-null int64
3 Sore throat 5434 non-null int64
4 Running Nose 5434 non-null int64
5 Asthma 5434 non-null int64
6 Chronic Lung Disease 5434 non-null int64
7 Headache 5434 non-null int64
8 Heart Disease 5434 non-null int64
9 Diabetes 5434 non-null int64
10 Hyper Tension 5434 non-null int64
11 Fatigue 5434 non-null int64
12 Gastrointestinal 5434 non-null int64
13 Abroad travel 5434 non-null int64
14 Contact with COVID Patient 5434 non-null int64
15 Attended Large Gathering 5434 non-null int64
16 Visited Public Exposed Places 5434 non-null int64
17 Family working in Public Exposed Places 5434 non-null int64
18 Wearing Masks 5434 non-null int64
19 Sanitization from Market 5434 non-null int64
20 COVID-19 5434 non-null int64
dtypes: int64(21)
memory usage: 891.6 KB
22 changes: 22 additions & 0 deletions data/data_preparation/missing_value.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
,missing_values ,percent_missing %
Breathing Problem,0,0.0
Fever,0,0.0
Dry Cough,0,0.0
Sore throat,0,0.0
Running Nose,0,0.0
Asthma,0,0.0
Chronic Lung Disease,0,0.0
Headache,0,0.0
Heart Disease,0,0.0
Diabetes,0,0.0
Hyper Tension,0,0.0
Fatigue ,0,0.0
Gastrointestinal ,0,0.0
Abroad travel,0,0.0
Contact with COVID Patient,0,0.0
Attended Large Gathering,0,0.0
Visited Public Exposed Places,0,0.0
Family working in Public Exposed Places,0,0.0
Wearing Masks,0,0.0
Sanitization from Market,0,0.0
COVID-19,0,0.0
7 changes: 7 additions & 0 deletions init_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import sqlite3

connection = sqlite3.connect('selftestcovid19.db')
with open('selftestcovid19.sql') as f:
connection.executescript(f.read())
connection.commit()
connection.close()
151 changes: 151 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
#################################################
# 4.6 Distribuzione del modello
#################################################
from multiprocessing import connection
import sqlite3
from flask import Flask, render_template, redirect, request
app = Flask(__name__)
import pickle

# Apertura del model.pkl per estrarre i dati passati da myTraining.py
file = open('model.pkl', 'rb')
clf = pickle.load(file)
file.close()

# Applicazione FLASK
@app.route('/', methods=["GET", "POST"])
def covid_checker():
if request.method == "POST":
myDict = request.form
breating = int(myDict['Breathing Problem'])
fever = int(myDict['Fever'])
dry = int(myDict['Dry Cough'])
sore = int(myDict['Sore throat'])
running = int(myDict['Running Nose'])
asthma = int(myDict['Asthma'])
chronic = int(myDict['Chronic Lung Disease'])
headache = int(myDict['Headache'])
heart = int(myDict['Heart Disease'])
diabetes = int(myDict['Diabetes'])
hyper = int(myDict['Hyper Tension'])
fatigue = int(myDict['Fatigue '])
gastrointestinal = int(myDict['Gastrointestinal '])
abroad = int(myDict['Abroad travel'])
contact = int(myDict['Contact with COVID Patient'])
attended = int(myDict['Attended Large Gathering'])
visited = int(myDict['Visited Public Exposed Places'])
family = int(myDict['Family working in Public Exposed Places'])
wearing = int(myDict['Wearing Masks'])
sanitization = int(myDict['Sanitization from Market'])
# Inferenza
inputFeatures = [breating, fever, dry, sore, running, asthma, chronic, headache,
heart, diabetes, hyper, fatigue, gastrointestinal, abroad, contact,
attended, visited, family, wearing, sanitization]
infProb =clf.predict_proba([inputFeatures])[0][1]

# Verifica del risultato
if infProb >= 0 and infProb <= 0.50:
str1 = " Pertanto la tua situazione non desta preoccupazione verso l'infezione al SARS-CoV-2 (COVID-19). \
Se comunque la preoccupazione sussiste è bene chiamare il proprio medico di fiducia/famiglia per informazioni \
più dettagliate."
return render_template('show.html', inf = round((infProb*100), 0), text = str1)
elif infProb > 0.50 and infProb <= 0.75:
str2 = " Pertanto la tua situazione è dubbia, riprova a fare il test oppure chiama il tuo medico di famiglia, \
il tuo pediatra o la guardia medica per avere informazioni più dettagliate. Prenota un tampone RAPIDO presso una farmacia \
nei pressi della tua zona."
return render_template('showRapido.html', inf = round((infProb*100), 0), text = str2)
elif infProb > 0.75 and infProb <= 1:
str3 = " Pertanto la tua situazione suscita preoccupazione e per il test sei stato infettato dal SARS-CoV-2 (COVID-19). \
Tuttavia, recati SOLO in farmacia per la prenotazione di un tampone MOLECOLARE e/o chiami al telefono il tuo medico di famiglia, \
il tuo pediatra o la guardia medica. Oppure chiami il Numero Verde regionale oppure ancora al Numero di Pubblica utilità: 1500."
return render_template('showMolecolare.html', inf = round((infProb*100), 0), text = str3)
return render_template('index.html')

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

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

@app.route('/dashboardAdmin', methods=["GET", "POST"])
def dashAdmin():
connection = sqlite3.connect('selftestcovid19.db')
connection.row_factory = sqlite3.Row
farmacie = connection.execute('SELECT * FROM Farmacie').fetchall()
connection.close()
return render_template('dashboardAdmin.html', farmacie=farmacie)

@app.route('/creaFarmacia', methods=["GET", "POST"])
def creaFarmacia():
if request.method == "POST":
NomeFarmacia = request.form['NomeFarmacia']
Citta = request.form['Citta']
CAP = request.form['CAP']
Email = request.form['Email']
PWD = request.form['PWD']
connection = sqlite3.connect('selftestcovid19.db')
connection.row_factory = sqlite3.Row
connection.execute('INSERT INTO Farmacie (NomeFarmacia, Citta, CAP, Email, PWD) VALUES (?,?,?,?,?)', (NomeFarmacia,Citta,CAP,Email,PWD))
connection.commit()
connection.close()
return redirect('/dashboardAdmin')
return render_template('creaFarmacia.html')

@app.route('/ricercaFarmacia', methods=["GET", "POST"])
def ricercaFarmacia():
if request.method == "POST":
Citta = request.form['Citta']
CAP = request.form['CAP']
connection = sqlite3.connect('selftestcovid19.db')
connection.row_factory = sqlite3.Row
farmacie = connection.execute('SELECT * FROM Farmacie WHERE (Citta = ? OR CAP = ?)', (Citta,CAP)).fetchall()
connection.close()
return render_template('/listaFarmacie.html', farmacie=farmacie)
return render_template('ricercaFarmacia.html')

@app.route('/modificaFarmacia', methods=["GET", "POST"])
def modificaFarmacia():
connection = sqlite3.connect('selftestcovid19.db')
connection.row_factory = sqlite3.Row
farmacie = connection.execute('SELECT * FROM Farmacie').fetchall()
connection.close()
return render_template('modificaFarmacia.html',farmacie=farmacie)

@app.route('/rimozioneFarmacia', methods=["GET", "POST"])
def rimozioneFarmacia():
connection = sqlite3.connect('selftestcovid19.db')
connection.row_factory = sqlite3.Row
farmacie = connection.execute('SELECT * FROM Farmacie').fetchall()
connection.close()
return render_template('rimozioneFarmacia.html',farmacie=farmacie)

@app.route('/<int:ID>/rimuoviFarmacia', methods=["POST"])
def rimuoviFarmacia(ID):
connection = sqlite3.connect('selftestcovid19.db')
connection.row_factory = sqlite3.Row
farmacie = connection.execute('DELETE FROM Farmacie WHERE ID = ?', (ID,))
connection.commit()
connection.close()
return redirect('/dashboardAdmin')

@app.route('/<int:ID>/aggiornaFarmacia', methods=["POST"])
def aggiornaFarmacia(ID):
if request.method == "POST":
NomeFarmacia = request.form['NomeFarmacia']
Citta = request.form['Citta']
CAP = request.form['CAP']
Email = request.form['Email']
PWD = request.form['PWD']
connection = sqlite3.connect('selftestcovid19.db')
connection.row_factory = sqlite3.Row
farmacie = connection.execute('UPDATE Farmacie SET NomeFarmacia = ?, Citta = ?, CAP = ?, Email = ?, PWD = ? WHERE ID = ?', (NomeFarmacia,Citta,CAP,Email,PWD,ID))
connection.commit()
connection.close()
return redirect('/dashboardAdmin')
return redirect('/dashboardAdmin')

# main
if __name__=="__main__":
app.run(debug=True)
Binary file added model.pkl
Binary file not shown.
Binary file removed momentaneo.zip
Binary file not shown.
Loading

0 comments on commit 9b33c72

Please sign in to comment.