Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Database Management System Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bouchaira Neirouz
Database Management System Project
Commits
3816183d
Commit
3816183d
authored
5 months ago
by
Bouchaira Neirouz
Browse files
Options
Downloads
Patches
Plain Diff
fin de l'interface
parent
87f93a41
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
company.db
+0
-0
0 additions, 0 deletions
company.db
streamlit_app.py
+269
-0
269 additions, 0 deletions
streamlit_app.py
with
269 additions
and
0 deletions
company.db
0 → 100644
+
0
−
0
View file @
3816183d
This diff is collapsed.
Click to expand it.
code_interface/
streamlit_app.py
→
streamlit_app.py
+
269
−
0
View file @
3816183d
import
streamlit
as
st
from
datetime
import
date
from
datetime
import
date
,
datetime
,
timedelta
import
sqlite3
import
pandas
as
pd
import
numpy
as
np
# Add this line to import numpy
...
...
@@ -8,13 +8,13 @@ st.write("Bienvenue!😃")
if
'
page
'
not
in
st
.
session_state
:
st
.
session_state
.
page
=
None
tab1
,
tab2
,
tab3
,
tab4
=
st
.
tabs
([
"
Suivi des
employé
s
"
,
"
Employés
avec
3 ans d
'
anciénneté
"
,
"
Création d
'
un compte employé
"
,
"
Bonus
"
])
tab1
,
tab2
,
tab3
,
tab4
,
tab5
=
st
.
tabs
([
"
💳
Suivi des
salaire
s
"
,
"
🕒
Employés
+
3 ans d
'
anciénneté
"
,
"
🚀Productivité
"
,
"
🎁Primes
"
,
"
🆕
Création d
'
un compte employé
"
])
with
tab1
:
st
.
header
(
"
Suivi Employés
"
)
popover
=
st
.
popover
(
"
Filtre employés à afficher
"
)
total
=
popover
.
checkbox
(
"
Salaires des employés par semaine
"
,
True
)
dimin
=
popover
.
checkbox
(
"
Salaires des employés ayant eu une diminution par semaine
"
,
True
)
conn
=
sqlite3
.
connect
(
r
'
C:\Users\neiro\Documents\+\GitHub\sgbd-usine\
donnees\company.db
'
)
conn
=
sqlite3
.
connect
(
r
'
donnees\company.db
'
)
cursor
=
conn
.
cursor
()
cursor
.
execute
(
"
SELECT DATE_LUNDI,SALAIRE_SEMAINE.NUMERO_EMPLOYE,NOM,PRENOM,SALAIRE_BASE,SALAIRE_AVANT, SALAIRE_APRES,NB_HEURES, NB_PRODUCTION,RETARD,ANCIENNETE,NOEL, DATE_DEBUT FROM SALAIRE_SEMAINE JOIN EMPLOYE ON EMPLOYE.NUMERO_EMPLOYE = SALAIRE_SEMAINE.NUMERO_EMPLOYE
"
)
employees
=
cursor
.
fetchall
()
...
...
@@ -31,7 +31,7 @@ with tab1:
conn
.
close
()
with
tab2
:
conn
=
sqlite3
.
connect
(
r
'
C:\Users\neiro\Documents\+\GitHub\sgbd-usine\
donnees\company.db
'
)
conn
=
sqlite3
.
connect
(
r
'
donnees\company.db
'
)
cursor
=
conn
.
cursor
()
on
=
st
.
toggle
(
"
Employés avec 3 ans d
'
anciénneté
"
)
cursor
.
execute
(
"
SELECT NUMERO_EMPLOYE,NOM,PRENOM,TYPE,DATE_DEBUT FROM EMPLOYE
"
)
...
...
@@ -57,11 +57,154 @@ with tab2:
st
.
write
(
"
Liste des employés par production
"
)
st
.
dataframe
(
df
[
df
[
'
Type du contrat
'
]
==
2
])
with
tab3
:
conn
=
sqlite3
.
connect
(
r
'
donnees\company.db
'
)
cursor
=
conn
.
cursor
()
cursor
.
execute
(
"
SELECT NUMERO_EMPLOYE,NOM,PRENOM,TYPE FROM EMPLOYE
"
)
employees
=
cursor
.
fetchall
()
liste_employes
=
sorted
([
(
str
(
employees
[
i
][
0
])
+
"
-
"
+
employees
[
i
][
1
]
+
"
"
+
employees
[
i
][
2
])
for
i
in
range
(
len
(
employees
))])
employe
=
st
.
selectbox
(
"
Employé
"
,
options
=
liste_employes
,
index
=
None
,
placeholder
=
"
Choisir un employé
"
)
if
employe
is
None
:
st
.
write
(
""
)
else
:
if
employees
[
int
(
employe
.
split
(
"
-
"
)[
0
])
-
1
][
3
]
==
1
:
cursor
.
execute
(
"
SELECT DATE_LUNDI, NB_HEURES FROM SALAIRE_SEMAINE WHERE NUMERO_EMPLOYE = ?
"
,
(
int
(
employe
.
split
(
"
-
"
)[
0
]),))
df
=
pd
.
DataFrame
(
cursor
.
fetchall
(),
columns
=
[
desc
[
0
]
for
desc
in
cursor
.
description
])
st
.
write
(
"
Nombre d
'
heures travaillées par semaine pour l
'
employé sélectionné
"
)
st
.
dataframe
(
df
)
import
matplotlib.pyplot
as
plt
# Filter the last 10 weeks
df
[
'
DATE_LUNDI
'
]
=
pd
.
to_datetime
(
df
[
'
DATE_LUNDI
'
])
last_10_weeks
=
df
.
sort_values
(
by
=
'
DATE_LUNDI
'
).
tail
(
10
)
with
tab3
:
# Calculate the average hours per week
average_hours
=
last_10_weeks
[
'
NB_HEURES
'
].
mean
()
# Plot the data
fig
,
ax
=
plt
.
subplots
()
ax
.
plot
(
last_10_weeks
[
'
DATE_LUNDI
'
],
last_10_weeks
[
'
NB_HEURES
'
],
marker
=
'
.
'
,
linestyle
=
'
-
'
,
linewidth
=
0.1
,
label
=
'
Nombre d
\'
heures travaillées
'
,
color
=
'
blue
'
)
ax
.
axhline
(
y
=
average_hours
,
color
=
'
red
'
,
linestyle
=
'
--
'
,
linewidth
=
0.5
,
label
=
f
'
Moyenne (
{
average_hours
:
.
2
f
}
)
'
)
ax
.
set_xlabel
(
'
Date
'
,
fontsize
=
4
)
ax
.
set_ylabel
(
'
Nombre d
\'
heures
'
,
fontsize
=
4
)
ax
.
set_title
(
'
Nombre d
\'
heures travaillées par semaine (dernières 10 semaines)
'
,
fontsize
=
4
)
ax
.
tick_params
(
axis
=
'
both
'
,
which
=
'
major
'
,
labelsize
=
3
,
rotation
=
45
)
fig
.
set_size_inches
(
3
,
2
)
ax
.
legend
(
fontsize
=
4
)
# Display the plot in Streamlit
st
.
pyplot
(
fig
)
else
:
cursor
.
execute
(
"
SELECT DATE_LUNDI, NB_PRODUCTION FROM SALAIRE_SEMAINE WHERE NUMERO_EMPLOYE = ?
"
,
(
int
(
employe
.
split
(
"
-
"
)[
0
]),))
df
=
pd
.
DataFrame
(
cursor
.
fetchall
(),
columns
=
[
desc
[
0
]
for
desc
in
cursor
.
description
])
st
.
write
(
"
Nombre de production par semaine pour l
'
employé sélectionné (question 4)
"
)
st
.
dataframe
(
df
)
with
tab4
:
# Fonction pour générer les lundis
def
generate_mondays
(
start_date
):
"""
Génère une liste de lundis à partir d
'
une date donnée jusqu
'
à un an après.
:param start_date: Date de début au format
'
YYYY-MM-DD
'
:return: Liste de lundis au format
'
YYYY-MM-DD
'
"""
start
=
datetime
.
strptime
(
start_date
,
'
%Y-%m-%d
'
)
end_date
=
start
+
timedelta
(
days
=
365
)
# Ajuster au premier lundi
if
start
.
weekday
()
!=
0
:
start
+=
timedelta
(
days
=
(
7
-
start
.
weekday
()))
mondays
=
[]
current_date
=
start
while
current_date
<=
end_date
:
mondays
.
append
(
current_date
.
strftime
(
'
%Y-%m-%d
'
))
current_date
+=
timedelta
(
weeks
=
1
)
return
mondays
# Connexion à la base de données
conn
=
sqlite3
.
connect
(
'
donnees\company.db
'
)
cursor
=
conn
.
cursor
()
# Génération des lundis
mondays
=
generate_mondays
(
datetime
.
now
().
strftime
(
'
%Y-%m-%d
'
))
# Exemple d'opérations avec les employés
chrismas_day
=
datetime
(
2024
,
12
,
25
)
cursor
.
execute
(
"
SELECT NUMERO_EMPLOYE, NOM, PRENOM, CS_PRODUCTION, CS_JOURNEE, DATE_DEBUT FROM EMPLOYE
"
)
employees
=
cursor
.
fetchall
()
prime_totale
=
[]
prime_partielle
=
[]
Bonus
=
[]
for
employee
in
employees
:
NUMERO_EMPLOYE
,
NOM
,
PRENOM
,
CS_PRODUCTION
,
CS_JOURNEE
,
DATE_DEBUT
=
employee
start_date
=
datetime
.
strptime
(
DATE_DEBUT
,
'
%Y-%m-%d
'
)
for
LUNDI
in
mondays
:
lundi
=
datetime
.
strptime
(
LUNDI
,
'
%Y-%m-%d
'
)
delta
=
lundi
-
start_date
delta_days
=
delta
.
days
delta_noel
=
lundi
-
chrismas_day
delta_noel_days
=
delta_noel
.
days
prime_partielle
=
0
prime_totale
=
0
prime_anniversaire
=
0
if
0
<=
delta_noel_days
%
365
<=
6
:
if
delta
.
days
>=
365
:
if
CS_JOURNEE
is
not
None
:
cursor
.
execute
(
f
"
SELECT SALAIRE_SEMAINE_BASE FROM GRILLE_SALAIRE_HORAIRE WHERE CS_HORAIRE =
{
CS_JOURNEE
}
"
)
salaire_base
=
cursor
.
fetchone
()[
0
]
prime_totale
=
salaire_base
*
4.5
if
CS_PRODUCTION
is
not
None
:
cursor
.
execute
(
f
"
SELECT SALAIRE_SEMAINE_BASE FROM GRILLE_SALAIRE_PROD WHERE CS_PRODUCTION =
{
CS_PRODUCTION
}
"
)
salaire_base
=
cursor
.
fetchone
()[
0
]
prime_totale
=
salaire_base
*
4.5
else
:
if
CS_JOURNEE
is
not
None
:
cursor
.
execute
(
f
"
SELECT SALAIRE_SEMAINE_BASE FROM GRILLE_SALAIRE_HORAIRE WHERE CS_HORAIRE =
{
CS_JOURNEE
}
"
)
salaire_base
=
cursor
.
fetchone
()[
0
]
prime_partielle
=
max
(
0
,
salaire_base
*
delta
.
days
/
365
)
if
CS_PRODUCTION
is
not
None
:
cursor
.
execute
(
f
"
SELECT SALAIRE_SEMAINE_BASE FROM GRILLE_SALAIRE_PROD WHERE CS_PRODUCTION =
{
CS_PRODUCTION
}
"
)
salaire_base
=
cursor
.
fetchone
()[
0
]
prime_partielle
=
max
(
0
,
salaire_base
*
100
*
delta
.
days
/
365
)
if
0
<=
abs
(
delta_days
%
365
)
<=
6
:
if
CS_JOURNEE
is
not
None
:
cursor
.
execute
(
f
"
SELECT SALAIRE_SEMAINE_BASE FROM GRILLE_SALAIRE_HORAIRE WHERE CS_HORAIRE =
{
CS_JOURNEE
}
"
)
salaire_base
=
cursor
.
fetchone
()[
0
]
prime_anniversaire
=
salaire_base
if
CS_PRODUCTION
is
not
None
:
cursor
.
execute
(
f
"
SELECT SALAIRE_SEMAINE_BASE FROM GRILLE_SALAIRE_PROD WHERE CS_PRODUCTION =
{
CS_PRODUCTION
}
"
)
salaire_base
=
cursor
.
fetchone
()[
0
]
prime_anniversaire
=
salaire_base
Bonus
.
append
((
NUMERO_EMPLOYE
,
NOM
,
PRENOM
,
DATE_DEBUT
,
LUNDI
,
prime_totale
,
prime_partielle
,
prime_anniversaire
,
prime_partielle
+
prime_totale
+
prime_anniversaire
))
Bonus
=
pd
.
DataFrame
(
Bonus
,
columns
=
[
'
NUMERO_EMPLOYE
'
,
'
NOM
'
,
'
PRENOM
'
,
'
DATE_DEBUT
'
,
'
LUNDI
'
,
'
PRIME_NOEL
'
,
'
PRIME_NOEL_PARTIELLES
'
,
'
PRIME_ANNIVERSAIRE
'
,
'
PRIMES
'
])
Bonus
=
Bonus
[[
'
LUNDI
'
,
'
NUMERO_EMPLOYE
'
,
'
NOM
'
,
'
PRENOM
'
,
'
DATE_DEBUT
'
,
'
PRIME_NOEL
'
,
'
PRIME_NOEL_PARTIELLES
'
,
'
PRIME_ANNIVERSAIRE
'
,
'
PRIMES
'
]]
Bonus
.
columns
=
[
'
Lundi
'
,
'
Numéro employé
'
,
'
Nom
'
,
'
Prénom
'
,
'
Date de début
'
,
'
Prime Noël
'
,
'
Prime Noël partielles
'
,
'
Prime anniversaire
'
,
'
Primes
'
]
Bonus
[
Bonus
[
'
Primes
'
]
>
0
].
head
(
50
)
st
.
header
(
"
Primes de Noël et d
'
anniversaire pour les employés pour l
'
an à venir
"
)
options
=
[
"
Primes d
'
anniversaire
"
,
"
Primes de Noël complètes
"
,
"
Primes de Noël partielles
"
]
selections
=
{
option
:
st
.
checkbox
(
option
)
for
option
in
options
}
if
selections
[
"
Primes de Noël partielles
"
]:
st
.
write
(
"
Primes de Noël partielles (question 6)
"
)
st
.
dataframe
(
Bonus
[
Bonus
[
'
Prime Noël partielles
'
]
>
0
][[
"
Lundi
"
,
"
Numéro employé
"
,
"
Nom
"
,
"
Prénom
"
,
"
Date de début
"
,
"
Prime Noël partielles
"
]])
if
selections
[
"
Primes de Noël complètes
"
]:
st
.
write
(
"
Primes de Noël complètes (question 5/7)
"
)
st
.
dataframe
(
Bonus
[
Bonus
[
'
Prime Noël
'
]
>
0
][[
"
Lundi
"
,
"
Numéro employé
"
,
"
Nom
"
,
"
Prénom
"
,
"
Date de début
"
,
"
Prime Noël
"
]])
if
selections
[
"
Primes d
'
anniversaire
"
]:
st
.
write
(
"
Primes d
'
anniversaire (question 5)
"
)
st
.
dataframe
(
Bonus
[
Bonus
[
'
Prime anniversaire
'
]
>
0
][[
"
Lundi
"
,
"
Numéro employé
"
,
"
Nom
"
,
"
Prénom
"
,
"
Date de début
"
,
"
Prime anniversaire
"
]])
with
tab5
:
st
.
header
(
"
Création de compte employé
"
)
conn
=
sqlite3
.
connect
(
r
'
C:\Users\neiro\Documents\+\GitHub\sgbd-usine\
donnees\company.db
'
)
conn
=
sqlite3
.
connect
(
r
'
donnees\company.db
'
)
cursor
=
conn
.
cursor
()
cursor
.
execute
(
"
SELECT MAX(NUMERO_EMPLOYE) FROM EMPLOYE
"
)
max_numero_employe
=
cursor
.
fetchone
()[
0
]
...
...
@@ -92,7 +235,7 @@ with tab3:
# Submit button
if
st
.
button
(
"
Create Account
"
):
# Connect to the database
conn
=
sqlite3
.
connect
(
r
'
C:\Users\neiro\Documents\+\GitHub\sgbd-usine\
donnees\company.db
'
)
conn
=
sqlite3
.
connect
(
r
'
donnees\company.db
'
)
cursor
=
conn
.
cursor
()
cursor
.
execute
(
"""
SELECT NUMERO_EMPLOYE FROM EMPLOYE
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment