Source code for GUI.GUI_functions

import json
import os
import pandas
import streamlit

import plotly.express as px


[docs] def import_GUI_input_values_json() -> dict: """ Function to import GUI settings from an existing json file and save it as a dict. :param json_file_path: file name to the underlying json with \ input values for all GUI pages :type json_file_path: str :return: **GUI_settings_cache_dict_reload** (dict) - exported \ dict from json file including a (sub)dict for every GUI page """ # Import json file including several (sub)dicts for every GUI page # Each (sub)dict includes input values as a cache from the last session json_file_path = os.path.dirname(os.path.abspath(__file__)) + "/cache.json" with open(json_file_path, "r", encoding="utf-8") as infile: GUI_settings_cache_dict_reload = json.load(infile) for row in GUI_settings_cache_dict_reload: if GUI_settings_cache_dict_reload[row] == "None": GUI_settings_cache_dict_reload[row] = None return GUI_settings_cache_dict_reload
[docs] def short_result_interactive_dia(result_path_results: str, session_state_name: str, title: str) -> None: """ Function to create interactive results. :param result_path_results: path to a result results.csv file :type result_path_results: str :param session_state_name: string of the streamlit session \ state in which the interactive results diagram whill be \ stored :type session_state_name: str :param title: title of the diagram created within this method :type title: str """ # Header streamlit.subheader(title) # loading result.csv as a dataframe result_df = pandas.read_csv(result_path_results) # creating column headers to select column_headers_result = list(result_df.columns.values) # column headers without date list_headers = column_headers_result[1:] # selecting headers select_headers = streamlit.multiselect("Select a bus:", list_headers) # filtered dataframe filtered_df = result_df[select_headers] # plotting fig = px.line(filtered_df).update_layout( xaxis_title="timestep (hour)", yaxis_title="voltage (V) / current (A)") streamlit.session_state[session_state_name] = fig