Skip to content
Snippets Groups Projects
Commit b40a0bdf authored by Bouchaira Neirouz's avatar Bouchaira Neirouz
Browse files

saves

parent 91d57eac
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id: tags:
``` python
import sqlite3
# Connect to the database
conn = sqlite3.connect('company.db')
# Create a cursor object
cursor = conn.cursor()
print("Connected to company.db")
```
%% Output
Connected to company.db
%% Cell type:code id: tags:
``` python
import pandas as pd
from datetime import datetime, timedelta
chrismas_day = datetime(2024, 12, 25)
cursor.execute("SELECT NUMERO_EMPLOYE, NOM, PRENOM, CS_PRODUCTION,CS_JOURNEE, DATE_DEBUT FROM EMPLOYE")
employees = cursor.fetchall()
# Create a list to store the data
prime_totale = []
prime_partielle=[]
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'
"""
# Convertir la date de départ en objet datetime
start = datetime.strptime(start_date, '%Y-%m-%d')
end_date = start + timedelta(days=365)
# Trouver le premier lundi (si la date donnée n'est pas un lundi)
if start.weekday() != 0: # Si ce n'est pas un lundi
start += timedelta(days=(7 - start.weekday())) # Aller au prochain lundi
# Générer les lundis
mondays = []
current_date = start
while current_date <= end_date:
mondays.append(current_date.strftime('%Y-%m-%d'))
current_date += timedelta(weeks=1) # Passer au lundi suivant
return mondays
mondays=generate_mondays('2024-12-04')
```
%% Cell type:code id: tags:
``` python
import sqlite3
import pandas as pd
from datetime import datetime, timedelta
# 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
# Utilisation de SQLite
try:
# Connexion à la base de données
conn = sqlite3.connect('company.db')
cursor = conn.cursor()
print("Connected to company.db")
# 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_noel=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_noel= 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_noel= 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_noel= 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_noel=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, (datetime.strptime(LUNDI, "%Y-%m-%d") - timedelta(days=7)), prime_noel+prime_anniversaire))
Bonus.append((NUMERO_EMPLOYE, NOM, PRENOM, DATE_DEBUT, (datetime.strptime(LUNDI, "%Y-%m-%d") - timedelta(days=7)), prime_noel,prime_anniversaire))
# Sauvegarde des lundis dans une table de la base
# cursor.executemany("INSERT OR IGNORE INTO LUNDIS (date_lundi) VALUES (?)", [(monday,) for monday in mondays])
# conn.commit()
# pri<nt("Mondays added to the database.")
except sqlite3.Error as e:
print(f"SQLite error: {e}")
```
%% Output
Connected to company.db
%% Cell type:code id: tags:
``` python
Bonus = pd.DataFrame(Bonus, columns=['NUMERO_EMPLOYE','NOM', 'PRENOM' ,'DATE_DEBUT', 'LUNDI','PRIMES'])
Bonus[Bonus['PRIMES']>0].head(50)
```
%% Output
NUMERO_EMPLOYE NOM PRENOM DATE_DEBUT LUNDI PRIMES
3 1 Dubois Michel 2020-11-13 2024-12-23 2160.00000
49 1 Dubois Michel 2020-11-13 2025-11-10 480.00000
55 2 Bouchaira Neirouz 2021-11-13 2024-12-23 2160.00000
101 2 Bouchaira Neirouz 2021-11-13 2025-11-10 480.00000
107 3 Caty Jeanne 2019-11-03 2024-12-23 3712.50000
151 3 Caty Jeanne 2019-11-03 2025-10-27 825.00000
159 5 Mourin Julie 2023-11-13 2024-12-23 2126.25000
205 5 Mourin Julie 2023-11-13 2025-11-10 472.50000
211 6 Bowers Matthew 2024-11-20 2024-12-23 52.60274
258 6 Bowers Matthew 2024-11-20 2025-11-17 480.00000
263 7 Jura Charlie 2022-11-28 2024-12-23 3712.50000
311 7 Jura Charlie 2022-11-28 2025-11-24 825.00000
%% Cell type:code id: tags:
``` python
datetime.now().strftime('%Y-%m-%d')
```
%% Output
'2024-12-07'
%% Cell type:code id: tags:
``` python
```
......
......@@ -3553,7 +3553,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
......@@ -3567,7 +3567,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.0"
}
},
"nbformat": 4,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment