Update Database files

master
tomivt 4 months ago
parent 1ca46f38b8
commit 318e6d481c

BIN
.DS_Store vendored

Binary file not shown.

File diff suppressed because one or more lines are too long

@ -1,28 +1,64 @@
import pandas as pd
# from sqlalchemy import create_engine, text, exc
from numpy import random as rdm
from sqlalchemy import create_engine, text, exc
engine = create_engine("postgresql://kiem@:5432/dbwikifantasy")
try:
co = engine.connect()
print("Connexion à la base de données : dbWikiFantasy\n")
df = pd.read_csv('dataset.csv').drop_duplicates().copy()
print("Affichage des données du fichier : dataset.csv \n\n", df)
dfQuote = df[['quote', 'title']].drop_duplicates().copy()
dfQuote = df[['quote']].drop_duplicates().copy()
dfSupport = df[['title', 'type', 'year']].drop_duplicates().copy()
dfSupport = df[['support']].drop_duplicates().copy()
# Support data insertion
for line in dfSupport.itertuples():
co.execute (text('''INSERT INTO Support (title, form, release)
VALUES (:title, :form, :release);'''),
{
'title' : line.title,
'form' : line.type,
'release' : line.year
})
dfType = df[['type']].drop_duplicates().copy()
co.commit()
for line in dfQuote.itertuples():
idSupport = co.execute (
text('''SELECT id_support, title FROM Support
WHERE title = :title;'''),
{'title' : line.title}
).fetchone()
'''
if idSupport :
co.execute (
text('''INSERT INTO Quote (content, img_path, likes, time_code, langue, is_valid, support)
VALUES (:content, :img_path, :likes, :time_code, :langue, :is_valid, :support);'''),
{
'content' : line.quote,
'img_path' : "/IMG/PATH/" + (idSupport[1][0:10]).strip().replace(" ", "").replace(":", ""),
'likes' : rdm.randint(1000),
'time_code' : str(rdm.randint(200)) + ":" + str(rdm.randint(59)),
'langue' : "English",
'is_valid' : True,
'support' : idSupport[0],
})
engine = create_engine("postgresql://tonguyen@:5432/dbWF")
co.commit()
try:
except exc.SQLAlchemyError as error:
print(error)
co = engine.connect()
print("Connexion à la base de données : dbWF\n")
print("Veuillez patienter lors de l'insertion des données\n")
finally:
'''
if co is not None:
print("Déconnexion de la base : dbsae2_04\n")
co.close()

@ -1,23 +1,34 @@
CREATE TABLE User (
id_user numeric PRIMARY KEY,
DROP TABLE IF EXISTS Users CASCADE;
DROP TABLE IF EXISTS Support CASCADE;
DROP TABLE IF EXISTS Quote CASCADE;
DROP TABLE IF EXISTS Commentary CASCADE;
DROP TABLE IF EXISTS Favorite CASCADE;
DROP TABLE IF EXISTS QuizQuestions CASCADE;
DROP TABLE IF EXISTS Quiz CASCADE;
DROP TABLE IF EXISTS Question CASCADE;
CREATE TABLE Users (
id_user SERIAL PRIMARY KEY,
username varchar(50) NOT NULL,
email varchar(50) NOT NULL,
phone varchar(10) NOT NULL,
pssword varchar(99) NOT NULL,
creation date NOT NULL,
CONSTRAINT uniq_fields UNIQUE (username, email, phone)
CONSTRAINT unique_col UNIQUE (username, email, phone)
);
CREATE TABLE Commentary (
id_comment numeric PRIMARY KEY,
comment text NOT NULL,
user numeric REFERENCES User(id_user),
quote numeric REFERENCES Quote(id_quote)
);
CREATE TABLE Support (
id_support SERIAL PRIMARY KEY,
title varchar(99) NOT NULL,
form varchar(30) NOT NULL,
release numeric NOT NULL,
CONSTRAINT type_form CHECK (form IN ('movie', 'video-game', 'novel', 'anime', 'tv'))
);
CREATE TABLE Quote (
id_quote numeric PRIMARY KEY,
id_quote SERIAL PRIMARY KEY,
content text NOT NULL UNIQUE,
img_path varchar(50) NOT NULL,
likes numeric NOT NULL DEFAULT 0,
@ -25,27 +36,27 @@ CREATE TABLE Quote (
langue varchar(50) NOT NULL,
is_valid boolean NOT NULL DEFAULT true,
reason text,
support numeric REFERENCES Support(id_support),
user numeric REFERENCES User(id_user)
user_q integer REFERENCES Users(id_user),
support integer REFERENCES Support(id_support),
CONSTRAINT reason_txt CHECK (is_valid OR reason IS NOT NULL)
);
CREATE TABLE Support (
id_support numeric PRIMARY KEY,
title varchar(50) NOT NULL,
form varchar(30) NOT NULL,
release date NOT NULL,
CONSTRAINT type_form CHECK (form IN ('Movie', 'Video-Game', 'Novel', 'Anime'))
CREATE TABLE Commentary (
id_comment numeric PRIMARY KEY,
comment text NOT NULL,
user_c integer REFERENCES Users(id_user),
quote_c integer REFERENCES Quote(id_quote)
);
CREATE TABLE Favorite (
id_fav numeric PRIMARY KEY,
user numeric REFERENCES User(id_user),
quote numeric REFERENCES Quote(id_quote)
user_f integer REFERENCES Users(id_user),
quote_f integer REFERENCES Quote(id_quote),
CONSTRAINT pk_favorite PRIMARY KEY (user_f, quote_f)
);
CREATE TABLE Quiz (
id_quiz numeric PRIMARY KEY,
lvl numeric NOT NULL,
level numeric NOT NULL,
duration numeric NOT NULL
);
@ -56,6 +67,11 @@ CREATE TABLE Question (
answerB varchar(99) NOT NULL,
answerC varchar(99) NOT NULL,
answerD varchar(99) NOT NULL,
cAnswer varchar(99) NOT NULL,
quiz numeric REFERENCES Quiz(id_quiz)
cAnswer varchar(99) NOT NULL
);
CREATE TABLE QuizQuestions (
quiz_qq numeric REFERENCES Quiz(id_quiz),
question_qq numeric REFERENCES Question(id_question),
CONSTRAINT pk_qq PRIMARY KEY (quiz_qq, question_qq)
);
Loading…
Cancel
Save