Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider 768cd1a5 rédigé par E214194U's avatar E214194U
Parcourir les fichiers

maj

parent 1b3d1e67
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 372 ajouts et 13 suppressions
# Compte Rendu du Mini-Projet / Exploitation d'une Base de Données
Alexandre Clénet - Benjamin Couet - Nathan Marie - Romain Gouraud / Groupe 2
* Alexandre Clénet : i2b07a
* Benjamin Couet : i2b07b
* Nathan Marie : i2b06b
* Romain Gouraud : i2b05b
## La base de données donné en première forme normale :
RECHARGEELECTRIQUE ( codestation, nombrepointsdecharge, aménageur, enseigne, opérateur, libelléstation, adresse, longitude, latitude, codepointdecharge, puissancemaximum, typedeprise, accèsrecharge, horaires, observations, datedemiseajour, localisation, insee, commune, département, code_dep, code_reg );
## 1. Décomposer cette table en plusieurs tables. Chaque relation doit-être en 3ième forme normale.
<span style="color: #e11d1d">Station</span> ((<span style="color: #e11d1d">**codestation**</span>, nombrepointsdecharge, aménageur, enseigne, opérateur, libelléstation, adresse, longitude, latitude, <span style="color: #26B260">#insee</span>, source, <span style="color: #e69138">#codepointdecharge</span> );
<span style="color: #e69138">Borne</span> (<span style="color: #e69138">**codepointdecharge**</span>, puissancemaximum, typedeprise, accèsrecharge, horaires, observations, datedemiseajour, localisation );
<span style="color: #26B260">Commune</span> (<span style="color: #26B260">**insee**</span>, commune, <span style="color: #4155ff">#département</span> );
<span style="color: #4155ff">Département</span> (<span style="color: #4155ff">**département**</span>, code_dep, code_reg );
## 2. Répartissez les tables sur chaque étudiant. Attention les données doivent être partagées. Chaque étudiant doit travailler sur ces propre données.
### Alexandre : `Station`
```sql
create Table Station as select
codestation,
nombrepointsdecharge,
aménageur,
enseigne,
opérateur,
libelléstation,
adresse,
longitude,
latitude,
insee,
source,
codepointdecharge
from basetd.rechargeelectrique;
--Transformation en nombre
update station
set nombrepointsdecharge=Replace(nombrepointsdecharge, '.', ',');
--Maj des données
DELETE FROM station WHERE insee='85234.0';
DELETE FROM station WHERE insee='44143.0';
DELETE FROM station WHERE insee='85234.0';
insert into i2B05B.commune VALUES('85234.0','Saint-Jean-de-Monts','Vendée');
insert into i2B05B.commune VALUES('44143','Rezé','Loire-Atlantique');
update i2B05B.commune set insee = '44143.0' where insee ='44143' ;
update station set insee = '85234.0' where CODESTATION ='FR*S85*P85234*001' ;
```
### Nathan : `Borne`
```sql
create table borne as select
codepointdecharge,
puissancemaximum,
typedeprise,
accèsrecharge,
horaires,
observations,
datedemiseajour,
localisation
from basetd.rechargeelectrique;
```
### Romain : `Commune`
```sql
create table commune as select distinct
insee,
commune,
département
from BASETD.rechargeelectrique ;
--Repérage de doublons
SELECT insee,COUNT(*) AS insee
FROM commune
GROUP BY insee
HAVING COUNT(*) > 1;
--Suppression
delete from commune where commune = 'Saint-Paul';
delete from commune where département = 'Ille-et-Vilaine';
delete from commune where département = 'Gironde';
--Modification
update commune set insee = '85248.0' where commune ='Saint-Martin-Lars-en-Sainte-Hermine' ;
delete from commune where insee='85248.0';
commit;
```
### Benjamin : `Département`
```sql
create table Departement as select distinct
département,
code_dep,
code_reg
from basetd.rechargeelectrique where département not in
--On enlève les Département hors Pays de la Loire :
(select département from basetd.rechargeelectrique where département in
('Gironde', 'La Réunion' ,'Ille-et-Vilaine') );
```
## 3. Vous devez maintenant créer les contraintes d’intégrité PK et FK des tables en locale.
### Alexandre : `Station`
```sql
ALTER TABLE station ADD CONSTRAINT pk_station PRIMARY KEY ( codestation );
```
### Nathan : `Borne`
```sql
ALTER TABLE borne ADD CONSTRAINT pk_borne PRIMARY KEY ( codepointdecharge );
```
### Romain : `Commune`
```sql
ALTER TABLE commune ADD CONSTRAINT pk_commune PRIMARY KEY ( insee );
```
### Benjamin : `Département`
```sql
ALTER TABLE Departement ADD CONSTRAINT pk_departement PRIMARY KEY (département);
```
## 4. Créez maintenant les contraintes qui sont distants. Donnez les différents droits qui sont utilisés.
### Alexandre : `Station`
```sql
--Droits
grant select on station to i2b06b, i2b07b, i2b05b;
grant update on station to i2b06b, i2b07b, i2b05b;
grant insert on station to i2b06b, i2b07b, i2b05b;
--Clé étrangère
alter table station add constraint fk_insee_station
foreign key(insee) references i2b05b.commune(insee);
--Clé étrangère
alter table station add constraint fk_codepointdecharge_station
foreign key(codepointdecharge) references i2b06b.borne(codepointdecharge);
```
### Nathan : `Borne`
```sql
--Droits
grant select on borne to i2b07b, i2b07a, i2b05b;
grant update on borne to i2b07b, i2b07a, i2b05b;
grant insert on borne to i2b07b, i2b07a, i2b05b;
grant REFERENCES (codepointdecharge) on borne to i2b07a;
```
### Romain : `Commune`
```sql
--Droits
grant select on commune to i2b06b, i2b07a, i2b07b;
grant update on commune to i2b06b, i2b07a, i2b07b;
grant insert on commune to i2b06b, i2b07a, i2b07b;
grant REFERENCES (insee) on commune to i2b07a;
--Clé étrangère
alter table commune add constraint fk_commune foreign key(département) references i2b07b.Departement(département);
```
### Benjamin : `Département`
```sql
--Droits
grant select on departement to i2b06b, i2b07a, i2b05b;
grant update on departement to i2b06b, i2b07a, i2b05b;
grant insert on departement to i2b06b, i2b07a, i2b05b;
grant REFERENCES (département) on departement to i2b05b;
```
## 5. Donnez les requêtes suivantes :
On va se focaliser sur `un seul identifiant` car les requetes sont les memes pour tout le monde. (La seule différence est la table propre à l'id, ici présent `point de vue` de `Station / Alexandre`)
### Affichez pour chaque Aménageur le nombre de prises par commune. Dans ce cas avoir une requête par département. En sortie : Aménageur, commune , nombre de prises.
```sql
--Loire-Atlantique :
select aménageur,commune,sum(nombrepointsdecharge) nbrprise
from I2B05B.commune natural join I2B07B.departement natural join station
where département='Loire-Atlantique'
group by aménageur,commune
order by 1;
--Vendée :
select aménageur,commune,sum(nombrepointsdecharge) nbrprise
from I2B05B.commune natural join I2B07B.departement natural join station
where département='Vendée'
group by aménageur,commune
order by 1;
--Sarthe :
select aménageur,commune,sum(nombrepointsdecharge) nbrprise
from I2B05B.commune natural join I2B07B.departement natural join station
where département='Sarthe'
group by aménageur,commune
order by 1;
--Mayenne :
select aménageur,commune,sum(nombrepointsdecharge) nbrprise
from I2B05B.commune natural join I2B07B.departement natural join station
where département='Mayenne'
group by aménageur,commune
order by 1;
--Maine-et-Loire :
select aménageur,commune,sum(nombrepointsdecharge) nbrprise
from I2B05B.commune natural join I2B07B.departement natural join station
where département='Maine-et-Loire'
group by aménageur,commune
order by 1;
```
### Afficher pour chaque Aménageur le nombre de prises avec la puissance Max
```sql
select aménageur,puissancemaximum,sum(nombrepointsdecharge) nbrprise
from I2B06B.borne natural join station
group by aménageur,puissancemaximum
order by 1;
```
### Affichez pour chaque département la répartition des prises par commune. Dans ce cas avoir une requête par département. En sortie : Commune , nombre de prises.
```sql
--Loire-Atlantique :
select commune,sum(nombrepointsdecharge) nbrprise
from I2B05B.commune natural join I2B07B.departement natural join station
where département='Loire-Atlantique'
group by commune
order by 1;
--Vendée :
select commune,sum(nombrepointsdecharge) nbrprise
from I2B05B.commune natural join I2B07B.departement natural join station
where département='Vendée'
group by commune
order by 1;
--Sarthe :
select commune,sum(nombrepointsdecharge) nbrprise
from I2B05B.commune natural join I2B07B.departement natural join station
where département='Sarthe'
group by commune
order by 1;
--Mayenne :
select commune,sum(nombrepointsdecharge) nbrprise
from I2B05B.commune natural join I2B07B.departement natural join station
where département='Mayenne'
group by commune
order by 1;
--Maine-et-Loire :
select commune,sum(nombrepointsdecharge) nbrprise
from I2B05B.commune natural join I2B07B.departement natural join station
where département='Maine-et-Loire'
group by commune
order by 1;
```
### Proposez 2 autres types de requêtes
```sql
--Nombre de prises total par aménageurs
select aménageur,sum(nombrepointsdecharge) nbrprise
from I2B06B.borne natural join station
group by aménageur
order by 1;
--Aménageurs qui possèdent des bornes gratuites
select distinct aménageur
from I2B06B.borne natural join station
where accèsrecharge in ('Gratuit','gratuit')
order by 1;
```
## 6. Vous générez aussi différents graphiques(en batons et batons empilés).
### `Nombre de prises` pour chaque `aménageur` :
![alt text](nbrparamen.png)
### `Nombre de prises` pour chaque `aménageur` avec chaque puissance :
![alt text](nbravecpuissance.png)
### `Nombre de prises` pour chaque `commune vendéenne` :
![alt text](nbrVEcommune.png)
## 7. Faites une synthèse de ces requêtes en passant par des vues. C’est à dire avoir une vue globale des Pays de la Loire. Quels droits devriez vous lui donner.
```sql
create or replace view nbrpriseAménLA as
select aménageur,commune,sum(nombrepointsdecharge) nbrprise
from I2B05B.commune natural join I2B07B.departement natural join station
where département='Loire-Atlantique'
group by aménageur,commune
order by 1;
create or replace view nbrpriseAménVE as
select aménageur,commune,sum(nombrepointsdecharge) nbrprise
from I2B05B.commune natural join I2B07B.departement natural join station
where département='Vendée'
group by aménageur,commune
order by 1;
create or replace view nbrpriseAménSA as
select aménageur,commune,sum(nombrepointsdecharge) nbrprise
from I2B05B.commune natural join I2B07B.departement natural join station
where département='Sarthe'
group by aménageur,commune
order by 1;
create or replace view nbrpriseAménMA as
select aménageur,commune,sum(nombrepointsdecharge) nbrprise
from I2B05B.commune natural join I2B07B.departement natural join station
where département='Mayenne'
group by aménageur,commune
order by 1;
create or replace view nbrpriseAménML as
select aménageur,commune,sum(nombrepointsdecharge) nbrprise
from I2B05B.commune natural join I2B07B.departement natural join station
where département='Maine-et-Loire'
group by aménageur,commune
order by 1;
create or replace view nbrpriseAménPDL as
select * from nbrpriseAménLA
union all
select * from nbrpriseAménVE
union all
select * from nbrpriseAménSA
union all
select * from nbrpriseAménMA
union all
select * from nbrpriseAménML;
```
## 8. A partir de ces Vues, vous donnez les différents graphiques.
### `Nombre de prises` pour chaque `aménageur` des `Pays de la Loire` :
requête : select aménageur,sum(nbrprise) from nbrpriseAménPDL group by aménageur;
![alt text](nbrborneparamenPDL.png)
### `Nombre de communes` prisent en charge par chaque `aménageur` :
requête : select aménageur,count(*) from nbrpriseAménPDL group by aménageur;
![alt text](nbrcommuneparamen.png)
\ No newline at end of file
Fichier ajouté
BD/mini projet/nbrVEcommune.png

224 ko

BD/mini projet/nbravecpuissance.png

25,6 ko

BD/mini projet/nbrborneparamenPDL.png

75,4 ko

BD/mini projet/nbrcommuneparamen.png

22,6 ko

BD/mini projet/nbrparamen.png

29,3 ko

......@@ -6,7 +6,7 @@ select * from BASETD.rechargeelectrique t1 where t1.d
--INSEE DOUBLE
select t1.commune,t1.insee from BASETD.rechargeelectrique t1,BASETD.rechargeelectrique t2 where t1.insee=t2.insee and t1.commune!=t2.commune;
drop table Station;
drop table station;
create Table Station as select codestation,
nombrepointsdecharge,
amnageur,
......@@ -21,8 +21,30 @@ source,
codepointdecharge
from basetd.rechargeelectrique;
update station
set nombrepointsdecharge=Replace(nombrepointsdecharge, '.', ',');
grant select on Station to i2b05b ,i2b06b ,i2b07b;
DELETE FROM station WHERE insee='85234.0';
DELETE FROM station WHERE insee='44143.0';
DELETE FROM station WHERE insee='85234.0';
insert into i2B05B.commune VALUES('85234.0','Saint-Jean-de-Monts','Vende');
insert into i2B05B.commune VALUES('44143','Rez','Loire-Atlantique');
update i2B05B.commune set insee = '44143.0' where insee ='44143' ;
update station set insee = '85234.0' where CODESTATION ='FR*S85*P85234*001' ;
ALTER TABLE station ADD CONSTRAINT pk_station PRIMARY KEY ( codestation );
grant select on station to i2b06b, i2b07b, i2b05b;
grant update on station to i2b06b, i2b07b, i2b05b;
grant insert on station to i2b06b, i2b07b, i2b05b;
--Cl trangre
alter table station add constraint fk_insee_station
foreign key(insee) references i2b05b.commune(insee);
--Cl trangre
alter table station add constraint fk_codepointdecharge_station
foreign key(codepointdecharge) references i2b06b.borne(codepointdecharge);
select * from station ;
select * from I2B05B.commune ;
......@@ -89,6 +111,15 @@ where d
group by commune
order by 1;
select amnageur,sum(nombrepointsdecharge) nbrprise
from I2B06B.borne natural join station
group by amnageur
order by 1;
select distinct amnageur
from I2B06B.borne natural join station
where accsrecharge in ('Gratuit','gratuit')
order by 1;
--7
......@@ -138,4 +169,7 @@ select * from nbrpriseAm
union all
select * from nbrpriseAmnML;
select * from nbrpriseAmnPDL;
\ No newline at end of file
select * from nbrpriseAmnPDL;
select amnageur,sum(nbrprise) from nbrpriseAmnPDL group by amnageur;
select amnageur,count(*) from nbrpriseAmnPDL group by amnageur;
\ No newline at end of file
Stat/TP2/1.1.png

42,1 ko

Stat/TP2/1.2.png

34,2 ko

Stat/TP2/1.3.png

34,7 ko

Stat/TP2/1.4.png

38,6 ko

Stat/TP2/1.5.png

30,9 ko

Stat/TP2/1.6.png

34,7 ko

Stat/TP2/1.7.png

39,1 ko

Stat/TP2/1.8.png

25,2 ko

import csv as csv
from turtle import color
from typing import List
from unicodedata import decimal
import matplotlib.pyplot as plt
from psutil import LINUX
def csvopen(A):
......@@ -14,7 +11,7 @@ def csvopen(A):
for row in data:
Liste.append(list(row))
for i in range(1,len(Liste)):
Liste[i] = [float(s) for s in Liste[i]]
Liste[i] = [float(s.replace(',','.')) for s in Liste[i]]
Lx=[]
Ly=[]
......@@ -46,19 +43,20 @@ def coeffs_droite_reg(X,Y):
def etude(X,Y):
ig, ax = plt.subplots()
mX,mY=point_moyen(X,Y)
ax.scatter(X, Y,color='blue')
ax.scatter(mX, mY,color='Orange')
ax.scatter(X, Y,color='blue',label='données')
ax.scatter(mX, mY,color='Orange',label='point moyen')
a,b=coeffs_droite_reg(X,Y)
correc=[]
for i in X:
correc.append(a*i+b)
ax.plot(X, correc,color='Orange')
ax.set_title(f"{coeff_corr(X,Y)}")
ax.plot(X, correc,color='Orange',label='droite de régression linéaire')
ax.set_title(f"coefficient de corrélation : {coeff_corr(X,Y)}")
plt.legend()
plt.show()
def main():
Lx,Ly=csvopen("ExBsetA.csv")
L2x,L2y=csvopen("ExBsetB.csv")
Lx,Ly=csvopen("ExBsetB.csv")
L2x,L2y=csvopen("ExBsetA.csv")
Lx+=L2x
Ly+=L2y
etude(Lx,Ly)
......
Stat/TP2/2.1.png

30,9 ko

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import linregress
x, y = np.loadtxt("regLinData.dat", unpack=True)
regress = linregress(x, y)
coef = np.polyfit(x, y - (regress.slope*x + regress.intercept), 2)
plt.scatter(x, y, s=2, label='données')
plt.plot(x, regress.intercept + regress.slope*x)
plt.plot(x, coef[0]*x**2 + coef[1]*x + coef[2])
plt.scatter(x, y - (regress.slope*x + regress.intercept), s=2, label='résidu')
plt.legend()
plt.show()
\ No newline at end of file
Fichier ajouté
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter