Skip to content

Commit

Permalink
fix pre-commit failures
Browse files Browse the repository at this point in the history
  • Loading branch information
kizjemarif committed Dec 24, 2024
1 parent 71e5d02 commit 99dc562
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 109 deletions.
6 changes: 3 additions & 3 deletions SETTINGS.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
NAVBAR_PATHS = {"Pagina 1": "page1", "Pagina 2": "page2"}

SETTINGS = {
'Invullen': 'invullen',
'Overzicht': 'overzicht',
"Uitloggen": "uitloggen"
"Invullen": "invullen",
"Overzicht": "overzicht",
"Uitloggen": "uitloggen",
} # This are the options for in the dropdown menu on the riht of the navbar
62 changes: 11 additions & 51 deletions functions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import os
import pickle
import re
from datetime import datetime, timedelta

import pandas as pd
import plotly.graph_objects as go
import streamlit as st
from datetime import datetime, timedelta


def update_user_csv(username, week_numbers, selected_category, notes):
# Define the file path based on the username
Expand Down Expand Up @@ -47,7 +49,6 @@ def update_user_csv(username, week_numbers, selected_category, notes):

# Save the updated DataFrame back to the CSV file


df.to_csv(csv_file, index=False)


Expand Down Expand Up @@ -132,9 +133,11 @@ def read_user_data(username):

# checks all employees files based on list of employees and creates for selected week overview of work pressure of each employee
# if employee didn't fill form for selected week, it will be listed as bad_employee and shamed in dashboard
@st.cache_data(ttl=300, show_spinner="Je zorgen maken is de verkeerde kant op fantaseren")
@st.cache_data(
ttl=300, show_spinner="Je zorgen maken is de verkeerde kant op fantaseren"
)
def create_week_planning_team(week_number, employees_list):
#print(employees_list)
# print(employees_list)
df_current_week = pd.DataFrame(columns=["name", "druk", "note", "color"])
good_employees = []
bad_employees = []
Expand Down Expand Up @@ -180,52 +183,6 @@ def create_week_planning_team(week_number, employees_list):
return df_current_week, bad_employees


def create_week_planning_team(week_number, employees_list):
#print(employees_list)
df_current_week = pd.DataFrame(columns=["name", "druk", "note", "color"])
good_employees = []
bad_employees = []
for employee in employees_list:
# get planning of employee
planning_employee = read_user_data(employee)
planning_employee_cw = planning_employee.loc[
planning_employee["week"] == week_number
].reset_index()

# check if it is filled in
filled_in = (
planning_employee_cw["druk"]
.isin(["Afwezig", "Heel Rustig", "Rustig", "Goed", "Druk", "Heel druk"])
.any()
)

if filled_in:
good_employees += [employee]
if planning_employee_cw["druk"][0] == "Heel Rustig":
color = "#9c27b0"
elif planning_employee_cw["druk"][0] == "Rustig":
color = "#ec407a"
elif planning_employee_cw["druk"][0] == "Goed":
color = "#BDDB45"
elif planning_employee_cw["druk"][0] == "Druk":
color = "#fb8c00"
elif planning_employee_cw["druk"][0] == "Heel druk":
color = "#e53935"
else:
color = "#81d4fa"

employee_row = {
"name": employee.capitalize(),
"druk": planning_employee_cw["druk"][0],
"note": planning_employee_cw["note"][0],
"color": color,
}
df_current_week.loc[len(df_current_week)] = employee_row
else:
bad_employees += [employee]

return df_current_week, bad_employees

# makes plotly bar chart of employees work planning overview for selected week
def create_overview_graph(df__week, week_number, startday_week):
# Create Horizontal bar chart
Expand Down Expand Up @@ -263,10 +220,13 @@ def create_overview_graph(df__week, week_number, startday_week):
) # zorgt ervoor dat x-axis heeft juiste volgorde
return fig


def get_week_details(week_offset=0):
"""Returns the ISO week number, start date, and end date with an optional offset."""
today = datetime.now()
start_of_week = today - timedelta(days=today.weekday()) + timedelta(weeks=week_offset)
start_of_week = (
today - timedelta(days=today.weekday()) + timedelta(weeks=week_offset)
)
end_of_week = start_of_week + timedelta(days=4)
week_number = start_of_week.isocalendar().week
return week_number, start_of_week.date(), end_of_week.date()
5 changes: 2 additions & 3 deletions qoutes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 11 16:40:48 2024
Expand Down Expand Up @@ -40,5 +39,5 @@
"Het beginnen van de dingen dat was vaak toch het mooist – Griet Op de Beeck",
"Time you enjoy wasting, was not wasted – John Lennon",
"Als piraat bereik je meer dan wanneer je bij de marine gaat – Steve Jobs",
"The best way to predict the future is to invent it. – Alan Kay"
]
"The best way to predict the future is to invent it. – Alan Kay",
]
7 changes: 5 additions & 2 deletions scripts/create_hashed_.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import bcrypt
import yaml
from yaml.loader import SafeLoader


# Function to hash a password
def hash_password(password):
return bcrypt.hashpw(password.encode(), bcrypt.gensalt()).decode()


# Load YAML file
with open('./config.yaml') as file:
with open("./config.yaml") as file:
config = yaml.load(file, Loader=SafeLoader)

# Hash all passwords and update YAML structure
Expand All @@ -15,5 +18,5 @@ def hash_password(password):
user_data["password"] = hash_password(user_data["password"])

# Save the updated YAML file with hashed passwords
with open('./config.yaml', 'w') as file:
with open("./config.yaml", "w") as file:
yaml.dump(config, file)
1 change: 1 addition & 0 deletions utils2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def inject_custom_css():
with open("assets/styles.css") as f:
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)


def get_current_route():
try:
nav_param = st.query_params.nav
Expand Down
92 changes: 42 additions & 50 deletions wim.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
from datetime import datetime, timedelta
import random
from datetime import datetime, timedelta

import streamlit as st
import streamlit_authenticator as stauth
import yaml
from PIL import Image
#from streamlit_date_picker import PickerType, date_range_picker
from yaml.loader import SafeLoader

# from streamlit_date_picker import PickerType, date_range_picker
import utils2 as utl
from functions import (
create_overview_graph,
create_week_planning_team,
extract_weeks,
get_week_details,
update_user_csv,
get_week_details
)
from time import time
import time
from qoutes import list_bad_qoutes

im = Image.open("./images/wim_logo.png")

Expand All @@ -42,52 +39,49 @@
"""



st.markdown(streamlit_settings, unsafe_allow_html=True)
# Configuration settings
showWarningOnDirectExecution = False

st.cache_resource(show_spinner=False)


def read_yaml():
with open('./config.yaml') as file:
with open("./config.yaml") as file:
config = yaml.load(file, Loader=SafeLoader)
return config




# Retrieve current and next week details
current_week_number, current_week_start, current_week_end = get_week_details()
next_week_number, next_week_start, next_week_end = get_week_details(week_offset=1)

config = read_yaml()
authenticator = stauth.Authenticate(
config["credentials"],
config["cookie"]["name"],
config["cookie"]["key"]
config["credentials"], config["cookie"]["name"], config["cookie"]["key"]
)

name, authentication_status, username = authenticator.login(location="main")
#authentication_status = True
#name = 'kizje'
#username = "kizje"
# authentication_status = True
# name = 'kizje'
# username = "kizje"
if authentication_status:
utl.navbar_authenticated(name)
nav = (st.query_params.get("nav"))
nav = st.query_params.get("nav")
if nav == "invullen":
#qoutes
# qoute_random = random.choice(list_bad_qoutes)
# qoute, auteur = qoute_random.split("–")
# placeholder = st.empty()
# placeholder1 = st.empty()
# qoutes
# qoute_random = random.choice(list_bad_qoutes)
# qoute, auteur = qoute_random.split("–")
# placeholder = st.empty()
# placeholder1 = st.empty()
# Loop through each letter in the text
# for i in range(len(qoute) + 1):
# placeholder.header(qoute[:i]) # Update the container with the current substring
# time.sleep(0.03)
#st.header(qoute)
#for i in range(len(auteur) + 1):
# placeholder1.text(auteur[:i]) # Update the container with the current substring
# time.sleep(0.03)
# for i in range(len(qoute) + 1):
# placeholder.header(qoute[:i]) # Update the container with the current substring
# time.sleep(0.03)
# st.header(qoute)
# for i in range(len(auteur) + 1):
# placeholder1.text(auteur[:i]) # Update the container with the current substring
# time.sleep(0.03)
selected_weeks = []
current_week_selected = st.checkbox(
label=f"Deze week (Week {current_week_number}: {current_week_start} - {current_week_end})",
Expand Down Expand Up @@ -125,27 +119,24 @@ def read_yaml():
selected_category = selected_category[2:]
update_user_csv(username, selected_weeks, selected_category, notes)
st.write(
f'{username}, Bedankt voor het invullen, door de datum aan te passen kan je ook voor volgende week alvast je verwachte drukte invullen.')
st.write('Geniet van je week!')
st.write('')
st.write('')
st.markdown(''
''
''
''
''
'')
st.markdown('')
st.markdown('')
st.markdown('')

f"{username}, Bedankt voor het invullen, door de datum aan te passen kan je ook voor volgende week alvast je verwachte drukte invullen."
)
st.write("Geniet van je week!")
st.write("")
st.write("")
st.markdown("" "" "" "" "" "")
st.markdown("")
st.markdown("")
st.markdown("")

elif nav == "overzicht":
st.write("")
st.write("")
st.write("")

tab1, tab2 = st.tabs([":mantelpiece_clock: Deze week", ":calendar: Volgende week"])
tab1, tab2 = st.tabs(
[":mantelpiece_clock: Deze week", ":calendar: Volgende week"]
)

# alle namen
employees_list = [
Expand Down Expand Up @@ -178,7 +169,7 @@ def read_yaml():
current_week_number, employees_list
)
# print(current_week_planning)
default_start = today -timedelta(days=today.weekday())
default_start = today - timedelta(days=today.weekday())
graph_current_week = create_overview_graph(
current_week_planning, current_week_number, default_start
)
Expand Down Expand Up @@ -221,11 +212,13 @@ def read_yaml():

with tab2:
next_week_number = datetime.now().isocalendar()[1] + 1
start_day_next_week = default_start + timedelta(days=7)
start_day_next_week = default_start + timedelta(days=7)
next_week_planning, bad_employees = create_week_planning_team(
next_week_number, employees_list
)
graph_next_week = create_overview_graph(next_week_planning, next_week_number, start_day_next_week)
graph_next_week = create_overview_graph(
next_week_planning, next_week_number, start_day_next_week
)

# place graph or next week planning on right spot

Expand Down Expand Up @@ -274,4 +267,3 @@ def read_yaml():


utl.inject_custom_css()

0 comments on commit 99dc562

Please sign in to comment.