diff --git a/dashboard/data/data_loader.py b/dashboard/data/data_loader.py index 8fa7fc3af..a7e932543 100644 --- a/dashboard/data/data_loader.py +++ b/dashboard/data/data_loader.py @@ -10,10 +10,11 @@ API_PATH = os.getenv("CODECARBON_API_URL") if API_PATH is None: - # API_PATH = "http://carbonserver.cleverapps.io" - API_PATH = "https://api.codecarbon.io" -# API_PATH = "http://localhost:8008" # export CODECARBON_API_URL=http://localhost:8008 -# API_PATH = "http://carbonserver.cleverapps.io" + #API_PATH = "http://carbonserver.cleverapps.io" + #API_PATH = "https://api.codecarbon.io" + API_PATH = "http://localhost:8008" + #export CODECARBON_API_URL=http://localhost:8008 + #API_PATH = "http://carbonserver.cleverapps.io" USER = "jessica" PSSD = "fake-super-secret-token" diff --git a/dashboard/layout/callbacks.py b/dashboard/layout/callbacks.py index fe6994b2a..536068827 100644 --- a/dashboard/layout/callbacks.py +++ b/dashboard/layout/callbacks.py @@ -2,7 +2,7 @@ import pandas as pd import plotly.express as px import plotly.graph_objects as go -from dash.dependencies import Input, Output +from dash.dependencies import Input, Output ,State from data.data_functions import ( get_experiment, get_experiment_runs, @@ -22,12 +22,14 @@ from layout.template import darkgreen, vividgreen from plotly.subplots import make_subplots -from dash import Input, Output +from dash import Input, Output,State , no_update +from dash.exceptions import PreventUpdate import json import os import requests +import time API_PATH = os.getenv("CODECARBON_API_URL") @@ -43,75 +45,138 @@ # ************************************************************************ # ************************************************************************ +# @app.callback( +# Output('body-div', 'children'), +# #Output('err','children'), +# Input('show-secret', 'n_clicks'), + +# State('input_organame','value'), +# State('input_orgadesc','value'), +# #prevent_initial_call=True, +# running=[(Output("show-secret", "disabled"), True, False)] +# ) +# def update_output(n_clicks,input_organame,input_orgadesc): +# try: +# #time.sleep(5) +# if n_clicks is None: +# raise PreventUpdate +# if not input_organame and not input_orgadesc: +# return [""] +# else: +# print(input_organame) +# print(input_orgadesc) +# return [f'votre saisie est {input_organame} and {input_orgadesc} '] +# except Exception as e: +# return no_update, ''.format(e.args) + +# def checkText(input_organame): +# for char in input_organame: +# if not char.isalpha(): +# return False +# return True + @app.callback( - Output("output","children"), - Output(component_id="organame", component_property="children"), - Output(component_id="orgadesc", component_property="children"), + Output("Orgacard_to_hidden", "style"), + Output("Output_text","style"), + Output("Output_data","children"), + Output("Teamcard_to_hidden","style"), + [Input('submit_btn','n_clicks')], + [State("input_organame", "value"), + State("input_orgadesc", "value")], + +) +def toggle_card_visibility(n_clicks,input_organame,input_orgadesc): + try: + if n_clicks is None: + raise PreventUpdate + if not input_organame or not input_orgadesc: + return {"display":"block"},{"display":"none"}, [""] ,{"display":"none"} + else: + Output_data= save_organization(input_organame,input_orgadesc) + print(Output_data) + print(n_clicks) + print(input_organame) + print(input_orgadesc) + return {"display":"none"},{"display":"block"},[Output_data],{"display":"block"} + except Exception as e: + return {"display":"block"},{"display":"block"}, e.args,{"display":"none"} + +def save_organization(input_organame, input_orgadesc) -> str: + try: + path = f"{API_PATH}/organization" + print(path) + payload = {'name': input_organame , 'description' : input_orgadesc} + response = requests.post(path, json=payload) + message = "" + if response.status_code == 201: + return f'You have entered "{input_organame}" and "{input_orgadesc}" into the database' + else: + if response.status_code == 405: + return f'You have entered "{response.status_code}" and reason : "{response.reason}" ' + else: + return f'You have entered error : "{response.status_code}" and reason : "{response.reason}" for path {path} and payload {payload}' + except: + return f'none' - Input("input_organame", "value"), +####################### - Input("input_orgadesc", "value"), +# Refresh organizations list +# @app.callback( +# [ +# Output(component_id="dropdown-div", component_property="options"), +# Output(component_id="dropdown-div", component_property="value"), +# ], +# [Input("url-location", "pathname")], +# ) +# def refresh_org_list(url): +# df_org = get_organization_list() +# org_id = df_org.id.unique().tolist()[1] +# options = [ +# {"label": orgName, "value": orgId} +# for orgName, orgId in zip(df_org.name, df_org.id) +# ] +# return options, org_id - Input('submit_btn','n_clicks'), - -) -def on_button_click(input_organame,input_orgadesc,n_clicks): - try: - - if n_clicks: - path = f"{API_PATH}/organization" - print(path) - payload = {'name': input_organame , 'description' : input_orgadesc} - response = requests.post(path, json=payload) - - if response.status_code == 201: - return f'You have entered "{input_organame}" and "{input_orgadesc}" into the database.' - else: - if response.status_code == 405: - return f'You have entered "{response.status_code}" and reason : "{response.reason}" ' - else: - return f'You have entered error : "{response.status_code}" and reason : "{response.reason}" for path {path} and payload {payload}' - except: - return f'none' -#@app.callback( -## Output("output2","children"), -# Input("input_teamname", "value"), -# Input("input_teamdesc", "value"), -# Input(component_id="org-dropdown", component_property="value"), -# Input('submit_btn_team','n_clicks'), -#) -#def on_button_click(input_teamname,input_teamdesc,n_clicks): - #if n_clicks: - # return f'Input1 {input_teamname} and Input2 {input_teamdesc} and nb {n_clicks}' - +# def update_dropdown(n_clicks, value1, value2): +# if n_clicks > 0 and value1 and value2: +# # Charger les options à partir de la base de données +# options = get_options_from_database() +# # Retourner la liste déroulante avec les options chargées +# return dcc.Dropdown(id='dropdown', options=options, placeholder='Sélectionnez une option') +# else: +# return None -@app.callback( - [ - Output(component_id="teamPicked", component_property="options"), - # Output(component_id="projectPicked", component_property="value"), - ], - [ - Input(component_id="org-dropdown", component_property="value"), - ], -) -def update_team_from_organization(value): - orga_id = value - df_team = get_team_list(orga_id) - if len(df_team) > 0: - # project_id = df_project.id.unique().tolist()[0] - # project_name = df_project.name.unique().tolist()[0] - options = [ - {"label": teamName, "value": teamId} - for teamName, teamId in zip(df_team.name, df_team.id) - ] - else: - # project_id = None - # project_name = "No Project !!!" - options = [] - return [options] + + + +#@app.callback( +# [ +# Output(component_id="teamPicked", component_property="options"), +# # Output(component_id="projectPicked", component_property="value"), +# ], +# [ +# Input(component_id="org-dropdown", component_property="value"), +# ], +#) +#def update_team_from_organization(value): +# orga_id = value +# df_team = get_team_list(orga_id) +# if len(df_team) > 0: +# # project_id = df_project.id.unique().tolist()[0] + # project_name = df_project.name.unique().tolist()[0] + # options = [ + # {"label": teamName, "value": teamId} + # for teamName, teamId in zip(df_team.name, df_team.id) + # ] + # else: + # # project_id = None + # # project_name = "No Project !!!" + # options = [] + + # return [options] diff --git a/dashboard/layout/pages/admin.py b/dashboard/layout/pages/admin.py index ddd7dc825..1a013d8aa 100644 --- a/dashboard/layout/pages/admin.py +++ b/dashboard/layout/pages/admin.py @@ -4,11 +4,9 @@ from data.data_functions import get_organization_list, get_project_list, get_team_list - dash.register_page(__name__, path='/admin', name="Admin",order=1) - ##################### Get Data ########################### df_org = get_organization_list() @@ -37,38 +35,73 @@ def layout(): ), html.Br(), - dbc.Row( + dbc.Row( [ dbc.Col([ dbc.Card( + id="Orgacard_to_hidden", + children= [ - + dbc.CardHeader("Formulaire",style={"color":"#CDCDCD"}), dbc.CardBody( + children= [ html.H5( "Create an Organization :", style={"color":"white"} ), html.Hr(), - html.Div(id='output'), - dcc.Input(id="input_organame", type="text", placeholder="Name", debounce=True ), + dcc.Input(id="input_organame", type="text", placeholder="Name"), html.Br(), - dcc.Input(id="input_orgadesc", type="text", placeholder="Description" , debounce=True ), + dcc.Input(id="input_orgadesc", type="text", placeholder="Description" ), html.Br(), html.Br(), dbc.Button("submit", id="submit_btn", color="primary", n_clicks=0 ), ], - style={"height": "10%", "border-radius": "10px", "border":"solid" , "border-color":"#CDCDCD" + style={"height": "10%", "border-radius": "10px", "border":"solid" , "border-color":"#CDCDCD" }, - className="shadow" + className="shadow", + #value="on" + ) + + + + ],style={"display":"block"} #make the card visible starting + ), + dbc.Card( + id="Output_text", + children= + [ + dbc.CardHeader("Result",style={"color":"#CDCDCD"} ), + dbc.CardBody( + [ + + html.Div(id='Output_data'), + + ],style={"color":"#CDCDCD"} + ), + + + ],style={"display":"none","color":"#CDCDCD"} + ), + + - ] - ) ]), - dbc.Col([ + + + ] + + + + ), + html.Br(), + dbc.Col([ dbc.Card( + id="Teamcard_to_hidden", + children= [ dbc.CardBody( @@ -79,8 +112,9 @@ def layout(): ), dbc.Label("organization selected : ",width=10 ,style={"color": "white"}, ), + #dcc.Dropdown(id='dropdown-div'), dcc.Dropdown( - id="org-dropdown", + #id="dropdown-div", options=[ {"label": orgName, "value": orgId} for orgName, orgId in zip( @@ -94,7 +128,6 @@ def layout(): #html.Div(id='output2'), html.Br(), - dcc.Input(id="input_teamname", type="text", placeholder="Name", debounce=True ), html.Br(), dcc.Input(id="input_teamdesc", type="text", placeholder="Description" , debounce=True ), @@ -106,80 +139,27 @@ def layout(): }, className="shadow" ), - ] + ],style={"display":"none"} ) ]), - dbc.Col([ - dbc.Card( - [ - - dbc.CardBody( - [ - - html.H5( - "Create a project :", style={"color":"white"} - ), - dbc.Label("organization selected : ", width=10 , style={"color": "white"}), - dcc.Dropdown( - id="org-dropdown", - options=[ - {"label": orgName, "value": orgId} - for orgName, orgId in zip( - df_org.name, df_org.id - ) - ], - clearable=False, - value=orga_id, - # value=df_org.id.unique().tolist()[0], - # value="Select your organization", - style={"color": "black"}, - # clearable=False, - ), - dbc.Label("team selected : ", width=10 , style={"color": "white"} ), - dbc.RadioItems( - id="teamPicked", - options=[ - {"label": teamName, "value": teamId} - for teamName, teamId in zip( - df_team.name, df_team.id - ) - ], - value=df_team.id.unique().tolist()[-1] - if len(df_team) > 0 - else "No team in this organization !", - inline=True, - style={"color": "white"} - # label_checked_class_name="text-primary", - # input_checked_class_name="border border-primary bg-primary", - ), - dbc.Label("Project ", width=10, style={"color": "white"}), - #html.Div(id='output'), - dbc.Input(id="input_projectname", type="text", placeholder="Name", debounce=True ), - dbc.Input(id="input_projectdesc", type="text", placeholder="Description" , debounce=True ), - html.Br(), - - - dbc.Button("submit", id="submit_btn_project", color="primary", n_clicks=0), - ], - style={"height": "10%", "border-radius": "10px", "border":"solid" , "border-color":"#CDCDCD" - }, - className="shadow" - ), - ] - ) - - ]), - - - ] - - ), - + + + # html.Div([ + + # dcc.Input(id="input_organame", type="text", placeholder="Name"), + # html.Br(), + # dcc.Input(id="input_orgadesc", type="text", placeholder="Description"), + # dbc.Button("submit", id="show-secret", color="primary",n_clicks=0), + # #html.Div(id='err', style={'color':'red'}), + # html.Div(id='body-div', children='Enter a value and press submit') + + # ]) + @@ -188,4 +168,6 @@ def layout(): ), - \ No newline at end of file + + + diff --git a/dashboard/layout/pages/codecarbon.py b/dashboard/layout/pages/codecarbon.py index 1eeceff88..732181eac 100644 --- a/dashboard/layout/pages/codecarbon.py +++ b/dashboard/layout/pages/codecarbon.py @@ -8,7 +8,7 @@ from dashboard.layout.components import Components -dash.register_page(__name__, path='/codecarbon', name="Codecarbon", order=2 ) +dash.register_page(__name__, path='/codecarbon', name="Codecarbon", order=2) # Set configuration (prevent default plotly modebar to appears, disable zoom on figures, set a double click reset ~ not working that good IMO )