Skip to content

Commit

Permalink
Merge pull request #1 from nens/reinout-fixes
Browse files Browse the repository at this point in the history
Fixes (imports, formatting, etc)
  • Loading branch information
reinout authored Nov 4, 2024
2 parents d722234 + d152561 commit b9553ab
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 85 deletions.
24 changes: 24 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
indent_style = space
indent_size = 4
max_line_length = 88

[*.{toml,yaml,yml}]
indent_size = 2

[*.{json,geojson,jsonl,js,jsx,ts,tsx,css,less,scss,html,xml}]
indent_size = 2

[*.md]
max_line_length = off

[Makefile]
indent_style = tab

### Extra lines below are preserved ###
2 changes: 1 addition & 1 deletion .github/workflows/nens-meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11
python-version: 3.12
- uses: pre-commit/[email protected]

### Extra lines below are preserved ###
58 changes: 44 additions & 14 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,46 @@
__pycache__
localsecret.py
config/localsecret.py
# Pyc/pyo/backup files.
*.py[co]
*~
*.swp
*.pyc
.DS_Store

# Packages/buildout/pip/pipenv
*.egg
*.egg-info
sdist
pip-log.txt
bower_components/
node_modules/
doc/build/
ansible/*.retry
.venv
venv
bin/
lib/
pyvenv.cfg
dist/
var/
*.suggestion

# Our generated files
for_step_summary.md

# Unit test / coverage reports
.coverage
.tox
htmlcov
.codeintel
coverage.*
.pytest_cache

# Pycharm, visual studio
.idea
.vscode

# Docker
docker-compose.override.yml

### Extra lines below are preserved ###
.streamlit/secrets.toml
secrets.toml
vevn
*.pyc
*.html
*.iml
*.xml
*.pbix
evn
.env
node_modules
.idea/workspace.xml
scripts/__pycache__/functions.cpython-38.pyc
5 changes: 5 additions & 0 deletions .nens.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[meta]
uses_python = true
uses_ansible = false
meta_version = "0.8.dev0"
project_name = "wim"
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ repos:
args: [--allow-multiple-documents]
- id: check-toml
- id: check-added-large-files

### Extra lines below are preserved ###
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.2
rev: v0.1.13
hooks:
# Run the linter.
- id: ruff
args: ["--fix"]
# Run the formatter.
- id: ruff-format

### Extra lines below are preserved ###
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.11
FROM python:3.12

WORKDIR /app

Expand Down
1 change: 0 additions & 1 deletion SETTINGS.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# SETTINGS
TITLE = ""
LOGO_PATH = "./images/wim_logo.png"
Expand Down
4 changes: 0 additions & 4 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ credentials:
email: [email protected]
name: Joost
password: Joost # To be replaced with hashed password
evert:
email: [email protected]
name: Evert
password: Evert # To be replaced with hashed password
eefje:
email: [email protected]
name: Eefje
Expand Down
7 changes: 4 additions & 3 deletions functions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import re
import os
import pandas as pd
import pickle
import re

import pandas as pd
import plotly.graph_objects as go


Expand Down Expand Up @@ -143,7 +144,7 @@ def create_week_planning_team(week_number, employees_list):
.any()
)

if filled_in == True:
if filled_in:
good_employees += [employee]
if planning_employee_cw["druk"][0] == "Heel Rustig":
color = "#9c27b0"
Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[tool.ruff]
target-version = "py312"

[tool.ruff.lint]
select = ["E4", "E7", "E9", "F", "I", "UP"]

[tool.zest-releaser]
release = false
74 changes: 38 additions & 36 deletions scripts/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,42 +240,44 @@ def create_custom_box(title, text, icon, background_color="#f0f0f0"):
)


def display_expander_content(locs, df, expander_index, var):
expander_key = f"expander_{expander_index}"
if expander_key not in st.session_state:
st.session_state[expander_key] = False

expander = st.expander(
f"Meetlocatie {expander_index}", expanded=st.session_state[expander_key]
)

with expander:
if st.session_state[expander_key] is False:
st.session_state[expander_key] = True

if st.session_state[expander_key]:
selected_location_name = st.selectbox(
f"Selecteer de meetlocatie {expander_index}", locs["name"]
)

selected_location_code = locs.loc[
locs["name"] == selected_location_name, "code"
].iloc[0]

if var == "groundwater":
plot_timeseries_with_percentiles(
df,
selected_location_code,
title=selected_location_name,
ylabel="Grondwaterniveau (mNAP)",
)
else:
plot_timeseries_with_phases(
df,
selected_location_code,
title=selected_location_name,
ylabel="Afvoer debiet m3/s",
)
# Commented out by Reinout, seems not to be in use ("undefined plot_timeseries_with_percentiles")?
#
# def display_expander_content(locs, df, expander_index, var):
# expander_key = f"expander_{expander_index}"
# if expander_key not in st.session_state:
# st.session_state[expander_key] = False

# expander = st.expander(
# f"Meetlocatie {expander_index}", expanded=st.session_state[expander_key]
# )

# with expander:
# if st.session_state[expander_key] is False:
# st.session_state[expander_key] = True

# if st.session_state[expander_key]:
# selected_location_name = st.selectbox(
# f"Selecteer de meetlocatie {expander_index}", locs["name"]
# )

# selected_location_code = locs.loc[
# locs["name"] == selected_location_name, "code"
# ].iloc[0]

# if var == "groundwater":
# plot_timeseries_with_percentiles(
# df,
# selected_location_code,
# title=selected_location_name,
# ylabel="Grondwaterniveau (mNAP)",
# )
# else:
# plot_timeseries_with_phases(
# df,
# selected_location_code,
# title=selected_location_name,
# ylabel="Afvoer debiet m3/s",
# )


def hover_popup(bold_text, icon_html, popup_text):
Expand Down
28 changes: 15 additions & 13 deletions utils2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import streamlit as st
import base64

import streamlit as st
from streamlit.components.v1 import html
from SETTINGS import *

from SETTINGS import LOGO_PATH, NAV_BOOL, NAVBAR_PATHS, SETTINGS, TITLE


def inject_custom_css():
Expand All @@ -17,7 +19,7 @@ def get_current_route():
st.query_params.nav = "invullen"
return nav_param

except:
except: # noqa: E722
if "nav" not in st.query_params.to_dict():
st.query_params.nav = "invullen"

Expand All @@ -28,7 +30,7 @@ def navbar_authenticated(name, title=TITLE, logo_path=LOGO_PATH, nav_bool=NAV_BO

current_route = get_current_route()

if nav_bool == True:
if nav_bool:
navbar_items = ""
for key, value in NAVBAR_PATHS.items():
if value == current_route:
Expand Down Expand Up @@ -64,15 +66,15 @@ def navbar_authenticated(name, title=TITLE, logo_path=LOGO_PATH, nav_bool=NAV_BO
"""
<style>
.appview-container .main .block-container {{
padding-top: {padding_top}rem;
padding-bottom: {padding_bottom}rem;
padding-top: 0rem;
padding-bottom: 0rem;
}}
st.markdown(
}}
unsafe_allow_html=True,
)
</style>""".format(padding_top=0, padding_bottom=0),
</style>""",
unsafe_allow_html=True,
)
st.markdown(component, unsafe_allow_html=True)
Expand Down Expand Up @@ -117,15 +119,15 @@ def navbar_authenticated(name, title=TITLE, logo_path=LOGO_PATH, nav_bool=NAV_BO
"""
<style>
.appview-container .main .block-container {{
padding-top: {padding_top}rem;
padding-bottom: {padding_bottom}rem;
padding-top: 0rem;
padding-bottom: 0rem;
}}
st.markdown(
}}
unsafe_allow_html=True,
)
</style>""".format(padding_top=0, padding_bottom=0),
</style>""",
unsafe_allow_html=True,
)
st.markdown(component, unsafe_allow_html=True)
Expand Down Expand Up @@ -168,11 +170,11 @@ def navbar_unauthenticated(title=TITLE, logo_path=LOGO_PATH):
"""
<style>
.appview-container .main .block-container {{
padding-top: {padding_top}rem;
padding-bottom: {padding_bottom}rem;
padding-top: 0rem;
padding-bottom: 0rem;
}}
</style>""".format(padding_top=0, padding_bottom=0),
</style>""",
unsafe_allow_html=True,
)
st.markdown(component, unsafe_allow_html=True)
23 changes: 14 additions & 9 deletions wim.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import random
from datetime import datetime, timedelta

import streamlit as st
import streamlit_authenticator as stauth
from streamlit_date_picker import date_range_picker, PickerType
import utils2 as utl
import yaml
from PIL import Image
from streamlit_date_picker import PickerType, date_range_picker
from yaml.loader import SafeLoader
from datetime import datetime, timedelta
import datetime
import random
from functions import *

from PIL import Image
import utils2 as utl
from functions import (
create_overview_graph,
create_week_planning_team,
extract_weeks,
update_user_csv,
)

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

Expand Down Expand Up @@ -235,9 +240,9 @@

if authentication_status:
utl.navbar_authenticated(name)
elif authentication_status == False:
elif authentication_status is False:
utl.navbar_unauthenticated()
st.error("Username/password is incorrect")
elif authentication_status == None:
elif authentication_status is None:
utl.navbar_unauthenticated()
st.warning("Please enter your username and password")

0 comments on commit b9553ab

Please sign in to comment.