reformat
This commit is contained in:
@ -1,13 +0,0 @@
|
||||
from src.m.connexionBDD import connexionBDD
|
||||
|
||||
|
||||
class Abonnement:
|
||||
def __init__(self, libelle, prix, estPackGar):
|
||||
self.libelle = libelle
|
||||
self.prix = prix
|
||||
self.estPackGar = estPackGar
|
||||
|
||||
def addContrat(self, contrat):
|
||||
connexion = connexionBDD()
|
||||
# indId= connexion.cur.execute("SELECT abonnement.idAbonnement FROM abonnement WHERE libelle = ? AND prix = ? AND estPackGar=?;"(self.libelle, self.prix, self.estPackGar))
|
||||
# idAbonnement = int(''.join(map(str,indId)))
|
@ -1,26 +1,45 @@
|
||||
import random
|
||||
import sqlite3
|
||||
import string
|
||||
from src.m.connexionBDD import connexionBDD
|
||||
|
||||
|
||||
__author__ = 'sidya'
|
||||
|
||||
class Client:
|
||||
@staticmethod
|
||||
def get(id):
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM client WHERE idClient='"+str(id)+"'")
|
||||
row = r.fetchone()
|
||||
if row is None :
|
||||
raise IndexError("Invalid id")
|
||||
c.seDeconnecter()
|
||||
return Client(id, row["nom"],row["prenom"],row["adresse"], bool(row["typeAbonnement"]))
|
||||
|
||||
class Client():
|
||||
clients = []
|
||||
|
||||
def __init__(self, nom, prenom, adresse, typeAbonnement):
|
||||
while True:
|
||||
id = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in
|
||||
range(random.randint(1, 10)))
|
||||
if Client.get(id) is None:
|
||||
break
|
||||
self.__id = id
|
||||
def __init__(self,id, nom, prenom, adresse, typeAbonnement):
|
||||
self.__nom = nom
|
||||
self.__prenom = prenom
|
||||
self.__typeAbonnement = typeAbonnement
|
||||
self.__adresse = adresse
|
||||
self.clients.append(self)
|
||||
|
||||
if id is None:
|
||||
while True:
|
||||
id = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in
|
||||
range(random.randint(1, 10)))
|
||||
try :
|
||||
Client.get(id)
|
||||
except IndexError :
|
||||
break
|
||||
|
||||
self.__id = id
|
||||
c = connexionBDD()
|
||||
c.execute("INSERT INTO client (idClient, nom, prenom, adresse, typeAbonnement) VALUES (?,?,?,?,?)",
|
||||
(str(self.__id), str(self.__nom), str(self.__prenom), "", str(self.__typeAbonnement)))
|
||||
self.__id = id
|
||||
c.seDeconnecter()
|
||||
else:
|
||||
self.__id = id
|
||||
|
||||
@property
|
||||
def prenom(self):
|
||||
@ -42,46 +61,14 @@ class Client():
|
||||
def abonnement(self):
|
||||
return self.__typeAbonnement
|
||||
|
||||
@staticmethod
|
||||
def get(id):
|
||||
for client in Client.clients:
|
||||
if client.id == id:
|
||||
return client
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def loadAll(connection):
|
||||
with connection:
|
||||
connection.row_factory = sqlite3.Row
|
||||
cur = connection.cursor()
|
||||
cur.execute("SELECT * FROM Client")
|
||||
rows = cur.fetchall()
|
||||
for row in rows:
|
||||
Client(row["num"], row["nom"], row["prenom"], row["adr"], int(row["abo"]))
|
||||
connection.close()
|
||||
|
||||
@staticmethod
|
||||
def saveAll(connection):
|
||||
cur = connection.cursor()
|
||||
# reset table Client
|
||||
cur.execute("DROP TABLE IF EXISTS Client")
|
||||
cur.execute(
|
||||
"""create table Client (num varchar(10) PRIMARY KEY, nom varchar(30), prenom varchar(30), adr varchar(50), abo int(1))""")
|
||||
# insert clients
|
||||
for c in Client.tous:
|
||||
cur.execute("insert into Client values (?, ?, ?, ?, ?)", (c.id, c.nom, c.prenom, c.adr, c.abonnement))
|
||||
connection.commit()
|
||||
connection.close()
|
||||
|
||||
def maj(self, nom, prenom, adresse, typeAbonnement):
|
||||
self.__nom = nom
|
||||
self.__prenom = prenom
|
||||
self.__typeAbonnement = typeAbonnement
|
||||
self.__adresse = adresse
|
||||
|
||||
def __str__(self):
|
||||
return "( " + self.__id + ", " + self.__nom + ", " + self.__prenom + ", " + self.__adresse + ", " + str(
|
||||
self.__typeAbonnement) + " )"
|
||||
|
||||
|
||||
return "[Client :" \
|
||||
" id = " + str(self.__id) + ", " \
|
||||
" prenom = " + str(self.__prenom) + ", " \
|
||||
" nom = " + str(self.__nom) + ", " \
|
||||
" adresse = " + str(self.__adresse) + ", " \
|
||||
" typeAbonnement = " + str(self.__typeAbonnement) + "]"
|
||||
|
||||
class TypeAbonnement:
|
||||
ABONNE = 0
|
||||
SUPER_ABONNE = 1
|
@ -1,26 +0,0 @@
|
||||
__author__ = 'sidya'
|
||||
|
||||
|
||||
class connexionBDD:
|
||||
def __init__(self):
|
||||
try:
|
||||
self.__conn = sqlite3.connect("BD.sql3")
|
||||
self.__cur = self.__conn.cursor()
|
||||
except Exception as e:
|
||||
pass # later
|
||||
|
||||
def seDeconnecter(self):
|
||||
self.__cur.close()
|
||||
self.__conn.close()
|
||||
|
||||
def execute(self, req):
|
||||
try:
|
||||
r = self.__cur.execute(req)
|
||||
self.__conn.commit()
|
||||
except Exception as e:
|
||||
pass # later
|
||||
return r
|
||||
|
||||
|
||||
def lastId(self):
|
||||
return self.__cur.lastrowid
|
@ -1,23 +0,0 @@
|
||||
from src.m.connexionBDD import connexionBDD
|
||||
|
||||
|
||||
class Contrat:
|
||||
def __init__(self, dateDebut, dateFin):
|
||||
self.dateDebut = dateDebut
|
||||
self.dateFin = dateFin
|
||||
|
||||
def enregistrerContrat(self):
|
||||
connection = connexionBDD()
|
||||
connection.cur.execute("INSERT INTO contrat (idContrat,dateDebut,dateFin, estEncours) VALUES (NULL,?,?,1);",
|
||||
( self.dateDebut, self.dateFin, 1))
|
||||
connection.seDeconnecter()
|
||||
|
||||
def rompreContrat(self, idCLient):
|
||||
connection = connexionBDD()
|
||||
indContrat = connection.cur.execute(
|
||||
"SELECT Contrat.idContrat FROM contrat where idClient =? AND dateDebut = ? AND dateFin=? ;"(idCLient,
|
||||
self.dateDebut,
|
||||
self.dateFin))
|
||||
idContrat = int(''.join(map(str, indContrat)))
|
||||
connection.cur.execute("Update contrat where idContrat=? set estEnCours =0;", ( idContrat))
|
||||
connection.seDeconnecter()
|
@ -1,19 +0,0 @@
|
||||
from src.m.Service import Service
|
||||
from src.m.connexionBDD import connexionBDD
|
||||
|
||||
|
||||
class Entretien(Service):
|
||||
def __init__(self, jourService, moisService, anneeService, jourDemande, moisDemande, anneeDemande, rapport,
|
||||
categorie, idClient):
|
||||
super(Service, self).__init__(self, jourService, moisService, anneeService, jourDemande, moisDemande,
|
||||
anneeDemande, rapport, categorie)
|
||||
self.categorie = 2
|
||||
self.etat = 0
|
||||
self.idService = self.enregistrerService(self, idClient, self.categorie, self.etat)
|
||||
|
||||
|
||||
def effectuerEntretien(self):
|
||||
self.etat = 1
|
||||
connexion = connexionBDD()
|
||||
connexion.cur.execute("UPDATE service SET etat= 1 WHERE idService = ?", (self.idService))
|
||||
connexion.seDeconnecter()
|
@ -1,26 +0,0 @@
|
||||
from src.m.TypePlace import TypePlace
|
||||
|
||||
__author__ = 'sidya'
|
||||
|
||||
|
||||
class ListeTypePlace:
|
||||
"""
|
||||
Classe qui permet de définir une liste de type de place par niveau pour la création d'un parking
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.l = []
|
||||
|
||||
def add(self, h, l, nb):
|
||||
self.l.append(TypePlace(h, l, nb))
|
||||
|
||||
@property
|
||||
def nbPlaceTotal(self):
|
||||
i = 0
|
||||
for t in self.l:
|
||||
i += t.nb
|
||||
return i
|
||||
|
||||
@property
|
||||
def liste(self):
|
||||
return self.l
|
@ -1,29 +0,0 @@
|
||||
import calendar
|
||||
|
||||
from src.m.Service import Service
|
||||
from src.m.connexionBDD import connexionBDD
|
||||
|
||||
|
||||
class Livraison(Service):
|
||||
def __init__(self, jourService, moisService, anneeService, jourDemande, moisDemande, anneeDemande, rapport,
|
||||
categorie, idClient):
|
||||
super(Service, self).__init__(self, jourService, moisService, anneeService, jourDemande, moisDemande,
|
||||
anneeDemande, rapport, categorie)
|
||||
self.categorie = 3
|
||||
self.etat = 0
|
||||
# 3.Obtenir l'idVoiturier: en recherchant celui qui est disponible le jour en question
|
||||
self.idService = self.enregistrerService(self, idClient, self.categorie, self.etat)
|
||||
jour = calendar.weekday(self.dateService._day, self.dateService._month, self.dateService._year)
|
||||
connexion = connexionBDD()
|
||||
indiceVoiturier = connexion.cur.execute(
|
||||
"SELECT voiturier.idVoiturier FROM voiturier WHERE voiturier.joursDisponible = ?; ", (jour))
|
||||
idVoiturier = int(''.join(map(str, indiceVoiturier)))
|
||||
connexion.cur.execute("UPDATE service SET idVoiturier= ? WHERE idService = ?", (idVoiturier, self.idService))
|
||||
connexion.seDeconnecter()
|
||||
|
||||
def effectuerLivraison(self):
|
||||
self.etat = 1
|
||||
connexion = connexionBDD()
|
||||
connexion.cur.execute("UPDATE service SET etat= 1 WHERE idService = ?", (self.idService))
|
||||
connexion.seDeconnecter()
|
||||
|
@ -1,18 +0,0 @@
|
||||
from src.m.Service import Service
|
||||
from src.m.connexionBDD import connexionBDD
|
||||
|
||||
|
||||
class Maintenance(Service):
|
||||
def __init__(self, jourService, moisService, anneeService, jourDemande, moisDemande, anneeDemande, rapport,
|
||||
categorie, idClient):
|
||||
super(Service, self).__init__(self, jourService, moisService, anneeService, jourDemande, moisDemande,
|
||||
anneeDemande, rapport, categorie)
|
||||
self.categorie = 1
|
||||
self.etat = 0
|
||||
self.idService = self.enregistrerService(self, idClient, self.categorie, self.etat)
|
||||
|
||||
def effectuerMaintenance(self):
|
||||
self.etat = 1
|
||||
connexion = connexionBDD()
|
||||
connexion.cur.execute("UPDATE service SET etat= 1 WHERE idService = ?", (self.idService))
|
||||
|
312
src/m/Parking.py
312
src/m/Parking.py
@ -1,30 +1,44 @@
|
||||
from src.m.Place import Place
|
||||
import random
|
||||
import string
|
||||
import datetime
|
||||
from src.m.Voiture import Voiture
|
||||
from src.m.connexionBDD import connexionBDD
|
||||
|
||||
__author__ = 'sidya'
|
||||
|
||||
|
||||
|
||||
class Parking:
|
||||
"""
|
||||
Definie un parking
|
||||
"""
|
||||
parkings = []
|
||||
|
||||
def __init__(self, typePlaces, nom):
|
||||
"""
|
||||
Creer objet parking
|
||||
:param typePlaces: ListeTypePlace
|
||||
:param nom: str
|
||||
:return:
|
||||
"""
|
||||
self.__typePlaces = typePlaces
|
||||
@staticmethod
|
||||
def get(id):
|
||||
for p in Parking.parkings :
|
||||
if p.id == id :
|
||||
return p
|
||||
|
||||
@staticmethod
|
||||
def getAll():
|
||||
return Parking.parkings
|
||||
|
||||
|
||||
def __init__(self, nom, listeTypePlace):
|
||||
self.__nom = nom
|
||||
self.__prix = 10
|
||||
self.__Places = {}
|
||||
l = []
|
||||
for t in typePlaces.liste:
|
||||
for i in range(0, t.nb):
|
||||
l.append(Place(i + 1, 1, t.longueur, t.hauteur))
|
||||
self.__Places = l
|
||||
c = connexionBDD()
|
||||
c.execute("INSERT INTO parking (nom) VALUES ('"+str(self.__nom)+"')", ())
|
||||
self.__id = c.lastId()
|
||||
|
||||
#Crea des places
|
||||
n = 0
|
||||
for typePlace in listeTypePlace :
|
||||
for i in range(typePlace.nombre) :
|
||||
print(Place(None,self,typePlace,1,n,True,False))
|
||||
n += 1
|
||||
self.parkings.append(self)
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return self.__id
|
||||
|
||||
@property
|
||||
def nom(self):
|
||||
@ -32,16 +46,15 @@ class Parking:
|
||||
|
||||
@property
|
||||
def nbPlaces(self):
|
||||
return self.__typePlaces.nbPlaceTotal
|
||||
|
||||
return Place.nbPlaceParking(self.__id)
|
||||
|
||||
@property
|
||||
def nbPlacesLibresParking(self):
|
||||
i = 0
|
||||
for p in self.__Places:
|
||||
if p.estLibre:
|
||||
i += 1
|
||||
return i
|
||||
return Place.nbPlaceLibreParking(self.__id)
|
||||
|
||||
@property
|
||||
def nbSuperAbo(self):
|
||||
return Place.nbSuperAbo(self.__id)
|
||||
|
||||
def recherchePlace(self, voiture):
|
||||
"""
|
||||
@ -49,17 +62,240 @@ class Parking:
|
||||
:param voiture: Voiture
|
||||
:return: Place
|
||||
"""
|
||||
place = None
|
||||
for p in self.__Places:
|
||||
if p.estLibre and p.dimValide(voiture.getHauteur, voiture.getLongueur):
|
||||
pass
|
||||
place = p
|
||||
break
|
||||
return place
|
||||
|
||||
|
||||
def addAbonnement(self, Abonnement):
|
||||
pass
|
||||
return Place.placeValide(self.__id, voiture)
|
||||
|
||||
def __str__(self):
|
||||
return "Parking : niveau : " + str(self.__nbNiveaux)
|
||||
return "[Parking : nom = " + self.__nom +"]"
|
||||
|
||||
|
||||
class Place:
|
||||
@staticmethod
|
||||
def get(id):
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM place WHERE idPlace='"+str(id)+"'")
|
||||
row = r.fetchone()
|
||||
if row is None :
|
||||
raise IndexError("Invalid id")
|
||||
c.seDeconnecter()
|
||||
return Place(id,row["idParking"],row["idTypePlace"],row["niveau"],
|
||||
row["numero"],row["estLibre"],row["estSuperAbo"])
|
||||
|
||||
def __init__(self, id, parking, typePlace, niveau, numero, estLibre, estSuperAbo):
|
||||
self.__parking = parking
|
||||
self.__typePlace = typePlace
|
||||
self.__niveau = niveau
|
||||
self.__numero = numero
|
||||
self.__estLibre = estLibre
|
||||
self.__estSuperAbo = estSuperAbo
|
||||
if id is None :
|
||||
c = connexionBDD()
|
||||
c.execute("INSERT INTO place (idParking, idTypePlace, niveau, numero, estLibre, estSuperAbo) "
|
||||
"VALUES (?,?,?,?,?,?)",
|
||||
(self.__parking.id, self.__typePlace.id,self.__niveau,
|
||||
self.__numero, self.__estLibre, int(self.__estSuperAbo)))
|
||||
self.__id = c.lastId()
|
||||
c.seDeconnecter()
|
||||
else :
|
||||
self.__id = id
|
||||
|
||||
def prendre(self):
|
||||
"""
|
||||
Rend la place indisponible
|
||||
:param Placement:
|
||||
:return:
|
||||
"""
|
||||
if (self.__estLibre == False):
|
||||
raise Exception("Place déjà prise")
|
||||
self.__estLibre = False
|
||||
c = connexionBDD()
|
||||
c.execute("UPDATE place SET estLibre = 0 WHERE idPlace = ?", (str(self.__id)))
|
||||
c.seDeconnecter()
|
||||
|
||||
def liberer(self):
|
||||
"""
|
||||
Libere une place non dispo
|
||||
:return:
|
||||
"""
|
||||
if (self.__estLibre == True):
|
||||
raise Exception("Impossible de liberer une place vide")
|
||||
self.__estLibre = False
|
||||
c = connexionBDD()
|
||||
c.execute("UPDATE place SET estLibre = 1 WHERE idPlace = ?", (str(self.__id)))
|
||||
c.seDeconnecter()
|
||||
|
||||
@staticmethod
|
||||
def nbPlaceParking(idParking):
|
||||
c = connexionBDD()
|
||||
print("lol")
|
||||
r = c.execute("SELECT COUNT(*) FROM place WHERE idParking = ?", (str(idParking)))
|
||||
row = r.fetchone()
|
||||
c.seDeconnecter()
|
||||
return row[0]
|
||||
|
||||
@staticmethod
|
||||
def nbPlaceLibreParking(idParking):
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT COUNT(*) FROM place WHERE idParking = ? AND estLibre = 1", (str(idParking)))
|
||||
row = r.fetchone()
|
||||
c.seDeconnecter()
|
||||
return row[0]
|
||||
|
||||
@staticmethod
|
||||
def nbSuperAbo(idParking):
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT COUNT(*) FROM place WHERE idParking = ? AND estSuperAbo = 1", (str(idParking)))
|
||||
row = r.fetchone()
|
||||
c.seDeconnecter()
|
||||
return row[0]
|
||||
|
||||
@staticmethod
|
||||
def placeValide(idPArking, voiture):
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM place WHERE idParking= ? AND estLibre = 1 "
|
||||
"AND idTypePlace =(SELECT idTypePlace FROM typePlace "
|
||||
"WHERE hauteur>? AND longueur>? ORDER BY longueur) ",
|
||||
(str(idPArking),str(voiture.hauteur),str(voiture.longueur)))
|
||||
row = r.fetchone()
|
||||
c.seDeconnecter()
|
||||
if row is None :
|
||||
return None
|
||||
else :
|
||||
return Place(row["idPlace"],row["idParking"], row["idtypePlace"],
|
||||
row["niveau"], row["numero"], bool(row["estLibre"]), bool(row["estSuperAbo"]))
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return "[Place : " \
|
||||
"Parking = " + str(self.__parking) + "," \
|
||||
"typePlace = " + str(self.__typePlace) + "," \
|
||||
"niveau = " + str(self.__niveau) + "," \
|
||||
"numero = " + str(self.__numero) + "," \
|
||||
"estLibre = " + str(self.__estLibre) + "," \
|
||||
"estSuperAbo = " + str(self.__estSuperAbo) + "]" \
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return self.__id
|
||||
|
||||
|
||||
|
||||
class TypePlace:
|
||||
@staticmethod
|
||||
def get(id):
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM typePlace WHERE idTypePlace='"+str(id)+"'")
|
||||
row = r.fetchone()
|
||||
if row is None :
|
||||
raise IndexError("Invalid id")
|
||||
c.seDeconnecter()
|
||||
return TypePlace(id,row["longueur"],row["hauteur"],row["nombre"])
|
||||
|
||||
|
||||
def __init__(self, id ,longueur, hauteur, nombre):
|
||||
self.__longueur = longueur
|
||||
self.__hauteur = hauteur
|
||||
self.__nombre = nombre
|
||||
if id is None :
|
||||
c = connexionBDD()
|
||||
c.execute("INSERT INTO typePlace (longueur,hauteur,nombre) VALUES (?,?,?)",
|
||||
(self.__longueur, self.__hauteur, self.__nombre))
|
||||
self.__id = c.lastId()
|
||||
c.seDeconnecter()
|
||||
else:
|
||||
self.__id = id
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return self.__id
|
||||
|
||||
@property
|
||||
def longueur(self):
|
||||
return self.__longueur
|
||||
|
||||
@property
|
||||
def hauteur(self):
|
||||
return self.__hauteur
|
||||
|
||||
@property
|
||||
def nombre(self):
|
||||
return self.__nombre
|
||||
|
||||
def __str__(self):
|
||||
return "[TypePlace : " \
|
||||
"id = " + str(self.__id) + "," \
|
||||
"longueur = " + str(self.__longueur) + "," \
|
||||
"hauteur = " + str(self.hauteur) + "," \
|
||||
"nombre = " + str(self.nombre) + "]"
|
||||
|
||||
|
||||
class Placement:
|
||||
placementsEnCours = []
|
||||
|
||||
@staticmethod
|
||||
def get(id):
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM placement WHERE idPlacement='"+str(id)+"'")
|
||||
row = r.fetchone()
|
||||
if row is None :
|
||||
raise IndexError("Invalid id")
|
||||
c.seDeconnecter()
|
||||
print(row["idVoiture"])
|
||||
return Placement(row["idPlacement"], Voiture.get(row["idVoiture"]), Place.get(row["idPlace"]),
|
||||
row["debut"], row["fin"])
|
||||
|
||||
|
||||
def __init__(self,id, voiture, place, debut, fin):
|
||||
"""
|
||||
Creer un placement
|
||||
:param voiture: Voiture
|
||||
:param place: Place
|
||||
:return:
|
||||
"""
|
||||
self.__voiture = voiture
|
||||
self.__place = place
|
||||
place.prendre()
|
||||
self.placementsEnCours.append(self)
|
||||
if id is None :
|
||||
self.__debut = datetime.datetime
|
||||
self.__fin = None
|
||||
while True:
|
||||
id = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in
|
||||
range(random.randint(1, 10)))
|
||||
try:
|
||||
Placement.get(id)
|
||||
except IndexError:
|
||||
break
|
||||
c = connexionBDD()
|
||||
c.execute("INSERT INTO placement (idPlacement,idVoiture,idPlace, debut, fin) VALUES (?,?,?,?,?)",
|
||||
(str(id), str(self.__voiture.id), str(self.__place.id), str(self.__debut), "NULL"))
|
||||
self.__id = id
|
||||
c.seDeconnecter()
|
||||
else:
|
||||
self.__id = id
|
||||
self.__debut = debut
|
||||
self.__fin = fin
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return self.__id
|
||||
|
||||
def __str__(self):
|
||||
return "[Placement : " \
|
||||
"id = " + self.__id +"," \
|
||||
"Voiture = " + self.__voiture +"," \
|
||||
"Place = " + self.__place +"," \
|
||||
"Debut = " + self.__debut +"," \
|
||||
"Fin = " + self.__fin +"]"
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__" :
|
||||
c = connexionBDD()
|
||||
c.initialisationBDD()
|
||||
c.seDeconnecter()
|
||||
listeTypePlaces = []
|
||||
listeTypePlaces.append(TypePlace(None,200, 300,10))
|
||||
listeTypePlaces.append(TypePlace(None,120, 250,15))
|
||||
p = Parking("test",listeTypePlaces)
|
||||
print (p)
|
@ -1,79 +0,0 @@
|
||||
__author__ = 'sidya'
|
||||
|
||||
|
||||
class Place:
|
||||
"""
|
||||
Representation d'une place
|
||||
"""
|
||||
|
||||
def __init__(self, numero, niveau, longueur, hauteur):
|
||||
"""
|
||||
Creer une place.
|
||||
Les dimensions doivent etre données en cm (longueur, hauteur)
|
||||
:param numero: int
|
||||
:param niveau: int
|
||||
:param longueur: int
|
||||
:param hauteur: int
|
||||
:return:
|
||||
"""
|
||||
self.__numero = numero
|
||||
self.__niveau = niveau
|
||||
self.__longueur = longueur
|
||||
self.__hauteur = hauteur
|
||||
self.__estLibre = True
|
||||
self.__estSuperAbo = False
|
||||
self.__Placement = None
|
||||
|
||||
@property
|
||||
def estLibre(self):
|
||||
return self.__estLibre
|
||||
|
||||
@property
|
||||
def estReserver(self):
|
||||
return self.__estSuperAbo
|
||||
|
||||
def dimValide(self, h, l):
|
||||
"""
|
||||
Retourn si un element de hauteur (cm) h et de longueur(cm) l passe dans la place
|
||||
:param h: int
|
||||
:param l: int
|
||||
:return: bool
|
||||
"""
|
||||
return h < self.__hauteur and l < self.__longueur
|
||||
|
||||
def superAbo(self):
|
||||
"""
|
||||
Renvoit si la place est une place superAbo
|
||||
:return: bool
|
||||
"""
|
||||
if (self.__estSuperAbo == True):
|
||||
raise Exception("Place déjà reservé")
|
||||
self.__estSuperAbo = True
|
||||
|
||||
|
||||
def prendre(self):
|
||||
"""
|
||||
Rend la place indisponible
|
||||
:param Placement:
|
||||
:return:
|
||||
"""
|
||||
if (self.__estLibre == False):
|
||||
raise Exception("Place déjà prise")
|
||||
self.__estLibre = False
|
||||
|
||||
def liberer(self):
|
||||
"""
|
||||
Libere une place non dispo
|
||||
:return:
|
||||
"""
|
||||
if (self.__estLibre == True):
|
||||
raise Exception("Impossible de liberer une place vide")
|
||||
self.__estLibre = True
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,53 +0,0 @@
|
||||
import datetime
|
||||
import random
|
||||
import string
|
||||
|
||||
__author__ = 'sidya'
|
||||
|
||||
|
||||
class Placement:
|
||||
placements = []
|
||||
|
||||
def __init__(self, voiture, place):
|
||||
"""
|
||||
Creer un placement
|
||||
:param voiture: Voiture
|
||||
:param place: Place
|
||||
:return:
|
||||
"""
|
||||
while True:
|
||||
id = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in
|
||||
range(random.randint(1, 10)))
|
||||
if Placement.get(id) is None:
|
||||
break
|
||||
self.__id = id
|
||||
self.__voiture = voiture
|
||||
self.__place = place
|
||||
self.__debut = datetime.datetime
|
||||
self.__fin = None
|
||||
place.prendre()
|
||||
self.placements.append(self)
|
||||
|
||||
def end(self):
|
||||
self.__fin = datetime.datetime
|
||||
self.__place.liberer()
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return self.__id
|
||||
|
||||
@staticmethod
|
||||
def get(id):
|
||||
"""
|
||||
Recupere le Placement d'id id
|
||||
:param id: str
|
||||
:return: Placement or None
|
||||
"""
|
||||
for p in Placement.placements:
|
||||
if p.__id == id:
|
||||
return p
|
||||
return None
|
||||
|
||||
@property
|
||||
def estEnCours(self):
|
||||
return datetime.datetime < self.__fin
|
@ -1,49 +1,4 @@
|
||||
import calendar
|
||||
import datetime
|
||||
|
||||
from src.m.connexionBDD import connexionBDD
|
||||
|
||||
__author__ = 'sidya'
|
||||
|
||||
class Service:
|
||||
def __init__(self, jourService, moisService, anneeService, jourDemande, moisDemande, anneeDemande, rapport):
|
||||
try:
|
||||
dateService = datetime.date(anneeService, moisService, jourService)
|
||||
self.dateService = dateService
|
||||
except:
|
||||
# Si la date n'est pas un nombre ou bien si ceux ci sont abérrents
|
||||
print("la date de service n\'est pas correcte")
|
||||
try:
|
||||
dateDemande = datetime.date(anneeDemande, moisDemande, jourDemande)
|
||||
self.dateDemande = dateDemande
|
||||
except:
|
||||
print("la date de service n\'est pas correcte")
|
||||
self.rapport = rapport
|
||||
|
||||
def enregistrerService(self, idClient, categorie, etat):
|
||||
try:
|
||||
connection = connexionBDD()
|
||||
# 1.obtenir id service (fonction max de sqlite ne marche pas bien...elle ne prend en compte que le premier chiffre. Ex: max(56,9)= 9... )
|
||||
connection.cur.execute("SELECT count(service.idSercice) FROM service;")
|
||||
# entrée dans la base de donnée
|
||||
indiceidSer = connection.cur.execute("SELECT count(service.idService) FROM service;")
|
||||
idService = int(''.join(map(str, indiceidSer))) + 1
|
||||
#2. obtenir l'idClient: définir une variable globale lors de l'execution du "jeu"
|
||||
#3.Obtenir l'idVoiturier: en recherchant celui qui est disponible le jour en question
|
||||
jour = calendar.weekday(self.dateService._day, self.dateService._month, self.dateService._year)
|
||||
indiceVoiturier = connection.cur.execute(
|
||||
"SELECT voiturier.idVoiturier FROM voiturier WHERE voiturier.joursDisponible = ?; ", (jour))
|
||||
idVoiturier = int(''.join(map(str, indiceVoiturier)))
|
||||
connection.cur.execute(
|
||||
"INSERT INTO service (idService,dateService,dateDemande,rapport,idClient,idVoiturier,idService, idVoiturier, categorie, etat) VALUES (?,?,?,?,?,?,?,?,?,?);",
|
||||
(idService, self.dateService, self.dateDemande, self.rapport, idClient, idVoiturier, idService,
|
||||
categorie, etat))
|
||||
connection.seDeconnecter()
|
||||
return idService
|
||||
except Exception as e:
|
||||
print
|
||||
str(e)
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
pass
|
@ -1,6 +0,0 @@
|
||||
__author__ = 'sidya'
|
||||
|
||||
|
||||
class TypeAbonnement:
|
||||
ABONNE = 0
|
||||
SUPER_ABONNE = 1
|
@ -1,24 +0,0 @@
|
||||
__author__ = 'sidya'
|
||||
|
||||
|
||||
class TypePlace:
|
||||
"""
|
||||
Classe qui permet de définir un type de place
|
||||
"""
|
||||
|
||||
def __init__(self, h, l, nb):
|
||||
self.__hauteur = h
|
||||
self.__longueur = l
|
||||
self.__nb = nb
|
||||
|
||||
@property
|
||||
def hauteur(self):
|
||||
return self.__hauteur
|
||||
|
||||
@property
|
||||
def longueur(self):
|
||||
return self.__longueur
|
||||
|
||||
@property
|
||||
def nb(self):
|
||||
return self.__nb
|
@ -1,26 +1,57 @@
|
||||
class Voiture():
|
||||
def __init__(self, longueur, hauteur, imma):
|
||||
self._hauteur = hauteur
|
||||
self._longueur = longueur
|
||||
self._immatriculation = imma
|
||||
self._estDansParking = False
|
||||
from src.m.connexionBDD import connexionBDD
|
||||
|
||||
__author__ = 'sidya'
|
||||
|
||||
class Voiture:
|
||||
@staticmethod
|
||||
def get(id):
|
||||
c = connexionBDD()
|
||||
r = c.execute("SELECT * FROM voiture WHERE idVoiture='"+str(id)+"'")
|
||||
row = r.fetchone()
|
||||
if row is None :
|
||||
raise IndexError("Invalid id")
|
||||
c.seDeconnecter()
|
||||
return Voiture(id,row["longueur"],row["hauteur"],row["imma"], bool(row["estDansParking"]))
|
||||
|
||||
|
||||
def __init__(self, longueur, hauteur, imma, estDansParking):
|
||||
self.__longueur = longueur
|
||||
self.__hauteur = hauteur
|
||||
self.__imma = imma
|
||||
self.__estDansParking = estDansParking
|
||||
|
||||
if id is None :
|
||||
c = connexionBDD()
|
||||
c.execute("INSERT INTO voiture (longueur,hauteur,imma, estDansParking) VALUES (?,?,?,?)",
|
||||
(self.__longueur, self.__hauteur, self.__imma, int(self.__estDansParking)))
|
||||
self.__id = c.lastId()
|
||||
c.seDeconnecter()
|
||||
else:
|
||||
self.__id = id
|
||||
|
||||
@property
|
||||
def getHauteur(self):
|
||||
return self._hauteur
|
||||
def id(self):
|
||||
return self.__id
|
||||
|
||||
@property
|
||||
def getLongueur(self):
|
||||
return self._longueur
|
||||
def hauteur(self):
|
||||
return self.__hauteur
|
||||
|
||||
@property
|
||||
def getImmatriculation(self):
|
||||
return self._immatriculation
|
||||
def longueur(self):
|
||||
return self.__longueur
|
||||
|
||||
@property
|
||||
def immatriculation(self):
|
||||
return self.__immatriculation
|
||||
|
||||
@property
|
||||
def estDansParking(self):
|
||||
return self._estDansParking == True
|
||||
|
||||
# def addPlacement(self, placement):
|
||||
|
||||
return self.__estDansParking == True
|
||||
|
||||
def __str__(self):
|
||||
return "[Voiture :" \
|
||||
" longueur = " +self.__longueur + ", " \
|
||||
" hauteur = " +self.__hauteur + ", " \
|
||||
" imma = " +self.__imma + ", " \
|
||||
" estDansParking = " +self.__estDansParking + "]"
|
@ -1,28 +0,0 @@
|
||||
import time
|
||||
|
||||
from src.m.connexionBDD import connexionBDD
|
||||
|
||||
|
||||
class Voiturier:
|
||||
def __init__(self, id, nom, prenom):
|
||||
self.numero = id
|
||||
self.nom = nom
|
||||
self.prenom = prenom
|
||||
|
||||
def enregistrerVoiturier(self, nom, prenom, dateEmbauche):
|
||||
connexion = connexionBDD()
|
||||
# entrée dans la base de donnée
|
||||
indiceidVoiturier = connexion.cur.execute("SELECT count(voiturier.idVoiturier) FROM voiturier;") + 1
|
||||
idVoiturier = int(''.join(map(str, indiceidVoiturier))) + 1
|
||||
connexion.cur.execute("INSERT INTO voiturier (idVoiturier,nom, prenom, dateEmbauche) VALUES (?,?,?,?);",
|
||||
(self.idVoiturier, nom, prenom, dateEmbauche))
|
||||
connexion.seDeconnecter()
|
||||
|
||||
def livrerVoiture(self):
|
||||
dateJour = time.strptime()
|
||||
connexion = connexionBDD()
|
||||
indiceLivraison = connexion.cur.execute("SELECT count(voiturier.idVoiturier) FROM voiturier;")
|
||||
idLivraison = int(''.join(map(str, indiceLivraison))) + 1
|
||||
connexion.cur.execute("INSERT INTO livraison (idLivraison,dateLivraison, idVoiturier) VALUES (?,?,?,?);",
|
||||
(idLivraison, dateJour, self.idVoiturier))
|
||||
connexion.seDeconnecter()
|
@ -1,12 +1,32 @@
|
||||
import sqlite3
|
||||
__author__ = 'sidya'
|
||||
|
||||
import sqlite3
|
||||
|
||||
class connexionBDD:
|
||||
def __init__(self):
|
||||
self.chemin = "BDDprojetPython.sq3"
|
||||
self.conn = sqlite3.connect(self.chemin)
|
||||
self.cur = self.conn.cursor()
|
||||
self.__chemin = "m/BDDprojetPython.sq3"
|
||||
self.__conn = sqlite3.connect(self.__chemin)
|
||||
self.__conn.row_factory = sqlite3.Row
|
||||
self.__cur = self.__conn.cursor()
|
||||
|
||||
def execute(self, req, param = ()):
|
||||
r = None
|
||||
#try:
|
||||
r = self.__cur.execute(req, param)
|
||||
self.__conn.commit()
|
||||
"""except Exception as e:
|
||||
print (e)"""
|
||||
return r
|
||||
|
||||
def lastId(self):
|
||||
return self.__cur.lastrowid
|
||||
|
||||
def seDeconnecter(self):
|
||||
self.cur.close()
|
||||
self.conn.close()
|
||||
self.__cur.close()
|
||||
self.__conn.close()
|
||||
|
||||
def initialisationBDD(self):
|
||||
with open("m/table.sql") as f:
|
||||
sql = f.read()
|
||||
self.__conn.executescript(sql)
|
||||
self.__conn.commit()
|
||||
|
@ -1,27 +1,75 @@
|
||||
DROP TABLE IF EXISTS service;
|
||||
DROP TABLE IF EXISTS contrat;
|
||||
DROP TABLE IF EXISTS client;
|
||||
DROP TABLE IF EXISTS abonnement;
|
||||
DROP TABLE IF EXISTS placement;
|
||||
DROP TABLE IF EXISTS voiture;
|
||||
DROP TABLE IF EXISTS place;
|
||||
DROP TABLE IF EXISTS parking;
|
||||
DROP TABLE IF EXISTS typePlace;
|
||||
|
||||
|
||||
|
||||
CREATE TABLE parking (
|
||||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
nom VARCHAR(30),
|
||||
idParking INTEGER PRIMARY KEY ,
|
||||
nom VARCHAR(30)
|
||||
);
|
||||
|
||||
CREATE TABLE place (
|
||||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
idParking INT UNSIGNED FOREIGN KEY,
|
||||
idType INT UNSIGNED FOREIGN KEY,
|
||||
niveau INT UNSIGNED,
|
||||
numero INT UNSIGNED
|
||||
);
|
||||
|
||||
CREATE TABLE typePlace (
|
||||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
longueur INT UNSIGNED,
|
||||
hauteur INT UNSIGNED,
|
||||
largeur INT UNSIGNED,
|
||||
estLibre INT(1),
|
||||
estSuperAbo int(1)
|
||||
idTypePlace INTEGER PRIMARY KEY ,
|
||||
longueur INTEGER ,
|
||||
hauteur INTEGER ,
|
||||
nombre INTEGER
|
||||
);
|
||||
|
||||
CREATE TABLE place (
|
||||
idPlace INTEGER PRIMARY KEY ,
|
||||
idParking INTEGER ,
|
||||
idTypePlace INTEGER ,
|
||||
niveau INTEGER ,
|
||||
numero INTEGER ,
|
||||
estLibre INTEGER(1),
|
||||
estSuperAbo INTEGER(1),
|
||||
FOREIGN KEY (idParking) REFERENCES parking(id),
|
||||
FOREIGN KEY (idTypePlace) REFERENCES typePlace(id)
|
||||
);
|
||||
|
||||
CREATE TABLE voiture (
|
||||
idVoiture INTEGER PRIMARY KEY ,
|
||||
hauteur INTEGER ,
|
||||
longueur INTEGER ,
|
||||
imma VARCHAR(10),
|
||||
estDansParking INTEGER(1)
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE placement (
|
||||
idPlacement VARCHAR(10) PRIMARY KEY ,
|
||||
idVoiture INTEGER ,
|
||||
idPlace INTEGER ,
|
||||
debut DATE,
|
||||
fin DATE,
|
||||
FOREIGN KEY (idVoiture) REFERENCES voiture(id),
|
||||
FOREIGN KEY (idPlace) REFERENCES place(id)
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE client (
|
||||
idClient VARCHAR(10) PRIMARY KEY ,
|
||||
nom VARCHAR(20),
|
||||
prenom VARCHAR(20),
|
||||
adresse VARCHAR(50),
|
||||
typeAbonnement INTEGER
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE service (
|
||||
idService INTEGER PRIMARY KEY ,
|
||||
idClient VARCHAR(10),
|
||||
dateDemande DATE,
|
||||
dateService DATE,
|
||||
dateRealisation DATE,
|
||||
rapport VARCHAR(255),
|
||||
FOREIGN KEY (idClient) REFERENCES client(id)
|
||||
);
|
@ -1,16 +0,0 @@
|
||||
__author__ = 'sidya'
|
||||
|
||||
from nose.tools import assert_equal
|
||||
|
||||
from src.m.Parking import Parking
|
||||
|
||||
|
||||
class TestParking:
|
||||
def recherchePlace(self):
|
||||
"""
|
||||
Test d'attribution des places
|
||||
"""
|
||||
p = Parking()
|
||||
assert_equal()
|
||||
|
||||
|
@ -1,5 +0,0 @@
|
||||
__author__ = 'sidya'
|
||||
|
||||
|
||||
class TestPlace:
|
||||
pass
|
@ -1 +0,0 @@
|
||||
__author__ = 'sidya'
|
@ -1,14 +0,0 @@
|
||||
__author__ = 'nadiel'
|
||||
|
||||
|
||||
class testClient:
|
||||
# def testsAbonner:
|
||||
|
||||
def testnouvelleVoiture(self):
|
||||
assert ()
|
||||
#v = Voiture()
|
||||
|
||||
|
||||
#def testTailleMax(self):
|
||||
# c = Camera()
|
||||
# assert (c.capturerHauteur()>1.5)
|
@ -1,5 +0,0 @@
|
||||
from src.m.placement import Placement
|
||||
class testPlacement:
|
||||
def test_init(self):
|
||||
newPlacement = Placement()
|
||||
|
@ -1,7 +0,0 @@
|
||||
class testService:
|
||||
"""Fonction qui vérifie si la date insérée cest dans un format correcte (année est égale à l'année courante, 01≤jour≤31 et 01≤mois≤12); renvoie une erreur sinon"""
|
||||
|
||||
|
||||
def testFormatDate(self, jourInsere, moisInsere, anneeInsere):
|
||||
|
||||
|
Reference in New Issue
Block a user