ajout du tp9-10 de BDD

master
antoine.perederii 2 years ago
parent 13736bec78
commit 04e840d7b2

@ -0,0 +1,4 @@
#!/bin/bash
sed -r 's/: psycopg2\.(connection|cursor)//' tp.py > /tmp/patched_tp.py
python3 /tmp/patched_tp.py

File diff suppressed because it is too large Load Diff

@ -0,0 +1,46 @@
INSERT INTO Discipline VALUES('ARC','Archery');
INSERT INTO Discipline VALUES('CRD','Cycling Road');
INSERT INTO Discipline VALUES('FEN','Fencing');
INSERT INTO Discipline VALUES('JUD','Judo');
INSERT INTO Discipline VALUES('SHO','Shooting');
INSERT INTO Discipline VALUES('TKW','Taekwondo');
INSERT INTO Discipline VALUES('WLF','Weightlifting');
INSERT INTO Discipline VALUES('DIV','Diving');
INSERT INTO Discipline VALUES('SKB','Skateboarding');
INSERT INTO Discipline VALUES('SWM','Swimming');
INSERT INTO Discipline VALUES('GAR','Artistic Gymnastics');
INSERT INTO Discipline VALUES('CSL','Canoe Slalom');
INSERT INTO Discipline VALUES('MTB','Cycling Mountain Bike');
INSERT INTO Discipline VALUES('TTE','Table Tennis');
INSERT INTO Discipline VALUES('TRI','Triathlon');
INSERT INTO Discipline VALUES('BSB','Baseball/Softball');
INSERT INTO Discipline VALUES('EQU','Equestrian');
INSERT INTO Discipline VALUES('SRF','Surfing');
INSERT INTO Discipline VALUES('BK3','3x3 Basketball');
INSERT INTO Discipline VALUES('ROW','Rowing');
INSERT INTO Discipline VALUES('RUG','Rugby Sevens');
INSERT INTO Discipline VALUES('ATH','Athletics');
INSERT INTO Discipline VALUES('BDM','Badminton');
INSERT INTO Discipline VALUES('BMX','Cycling BMX Racing');
INSERT INTO Discipline VALUES('TEN','Tennis');
INSERT INTO Discipline VALUES('GTR','Trampoline Gymnastics');
INSERT INTO Discipline VALUES('BOX','Boxing');
INSERT INTO Discipline VALUES('SAL','Sailing');
INSERT INTO Discipline VALUES('BMF','Cycling BMX Freestyle');
INSERT INTO Discipline VALUES('GLF','Golf');
INSERT INTO Discipline VALUES('CTR','Cycling Track');
INSERT INTO Discipline VALUES('WRE','Wrestling');
INSERT INTO Discipline VALUES('CSP','Canoe Sprint');
INSERT INTO Discipline VALUES('SWA','Artistic Swimming');
INSERT INTO Discipline VALUES('OWS','Marathon Swimming');
INSERT INTO Discipline VALUES('HOC','Hockey');
INSERT INTO Discipline VALUES('KTE','Karate');
INSERT INTO Discipline VALUES('CLB','Sport Climbing');
INSERT INTO Discipline VALUES('VBV','Beach Volleyball');
INSERT INTO Discipline VALUES('FBL','Football');
INSERT INTO Discipline VALUES('MPN','Modern Pentathlon');
INSERT INTO Discipline VALUES('BKB','Basketball');
INSERT INTO Discipline VALUES('HBL','Handball');
INSERT INTO Discipline VALUES('GRY','Rhythmic Gymnastics');
INSERT INTO Discipline VALUES('VVO','Volleyball');
INSERT INTO Discipline VALUES('WPO','Water Polo');

@ -0,0 +1,355 @@
INSERT INTO Epreuve VALUES('E001','ARC','Mixed Team','2021-07-24'::date);
INSERT INTO Epreuve VALUES('E002','CRD','Men''s Road Race','2021-07-24'::date);
INSERT INTO Epreuve VALUES('E003','FEN','Men''s Sabre Individual','2021-07-24'::date);
INSERT INTO Epreuve VALUES('E004','FEN','Women''s Epée Individual','2021-07-24'::date);
INSERT INTO Epreuve VALUES('E005','JUD','Men -60 kg','2021-07-24'::date);
INSERT INTO Epreuve VALUES('E006','JUD','Women -48 kg','2021-07-24'::date);
INSERT INTO Epreuve VALUES('E007','SHO','10m Air Pistol Men','2021-07-24'::date);
INSERT INTO Epreuve VALUES('E008','SHO','10m Air Rifle Women','2021-07-24'::date);
INSERT INTO Epreuve VALUES('E009','TKW','Men -58kg','2021-07-24'::date);
INSERT INTO Epreuve VALUES('E010','TKW','Women -49kg','2021-07-24'::date);
INSERT INTO Epreuve VALUES('E011','WLF','Women''s 49kg','2021-07-24'::date);
INSERT INTO Epreuve VALUES('E012','ARC','Women''s Team','2021-07-25'::date);
INSERT INTO Epreuve VALUES('E013','CRD','Women''s Road Race','2021-07-25'::date);
INSERT INTO Epreuve VALUES('E014','DIV','Women''s Synchronised 3m Springboard','2021-07-25'::date);
INSERT INTO Epreuve VALUES('E015','FEN','Men''s Epée Individual','2021-07-25'::date);
INSERT INTO Epreuve VALUES('E016','FEN','Women''s Foil Individual','2021-07-25'::date);
INSERT INTO Epreuve VALUES('E017','JUD','Men -66 kg','2021-07-25'::date);
INSERT INTO Epreuve VALUES('E018','JUD','Women -52 kg','2021-07-25'::date);
INSERT INTO Epreuve VALUES('E019','SHO','10m Air Pistol Women','2021-07-25'::date);
INSERT INTO Epreuve VALUES('E020','SHO','10m Air Rifle Men','2021-07-25'::date);
INSERT INTO Epreuve VALUES('E021','SKB','Men''s Street','2021-07-25'::date);
INSERT INTO Epreuve VALUES('E022','SWM','Men''s 400m Freestyle','2021-07-25'::date);
INSERT INTO Epreuve VALUES('E023','SWM','Men''s 400m Individual Medley','2021-07-25'::date);
INSERT INTO Epreuve VALUES('E024','SWM','Women''s 4 x 100m Freestyle Relay','2021-07-25'::date);
INSERT INTO Epreuve VALUES('E025','SWM','Women''s 400m Individual Medley','2021-07-25'::date);
INSERT INTO Epreuve VALUES('E026','TKW','Men -68kg','2021-07-25'::date);
INSERT INTO Epreuve VALUES('E027','TKW','Women -57kg','2021-07-25'::date);
INSERT INTO Epreuve VALUES('E028','WLF','Men''s 61kg','2021-07-25'::date);
INSERT INTO Epreuve VALUES('E029','WLF','Men''s 67kg','2021-07-25'::date);
INSERT INTO Epreuve VALUES('E030','ARC','Men''s Team','2021-07-26'::date);
INSERT INTO Epreuve VALUES('E031','GAR','Men''s Team','2021-07-26'::date);
INSERT INTO Epreuve VALUES('E032','CSL','Men''s Canoe','2021-07-26'::date);
INSERT INTO Epreuve VALUES('E033','MTB','Men''s Cross-country','2021-07-26'::date);
INSERT INTO Epreuve VALUES('E034','DIV','Men''s Synchronised 10m Platform','2021-07-26'::date);
INSERT INTO Epreuve VALUES('E035','FEN','Men''s Foil Individual','2021-07-26'::date);
INSERT INTO Epreuve VALUES('E036','FEN','Women''s Sabre Individual','2021-07-26'::date);
INSERT INTO Epreuve VALUES('E037','JUD','Men -73 kg','2021-07-26'::date);
INSERT INTO Epreuve VALUES('E038','JUD','Women -57 kg','2021-07-26'::date);
INSERT INTO Epreuve VALUES('E039','SHO','Skeet Men','2021-07-26'::date);
INSERT INTO Epreuve VALUES('E040','SHO','Skeet Women','2021-07-26'::date);
INSERT INTO Epreuve VALUES('E041','SKB','Women''s Street','2021-07-26'::date);
INSERT INTO Epreuve VALUES('E042','SWM','Men''s 100m Breaststroke','2021-07-26'::date);
INSERT INTO Epreuve VALUES('E043','SWM','Men''s 4 x 100m Freestyle Relay','2021-07-26'::date);
INSERT INTO Epreuve VALUES('E044','SWM','Women''s 100m Butterfly','2021-07-26'::date);
INSERT INTO Epreuve VALUES('E045','SWM','Women''s 400m Freestyle','2021-07-26'::date);
INSERT INTO Epreuve VALUES('E046','TTE','Mixed Doubles','2021-07-26'::date);
INSERT INTO Epreuve VALUES('E047','TKW','Men -80kg','2021-07-26'::date);
INSERT INTO Epreuve VALUES('E048','TKW','Women -67kg','2021-07-26'::date);
INSERT INTO Epreuve VALUES('E049','TRI','Men''s Individual','2021-07-26'::date);
INSERT INTO Epreuve VALUES('E050','WLF','Women''s 55kg','2021-07-26'::date);
INSERT INTO Epreuve VALUES('E051','GAR','Women''s Team','2021-07-27'::date);
INSERT INTO Epreuve VALUES('E052','BSB','Softball','2021-07-27'::date);
INSERT INTO Epreuve VALUES('E053','CSL','Women''s Kayak','2021-07-27'::date);
INSERT INTO Epreuve VALUES('E054','MTB','Women''s Cross-country','2021-07-27'::date);
INSERT INTO Epreuve VALUES('E055','DIV','Women''s Synchronised 10m Platform','2021-07-27'::date);
INSERT INTO Epreuve VALUES('E056','EQU','Dressage Team','2021-07-27'::date);
INSERT INTO Epreuve VALUES('E057','FEN','Women''s Epée Team','2021-07-27'::date);
INSERT INTO Epreuve VALUES('E058','JUD','Men -81 kg','2021-07-27'::date);
INSERT INTO Epreuve VALUES('E059','JUD','Women -63 kg','2021-07-27'::date);
INSERT INTO Epreuve VALUES('E060','SHO','10m Air Pistol Mixed Team','2021-07-27'::date);
INSERT INTO Epreuve VALUES('E061','SHO','10m Air Rifle Mixed Team','2021-07-27'::date);
INSERT INTO Epreuve VALUES('E062','SRF','Men','2021-07-27'::date);
INSERT INTO Epreuve VALUES('E063','SRF','Women','2021-07-27'::date);
INSERT INTO Epreuve VALUES('E064','SWM','Men''s 100m Backstroke','2021-07-27'::date);
INSERT INTO Epreuve VALUES('E065','SWM','Men''s 200m Freestyle','2021-07-27'::date);
INSERT INTO Epreuve VALUES('E066','SWM','Women''s 100m Backstroke','2021-07-27'::date);
INSERT INTO Epreuve VALUES('E067','SWM','Women''s 100m Breaststroke','2021-07-27'::date);
INSERT INTO Epreuve VALUES('E068','TKW','Men +80kg','2021-07-27'::date);
INSERT INTO Epreuve VALUES('E069','TKW','Women +67kg','2021-07-27'::date);
INSERT INTO Epreuve VALUES('E070','TRI','Women''s Individual','2021-07-27'::date);
INSERT INTO Epreuve VALUES('E071','WLF','Women''s 59kg','2021-07-27'::date);
INSERT INTO Epreuve VALUES('E072','WLF','Women''s 64kg','2021-07-27'::date);
INSERT INTO Epreuve VALUES('E073','BK3','Men','2021-07-28'::date);
INSERT INTO Epreuve VALUES('E074','BK3','Women','2021-07-28'::date);
INSERT INTO Epreuve VALUES('E075','GAR','Men''s All-Around','2021-07-28'::date);
INSERT INTO Epreuve VALUES('E076','CRD','Men''s Individual Time Trial','2021-07-28'::date);
INSERT INTO Epreuve VALUES('E077','CRD','Women''s Individual Time Trial','2021-07-28'::date);
INSERT INTO Epreuve VALUES('E078','DIV','Men''s Synchronised 3m Springboard','2021-07-28'::date);
INSERT INTO Epreuve VALUES('E079','EQU','Dressage Individual','2021-07-28'::date);
INSERT INTO Epreuve VALUES('E080','FEN','Men''s Sabre Team','2021-07-28'::date);
INSERT INTO Epreuve VALUES('E081','JUD','Men -90 kg','2021-07-28'::date);
INSERT INTO Epreuve VALUES('E082','JUD','Women -70 kg','2021-07-28'::date);
INSERT INTO Epreuve VALUES('E083','ROW','Men''s Double Sculls','2021-07-28'::date);
INSERT INTO Epreuve VALUES('E084','ROW','Men''s Four','2021-07-28'::date);
INSERT INTO Epreuve VALUES('E085','ROW','Men''s Quadruple Sculls','2021-07-28'::date);
INSERT INTO Epreuve VALUES('E086','ROW','Women''s Double Sculls','2021-07-28'::date);
INSERT INTO Epreuve VALUES('E087','ROW','Women''s Four','2021-07-28'::date);
INSERT INTO Epreuve VALUES('E088','ROW','Women''s Quadruple Sculls','2021-07-28'::date);
INSERT INTO Epreuve VALUES('E089','RUG','Men','2021-07-28'::date);
INSERT INTO Epreuve VALUES('E090','SWM','Men''s 200m Butterfly','2021-07-28'::date);
INSERT INTO Epreuve VALUES('E091','SWM','Men''s 4 x 200m Freestyle Relay','2021-07-28'::date);
INSERT INTO Epreuve VALUES('E092','SWM','Women''s 1500m Freestyle','2021-07-28'::date);
INSERT INTO Epreuve VALUES('E093','SWM','Women''s 200m Freestyle','2021-07-28'::date);
INSERT INTO Epreuve VALUES('E094','SWM','Women''s 200m Individual Medley','2021-07-28'::date);
INSERT INTO Epreuve VALUES('E095','WLF','Men''s 73kg','2021-07-28'::date);
INSERT INTO Epreuve VALUES('E096','GAR','Women''s All-Around','2021-07-29'::date);
INSERT INTO Epreuve VALUES('E097','CSL','Women''s Canoe','2021-07-29'::date);
INSERT INTO Epreuve VALUES('E098','FEN','Women''s Foil Team','2021-07-29'::date);
INSERT INTO Epreuve VALUES('E099','JUD','Men -100 kg','2021-07-29'::date);
INSERT INTO Epreuve VALUES('E100','JUD','Women -78 kg','2021-07-29'::date);
INSERT INTO Epreuve VALUES('E101','ROW','Lightweight Men''s Double Sculls','2021-07-29'::date);
INSERT INTO Epreuve VALUES('E102','ROW','Lightweight Women''s Double Sculls','2021-07-29'::date);
INSERT INTO Epreuve VALUES('E103','ROW','Men''s Pair','2021-07-29'::date);
INSERT INTO Epreuve VALUES('E104','ROW','Women''s Pair','2021-07-29'::date);
INSERT INTO Epreuve VALUES('E105','SHO','Trap Men','2021-07-29'::date);
INSERT INTO Epreuve VALUES('E106','SHO','Trap Women','2021-07-29'::date);
INSERT INTO Epreuve VALUES('E107','SWM','Men''s 100m Freestyle','2021-07-29'::date);
INSERT INTO Epreuve VALUES('E108','SWM','Men''s 200m Breaststroke','2021-07-29'::date);
INSERT INTO Epreuve VALUES('E109','SWM','Men''s 800m Freestyle','2021-07-29'::date);
INSERT INTO Epreuve VALUES('E110','SWM','Women''s 200m Butterfly','2021-07-29'::date);
INSERT INTO Epreuve VALUES('E111','SWM','Women''s 4 x 200m Freestyle Relay','2021-07-29'::date);
INSERT INTO Epreuve VALUES('E112','TTE','Women''s Singles','2021-07-29'::date);
INSERT INTO Epreuve VALUES('E113','ARC','Women''s Individual','2021-07-30'::date);
INSERT INTO Epreuve VALUES('E114','ATH','Men''s 10,000m','2021-07-30'::date);
INSERT INTO Epreuve VALUES('E115','BDM','Mixed Doubles','2021-07-30'::date);
INSERT INTO Epreuve VALUES('E116','CSL','Men''s Kayak','2021-07-30'::date);
INSERT INTO Epreuve VALUES('E117','BMX','Men','2021-07-30'::date);
INSERT INTO Epreuve VALUES('E118','BMX','Women','2021-07-30'::date);
INSERT INTO Epreuve VALUES('E119','FEN','Men''s Epée Team','2021-07-30'::date);
INSERT INTO Epreuve VALUES('E120','JUD','Men +100 kg','2021-07-30'::date);
INSERT INTO Epreuve VALUES('E121','JUD','Women +78 kg','2021-07-30'::date);
INSERT INTO Epreuve VALUES('E122','ROW','Men''s Eight','2021-07-30'::date);
INSERT INTO Epreuve VALUES('E123','ROW','Men''s Single Sculls','2021-07-30'::date);
INSERT INTO Epreuve VALUES('E124','ROW','Women''s Eight','2021-07-30'::date);
INSERT INTO Epreuve VALUES('E125','ROW','Women''s Single Sculls','2021-07-30'::date);
INSERT INTO Epreuve VALUES('E126','SHO','25m Pistol Women','2021-07-30'::date);
INSERT INTO Epreuve VALUES('E127','SWM','Men''s 200m Backstroke','2021-07-30'::date);
INSERT INTO Epreuve VALUES('E128','SWM','Men''s 200m Individual Medley','2021-07-30'::date);
INSERT INTO Epreuve VALUES('E129','SWM','Women''s 100m Freestyle','2021-07-30'::date);
INSERT INTO Epreuve VALUES('E130','SWM','Women''s 200m Breaststroke','2021-07-30'::date);
INSERT INTO Epreuve VALUES('E131','TTE','Men''s Singles','2021-07-30'::date);
INSERT INTO Epreuve VALUES('E132','TEN','Men''s Doubles','2021-07-30'::date);
INSERT INTO Epreuve VALUES('E133','GTR','Women','2021-07-30'::date);
INSERT INTO Epreuve VALUES('E134','ARC','Men''s Individual','2021-07-31'::date);
INSERT INTO Epreuve VALUES('E135','ATH','4 x 400m Relay Mixed','2021-07-31'::date);
INSERT INTO Epreuve VALUES('E136','ATH','Men''s Discus Throw','2021-07-31'::date);
INSERT INTO Epreuve VALUES('E137','ATH','Women''s 100m','2021-07-31'::date);
INSERT INTO Epreuve VALUES('E138','BDM','Men''s Doubles','2021-07-31'::date);
INSERT INTO Epreuve VALUES('E139','BOX','Women''s Feather (54-57kg)','2021-07-31'::date);
INSERT INTO Epreuve VALUES('E140','FEN','Women''s Sabre Team','2021-07-31'::date);
INSERT INTO Epreuve VALUES('E141','JUD','Mixed Team','2021-07-31'::date);
INSERT INTO Epreuve VALUES('E142','RUG','Women','2021-07-31'::date);
INSERT INTO Epreuve VALUES('E143','SAL','Men''s Windsurfer - RS:X','2021-07-31'::date);
INSERT INTO Epreuve VALUES('E144','SAL','Women''s Windsurfer - RS:X','2021-07-31'::date);
INSERT INTO Epreuve VALUES('E145','SHO','50m Rifle 3 Positions Women','2021-07-31'::date);
INSERT INTO Epreuve VALUES('E146','SHO','Trap Mixed Team','2021-07-31'::date);
INSERT INTO Epreuve VALUES('E147','SWM','Men''s 100m Butterfly','2021-07-31'::date);
INSERT INTO Epreuve VALUES('E148','SWM','Mixed 4 x 100m Medley Relay','2021-07-31'::date);
INSERT INTO Epreuve VALUES('E149','SWM','Women''s 200m Backstroke','2021-07-31'::date);
INSERT INTO Epreuve VALUES('E150','SWM','Women''s 800m Freestyle','2021-07-31'::date);
INSERT INTO Epreuve VALUES('E151','TEN','Men''s Singles','2021-07-31'::date);
INSERT INTO Epreuve VALUES('E152','TEN','Mixed Doubles','2021-07-31'::date);
INSERT INTO Epreuve VALUES('E153','TEN','Women''s Doubles','2021-07-31'::date);
INSERT INTO Epreuve VALUES('E154','TEN','Women''s Singles','2021-07-31'::date);
INSERT INTO Epreuve VALUES('E155','GTR','Men','2021-07-31'::date);
INSERT INTO Epreuve VALUES('E156','TRI','Mixed Relay','2021-07-31'::date);
INSERT INTO Epreuve VALUES('E157','WLF','Men''s 81kg','2021-07-31'::date);
INSERT INTO Epreuve VALUES('E158','WLF','Men''s 96kg','2021-07-31'::date);
INSERT INTO Epreuve VALUES('E159','GAR','Men''s Floor Exercise','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E160','GAR','Men''s Pommel Horse','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E161','GAR','Women''s Uneven Bars','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E162','GAR','Women''s Vault','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E163','ATH','Men''s 100m','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E164','ATH','Men''s High Jump','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E165','ATH','Women''s Shot Put','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E166','ATH','Women''s Triple Jump','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E167','BDM','Women''s Singles','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E168','BOX','Men''s Light Heavy (75-81kg)','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E169','BOX','Men''s Welter (63-69kg)','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E170','BMF','Men''s Park','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E171','BMF','Women''s Park','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E172','DIV','Women''s 3m Springboard','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E173','FEN','Men''s Foil Team','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E174','GLF','Men''s Individual Stroke Play','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E175','SAL','Men''s One Person Dinghy - Laser','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E176','SAL','Women''s One Person Dinghy - Laser Radial','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E177','SWM','Men''s 1500m Freestyle','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E178','SWM','Men''s 4 x 100m Medley Relay','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E179','SWM','Men''s 50m Freestyle','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E180','SWM','Women''s 4 x 100m Medley Relay','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E181','SWM','Women''s 50m Freestyle','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E182','TEN','Men''s Singles','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E183','TEN','Mixed Doubles','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E184','TEN','Women''s Doubles','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E185','WLF','Women''s 76kg','2021-08-01'::date);
INSERT INTO Epreuve VALUES('E186','GAR','Men''s Rings','2021-08-02'::date);
INSERT INTO Epreuve VALUES('E187','GAR','Men''s Vault','2021-08-02'::date);
INSERT INTO Epreuve VALUES('E188','GAR','Women''s Floor Exercise','2021-08-02'::date);
INSERT INTO Epreuve VALUES('E189','ATH','Men''s 3000m Steeplechase','2021-08-02'::date);
INSERT INTO Epreuve VALUES('E190','ATH','Men''s Long Jump','2021-08-02'::date);
INSERT INTO Epreuve VALUES('E191','ATH','Women''s 100m Hurdles','2021-08-02'::date);
INSERT INTO Epreuve VALUES('E192','ATH','Women''s 5000m','2021-08-02'::date);
INSERT INTO Epreuve VALUES('E193','ATH','Women''s Discus Throw','2021-08-02'::date);
INSERT INTO Epreuve VALUES('E194','BDM','Men''s Singles','2021-08-02'::date);
INSERT INTO Epreuve VALUES('E195','BDM','Women''s Doubles','2021-08-02'::date);
INSERT INTO Epreuve VALUES('E196','CTR','Women''s Team Sprint','2021-08-02'::date);
INSERT INTO Epreuve VALUES('E197','EQU','Eventing Individual','2021-08-02'::date);
INSERT INTO Epreuve VALUES('E198','EQU','Eventing Team','2021-08-02'::date);
INSERT INTO Epreuve VALUES('E199','SHO','25m Rapid Fire Pistol Men','2021-08-02'::date);
INSERT INTO Epreuve VALUES('E200','SHO','50m Rifle 3 Positions Men','2021-08-02'::date);
INSERT INTO Epreuve VALUES('E201','WLF','Women''s +87kg','2021-08-02'::date);
INSERT INTO Epreuve VALUES('E202','WLF','Women''s 87kg','2021-08-02'::date);
INSERT INTO Epreuve VALUES('E203','WRE','Men''s Greco-Roman 130kg','2021-08-02'::date);
INSERT INTO Epreuve VALUES('E204','WRE','Men''s Greco-Roman 60kg','2021-08-02'::date);
INSERT INTO Epreuve VALUES('E205','WRE','Women''s Freestyle 76kg','2021-08-02'::date);
INSERT INTO Epreuve VALUES('E206','GAR','Men''s Horizontal Bar','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E207','GAR','Men''s Parallel Bars','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E208','GAR','Women''s Balance Beam','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E209','ATH','Men''s 400m Hurdles','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E210','ATH','Men''s Pole Vault','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E211','ATH','Women''s 200m','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E212','ATH','Women''s 800m','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E213','ATH','Women''s Hammer Throw','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E214','ATH','Women''s Long Jump','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E215','BOX','Men''s Feather (52-57kg)','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E216','BOX','Men''s Heavy (81-91kg)','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E217','BOX','Men''s Welter (63-69kg)','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E218','BOX','Women''s Feather (54-57kg)','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E219','CSP','Men''s Canoe Double 1000m','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E220','CSP','Men''s Kayak Single 1000m','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E221','CSP','Women''s Kayak Double 500m','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E222','CSP','Women''s Kayak Single 200m','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E223','CTR','Men''s Team Sprint','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E224','CTR','Women''s Team Pursuit','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E225','DIV','Men''s 3m Springboard','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E226','SAL','Men''s One Person Dinghy (Heavyweight) - Finn','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E227','SAL','Men''s Skiff - 49er','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E228','SAL','Mixed Multihull - Nacra 17 Foiling','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E229','SAL','Women''s Skiff - 49er FX','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E230','WLF','Men''s 109kg','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E231','WRE','Men''s Greco-Roman 77kg','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E232','WRE','Men''s Greco-Roman 97kg','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E233','WRE','Women''s Freestyle 68kg','2021-08-03'::date);
INSERT INTO Epreuve VALUES('E234','SWA','Duet','2021-08-04'::date);
INSERT INTO Epreuve VALUES('E235','ATH','Men''s 200m','2021-08-04'::date);
INSERT INTO Epreuve VALUES('E236','ATH','Men''s 800m','2021-08-04'::date);
INSERT INTO Epreuve VALUES('E237','ATH','Men''s Decathlon','2021-08-04'::date);
INSERT INTO Epreuve VALUES('E238','ATH','Men''s Hammer Throw','2021-08-04'::date);
INSERT INTO Epreuve VALUES('E239','ATH','Women''s 3000m Steeplechase','2021-08-04'::date);
INSERT INTO Epreuve VALUES('E240','ATH','Women''s 400m Hurdles','2021-08-04'::date);
INSERT INTO Epreuve VALUES('E241','ATH','Women''s Heptathlon','2021-08-04'::date);
INSERT INTO Epreuve VALUES('E242','BOX','Men''s Light Heavy (75-81kg)','2021-08-04'::date);
INSERT INTO Epreuve VALUES('E243','BOX','Men''s Super Heavy (+91kg)','2021-08-04'::date);
INSERT INTO Epreuve VALUES('E244','BOX','Women''s Fly (48-51kg)','2021-08-04'::date);
INSERT INTO Epreuve VALUES('E245','BOX','Women''s Welter (64-69kg)','2021-08-04'::date);
INSERT INTO Epreuve VALUES('E246','CTR','Men''s Team Pursuit','2021-08-04'::date);
INSERT INTO Epreuve VALUES('E247','EQU','Jumping Individual','2021-08-04'::date);
INSERT INTO Epreuve VALUES('E248','OWS','Women''s 10km','2021-08-04'::date);
INSERT INTO Epreuve VALUES('E249','SAL','Men''s Two Person Dinghy - 470','2021-08-04'::date);
INSERT INTO Epreuve VALUES('E250','SAL','Women''s Two Person Dinghy - 470','2021-08-04'::date);
INSERT INTO Epreuve VALUES('E251','SKB','Women''s Park','2021-08-04'::date);
INSERT INTO Epreuve VALUES('E252','WLF','Men''s +109kg','2021-08-04'::date);
INSERT INTO Epreuve VALUES('E253','WRE','Men''s Greco-Roman 67kg','2021-08-04'::date);
INSERT INTO Epreuve VALUES('E254','WRE','Men''s Greco-Roman 87kg','2021-08-04'::date);
INSERT INTO Epreuve VALUES('E255','WRE','Women''s Freestyle 62kg','2021-08-04'::date);
INSERT INTO Epreuve VALUES('E256','ATH','Men''s 110m Hurdles','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E257','ATH','Men''s 20km Race Walk','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E258','ATH','Men''s 400m','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E259','ATH','Men''s Shot Put','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E260','ATH','Men''s Triple Jump','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E261','ATH','Women''s Pole Vault','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E262','BOX','Men''s Feather (52-57kg)','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E263','BOX','Men''s Fly (48-52kg)','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E264','BOX','Men''s Middle (69-75kg)','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E265','BOX','Women''s Light (57-60kg)','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E266','CSP','Men''s Kayak Double 1000m','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E267','CSP','Men''s Kayak Single 200m','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E268','CSP','Women''s Canoe Single 200m','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E269','CSP','Women''s Kayak Single 500m','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E270','CTR','Men''s Omnium','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E271','CTR','Women''s Keirin','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E272','DIV','Women''s 10m Platform','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E273','HOC','Men','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E274','KTE','Men''s Kumite -67kg','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E275','KTE','Women''s Kata','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E276','KTE','Women''s Kumite -55kg','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E277','OWS','Men''s 10km','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E278','SKB','Men''s Park','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E279','CLB','Men''s Combined','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E280','TTE','Women''s Team','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E281','WRE','Men''s Freestyle 57kg','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E282','WRE','Men''s Freestyle 86kg','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E283','WRE','Women''s Freestyle 57kg','2021-08-05'::date);
INSERT INTO Epreuve VALUES('E284','ATH','Men''s 4 x 100m Relay','2021-08-06'::date);
INSERT INTO Epreuve VALUES('E285','ATH','Men''s 5000m','2021-08-06'::date);
INSERT INTO Epreuve VALUES('E286','ATH','Men''s 50km Race Walk','2021-08-06'::date);
INSERT INTO Epreuve VALUES('E287','ATH','Women''s 1500m','2021-08-06'::date);
INSERT INTO Epreuve VALUES('E288','ATH','Women''s 20km Race Walk','2021-08-06'::date);
INSERT INTO Epreuve VALUES('E289','ATH','Women''s 4 x 100m Relay','2021-08-06'::date);
INSERT INTO Epreuve VALUES('E290','ATH','Women''s 400m','2021-08-06'::date);
INSERT INTO Epreuve VALUES('E291','ATH','Women''s Javelin Throw','2021-08-06'::date);
INSERT INTO Epreuve VALUES('E292','VBV','Women','2021-08-06'::date);
INSERT INTO Epreuve VALUES('E293','BOX','Men''s Heavy (81-91kg)','2021-08-06'::date);
INSERT INTO Epreuve VALUES('E294','BOX','Men''s Light (57-63kg)','2021-08-06'::date);
INSERT INTO Epreuve VALUES('E295','BOX','Women''s Middle (69-75kg)','2021-08-06'::date);
INSERT INTO Epreuve VALUES('E296','CTR','Men''s Sprint','2021-08-06'::date);
INSERT INTO Epreuve VALUES('E297','CTR','Women''s Madison','2021-08-06'::date);
INSERT INTO Epreuve VALUES('E298','FBL','Women','2021-08-06'::date);
INSERT INTO Epreuve VALUES('E299','HOC','Women','2021-08-06'::date);
INSERT INTO Epreuve VALUES('E300','KTE','Men''s Kata','2021-08-06'::date);
INSERT INTO Epreuve VALUES('E301','KTE','Men''s Kumite -75kg','2021-08-06'::date);
INSERT INTO Epreuve VALUES('E302','KTE','Women''s Kumite -61kg','2021-08-06'::date);
INSERT INTO Epreuve VALUES('E303','MPN','Women''s Individual','2021-08-06'::date);
INSERT INTO Epreuve VALUES('E304','CLB','Women''s Combined','2021-08-06'::date);
INSERT INTO Epreuve VALUES('E305','TTE','Men''s Team','2021-08-06'::date);
INSERT INTO Epreuve VALUES('E306','WRE','Men''s Freestyle 125kg','2021-08-06'::date);
INSERT INTO Epreuve VALUES('E307','WRE','Men''s Freestyle 74kg','2021-08-06'::date);
INSERT INTO Epreuve VALUES('E308','WRE','Women''s Freestyle 53kg','2021-08-06'::date);
INSERT INTO Epreuve VALUES('E309','SWA','Team','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E310','ATH','Men''s 1500m','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E311','ATH','Men''s 4 x 400m Relay','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E312','ATH','Men''s Javelin Throw','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E313','ATH','Women''s 10,000m','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E314','ATH','Women''s 4 x 400m Relay','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E315','ATH','Women''s High Jump','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E316','ATH','Women''s Marathon','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E317','BSB','Baseball','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E318','BKB','Men','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E319','VBV','Men','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E320','BOX','Men''s Fly (48-52kg)','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E321','BOX','Men''s Middle (69-75kg)','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E322','BOX','Women''s Fly (48-51kg)','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E323','BOX','Women''s Welter (64-69kg)','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E324','CSP','Men''s Canoe Single 1000m','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E325','CSP','Men''s Kayak Four 500m','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E326','CSP','Women''s Canoe Double 500m','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E327','CSP','Women''s Kayak Four 500m','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E328','CTR','Men''s Madison','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E329','DIV','Men''s 10m Platform','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E330','EQU','Jumping Team','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E331','FBL','Men','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E332','GLF','Women''s Individual Stroke Play','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E333','HBL','Men','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E334','KTE','Men''s Kumite +75kg','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E335','KTE','Women''s Kumite +61kg','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E336','MPN','Men''s Individual','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E337','GRY','Individual All-Around','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E338','VVO','Men','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E339','WPO','Women','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E340','WRE','Men''s Freestyle 65kg','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E341','WRE','Men''s Freestyle 97kg','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E342','WRE','Women''s Freestyle 50kg','2021-08-07'::date);
INSERT INTO Epreuve VALUES('E343','ATH','Men''s Marathon','2021-08-08'::date);
INSERT INTO Epreuve VALUES('E344','BKB','Women','2021-08-08'::date);
INSERT INTO Epreuve VALUES('E345','BOX','Men''s Light (57-63kg)','2021-08-08'::date);
INSERT INTO Epreuve VALUES('E346','BOX','Men''s Super Heavy (+91kg)','2021-08-08'::date);
INSERT INTO Epreuve VALUES('E347','BOX','Women''s Light (57-60kg)','2021-08-08'::date);
INSERT INTO Epreuve VALUES('E348','BOX','Women''s Middle (69-75kg)','2021-08-08'::date);
INSERT INTO Epreuve VALUES('E349','CTR','Men''s Keirin','2021-08-08'::date);
INSERT INTO Epreuve VALUES('E350','CTR','Women''s Omnium','2021-08-08'::date);
INSERT INTO Epreuve VALUES('E351','CTR','Women''s Sprint','2021-08-08'::date);
INSERT INTO Epreuve VALUES('E352','HBL','Women','2021-08-08'::date);
INSERT INTO Epreuve VALUES('E353','GRY','Group All-Around','2021-08-08'::date);
INSERT INTO Epreuve VALUES('E354','VVO','Women','2021-08-08'::date);
INSERT INTO Epreuve VALUES('E355','WPO','Men','2021-08-08'::date);

@ -0,0 +1,225 @@
import pandas
import psycopg2
import matplotlib.pyplot as plt
from getpass import getpass
filename = r'vgsales.csv'
db_host = input('Nom d\'hôte : ')
if not db_host:
db_host = 'berlin'
db_name = input('Nom de la base de données : ')
if not db_name:
db_name = 'dbclfreville2'
db_user = input('Utilisateur : ')
if not db_user:
db_user = 'clfreville2'
db_password = getpass('Mot de passe : ')
##########
# Partie 1
##########
connection = psycopg2.connect(host=db_host, port=5432, database=db_name, user=db_user, password=db_password)
cur = connection.cursor()
def create_table(connection, filename):
cur = connection.cursor()
# 2. Création et population de la table
cur.execute("""CREATE TABLE IF NOT EXISTS plain_jeu (
nom VARCHAR(150) NOT NULL,
plateforme VARCHAR(10) NOT NULL,
annee_sortie INTEGER,
genre VARCHAR(20) NOT NULL,
editeur VARCHAR(40) NOT NULL,
ventes_na NUMERIC(6, 2) NOT NULL DEFAULT 0,
ventes_ue NUMERIC(6, 2) NOT NULL DEFAULT 0,
ventes_jp NUMERIC(6, 2) NOT NULL DEFAULT 0,
ventes_autre NUMERIC(6, 2) NOT NULL DEFAULT 0,
ventes_total NUMERIC(6, 2) NOT NULL DEFAULT 0, -- Redondant vu que devrait être le total des autres colonnes des ventes
PRIMARY KEY(nom, plateforme)
)""")
ventes = pandas.read_csv(filename)
# 3. Élimination des doublons
df = pandas.DataFrame(ventes).drop_duplicates(subset=['Name', 'Platform'])
# 2. Insertions
for row in df.itertuples():
cur.execute("INSERT INTO plain_jeu VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s);",
(row.Name, row.Platform, int(row.Year) if not pandas.isnull(row.Year) else None, row.Genre,
row.Publisher, row.NA_Sales, row.EU_Sales,
row.JP_Sales, row.Other_Sales, row.Global_Sales))
# 5. Recherche des lignes incohérentes (par delta vu qu'il s'agit de nombre flottants)
cur.execute("""SELECT nom, plateforme, ROUND((ventes_na + ventes_ue + ventes_jp + ventes_autre)::numeric, 2), ventes_total
FROM plain_jeu
WHERE ABS(ventes_na + ventes_ue + ventes_jp + ventes_autre - ventes_total) > 0.1""")
for row in cur.fetchall():
print(row)
# 6. Recalcul des ventes pour les lignes incohérentes
cur.execute("""UPDATE plain_jeu
SET ventes_total = ROUND((ventes_na + ventes_ue + ventes_jp + ventes_autre)::numeric, 2)
WHERE ABS(ventes_na + ventes_ue + ventes_jp + ventes_autre - ventes_total) > 0.1;""")
connection.commit()
# 7. Création du DataFrame propre
return pandas.read_sql("SELECT * FROM plain_jeu;", con=connection)
##########
# Partie 2
##########
def sales_graphs(connection):
# 1. Calcul des ventes moyennes par année de sortie et pour le genre aventure
df = pandas.read_sql("""SELECT annee_sortie, AVG(ventes_total) ventes_moyennes, SUM(ventes_total) ventes_totales FROM plain_jeu
WHERE genre = 'Adventure' AND annee_sortie IS NOT NULL
GROUP BY annee_sortie
ORDER BY annee_sortie;""", con=connection)
# 2/3. Affichage sous forme de courbe
fig = df.plot(x='annee_sortie', y=['ventes_moyennes', 'ventes_totales'])
fig.legend(['Ventes moyennes', 'Ventes totales'])
fig.set_xlabel('Année de sortie')
fig.set_ylabel('Ventes (en millions)')
# 4. Ventes totales pour l'ensemble des jeux
df = pandas.read_sql("""SELECT annee_sortie, genre, SUM(ventes_total) ventes_totales FROM plain_jeu
WHERE annee_sortie IS NOT NULL
GROUP BY annee_sortie, genre
ORDER BY annee_sortie;""", con=connection)
fig, ax = plt.subplots()
for label, group in df.groupby(['genre']):
ax = group.plot(ax=ax, kind='line', x='annee_sortie', y='ventes_totales', label=label)
ax.set_xlabel('Année de sortie')
ax.set_ylabel('Ventes (en millions)')
##########
# Partie 3
##########
def sales2_graphs(connection):
# 1. Calcul du total des ventes en Europe par plateforme
df = pandas.read_sql("""SELECT plateforme, SUM(ventes_ue) ventes_ue FROM plain_jeu
GROUP BY plateforme
ORDER BY ventes_ue;""", con=connection)
def plot_ventes_ue(df: pandas.DataFrame, plot_kind: str = 'line'):
if plot_kind == 'line':
fig = df.plot(x='plateforme', y='ventes_ue', legend=False)
else:
fig = df.plot(x='plateforme', y='ventes_ue', kind=plot_kind)
fig.set_xlabel('Plateforme')
fig.set_ylabel('Ventes en Europe (en millions)')
fig.set_title('Ventes de jeux vidéos en Europe par plateforme')
# 2. Affichage sous forme de courbe
plot_ventes_ue(df)
# 3. Affichage sous forme d'histogramme (TODO labels)
# plot_ventes_ue(df, 'hist')
plot_ventes_ue(df, 'bar')
# 4. Calcul du total des ventes par plateforme et par zone géographique
df = pandas.read_sql("""SELECT plateforme, SUM(ventes_na) ventes_na, SUM(ventes_ue) ventes_ue, SUM(ventes_jp) ventes_jp, SUM(ventes_autre) ventes_autre FROM plain_jeu
GROUP BY plateforme;""", con=connection)
# 5/6. Affichage sous forme de courbes
fig = df.plot(x='plateforme', style=['r*-', 'bo--', 'y^-', 'gs--']) # TODO linestyle
fig.set_xlabel('Plateforme')
fig.set_ylabel('Ventes (en millions)')
fig = df.plot.bar(x='plateforme', y=['ventes_na', 'ventes_ue', 'ventes_jp', 'ventes_autre'])
fig.set_xlabel('Plateforme')
fig.set_ylabel('Ventes (en millions)')
cur = connection.cursor()
##########
# Partie 4
##########
def plot_ventes_jeu(cur: psycopg2.extensions.cursor, nom: str, pourcentages: bool = True):
# 1. Récupération des ventes, réorganisées en plusieurs lignes dans le dataframe
cur.execute("""SELECT ventes_na, ventes_ue, ventes_jp, ventes_autre FROM plain_jeu
WHERE nom = '%s';""" % nom)
data = cur.fetchone()
zones = [desc[0].split('_')[1] for desc in cur.description]
df = pandas.DataFrame([[zones[i], float(data[i])] for i in range(len(data))], columns=['zone', 'ventes'],
index=zones)
title = 'Ventes du jeu ' + nom + ' par zone géographique'
# 2. Diagramme en bâtons
fig = df.plot.bar(x='zone', y='ventes', legend=False, rot=0)
fig.set_title(title)
if pourcentages:
# 4. Diagramme camembert avec pourcentages
fig = df.plot.pie(y='ventes', labels=None, autopct='%1.1f%%')
else:
# 3. Diagramme camembert
fig = df.plot.pie(y='ventes', legend=False)
fig.set_title(title)
fig.set_ylabel('Zone géographique')
fig.set_ylabel('Ventes (en millions)')
plot_ventes_jeu(cur, 'Mario Kart 64')
# 5. Résultats de Mario Kart Wii
plot_ventes_jeu(cur, 'Mario Kart Wii')
# Partie 5
# 1/2. Pourcentage du total des ventes par genre
df = pandas.read_sql("""SELECT genre, SUM(ventes_total) total_ventes FROM plain_jeu
GROUP BY genre;""", con=connection)
df.set_index('genre', inplace=True)
# 3. Diagramme camembert
fig = df.plot.pie(y='total_ventes', legend=False, autopct='%1.1f%%')
fig.set_title('Ventes mondiales de jeux vidéos par genre')
fig.set_ylabel('')
# 4. 4 camemberts du total des ventes par genre et par
df = pandas.read_sql("""
SELECT CASE WHEN annee_sortie < 1990 THEN '< 1990'
WHEN annee_sortie BETWEEN 1990 AND 1999 THEN '<=> 1990-1999'
WHEN annee_sortie BETWEEN 2000 AND 2009 THEN '<=> 2000-2009'
WHEN annee_sortie >= 2010 THEN '>= 2010'
END annee,
genre,
SUM(ventes_total) ventes_totales
FROM plain_jeu
WHERE annee_sortie IS NOT NULL
GROUP BY annee, genre
ORDER BY annee, genre;""", con=connection)
grouped = df.groupby('annee')
rowlength = grouped.ngroups // 2
fig, axs = plt.subplots(figsize=(9, 4), nrows=2, ncols=rowlength)
targets = zip(grouped.groups.keys(), axs.flatten())
legend = []
for i, (key, ax) in enumerate(targets):
group = grouped.get_group(key)
legend = group['genre']
ax = group.plot.pie(ax=ax, y='ventes_totales', labels=None, legend=False, colors=plt.cm.tab20.colors)
ax.set_ylabel('')
ax.set_title(key)
fig.legend(legend)
fig.suptitle('Ventes de jeux vidéos par genre et par période')
plt.show()
cur.close()
connection.close()

@ -0,0 +1,9 @@
\i tables.sql
\i pays.sql
\i discipline.sql
\i athletes.sql
\i pratiquer.sql
\i epreuve.sql
\i resultats.sql
\d

@ -0,0 +1,208 @@
INSERT INTO Pays VALUES('NOR','Norway');
INSERT INTO Pays VALUES('ESP','Spain');
INSERT INTO Pays VALUES('ITA','Italy');
INSERT INTO Pays VALUES('FRA','France');
INSERT INTO Pays VALUES('CHI','Chile');
INSERT INTO Pays VALUES('SUD','Sudan');
INSERT INTO Pays VALUES('IRI','Islamic Republic of Iran');
INSERT INTO Pays VALUES('AZE','Azerbaijan');
INSERT INTO Pays VALUES('NED','Netherlands');
INSERT INTO Pays VALUES('AUS','Australia');
INSERT INTO Pays VALUES('USA','United States of America');
INSERT INTO Pays VALUES('QAT','Qatar');
INSERT INTO Pays VALUES('EGY','Egypt');
INSERT INTO Pays VALUES('BEL','Belgium');
INSERT INTO Pays VALUES('MAS','Malaysia');
INSERT INTO Pays VALUES('SGP','Singapore');
INSERT INTO Pays VALUES('MDV','Maldives');
INSERT INTO Pays VALUES('KSA','Saudi Arabia');
INSERT INTO Pays VALUES('GER','Germany');
INSERT INTO Pays VALUES('UZB','Uzbekistan');
INSERT INTO Pays VALUES('INA','Indonesia');
INSERT INTO Pays VALUES('KAZ','Kazakhstan');
INSERT INTO Pays VALUES('BRN','Bahrain');
INSERT INTO Pays VALUES('JPN','Japan');
INSERT INTO Pays VALUES('ETH','Ethiopia');
INSERT INTO Pays VALUES('CAN','Canada');
INSERT INTO Pays VALUES('MLT','Malta');
INSERT INTO Pays VALUES('SRI','Sri Lanka');
INSERT INTO Pays VALUES('MAR','Morocco');
INSERT INTO Pays VALUES('AUT','Austria');
INSERT INTO Pays VALUES('MTN','Mauritania');
INSERT INTO Pays VALUES('ROC','ROC');
INSERT INTO Pays VALUES('BRA','Brazil');
INSERT INTO Pays VALUES('LBA','Libya');
INSERT INTO Pays VALUES('NRU','Nauru');
INSERT INTO Pays VALUES('SUI','Switzerland');
INSERT INTO Pays VALUES('RSA','South Africa');
INSERT INTO Pays VALUES('GUY','Guyana');
INSERT INTO Pays VALUES('GEO','Georgia');
INSERT INTO Pays VALUES('POR','Portugal');
INSERT INTO Pays VALUES('JOR','Jordan');
INSERT INTO Pays VALUES('PLE','Palestine');
INSERT INTO Pays VALUES('IND','India');
INSERT INTO Pays VALUES('CYP','Cyprus');
INSERT INTO Pays VALUES('NGR','Nigeria');
INSERT INTO Pays VALUES('TUN','Tunisia');
INSERT INTO Pays VALUES('SRB','Serbia');
INSERT INTO Pays VALUES('MEX','Mexico');
INSERT INTO Pays VALUES('COL','Colombia');
INSERT INTO Pays VALUES('ESA','El Salvador');
INSERT INTO Pays VALUES('ROU','Romania');
INSERT INTO Pays VALUES('POL','Poland');
INSERT INTO Pays VALUES('FSM','Federated States of Micronesia');
INSERT INTO Pays VALUES('NZL','New Zealand');
INSERT INTO Pays VALUES('TUR','Turkey');
INSERT INTO Pays VALUES('SWE','Sweden');
INSERT INTO Pays VALUES('GBR','Great Britain');
INSERT INTO Pays VALUES('HUN','Hungary');
INSERT INTO Pays VALUES('LTU','Lithuania');
INSERT INTO Pays VALUES('PUR','Puerto Rico');
INSERT INTO Pays VALUES('ANG','Angola');
INSERT INTO Pays VALUES('CGO','Congo');
INSERT INTO Pays VALUES('MON','Monaco');
INSERT INTO Pays VALUES('RWA','Rwanda');
INSERT INTO Pays VALUES('KEN','Kenya');
INSERT INTO Pays VALUES('ARM','Armenia');
INSERT INTO Pays VALUES('SAM','Samoa (until 1996 Western Samoa)');
INSERT INTO Pays VALUES('BRU','Brunei Darussalam');
INSERT INTO Pays VALUES('BAN','Bangladesh');
INSERT INTO Pays VALUES('KOR','Republic of Korea');
INSERT INTO Pays VALUES('BEN','Benin');
INSERT INTO Pays VALUES('CIV','Côte d''Ivoire');
INSERT INTO Pays VALUES('TTO','Trinidad and Tobago');
INSERT INTO Pays VALUES('CHN','People''s Republic of China');
INSERT INTO Pays VALUES('SEN','Senegal');
INSERT INTO Pays VALUES('ALG','Algeria');
INSERT INTO Pays VALUES('TJK','Tajikistan');
INSERT INTO Pays VALUES('PAK','Pakistan');
INSERT INTO Pays VALUES('KGZ','Kyrgyzstan');
INSERT INTO Pays VALUES('LAT','Latvia');
INSERT INTO Pays VALUES('OMA','Oman');
INSERT INTO Pays VALUES('KUW','Kuwait');
INSERT INTO Pays VALUES('IRQ','Iraq');
INSERT INTO Pays VALUES('EOR','EOR');
INSERT INTO Pays VALUES('YEM','Yemen');
INSERT INTO Pays VALUES('ISR','Israel');
INSERT INTO Pays VALUES('CUB','Cuba');
INSERT INTO Pays VALUES('ARG','Argentina');
INSERT INTO Pays VALUES('UKR','Ukraine');
INSERT INTO Pays VALUES('UAE','United Arab Emirates');
INSERT INTO Pays VALUES('NIG','Niger');
INSERT INTO Pays VALUES('DJI','Djibouti');
INSERT INTO Pays VALUES('SOM','Somalia');
INSERT INTO Pays VALUES('BUL','Bulgaria');
INSERT INTO Pays VALUES('BER','Bermuda');
INSERT INTO Pays VALUES('IRL','Ireland');
INSERT INTO Pays VALUES('JAM','Jamaica');
INSERT INTO Pays VALUES('EST','Estonia');
INSERT INTO Pays VALUES('PAR','Paraguay');
INSERT INTO Pays VALUES('CRC','Costa Rica');
INSERT INTO Pays VALUES('DOM','Dominican Republic');
INSERT INTO Pays VALUES('HON','Honduras');
INSERT INTO Pays VALUES('CPV','Cape Verde');
INSERT INTO Pays VALUES('GRE','Greece');
INSERT INTO Pays VALUES('VEN','Venezuela');
INSERT INTO Pays VALUES('UGA','Uganda');
INSERT INTO Pays VALUES('PER','Peru');
INSERT INTO Pays VALUES('BLR','Belarus');
INSERT INTO Pays VALUES('SMR','San Marino');
INSERT INTO Pays VALUES('GHA','Ghana');
INSERT INTO Pays VALUES('ECU','Ecuador');
INSERT INTO Pays VALUES('BOT','Botswana');
INSERT INTO Pays VALUES('BAH','Bahamas');
INSERT INTO Pays VALUES('DEN','Denmark');
INSERT INTO Pays VALUES('PHI','Philippines');
INSERT INTO Pays VALUES('GUM','Guam');
INSERT INTO Pays VALUES('MAD','Madagascar');
INSERT INTO Pays VALUES('HAI','Haiti');
INSERT INTO Pays VALUES('CZE','Czech Republic');
INSERT INTO Pays VALUES('MNE','Montenegro');
INSERT INTO Pays VALUES('AFG','Afghanistan');
INSERT INTO Pays VALUES('URU','Uruguay');
INSERT INTO Pays VALUES('PAN','Panama');
INSERT INTO Pays VALUES('FIN','Finland');
INSERT INTO Pays VALUES('CMR','Cameroon');
INSERT INTO Pays VALUES('SYR','Syrian Arab Republic');
INSERT INTO Pays VALUES('TKM','Turkmenistan');
INSERT INTO Pays VALUES('HKG','Hong Kong, China');
INSERT INTO Pays VALUES('TOG','Togo');
INSERT INTO Pays VALUES('SEY','Seychelles');
INSERT INTO Pays VALUES('MGL','Mongolia');
INSERT INTO Pays VALUES('SLO','Slovenia');
INSERT INTO Pays VALUES('GUI','Guinea');
INSERT INTO Pays VALUES('SVK','Slovakia');
INSERT INTO Pays VALUES('FIJ','Fiji');
INSERT INTO Pays VALUES('ZAM','Zambia');
INSERT INTO Pays VALUES('NCA','Nicaragua');
INSERT INTO Pays VALUES('SLE','Sierra Leone');
INSERT INTO Pays VALUES('GUA','Guatemala');
INSERT INTO Pays VALUES('PNG','Papua New Guinea');
INSERT INTO Pays VALUES('GAM','Gambia');
INSERT INTO Pays VALUES('LBN','LBN');
INSERT INTO Pays VALUES('COK','Cook Islands');
INSERT INTO Pays VALUES('BAR','Barbados');
INSERT INTO Pays VALUES('LUX','Luxembourg');
INSERT INTO Pays VALUES('MDA','Republic of Moldova');
INSERT INTO Pays VALUES('NEP','Nepal');
INSERT INTO Pays VALUES('CRO','Croatia');
INSERT INTO Pays VALUES('KIR','Kiribati');
INSERT INTO Pays VALUES('MKD','North Macedonia');
INSERT INTO Pays VALUES('MAW','Malawi');
INSERT INTO Pays VALUES('COD','Democratic Republic of the Congo');
INSERT INTO Pays VALUES('LAO','Lao People''s Democratic Republic');
INSERT INTO Pays VALUES('THA','Thailand');
INSERT INTO Pays VALUES('VIN','St Vincent and the Grenadines');
INSERT INTO Pays VALUES('ALB','Albania');
INSERT INTO Pays VALUES('GBS','Guinea-Bissau');
INSERT INTO Pays VALUES('BOL','Bolivia');
INSERT INTO Pays VALUES('BIH','Bosnia and Herzegovina');
INSERT INTO Pays VALUES('TPE','Chinese Taipei');
INSERT INTO Pays VALUES('LCA','Saint Lucia');
INSERT INTO Pays VALUES('PLW','Palau');
INSERT INTO Pays VALUES('MRI','Mauritius');
INSERT INTO Pays VALUES('SKN','Saint Kitts and Nevis');
INSERT INTO Pays VALUES('CAY','Cayman Islands');
INSERT INTO Pays VALUES('ASA','American Samoa');
INSERT INTO Pays VALUES('BIZ','Belize');
INSERT INTO Pays VALUES('VAN','Vanuatu');
INSERT INTO Pays VALUES('STP','Sao Tome and Principe');
INSERT INTO Pays VALUES('TLS','Timor-Leste');
INSERT INTO Pays VALUES('ISV','Virgin Islands, US');
INSERT INTO Pays VALUES('ERI','Eritrea');
INSERT INTO Pays VALUES('MLI','Mali');
INSERT INTO Pays VALUES('BUR','Burkina Faso');
INSERT INTO Pays VALUES('TGA','Tonga');
INSERT INTO Pays VALUES('NAM','Namibia');
INSERT INTO Pays VALUES('VIE','Vietnam');
INSERT INTO Pays VALUES('SWZ','Eswatini');
INSERT INTO Pays VALUES('AND','Andorra');
INSERT INTO Pays VALUES('ARU','Aruba');
INSERT INTO Pays VALUES('COM','Comoros');
INSERT INTO Pays VALUES('GEQ','Equatorial Guinea');
INSERT INTO Pays VALUES('LBR','Liberia');
INSERT INTO Pays VALUES('GRN','Grenada');
INSERT INTO Pays VALUES('SOL','Solomon Islands');
INSERT INTO Pays VALUES('MHL','Marshall Islands');
INSERT INTO Pays VALUES('BDI','Burundi');
INSERT INTO Pays VALUES('TAN','United Republic of Tanzania');
INSERT INTO Pays VALUES('GAB','Gabon');
INSERT INTO Pays VALUES('KOS','Kosovo');
INSERT INTO Pays VALUES('ANT','Antigua and Barbuda');
INSERT INTO Pays VALUES('MOZ','Mozambique');
INSERT INTO Pays VALUES('ISL','Iceland');
INSERT INTO Pays VALUES('SSD','South Sudan');
INSERT INTO Pays VALUES('LIE','Liechtenstein');
INSERT INTO Pays VALUES('CAM','Cambodia');
INSERT INTO Pays VALUES('CHA','Chad');
INSERT INTO Pays VALUES('BHU','Bhutan');
INSERT INTO Pays VALUES('ZIM','Zimbabwe');
INSERT INTO Pays VALUES('LES','Lesotho');
INSERT INTO Pays VALUES('DMA','Dominique');
INSERT INTO Pays VALUES('TUV','Tuvalu');
INSERT INTO Pays VALUES('IVB','Virgin Islands, British');
INSERT INTO Pays VALUES('CAF','Central African Republic');
INSERT INTO Pays VALUES('MYA','Myanmar');
INSERT INTO Pays VALUES('SUR','Suriname');
INSERT INTO Pays VALUES('RUS','Russian Federation');
INSERT INTO Pays VALUES('URS','URSS');

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,79 @@
DROP TABLE IF EXISTS Present;
DROP TABLE IF EXISTS Resultat_FR;
DROP TABLE IF EXISTS Resultat;
DROP TABLE IF EXISTS Medaille;
DROP TABLE IF EXISTS Epreuve;
DROP TABLE IF EXISTS Pratiquer;
DROP TABLE IF EXISTS Athlete;
DROP TABLE IF EXISTS Discipline;
DROP TABLE IF EXISTS Pays;
CREATE TABLE Pays(
code char(3) PRIMARY KEY,
nom varchar(40) UNIQUE NOT NULL
);
CREATE TABLE Discipline(
code char(3) PRIMARY KEY,
nom varchar(40) UNIQUE NOT NULL
);
CREATE TABLE Athlete(
code char(6) PRIMARY KEY,
nom varchar(40) NOT NULL,
prenom varchar(40) NOT NULL,
sexe char(1) CHECK(sexe IN('F','M')),
dateNaiss date,
paysNaiss char(3) REFERENCES Pays,
pays char(3) NOT NULL REFERENCES Pays,
taille numeric(3,2)
);
CREATE TABLE Pratiquer(
athlete char(6) REFERENCES Athlete,
discipl char(3) REFERENCES Discipline,
PRIMARY KEY(athlete, discipl)
);
CREATE TABLE Epreuve(
code char(4) PRIMARY KEY,
discipl char(3) NOT NULL REFERENCES Discipline,
nom varchar(55) NOT NULL,
dateE date NOT NULL
);
CREATE TABLE Medaille(
place numeric(1) PRIMARY KEY,
couleur varchar(6)
);
CREATE TABLE Resultat(
epreuve char(4) REFERENCES Epreuve,
athlete char(6) REFERENCES Athlete,
medaille numeric(1) REFERENCES Medaille,
PRIMARY KEY(epreuve,athlete)
);
INSERT INTO Medaille VALUES(1,'Or');
INSERT INTO Medaille VALUES(2,'Argent');
INSERT INTO Medaille VALUES(3,'Bronze');
/*
disciplrel2, 0N Discipline, 11 Epreuve:
Discipline: code, nom
Pratiquer, 0N Athlete, 0N Discipline:
:
Epreuve: code, nom, dateE
Resultat, 0N Athlete, 0N Epreuve, 0N Medaille:
Athlete: code, nom, prenom, sexe, dateNaiss, taille
Resider, 0N Pays, 11 Athlete:
:
Medaille: place, couleur
Etre né, 0N Pays, 01 Athlete:
Pays: code, nom
*/

@ -0,0 +1,72 @@
year,population,labor_force,population_percent,employed_total,employed_percent,agrictulture_ratio,nonagriculture_ratio,unemployed,unemployed_percent,not_in_labor,footnotes
1941,99900,55910,56.0,50350,50.4,9100,41250,5560,9.9,43990,
1942,98640,56410,57.2,53750,54.5,9250,44500,2660,4.7,42230,
1943,94640,55540,58.7,54470,57.6,9080,45390,1070,1.9,39100,
1944,93220,54630,58.6,53960,57.9,8950,45010,670,1.2,38590,
1945,94090,53860,57.2,52820,56.1,8580,44240,1040,1.9,40230,
1946,103070,57520,55.8,55250,53.6,8320,46930,2270,3.9,45550,
1947,106018,60168,56.8,57812,54.5,8256,49557,2356,3.9,45850,
1947,101827,59350,58.3,57038,56.0,7890,49148,2311,3.9,42477,
1948,103068,60621,58.8,58343,56.6,7629,50714,2276,3.8,42447,
1949,103994,61286,58.9,57651,55.4,7658,49993,3637,5.9,42708,
1950,104995,62208,59.2,58918,56.1,7160,51758,3288,5.3,42787,
1951,104621,62017,59.2,59961,57.3,6726,53235,2055,3.3,42604,
1952,105231,62138,59.0,60250,57.3,6500,53749,1883,3.0,43093,
1953,107056,63015,58.9,61179,57.1,6260,54919,1834,2.9,44041,1
1954,108321,63643,58.8,60109,55.5,6205,53904,3532,5.5,44678,
1955,109683,65023,59.3,62170,56.7,6450,55722,2852,4.4,44660,
1956,110954,66552,60.0,63799,57.5,6283,57514,2750,4.1,44402,
1957,112265,66929,59.6,64071,57.1,5947,58123,2859,4.3,45336,
1958,113727,67639,59.5,63036,55.4,5586,57450,4602,6.8,46088,
1959,115329,68369,59.3,64630,56.0,5565,59065,3740,5.5,46960,
1960,117245,69628,59.4,65778,56.1,5458,60318,3852,5.5,47617,1
1961,118771,70459,59.3,65746,55.4,5200,60546,4714,6.7,48312,
1962,120153,70614,58.8,66702,55.5,4944,61759,3911,5.5,49539,1
1963,122416,71833,58.7,67762,55.4,4687,63076,4070,5.7,50583,
1964,124485,73091,58.7,69305,55.7,4523,64782,3786,5.2,51394,
1965,126513,74455,58.9,71088,56.2,4361,66726,3366,4.5,52058,
1966,128058,75770,59.2,72895,56.9,3979,68915,2875,3.8,52288,
1967,129874,77347,59.6,74372,57.3,3844,70527,2975,3.8,52527,
1968,132028,78737,59.6,75920,57.5,3817,72103,2817,3.6,53291,
1969,134335,80734,60.1,77902,58.0,3606,74296,2832,3.5,53602,
1970,137085,82771,60.4,78678,57.4,3463,75215,4093,4.9,54315,
1971,140216,84382,60.2,79367,56.6,3394,75972,5016,5.9,55834,
1972,144126,87034,60.4,82153,57.0,3484,78669,4882,5.6,57091,1
1973,147096,89429,60.8,85064,57.8,3470,81594,4365,4.9,57667,1
1974,150120,91949,61.3,86794,57.8,3515,83279,5156,5.6,58171,
1975,153153,93774,61.2,85846,56.1,3408,82438,7929,8.5,59377,
1976,156150,96158,61.6,88752,56.8,3331,85421,7406,7.7,59991,
1977,159033,99008,62.3,92017,57.9,3283,88734,6991,7.1,60025,
1978,161910,102250,63.2,96048,59.3,3387,92661,6202,6.1,59659,1
1979,164863,104962,63.7,98824,59.9,3347,95477,6137,5.8,59900,
1980,167745,106940,63.8,99302,59.2,3364,95938,7637,7.1,60806,
1981,170130,108670,63.9,100397,59.0,3368,97030,8273,7.6,61460,
1982,172271,110204,64.0,99526,57.8,3401,96125,10678,9.7,62067,
1983,174215,111550,64.0,100834,57.9,3383,97450,10717,9.6,62665,
1984,176383,113544,64.4,105005,59.5,3321,101685,8539,7.5,62839,
1985,178206,115461,64.8,107150,60.1,3179,103971,8312,7.2,62744,
1986,180587,117834,65.3,109597,60.7,3163,106434,8237,7.0,62752,1
1987,182753,119865,65.6,112440,61.5,3208,109232,7425,6.2,62888,
1988,184613,121669,65.9,114968,62.3,3169,111800,6701,5.5,62944,
1989,186393,123869,66.5,117342,63.0,3199,114142,6528,5.3,62523,
1990,189164,125840,66.5,118793,62.8,3223,115570,7047,5.6,63324,1
1991,190925,126346,66.2,117718,61.7,3269,114449,8628,6.8,64578,
1992,192805,128105,66.4,118492,61.5,3247,115245,9613,7.5,64700,
1993,194838,129200,66.3,120259,61.7,3115,117144,8940,6.9,65638,
1994,196814,131056,66.6,123060,62.5,3409,119651,7996,6.1,65758,1
1995,198584,132304,66.6,124900,62.9,3440,121460,7404,5.6,66280,
1996,200591,133943,66.8,126708,63.2,3443,123264,7236,5.4,66647,
1997,203133,136297,67.1,129558,63.8,3399,126159,6739,4.9,66836,1
1998,205220,137673,67.1,131463,64.1,3378,128085,6210,4.5,67547,1
1999,207753,139368,67.1,133488,64.3,3281,130207,5880,4.2,68385,1
2000,212577,142583,67.1,136891,64.4,2464,134427,5692,4.0,69994,1
2001,215092,143734,66.8,136933,63.7,2299,134635,6801,4.7,71359,
2002,217570,144863,66.6,136485,62.7,2311,134174,8378,5.8,72707,
2003,221168,146510,66.2,137736,62.3,2275,135461,8774,6.0,74658,1
2004,223357,147401,66.0,139252,62.3,2232,137020,8149,5.5,75956,1
2005,226082,149320,66.0,141730,62.7,2197,139532,7591,5.1,76762,1
2006,228815,151428,66.2,144427,63.1,2206,142221,7001,4.6,77387,1
2007,231867,153124,66.0,146047,63.0,2095,143952,7078,4.6,78743,1
2008,233788,154287,66.0,145362,62.2,2168,143194,8924,5.8,79501,1
2009,235801,154142,65.4,139877,59.3,2103,137775,14265,9.3,81659,1
2010,237830,153889,64.7,139064,58.5,2206,136858,14825,9.6,83941,1
1 year population labor_force population_percent employed_total employed_percent agrictulture_ratio nonagriculture_ratio unemployed unemployed_percent not_in_labor footnotes
2 1941 99900 55910 56.0 50350 50.4 9100 41250 5560 9.9 43990
3 1942 98640 56410 57.2 53750 54.5 9250 44500 2660 4.7 42230
4 1943 94640 55540 58.7 54470 57.6 9080 45390 1070 1.9 39100
5 1944 93220 54630 58.6 53960 57.9 8950 45010 670 1.2 38590
6 1945 94090 53860 57.2 52820 56.1 8580 44240 1040 1.9 40230
7 1946 103070 57520 55.8 55250 53.6 8320 46930 2270 3.9 45550
8 1947 106018 60168 56.8 57812 54.5 8256 49557 2356 3.9 45850
9 1947 101827 59350 58.3 57038 56.0 7890 49148 2311 3.9 42477
10 1948 103068 60621 58.8 58343 56.6 7629 50714 2276 3.8 42447
11 1949 103994 61286 58.9 57651 55.4 7658 49993 3637 5.9 42708
12 1950 104995 62208 59.2 58918 56.1 7160 51758 3288 5.3 42787
13 1951 104621 62017 59.2 59961 57.3 6726 53235 2055 3.3 42604
14 1952 105231 62138 59.0 60250 57.3 6500 53749 1883 3.0 43093
15 1953 107056 63015 58.9 61179 57.1 6260 54919 1834 2.9 44041 1
16 1954 108321 63643 58.8 60109 55.5 6205 53904 3532 5.5 44678
17 1955 109683 65023 59.3 62170 56.7 6450 55722 2852 4.4 44660
18 1956 110954 66552 60.0 63799 57.5 6283 57514 2750 4.1 44402
19 1957 112265 66929 59.6 64071 57.1 5947 58123 2859 4.3 45336
20 1958 113727 67639 59.5 63036 55.4 5586 57450 4602 6.8 46088
21 1959 115329 68369 59.3 64630 56.0 5565 59065 3740 5.5 46960
22 1960 117245 69628 59.4 65778 56.1 5458 60318 3852 5.5 47617 1
23 1961 118771 70459 59.3 65746 55.4 5200 60546 4714 6.7 48312
24 1962 120153 70614 58.8 66702 55.5 4944 61759 3911 5.5 49539 1
25 1963 122416 71833 58.7 67762 55.4 4687 63076 4070 5.7 50583
26 1964 124485 73091 58.7 69305 55.7 4523 64782 3786 5.2 51394
27 1965 126513 74455 58.9 71088 56.2 4361 66726 3366 4.5 52058
28 1966 128058 75770 59.2 72895 56.9 3979 68915 2875 3.8 52288
29 1967 129874 77347 59.6 74372 57.3 3844 70527 2975 3.8 52527
30 1968 132028 78737 59.6 75920 57.5 3817 72103 2817 3.6 53291
31 1969 134335 80734 60.1 77902 58.0 3606 74296 2832 3.5 53602
32 1970 137085 82771 60.4 78678 57.4 3463 75215 4093 4.9 54315
33 1971 140216 84382 60.2 79367 56.6 3394 75972 5016 5.9 55834
34 1972 144126 87034 60.4 82153 57.0 3484 78669 4882 5.6 57091 1
35 1973 147096 89429 60.8 85064 57.8 3470 81594 4365 4.9 57667 1
36 1974 150120 91949 61.3 86794 57.8 3515 83279 5156 5.6 58171
37 1975 153153 93774 61.2 85846 56.1 3408 82438 7929 8.5 59377
38 1976 156150 96158 61.6 88752 56.8 3331 85421 7406 7.7 59991
39 1977 159033 99008 62.3 92017 57.9 3283 88734 6991 7.1 60025
40 1978 161910 102250 63.2 96048 59.3 3387 92661 6202 6.1 59659 1
41 1979 164863 104962 63.7 98824 59.9 3347 95477 6137 5.8 59900
42 1980 167745 106940 63.8 99302 59.2 3364 95938 7637 7.1 60806
43 1981 170130 108670 63.9 100397 59.0 3368 97030 8273 7.6 61460
44 1982 172271 110204 64.0 99526 57.8 3401 96125 10678 9.7 62067
45 1983 174215 111550 64.0 100834 57.9 3383 97450 10717 9.6 62665
46 1984 176383 113544 64.4 105005 59.5 3321 101685 8539 7.5 62839
47 1985 178206 115461 64.8 107150 60.1 3179 103971 8312 7.2 62744
48 1986 180587 117834 65.3 109597 60.7 3163 106434 8237 7.0 62752 1
49 1987 182753 119865 65.6 112440 61.5 3208 109232 7425 6.2 62888
50 1988 184613 121669 65.9 114968 62.3 3169 111800 6701 5.5 62944
51 1989 186393 123869 66.5 117342 63.0 3199 114142 6528 5.3 62523
52 1990 189164 125840 66.5 118793 62.8 3223 115570 7047 5.6 63324 1
53 1991 190925 126346 66.2 117718 61.7 3269 114449 8628 6.8 64578
54 1992 192805 128105 66.4 118492 61.5 3247 115245 9613 7.5 64700
55 1993 194838 129200 66.3 120259 61.7 3115 117144 8940 6.9 65638
56 1994 196814 131056 66.6 123060 62.5 3409 119651 7996 6.1 65758 1
57 1995 198584 132304 66.6 124900 62.9 3440 121460 7404 5.6 66280
58 1996 200591 133943 66.8 126708 63.2 3443 123264 7236 5.4 66647
59 1997 203133 136297 67.1 129558 63.8 3399 126159 6739 4.9 66836 1
60 1998 205220 137673 67.1 131463 64.1 3378 128085 6210 4.5 67547 1
61 1999 207753 139368 67.1 133488 64.3 3281 130207 5880 4.2 68385 1
62 2000 212577 142583 67.1 136891 64.4 2464 134427 5692 4.0 69994 1
63 2001 215092 143734 66.8 136933 63.7 2299 134635 6801 4.7 71359
64 2002 217570 144863 66.6 136485 62.7 2311 134174 8378 5.8 72707
65 2003 221168 146510 66.2 137736 62.3 2275 135461 8774 6.0 74658 1
66 2004 223357 147401 66.0 139252 62.3 2232 137020 8149 5.5 75956 1
67 2005 226082 149320 66.0 141730 62.7 2197 139532 7591 5.1 76762 1
68 2006 228815 151428 66.2 144427 63.1 2206 142221 7001 4.6 77387 1
69 2007 231867 153124 66.0 146047 63.0 2095 143952 7078 4.6 78743 1
70 2008 233788 154287 66.0 145362 62.2 2168 143194 8924 5.8 79501 1
71 2009 235801 154142 65.4 139877 59.3 2103 137775 14265 9.3 81659 1
72 2010 237830 153889 64.7 139064 58.5 2206 136858 14825 9.6 83941 1

@ -0,0 +1,4 @@
digraph abc {
rankdir=LR;
a -> b -> c;
}

Binary file not shown.

@ -0,0 +1,172 @@
{
"AED": "United Arab Emirates Dirham",
"AFN": "Afghan Afghani",
"ALL": "Albanian Lek",
"AMD": "Armenian Dram",
"ANG": "Netherlands Antillean Guilder",
"AOA": "Angolan Kwanza",
"ARS": "Argentine Peso",
"AUD": "Australian Dollar",
"AWG": "Aruban Florin",
"AZN": "Azerbaijani Manat",
"BAM": "Bosnia-Herzegovina Convertible Mark",
"BBD": "Barbadian Dollar",
"BDT": "Bangladeshi Taka",
"BGN": "Bulgarian Lev",
"BHD": "Bahraini Dinar",
"BIF": "Burundian Franc",
"BMD": "Bermudan Dollar",
"BND": "Brunei Dollar",
"BOB": "Bolivian Boliviano",
"BRL": "Brazilian Real",
"BSD": "Bahamian Dollar",
"BTC": "Bitcoin",
"BTN": "Bhutanese Ngultrum",
"BWP": "Botswanan Pula",
"BYN": "Belarusian Ruble",
"BZD": "Belize Dollar",
"CAD": "Canadian Dollar",
"CDF": "Congolese Franc",
"CHF": "Swiss Franc",
"CLF": "Chilean Unit of Account (UF)",
"CLP": "Chilean Peso",
"CNH": "Chinese Yuan (Offshore)",
"CNY": "Chinese Yuan",
"COP": "Colombian Peso",
"CRC": "Costa Rican Colón",
"CUC": "Cuban Convertible Peso",
"CUP": "Cuban Peso",
"CVE": "Cape Verdean Escudo",
"CZK": "Czech Republic Koruna",
"DJF": "Djiboutian Franc",
"DKK": "Danish Krone",
"DOP": "Dominican Peso",
"DZD": "Algerian Dinar",
"EGP": "Egyptian Pound",
"ERN": "Eritrean Nakfa",
"ETB": "Ethiopian Birr",
"EUR": "Euro",
"FJD": "Fijian Dollar",
"FKP": "Falkland Islands Pound",
"GBP": "British Pound Sterling",
"GEL": "Georgian Lari",
"GGP": "Guernsey Pound",
"GHS": "Ghanaian Cedi",
"GIP": "Gibraltar Pound",
"GMD": "Gambian Dalasi",
"GNF": "Guinean Franc",
"GTQ": "Guatemalan Quetzal",
"GYD": "Guyanaese Dollar",
"HKD": "Hong Kong Dollar",
"HNL": "Honduran Lempira",
"HRK": "Croatian Kuna",
"HTG": "Haitian Gourde",
"HUF": "Hungarian Forint",
"IDR": "Indonesian Rupiah",
"ILS": "Israeli New Sheqel",
"IMP": "Manx pound",
"INR": "Indian Rupee",
"IQD": "Iraqi Dinar",
"IRR": "Iranian Rial",
"ISK": "Icelandic Króna",
"JEP": "Jersey Pound",
"JMD": "Jamaican Dollar",
"JOD": "Jordanian Dinar",
"JPY": "Japanese Yen",
"KES": "Kenyan Shilling",
"KGS": "Kyrgystani Som",
"KHR": "Cambodian Riel",
"KMF": "Comorian Franc",
"KPW": "North Korean Won",
"KRW": "South Korean Won",
"KWD": "Kuwaiti Dinar",
"KYD": "Cayman Islands Dollar",
"KZT": "Kazakhstani Tenge",
"LAK": "Laotian Kip",
"LBP": "Lebanese Pound",
"LKR": "Sri Lankan Rupee",
"LRD": "Liberian Dollar",
"LSL": "Lesotho Loti",
"LYD": "Libyan Dinar",
"MAD": "Moroccan Dirham",
"MDL": "Moldovan Leu",
"MGA": "Malagasy Ariary",
"MKD": "Macedonian Denar",
"MMK": "Myanma Kyat",
"MNT": "Mongolian Tugrik",
"MOP": "Macanese Pataca",
"MRU": "Mauritanian Ouguiya",
"MUR": "Mauritian Rupee",
"MVR": "Maldivian Rufiyaa",
"MWK": "Malawian Kwacha",
"MXN": "Mexican Peso",
"MYR": "Malaysian Ringgit",
"MZN": "Mozambican Metical",
"NAD": "Namibian Dollar",
"NGN": "Nigerian Naira",
"NIO": "Nicaraguan Córdoba",
"NOK": "Norwegian Krone",
"NPR": "Nepalese Rupee",
"NZD": "New Zealand Dollar",
"OMR": "Omani Rial",
"PAB": "Panamanian Balboa",
"PEN": "Peruvian Nuevo Sol",
"PGK": "Papua New Guinean Kina",
"PHP": "Philippine Peso",
"PKR": "Pakistani Rupee",
"PLN": "Polish Zloty",
"PYG": "Paraguayan Guarani",
"QAR": "Qatari Rial",
"RON": "Romanian Leu",
"RSD": "Serbian Dinar",
"RUB": "Russian Ruble",
"RWF": "Rwandan Franc",
"SAR": "Saudi Riyal",
"SBD": "Solomon Islands Dollar",
"SCR": "Seychellois Rupee",
"SDG": "Sudanese Pound",
"SEK": "Swedish Krona",
"SGD": "Singapore Dollar",
"SHP": "Saint Helena Pound",
"SLL": "Sierra Leonean Leone",
"SOS": "Somali Shilling",
"SRD": "Surinamese Dollar",
"SSP": "South Sudanese Pound",
"STD": "São Tomé and Príncipe Dobra (pre-2018)",
"STN": "São Tomé and Príncipe Dobra",
"SVC": "Salvadoran Colón",
"SYP": "Syrian Pound",
"SZL": "Swazi Lilangeni",
"THB": "Thai Baht",
"TJS": "Tajikistani Somoni",
"TMT": "Turkmenistani Manat",
"TND": "Tunisian Dinar",
"TOP": "Tongan Pa'anga",
"TRY": "Turkish Lira",
"TTD": "Trinidad and Tobago Dollar",
"TWD": "New Taiwan Dollar",
"TZS": "Tanzanian Shilling",
"UAH": "Ukrainian Hryvnia",
"UGX": "Ugandan Shilling",
"USD": "United States Dollar",
"UYU": "Uruguayan Peso",
"UZS": "Uzbekistan Som",
"VEF": "Venezuelan Bolívar Fuerte (Old)",
"VES": "Venezuelan Bolívar Soberano",
"VND": "Vietnamese Dong",
"VUV": "Vanuatu Vatu",
"WST": "Samoan Tala",
"XAF": "CFA Franc BEAC",
"XAG": "Silver Ounce",
"XAU": "Gold Ounce",
"XCD": "East Caribbean Dollar",
"XDR": "Special Drawing Rights",
"XOF": "CFA Franc BCEAO",
"XPD": "Palladium Ounce",
"XPF": "CFP Franc",
"XPT": "Platinum Ounce",
"YER": "Yemeni Rial",
"ZAR": "South African Rand",
"ZMW": "Zambian Kwacha",
"ZWL": "Zimbabwean Dollar"
}

@ -0,0 +1,4 @@
#!/bin/bash
sed -r 's/: psycopg2\.(connection|cursor)//' load.py > /tmp/patched_load.py
python3 /tmp/patched_load.py

@ -0,0 +1,171 @@
import pandas
import psycopg2 # pip3 install types-psycopg2
import matplotlib.pyplot as plt
from getpass import getpass
import json
import folium
from folium.plugins import BeautifyIcon
from typing import Union
def create_tables(connection: psycopg2.connection, filename: str):
cur = connection.cursor()
with open(filename) as f:
cur.execute(f.read())
connection.commit()
cur.close()
def load_currencies(connection: psycopg2.connection, filename: str):
cur = connection.cursor()
with open(filename) as f:
for iso, full_name in json.load(f).items():
cur.execute("INSERT INTO currency VALUES (%s, %s);", (iso, full_name))
connection.commit()
cur.close()
def format_price(price: Union[float, str]) -> float:
if isinstance(price, float):
return price
return float(price.replace(',', ''))
def format_award(award: str) -> int:
if award == '3 MICHELIN Stars':
return 3
if award == '2 MICHELIN Stars':
return 2
if award == '1 MICHELIN Star':
return 1
return 0
def color_award(stars: int) -> str:
if stars == 3:
return 'orange'
if stars == 2:
return '#c0c0c0'
if stars == 1:
return '#c49c48'
return '#132b5e'
def stars_radius(stars: int) -> int:
if stars > 1:
return 5
if stars == 1:
return 4
return 3
def load_restaurants(connection: psycopg2.connection, filename: str):
cur = connection.cursor()
df = pandas.DataFrame(pandas.read_csv(filename))
for row in df.itertuples():
cur.execute("INSERT INTO restaurant (name, location, min_price, max_price, currency, latitude, longitude, phone_number, url, website_url, stars) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) RETURNING id;",
(row.Name, row.Location, format_price(row.MinPrice), format_price(row.MaxPrice), row.Currency if not pandas.isnull(row.Currency) else None, row.Latitude, row.Longitude, row.PhoneNumber, row.Url, row.WebsiteUrl, format_award(row.Award))
)
restaurant_id = cur.fetchone()[0]
for cuisine in row.Cuisine.split(', '):
#cur.execute("INSERT INTO cuisine (name) VALUES (%s) ON CONFLICT DO NOTHING RETURNING id;", (cuisine,))
cur.execute("INSERT INTO cuisine (name) VALUES (%s) ON CONFLICT (name) DO UPDATE SET name = EXCLUDED.name RETURNING id;", (cuisine,))
cuisine_id = cur.fetchone()[0]
cur.execute("INSERT INTO cuisine_restaurant VALUES (%s, %s);", (restaurant_id, cuisine_id))
connection.commit()
cur.close()
def cuisine(connection: psycopg2.connection):
df = pandas.read_sql("""SELECT c.name, COUNT(*) restaurants
FROM cuisine_restaurant cr
INNER JOIN cuisine c ON c.id = cr.cuisine
GROUP BY c.id
ORDER BY 2 DESC
LIMIT 20;""", con=connection)
fig = df.plot.barh(x='name', y='restaurants', legend=False)
fig.invert_yaxis()
fig.set_title('Most common cuisine types in the Michelin guide')
fig.set_xlabel('Cuisine type')
fig.set_ylabel('Number of restaurants')
fig.bar_label(fig.containers[0]) # Show values
def currencies(connection: psycopg2.connection):
df = pandas.read_sql("""SELECT c.iso, c.full_name, COUNT(*) restaurants
FROM restaurant r
INNER JOIN currency c ON c.iso = r.currency
GROUP BY c.iso
ORDER BY 3 DESC
LIMIT 10;""", con=connection)
fig = df.plot.bar(x='iso', y='restaurants', legend=False, rot=0)
fig.set_title('Most common accepted currencies in the Michelin guide')
fig.set_xlabel('Currency')
fig.set_ylabel('Number of restaurants')
fig.bar_label(fig.containers[0]) # Show values
def prices(connection: psycopg2.connection):
df = pandas.read_sql("""SELECT CASE WHEN min_price < 10 THEN '< 10'
WHEN min_price >= 10 AND min_price < 15 THEN '[10;15['
WHEN min_price >= 15 AND min_price < 20 THEN '[15;20['
WHEN min_price >= 20 AND min_price < 30 THEN '[20;30['
WHEN min_price >= 30 AND min_price < 50 THEN '[30;50['
WHEN min_price >= 50 AND min_price < 100 THEN '[50;100['
WHEN min_price >= 100 AND min_price < 200 THEN '[100;200['
WHEN min_price >= 200 AND min_price < 500 THEN '[200;500['
WHEN min_price >= 500 AND min_price < 1000 THEN '[500;1000['
WHEN min_price >= 1000 THEN '>= 1000'
END min_price_range,
COUNT(*) nb
FROM restaurant
WHERE currency = 'EUR'
GROUP BY min_price_range;""", con=connection)
fig = df.plot.pie(y='nb', labels=df['min_price_range'], legend=False)
def map(connection: psycopg2.connection):
map_osm = folium.Map(zoom_start=4)
groups = [folium.FeatureGroup('Bib Gourmand' if stars == 0 else str(stars) + ' stars') for stars in range(4)]
df = pandas.read_sql("""SELECT latitude, longitude, name, min_price, max_price, currency, stars FROM restaurant;""", con=connection)
#df['color'] = df.apply(color_award, axis=1)
for _, latitude, longitude, name, min_price, max_price, currency, stars in df[['latitude', 'longitude', 'name', 'min_price', 'max_price', 'currency', 'stars']].itertuples():
is_star = stars != 0
popup = (
"<strong>{name}</strong><br>"
"From {min_price} to {max_price} {currency}<br>"
"{award}<br>"
"______________________"
).format(name=name, min_price=min_price, max_price=max_price, currency=currency, award=str(stars) + ' stars' if is_star else 'Bib Gourmand')
color = color_award(stars)
if stars == 3:
icon = BeautifyIcon(icon='star', inner_icon_style=('color:' + color), border_color='transparent', background_color='transparent')
folium.Marker(location=[latitude, longitude], popup=popup, radius=stars_radius(stars), fill=True, fill_opacity=1, icon=icon).add_to(groups[stars])
else:
folium.CircleMarker(location=[latitude, longitude], popup=popup, color=color, fill_color=color, radius=stars_radius(stars), fill=True, fill_opacity=1).add_to(groups[stars])
for group in groups:
map_osm.add_child(group)
map_osm.add_child(folium.map.LayerControl())
map_osm.save('/tmp/test_map.html')
if __name__ == '__main__':
db_host = input('Nom d\'hôte : ')
if not db_host:
db_host = 'berlin'
db_name = input('Nom de la base de données : ')
if not db_name:
db_name = 'dbclfreville2'
db_user = input('Utilisateur : ')
if not db_user:
db_user = 'clfreville2'
db_password = getpass('Mot de passe : ')
connection = psycopg2.connect(host=db_host, port=5432, database=db_name, user=db_user, password=db_password)
#create_tables(connection, 'table.sql')
#load_currencies(connection, 'currencies.json')
#load_restaurants(connection, 'michelin_my_maps.csv')
cuisine(connection)
currencies(connection)
prices(connection)
#map(connection)
connection.close()
plt.show()

@ -0,0 +1,84 @@
import pandas
import psycopg2 # pip3 install types-psycopg2
import matplotlib.pyplot as plt
from getpass import getpass
from calendar import month_abbr
from typing import Dict
# Create a mapping
# month name to int value
month_to_int: Dict[str, int] = dict((val, name) for name, val in enumerate(month_abbr))
def create_table(connection: psycopg2.connection, filename: str):
cur = connection.cursor()
cur.execute("""CREATE TABLE IF NOT EXISTS unemployment (
year_month DATE PRIMARY KEY,
primary_school NUMERIC(4, 2) NOT NULL CHECK (primary_school >= 0),
high_school NUMERIC(4, 2) NOT NULL CHECK (high_school >= 0),
associates_degree NUMERIC(4, 2) NOT NULL CHECK (associates_degree >= 0),
professional_degree NUMERIC(4, 2) NOT NULL CHECK (professional_degree >= 0),
white NUMERIC(4, 2) NOT NULL CHECK (white >= 0),
black NUMERIC(4, 2) NOT NULL CHECK (black >= 0),
asian NUMERIC(4, 2) NOT NULL CHECK (asian >= 0),
hispanic NUMERIC(4, 2) NOT NULL CHECK (hispanic >= 0),
men NUMERIC(4, 2) NOT NULL CHECK (men >= 0),
woman NUMERIC(4, 2) NOT NULL CHECK (woman >= 0)
);""")
df = pandas.DataFrame(pandas.read_csv(filename)).dropna()
for row in df.itertuples():
cur.execute("INSERT INTO unemployment VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);",
(str(row.Year) + '-' + str(month_to_int[row.Month]) + '-1', row.Primary_School, row.High_School, row.Associates_Degree, row.Professional_Degree, row.White, row.Black, row.Asian, row.Hispanic, row.Men, row.Women))
connection.commit()
cur.close()
def append_data(connection: psycopg2.connection, filename: str):
# https://datahub.io/core/employment-us
cur = connection.cursor()
df = pandas.DataFrame(pandas.read_csv(filename)).dropna()
for row in df.itertuples():
cur.execute("INSERT INTO unemployment VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);",
(str(row.Year) + '-' + str(month_to_int[row.Month]) + '-1', row.Primary_School, row.High_School, row.Associates_Degree, row.Professional_Degree, row.White, row.Black, row.Asian, row.Hispanic, row.Men, row.Women))
connection.commit()
cur.close()
def graph_evolution(connection: psycopg2.connection):
df = pandas.read_sql("""SELECT * FROM unemployment ORDER BY year_month;""", con=connection)
fig = df.plot(x='year_month', y=['primary_school', 'high_school', 'associates_degree', 'professional_degree'])
fig.set_xlabel('Period')
fig.set_ylabel('Unemployement percentage')
fig = df.plot(x='year_month', y=['white', 'black', 'asian', 'hispanic'])
fig.set_xlabel('Period')
fig.set_ylabel('Unemployement percentage')
fig = df.plot(x='year_month', y=['men', 'woman'])
fig.set_xlabel('Period')
fig.set_ylabel('Unemployement percentage')
if __name__ == '__main__':
db_host = input('Nom d\'hôte : ')
if not db_host:
db_host = 'berlin'
db_name = input('Nom de la base de données : ')
if not db_name:
db_name = 'dbclfreville2'
db_user = input('Utilisateur : ')
if not db_user:
db_user = 'clfreville2'
db_password = getpass('Mot de passe : ')
connection = psycopg2.connect(host=db_host, port=5432, database=db_name, user=db_user, password=db_password)
#create_table(connection, 'unemployment_data_us.csv')
graph_evolution(connection)
connection.close()
plt.show()

File diff suppressed because it is too large Load Diff

@ -0,0 +1,40 @@
digraph mld {
node [shape=plain]
rankdir=LR;
N0[label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>currency</i></td></tr>
<tr><td><u>iso</u></td></tr>
<tr><td>full_name</td></tr>
</table>>];
N1[label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>cuisine</i></td></tr>
<tr><td><u>id</u></td></tr>
<tr><td>name</td></tr>
</table>>];
N2[label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>restaurant</i></td></tr>
<tr><td><u>id</u></td></tr>
<tr><td>name</td></tr>
<tr><td>location</td></tr>
<tr><td>min_price</td></tr>
<tr><td>max_price</td></tr>
<tr><td>##currency</td></tr>
<tr><td>latitude</td></tr>
<tr><td>longitude</td></tr>
<tr><td>phone_number</td></tr>
<tr><td>url</td></tr>
<tr><td>website_url</td></tr>
</table>>];
N3[label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>cuisine_restaurant</i></td></tr>
<tr><td><u>##restaurant</u></td></tr>
<tr><td><u>##cuisine</u></td></tr>
</table>>];
N2 -> N0[label=""];
N3 -> N2[label=""];
N3 -> N1[label=""];
}

Binary file not shown.

@ -0,0 +1,100 @@
%% Creator: Inkscape inkscape 0.92.4, www.inkscape.org
%% PDF/EPS/PS + LaTeX output extension by Johan Engelen, 2010
%% Accompanies image file 'mld.pdf' (pdf, eps, ps)
%%
%% To include the image in your LaTeX document, write
%% \input{<filename>.pdf_tex}
%% instead of
%% \includegraphics{<filename>.pdf}
%% To scale the image, write
%% \def\svgwidth{<desired width>}
%% \input{<filename>.pdf_tex}
%% instead of
%% \includegraphics[width=<desired width>]{<filename>.pdf}
%%
%% Images with a different path to the parent latex file can
%% be accessed with the `import' package (which may need to be
%% installed) using
%% \usepackage{import}
%% in the preamble, and then including the image with
%% \import{<path to file>}{<filename>.pdf_tex}
%% Alternatively, one can specify
%% \graphicspath{{<path to file>/}}
%%
%% For more information, please see info/svg-inkscape on CTAN:
%% http://tug.ctan.org/tex-archive/info/svg-inkscape
%%
\begingroup%
\makeatletter%
\providecommand\color[2][]{%
\errmessage{(Inkscape) Color is used for the text in Inkscape, but the package 'color.sty' is not loaded}%
\renewcommand\color[2][]{}%
}%
\providecommand\transparent[1]{%
\errmessage{(Inkscape) Transparency is used (non-zero) for the text in Inkscape, but the package 'transparent.sty' is not loaded}%
\renewcommand\transparent[1]{}%
}%
\providecommand\rotatebox[2]{#2}%
\newcommand*\fsize{\dimexpr\f@size pt\relax}%
\newcommand*\lineheight[1]{\fontsize{\fsize}{#1\fsize}\selectfont}%
\ifx\svgwidth\undefined%
\setlength{\unitlength}{411bp}%
\ifx\svgscale\undefined%
\relax%
\else%
\setlength{\unitlength}{\unitlength * \real{\svgscale}}%
\fi%
\else%
\setlength{\unitlength}{\svgwidth}%
\fi%
\global\let\svgwidth\undefined%
\global\let\svgscale\undefined%
\makeatother%
\begin{picture}(1,0.83090024)%
\lineheight{1}%
\setlength\tabcolsep{0pt}%
\put(0,0){\includegraphics[width=\unitlength,page=1]{mld.pdf}}%
\put(0.82116788,0.35961071){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}\textit{currency}\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=2]{mld.pdf}}%
\put(0.87226277,0.30851582){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}iso\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=3]{mld.pdf}}%
\put(0.81143552,0.25498784){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}full_name\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=4]{mld.pdf}}%
\put(0.51459854,0.78783452){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}\textit{cuisine}\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=5]{mld.pdf}}%
\put(0.55961071,0.73673963){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}id\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=6]{mld.pdf}}%
\put(0.5243309,0.68321165){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}name\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=7]{mld.pdf}}%
\put(0.48418491,0.59075427){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}\textit{restaurant}\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=8]{mld.pdf}}%
\put(0.56082725,0.53965937){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}id\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=9]{mld.pdf}}%
\put(0.52554745,0.48613139){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}name\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=10]{mld.pdf}}%
\put(0.50729927,0.4350365){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}location\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=11]{mld.pdf}}%
\put(0.49148418,0.38394161){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}min_price\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=12]{mld.pdf}}%
\put(0.48540146,0.33284672){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}max_price\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=13]{mld.pdf}}%
\put(0.48540146,0.28175183){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}#currency\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=14]{mld.pdf}}%
\put(0.50973236,0.23065694){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}latitude\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=15]{mld.pdf}}%
\put(0.49513382,0.17956205){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}longitude\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=16]{mld.pdf}}%
\put(0.44403893,0.12846715){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}phone_number\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=17]{mld.pdf}}%
\put(0.55352798,0.07737226){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}url\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=18]{mld.pdf}}%
\put(0.47688564,0.02627737){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}website_url\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=19]{mld.pdf}}%
\put(0.01824818,0.57372264){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}\textit{cuisine_restaurant}\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=20]{mld.pdf}}%
\put(0.0729927,0.52262774){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}#restaurant\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=21]{mld.pdf}}%
\put(0.10462287,0.47153285){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}#cuisine\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=22]{mld.pdf}}%
\end{picture}%
\endgroup%

@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.40.1 (20161225.0304)
-->
<!-- Title: mcd Pages: 1 -->
<svg width="411pt" height="342pt"
viewBox="0.00 0.00 411.00 341.50" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 337.5)">
<title>mcd</title>
<polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-337.5 407,-337.5 407,4 -4,4"/>
<!-- N0 -->
<g id="node1" class="node">
<title>N0</title>
<polygon fill="none" stroke="#000000" points="326.5,-136 326.5,-157 403.5,-157 403.5,-136 326.5,-136"/>
<text text-anchor="start" x="333.5" y="-143.8" font-family="Verdana" font-style="italic" font-size="14.00" fill="#000000">currency</text>
<polygon fill="none" stroke="#000000" points="326.5,-115 326.5,-136 403.5,-136 403.5,-115 326.5,-115"/>
<text text-anchor="start" x="354.5" y="-122.8" font-family="Verdana" text-decoration="underline" font-size="14.00" fill="#000000">iso</text>
<polygon fill="none" stroke="#000000" points="326.5,-94 326.5,-115 403.5,-115 403.5,-94 326.5,-94"/>
<text text-anchor="start" x="329.5" y="-100.8" font-family="Verdana" font-size="14.00" fill="#000000">full_name</text>
</g>
<!-- N1 -->
<g id="node2" class="node">
<title>N1</title>
<polygon fill="none" stroke="#000000" points="204.5,-312 204.5,-333 260.5,-333 260.5,-312 204.5,-312"/>
<text text-anchor="start" x="207.5" y="-319.8" font-family="Verdana" font-style="italic" font-size="14.00" fill="#000000">cuisine</text>
<polygon fill="none" stroke="#000000" points="204.5,-291 204.5,-312 260.5,-312 260.5,-291 204.5,-291"/>
<text text-anchor="start" x="226" y="-298.8" font-family="Verdana" text-decoration="underline" font-size="14.00" fill="#000000">id</text>
<polygon fill="none" stroke="#000000" points="204.5,-270 204.5,-291 260.5,-291 260.5,-270 204.5,-270"/>
<text text-anchor="start" x="211.5" y="-276.8" font-family="Verdana" font-size="14.00" fill="#000000">name</text>
</g>
<!-- N2 -->
<g id="node3" class="node">
<title>N2</title>
<polygon fill="none" stroke="#000000" points="175.5,-231 175.5,-252 290.5,-252 290.5,-231 175.5,-231"/>
<text text-anchor="start" x="195" y="-238.8" font-family="Verdana" font-style="italic" font-size="14.00" fill="#000000">restaurant</text>
<polygon fill="none" stroke="#000000" points="175.5,-210 175.5,-231 290.5,-231 290.5,-210 175.5,-210"/>
<text text-anchor="start" x="226.5" y="-217.8" font-family="Verdana" text-decoration="underline" font-size="14.00" fill="#000000">id</text>
<polygon fill="none" stroke="#000000" points="175.5,-189 175.5,-210 290.5,-210 290.5,-189 175.5,-189"/>
<text text-anchor="start" x="212" y="-195.8" font-family="Verdana" font-size="14.00" fill="#000000">name</text>
<polygon fill="none" stroke="#000000" points="175.5,-168 175.5,-189 290.5,-189 290.5,-168 175.5,-168"/>
<text text-anchor="start" x="204.5" y="-174.8" font-family="Verdana" font-size="14.00" fill="#000000">location</text>
<polygon fill="none" stroke="#000000" points="175.5,-147 175.5,-168 290.5,-168 290.5,-147 175.5,-147"/>
<text text-anchor="start" x="198" y="-153.8" font-family="Verdana" font-size="14.00" fill="#000000">min_price</text>
<polygon fill="none" stroke="#000000" points="175.5,-126 175.5,-147 290.5,-147 290.5,-126 175.5,-126"/>
<text text-anchor="start" x="195.5" y="-132.8" font-family="Verdana" font-size="14.00" fill="#000000">max_price</text>
<polygon fill="none" stroke="#000000" points="175.5,-105 175.5,-126 290.5,-126 290.5,-105 175.5,-105"/>
<text text-anchor="start" x="195.5" y="-111.8" font-family="Verdana" font-size="14.00" fill="#000000">#currency</text>
<polygon fill="none" stroke="#000000" points="175.5,-84 175.5,-105 290.5,-105 290.5,-84 175.5,-84"/>
<text text-anchor="start" x="205.5" y="-90.8" font-family="Verdana" font-size="14.00" fill="#000000">latitude</text>
<polygon fill="none" stroke="#000000" points="175.5,-63 175.5,-84 290.5,-84 290.5,-63 175.5,-63"/>
<text text-anchor="start" x="199.5" y="-69.8" font-family="Verdana" font-size="14.00" fill="#000000">longitude</text>
<polygon fill="none" stroke="#000000" points="175.5,-42 175.5,-63 290.5,-63 290.5,-42 175.5,-42"/>
<text text-anchor="start" x="178.5" y="-48.8" font-family="Verdana" font-size="14.00" fill="#000000">phone_number</text>
<polygon fill="none" stroke="#000000" points="175.5,-21 175.5,-42 290.5,-42 290.5,-21 175.5,-21"/>
<text text-anchor="start" x="223.5" y="-27.8" font-family="Verdana" font-size="14.00" fill="#000000">url</text>
<polygon fill="none" stroke="#000000" points="175.5,0 175.5,-21 290.5,-21 290.5,0 175.5,0"/>
<text text-anchor="start" x="192" y="-6.8" font-family="Verdana" font-size="14.00" fill="#000000">website_url</text>
</g>
<!-- N2&#45;&gt;N0 -->
<g id="edge1" class="edge">
<title>N2&#45;&gt;N0</title>
<path fill="none" stroke="#000000" stroke-width="1.25" d="M290.0131,-126C297.663,-126 305.4675,-126 313.0064,-126"/>
<polygon fill="#000000" stroke="#000000" stroke-width="1.25" points="313.2792,-130.3751 325.7792,-126 313.2792,-121.6251 313.2792,-130.3751"/>
</g>
<!-- N3 -->
<g id="node4" class="node">
<title>N3</title>
<polygon fill="none" stroke="#000000" points=".5,-224 .5,-245 139.5,-245 139.5,-224 .5,-224"/>
<text text-anchor="start" x="3.5" y="-231.8" font-family="Verdana" font-style="italic" font-size="14.00" fill="#000000">cuisine_restaurant</text>
<polygon fill="none" stroke="#000000" points=".5,-203 .5,-224 139.5,-224 139.5,-203 .5,-203"/>
<text text-anchor="start" x="26" y="-210.8" font-family="Verdana" text-decoration="underline" font-size="14.00" fill="#000000">#restaurant</text>
<polygon fill="none" stroke="#000000" points=".5,-182 .5,-203 139.5,-203 139.5,-182 .5,-182"/>
<text text-anchor="start" x="39" y="-189.8" font-family="Verdana" text-decoration="underline" font-size="14.00" fill="#000000">#cuisine</text>
</g>
<!-- N3&#45;&gt;N1 -->
<g id="edge3" class="edge">
<title>N3&#45;&gt;N1</title>
<path fill="none" stroke="#000000" stroke-width="1.25" d="M127.8863,-245.5215C149.472,-257.1751 173.4159,-270.1018 192.9436,-280.6444"/>
<polygon fill="#000000" stroke="#000000" stroke-width="1.25" points="191.0967,-284.6191 204.1745,-286.7077 195.2535,-276.9195 191.0967,-284.6191"/>
</g>
<!-- N3&#45;&gt;N2 -->
<g id="edge2" class="edge">
<title>N3&#45;&gt;N2</title>
<path fill="none" stroke="#000000" stroke-width="1.25" d="M127.8863,-182.4785C139.4471,-176.2372 151.6843,-169.6306 163.5572,-163.2207"/>
<polygon fill="#000000" stroke="#000000" stroke-width="1.25" points="165.8739,-166.9419 174.7948,-157.1537 161.717,-159.2423 165.8739,-166.9419"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

@ -0,0 +1,26 @@
\relax
\providecommand\hyper@newdestlabel[2]{}
\catcode `:\active
\catcode `;\active
\catcode `!\active
\catcode `?\active
\providecommand\HyperFirstAtBeginDocument{\AtBeginDocument}
\HyperFirstAtBeginDocument{\ifx\hyper@anchor\@undefined
\global\let\oldcontentsline\contentsline
\gdef\contentsline#1#2#3#4{\oldcontentsline{#1}{#2}{#3}}
\global\let\oldnewlabel\newlabel
\gdef\newlabel#1#2{\newlabelxx{#1}#2}
\gdef\newlabelxx#1#2#3#4#5#6{\oldnewlabel{#1}{{#2}{#3}}}
\AtEndDocument{\ifx\hyper@anchor\@undefined
\let\contentsline\oldcontentsline
\let\newlabel\oldnewlabel
\fi}
\fi}
\global\let\hyper@last\relax
\gdef\HyperFirstAtBeginDocument#1{#1}
\providecommand\HyField@AuxAddToFields[1]{}
\providecommand\HyField@AuxAddToCoFields[2]{}
\babel@aux{french}{}
\@writefile{toc}{\contentsline {section}{\numberline {1}Jeu de donn\IeC {\'e}es}{1}{section.1}\protected@file@percent }
\@writefile{toc}{\contentsline {section}{\numberline {2}Mod\IeC {\`e}le de donn\IeC {\'e}es}{1}{section.2}\protected@file@percent }
\@writefile{toc}{\contentsline {section}{\numberline {3}Analyse}{2}{section.3}\protected@file@percent }

@ -0,0 +1,433 @@
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2019/dev/Debian) (preloaded format=pdflatex 2021.7.23) 16 MAY 2022 17:26
entering extended mode
restricted \write18 enabled.
%&-line parsing enabled.
**rapport.tex
(./rapport.tex
LaTeX2e <2018-12-01>
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2018/09/03 v1.4i Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo
File: size10.clo 2018/09/03 v1.4i Standard LaTeX file (size option)
)
\c@part=\count80
\c@section=\count81
\c@subsection=\count82
\c@subsubsection=\count83
\c@paragraph=\count84
\c@subparagraph=\count85
\c@figure=\count86
\c@table=\count87
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
)
(/usr/share/texlive/texmf-dist/tex/generic/babel/babel.sty
Package: babel 2018/11/13 3.27 The Babel package
(/usr/share/texlive/texmf-dist/tex/generic/babel/switch.def
File: switch.def 2018/11/13 3.27 Babel switching mechanism
)
(/usr/share/texlive/texmf-dist/tex/generic/babel-french/french.ldf
Language: french 2019/01/30 v3.5d French support from the babel system
(/usr/share/texlive/texmf-dist/tex/generic/babel/babel.def
File: babel.def 2018/11/13 3.27 Babel common definitions
\babel@savecnt=\count88
\U@D=\dimen103
(/usr/share/texlive/texmf-dist/tex/generic/babel/txtbabel.def)
\bbl@dirlevel=\count89
)
\l@acadian = a dialect from \language\l@french
\FB@nonchar=\count90
Package babel Info: Making : an active character on input line 414.
Package babel Info: Making ; an active character on input line 415.
Package babel Info: Making ! an active character on input line 416.
Package babel Info: Making ? an active character on input line 417.
\FBguill@level=\count91
\FBold@everypar=\toks14
\FB@Mht=\dimen104
\mc@charclass=\count92
\mc@charfam=\count93
\mc@charslot=\count94
\std@mcc=\count95
\dec@mcc=\count96
\c@FBcaption@count=\count97
\listindentFB=\dimen105
\descindentFB=\dimen106
\labelindentFB=\dimen107
\labelwidthFB=\dimen108
\leftmarginFB=\dimen109
\parindentFFN=\dimen110
\FBfnindent=\dimen111
))
(/usr/share/texlive/texmf-dist/tex/latex/carlisle/scalefnt.sty)
(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty
Package: keyval 2014/10/28 v1.15 key=value parser (DPC)
\KV@toks@=\toks15
)
(/usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty
Package: inputenc 2018/08/11 v1.3c Input encoding file
\inpenc@prehook=\toks16
\inpenc@posthook=\toks17
)
(/usr/share/texlive/texmf-dist/tex/latex/tools/enumerate.sty
Package: enumerate 2015/07/23 v3.00 enumerate extensions (DPC)
\@enLab=\toks18
)
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hyperref.sty
Package: hyperref 2018/11/30 v6.88e Hypertext links for LaTeX
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/hobsub-hyperref.sty
Package: hobsub-hyperref 2016/05/16 v1.14 Bundle oberdiek, subset hyperref (HO)
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/hobsub-generic.sty
Package: hobsub-generic 2016/05/16 v1.14 Bundle oberdiek, subset generic (HO)
Package: hobsub 2016/05/16 v1.14 Construct package bundles (HO)
Package: infwarerr 2016/05/16 v1.4 Providing info/warning/error messages (HO)
Package: ltxcmds 2016/05/16 v1.23 LaTeX kernel commands for general use (HO)
Package: ifluatex 2016/05/16 v1.4 Provides the ifluatex switch (HO)
Package ifluatex Info: LuaTeX not detected.
Package: ifvtex 2016/05/16 v1.6 Detect VTeX and its facilities (HO)
Package ifvtex Info: VTeX not detected.
Package: intcalc 2016/05/16 v1.2 Expandable calculations with integers (HO)
Package: ifpdf 2018/09/07 v3.3 Provides the ifpdf switch
Package: etexcmds 2016/05/16 v1.6 Avoid name clashes with e-TeX commands (HO)
Package: kvsetkeys 2016/05/16 v1.17 Key value parser (HO)
Package: kvdefinekeys 2016/05/16 v1.4 Define keys (HO)
Package: pdftexcmds 2018/09/10 v0.29 Utility functions of pdfTeX for LuaTeX (HO
)
Package pdftexcmds Info: LuaTeX not detected.
Package pdftexcmds Info: \pdf@primitive is available.
Package pdftexcmds Info: \pdf@ifprimitive is available.
Package pdftexcmds Info: \pdfdraftmode found.
Package: pdfescape 2016/05/16 v1.14 Implements pdfTeX's escape features (HO)
Package: bigintcalc 2016/05/16 v1.4 Expandable calculations on big integers (HO
)
Package: bitset 2016/05/16 v1.2 Handle bit-vector datatype (HO)
Package: uniquecounter 2016/05/16 v1.3 Provide unlimited unique counter (HO)
)
Package hobsub Info: Skipping package `hobsub' (already loaded).
Package: letltxmacro 2016/05/16 v1.5 Let assignment for LaTeX macros (HO)
Package: hopatch 2016/05/16 v1.3 Wrapper for package hooks (HO)
Package: xcolor-patch 2016/05/16 xcolor patch
Package: atveryend 2016/05/16 v1.9 Hooks at the very end of document (HO)
Package atveryend Info: \enddocument detected (standard20110627).
Package: atbegshi 2016/06/09 v1.18 At begin shipout hook (HO)
Package: refcount 2016/05/16 v3.5 Data extraction from label references (HO)
Package: hycolor 2016/05/16 v1.8 Color options for hyperref/bookmark (HO)
)
(/usr/share/texlive/texmf-dist/tex/generic/ifxetex/ifxetex.sty
Package: ifxetex 2010/09/12 v0.6 Provides ifxetex conditional
)
(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/auxhook.sty
Package: auxhook 2016/05/16 v1.4 Hooks for auxiliary files (HO)
)
(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/kvoptions.sty
Package: kvoptions 2016/05/16 v3.12 Key value format for package options (HO)
)
\@linkdim=\dimen112
\Hy@linkcounter=\count98
\Hy@pagecounter=\count99
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/pd1enc.def
File: pd1enc.def 2018/11/30 v6.88e Hyperref: PDFDocEncoding definition (HO)
Now handling font encoding PD1 ...
... no UTF-8 mapping file for font encoding PD1
)
\Hy@SavedSpaceFactor=\count100
(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/hyperref.cfg
File: hyperref.cfg 2002/06/06 v1.2 hyperref configuration of TeXLive
)
Package hyperref Info: Hyper figures OFF on input line 4519.
Package hyperref Info: Link nesting OFF on input line 4524.
Package hyperref Info: Hyper index ON on input line 4527.
Package hyperref Info: Plain pages OFF on input line 4534.
Package hyperref Info: Backreferencing OFF on input line 4539.
Package hyperref Info: Implicit mode ON; LaTeX internals redefined.
Package hyperref Info: Bookmarks ON on input line 4772.
\c@Hy@tempcnt=\count101
(/usr/share/texlive/texmf-dist/tex/latex/url/url.sty
\Urlmuskip=\muskip10
Package: url 2013/09/16 ver 3.4 Verb mode for urls, etc.
)
LaTeX Info: Redefining \url on input line 5125.
\XeTeXLinkMargin=\dimen113
\Fld@menulength=\count102
\Field@Width=\dimen114
\Fld@charsize=\dimen115
Package hyperref Info: Hyper figures OFF on input line 6380.
Package hyperref Info: Link nesting OFF on input line 6385.
Package hyperref Info: Hyper index ON on input line 6388.
Package hyperref Info: backreferencing OFF on input line 6395.
Package hyperref Info: Link coloring OFF on input line 6400.
Package hyperref Info: Link coloring with OCG OFF on input line 6405.
Package hyperref Info: PDF/A mode OFF on input line 6410.
LaTeX Info: Redefining \ref on input line 6450.
LaTeX Info: Redefining \pageref on input line 6454.
\Hy@abspage=\count103
\c@Item=\count104
\c@Hfootnote=\count105
)
Package hyperref Info: Driver (autodetected): hpdftex.
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hpdftex.def
File: hpdftex.def 2018/11/30 v6.88e Hyperref driver for pdfTeX
\Fld@listcount=\count106
\c@bookmark@seq@number=\count107
(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/rerunfilecheck.sty
Package: rerunfilecheck 2016/05/16 v1.8 Rerun checks for auxiliary files (HO)
Package uniquecounter Info: New unique counter `rerunfilecheck' on input line 2
82.
)
\Hy@SectionHShift=\skip43
)
(/usr/share/texlive/texmf-dist/tex/latex/dirtytalk/dirtytalk.sty
Package: dirtytalk 2010/11/21 A package making "quoting" easier
(/usr/share/texlive/texmf-dist/tex/latex/base/ifthen.sty
Package: ifthen 2014/09/29 v1.1c Standard LaTeX ifthen package (DPC)
)
\c@dirtytalk@qdepth=\count108
)
(/usr/share/texlive/texmf-dist/tex/latex/graphviz/graphviz.sty
Package: graphviz 2013/08/15 v0.94 .dtx graphviz file
(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphicx.sty
Package: graphicx 2017/06/01 v1.1a Enhanced LaTeX Graphics (DPC,SPQR)
(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphics.sty
Package: graphics 2017/06/25 v1.2c Standard LaTeX Graphics (DPC,SPQR)
(/usr/share/texlive/texmf-dist/tex/latex/graphics/trig.sty
Package: trig 2016/01/03 v1.10 sin cos tan (DPC)
)
(/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/graphics.cfg
File: graphics.cfg 2016/06/04 v1.11 sample graphics configuration
)
Package graphics Info: Driver file: pdftex.def on input line 99.
(/usr/share/texlive/texmf-dist/tex/latex/graphics-def/pdftex.def
File: pdftex.def 2018/01/08 v1.0l Graphics/color driver for pdftex
))
\Gin@req@height=\dimen116
\Gin@req@width=\dimen117
))
(/usr/share/texlive/texmf-dist/tex/latex/geometry/geometry.sty
Package: geometry 2018/04/16 v5.8 Page Geometry
\Gm@cnth=\count109
\Gm@cntv=\count110
\c@Gm@tempcnt=\count111
\Gm@bindingoffset=\dimen118
\Gm@wd@mp=\dimen119
\Gm@odd@mp=\dimen120
\Gm@even@mp=\dimen121
\Gm@layoutwidth=\dimen122
\Gm@layoutheight=\dimen123
\Gm@layouthoffset=\dimen124
\Gm@layoutvoffset=\dimen125
\Gm@dimlist=\toks19
)
LaTeX Warning: Unused global option(s):
[fontsize=12pt].
(./rapport.aux)
\openout1 = `rapport.aux'.
LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 16.
LaTeX Font Info: ... okay on input line 16.
LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 16.
LaTeX Font Info: ... okay on input line 16.
LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 16.
LaTeX Font Info: ... okay on input line 16.
LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 16.
LaTeX Font Info: ... okay on input line 16.
LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 16.
LaTeX Font Info: ... okay on input line 16.
LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 16.
LaTeX Font Info: ... okay on input line 16.
LaTeX Font Info: Checking defaults for PD1/pdf/m/n on input line 16.
LaTeX Font Info: ... okay on input line 16.
LaTeX Info: Redefining \degres on input line 16.
LaTeX Info: Redefining \dots on input line 16.
Package french.ldf Info: Setting StandardEnumerateEnv=true for
(french.ldf) compatibility with enumerate package,
(french.ldf) reported on input line 16.
LaTeX Info: Redefining \up on input line 16.
Package french.ldf Warning: OT1 encoding should not be used for French.
(french.ldf) Add \usepackage[T1]{fontenc} to the preamble
(french.ldf) of your document; reported on input line 16.
\AtBeginShipoutBox=\box27
Package hyperref Info: Link coloring OFF on input line 16.
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/nameref.sty
Package: nameref 2016/05/21 v2.44 Cross-referencing by name of section
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/gettitlestring.sty
Package: gettitlestring 2016/05/16 v1.5 Cleanup title references (HO)
)
\c@section@level=\count112
)
LaTeX Info: Redefining \ref on input line 16.
LaTeX Info: Redefining \pageref on input line 16.
LaTeX Info: Redefining \nameref on input line 16.
(./rapport.out) (./rapport.out)
\@outlinefile=\write3
\openout3 = `rapport.out'.
(/usr/share/texlive/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
\scratchcounter=\count113
\scratchdimen=\dimen126
\scratchbox=\box28
\nofMPsegments=\count114
\nofMParguments=\count115
\everyMPshowfont=\toks20
\MPscratchCnt=\count116
\MPscratchDim=\dimen127
\MPnumerator=\count117
\makeMPintoPDFobject=\count118
\everyMPtoPDFconversion=\toks21
) (/usr/share/texlive/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty
Package: epstopdf-base 2016/05/15 v2.6 Base part for package epstopdf
(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/grfext.sty
Package: grfext 2016/05/16 v1.2 Manage graphics extensions (HO)
)
Package epstopdf-base Info: Redefining graphics rule for `.eps' on input line 4
38.
Package grfext Info: Graphics extension search list:
(grfext) [.pdf,.png,.jpg,.mps,.jpeg,.jbig2,.jb2,.PDF,.PNG,.JPG,.JPE
G,.JBIG2,.JB2,.eps]
(grfext) \AppendGraphicsExtensions on input line 456.
(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg
File: epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Liv
e
))
*geometry* driver: auto-detecting
*geometry* detected driver: pdftex
*geometry* verbose mode - [ preamble ] result:
* driver: pdftex
* paper: a4paper
* layout: <same size as paper>
* layoutoffset:(h,v)=(0.0pt,0.0pt)
* modes:
* h-part:(L,W,R)=(81.94394pt, 433.62pt, 81.94394pt)
* v-part:(T,H,B)=(106.75473pt, 578.15999pt, 160.13213pt)
* \paperwidth=597.50787pt
* \paperheight=845.04684pt
* \textwidth=433.62pt
* \textheight=578.15999pt
* \oddsidemargin=9.67395pt
* \evensidemargin=9.67395pt
* \topmargin=-2.51526pt
* \headheight=12.0pt
* \headsep=25.0pt
* \topskip=10.0pt
* \footskip=30.0pt
* \marginparwidth=65.0pt
* \marginparsep=11.0pt
* \columnsep=10.0pt
* \skip\footins=9.0pt plus 4.0pt minus 2.0pt
* \hoffset=0.0pt
* \voffset=0.0pt
* \mag=1000
* \@twocolumnfalse
* \@twosidefalse
* \@mparswitchfalse
* \@reversemarginfalse
* (1in=72.27pt=25.4mm, 1cm=28.453pt)
LaTeX Font Info: External font `cmex10' loaded for size
(Font) <12> on input line 19.
LaTeX Font Info: External font `cmex10' loaded for size
(Font) <8> on input line 19.
LaTeX Font Info: External font `cmex10' loaded for size
(Font) <6> on input line 19.
(./rapport.toc)
\tf@toc=\write4
\openout4 = `rapport.toc'.
LaTeX Font Info: External font `cmex10' loaded for size
(Font) <7> on input line 32.
LaTeX Font Info: External font `cmex10' loaded for size
(Font) <5> on input line 32.
runsystem(dot -Tpdf -o mld.pdf mld.dot)...disabled (restricted).
<mld.pdf, id=20, 411.5375pt x 415.5525pt>
File: mld.pdf Graphic file (type pdf)
<use mld.pdf>
Package pdftex.def Info: mld.pdf used on input line 36.
(pdftex.def) Requested size: 411.5365pt x 415.55148pt.
\dotfile=\write5
\openout5 = `mld.dot'.
[1
{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}]
<most-common-cuisines.png, id=34, 813.0375pt x 346.896pt>
File: most-common-cuisines.png Graphic file (type png)
<use most-common-cuisines.png>
Package pdftex.def Info: most-common-cuisines.png used on input line 81.
(pdftex.def) Requested size: 433.62pt x 185.0079pt.
Overfull \hbox (15.0pt too wide) in paragraph at lines 81--82
[][]
[]
[2 <./mld.pdf>]
<restaurants-currencies.png, id=54, 462.528pt x 346.896pt>
File: restaurants-currencies.png Graphic file (type png)
<use restaurants-currencies.png>
Package pdftex.def Info: restaurants-currencies.png used on input line 85.
(pdftex.def) Requested size: 433.62pt x 325.23007pt.
Overfull \hbox (15.0pt too wide) in paragraph at lines 85--86
[][]
[]
Package atveryend Info: Empty hook `BeforeClearDocument' on input line 87.
[3 <./most-common-cuisines.png> <./restaurants-currencies.png>]
Package atveryend Info: Empty hook `AfterLastShipout' on input line 87.
(./rapport.aux)
Package atveryend Info: Executing hook `AtVeryEndDocument' on input line 87.
Package atveryend Info: Executing hook `AtEndAfterFileList' on input line 87.
Package rerunfilecheck Info: File `rapport.out' has not changed.
(rerunfilecheck) Checksum: D35FA7175A597D6DA1CEF7C72F88C445;152.
Package atveryend Info: Empty hook `AtVeryVeryEnd' on input line 87.
)
Here is how much of TeX's memory you used:
6853 strings out of 494532
101410 string characters out of 6176185
204092 words of memory out of 5000000
10457 multiletter control sequences out of 15000+600000
7934 words of font info for 28 fonts, out of 8000000 for 9000
14 hyphenation exceptions out of 8191
32i,7n,31p,537b,423s stack positions out of 5000i,500n,10000p,200000b,80000s
</usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx10.pfb></us
r/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx12.pfb></usr/shar
e/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmmi10.pfb></usr/share/texl
ive/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb></usr/share/texlive/tex
mf-dist/fonts/type1/public/amsfonts/cm/cmr12.pfb></usr/share/texlive/texmf-dist
/fonts/type1/public/amsfonts/cm/cmr17.pfb></usr/share/texlive/texmf-dist/fonts/
type1/public/amsfonts/cm/cmti10.pfb></usr/share/texlive/texmf-dist/fonts/type1/
urw/times/utmr8a.pfb></usr/share/texlive/texmf-dist/fonts/type1/urw/times/utmri
8a.pfb>
Output written on rapport.pdf (3 pages, 230862 bytes).
PDF statistics:
91 PDF objects out of 1000 (max. 8388607)
69 compressed objects within 1 object stream
8 named destinations out of 1000 (max. 500000)
40 words of extra memory for PDF output out of 10000 (max. 10000000)

@ -0,0 +1,87 @@
\documentclass[fontsize=12pt]{article}
\usepackage[french]{babel}
\usepackage[utf8]{inputenc}
\usepackage{enumerate}
\usepackage{hyperref}
\usepackage{dirtytalk}
\usepackage[pdf]{graphviz}
\title{SAÉ S2.04 - Exploitation de base de données}
\author{Clément Fréville, Bastien Ollier, Nathan Dauga}
\date{7 mai 2022}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\begin{document}
\maketitle
\tableofcontents
\section{Jeu de données}
À partir des références présentées dans le \textit{guide Michelin 2021} et \href{https://www.kaggle.com/datasets/ngshiheng/michelin-guide-restaurants-2021}{présentées au format CSV}, nous allons étudier les tendances présentes.
Chaque restaurant est d'abord caractérisé par son nom, son adresse et ses informations de contact. Les restaurants proposant une cuisine de qualité sont récompensés par une, deux voire trois \say{Étoiles Michelin}. Elles définissent de très bonnes tables pour une étoile et une cuisine exceptionnelle pour trois étoiles. Le \say{Bib Gourmand} récompense quant à lui les repas soignés à prix modéré. Le critère du guide est de pouvoir commander trois plats complets pour environ 39 euros.
Chaque restaurant propose un ou plusieurs genres de cuisines. Une cuisine peut être \say{régionale}, \say{française} ou \say{moderne} par exemple. Le \textit{guide Michelin} fournit également un prix minimal et maximal pour une monnaie donnée.
\section{Modèle de données}
Nous avons déduit à partir de ce jeu de données une entité \textbf{restaurant} et une entité \textbf{cuisine}. À partir d'un autre jeu de données, nous avons extrait une nouvelle entité \textbf{monnaie}. Un restaurant \textit{propose} de $1$ à $n$ cuisines et \textit{utilise} $1$ monnaie.
Nous en déduisons le \textit{Modèle Logique de Données} suivant :
\digraph{mld} {
node [shape=plain]
rankdir=LR;
N0[label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>currency</i></td></tr>
<tr><td><u>iso</u></td></tr>
<tr><td>full_name</td></tr>
</table>>];
N1[label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>cuisine</i></td></tr>
<tr><td><u>id</u></td></tr>
<tr><td>name</td></tr>
</table>>];
N2[label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>restaurant</i></td></tr>
<tr><td><u>id</u></td></tr>
<tr><td>name</td></tr>
<tr><td>location</td></tr>
<tr><td>min_price</td></tr>
<tr><td>max_price</td></tr>
<tr><td>#currency</td></tr>
<tr><td>latitude</td></tr>
<tr><td>longitude</td></tr>
<tr><td>phone_number</td></tr>
<tr><td>url</td></tr>
<tr><td>website_url</td></tr>
</table>>];
N3[label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td><i>cuisine_restaurant</i></td></tr>
<tr><td><u>#restaurant</u></td></tr>
<tr><td><u>#cuisine</u></td></tr>
</table>>];
N2 -> N0[label=""];
N3 -> N2[label=""];
N3 -> N1[label=""];
}
\section{Analyse}
Le \textit{guide Michelin} référence de nombreux genres de cuisines. Quelles sont les genres les plus présents ?
\includegraphics[width=\textwidth]{most-common-cuisines.png}
Si le \textit{guide Michelin} est essentiellement européen, quelles autres monnaies sont utilisées ?
\includegraphics[width=\textwidth]{restaurants-currencies.png}
\end{document}

@ -0,0 +1,4 @@
\babel@toc {french}{}
\contentsline {section}{\numberline {1}Jeu de donn\IeC {\'e}es}{1}{section.1}%
\contentsline {section}{\numberline {2}Mod\IeC {\`e}le de donn\IeC {\'e}es}{1}{section.2}%
\contentsline {section}{\numberline {3}Analyse}{2}{section.3}%

@ -0,0 +1,43 @@
SELECT c.iso, c.full_name, COUNT(*) restaurants
FROM restaurant r
INNER JOIN currency c ON c.iso = r.currency
GROUP BY c.iso
ORDER BY 3 DESC
LIMIT 10;
SELECT min_price
FROM restaurant
WHERE currency = 'EUR'
ORDER BY min_price
GROUP BY '[3,7)'::int4range;
/*WITH series AS (
SELECT generate_series(
(SELECT MIN(min_price) FROM restaurant),
(SELECT MAX(min_price) FROM restaurant WHERE min_price != 'NaN'::NUMERIC),
10
) low_bound_price
)
SELECT '[' || s.low_bound_price || ',' || (s.low_bound_price+10) || '[', COUNT(*) restaurants
FROM series s
LEFT JOIN restaurant r
ON r.min_price >= s.low_bound_price
AND r.min_price < (s.low_bound_price + 10)
GROUP BY low_bound_price;*/
-- COUNT(*) FILTER ?
SELECT CASE WHEN min_price < 5 THEN '< 5'
WHEN min_price >= 5 AND min_price < 10 THEN '[5;10['
WHEN min_price >= 10 AND min_price < 15 THEN '[10;15['
WHEN min_price >= 15 AND min_price < 20 THEN '[15;20['
WHEN min_price >= 20 AND min_price < 30 THEN '[20;30['
WHEN min_price >= 30 AND min_price < 50 THEN '[30;50['
WHEN min_price >= 50 AND min_price < 100 THEN '[50;100['
WHEN min_price >= 100 AND min_price < 200 THEN '[100;200['
WHEN min_price >= 200 AND min_price < 500 THEN '[200;500['
WHEN min_price >= 500 AND min_price < 1000 THEN '[500;1000['
WHEN min_price >= 1000 THEN '>= 1000'
END min_price_range,
COUNT(*) nb
FROM restaurant
GROUP BY min_price_range;

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

@ -0,0 +1,100 @@
%% Creator: Inkscape inkscape 0.92.4, www.inkscape.org
%% PDF/EPS/PS + LaTeX output extension by Johan Engelen, 2010
%% Accompanies image file 'mld_svg-tex.pdf' (pdf, eps, ps)
%%
%% To include the image in your LaTeX document, write
%% \input{<filename>.pdf_tex}
%% instead of
%% \includegraphics{<filename>.pdf}
%% To scale the image, write
%% \def\svgwidth{<desired width>}
%% \input{<filename>.pdf_tex}
%% instead of
%% \includegraphics[width=<desired width>]{<filename>.pdf}
%%
%% Images with a different path to the parent latex file can
%% be accessed with the `import' package (which may need to be
%% installed) using
%% \usepackage{import}
%% in the preamble, and then including the image with
%% \import{<path to file>}{<filename>.pdf_tex}
%% Alternatively, one can specify
%% \graphicspath{{<path to file>/}}
%%
%% For more information, please see info/svg-inkscape on CTAN:
%% http://tug.ctan.org/tex-archive/info/svg-inkscape
%%
\begingroup%
\makeatletter%
\providecommand\color[2][]{%
\errmessage{(Inkscape) Color is used for the text in Inkscape, but the package 'color.sty' is not loaded}%
\renewcommand\color[2][]{}%
}%
\providecommand\transparent[1]{%
\errmessage{(Inkscape) Transparency is used (non-zero) for the text in Inkscape, but the package 'transparent.sty' is not loaded}%
\renewcommand\transparent[1]{}%
}%
\providecommand\rotatebox[2]{#2}%
\newcommand*\fsize{\dimexpr\f@size pt\relax}%
\newcommand*\lineheight[1]{\fontsize{\fsize}{#1\fsize}\selectfont}%
\ifx\svgwidth\undefined%
\setlength{\unitlength}{411bp}%
\ifx\svgscale\undefined%
\relax%
\else%
\setlength{\unitlength}{\unitlength * \real{\svgscale}}%
\fi%
\else%
\setlength{\unitlength}{\svgwidth}%
\fi%
\global\let\svgwidth\undefined%
\global\let\svgscale\undefined%
\makeatother%
\begin{picture}(1,0.83090024)%
\lineheight{1}%
\setlength\tabcolsep{0pt}%
\put(0,0){\includegraphics[width=\unitlength,page=1]{mld_svg-tex.pdf}}%
\put(0.82116788,0.35961071){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}\textit{currency}\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=2]{mld_svg-tex.pdf}}%
\put(0.87226277,0.30851582){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}iso\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=3]{mld_svg-tex.pdf}}%
\put(0.81143552,0.25498784){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}full_name\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=4]{mld_svg-tex.pdf}}%
\put(0.51459854,0.78783452){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}\textit{cuisine}\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=5]{mld_svg-tex.pdf}}%
\put(0.55961071,0.73673963){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}id\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=6]{mld_svg-tex.pdf}}%
\put(0.5243309,0.68321165){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}name\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=7]{mld_svg-tex.pdf}}%
\put(0.48418491,0.59075427){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}\textit{restaurant}\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=8]{mld_svg-tex.pdf}}%
\put(0.56082725,0.53965937){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}id\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=9]{mld_svg-tex.pdf}}%
\put(0.52554745,0.48613139){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}name\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=10]{mld_svg-tex.pdf}}%
\put(0.50729927,0.4350365){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}location\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=11]{mld_svg-tex.pdf}}%
\put(0.49148418,0.38394161){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}min_price\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=12]{mld_svg-tex.pdf}}%
\put(0.48540146,0.33284672){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}max_price\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=13]{mld_svg-tex.pdf}}%
\put(0.48540146,0.28175183){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}#currency\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=14]{mld_svg-tex.pdf}}%
\put(0.50973236,0.23065694){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}latitude\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=15]{mld_svg-tex.pdf}}%
\put(0.49513382,0.17956205){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}longitude\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=16]{mld_svg-tex.pdf}}%
\put(0.44403893,0.12846715){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}phone_number\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=17]{mld_svg-tex.pdf}}%
\put(0.55352798,0.07737226){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}url\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=18]{mld_svg-tex.pdf}}%
\put(0.47688564,0.02627737){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}website_url\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=19]{mld_svg-tex.pdf}}%
\put(0.01824818,0.57372264){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}\textit{cuisine_restaurant}\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=20]{mld_svg-tex.pdf}}%
\put(0.0729927,0.52262774){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}#restaurant\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=21]{mld_svg-tex.pdf}}%
\put(0.10462287,0.47153285){\color[rgb]{0,0,0}\makebox(0,0)[lt]{\lineheight{1.25}\smash{\begin{tabular}[t]{l}#cuisine\end{tabular}}}}%
\put(0,0){\includegraphics[width=\unitlength,page=22]{mld_svg-tex.pdf}}%
\end{picture}%
\endgroup%

@ -0,0 +1,30 @@
CREATE TABLE currency (
iso CHAR(3) PRIMARY KEY,
full_name VARCHAR(40) NOT NULL
);
CREATE TABLE cuisine (
id SERIAL PRIMARY KEY,
name VARCHAR(30)
);
CREATE TABLE restaurant (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
location VARCHAR(150) NOT NULL,
min_price NUMERIC(9, 2) NOT NULL,
max_price NUMERIC(9, 2) NOT NULL,
currency CHAR(3) REFERENCES currency(iso),
latitude FLOAT,
longitude FLOAT,
phone_number VARCHAR(16),
url VARCHAR(255) NOT NULL,
website_url VARCHAR(255) NOT NULL
);
CREATE TABLE cuisine_restaurant (
restaurant INT REFERENCES restaurant(id),
cuisine INT REFERENCES cuisine(id),
PRIMARY KEY(restaurant, cuisine)
);
-- TODO : pourquoi sqlship ne gère pas les if not exists ???????

@ -0,0 +1,40 @@
-- https://www.kaggle.com/datasets/ngshiheng/michelin-guide-restaurants-2021
-- https://docs.openexchangerates.org/docs/currencies-json
DROP TABLE IF EXISTS cuisine_restaurant;
DROP TABLE IF EXISTS restaurant;
DROP TABLE IF EXISTS currency;
DROP TABLE IF EXISTS cuisine;
CREATE TABLE IF NOT EXISTS currency (
iso CHAR(3) PRIMARY KEY, -- ISO 4217
full_name VARCHAR(40) NOT NULL,
UNIQUE(full_name)
);
CREATE TABLE IF NOT EXISTS cuisine (
id SERIAL PRIMARY KEY,
name VARCHAR(30),
UNIQUE (name)
);
CREATE TABLE IF NOT EXISTS restaurant (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
location VARCHAR(150) NOT NULL,
min_price NUMERIC(9, 2) NOT NULL,
max_price NUMERIC(9, 2) NOT NULL,
currency CHAR(3) REFERENCES currency(iso),
latitude FLOAT,
longitude FLOAT,
phone_number VARCHAR(16),
url VARCHAR(255) NOT NULL,
website_url VARCHAR(255) NOT NULL,
stars INT NOT NULL DEFAULT 0
);
CREATE TABLE IF NOT EXISTS cuisine_restaurant (
restaurant INT REFERENCES restaurant(id),
cuisine INT REFERENCES cuisine(id),
PRIMARY KEY(restaurant, cuisine)
);

@ -0,0 +1,133 @@
Year,Month,Primary_School,Date,High_School,Associates_Degree,Professional_Degree,White,Black,Asian,Hispanic,Men,Women
2010,Jan,15.3,Jan-2010,10.2,8.6,4.9,8.8,16.5,8.3,12.9,10.2,7.9
2011,Jan,14.3,Jan-2011,9.5,8.1,4.3,8.1,15.8,6.8,12.3,9.0,7.9
2012,Jan,13.0,Jan-2012,8.5,7.1,4.3,7.4,13.6,6.7,10.7,7.7,7.6
2013,Jan,12.0,Jan-2013,8.1,6.9,3.8,7.1,13.7,6.4,9.7,7.5,7.2
2014,Jan,9.4,Jan-2014,6.5,5.9,3.3,5.7,12.1,4.7,8.3,6.2,5.8
2015,Jan,8.3,Jan-2015,5.4,5.2,2.8,4.9,10.3,4.0,6.7,5.3,5.0
2016,Jan,7.1,Jan-2016,5.2,4.2,2.5,4.2,8.7,3.6,5.8,4.4,4.5
2017,Jan,7.4,Jan-2017,5.2,3.8,2.5,4.2,7.5,3.7,5.8,4.3,4.4
2018,Jan,5.4,Jan-2018,4.4,3.4,2.1,3.5,7.5,3.0,5.0,3.8,3.6
2019,Jan,5.7,Jan-2019,3.7,3.4,2.4,3.5,6.8,3.1,4.8,3.7,3.6
2020,Jan,5.5,Jan-2020,3.8,2.8,2.0,3.1,6.0,3.0,4.3,3.3,3.2
2010,Feb,15.8,Feb-2010,10.7,8.1,4.9,8.9,16.1,8.2,12.7,10.3,8.0
2011,Feb,14.0,Feb-2011,9.7,7.9,4.3,8.1,15.5,6.7,11.8,8.9,7.9
2012,Feb,13.1,Feb-2012,8.3,7.2,4.2,7.4,14.0,6.2,10.9,7.7,7.6
2013,Feb,11.3,Feb-2013,7.9,6.5,3.9,6.8,13.8,6.0,9.7,7.0,7.0
2014,Feb,9.8,Feb-2014,6.4,6.0,3.4,5.8,11.8,5.9,8.2,6.3,5.9
2015,Feb,8.2,Feb-2015,5.4,5.0,2.7,4.7,10.1,4.0,6.8,5.2,4.9
2016,Feb,7.0,Feb-2016,5.2,4.2,2.5,4.3,8.5,3.8,5.4,4.5,4.5
2017,Feb,7.7,Feb-2017,4.9,4.0,2.4,4.0,7.9,3.4,5.5,4.3,4.2
2018,Feb,5.7,Feb-2018,4.4,3.5,2.2,3.7,6.7,2.9,4.9,3.7,3.8
2019,Feb,5.3,Feb-2019,3.7,3.1,2.2,3.3,6.9,3.1,4.3,3.5,3.4
2020,Feb,5.7,Feb-2020,3.6,3.0,1.9,3.1,5.8,2.5,4.4,3.3,3.1
2010,Mar,14.9,Mar-2010,11.0,8.4,4.9,8.9,16.8,7.6,12.9,10.2,8.1
2011,Mar,14.1,Mar-2011,9.7,7.5,4.4,8.0,15.8,7.3,11.6,8.8,7.8
2012,Mar,12.8,Mar-2012,8.1,7.5,4.1,7.3,14.0,6.4,10.6,7.7,7.4
2013,Mar,11.1,Mar-2013,7.7,6.3,3.8,6.7,13.0,5.1,9.3,6.9,6.9
2014,Mar,9.4,Mar-2014,6.3,6.0,3.4,5.8,12.1,5.5,7.9,6.1,6.2
2015,Mar,8.6,Mar-2015,5.3,4.8,2.4,4.8,9.9,3.2,6.8,5.1,4.9
2016,Mar,7.3,Mar-2016,5.3,4.1,2.6,4.3,8.9,3.9,5.5,4.5,4.6
2017,Mar,6.6,Mar-2017,4.9,3.7,2.4,3.9,7.9,3.3,5.0,4.2,3.9
2018,Mar,5.5,Mar-2018,4.3,3.5,2.2,3.6,6.8,3.1,5.0,3.7,3.7
2019,Mar,5.8,Mar-2019,3.7,3.4,2.0,3.4,6.6,3.1,4.7,3.6,3.3
2020,Mar,6.8,Mar-2020,4.4,3.7,2.5,4.0,6.7,4.1,6.0,4.0,4.0
2010,Apr,14.7,Apr-2010,10.8,8.4,4.8,9.0,16.6,7.0,12.5,10.2,8.3
2011,Apr,14.7,Apr-2011,9.9,7.5,4.5,8.1,16.5,6.5,11.9,8.9,8.0
2012,Apr,12.5,Apr-2012,8.0,7.6,4.0,7.4,13.3,5.4,10.3,7.6,7.4
2013,Apr,11.6,Apr-2013,7.5,6.4,3.9,6.7,13.3,5.3,9.0,7.2,6.7
2014,Apr,8.7,Apr-2014,6.2,5.7,3.3,5.3,11.6,5.9,7.2,5.9,5.6
2015,Apr,8.4,Apr-2015,5.5,4.7,2.7,4.7,9.7,4.4,6.8,5.0,5.0
2016,Apr,7.6,Apr-2016,5.5,4.2,2.4,4.4,8.8,3.8,6.1,4.6,4.6
2017,Apr,6.4,Apr-2017,4.6,3.7,2.5,3.9,7.9,3.3,5.1,3.9,4.1
2018,Apr,5.8,Apr-2018,4.3,3.4,2.1,3.6,6.4,2.8,4.8,3.7,3.5
2019,Apr,5.3,Apr-2019,3.4,3.1,2.1,3.1,6.6,2.2,4.2,3.4,3.1
2020,Apr,,Apr-2020,,,,,,,,,
2010,May,14.6,May-2010,10.9,8.2,4.6,8.7,15.5,7.8,12.0,9.7,8.1
2011,May,14.5,May-2011,9.6,7.8,4.5,7.9,16.3,7.2,11.6,8.8,8.0
2012,May,12.9,May-2012,8.3,7.7,3.9,7.4,13.5,5.5,10.9,7.7,7.4
2013,May,11.0,May-2013,7.3,6.5,3.9,6.7,13.4,4.5,9.0,7.1,6.5
2014,May,9.2,May-2014,6.5,5.5,3.2,5.4,11.4,5.7,7.7,5.9,5.8
2015,May,8.7,May-2015,5.8,4.4,2.8,4.8,10.3,4.1,6.8,5.2,5.1
2016,May,7.5,May-2016,5.1,3.9,2.5,4.2,8.2,4.2,5.6,4.5,4.3
2017,May,6.3,May-2017,4.8,4.1,2.3,3.8,7.7,3.7,5.2,4.0,4.1
2018,May,5.5,May-2018,3.9,3.3,2.0,3.5,5.9,2.2,4.9,3.6,3.4
2019,May,5.4,May-2019,3.6,2.8,2.1,3.3,6.2,2.5,4.2,3.4,3.3
2020,May,,May-2020,,,,,,,,,
2010,Jun,14.2,Jun-2010,10.6,8.1,4.4,8.6,15.2,7.4,12.3,9.7,7.7
2011,Jun,14.4,Jun-2011,10.0,8.3,4.3,8.1,16.2,6.5,11.5,9.0,8.0
2012,Jun,12.6,Jun-2012,8.6,7.3,4.0,7.3,14.5,6.1,10.9,7.7,7.4
2013,Jun,10.7,Jun-2013,7.7,6.5,3.8,6.6,14.2,4.7,9.1,7.0,6.8
2014,Jun,9.2,Jun-2014,5.9,5.2,3.3,5.3,11.0,4.7,7.8,5.7,5.3
2015,Jun,8.2,Jun-2015,5.4,4.2,2.5,4.6,9.7,3.9,6.7,4.8,4.7
2016,Jun,7.6,Jun-2016,5.1,4.2,2.5,4.3,8.8,3.5,5.9,4.5,4.4
2017,Jun,6.5,Jun-2017,4.6,3.8,2.3,3.8,7.1,3.6,4.9,4.0,4.0
2018,Jun,5.5,Jun-2018,4.1,3.3,2.3,3.5,6.5,3.2,4.5,3.7,3.6
2019,Jun,5.3,Jun-2019,3.9,3.0,2.1,3.3,6.0,2.1,4.3,3.3,3.3
2020,Jun,,Jun-2020,,,,,,,,,
2010,Jul,13.5,Jul-2010,10.0,8.3,4.5,8.5,15.6,7.9,12.2,9.6,7.9
2011,Jul,14.5,Jul-2011,9.1,8.3,4.2,8.0,15.9,7.4,11.2,8.8,7.9
2012,Jul,12.4,Jul-2012,8.5,7.2,4.1,7.3,14.2,5.9,10.2,7.7,7.4
2013,Jul,10.8,Jul-2013,7.5,6.1,3.8,6.5,12.6,5.3,9.4,7.0,6.3
2014,Jul,9.5,Jul-2014,6.1,5.3,3.1,5.3,11.6,4.2,7.7,5.7,5.6
2015,Jul,8.3,Jul-2015,5.5,4.3,2.5,4.5,9.1,3.9,6.9,4.8,4.8
2016,Jul,6.5,Jul-2016,5.1,4.2,2.5,4.2,8.4,3.8,5.5,4.6,4.2
2017,Jul,7.1,Jul-2017,4.5,3.7,2.3,3.7,7.4,3.8,5.1,4.0,3.9
2018,Jul,5.2,Jul-2018,4.1,3.2,2.2,3.3,6.6,3.1,4.4,3.4,3.6
2019,Jul,5.2,Jul-2019,3.6,3.2,2.1,3.3,5.9,2.8,4.5,3.3,3.3
2020,Jul,,Jul-2020,,,,,,,,,
2010,Aug,14.1,Aug-2010,10.0,8.7,4.6,8.6,15.9,7.3,12.0,9.6,8.0
2011,Aug,14.1,Aug-2011,9.3,8.3,4.2,7.9,16.4,7.2,11.2,8.7,7.9
2012,Aug,11.8,Aug-2012,8.6,6.7,4.1,7.2,13.8,5.9,10.1,7.6,7.3
2013,Aug,11.1,Aug-2013,7.4,6.1,3.4,6.4,12.8,5.1,9.2,7.1,6.2
2014,Aug,9.2,Aug-2014,6.1,5.3,3.2,5.3,11.4,4.5,7.4,5.7,5.6
2015,Aug,7.9,Aug-2015,5.5,4.3,2.4,4.4,9.4,3.4,6.6,4.7,4.6
2016,Aug,7.4,Aug-2016,5.0,4.2,2.6,4.3,8.0,4.1,5.6,4.5,4.4
2017,Aug,6.1,Aug-2017,5.1,3.7,2.4,3.8,7.7,3.9,5.2,4.1,4.0
2018,Aug,5.7,Aug-2018,3.9,3.5,2.0,3.4,6.3,3.0,4.7,3.5,3.5
2019,Aug,5.4,Aug-2019,3.6,3.0,2.1,3.4,5.4,2.8,4.2,3.3,3.3
2020,Aug,,Aug-2020,,,,,,,,,
2010,Sep,15.6,Sep-2010,9.7,8.9,4.5,8.6,16.0,6.6,12.3,9.6,8.0
2011,Sep,14.3,Sep-2011,9.4,8.5,4.2,7.9,15.9,8.0,11.2,8.7,8.2
2012,Sep,11.7,Sep-2012,8.5,6.6,4.0,7.0,13.6,4.9,9.7,7.3,7.1
2013,Sep,10.5,Sep-2013,7.6,6.1,3.7,6.3,13.0,5.4,8.8,7.1,6.2
2014,Sep,8.5,Sep-2014,5.4,5.4,2.9,5.1,11.0,4.4,6.8,5.3,5.5
2015,Sep,7.9,Sep-2015,5.3,4.3,2.5,4.4,9.3,3.5,6.2,4.7,4.6
2016,Sep,8.5,Sep-2016,5.3,4.2,2.5,4.4,8.5,3.8,6.4,4.7,4.4
2017,Sep,6.7,Sep-2017,4.4,3.6,2.3,3.7,7.2,3.6,5.1,3.9,3.9
2018,Sep,5.7,Sep-2018,3.8,3.2,2.0,3.3,6.2,3.5,4.6,3.4,3.3
2019,Sep,4.8,Sep-2019,3.6,2.9,2.0,3.2,5.5,2.5,3.9,3.2,3.1
2020,Sep,,Sep-2020,,,,,,,,,
2010,Oct,15.0,Oct-2010,9.8,8.2,4.6,8.6,15.6,7.2,12.3,9.4,8.0
2011,Oct,13.5,Oct-2011,9.4,8.1,4.3,7.9,14.6,7.4,11.3,8.6,7.8
2012,Oct,12.1,Oct-2012,8.3,6.9,3.7,6.9,14.1,4.9,10.0,7.2,7.1
2013,Oct,10.9,Oct-2013,7.2,6.4,3.7,6.3,12.8,5.4,9.1,6.9,6.3
2014,Oct,8.1,Oct-2014,5.7,4.9,3.0,4.9,10.6,5.1,6.8,5.1,5.4
2015,Oct,7.6,Oct-2015,5.2,4.4,2.5,4.4,9.0,3.5,6.3,4.7,4.6
2016,Oct,7.4,Oct-2016,5.4,3.9,2.6,4.4,8.4,3.4,5.8,4.6,4.4
2017,Oct,5.9,Oct-2017,4.2,3.7,2.1,3.5,7.4,3.0,4.9,3.8,3.7
2018,Oct,5.9,Oct-2018,4.0,3.1,2.0,3.3,6.3,3.1,4.4,3.5,3.4
2019,Oct,5.5,Oct-2019,3.7,2.8,2.1,3.2,5.5,2.8,4.1,3.2,3.2
2020,Oct,,Oct-2020,,,,,,,,,
2010,Nov,15.4,Nov-2010,10.0,8.6,5.0,8.9,16.2,7.5,12.9,9.9,8.4
2011,Nov,12.8,Nov-2011,8.8,7.7,4.4,7.7,15.6,6.4,11.2,8.2,7.8
2012,Nov,12.0,Nov-2012,8.0,6.5,3.9,6.8,13.3,6.3,9.9,7.2,7.0
2013,Nov,10.7,Nov-2013,7.2,6.4,3.4,6.1,12.3,5.2,8.7,6.6,6.2
2014,Nov,8.6,Nov-2014,5.7,4.9,3.2,5.0,10.9,4.8,6.6,5.4,5.3
2015,Nov,6.8,Nov-2015,5.4,4.4,2.5,4.4,9.4,3.9,6.4,4.8,4.6
2016,Nov,7.8,Nov-2016,5.0,3.9,2.4,4.2,8.1,3.1,5.8,4.3,4.3
2017,Nov,5.2,Nov-2017,4.4,3.6,2.1,3.7,7.4,3.0,4.8,3.8,3.7
2018,Nov,5.6,Nov-2018,3.5,3.1,2.2,3.4,6.1,2.8,4.5,3.3,3.4
2019,Nov,5.3,Nov-2019,3.7,2.9,2.0,3.2,5.6,2.6,4.2,3.2,3.2
2020,Nov,,Nov-2020,,,,,,,,,
2010,Dec,15.0,Dec-2010,9.8,8.1,4.8,8.5,15.5,7.2,12.9,9.4,8.0
2011,Dec,13.7,Dec-2011,8.7,7.6,4.1,7.5,15.4,6.8,11.1,8.0,7.8
2012,Dec,11.8,Dec-2012,8.0,6.9,4.0,6.9,14.0,6.6,9.6,7.2,7.4
2013,Dec,9.8,Dec-2013,7.0,6.2,3.3,5.9,11.9,4.3,8.3,6.3,6.1
2014,Dec,8.6,Dec-2014,5.3,5.0,2.8,4.7,10.6,4.4,6.4,5.2,5.1
2015,Dec,6.4,Dec-2015,5.6,4.1,2.5,4.4,8.5,4.1,6.2,4.6,4.5
2016,Dec,7.5,Dec-2016,5.1,3.8,2.5,4.2,7.9,2.7,5.9,4.4,4.3
2017,Dec,6.2,Dec-2017,4.2,3.6,2.2,3.7,6.7,2.5,5.0,3.7,3.7
2018,Dec,5.8,Dec-2018,3.8,3.3,2.2,3.4,6.6,3.3,4.4,3.6,3.5
2019,Dec,5.2,Dec-2019,3.7,2.7,1.9,3.2,5.9,2.5,4.2,3.1,3.2
2020,Dec,,Dec-2020,,,,,,,,,
1 Year Month Primary_School Date High_School Associates_Degree Professional_Degree White Black Asian Hispanic Men Women
2 2010 Jan 15.3 Jan-2010 10.2 8.6 4.9 8.8 16.5 8.3 12.9 10.2 7.9
3 2011 Jan 14.3 Jan-2011 9.5 8.1 4.3 8.1 15.8 6.8 12.3 9.0 7.9
4 2012 Jan 13.0 Jan-2012 8.5 7.1 4.3 7.4 13.6 6.7 10.7 7.7 7.6
5 2013 Jan 12.0 Jan-2013 8.1 6.9 3.8 7.1 13.7 6.4 9.7 7.5 7.2
6 2014 Jan 9.4 Jan-2014 6.5 5.9 3.3 5.7 12.1 4.7 8.3 6.2 5.8
7 2015 Jan 8.3 Jan-2015 5.4 5.2 2.8 4.9 10.3 4.0 6.7 5.3 5.0
8 2016 Jan 7.1 Jan-2016 5.2 4.2 2.5 4.2 8.7 3.6 5.8 4.4 4.5
9 2017 Jan 7.4 Jan-2017 5.2 3.8 2.5 4.2 7.5 3.7 5.8 4.3 4.4
10 2018 Jan 5.4 Jan-2018 4.4 3.4 2.1 3.5 7.5 3.0 5.0 3.8 3.6
11 2019 Jan 5.7 Jan-2019 3.7 3.4 2.4 3.5 6.8 3.1 4.8 3.7 3.6
12 2020 Jan 5.5 Jan-2020 3.8 2.8 2.0 3.1 6.0 3.0 4.3 3.3 3.2
13 2010 Feb 15.8 Feb-2010 10.7 8.1 4.9 8.9 16.1 8.2 12.7 10.3 8.0
14 2011 Feb 14.0 Feb-2011 9.7 7.9 4.3 8.1 15.5 6.7 11.8 8.9 7.9
15 2012 Feb 13.1 Feb-2012 8.3 7.2 4.2 7.4 14.0 6.2 10.9 7.7 7.6
16 2013 Feb 11.3 Feb-2013 7.9 6.5 3.9 6.8 13.8 6.0 9.7 7.0 7.0
17 2014 Feb 9.8 Feb-2014 6.4 6.0 3.4 5.8 11.8 5.9 8.2 6.3 5.9
18 2015 Feb 8.2 Feb-2015 5.4 5.0 2.7 4.7 10.1 4.0 6.8 5.2 4.9
19 2016 Feb 7.0 Feb-2016 5.2 4.2 2.5 4.3 8.5 3.8 5.4 4.5 4.5
20 2017 Feb 7.7 Feb-2017 4.9 4.0 2.4 4.0 7.9 3.4 5.5 4.3 4.2
21 2018 Feb 5.7 Feb-2018 4.4 3.5 2.2 3.7 6.7 2.9 4.9 3.7 3.8
22 2019 Feb 5.3 Feb-2019 3.7 3.1 2.2 3.3 6.9 3.1 4.3 3.5 3.4
23 2020 Feb 5.7 Feb-2020 3.6 3.0 1.9 3.1 5.8 2.5 4.4 3.3 3.1
24 2010 Mar 14.9 Mar-2010 11.0 8.4 4.9 8.9 16.8 7.6 12.9 10.2 8.1
25 2011 Mar 14.1 Mar-2011 9.7 7.5 4.4 8.0 15.8 7.3 11.6 8.8 7.8
26 2012 Mar 12.8 Mar-2012 8.1 7.5 4.1 7.3 14.0 6.4 10.6 7.7 7.4
27 2013 Mar 11.1 Mar-2013 7.7 6.3 3.8 6.7 13.0 5.1 9.3 6.9 6.9
28 2014 Mar 9.4 Mar-2014 6.3 6.0 3.4 5.8 12.1 5.5 7.9 6.1 6.2
29 2015 Mar 8.6 Mar-2015 5.3 4.8 2.4 4.8 9.9 3.2 6.8 5.1 4.9
30 2016 Mar 7.3 Mar-2016 5.3 4.1 2.6 4.3 8.9 3.9 5.5 4.5 4.6
31 2017 Mar 6.6 Mar-2017 4.9 3.7 2.4 3.9 7.9 3.3 5.0 4.2 3.9
32 2018 Mar 5.5 Mar-2018 4.3 3.5 2.2 3.6 6.8 3.1 5.0 3.7 3.7
33 2019 Mar 5.8 Mar-2019 3.7 3.4 2.0 3.4 6.6 3.1 4.7 3.6 3.3
34 2020 Mar 6.8 Mar-2020 4.4 3.7 2.5 4.0 6.7 4.1 6.0 4.0 4.0
35 2010 Apr 14.7 Apr-2010 10.8 8.4 4.8 9.0 16.6 7.0 12.5 10.2 8.3
36 2011 Apr 14.7 Apr-2011 9.9 7.5 4.5 8.1 16.5 6.5 11.9 8.9 8.0
37 2012 Apr 12.5 Apr-2012 8.0 7.6 4.0 7.4 13.3 5.4 10.3 7.6 7.4
38 2013 Apr 11.6 Apr-2013 7.5 6.4 3.9 6.7 13.3 5.3 9.0 7.2 6.7
39 2014 Apr 8.7 Apr-2014 6.2 5.7 3.3 5.3 11.6 5.9 7.2 5.9 5.6
40 2015 Apr 8.4 Apr-2015 5.5 4.7 2.7 4.7 9.7 4.4 6.8 5.0 5.0
41 2016 Apr 7.6 Apr-2016 5.5 4.2 2.4 4.4 8.8 3.8 6.1 4.6 4.6
42 2017 Apr 6.4 Apr-2017 4.6 3.7 2.5 3.9 7.9 3.3 5.1 3.9 4.1
43 2018 Apr 5.8 Apr-2018 4.3 3.4 2.1 3.6 6.4 2.8 4.8 3.7 3.5
44 2019 Apr 5.3 Apr-2019 3.4 3.1 2.1 3.1 6.6 2.2 4.2 3.4 3.1
45 2020 Apr Apr-2020
46 2010 May 14.6 May-2010 10.9 8.2 4.6 8.7 15.5 7.8 12.0 9.7 8.1
47 2011 May 14.5 May-2011 9.6 7.8 4.5 7.9 16.3 7.2 11.6 8.8 8.0
48 2012 May 12.9 May-2012 8.3 7.7 3.9 7.4 13.5 5.5 10.9 7.7 7.4
49 2013 May 11.0 May-2013 7.3 6.5 3.9 6.7 13.4 4.5 9.0 7.1 6.5
50 2014 May 9.2 May-2014 6.5 5.5 3.2 5.4 11.4 5.7 7.7 5.9 5.8
51 2015 May 8.7 May-2015 5.8 4.4 2.8 4.8 10.3 4.1 6.8 5.2 5.1
52 2016 May 7.5 May-2016 5.1 3.9 2.5 4.2 8.2 4.2 5.6 4.5 4.3
53 2017 May 6.3 May-2017 4.8 4.1 2.3 3.8 7.7 3.7 5.2 4.0 4.1
54 2018 May 5.5 May-2018 3.9 3.3 2.0 3.5 5.9 2.2 4.9 3.6 3.4
55 2019 May 5.4 May-2019 3.6 2.8 2.1 3.3 6.2 2.5 4.2 3.4 3.3
56 2020 May May-2020
57 2010 Jun 14.2 Jun-2010 10.6 8.1 4.4 8.6 15.2 7.4 12.3 9.7 7.7
58 2011 Jun 14.4 Jun-2011 10.0 8.3 4.3 8.1 16.2 6.5 11.5 9.0 8.0
59 2012 Jun 12.6 Jun-2012 8.6 7.3 4.0 7.3 14.5 6.1 10.9 7.7 7.4
60 2013 Jun 10.7 Jun-2013 7.7 6.5 3.8 6.6 14.2 4.7 9.1 7.0 6.8
61 2014 Jun 9.2 Jun-2014 5.9 5.2 3.3 5.3 11.0 4.7 7.8 5.7 5.3
62 2015 Jun 8.2 Jun-2015 5.4 4.2 2.5 4.6 9.7 3.9 6.7 4.8 4.7
63 2016 Jun 7.6 Jun-2016 5.1 4.2 2.5 4.3 8.8 3.5 5.9 4.5 4.4
64 2017 Jun 6.5 Jun-2017 4.6 3.8 2.3 3.8 7.1 3.6 4.9 4.0 4.0
65 2018 Jun 5.5 Jun-2018 4.1 3.3 2.3 3.5 6.5 3.2 4.5 3.7 3.6
66 2019 Jun 5.3 Jun-2019 3.9 3.0 2.1 3.3 6.0 2.1 4.3 3.3 3.3
67 2020 Jun Jun-2020
68 2010 Jul 13.5 Jul-2010 10.0 8.3 4.5 8.5 15.6 7.9 12.2 9.6 7.9
69 2011 Jul 14.5 Jul-2011 9.1 8.3 4.2 8.0 15.9 7.4 11.2 8.8 7.9
70 2012 Jul 12.4 Jul-2012 8.5 7.2 4.1 7.3 14.2 5.9 10.2 7.7 7.4
71 2013 Jul 10.8 Jul-2013 7.5 6.1 3.8 6.5 12.6 5.3 9.4 7.0 6.3
72 2014 Jul 9.5 Jul-2014 6.1 5.3 3.1 5.3 11.6 4.2 7.7 5.7 5.6
73 2015 Jul 8.3 Jul-2015 5.5 4.3 2.5 4.5 9.1 3.9 6.9 4.8 4.8
74 2016 Jul 6.5 Jul-2016 5.1 4.2 2.5 4.2 8.4 3.8 5.5 4.6 4.2
75 2017 Jul 7.1 Jul-2017 4.5 3.7 2.3 3.7 7.4 3.8 5.1 4.0 3.9
76 2018 Jul 5.2 Jul-2018 4.1 3.2 2.2 3.3 6.6 3.1 4.4 3.4 3.6
77 2019 Jul 5.2 Jul-2019 3.6 3.2 2.1 3.3 5.9 2.8 4.5 3.3 3.3
78 2020 Jul Jul-2020
79 2010 Aug 14.1 Aug-2010 10.0 8.7 4.6 8.6 15.9 7.3 12.0 9.6 8.0
80 2011 Aug 14.1 Aug-2011 9.3 8.3 4.2 7.9 16.4 7.2 11.2 8.7 7.9
81 2012 Aug 11.8 Aug-2012 8.6 6.7 4.1 7.2 13.8 5.9 10.1 7.6 7.3
82 2013 Aug 11.1 Aug-2013 7.4 6.1 3.4 6.4 12.8 5.1 9.2 7.1 6.2
83 2014 Aug 9.2 Aug-2014 6.1 5.3 3.2 5.3 11.4 4.5 7.4 5.7 5.6
84 2015 Aug 7.9 Aug-2015 5.5 4.3 2.4 4.4 9.4 3.4 6.6 4.7 4.6
85 2016 Aug 7.4 Aug-2016 5.0 4.2 2.6 4.3 8.0 4.1 5.6 4.5 4.4
86 2017 Aug 6.1 Aug-2017 5.1 3.7 2.4 3.8 7.7 3.9 5.2 4.1 4.0
87 2018 Aug 5.7 Aug-2018 3.9 3.5 2.0 3.4 6.3 3.0 4.7 3.5 3.5
88 2019 Aug 5.4 Aug-2019 3.6 3.0 2.1 3.4 5.4 2.8 4.2 3.3 3.3
89 2020 Aug Aug-2020
90 2010 Sep 15.6 Sep-2010 9.7 8.9 4.5 8.6 16.0 6.6 12.3 9.6 8.0
91 2011 Sep 14.3 Sep-2011 9.4 8.5 4.2 7.9 15.9 8.0 11.2 8.7 8.2
92 2012 Sep 11.7 Sep-2012 8.5 6.6 4.0 7.0 13.6 4.9 9.7 7.3 7.1
93 2013 Sep 10.5 Sep-2013 7.6 6.1 3.7 6.3 13.0 5.4 8.8 7.1 6.2
94 2014 Sep 8.5 Sep-2014 5.4 5.4 2.9 5.1 11.0 4.4 6.8 5.3 5.5
95 2015 Sep 7.9 Sep-2015 5.3 4.3 2.5 4.4 9.3 3.5 6.2 4.7 4.6
96 2016 Sep 8.5 Sep-2016 5.3 4.2 2.5 4.4 8.5 3.8 6.4 4.7 4.4
97 2017 Sep 6.7 Sep-2017 4.4 3.6 2.3 3.7 7.2 3.6 5.1 3.9 3.9
98 2018 Sep 5.7 Sep-2018 3.8 3.2 2.0 3.3 6.2 3.5 4.6 3.4 3.3
99 2019 Sep 4.8 Sep-2019 3.6 2.9 2.0 3.2 5.5 2.5 3.9 3.2 3.1
100 2020 Sep Sep-2020
101 2010 Oct 15.0 Oct-2010 9.8 8.2 4.6 8.6 15.6 7.2 12.3 9.4 8.0
102 2011 Oct 13.5 Oct-2011 9.4 8.1 4.3 7.9 14.6 7.4 11.3 8.6 7.8
103 2012 Oct 12.1 Oct-2012 8.3 6.9 3.7 6.9 14.1 4.9 10.0 7.2 7.1
104 2013 Oct 10.9 Oct-2013 7.2 6.4 3.7 6.3 12.8 5.4 9.1 6.9 6.3
105 2014 Oct 8.1 Oct-2014 5.7 4.9 3.0 4.9 10.6 5.1 6.8 5.1 5.4
106 2015 Oct 7.6 Oct-2015 5.2 4.4 2.5 4.4 9.0 3.5 6.3 4.7 4.6
107 2016 Oct 7.4 Oct-2016 5.4 3.9 2.6 4.4 8.4 3.4 5.8 4.6 4.4
108 2017 Oct 5.9 Oct-2017 4.2 3.7 2.1 3.5 7.4 3.0 4.9 3.8 3.7
109 2018 Oct 5.9 Oct-2018 4.0 3.1 2.0 3.3 6.3 3.1 4.4 3.5 3.4
110 2019 Oct 5.5 Oct-2019 3.7 2.8 2.1 3.2 5.5 2.8 4.1 3.2 3.2
111 2020 Oct Oct-2020
112 2010 Nov 15.4 Nov-2010 10.0 8.6 5.0 8.9 16.2 7.5 12.9 9.9 8.4
113 2011 Nov 12.8 Nov-2011 8.8 7.7 4.4 7.7 15.6 6.4 11.2 8.2 7.8
114 2012 Nov 12.0 Nov-2012 8.0 6.5 3.9 6.8 13.3 6.3 9.9 7.2 7.0
115 2013 Nov 10.7 Nov-2013 7.2 6.4 3.4 6.1 12.3 5.2 8.7 6.6 6.2
116 2014 Nov 8.6 Nov-2014 5.7 4.9 3.2 5.0 10.9 4.8 6.6 5.4 5.3
117 2015 Nov 6.8 Nov-2015 5.4 4.4 2.5 4.4 9.4 3.9 6.4 4.8 4.6
118 2016 Nov 7.8 Nov-2016 5.0 3.9 2.4 4.2 8.1 3.1 5.8 4.3 4.3
119 2017 Nov 5.2 Nov-2017 4.4 3.6 2.1 3.7 7.4 3.0 4.8 3.8 3.7
120 2018 Nov 5.6 Nov-2018 3.5 3.1 2.2 3.4 6.1 2.8 4.5 3.3 3.4
121 2019 Nov 5.3 Nov-2019 3.7 2.9 2.0 3.2 5.6 2.6 4.2 3.2 3.2
122 2020 Nov Nov-2020
123 2010 Dec 15.0 Dec-2010 9.8 8.1 4.8 8.5 15.5 7.2 12.9 9.4 8.0
124 2011 Dec 13.7 Dec-2011 8.7 7.6 4.1 7.5 15.4 6.8 11.1 8.0 7.8
125 2012 Dec 11.8 Dec-2012 8.0 6.9 4.0 6.9 14.0 6.6 9.6 7.2 7.4
126 2013 Dec 9.8 Dec-2013 7.0 6.2 3.3 5.9 11.9 4.3 8.3 6.3 6.1
127 2014 Dec 8.6 Dec-2014 5.3 5.0 2.8 4.7 10.6 4.4 6.4 5.2 5.1
128 2015 Dec 6.4 Dec-2015 5.6 4.1 2.5 4.4 8.5 4.1 6.2 4.6 4.5
129 2016 Dec 7.5 Dec-2016 5.1 3.8 2.5 4.2 7.9 2.7 5.9 4.4 4.3
130 2017 Dec 6.2 Dec-2017 4.2 3.6 2.2 3.7 6.7 2.5 5.0 3.7 3.7
131 2018 Dec 5.8 Dec-2018 3.8 3.3 2.2 3.4 6.6 3.3 4.4 3.6 3.5
132 2019 Dec 5.2 Dec-2019 3.7 2.7 1.9 3.2 5.9 2.5 4.2 3.1 3.2
133 2020 Dec Dec-2020

@ -0,0 +1,53 @@
DROP TABLE IF EXISTS suivre;
DROP TABLE IF EXISTS louer;
DROP TABLE IF EXISTS instrument;
DROP TABLE IF EXISTS eleve;
DROP TABLE IF EXISTS professeur;
DROP TABLE IF EXISTS niveau;
CREATE TABLE niveau
(
niveau SERIAL PRIMARY KEY,
tarifHoraire INT NOT NULL
);
CREATE TABLE professeur
(
num SERIAL PRIMARY KEY,
nom VARCHAR(255) NOT NULL,
prenom VARCHAR(255) NOT NULL,
noTel CHAR(10) NOT NULL
);
CREATE TABLE eleve
(
num SERIAL PRIMARY KEY,
nom VARCHAR(255) NOT NULL,
prenom VARCHAR(255) NOT NULL,
age INT NOT NULL,
rue VARCHAR(255) NOT NULL,
codePostal VARCHAR(255) NOT NULL,
ville VARCHAR(255) NOT NULL
);
CREATE TABLE instrument
(
id SERIAL PRIMARY KEY,
designation VARCHAR(255),
tarifLocation INT NOT NULL,
prof INT NOT NULL REFERENCES professeur (num)
);
CREATE TABLE suivre
(
eleve INT NOT NULL REFERENCES eleve (num),
instrument INT NOT NULL REFERENCES instrument (id),
niveau INT NOT NULL REFERENCES niveau (niveau)
);
CREATE TABLE louer
(
eleve INT NOT NULL REFERENCES eleve (num),
instrument INT NOT NULL REFERENCES instrument (id)
);

@ -0,0 +1,237 @@
import pandas
import psycopg2 # pip3 install types-psycopg2
import matplotlib.pyplot as plt
import numpy as np
from getpass import getpass
##########
# Partie 1
##########
def part1_create_table(connection: psycopg2.connection, filename: str) -> pandas.DataFrame:
cur = connection.cursor()
# 2. Création et population de la table
cur.execute("""CREATE TABLE IF NOT EXISTS plain_jeu (
nom VARCHAR(150) NOT NULL,
plateforme VARCHAR(10) NOT NULL,
annee_sortie INTEGER,
genre VARCHAR(20) NOT NULL,
editeur VARCHAR(40) NOT NULL,
ventes_na NUMERIC(6, 2) NOT NULL DEFAULT 0,
ventes_ue NUMERIC(6, 2) NOT NULL DEFAULT 0,
ventes_jp NUMERIC(6, 2) NOT NULL DEFAULT 0,
ventes_autre NUMERIC(6, 2) NOT NULL DEFAULT 0,
ventes_total NUMERIC(6, 2) NOT NULL DEFAULT 0, -- Redondant vu que devrait être le total des autres colonnes des ventes
PRIMARY KEY(nom, plateforme)
)""")
ventes = pandas.read_csv(filename)
# 3. Élimination des doublons
df = pandas.DataFrame(ventes).drop_duplicates(subset=['Name', 'Platform'])
# 2. Insertions
for row in df.itertuples():
cur.execute("INSERT INTO plain_jeu VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s);",
(row.Name, row.Platform, int(row.Year) if not pandas.isnull(row.Year) else None, row.Genre,
row.Publisher, row.NA_Sales, row.EU_Sales,
row.JP_Sales, row.Other_Sales, row.Global_Sales))
# 5. Recherche des lignes incohérentes (par delta vu qu'il s'agit de nombre flottants)
cur.execute("""SELECT nom, plateforme, ROUND((ventes_na + ventes_ue + ventes_jp + ventes_autre)::numeric, 2), ventes_total
FROM plain_jeu
WHERE ABS(ventes_na + ventes_ue + ventes_jp + ventes_autre - ventes_total) > 0.1""")
for row in cur.fetchall():
print(row)
# 6. Recalcul des ventes pour les lignes incohérentes
cur.execute("""UPDATE plain_jeu
SET ventes_total = ROUND((ventes_na + ventes_ue + ventes_jp + ventes_autre)::numeric, 2)
WHERE ABS(ventes_na + ventes_ue + ventes_jp + ventes_autre - ventes_total) > 0.1;""")
connection.commit()
cur.close()
# 7. Création du DataFrame propre
return pandas.read_sql("SELECT * FROM plain_jeu;", con=connection)
##########
# Partie 2
##########
def part2_graphs(connection: psycopg2.connection):
# 1. Calcul des ventes moyennes par année de sortie et pour le genre aventure
df = pandas.read_sql("""SELECT annee_sortie, AVG(ventes_total) ventes_moyennes, SUM(ventes_total) ventes_totales FROM plain_jeu
WHERE genre = 'Adventure' AND annee_sortie IS NOT NULL
GROUP BY annee_sortie
ORDER BY annee_sortie;""", con=connection)
# 2/3. Affichage sous forme de courbe
fig = df.plot(x='annee_sortie', y=['ventes_moyennes', 'ventes_totales'])
fig.legend(['Ventes moyennes', 'Ventes totales'])
fig.set_xlabel('Année de sortie')
fig.set_ylabel('Ventes (en millions)')
# 4. Ventes totales pour l'ensemble des jeux
df = pandas.read_sql("""SELECT annee_sortie, genre, SUM(ventes_total) ventes_totales FROM plain_jeu
WHERE annee_sortie IS NOT NULL
GROUP BY annee_sortie, genre
ORDER BY annee_sortie;""", con=connection)
fig, ax = plt.subplots()
for i, (label, group) in enumerate(df.groupby(['genre'])):
ax = group.plot(ax=ax, kind='line', x='annee_sortie',
y='ventes_totales', label=label, color=plt.cm.tab20.colors[i])
ax.set_xlabel('Année de sortie')
ax.set_ylabel('Ventes (en millions)')
##########
# Partie 3
##########
def part3_graphs(connection: psycopg2.connection):
# 1. Calcul du total des ventes en Europe par plateforme
df = pandas.read_sql("""SELECT plateforme, SUM(ventes_ue) ventes_ue FROM plain_jeu
GROUP BY plateforme
ORDER BY ventes_ue;""", con=connection)
def plot_ventes_ue(df: pandas.DataFrame, plot_kind: str = 'line'):
fig = df.plot(x='plateforme', y='ventes_ue', legend=False, kind=plot_kind)
fig.set_xlabel('Plateforme')
fig.set_ylabel('Ventes en Europe (en millions)')
fig.set_xticks(np.arange(len(df))) # Force l'affichage de tous les labels en abscisse
fig.set_xticklabels(df['plateforme'])
fig.set_title('Ventes de jeux vidéos en Europe par plateforme')
# 2. Affichage sous forme de courbe
plot_ventes_ue(df)
# 3. Affichage sous forme d'histogramme
# plot_ventes_ue(df, 'hist')
plot_ventes_ue(df, 'bar')
# 4. Calcul du total des ventes par plateforme et par zone géographique
df = pandas.read_sql("""SELECT plateforme, SUM(ventes_na) ventes_na, SUM(ventes_ue) ventes_ue, SUM(ventes_jp) ventes_jp, SUM(ventes_autre) ventes_autre FROM plain_jeu
GROUP BY plateforme
ORDER BY SUM(ventes_total);""", con=connection)
# 5/6. Affichage sous forme de courbes
fig = df.plot(x='plateforme', style=[
'r*-', 'bo--', 'y^:', 'gs-.'])
fig.set_xticks(np.arange(len(df['plateforme'])))
fig.set_xticklabels(df['plateforme'])
fig.set_xlabel('Plateforme')
fig.set_ylabel('Ventes (en millions)')
fig = df.plot.bar(x='plateforme', y=[
'ventes_na', 'ventes_ue', 'ventes_jp', 'ventes_autre'])
fig.set_xlabel('Plateforme')
fig.set_ylabel('Ventes (en millions)')
##########
# Partie 4
##########
def plot_ventes_jeu(cur: psycopg2.cursor, nom: str, pourcentages: bool = True):
# 1. Récupération des ventes, réorganisées en plusieurs lignes dans le dataframe
cur.execute("""SELECT ventes_na, ventes_ue, ventes_jp, ventes_autre FROM plain_jeu
WHERE nom = '%s';""" % nom)
data = cur.fetchone()
zones = [desc[0].split('_')[1] for desc in cur.description]
df = pandas.DataFrame([[zones[i], float(data[i])] for i in range(len(data))], columns=['zone', 'ventes'],
index=zones)
title = 'Ventes du jeu ' + nom + ' par zone géographique'
# 2. Diagramme en bâtons
fig = df.plot.bar(x='zone', y='ventes', legend=False, rot=0)
fig.set_title(title)
if pourcentages:
# 4. Diagramme camembert avec pourcentages
fig = df.plot.pie(y='ventes', labels=None, autopct='%1.1f%%')
else:
# 3. Diagramme camembert
fig = df.plot.pie(y='ventes', legend=False)
fig.set_title(title)
fig.set_xlabel('Zone géographique')
fig.set_ylabel('Ventes (en millions)')
def part4_graphs(connection: psycopg2.connection):
with connection.cursor() as cur:
plot_ventes_jeu(cur, 'Mario Kart 64')
# 5. Résultats de Mario Kart Wii
plot_ventes_jeu(cur, 'Mario Kart Wii')
##########
# Partie 5
##########
def part5_graphs(connection: psycopg2.connection):
# 1/2. Pourcentage du total des ventes par genre
df = pandas.read_sql("""SELECT genre, SUM(ventes_total) total_ventes FROM plain_jeu
GROUP BY genre;""", con=connection)
df.set_index('genre', inplace=True)
# 3. Diagramme camembert
fig = df.plot.pie(y='total_ventes', legend=False, autopct='%1.1f%%', colors=plt.cm.tab20.colors)
fig.set_title('Ventes mondiales de jeux vidéos par genre')
fig.set_ylabel('')
# 4. 4 camemberts du total des ventes par genre et par
df = pandas.read_sql("""
SELECT CASE WHEN annee_sortie < 1990 THEN '< 1990'
WHEN annee_sortie BETWEEN 1990 AND 1999 THEN '<=> 1990-1999'
WHEN annee_sortie BETWEEN 2000 AND 2009 THEN '<=> 2000-2009'
WHEN annee_sortie >= 2010 THEN '>= 2010'
END annee,
genre,
SUM(ventes_total) ventes_totales
FROM plain_jeu
WHERE annee_sortie IS NOT NULL
GROUP BY annee, genre
ORDER BY annee, genre;""", con=connection)
grouped = df.groupby('annee')
rowlength = grouped.ngroups // 2
fig, axs = plt.subplots(figsize=(9, 4), nrows=2, ncols=rowlength)
targets = zip(grouped.groups.keys(), axs.flatten())
legend = []
for (key, ax) in targets:
group = grouped.get_group(key)
legend = group['genre']
ax = group.plot.pie(ax=ax, y='ventes_totales', labels=None,
legend=False, colors=plt.cm.tab20.colors)
ax.set_ylabel('')
ax.set_title(key)
fig.legend(legend)
fig.suptitle('Ventes de jeux vidéos par genre et par période')
if __name__ == '__main__':
db_host = input('Nom d\'hôte : ')
if not db_host:
db_host = 'berlin'
db_name = input('Nom de la base de données : ')
if not db_name:
db_name = 'dbclfreville2'
db_user = input('Utilisateur : ')
if not db_user:
db_user = 'clfreville2'
db_password = getpass('Mot de passe : ')
connection = psycopg2.connect(host=db_host, port=5432, database=db_name, user=db_user, password=db_password)
#part1_create_table(connection, 'vgsales.csv')
part2_graphs(connection)
part3_graphs(connection)
part4_graphs(connection)
part5_graphs(connection)
connection.close()
plt.show()

@ -0,0 +1,52 @@
-- Combien dathlètes y a til ?
SELECT COUNT(*) FROM athlete;
-- Afficher les épreuves ayant eu lieu le 29 juillet 2021.
SELECT * FROM epreuve WHERE dateE = '2021-07-29';
-- Afficher le nom des disciplines ayant une épreuve le 29 juillet 2021.
SELECT DISTINCT e.nom FROM epreuve e
INNER JOIN discipline d ON e.discipl = d.code
WHERE dateE = '2021-07-29';
SELECT nom, prenom, dateNaiss FROM athlete
WHERE pays = (SELECT code FROM pays WHERE nom = 'France')
ORDER BY nom, prenom;
SELECT COUNT(*) medailles FROM resultat
WHERE athlete = (
SELECT code FROM athlete
WHERE nom = 'LEDECKY'
AND prenom = 'Kathleen'
);
SELECT a.nom nom_vainqueure, a.prenom prenom_vainqueure, p.nom pays_vainqueur, e.nom epreuve, d.nom discipline
FROM epreuve e
INNER JOIN discipline d ON d.code = e.discipl
INNER JOIN resultat r ON r.epreuve = e.code
INNER JOIN athlete a ON a.code = r.athlete
INNER JOIN pays p ON p.code = a.pays
WHERE e.code = 'E059'
AND medaille = (SELECT place FROM medaille WHERE couleur = 'Or');
-- Qui est lathlète le ou la plus jeune, parmi ceux dont on connaît la date de naissance ?
SELECT * FROM athlete
WHERE dateNaiss = (
SELECT MAX(dateNaiss) FROM athlete
WHERE dateNaiss IS NOT NULL
);
-- Qui est lathlète le ou la plus agée et quel était son âge à louverture des jeux (le 23 juillet2021) ?
SELECT *, ROUND(('2021-07-23'-dateNaiss) / 365.2422, 1) age FROM athlete
WHERE dateNaiss = (
SELECT MIN(dateNaiss) FROM athlete
WHERE dateNaiss IS NOT NULL
);
-- Lister les pays dont le nom commence par A et qui nont remporté aucune médaille.
SELECT * FROM pays
WHERE code NOT IN (
SELECT a.pays FROM resultat r
INNER JOIN athlete a ON a.code = r.athlete
) AND nom LIKE 'A%';

@ -0,0 +1,212 @@
-- 1. Écrire une fonction nb_femmes_v1 (sans utiliser de curseur) qui retourne le nombre dathlètes féminines concourant pour le pays dont le nom est passé en paramètre.
CREATE OR REPLACE FUNCTION nb_femmes_v1(nom_pays pays.nom%TYPE)
RETURNS INT AS $$
BEGIN
return (
SELECT COUNT(*)
FROM athlete a
INNER JOIN pays p ON p.code = a.pays
WHERE p.nom = nom_pays AND a.sexe = 'F'
);
END;
$$ LANGUAGE plpgsql;
-- 2. Même question, mais la fonction nb_femmes_v2 devra utiliser un curseur.
CREATE OR REPLACE FUNCTION nb_femmes_v2(nom_pays pays.nom%TYPE)
RETURNS INT AS $$
DECLARE
curs cursor FOR SELECT a.pays, a.paysNaiss
FROM athlete a
INNER JOIN pays p ON p.code = a.pays
WHERE p.nom = nom_pays AND sexe = 'F';
rec athlete.code%TYPE;
n INT := 0;
BEGIN
open curs;
fetch curs into rec;
while found loop
n = n + 1;
fetch curs into rec;
end loop;
close curs;
return n;
END;
$$ LANGUAGE plpgsql;
-- 3. Vérifier que vos deux fonctions retournent bien le même résultat. Vous pouvez par exemple tester avec la France.
SELECT nb_femmes_v1('France'), nb_femmes_v2('France');
-- 4. Modifier les deux fonctions précédentes pour ne compter que les athlètes féminines qui concourent pour un pays différent de leur pays de naissance.
CREATE OR REPLACE FUNCTION nb_femmes_v1(nom_pays pays.nom%TYPE)
RETURNS INT AS $$
BEGIN
return (
SELECT COUNT(*)
FROM athlete a
INNER JOIN pays p ON p.code = a.pays
WHERE p.nom = nom_pays AND a.sexe = 'F' AND a.pays != a.paysNaiss
);
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION nb_femmes_v2(nom_pays pays.nom%TYPE)
RETURNS INT AS $$
DECLARE
curs cursor FOR SELECT a.pays, a.paysNaiss
FROM athlete a
INNER JOIN pays p ON p.code = a.pays
WHERE p.nom = nom_pays AND sexe = 'F';
pays athlete.pays%TYPE;
paysNaiss athlete.paysNaiss%TYPE;
n INT := 0;
BEGIN
open curs;
fetch curs into pays, paysNaiss;
while found loop
if pays != paysNaiss then
n = n + 1;
end if;
fetch curs into pays, paysNaiss;
end loop;
close curs;
return n;
END;
$$ LANGUAGE plpgsql;
-- 5. Vérifier que vos deux fonctions retournent bien le même résultat.
SELECT nb_femmes_v1('France'), nb_femmes_v2('France');
-- 6. Ecrire un bloc PL/pgSQL anonyme permettant de mettre à jour le pays de naissance des athlètes pour lequel linformation nest pas connue, en indiquant comme pays celui pour lequel ils concourent. Afficher un message à chaque modification.
DO $$
DECLARE
curs cursor FOR SELECT pays
FROM athlete
WHERE paysNaiss IS NULL
FOR UPDATE;
athlete_pays athlete.pays%TYPE;
BEGIN
open curs;
fetch curs into athlete_pays;
while found loop
UPDATE athlete SET paysNaiss = athlete_pays WHERE CURRENT OF curs;
raise notice 'update';
fetch curs into athlete_pays;
end loop;
close curs;
END;
$$ LANGUAGE plpgsql;
-- 7. Pour pouvoir gérer laffectation des chambres dans le village olympique, lorganisation a besoin de connaître les dates de présence de chaque athlète. Créer une table Present(#athlete, dateArrivee, dateDepart).
DROP TABLE IF EXISTS present;
CREATE TABLE IF NOT EXISTS present (
athlete CHAR(6) PRIMARY KEY REFERENCES athlete(code),
dateArrivee DATE NOT NULL,
dateDepart DATE NOT NULL
);
-- 8. Ecrire un bloc PL/pgSQL anonyme permettant de remplir la table Present
INSERT INTO present
SELECT
a.code,
(MIN(e.dateE) - 14) dateArrivee,
LEAST(
'2021-08-11',
MAX(e.dateE) + 1 + (
CASE WHEN COUNT(r.medaille) >= 3 THEN 5
WHEN COUNT(r.medaille) >= 1 THEN 3
ELSE 0
END
)
) dateDepart
FROM athlete a
INNER JOIN pratiquer p ON p.athlete = a.code
INNER JOIN epreuve e ON e.discipl = p.discipl
LEFT JOIN resultat r ON r.athlete = a.code
GROUP BY a.code;
-- Version bloc anonyme
/*DO $$
DECLARE
curs cursor FOR SELECT a.code, MIN(e.dateE), MAX(e.dateE), COUNT(r.medaille)
FROM athlete a
INNER JOIN pratiquer p ON p.athlete = a.code
INNER JOIN epreuve e ON e.discipl = p.discipl
LEFT JOIN resultat r ON r.athlete = a.code
GROUP BY a.code;
code_athlete athlete.code%TYPE;
debut_epreuves DATE;
fin_epreuves DATE;
nb_medailles INT;
date_arrivee DATE;
date_depart DATE;
BEGIN
open curs;
fetch curs into code_athlete, debut_epreuves, fin_epreuves, nb_medailles;
while found loop
date_arrivee = debut_epreuves - 14;
if nb_medailles >= 3 then
date_depart := fin_epreuves + 6;
elsif nb_medailles >= 1 then
date_depart := fin_epreuves + 4;
else
date_depart := fin_epreuves + 1;
end if;
if date_depart > '2021-08-11' then
date_depart := '2021-08-11';
end if;
INSERT INTO present VALUES(code_athlete, date_arrivee, date_depart);
fetch curs into code_athlete, debut_epreuves, fin_epreuves, nb_medailles;
end loop;
close curs;
END;
$$ LANGUAGE plpgsql;*/
-- 9. Ecrire une fonction nbAth_jour qui prend en paramètre le nom dun pays, un sexe et une date et retourne le nombre dathlètes du pays et du sexe donnés présents au village olympique à la date donnée.
CREATE OR REPLACE FUNCTION nbAth_jour(nom_pays pays.nom%TYPE, sexe_athlete athlete.sexe%TYPE, date_presence DATE)
RETURNS INT AS $$
BEGIN
return (
SELECT COUNT(*) FROM present p
INNER JOIN athlete a ON a.code = p.athlete
WHERE a.pays = (SELECT code FROM pays WHERE nom = nom_pays)
AND sexe = sexe_athlete
AND date_presence BETWEEN dateArrivee AND dateDepart
);
END;
$$ LANGUAGE plpgsql;
-- 10. Utiliser la fonction nbAth_jour pour savoir combien de chambres sont nécessaires pour la délégation française le 6 août 2021, sachant que les athlètes sont deux par chambre et quil ny a pas de chambre mixte.
SELECT CEIL(nbAth_jour('France', 'F', '2021-08-06')::FLOAT / 2) + CEIL(nbAth_jour('France', 'M', '2021-08-06')::FLOAT / 2);
-- 11. Un virus circule. Ecrire une fonction confiner qui prend un paramètre (une date) et qui permet de repousser dune semaine, si besoin, le départ des athlètes qui étaient présents au village olympique à la date donnée. La fonction devra retourner le nombre dathlètes impactés
DROP FUNCTION confiner;
CREATE OR REPLACE FUNCTION confiner(date_confinement DATE)
RETURNS INT AS $$
DECLARE
curs cursor FOR SELECT dateDepart
FROM present
WHERE date_confinement BETWEEN dateArrivee AND dateDepart
FOR UPDATE;
date_depart present.dateDepart%TYPE;
nb INT := 0;
BEGIN
open curs;
fetch curs into date_depart;
while found loop
-- UPDATE present SET dateDepart = GREATEST(date_confinement + 7, dateDepart) WHERE CURRENT OF curs;
if (date_confinement + 7) > date_depart then
UPDATE present SET dateDepart = (date_confinement + 7) WHERE CURRENT OF curs;
nb = nb + 1;
end if;
fetch curs into date_depart;
end loop;
close curs;
return nb;
END;
$$ LANGUAGE plpgsql;
SELECT confiner('2021-07-27');
-- 12. Executer le script jo.sql pour annuler les modifications réalisées pendant ce tp.
\i jo.sql

@ -0,0 +1,44 @@
-- 1
SELECT rolname FROM pg_roles;
-- 2
CREATE TABLE test_clfreville2
(
id CHAR(4) PRIMARY KEY,
msg VARCHAR(60)
);
INSERT INTO test_clfreville2 VALUES
('AAAA', 'Félicitations vous avez découvert le premier message'),
('BBBB', 'Saviez-vous que l''ornithorynque est un mammifère?'),
('CCCC', 'Un tiens vaut mieux que deux tu l''auras'),
('DDDD', 'Le boutisme (endianness) c''est le genre des entiers');
-- 3
--CREATE ROLE test_clfreville2_lodufour1 LOGIN
--VALID UNTIL '2022-05-09';
--ALTER TABLE test_clfreville2 OWNER TO test_clfreville2_lodufour1;
-- 4
ALTER TABLE test_clfreville2
ADD nb NUMERIC;
-- 5
ALTER TABLE test_lodufour1 OWNER TO lodufour1;
-- 6
GRANT SELECT ON test_clfreville2 TO public;
--SELECT * FROM dblink('dbname=dblodufour1', 'SELECT * FROM test_lodufour1');
-- 7
INSERT INTO test_lodufour1 VALUES ('DMRT', 'Jeu de l''oie');
-- 8
REVOKE SELECT ON test_clfreville2 FROM public;
-- Connexion à une autre db depuis une connexion courante :
GRANT CONNECT ON DATABASE dbclfreville2 TO lodufour1; -- Autorise la connexion
GRANT INSERT ON test_clfreville2 TO lodufour1; -- Autorise l'insertion à un utilisateur
\connect dblodufour1
SELECT * FROM test_lodufour1;

@ -0,0 +1,119 @@
-- 1. Écrire une requête permettant de lister les codes de pays et le nombre de médailles dor quils ont remporté
SELECT a.pays code_pays,
COUNT(DISTINCT r.epreuve) medailles_or
FROM resultat r
INNER JOIN athlete a ON a.code = r.athlete
WHERE r.medaille = (
SELECT place FROM medaille WHERE couleur = 'Or'
)
GROUP BY a.pays;
-- 2. Transformer la requête précédente en vue nommée MedaillesOr.
CREATE VIEW MedaillesOr AS SELECT a.pays code_pays,
COUNT(DISTINCT r.epreuve) medailles_or
FROM resultat r
INNER JOIN athlete a ON a.code = r.athlete
WHERE r.medaille = (
SELECT place FROM medaille WHERE couleur = 'Or'
)
GROUP BY a.pays;
-- 3. Utiliser la vue créée pour trouver le nombre de médailles dor remportées par la France.
SELECT medailles_or FROM MedaillesOr WHERE code_pays = 'FRA';
/*CREATE OR REPLACE FUNCTION create_view_medailles(couleur_medaille medaille.couleur%TYPE) RETURNS void AS $$
BEGIN
-- TODO nom de la vue
CREATE VIEW MedaillesArgent AS SELECT a.pays code_pays,
COUNT(DISTINCT (r.epreuve, r.medaille)) medailles_or
FROM resultat r
INNER JOIN athlete a ON a.code = r.athlete
WHERE r.medaille = (
SELECT place FROM medaille WHERE couleur = couleur_medaille
)
GROUP BY a.pays;
END;
$$ LANGUAGE plpgsql;*/
CREATE VIEW MedaillesArgent AS SELECT a.pays code_pays,
COUNT(DISTINCT r.epreuve) medailles_argent
FROM resultat r
INNER JOIN athlete a ON a.code = r.athlete
WHERE r.medaille = (
SELECT place FROM medaille WHERE couleur = 'Argent'
)
GROUP BY a.pays;
CREATE VIEW MedaillesBronze AS SELECT a.pays code_pays,
COUNT(DISTINCT r.epreuve) medailles_bronze
FROM resultat r
INNER JOIN athlete a ON a.code = r.athlete
WHERE r.medaille = (
SELECT place FROM medaille WHERE couleur = 'Bronze'
)
GROUP BY a.pays;
-- 5. Créer une vue TableauMedailles listant le nombre de médailles dor, dargent, de bronze et le total.
CREATE VIEW TableauMedailles AS
SELECT p.nom pays,
COALESCE(o.medailles_or, 0) medailles_or, COALESCE(a.medailles_argent, 0) medailles_argent, COALESCE(b.medailles_bronze, 0) medailles_bronze,
(o.medailles_or + a.medailles_argent + b.medailles_bronze) total_medailles
FROM pays p
LEFT JOIN MedaillesOr o ON o.code_pays = p.code
LEFT JOIN MedaillesArgent a ON a.code_pays = p.code
LEFT JOIN MedaillesBronze b ON b.code_pays = p.code
WHERE medailles_or IS NOT NULL
OR medailles_argent IS NOT NULL
OR medailles_bronze IS NOT NULL -- Retire les pays qui ont 0 médaille peu importe la couleur
ORDER BY 2 DESC, 3 DESC, 4 DESC;
-- 6. Afficher le tableau des médailles.
SELECT * FROM tableaumedailles;
-- 7. Un organe de presse souhaite faire son propre classement, en ordonnant les pays en fonction ...
SELECT * FROM tableaumedailles ORDER BY total_medailles DESC, pays;
-- 1. Écrire une requête SQL calculant le nombre dathlètes pratiquants par discipline et par pays
SELECT p.discipl code_discipline, a.pays code_pays, COUNT(*) athletes FROM pratiquer p
INNER JOIN athlete a ON a.code = p.athlete
GROUP BY p.discipl, a.pays;
-- 2. Transformer la requête précédente en vue Pratiquants_v1
CREATE VIEW Pratiquants_v1 AS
SELECT p.discipl code_discipline, a.pays code_pays, COUNT(*) athletes FROM pratiquer p
INNER JOIN athlete a ON a.code = p.athlete
GROUP BY p.discipl, a.pays;
-- 3. Même chose pour Pratiquants_v2 mais ce sera une vue matérialisée.
CREATE MATERIALIZED VIEW Pratiquants_v2 AS
SELECT p.discipl code_discipline, a.pays code_pays, COUNT(*) athletes FROM pratiquer p
INNER JOIN athlete a ON a.code = p.athlete
GROUP BY p.discipl, a.pays;
-- 5. Utiliser les vues créées précédemment pour afficher le nombre dathlètes français pratiquant le judo
SELECT athletes francais_judokas FROM Pratiquants_v1
WHERE code_pays = 'FRA' AND code_discipline = 'JUD';
SELECT athletes francais_judokas FROM Pratiquants_v2
WHERE code_pays = 'FRA' AND code_discipline = 'JUD';
/*SELECT * FROM pratiquer p
INNER JOIN athlete a ON a.code = p.athlete
WHERE p.discipl = 'JUD' AND a.pays = 'FRA';*/
-- 6. Teddy RINER ne pratique plus le judo mais le skateboard (code SKB). Faire les modifications nécessaires.
/*DELETE FROM pratiquer WHERE athlete = (
SELECT code FROM athlete WHERE prenom = 'Teddy' AND nom = 'RINER'
) AND discipl = 'JUD';
INSERT INTO pratiquer VALUES (
(
SELECT code FROM athlete WHERE prenom = 'Teddy' AND nom = 'RINER'
),
'SKB'
);*/
UPDATE pratiquer SET discipl = 'SKB' WHERE athlete = (
SELECT code FROM athlete WHERE prenom = 'Teddy' AND nom = 'RINER'
) AND discipl = 'JUD';
-- 7 et 8.
-- Teddy RINNER est toujours référence dans la version 2 comme judoka puisque c'est une vue matérisalisée et qu'il faut la rafraîchir :
REFRESH MATERIALIZED VIEW Pratiquants_v2;

@ -0,0 +1,125 @@
-- 1. Nombre de violons loués par des élèves.
SELECT COUNT(*) FROM louer WHERE instrument = (
SELECT id FROM instrument WHERE designation = 'Violon'
);
-- 2. Numéros, noms et prénoms des élèves louant plus de 2 instruments.
SELECT e.num, e.nom, e.prenom
FROM louer l
INNER JOIN eleve e ON e.num = l.eleve
GROUP BY e.num
HAVING COUNT(*) > 1;
-- 3. Pour chaque instrument (id, designation), plus vieil élève (nom, prénom) suivant un cours de cet instrument.
WITH plusVieuxEleves AS (
SELECT MAX(e.age) age, s.instrument FROM suivre s
INNER JOIN eleve e ON e.num = s.eleve
GROUP BY s.instrument
)
SELECT i.id, i.designation, e.nom, e.prenom FROM suivre s
INNER JOIN instrument i ON i.id = s.instrument
INNER JOIN eleve e ON e.num = s.eleve
INNER JOIN plusVieuxEleves p ON p.age = e.age AND s.instrument = s.instrument;
-- 4. Définir la fonction PL/pgSQL total qui prend en paramètre un numéro délève et retourne le montant total quil doit régler à lécole de musique (pour les cours et la location des instruments) sachant quune inscription à un cours correspond à 30h de cours par an
CREATE OR REPLACE FUNCTION total(eleve_num INT)
RETURNS INT AS $$
DECLARE
totalCours INT;
totalInstruments INT;
BEGIN
SELECT COALESCE(SUM(n.tarifHoraire * 30), 0) INTO STRICT totalCours FROM suivre s
INNER JOIN niveau n ON n.niveau = s.niveau
WHERE s.eleve = eleve_num;
SELECT COALESCE(SUM(i.tarifLocation), 0) INTO STRICT totalInstruments FROM louer l
INNER JOIN instrument i ON i.id = l.instrument
WHERE l.eleve = eleve_num;
RETURN totalCours + totalInstruments;
END;
$$ LANGUAGE plpgsql;
-- 5. Utiliser la fonction total pour afficher le montant dû par chaque élève (num, nom, prénom)
SELECT num, nom, prenom, total(num) FROM eleve;
-- 6. Mettre à jour le tarif de location des instruments loués plus de 10 fois, en augmentant leur tarif de 50€.
-- Un GROUP BY ne s'associe pas vraiment avec un update :/
/*UPDATE instrument i SET tarifLocation = tarifLocation + 50
FROM louer l
WHERE l.instrument = i.id
GROUP BY i.id
HAVING COUNT(*) > 10;*/
UPDATE instrument SET tarifLocation = tarifLocation + 50
WHERE id IN (
SELECT instrument FROM louer
GROUP BY instrument
HAVING COUNT(*) > 10
);
/*DO $$
DECLARE
curs cursor FOR SELECT i.id FROM louer l
INNER JOIN instrument i ON l.instrument = i.id
GROUP BY i.id
HAVING COUNT(*) > 10
FOR UPDATE;
instrument_courant INT;
BEGIN
open curs;
fetch curs into instrument_courant;
while found loop
UPDATE instrument SET tarifLocation = tarifLocation + 50 WHERE CURRENT OF curs;
fetch curs into instrument_courant;
end loop;
close curs;
END;
$$ LANGUAGE plpgsql;*/
DO $$
DECLARE
curs cursor FOR SELECT instrument FROM louer
GROUP BY instrument
HAVING COUNT(*) > 10;
instrument_courant INT;
BEGIN
open curs;
fetch curs into instrument_courant;
while found loop
UPDATE instrument SET tarifLocation = tarifLocation + 50 WHERE instrument = instrument_courant;
fetch curs into instrument_courant;
end loop;
close curs;
END;
$$ LANGUAGE plpgsql;
-- 7. Créer une vue ElevesPiano rassemblant toutes les informations sur les élèves (nom, prénom, âge, adresse et niveau) des élèves qui suivent des cours de piano
CREATE VIEW ElevesPiano AS
SELECT e.nom, e.prenom, e.age, e.rue || e.codePostal || e.ville adresse, s.niveau
FROM suivre s
INNER JOIN eleve e ON e.num = s.eleve
WHERE s.instrument = (SELECT id FROM instrument WHERE designation = 'Piano');
-- 8. Créer un utilisateur rh pouvant créer des rôles.
CREATE USER rh CREATEROLE;
-- 9. Donner à lutilisateur rh lautorisation de consulter, ajouter, supprimer et modifier des lignes de la table Professeur.
GRANT CONNECT ON DATABASE dbclfreville2 TO rh;
GRANT SELECT, INSERT, DELETE, UPDATE ON Professeur TO rh;
-- 10. Ladministrateur de la base de données décide de changer de fonctionnement : au lieu davoir un seul compte rh utilisé par tous les RH de lécole de musique, il veut créer un compte pour chacun dentre eux, mais quils aient tous les droits de rh. (Le rôle rh ne devra plus être utilisable directement.)
--REVOKE LOGIN TO rh; -- Instruction seulement pour une base de données précise
ALTER ROLE rh RESET LOGIN;
CREATE USER ldupond PASSWORD 'azerty';
GRANT rh TO ldupond;
-- *quelques expérimentations sur la performance de ces requêtes*
EXPLAIN ANALYZE SELECT id FROM restaurant WHERE min_price >= ALL (SELECT min_price FROM restaurant); -- 178 / 21
EXPLAIN ANALYZE SELECT id FROM restaurant ORDER BY min_price DESC LIMIT 1; -- 5
EXPLAIN ANALYZE SELECT id FROM restaurant ORDER BY min_price DESC FETCH FIRST 1 ROWS ONLY; -- 5
EXPLAIN ANALYZE SELECT id FROM restaurant WHERE min_price = (SELECT MAX(min_price) FROM restaurant); -- 6
/*for cle, valeur in dictionnaire:
if valeur >= local_max:
local_max = valeur
local_max_cle = cle*/

@ -0,0 +1,268 @@
/*
=> TP 2, Fréville Clément G8
*/
-- 1. Nombre dathlètes par pays.
SELECT p.nom pays, COUNT(*) athletes FROM athlete a
INNER JOIN pays p ON p.code = a.pays
GROUP BY p.code;
/*
pays | athletes
----------------------------------+----------
Ethiopia | 37
Kuwait | 10
Denmark | 108
Nauru | 2
Netherlands | 283
Palau | 3
Samoa (until 1996 Western Samoa) | 8
United Arab Emirates | 5
[...]
*/
-- 2. Nombre dépreuves par discipline.
SELECT d.nom discipline, COUNT(*) nombre_epreuves FROM epreuve e
INNER JOIN discipline d ON d.code = e.discipl
GROUP BY d.code;
/*
discipline | nombre_epreuves
-----------------------+-----------------
Equestrian | 6
Taekwondo | 8
Hockey | 2
Volleyball | 2
Sport Climbing | 2
Skateboarding | 4
Handball | 2
Baseball/Softball | 2
Diving | 8
[...]
*/
-- 3. Date de la dernière épreuve de chaque discipline.
SELECT d.nom, to_char(MAX(e.dateE), 'dd/mm/YYYY') derniere_epreuve FROM epreuve e
INNER JOIN discipline d ON d.code = e.discipl
GROUP BY d.code;
/*
nom | derniere_epreuve
-----------------------+------------------
Equestrian | 07/08/2021
Taekwondo | 27/07/2021
Hockey | 06/08/2021
Volleyball | 08/08/2021
Sport Climbing | 06/08/2021
Skateboarding | 05/08/2021
Handball | 08/08/2021
Baseball/Softball | 07/08/2021
[...]
*/
-- 4. Date de naissance du plus jeune athlète par discipline et par sexe.
SELECT d.nom discipline, a.sexe, MAX(a.dateNaiss) date_naissance_plus_jeune FROM athlete a
INNER JOIN pratiquer p ON p.athlete = a.code
INNER JOIN discipline d ON p.discipl = d.code
WHERE a.dateNaiss IS NOT NULL
GROUP BY d.code, a.sexe;
/*
discipline | sexe | date_naissance_plus_jeune
-----------------------+------+---------------------------
Basketball | M | 2002-03-09
Water Polo | F | 2004-10-29
Water Polo | M | 2003-06-02
Athletics | M | 2004-01-29
Rhythmic Gymnastics | F | 2004-11-29
Equestrian | F | 1998-08-19
Modern Pentathlon | M | 2000-03-01
Triathlon | M | 1999-10-07
Hockey | M | 2002-03-19
Football | M | 2003-07-24
Swimming | M | 2005-07-19
[...]
*/
-- 5. Nombre total de médailles par pays, les pays ayant remporté le plus de médailles en premier.
SELECT p.nom pays, COUNT(*) medailles_remportees FROM resultat r
INNER JOIN athlete a ON a.code = r.athlete
INNER JOIN pays p ON p.code = a.pays
GROUP BY p.code
ORDER BY medailles_remportees DESC;
/*
pays | medailles_remportees
----------------------------+----------------------
United States of America | 295
ROC | 147
People's Republic of China | 140
France | 137
Japan | 131
Great Britain | 130
Australia | 129
Canada | 82
[...]
*/
-- 6. Nombre de médailles dor par pays, les pays ayant remporté le plus de médailles en premier.
SELECT p.nom pays, COUNT(*) medailles_or_remportees FROM resultat r
INNER JOIN athlete a ON a.code = r.athlete
INNER JOIN pays p ON p.code = a.pays
WHERE r.medaille = 1
GROUP BY p.code, r.medaille
ORDER BY medailles_or_remportees DESC;
/*
pays | medailles_or_remportees
----------------------------+-------------------------
United States of America | 112
Japan | 68
France | 65
People's Republic of China | 58
ROC | 40
Great Britain | 39
Australia | 36
Canada | 36
Netherlands | 31
Brazil | 29
[...]
*/
-- 7. Même question, mais uniquement les pays ayant remporté plus de 30 médailles dor
SELECT p.nom, COUNT(*) medailles_or_remportees FROM resultat r
INNER JOIN athlete a ON a.code = r.athlete
INNER JOIN pays p ON p.code = a.pays
WHERE r.medaille = 1
GROUP BY p.nom, r.medaille
HAVING COUNT(*) >= 30
ORDER BY medailles_or_remportees DESC;
/*
nom | medailles_or_remportees
----------------------------+-------------------------
United States of America | 112
Japan | 68
France | 65
People's Republic of China | 58
ROC | 40
Great Britain | 39
Australia | 36
Canada | 36
Netherlands | 31
*/
-- 8. Athlètes (code, nom, prénom, code du pays) pratiquant plusieurs disciplines.
SELECT a.code, a.nom, a.prenom, a.pays
FROM pratiquer p
INNER JOIN athlete a ON a.code = p.athlete
GROUP BY a.code, a.nom, a.prenom, a.pays
HAVING COUNT(*) > 1;
/*
code | nom | prenom | pays
--------+----------------+------------+------
A05315 | KOPECKY | Lotte | BEL
A01327 | BRENNAUER | Lisa | GER
A07786 | PALTRINIERI | Gregorio | ITA
A05148 | KIRPICHNIKOVA | Anastasiia | ROC
A02686 | DYGERT | Chloe | USA
A10627 | VAN ROUWENDAAL | Sharon | NED
A00622 | AUBRY | David | FRA
A05189 | KLEIN | Lisa | GER
A03293 | GANNA | Filippo | ITA
A11041 | WELLBROCK | Florian | GER
A03991 | HAVIK | Yoeri | NED
*/
-- 9. Athlètes (code, nom, prénom, code du pays) ayant remporté quatre médailles.
SELECT a.code, a.nom, a.prenom, a.pays
FROM resultat r
INNER JOIN athlete a ON a.code = r.athlete
GROUP BY a.code
HAVING COUNT(*) = 4;
/*
code | nom | prenom | pays
--------+---------+----------+------
A11582 | ZHANG | Yufei | CHN
A09215 | SCOTT | Duncan | GBR
A10225 | TITMUS | Ariarne | AUS
A06581 | McKEOWN | Kaylee | AUS
A05668 | LEDECKY | Kathleen | USA
*/
-- 10. Nombre dathlètes mineurs au début des Jeux Olympiques (le 23 juillet 2021) par discipline,uniquement pour les disciplines ayant au moins trois athlètes mineurs.
SELECT d.nom discipline, COUNT(*) athletes_mineurs
FROM pratiquer p
INNER JOIN athlete a ON a.code = p.athlete
INNER JOIN discipline d ON d.code = p.discipl
WHERE (('2021-07-23'-dateNaiss) / 365.2422) < 18
GROUP BY d.code
HAVING COUNT(*) > 2;
/*
discipline | athletes_mineurs
---------------------+------------------
Diving | 10
Skateboarding | 18
Artistic Swimming | 3
Athletics | 6
Artistic Gymnastics | 15
Table Tennis | 3
Swimming | 72
Rhythmic Gymnastics | 8
Shooting | 3
Sailing | 5
Archery | 4
*/
-- 11. Pays ayant le plus dathlètes.
SELECT pays, COUNT(*) athletes
FROM athlete a
GROUP BY a.pays
ORDER BY athletes DESC
LIMIT 1;
/*
pays | athletes
------+----------
USA | 633
*/
-- 11. (Variante) Pays ayant le plus dathlètes.
SELECT pays, COUNT(*) athletes
FROM athlete a
GROUP BY a.pays
HAVING COUNT(*) = (
SELECT MAX(c) FROM (
SELECT COUNT(*) c
FROM athlete
GROUP BY pays
) n_athletes
);
/*
pays | athletes
------+----------
USA | 633
*/
-- 12. Athlète (nom, prénom, code pays) ayant remporté le plus de médailles.
SELECT a.nom, a.prenom, a.pays, COUNT(*) medailles_remportees FROM resultat r
INNER JOIN athlete a ON a.code = r.athlete
GROUP BY a.code
ORDER BY medailles_remportees DESC
LIMIT 1;
/*
nom | prenom | pays | medailles_remportees
--------+--------+------+----------------------
McKEON | Emma | AUS | 7
*/
-- 12. (Variante) Athlète (nom, prénom, code pays) ayant remporté le plus de médailles.
SELECT a.nom, a.prenom, a.pays, COUNT(*) medailles_remportees
FROM resultat r
INNER JOIN athlete a ON a.code = r.athlete
GROUP BY a.code
HAVING COUNT(*) = (
SELECT MAX(c) FROM (
SELECT COUNT(*) c
FROM resultat
GROUP BY athlete
) n_resultats
);
/*
nom | prenom | pays | medailles_remportees
--------+--------+------+----------------------
McKEON | Emma | AUS | 7
*/

@ -0,0 +1,254 @@
/*
=> TP 3-4, Fréville Clément G8
*/
-- 1. Discipline proposant plus dépreuves en juillet quen août.
SELECT d.nom discipline FROM epreuve e
INNER JOIN discipline d ON d.code = e.discipl
WHERE EXTRACT(MONTH FROM e.dateE) = 7
GROUP BY d.code
HAVING COUNT(*) >= (
SELECT COUNT(*) FROM epreuve
WHERE discipl = d.code AND EXTRACT(MONTH FROM dateE) = 8
);
/*
discipline
-----------------------
Archery
3x3 Basketball
Cycling BMX Racing
Baseball/Softball
Cycling Road
Canoe Slalom
Diving
Fencing
Trampoline Gymnastics
Judo
Cycling Mountain Bike
Rowing
Rugby Sevens
Shooting
Skateboarding
Surfing
Swimming
Tennis
Taekwondo
Triathlon
Table Tennis
Weightlifting
(22 lignes)
*/
-- 2. Pays dont au moins la moitié des athlètes ont obtenu une médaille.
SELECT p.nom nom_pays,
COUNT(*) athletes,
COUNT(DISTINCT r.athlete) athletes_medailles
FROM athlete
INNER JOIN pays p ON athlete.pays = p.code
LEFT JOIN resultat r on athlete.code = r.athlete
GROUP BY p.code
HAVING COUNT(DISTINCT r.athlete) >= COUNT(*) FILTER (WHERE r.athlete IS NULL);
/*
nom_pays | athletes | athletes_medailles
------------+----------+--------------------
Bermuda | 2 | 1
Fiji | 32 | 26
San Marino | 6 | 3
(3 lignes)
*/
-- 3. Pays ayant remporté plus de médailles dor que de médailles dargent et de bronze cumulées.
SELECT pays,
COUNT(r.medaille) FILTER (WHERE r.medaille = 1) medailles_or,
COUNT(r.medaille) FILTER (WHERE r.medaille != 1) autres_medailles
FROM resultat r
INNER JOIN athlete a on a.code = r.athlete
GROUP BY pays
HAVING COUNT(r.medaille) FILTER (WHERE r.medaille = 1) >=
COUNT(r.medaille) FILTER (WHERE r.medaille != 1);
/*
pays | medailles_or | autres_medailles
------+--------------+------------------
CUB | 8 | 8
KOS | 2 | 0
EST | 4 | 1
BEL | 20 | 6
SLO | 3 | 2
TUN | 1 | 1
BER | 1 | 0
LAT | 4 | 1
THA | 1 | 1
FIJ | 13 | 13
BUL | 7 | 3
PUR | 1 | 0
MAR | 1 | 0
UGA | 2 | 2
BRA | 29 | 26
ECU | 2 | 1
BAH | 2 | 0
JPN | 68 | 63
QAT | 2 | 2
UZB | 3 | 2
(20 lignes)
*/
-- 4. Nom et prénom des athlètes féminines plus grandes que tous leurs compatriotes masculins.
SELECT nom, prenom FROM athlete a
WHERE sexe = 'F'
AND taille IS NOT NULL
AND taille >= ALL (
SELECT taille FROM athlete
WHERE pays = a.pays AND sexe = 'M' AND taille IS NOT NULL
);
/*
nom | prenom
-----------------------+----------------------
ABDUL HADI | Farah Ann
AL-KAABI | Fatimah Abbas Waheeb
ALVARADO | Luciana
ALVES LOPES | Marcia
AYIVON | Claire
BABOVIC | Anastasija
BALADIN | Hande
BANDA | Babra
BAYASGALAN | Solongo
BELEMU | Margaret
BENITEZ | Jackie
BOZ | Meryem
BRNOVIC | Tatjana
BYLON | Atheyna
[...]
(86 lignes)
*/
-- 5. Lister chaque athlète masculin français (nom, prénom, taille) et comparer leur taille avec celle du plus grand dentre eux.
SELECT nom, prenom, taille, taille - (
SELECT MAX(taille) FROM athlete
WHERE sexe = 'M' AND pays = 'FRA'
) diff FROM athlete
WHERE sexe = 'M' AND pays = 'FRA';
/*
nom | prenom | taille | diff
------------------+-----------------+--------+-------
ABALO | Luc | 1.83 | -0.35
AIT SAID | Samir | 1.68 | -0.50
ALBICY | Andrew | 1.78 | -0.40
ALIEV | Mourad | |
AMDOUNI | Morhad | |
AMOROS | Emile | 1.78 | -0.40
ANDRE | Sylvain | |
ANDRODIAS | Matthieu | 1.94 | -0.24
[...]
(220 lignes)
*/
-- 6. Pour chaque épreuve, indiquer sa date et les dates des premières et dernières épreuves de la discipline.
SELECT *,
(SELECT MIN(dateE) FROM epreuve WHERE discipl = e.discipl) datemin,
(SELECT MAX(dateE) FROM epreuve WHERE discipl = e.discipl) datemax
FROM epreuve e;
/*
code | discipl | nom | datee | datemin | datemax
------+---------+----------------------------------------------+------------+------------+------------
E001 | ARC | Mixed Team | 2021-07-24 | 2021-07-24 | 2021-07-31
E002 | CRD | Men's Road Race | 2021-07-24 | 2021-07-24 | 2021-07-28
E003 | FEN | Men's Sabre Individual | 2021-07-24 | 2021-07-24 | 2021-08-01
E004 | FEN | Women's Epée Individual | 2021-07-24 | 2021-07-24 | 2021-08-01
E005 | JUD | Men -60 kg | 2021-07-24 | 2021-07-24 | 2021-07-31
E006 | JUD | Women -48 kg | 2021-07-24 | 2021-07-24 | 2021-07-31
E007 | SHO | 10m Air Pistol Men | 2021-07-24 | 2021-07-24 | 2021-08-02
[...]
(355 lignes)
*/
-- 7. Un typhon est annoncé. Les épreuves de la dernière journée doivent être reportée dune semaine. Quelle commande permet de faire cette modification sans connaître la date de la dernière journée ?
UPDATE epreuve
SET dateE = dateE + 7
WHERE dateE = (
SELECT MAX(dateE) FROM epreuve
);
/*
UPDATE 13
*/
-- 8. Suspicion de dopage dans les épreuves dhaltérophilie (Weightlifting). Supprimer tous les résultats aux épreuves dhaltérophilie pour le pays ayant remporté le plus de médailles dans cette discipline.
DELETE FROM resultat r
USING epreuve e
WHERE e.code = r.epreuve AND e.discipl = (
SELECT code FROM discipline WHERE nom = 'Weightlifting'
) AND r.athlete IN (
SELECT code FROM athlete WHERE pays IN (
SELECT a.pays FROM resultat r
INNER JOIN epreuve e ON e.code = r.epreuve
INNER JOIN athlete a ON a.code = r.athlete
WHERE e.discipl = (
SELECT code FROM discipline WHERE nom = 'Weightlifting'
)
GROUP BY a.pays
ORDER BY COUNT(*) DESC
LIMIT 1
)
);
/*
DELETE 8
*/
-- 9. Ajouter une nouvelle épreuve :Womens team pour le golf ayant lieu le 09/08/2021 (code de lépreuve :E356).
INSERT INTO epreuve VALUES(
'E356',
(SELECT code FROM discipline WHERE nom = 'Golf'),
'Women''s team',
'2021-08-09'
);
/*
INSERT 0 1
*/
-- 10. Écrire une requête permettant de donner une médaille dor lors de lépreuve crée à la question précédente à toutes les golfeuses des Etats-unis.
INSERT INTO resultat
SELECT 'E356', a.code, (SELECT place FROM medaille WHERE couleur = 'Or')
FROM athlete a
INNER JOIN pratiquer p ON p.athlete = a.code
WHERE a.pays = (SELECT code FROM pays WHERE nom = 'United States of America')
AND p.discipl = (SELECT code FROM discipline WHERE nom = 'Golf')
AND a.sexe = 'F';
/*
INSERT 0 4
*/
-- 11. Même question mais pour donner une médaille dargent à toutes les golfeuses sud-coréennes.
INSERT INTO resultat
SELECT 'E356', a.code, (SELECT place FROM medaille WHERE couleur = 'Argent')
FROM athlete a
INNER JOIN pratiquer p ON p.athlete = a.code
WHERE a.pays = (SELECT code FROM pays WHERE nom = 'Republic of Korea')
AND p.discipl = (SELECT code FROM discipline WHERE nom = 'Golf')
AND a.sexe = 'F';
/*
INSERT 0 4
*/
-- 12. Vérifier que vos deux requêtes précédentes ont bien fonctionnées en affichant les résultats de lépreuve 'E356' (y compris nom, prénom et pays des médaillées).
SELECT p.nom pays, a.sexe, a.nom, a.prenom, m.couleur FROM resultat r
INNER JOIN medaille m ON m.place = r.medaille
INNER JOIN athlete a ON a.code = r.athlete
INNER JOIN pays p ON p.code = a.pays
WHERE r.epreuve = 'E356'
ORDER BY r.medaille;
/*
pays | sexe | nom | prenom | couleur
--------------------------+------+----------+-----------+---------
United States of America | F | THOMPSON | Lexi | Or
United States of America | F | KORDA | Jessica | Or
United States of America | F | KORDA | Nelly | Or
United States of America | F | KANG | Danielle | Or
Republic of Korea | F | PARK | Inbee | Argent
Republic of Korea | F | KIM | Hyojoo | Argent
Republic of Korea | F | KIM | Sei Young | Argent
Republic of Korea | F | KO | Jin Young | Argent
(8 lignes)
*/
-- 13. Réinitialiser votre base de données avec le script jo.sql pour annuler les modifications faites sur ces deux dernières questions.
\i jo.sql

@ -0,0 +1,33 @@
-- Recalcule les lignes avec des ventes totales incohérentes
UPDATE plain_jeu
SET ventes_total = ROUND((ventes_na + ventes_ue + ventes_jp + ventes_autre)::numeric, 2)
WHERE ABS(ventes_na + ventes_ue + ventes_jp + ventes_autre - ventes_total) > 0.1
SELECT annee_sortie, AVG(ventes_total) ventes_moyennes, SUM(ventes_total) ventes_totales FROM plain_jeu
WHERE genre = 'Adventure' AND annee_sortie IS NOT NULL
GROUP BY annee_sortie;
SELECT SUM(ventes_ue) FROM ventes
GROUP BY plateforme;
SELECT * FROM plain_jeu
WHERE nom = 'Mario Kart 64';
SELECT genre, SUM(ventes_total) total_ventes FROM plain_jeu
GROUP BY genre;
SELECT genre, ROUND((SUM(ventes_total) / (SELECT SUM(ventes_total) FROM plain_jeu)) * 100, 2) pourcentage_ventes FROM plain_jeu
GROUP BY genre;
SELECT CASE WHEN annee_sortie < 1990 THEN '< 1990'
WHEN annee_sortie BETWEEN 1990 AND 1999 THEN '1990-1999'
WHEN annee_sortie BETWEEN 2000 AND 2009 THEN '2000-2009'
WHEN annee_sortie >= 2010 THEN '>= 2010'
END annee,
genre,
SUM(ventes_total) ventes_totales
FROM plain_jeu
WHERE annee_sortie IS NOT NULL
GROUP BY genre, annee
ORDER BY annee;

@ -0,0 +1,113 @@
-- 1
SELECT * FROM aeroport WHERE pays = 'France' ORDER BY ville;
-- 2
SELECT v.* FROM vol v
INNER JOIN avion a ON a.immat = v.avion
WHERE v.compagnie != a.compagnie;
-- 3
SELECT DISTINCT a.nom, a.ville, a.pays
FROM vol v
INNER JOIN aeroport a ON v.aeroportArr = a.code
WHERE v.aeroportDep = (
SELECT code FROM aeroport WHERE ville = 'Clermont-Ferrand'
);
-- 4
SELECT MAX(m.nbPassagers) FROM avion a
INNER JOIN modele m ON m.code = a.modele
WHERE a.compagnie = (
SELECT numero FROM compagnie WHERE nom = 'Air France'
);
-- 5
SELECT m.nom, m.marque, a.matricule, MAX(a.dateMiseService)
FROM avion a
INNER JOIN modele m ON m.code = a.modele
GROUP BY a.modele;
-- 6
SELECT a.* FROM vol v
INNER JOIN avion a ON a.immat = v.avion
WHERE v.aeroportDep = 'CDG'
AND v.aeroportDep = 'JFK'
ORDER BY a.dateMiseService
LIMIT 1;
-- 7 (ou jointure)
SELECT a.*, (
SELECT COUNT(*) FROM vol WHERE aeroportDep = a.code OR aeroportArr = a.code
) nbVols
FROM aeroport a
ORDER BY a.nbVols DESC;
-- 8
SELECT a.*, COUNT(*)
FROM vol v
INNER JOIN avion a ON a.immat = v.numero
GROUP BY a.immat
HAVING COUNT(*) >= 20;
-- 9
SELECT a.compagnie
FROM avion a
INNER JOIN modele m ON m.code = a.modele
GROUP BY a.compagnie
HAVING COUNT(DISTINCT m.marque) = (
SELECT COUNT(DISTINCT m.marque) FROM modele
);
-- 10
SELECT compagnie
FROM avion
GROUP BY compagnie
HAVING COUNT(*) >= ALL (
SELECT COUNT(*) c
FROM avion
ORDER BY c DESC
);
-- 11
SELECT a.nom
FROM vol v
INNER JOIN aeroport a ON a.code = v.aeroportDep
WHERE a.pays = 'France'
GROUP BY a.code
HAVING COUNT(*) FILTER (WHERE v.compagnie = (
SELECT numero FROM compagnie WHERE nom = 'Air France'
)) >= (COUNT(*) * 3) / 4
);
-- 12
SELECT m.nom, ROUND((COUNT(*) * 100) / (
SELECT COUNT(*) FROM avion
WHERE compagnie = (SELECT numero FROM compagnie = 'Air France')
), 2) pourcentage
FROM avion a
INNER JOIN modele m ON m.code = a.modele
GROUP BY a.modele;
-- 13
DELETE vol v
USING avion a
WHERE v.avion = a.immat AND v.aeroportDep > (a.dateMiseService + 10000);
SELECT *
FROM vol v
INNER JOIN aeroport depart ON depart.code = v.aeroportDep
INNER JOIN aeroport arrive ON arrive.code = v.aeroportArr
INNER JOIN avion a ON a.immat = v.avion
INNER JOIN modele m ON m.code = a.modele
WHERE depart.pays IN ('France', 'USA') AND arrive.pays IN ('France', 'USA')
AND ((depart.pays = 'France' AND depart.ville LIKE 'C%')
OR (depart.pays = 'USA' AND arrive.ville LIKE 'L%'))
AND ((arrive.pays = 'France' AND arrive.ville LIKE 'C%')
OR (arrive.pays = 'USA' AND arrive.ville LIKE 'L%'))
AND m.nbPassagers % 3 = 0
AND a.compagnie != v.compagnie
AND (
SELECT COUNT(*) FROM vol
INNER JOIN co
)

@ -0,0 +1,315 @@
-- 2
DO $$
DECLARE
a INT := 0;
b INT := 1;
c INT := 1;
n INT := 7;
BEGIN
for i in 2..n loop
c = a + b;
a = b;
b = c;
end loop;
raise notice '%', c;
END;
$$ LANGUAGE plpgsql;
-- 3
CREATE OR REPLACE FUNCTION fibonacci(n INT)
RETURNS INT AS $$
DECLARE
a INT := 0;
b INT := 1;
c INT := 1;
BEGIN
if n = 0 then
return 0;
end if;
for i in 2..n loop
c = a + b;
a = b;
b = c;
end loop;
return c;
END;
$$ LANGUAGE plpgsql;
-- 4
SELECT fibonacci(0); -- 0
SELECT fibonacci(1); -- 1
SELECT fibonacci(2); -- 1
SELECT fibonacci(10); -- 55
-- 5
--DROP FUNCTION IF EXISTS nb_athletes;
CREATE OR REPLACE FUNCTION nb_athletes(code_pays pays.code%TYPE)
RETURNS INT AS $$
BEGIN
return (
SELECT COUNT(*)
FROM athlete
WHERE pays = code_pays
);
END;
$$ LANGUAGE plpgsql;
-- 6
SELECT nb_athletes('FRA');
-- 7
SELECT p.code, p.nom
FROM athlete a
INNER JOIN pays p ON p.code = a.pays
GROUP BY p.code
HAVING COUNT(*) > nb_athletes('FRA');
-- 8
CREATE OR REPLACE FUNCTION epr(nom_discipline discipline.nom%TYPE, date DATE)
RETURNS TABLE (code epreuve.code%TYPE, nom epreuve.nom%TYPE) AS $$
BEGIN
return query
SELECT e.code, e.nom
FROM epreuve e
WHERE e.discipl = (
SELECT d.code FROM discipline d WHERE d.nom = nom_discipline
) AND dateE = date;
END;
$$ LANGUAGE plpgsql;
-- 9
SELECT epr('Athletics', '2021-08-03');
-- 10
UPDATE epreuve SET dateE = dateE+1 WHERE code IN (SELECT code FROM epr('Equestrian', '2021-08-02'));
-- 11
CREATE OR REPLACE FUNCTION pratique(code_athlete athlete.code%TYPE)
RETURNS discipline.nom%TYPE AS $$
DECLARE
res discipline.nom%TYPE;
BEGIN
SELECT d.nom INTO STRICT res FROM pratiquer p
INNER JOIN discipline d ON d.code = p.discipl
WHERE p.athlete = code_athlete;
return res;
EXCEPTION
WHEN TOO_MANY_ROWS THEN
RAISE EXCEPTION 'L''athlète % pratique plusieurs sports.', code_athlete;
WHEN NO_DATA_FOUND THEN
RAISE EXCEPTION 'Athlète % inconnu.', code_athlete;
END;
$$ LANGUAGE plpgsql;
-- 12
SELECT pratique(
(
SELECT code FROM athlete WHERE prenom = 'Earvin' AND nom = upper('Ngapeth')
)
);
-- 13
SELECT pratique(
(
SELECT code FROM athlete WHERE prenom = 'Lotte' AND nom = upper('Kopecky')
)
);
-- 14
SELECT pratique('B01');
-- 15
CREATE OR REPLACE FUNCTION medailles(code_pays pays.code%TYPE)
RETURNS FLOAT AS $$
DECLARE
total_athletes INT;
athletes_medailles INT;
BEGIN
SELECT COUNT(*) INTO total_athletes
FROM athlete
WHERE pays = code_pays;
IF total_athletes = 0 THEN
RAISE EXCEPTION 'Le pays [%] % n''a pas d''athlète.', code_pays, (SELECT nom FROM pays WHERE code = code_pays);
END IF;
SELECT COUNT(DISTINCT r.athlete) INTO athletes_medailles
FROM resultat r
INNER JOIN athlete a ON a.code = r.athlete
WHERE a.pays = code_pays;
return athletes_medailles::FLOAT / total_athletes;
END;
$$ LANGUAGE plpgsql;
-- 16
SELECT medailles(
(
SELECT code FROM pays WHERE nom = 'France'
)
);
-- 17
SELECT medailles(
(
SELECT code FROM pays WHERE nom = 'URSS'
)
);
-- 18
SELECT p.nom, ROUND((medailles(p.code) * 100)::numeric, 2) medailles
FROM resultat r
INNER JOIN athlete a ON a.code = r.athlete
INNER JOIN pays p ON p.code = a.pays
GROUP BY p.code
ORDER BY 2 DESC;
-- 19
--DROP FUNCTION IF EXISTS ageMoy_V1;
CREATE OR REPLACE FUNCTION ageMoy_V1(code_pays pays.code%TYPE)
RETURNS FLOAT AS $$
BEGIN
return (
SELECT AVG(CURRENT_DATE - dateNaiss) / 365.2422
FROM athlete
WHERE pays = code_pays
);
END;
$$ LANGUAGE plpgsql;
-- 20
/*CREATE OR REPLACE FUNCTION ageMoy_V2(code_pays pays.code%TYPE)
RETURNS FLOAT AS $$
DECLARE
total INT := 0;
nb INT := 0;
r athlete%rowtype;
BEGIN
for r in
SELECT * FROM athlete WHERE pays = code_pays AND dateNaiss IS NOT NULL
loop
total = (CURRENT_DATE - r.dateNaiss) + total;
nb = nb + 1;
end loop;
return total::FLOAT / nb / 365.2422;
END;
$$ LANGUAGE plpgsql;*/
DROP FUNCTION IF EXISTS ageMoy_V2;
CREATE OR REPLACE FUNCTION ageMoy_V2(code_pays pays.code%TYPE)
RETURNS FLOAT AS $$
DECLARE
i INT;
fin INT;
total INT := 0;
nb INT := 0;
date_naiss athlete.dateNaiss%TYPE;
BEGIN
-- Oui.
SELECT SUBSTR(MIN(code), 2)::int INTO i FROM athlete WHERE pays = code_pays;
SELECT SUBSTR(MAX(code), 2)::int INTO fin FROM athlete WHERE pays = code_pays;
if i IS NULL then
return 0;
end if;
-- Teste pour chaque code possible
while i <= fin loop
SELECT dateNaiss INTO date_naiss FROM athlete WHERE code = to_char(i, 'FMA00000');
if date_naiss IS NOT NULL then
total = (CURRENT_DATE - date_naiss) + total;
nb = nb + 1;
end if;
i = i + 1;
end loop;
if nb = 0 then
return 0;
end if;
return total::FLOAT / nb / 365.2422;
END;
$$ LANGUAGE plpgsql;
-- 21
--SELECT ageMoy_V1('FRA') v1, ageMoy_V2('FRA') v2;
--SELECT ageMoy_V1('USA') v1, ageMoy_V2('USA') v2;
-- 22
CREATE OR REPLACE FUNCTION ageMoy_V1(code_pays pays.code%TYPE)
RETURNS FLOAT AS $$
BEGIN
return (
SELECT COALESCE(AVG(CURRENT_DATE - dateNaiss), 0) / 365.2422
FROM athlete
WHERE pays = code_pays AND dateNaiss IS NOT NULL
);
END;
$$ LANGUAGE plpgsql;
SELECT ageMoy_V1('') v1, ageMoy_V2('') v2;
-- 23
WITH age_moyen AS (
SELECT nom, ageMoy_V1(code) AS age_moyen FROM pays
) SELECT nom, age_moyen
FROM age_moyen
ORDER BY age_moyen DESC
LIMIT 1;
-- Ou
WITH age_moyen AS (
SELECT nom, ageMoy_V1(code) AS age_moyen FROM pays
) SELECT nom, age_moyen
FROM age_moyen
WHERE age_moyen = (SELECT MAX(age_moyen) FROM age_moyen);
-- 24
WITH age_moyen AS (
SELECT nom, ageMoy_V1(code) AS age_moyen FROM pays
) SELECT nom, age_moyen
FROM age_moyen
WHERE age_moyen != 0
ORDER BY age_moyen
LIMIT 1;
-- 25
CREATE OR REPLACE FUNCTION gagner(code_athlete athlete.code%TYPE, couleur_medaille medaille.couleur%TYPE)
RETURNS INT AS $$
BEGIN
return (
SELECT COUNT(*) FROM resultat WHERE athlete = code_athlete AND medaille = (
SELECT place FROM medaille WHERE couleur = couleur_medaille
)
);
END;
$$ LANGUAGE plpgsql;
-- 26
SELECT gagner(
(SELECT code FROM athlete WHERE prenom = 'Teddy' AND nom = 'RINER'),
'Or'
) medailles_or, gagner(
(SELECT code FROM athlete WHERE prenom = 'Teddy' AND nom = 'RINER'),
'Argent'
) medailles_argent, gagner(
(SELECT code FROM athlete WHERE prenom = 'Teddy' AND nom = 'RINER'),
'Bronze'
) medailles_bronze;
-- 27
CREATE TABLE IF NOT EXISTS resultat_fr (
code CHAR(6) PRIMARY KEY REFERENCES athlete(code),
nom VARCHAR(40) NOT NULL,
prenom VARCHAR(40) NOT NULL,
dateNaiss DATE,
nb_or INT DEFAULT 0,
nb_argent INT DEFAULT 0,
nb_bronze INT DEFAULT 0
);
-- 28
INSERT INTO resultat_fr
SELECT code, nom, prenom, dateNaiss, gagner(code, 'Or'), gagner(code, 'Argent'), gagner(code, 'Bronze')
FROM athlete
WHERE pays = (SELECT code FROM pays WHERE nom = 'France');
-- 29
SELECT * FROM resultat_fr ORDER BY (nb_or + nb_argent + nb_bronze) DESC, dateNaiss;

File diff suppressed because it is too large Load Diff

@ -40,8 +40,11 @@ $$ LANGUAGE plpgsql;
-- 4. Appel de la fonction avec comme parametre 0, 1, 2, 10
SELECT fibonacci(0);
SELECT * FROM fibonacci(1);
SELECT * FROM fibonacci(2);
SELECT * FROM fibonacci(10);
-- fibonacci
@ -95,7 +98,9 @@ SELECT nb_athletes('FRA');
-- 7. Ecrire une requete sql utilisant la fonction nb_athletes pour afficher le code et le nom de tous les pays ayant plus d'athlètes que la France
SELECT pays, nom FROM pays WHERE nb_athletes(pays.code) > nb_athletes('FRA');
SELECT pays, nom
FROM pays
WHERE nb_athletes(pays.code) > nb_athletes('FRA');
-- pays | nom
-- ------------------------------------+----------------------------
@ -190,62 +195,364 @@ SELECT epr('Equestrian', '2021-08-02');
-- 11. Ecrire une fonction pratique qui retourne le nom de la discipline pratiqué par un athlète dont on passe le code en paramètre
CREATE OR REPLACE FUNCTION pratique(code_athlete athlete.code%TYPE) RETURNS SETOF discipline AS $$
CREATE OR REPLACE FUNCTION pratique(code_athlete athlete.code%TYPE) RETURNS discipline.nom%TYPE AS $$
DECLARE
discipline discipline;
res discipline.nom%TYPE;
BEGIN
FOR discipline IN SELECT * FROM discipline d WHERE d.code IN (SELECT p.discipl FROM pratiquer p WHERE p.athlete = (SELECT a.code FROM athlete a WHERE a.nom = nom AND a.prenom = prenom)) LOOP
RETURN NEXT discipline;
END LOOP;
SELECT d.nom INTO STRICT res FROM pratiquer p
INNER JOIN discipline d ON d.code = p.discipl
WHERE p.athlete = code_athlete;
return res;
EXCEPTION
WHEN UNIQUE_VIOLATION THEN
RAISE NOTICE 'L ''athlète % pratique plusieurs disciplines', code_athlete;
WHEN TOO_MANY_ROWS THEN
RAISE EXCEPTION 'L''athlète % pratique plusieurs sports.', code_athlete;
WHEN NO_DATA_FOUND THEN
RAISE NOTICE 'Athlète % inconnu', code_athlete;
RAISE EXCEPTION 'Athlète % inconnu.', code_athlete;
END;
$$ LANGUAGE plpgsql;
-- CREATE OR REPLACE FUNCTION pratique(code_athlete varchar) RETURNS SETOF discipline AS $$
-- SELECT *
-- FROM discipline d
-- WHERE d.code IN (SELECT discipl FROM pratiquer WHERE athlete = code_athlete);
-- EXEPTION
-- WHEN UNIQUE_VIOLATION THEN
-- RAISE NOTICE 'L ''athlète % pratique plusieurs disciplines', code_athlete;
-- WHEN NO_DATA_FOUND THEN
-- RAISE NOTICE 'Athlète % inconnu', code_athlete;
-- $$ LANGUAGE SQL;
-- 12. Utiliser la fonction pratique pour trouver le sport pratiqué par Earvin NGAPETH
-- ? 12. Utiliser la fonction pratique pour trouver le sport pratiqué par Earvin NGAPETH
SELECT pratique(
(
SELECT code FROM athlete WHERE prenom = 'Earvin' AND nom = upper('Ngapeth')
)
);
-- pratique
-- ------------
-- Volleyball
-- (1 ligne)
-- ? 13. Meme question pour l'athlete Lotte KOPECKY
SELECT pratique(
(
SELECT code FROM athlete WHERE prenom = 'Lotte' AND nom = upper('Kopecky')
)
);
-- ERREUR: L'athlète A05315 pratique plusieurs sports.
-- CONTEXTE : fonction PL/pgSQL pratique(character), ligne 11 à RAISE
-- ? 14. Meme question pour l'thlete de code 'B01' (qui n'existe pas)
SELECT pratique('B01');
-- ASTUCE : N'a pas pu choisir un meilleur candidat dans les fonctions. Vous pourriez
-- avoir besoin d'ajouter des conversions explicites de type.
-- ? 15 Ecrire une fonction medailles calculant le pourcentage d'athlèthes médaillés parmis ceux du pays passé en paramètre
CREATE OR REPLACE FUNCTION medailles(code_pays pays.code%TYPE)
RETURNS FLOAT AS $$
DECLARE
total_athletes INT;
athletes_medailles INT;
BEGIN
SELECT COUNT(*) INTO total_athletes
FROM athlete
WHERE pays = code_pays;
SELECT code
FROM athlete
WHERE nom = 'NGAPETH' AND prenom = 'Earvin';
IF total_athletes = 0 THEN
RAISE EXCEPTION 'Le pays [%] % n''a pas d''athlète.', code_pays, (SELECT nom FROM pays WHERE code = code_pays);
END IF;
SELECT * FROM pratique('A07318');
SELECT COUNT(DISTINCT r.athlete) INTO athletes_medailles
FROM resultat r
INNER JOIN athlete a ON a.code = r.athlete
WHERE a.pays = code_pays;
return athletes_medailles::FLOAT / total_athletes;
END;
$$ LANGUAGE plpgsql;
-- ? 16. Tester votre fonction medailles avec la France
-- code | nom
-- ------+------------
-- VVO | Volleyball
SELECT medailles(
(
SELECT code FROM pays WHERE nom = 'France'
)
);
-- medailles
-- --------------------
-- 0.3282828282828283
-- (1 ligne)
-- 13. Meme question pour l'athlete Lotte KOPECKY
-- ? 17. Même question avec l'URSS
SELECT medailles(
(
SELECT code FROM pays WHERE nom = 'URSS'
)
);
-- ERREUR: Le pays [URS] URSS n'a pas d'athlète.
-- CONTEXTE : fonction PL/pgSQL medailles(character), ligne 11 à RAISE
-- ? 18. Utiliser la fonction medailles pour afficher tous les pays (nom et pourcentage de médaillés). avec les pays les plus détaillés (proportionellement parlant) en premier. Le pourcentage de médaillés devra avoir au plus 2décimales.
SELECT p.nom, ROUND((medailles(p.code) * 100)::numeric, 2) medailles
FROM resultat r
INNER JOIN athlete a ON a.code = r.athlete
INNER JOIN pays p ON p.code = a.pays
GROUP BY p.code
ORDER BY 2 DESC;
-- nom | medailles
-- ----------------------------+-----------
-- Fiji | 81.25
-- San Marino | 60.00
-- Bermuda | 50.00
-- Dominican Republic | 46.97
-- United States of America | 40.60
-- Serbia | 40.23
-- ROC | 37.54
-- France | 32.83
-- Botswana | 28.57
-- Great Britain | 28.32
-- People's Republic of China | 27.08
-- Denmark | 26.85
-- New Zealand | 26.75
-- Hungary | 26.74
-- Qatar | 25.00
-- Norway | 24.73
-- Bulgaria | 23.81
-- Armenia | 23.53
-- Chinese Taipei | 23.53
-- Sweden | 23.53
-- Cuba | 23.19
-- Jamaica | 22.95
-- Georgia | 22.86
-- Argentina | 22.75
-- Netherlands | 21.91
-- Indonesia | 21.43
-- Philippines | 21.05
-- Spain | 20.83
-- Australia | 20.25
-- Belgium | 20.00
-- Greece | 19.51
-- India | 19.05
-- Kyrgyzstan | 18.75
-- Japan | 18.57
-- Canada | 18.39
-- Croatia | 18.33
-- Kosovo | 18.18
-- Italy | 17.11
-- Slovakia | 17.07
-- Germany | 17.07
-- Brazil | 16.93
-- Syrian Arab Republic | 16.67
-- Grenada | 16.67
-- Mexico | 16.67
-- Ukraine | 16.34
-- 94 lignes
-- ? 19. Ecrire une fonction ageMoy qui calcule et retourne l'âge moyen des athlètes d'un pays dont le code est passé en paramètres
CREATE OR REPLACE FUNCTION ageMoy_V1(code_pays pays.code%TYPE)
RETURNS FLOAT AS $$
BEGIN
return (
SELECT AVG(CURRENT_DATE - dateNaiss) / 365.2422
FROM athlete
WHERE pays = code_pays
);
END;
$$ LANGUAGE plpgsql;
-- ? 20. Modifier la fonction ageMoy pour qu'elle retourn 0 si aucun athlète ne concourt pour le pays ou si on ne connait l'âge d'aucun de ses athlètes
DROP FUNCTION IF EXISTS ageMoy_V2;
CREATE OR REPLACE FUNCTION ageMoy_V2(code_pays pays.code%TYPE)
RETURNS FLOAT AS $$
DECLARE
i INT;
fin INT;
total INT := 0;
nb INT := 0;
date_naiss athlete.dateNaiss%TYPE;
BEGIN
-- Oui.
SELECT SUBSTR(MIN(code), 2)::int INTO i FROM athlete WHERE pays = code_pays;
SELECT SUBSTR(MAX(code), 2)::int INTO fin FROM athlete WHERE pays = code_pays;
if i IS NULL then
return 0;
end if;
-- Teste pour chaque code possible
while i <= fin loop
SELECT dateNaiss INTO date_naiss FROM athlete WHERE code = to_char(i, 'FMA00000');
if date_naiss IS NOT NULL then
total = (CURRENT_DATE - date_naiss) + total;
nb = nb + 1;
end if;
i = i + 1;
end loop;
if nb = 0 then
return 0;
end if;
return total::FLOAT / nb / 365.2422;
END;
$$ LANGUAGE plpgsql;
SELECT code
FROM athlete
WHERE nom = 'KOPECKY' AND prenom = 'Lotte';
-- ? 21. Utiliser cette fonction pour trouver le pays dont les thlètes sont en moyenne les plus jeunes
SELECT * FROM pratique('A05315');
-- ? 22. Même question pour le pays dont les athlètes sont en moyenne les plus jeunes
-- code | nom
-- ------+---------------
-- CRD | Cycling Road
-- CTR | Cycling Track
-- (2 lignes)
CREATE OR REPLACE FUNCTION ageMoy_V1(code_pays pays.code%TYPE)
RETURNS FLOAT AS $$
BEGIN
return (
SELECT COALESCE(AVG(CURRENT_DATE - dateNaiss), 0) / 365.2422
FROM athlete
WHERE pays = code_pays AND dateNaiss IS NOT NULL
);
END;
$$ LANGUAGE plpgsql;
-- 14. Meme question pour l'thlete de code 'B01' (qui n'existe pas)
SELECT ageMoy_V1('') v1, ageMoy_V2('') v2;
SELECT * FROM pratique('B01');
-- v1 | v2
-- ----+----
-- 0 | 0
-- (1 ligne)
WITH age_moyen AS (
SELECT nom, ageMoy_V1(code) AS age_moyen FROM pays
) SELECT nom, age_moyen
FROM age_moyen
ORDER BY age_moyen DESC
LIMIT 1;
-- nom | age_moyen
-- ----------------------+-------------------
-- United Arab Emirates | 34.15103731167976
-- (1 ligne)
WITH age_moyen AS (
SELECT nom, ageMoy_V1(code) AS age_moyen FROM pays
) SELECT nom, age_moyen
FROM age_moyen
WHERE age_moyen != 0
ORDER BY age_moyen
LIMIT 1;
-- nom | age_moyen
-- -------------------------------+--------------------
-- St Vincent and the Grenadines | 21.159475365478944
-- (1 ligne)
-- ? 23. Creer une fonction gagner qui prend en paramètre un code d'athlète et une couleur de médaille ('Or', 'Argent' ou 'Bronze') et qui retourne le nombre de médailles de cette couleur gagnées par cet athlète
CREATE OR REPLACE FUNCTION gagner(code_athlete athlete.code%TYPE, couleur_medaille medaille.couleur%TYPE)
RETURNS INT AS $$
BEGIN
return (
SELECT COUNT(*) FROM resultat WHERE athlete = code_athlete AND medaille = (
SELECT place FROM medaille WHERE couleur = couleur_medaille
)
);
END;
$$ LANGUAGE plpgsql;
-- ? 24. Tester votre fonction en affichant le nombre de médailles d'or, d'argent et de bronze gagnées par l'athlète Teddy RINER
SELECT gagner(
(SELECT code FROM athlete WHERE prenom = 'Teddy' AND nom = 'RINER'),
'Or'
) medailles_or, gagner(
(SELECT code FROM athlete WHERE prenom = 'Teddy' AND nom = 'RINER'),
'Argent'
) medailles_argent, gagner(
(SELECT code FROM athlete WHERE prenom = 'Teddy' AND nom = 'RINER'),
'Bronze'
) medailles_bronze;
-- medailles_or | medailles_argent | medailles_bronze
-- --------------+------------------+------------------
-- 1 | 0 | 1
-- (1 ligne)
-- ? 25. Creer une table Resultat_FR(code, nom, prenom, dateNaiss, nb_or, nb_argent, nb_bronze) qui servira pour contenir les résultats des athlètes français
CREATE TABLE IF NOT EXISTS resultat_fr (
code CHAR(6) PRIMARY KEY REFERENCES athlete(code),
nom VARCHAR(40) NOT NULL,
prenom VARCHAR(40) NOT NULL,
dateNaiss DATE,
nb_or INT DEFAULT 0,
nb_argent INT DEFAULT 0,
nb_bronze INT DEFAULT 0
);
-- ? 26. Remplir la table Resultat_FR avec une requete INSERT
INSERT INTO resultat_fr
SELECT code, nom, prenom, dateNaiss, gagner(code, 'Or'), gagner(code, 'Argent'), gagner(code, 'Bronze')
FROM athlete
WHERE pays = (SELECT code FROM pays WHERE nom = 'France');
-- INSERT 0 396
-- ? 27. Afficher les resultats des athlètes fraçais en les ordonnant en fonction du nombre total de médailles gagnées (les gagnants du plus grand nombre de médailles en premier), puis par date de naissance (les athlètes les plus agés en premier)
SELECT *
FROM resultat_fr
ORDER BY (nb_or + nb_argent + nb_bronze) DESC, dateNaiss;
-- code | nom | prenom | datenaiss | nb_or | nb_argent | nb_bronze
-- --------+---------------------+--------------------+------------+-------+-----------+-----------
-- A08619 | RINER | Teddy | 1989-04-07 | 1 | 0 | 1
-- A00129 | AGBEGNENOU | Clarisse | 1992-10-25 | 2 | 0 | 0
-- A06252 | MALONGA | Madeleine | 1993-12-25 | 1 | 1 | 0
-- A01407 | BUCHARD | Amandine | 1995-07-12 | 1 | 1 | 0
-- A01390 | BRUNET | Manon | 1996-02-07 | 0 | 1 | 1
-- A02151 | CYSIQUE | Sarah Leonie | 1998-07-06 | 1 | 1 | 0
-- A02474 | DICKO | Romane | 1999-09-30 | 1 | 0 | 1
-- A05542 | LAGHOUAG | Karim Florent | 1975-08-04 | 0 | 0 | 1
-- A10338 | TOUZAINT | Nicolas | 1980-05-10 | 0 | 0 | 1
-- A03395 | GENTY | Yann | 1981-12-26 | 1 | 0 | 0
-- A05650 | le PECHOUX | Erwann | 1982-01-13 | 1 | 0 | 0
-- A03762 | GUIGOU | Michael | 1982-01-28 | 1 | 0 | 0
-- A03801 | GUYART | Astrid | 1983-03-17 | 0 | 1 | 0
-- A04842 | KARABATIC | Nikola | 1984-04-11 | 1 | 0 | 0
-- A00006 | ABALO | Luc | 1984-09-06 | 1 | 0 | 0
-- A08096 | PICON | Charline | 1984-12-23 | 0 | 1 | 0
-- A05666 | LECOINTRE | Camille | 1985-02-25 | 0 | 0 | 1
-- A09538 | SIX | Christopher | 1985-12-12 | 0 | 0 | 1
-- A04242 | HORTA | Fanny | 1986-01-22 | 0 | 1 | 0
-- A05786 | LEYNAUD | Amandine | 1986-05-02 | 1 | 0 | 0
-- A01702 | CHAINE | Guillaume | 1986-10-24 | 1 | 0 | 0
-- A03406 | GERARD | Vincent | 1986-12-16 | 1 | 0 | 0
-- A01964 | CLERGET | Axel | 1987-02-28 | 1 | 0 | 0
-- A05532 | LACRABERE | Alexandra | 1987-04-27 | 1 | 0 | 0
-- A02279 | de COLO | Nando | 1987-06-23 | 0 | 1 | 0
-- A03725 | GRUDA | Sandrine | 1987-06-25 | 0 | 0 | 1
-- A02203 | DANCETTE | Blandine | 1988-02-14 | 1 | 0 | 0
-- A04841 | KARABATIC | Luka | 1988-04-19 | 1 | 0 | 0
-- A06873 | MIYEM | Endene | 1988-05-15 | 0 | 0 | 1
-- A06706 | MERTINE | Julien | 1988-06-25 | 1 | 0 | 0
-- A02719 | EDWIGE | Beatrice | 1988-10-03 | 1 | 0 | 0
-- A00863 | BATUM | Nicolas | 1988-12-14 | 0 | 1 | 0
-- A06746 | MICHEL | Sarah | 1989-01-10 | 0 | 0 | 1
-- A04110 | HEURTEL | Thomas | 1989-04-10 | 0 | 1 | 0
-- A08133 | PINEAU | Allison | 1989-05-02 | 1 | 0 | 0
-- A06053 | LUIS | Vincent | 1989-06-27 | 0 | 0 | 1
-- A02223 | DARLEUX | Cleopatre | 1989-07-01 | 1 | 0 | 0
-- A05645 | le BLOUCH | Kilian | 1989-10-07 | 1 | 0 | 0
-- A10287 | TONIUTTI | Benjamin | 1989-10-30 | 1 | 0 | 0
-- A07942 | PELLE | Chloe | 1989-11-14 | 0 | 1 | 0
-- A00982 | BERDER | Cecilia | 1989-12-13 | 0 | 1 | 0
-- A01912 | CIAK | Helena | 1989-12-15 | 0 | 0 | 1
-- A00223 | ALBICY | Andrew | 1990-03-21 | 0 | 1 | 0
-- A00434 | ANDRODIAS | Matthieu | 1990-06-11 | 1 | 0 | 0
-- A03667 | GREBENNIKOV | Jenia | 1990-08-13 | 1 | 0 | 0
-- 396 lignes

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save