main.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. from typing import Optional
  2. import dash
  3. import dash_html_components as html
  4. import dash_core_components as dcc
  5. import os
  6. from dash.dependencies import Input, Output
  7. from functools import reduce
  8. # Load data
  9. from data import Data
  10. from tools import get_options, generate_figure
  11. logs_path = "../Logs"
  12. log_files = sorted([file for file in os.listdir(logs_path) if not '.' in file], reverse=True)
  13. d1 = Data(logs_path)
  14. d2 = Data(logs_path)
  15. # df = pd.read_csv('data/stockdata2.csv', index_col=0, parse_dates=True)
  16. # df.index = pd.to_datetime(df['Date'])
  17. # Initialize the app
  18. app = dash.Dash(__name__)
  19. app.config.suppress_callback_exceptions = True
  20. app.layout = html.Div(
  21. children=[
  22. html.Div(className='row',
  23. children=[
  24. html.Div(className='four columns div-user-controls',
  25. children=[
  26. html.H2('VR Cycling - Visualize Logs'),
  27. html.H3('Pick a log folder.'),
  28. html.Div(
  29. className='div-for-dropdown',
  30. children=[
  31. dcc.Dropdown(id='select-log', options=get_options(log_files),
  32. multi=False, value=None,
  33. style={'backgroundColor': '#1E1E1E'},
  34. )
  35. ],
  36. style={'color': '#F1F1F1'}),
  37. html.Div(
  38. className='div-for-dropdown-group',
  39. children=[
  40. html.H3('First plot:'),
  41. dcc.Dropdown(id='select-file-1',
  42. multi=False,
  43. style={'backgroundColor': '#1E1E1E'}
  44. ),
  45. html.H3('Pick one or more data items.'),
  46. dcc.Dropdown(id='select-data-1',
  47. multi=True,
  48. style={'backgroundColor': '#1E1E1E'}
  49. )
  50. ]
  51. ),
  52. html.Div(
  53. className='div-for-dropdown-group',
  54. children=[
  55. html.H3('Second plot:'),
  56. dcc.Dropdown(id='select-file-2',
  57. multi=False,
  58. style={'backgroundColor': '#1E1E1E'}
  59. ),
  60. html.H3('Pick one or more data items.'),
  61. dcc.Dropdown(id='select-data-2',
  62. multi=True,
  63. style={'backgroundColor': '#1E1E1E'}
  64. )
  65. ])
  66. ]
  67. ),
  68. html.Div(className='eight columns div-for-charts bg-grey',
  69. children=[
  70. dcc.Graph(id='data-plot-1', config={'displayModeBar': False}, animate=True),
  71. html.Div(style={'height': '12px'}),
  72. dcc.Graph(id='data-plot-2', config={'displayModeBar': False}, animate=True),
  73. #dcc.Interval(
  74. # id='interval-component',
  75. # interval=1 * 1000, # in milliseconds
  76. # n_intervals=0
  77. #)
  78. ])
  79. ])
  80. ]
  81. )
  82. @app.callback(Output('select-file-1', 'options'),
  83. [Input('select-log', 'value')])
  84. def update_file_options_1(selected_folder):
  85. files = d1.read_folder(selected_folder)
  86. return get_options(files)
  87. @app.callback(Output('select-file-2', 'options'),
  88. [Input('select-log', 'value')])
  89. def update_file_options_2(selected_folder):
  90. files = d2.read_folder(selected_folder)
  91. return get_options(files)
  92. @app.callback(Output('select-data-1', 'options'),
  93. [Input('select-file-1', 'value')])
  94. def update_file_selection_1(selected_file):
  95. d1.read_data(selected_file)
  96. return get_options(d1.get_columns())
  97. @app.callback(Output('select-data-2', 'options'),
  98. [Input('select-file-2', 'value')])
  99. def update_file_selection_2(selected_file):
  100. d2.read_data(selected_file)
  101. return get_options(d2.get_columns())
  102. @app.callback(Output('data-plot-1', 'figure'),
  103. [Input('select-data-1', 'value')])
  104. def update_plot_1(selected_data_columns):
  105. #print(f'Interval {n}')
  106. return generate_figure(selected_data_columns, d1.df,
  107. f'Log Data - {d1.current_folder_name} - {d1.current_file_name}')
  108. @app.callback(Output('data-plot-2', 'figure'), [Input('select-data-2', 'value')])
  109. def update_plot_1(selected_data_columns):
  110. return generate_figure(selected_data_columns, d2.df,
  111. f'Log Data - {d2.current_folder_name} - {d2.current_file_name}')
  112. if __name__ == '__main__':
  113. app.run_server(debug=True)