main.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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.Div(
  28. className='div-for-dropdown-group',
  29. children=[
  30. html.H3('First plot:'),
  31. dcc.Dropdown(id='select-file-1',
  32. multi=False,
  33. options=get_options(d1.read_folder()),
  34. style={'backgroundColor': '#1E1E1E'}
  35. ),
  36. html.H3('Pick one or more data items.'),
  37. dcc.Dropdown(id='select-data-1',
  38. multi=True,
  39. style={'backgroundColor': '#1E1E1E'}
  40. )
  41. ]
  42. ),
  43. html.Div(
  44. className='div-for-dropdown-group',
  45. children=[
  46. html.H3('Second plot:'),
  47. dcc.Dropdown(id='select-file-2',
  48. multi=False,
  49. options=get_options(d1.read_folder()),
  50. style={'backgroundColor': '#1E1E1E'}
  51. ),
  52. html.H3('Pick one or more data items.'),
  53. dcc.Dropdown(id='select-data-2',
  54. multi=True,
  55. style={'backgroundColor': '#1E1E1E'}
  56. )
  57. ])
  58. ]
  59. ),
  60. html.Div(className='eight columns div-for-charts bg-grey',
  61. children=[
  62. dcc.Graph(id='data-plot-1', config={'displayModeBar': False}, animate=True),
  63. html.Div(style={'height': '12px'}),
  64. dcc.Graph(id='data-plot-2', config={'displayModeBar': False}, animate=True),
  65. # dcc.Interval(
  66. # id='interval-component',
  67. # interval=1 * 1000, # in milliseconds
  68. # n_intervals=0
  69. # )
  70. ])
  71. ])
  72. ]
  73. )
  74. @app.callback(Output('select-data-1', 'options'),
  75. [Input('select-file-1', 'value')])
  76. def update_file_selection_1(selected_file):
  77. d1.read_data(selected_file)
  78. return get_options(d1.get_columns())
  79. @app.callback(Output('select-data-2', 'options'),
  80. [Input('select-file-2', 'value')])
  81. def update_file_selection_2(selected_file):
  82. d2.read_data(selected_file)
  83. return get_options(d2.get_columns())
  84. @app.callback(Output('data-plot-1', 'figure'),
  85. [Input('select-data-1', 'value')])
  86. def update_plot_1(selected_data_columns):
  87. # print(f'Interval {n}')
  88. return generate_figure(selected_data_columns, d1.df,
  89. f'Log Data - {d1.current_file_name}')
  90. @app.callback(Output('data-plot-2', 'figure'), [Input('select-data-2', 'value')])
  91. def update_plot_1(selected_data_columns):
  92. return generate_figure(selected_data_columns, d2.df,
  93. f'Log Data - {d2.current_file_name}')
  94. if __name__ == '__main__':
  95. app.run_server(debug=True)