-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main_dashboard.py
68 lines (59 loc) · 2.7 KB
/
Main_dashboard.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import pandas as pd
import os
import dash
import dash_bootstrap_components as dbc
from LayoutCallbacks import layout, callbacks, preprocess_data
#initialize the dash application
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.MINTY])
# Get the current directory of the script
current_directory = os.path.dirname(__file__)
# Define the relative file paths to the JSON files
INPUT_FILEPATH = os.path.join(current_directory, "data\Design_Space_Data_Input.json")
OUTPUT_FILEPATH = os.path.join(current_directory, "data\Design_Space_Data_Output.json")
#constant values/ Column names/file names/ Weights
STEPSIZE_Y: int = 1
STEPSIZE_X: int = 2
X_STEPS:list[int] = [0, STEPSIZE_X, STEPSIZE_X * 2, STEPSIZE_X * 3, STEPSIZE_X * 4]
COLUMNS_TO_NORMALIZE: list[str] = ['MSU', 'MPU', 'Vmax ', 'SF_v', 'SF_h', 'Max_def', 'Mean_def', 'Epoch', 'a_p']
CATEGORICAL_COLUMNS: list[str] = ['youngPen', 'manu_type', 'L_ManuP']
OTHER_COLUMNS: list[str] = ['domain_1', 'domain_2', 'domain_3']
INPUT_COLUMNS: list[str] = ['domain_1', 'domain_2', 'domain_3', 'youngPen', 'a_p','manu_type', 'L_ManuP']
Weights: dict = {}
Weights["Index"] = COLUMNS_TO_NORMALIZE
Weights["Cost"] = [0, 0, 1, 0, 0, 0, 0, 0, 0]
Weights["Manu"] = [0, 0, 0, 0.5, 0.5, 0, 0, 0, 0]
Weights["Eco"] = [0, 0, 0, 0, 0, 0, 0, 1, 0]
CME: list[str] = ["Cost", "Manu", "Eco"]
DF_WEIGHTS: pd.DataFrame = pd.DataFrame.from_dict(Weights, orient='columns')
def load_data(input_path:str , output_path: str):
"""
Load input and output data from json files and concatenate them
:param input_path: The file path to the input JSON file.
:param output_path: The file path to the output JSON file.
:return: A DataFrame containing concatenated data from both input and output JSON files.
"""
df1 = pd.read_json(input_path, lines=True)
df2 = pd.read_json(output_path, lines=True)
df1.reset_index(drop=True, inplace=True)
df2.loc[:, 'Epoch'] = df2['Epoch'].apply(lambda x: x[-1])
df2.reset_index(drop=True, inplace=True)
return pd.concat([df1, df2], axis=1)
def main():
""""
- Run load data
- Run preprocess data in LayoutCallbacks script
- Set the layout
- Run callback function
"""
df = load_data(INPUT_FILEPATH,OUTPUT_FILEPATH)
df_n, df_input, max_domain, min_domain = preprocess_data(df,INPUT_COLUMNS, COLUMNS_TO_NORMALIZE)
args = [df_n, df_input, max_domain, min_domain,STEPSIZE_Y, INPUT_COLUMNS, COLUMNS_TO_NORMALIZE, DF_WEIGHTS]
app.layout = layout(*args)
callbacks(app,*args, CME,X_STEPS,OTHER_COLUMNS,df,CATEGORICAL_COLUMNS)
if __name__ == "__main__":
"""
Run main function and the server
"""
main()
#server = app.server Used for heroku Comment out code below
app.run_server(debug=False)