-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filling DB with groups Fixed adding groups Fixed adding tuteurs not working
- Loading branch information
Showing
3 changed files
with
187 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,106 +1,116 @@ | ||
import sqlite3 | ||
|
||
|
||
def createDB(relEnabled = False, feedbackEnabled = False): | ||
"""Create data storage in data.db""" | ||
connectDB = sqlite3.connect("data.db") | ||
cursor = connectDB.cursor() | ||
cursor.execute("""CREATE TABLE IF NOT EXISTS 'group'( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, | ||
label TEXT NOT NULL, | ||
level INT NOT NULL | ||
)""") | ||
connectDB.commit() | ||
cursor.execute("""CREATE TABLE IF NOT EXISTS 'tuteur'( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, | ||
name TEXT NOT NULL, | ||
surname TEXT NOT NULL, | ||
groupid INTEGER NOT NULL, | ||
freeon TEXT NOT NULL, | ||
subject TEXT NOT NULL, | ||
FOREIGN KEY (groupid) REFERENCES 'group'(id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED | ||
) | ||
""") | ||
cursor.execute("""CREATE TABLE IF NOT EXISTS 'tutore'( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, | ||
name TEXT NOT NULL, | ||
surname TEXT NOT NULL, | ||
groupid INTEGER NOT NULL, | ||
freeon TEXT NOT NULL, | ||
subject TEXT NOT NULL, | ||
FOREIGN KEY (groupid) REFERENCES 'group'(id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED | ||
)""") | ||
connectDB.commit() | ||
if relEnabled: | ||
cursor.execute("""CREATE TABLE IF NOT EXISTS relation( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, | ||
tuteurid INTEGER NOT NULL, | ||
tutoreid INTEGER NOT NULL, | ||
lessonsnumber INT, | ||
time TEXT NOT NULL, | ||
subject TEXT NOT NULL, | ||
feedbackid INTEGER, | ||
FOREIGN KEY (tuteurid) REFERENCES 'tuteur'(id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED, | ||
FOREIGN KEY (tutoreid) REFERENCES 'tutore'(id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED, | ||
FOREIGN KEY (feedbackid) REFERENCES 'retour'(id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED | ||
)""") | ||
if feedbackEnabled: | ||
cursor.execute("""CREATE TABLE IF NOT EXISTS retour( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, | ||
tuteurid INTEGER NOT NULL, | ||
tutoreid INTEGER NOT NULL, | ||
subject TEXT NOT NULL, | ||
time TEXT NOT NULL, | ||
efficiencyscore INT NOT NULL, | ||
socialscore INT NOT NULL, | ||
commentary TEXT, | ||
FOREIGN KEY (tuteurid) REFERENCES 'tuteur'(id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED, | ||
FOREIGN KEY (tutoreid) REFERENCES 'tutore'(id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED | ||
) | ||
""") | ||
connectDB.commit() | ||
connectDB.close() | ||
return | ||
|
||
|
||
def createRelTable(): | ||
connectDB = sqlite3.connect("data.db") | ||
cursor = connectDB.cursor() | ||
cursor.execute("""CREATE TABLE IF NOT EXISTS relation( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, | ||
tuteurid INTEGER NOT NULL, | ||
tutoreid INTEGER NOT NULL, | ||
lessonsnumber INT, | ||
time TEXT NOT NULL, | ||
subject TEXT NOT NULL, | ||
feedbackid INTEGER, | ||
FOREIGN KEY (tuteurid) REFERENCES 'tuteur'(id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED, | ||
FOREIGN KEY (tutoreid) REFERENCES 'tutore'(id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED, | ||
FOREIGN KEY (feedbackid) REFERENCES 'retour'(id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED | ||
)""") | ||
cursor.close() | ||
connectDB.commit() | ||
connectDB.close() | ||
return | ||
|
||
|
||
def createFeedbackTable(): | ||
connectDB = sqlite3.connect("data.db") | ||
cursor = connectDB.cursor() | ||
cursor.execute("""CREATE TABLE IF NOT EXISTS retour( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, | ||
tuteurid INTEGER NOT NULL, | ||
tutoreid INTEGER NOT NULL, | ||
subject TEXT NOT NULL, | ||
time TEXT NOT NULL, | ||
efficiencyscore INT NOT NULL, | ||
socialscore INT NOT NULL, | ||
commentary TEXT, | ||
FOREIGN KEY (tuteurid) REFERENCES 'tuteur'(id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED, | ||
FOREIGN KEY (tutoreid) REFERENCES 'tutore'(id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED | ||
) | ||
""") | ||
cursor.close() | ||
connectDB.commit() | ||
connectDB.close() | ||
import sqlite3 | ||
CoreLibs = __import__("fr-Xabi08-CAPAlgorythmCore", globals(), locals(), ["groupes"],0) | ||
|
||
|
||
def createDB(relEnabled = False, feedbackEnabled = False): | ||
"""Create data storage in data.db""" | ||
connectDB = sqlite3.connect("data.db") | ||
cursor = connectDB.cursor() | ||
cursor.execute("""CREATE TABLE IF NOT EXISTS 'group'( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, | ||
label TEXT NOT NULL, | ||
level INT NOT NULL | ||
)""") | ||
connectDB.commit() | ||
cursor.execute("""CREATE TABLE IF NOT EXISTS 'tuteur'( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, | ||
name TEXT NOT NULL, | ||
surname TEXT NOT NULL, | ||
groupid INTEGER NOT NULL, | ||
freeon TEXT NOT NULL, | ||
subject TEXT NOT NULL, | ||
FOREIGN KEY (groupid) REFERENCES 'group'(id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED | ||
) | ||
""") | ||
cursor.execute("""CREATE TABLE IF NOT EXISTS 'tutore'( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, | ||
name TEXT NOT NULL, | ||
surname TEXT NOT NULL, | ||
groupid INTEGER NOT NULL, | ||
freeon TEXT NOT NULL, | ||
subject TEXT NOT NULL, | ||
FOREIGN KEY (groupid) REFERENCES 'group'(id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED | ||
)""") | ||
connectDB.commit() | ||
if relEnabled: | ||
cursor.execute("""CREATE TABLE IF NOT EXISTS relation( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, | ||
tuteurid INTEGER NOT NULL, | ||
tutoreid INTEGER NOT NULL, | ||
lessonsnumber INT, | ||
time TEXT NOT NULL, | ||
subject TEXT NOT NULL, | ||
feedbackid INTEGER, | ||
FOREIGN KEY (tuteurid) REFERENCES 'tuteur'(id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED, | ||
FOREIGN KEY (tutoreid) REFERENCES 'tutore'(id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED, | ||
FOREIGN KEY (feedbackid) REFERENCES 'retour'(id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED | ||
)""") | ||
if feedbackEnabled: | ||
cursor.execute("""CREATE TABLE IF NOT EXISTS retour( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, | ||
tuteurid INTEGER NOT NULL, | ||
tutoreid INTEGER NOT NULL, | ||
subject TEXT NOT NULL, | ||
time TEXT NOT NULL, | ||
efficiencyscore INT NOT NULL, | ||
socialscore INT NOT NULL, | ||
commentary TEXT, | ||
FOREIGN KEY (tuteurid) REFERENCES 'tuteur'(id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED, | ||
FOREIGN KEY (tutoreid) REFERENCES 'tutore'(id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED | ||
) | ||
""") | ||
connectDB.commit() | ||
fillGroupTable(connectDB) | ||
connectDB.close() | ||
return | ||
|
||
|
||
def createRelTable(): | ||
connectDB = sqlite3.connect("data.db") | ||
cursor = connectDB.cursor() | ||
cursor.execute("""CREATE TABLE IF NOT EXISTS relation( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, | ||
tuteurid INTEGER NOT NULL, | ||
tutoreid INTEGER NOT NULL, | ||
lessonsnumber INT, | ||
time TEXT NOT NULL, | ||
subject TEXT NOT NULL, | ||
feedbackid INTEGER, | ||
FOREIGN KEY (tuteurid) REFERENCES 'tuteur'(id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED, | ||
FOREIGN KEY (tutoreid) REFERENCES 'tutore'(id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED, | ||
FOREIGN KEY (feedbackid) REFERENCES 'retour'(id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED | ||
)""") | ||
cursor.close() | ||
connectDB.commit() | ||
connectDB.close() | ||
return | ||
|
||
|
||
def createFeedbackTable(): | ||
connectDB = sqlite3.connect("data.db") | ||
cursor = connectDB.cursor() | ||
cursor.execute("""CREATE TABLE IF NOT EXISTS retour( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, | ||
tuteurid INTEGER NOT NULL, | ||
tutoreid INTEGER NOT NULL, | ||
subject TEXT NOT NULL, | ||
time TEXT NOT NULL, | ||
efficiencyscore INT NOT NULL, | ||
socialscore INT NOT NULL, | ||
commentary TEXT, | ||
FOREIGN KEY (tuteurid) REFERENCES 'tuteur'(id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED, | ||
FOREIGN KEY (tutoreid) REFERENCES 'tutore'(id) ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED | ||
) | ||
""") | ||
cursor.close() | ||
connectDB.commit() | ||
connectDB.close() | ||
return | ||
|
||
|
||
def fillGroupTable(DB): | ||
baseGroups = [["2E1","2E2","2E3","2E4","2E5","2E6"],["1TC1","1TC2","1TC3","1TC4","1TC5"],["TE1","TE2","TE3","TE4"]] | ||
for i in range(len(baseGroups)): | ||
for j in range(len(baseGroups[i])): | ||
CoreLibs.groupes.addGroup(baseGroups[i][j], len(baseGroups)-i,DB) | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,35 @@ | ||
CoreLibs = __import__("fr-Xabi08-CAPAlgorythmCore", globals(), locals(), ["utils"],0) | ||
|
||
def groupGetLVL(gname): | ||
MainDB = CoreLibs.utils.MainDB | ||
cursor = MainDB.cursor() | ||
cursor.execute("""SELECT level FROM 'group' WHERE label = ?""",(gname,)) | ||
results = cursor.fetchall() | ||
cursor.close() | ||
return results | ||
|
||
|
||
def addGroup(gname,level): | ||
MainDB = CoreLibs.utils.MainDB | ||
cursor = MainDB.cursor() | ||
cursor.execute("""INSERT INTO group (label,level) VALUES (?,?)""",(gname,level)) | ||
MainDB.commit() | ||
return cursor.close() | ||
|
||
|
||
def getGroupByName(gname): | ||
MainDB = CoreLibs.utils.MainDB | ||
cursor = MainDB.cursor() | ||
cursor.execute("""SELECT * FROM 'group' WHERE label = ?""",(gname,)) | ||
results = cursor.fetchall() | ||
cursor.close() | ||
return results | ||
|
||
|
||
def rmGroup(gid): | ||
MainDB = CoreLibs.utils.MainDB | ||
cursor = MainDB.cursor() | ||
cursor.execute("""DELETE FROM group WHERE id = ?""",(gid,)) | ||
MainDB.commit() | ||
CoreLibs = __import__("fr-Xabi08-CAPAlgorythmCore", globals(), locals(), ["utils"],0) | ||
|
||
def groupGetLVL(gname): | ||
MainDB = CoreLibs.utils.MainDB | ||
cursor = MainDB.cursor() | ||
cursor.execute("""SELECT level FROM 'group' WHERE label = ?""",(gname,)) | ||
results = cursor.fetchall() | ||
cursor.close() | ||
return results | ||
|
||
|
||
def addGroup(gname,level, MainDB = None): | ||
if MainDB == None: | ||
MainDB = CoreLibs.utils.MainDB | ||
cursor = MainDB.cursor() | ||
cursor.execute("""INSERT INTO 'group' (label,level) VALUES (?,?)""",(gname,level)) | ||
MainDB.commit() | ||
return cursor.close() | ||
|
||
|
||
def getGroupByName(gname): | ||
MainDB = CoreLibs.utils.MainDB | ||
cursor = MainDB.cursor() | ||
cursor.execute("""SELECT * FROM 'group' WHERE label = ?""",(gname,)) | ||
results = cursor.fetchall() | ||
cursor.close() | ||
return results | ||
|
||
|
||
def rmGroup(gid): | ||
MainDB = CoreLibs.utils.MainDB | ||
cursor = MainDB.cursor() | ||
cursor.execute("""DELETE FROM 'group' WHERE id = ?""",(gid,)) | ||
MainDB.commit() | ||
return cursor.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,39 @@ | ||
CoreLibs = __import__("fr-Xabi08-CAPAlgorythmCore", globals(), locals(), ["utils"],0) | ||
|
||
|
||
creneaux = CoreLibs.utils.creneaux | ||
|
||
|
||
def deleteTuteur(name, surname, groupid): | ||
MainDB = CoreLibs.utils.MainDB | ||
cursor = MainDB.cursor() | ||
delete_rq="DELETE FROM 'tuteur' WHERE name = '"+name+"' AND surname = '"+surname+"' AND groupid = "+str(groupid) | ||
cursor.execute(delete_rq) | ||
MainDB.commit() | ||
cursor.close() | ||
return | ||
|
||
|
||
def addTuteur(name, surname, groupid,parsedFreetime,parsedSubjects): | ||
MainDB = CoreLibs.utils.MainDB | ||
cursor = MainDB.cursor() | ||
cursor.execute("""INSERT INTO tuteur (name,surname,group,freeon,subject) VALUES (?,?,?,?,?)""",(name,surname,groupid,parsedFreetime,parsedSubjects)) | ||
MainDB.commit() | ||
return cursor.close() | ||
|
||
|
||
def findTuteur(groupLVL,parsedFreetime,parsedSubjects): | ||
results = [] | ||
MainDB = CoreLibs.utils.MainDB | ||
cursor = MainDB.cursor() | ||
freetimes = [i.replace("_","").replace("%","") for i in parsedFreetime] | ||
creneauxTXT = [CoreLibs.utils.creneaux[i.replace("_","").replace("%","")] for i in parsedFreetime] | ||
subjects = [i.replace("_","").replace("%","") for i in parsedSubjects] | ||
for i in parsedFreetime: | ||
for j in parsedSubjects: | ||
cursor.execute("""SELECT 'tuteur'.id,name, surname FROM 'tuteur' INNER JOIN 'group' ON 'tuteur'.groupid = 'group'.id WHERE 'group'.level <= ? AND freeon LIKE ? AND subject LIKE ?""",(groupLVL,i,j)) | ||
tmp = cursor.fetchall() | ||
results.append(tmp) | ||
print(i,j,tmp) | ||
cursor.close() | ||
CoreLibs = __import__("fr-Xabi08-CAPAlgorythmCore", globals(), locals(), ["utils"],0) | ||
|
||
|
||
creneaux = CoreLibs.utils.creneaux | ||
|
||
|
||
def deleteTuteur(name, surname, groupid): | ||
MainDB = CoreLibs.utils.MainDB | ||
cursor = MainDB.cursor() | ||
delete_rq="DELETE FROM 'tuteur' WHERE name = '"+name+"' AND surname = '"+surname+"' AND groupid = "+str(groupid) | ||
cursor.execute(delete_rq) | ||
MainDB.commit() | ||
cursor.close() | ||
return | ||
|
||
|
||
def addTuteur(name, surname, groupid,parsedFreetime,parsedSubjects): | ||
MainDB = CoreLibs.utils.MainDB | ||
cursor = MainDB.cursor() | ||
cursor.execute("""INSERT INTO tuteur (name,surname,groupid,freeon,subject) VALUES (?,?,?,?,?)""",(name,surname,groupid,parsedFreetime,parsedSubjects)) | ||
MainDB.commit() | ||
return cursor.close() | ||
|
||
|
||
def findTuteur(groupLVL,parsedFreetime,parsedSubjects): | ||
results = [] | ||
MainDB = CoreLibs.utils.MainDB | ||
cursor = MainDB.cursor() | ||
freetimes = [i.replace("_","").replace("%","") for i in parsedFreetime] | ||
creneauxTXT = [CoreLibs.utils.creneaux[i.replace("_","").replace("%","")] for i in parsedFreetime] | ||
subjects = [i.replace("_","").replace("%","") for i in parsedSubjects] | ||
for i in parsedFreetime: | ||
for j in parsedSubjects: | ||
cursor.execute("""SELECT 'tuteur'.id,name, surname FROM 'tuteur' INNER JOIN 'group' ON 'tuteur'.groupid = 'group'.id WHERE 'group'.level <= ? AND freeon LIKE ? AND subject LIKE ?""",(groupLVL,i,j)) | ||
tmp = cursor.fetchall() | ||
results.append(tmp) | ||
print(i,j,tmp) | ||
cursor.close() | ||
return {"creneaux":freetimes,"subjects":subjects,"creneauxTXT":creneauxTXT,"results":results} |