Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.72 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. import plotly.graph_objs as go
  5. import pandas as pd
  6. import dash
  7. import dash_core_components as dcc
  8. import dash_html_components as html
  9. from dash.dependencies import Input, Output
  10. import os
  11. import numpy as np
  12.  
  13. temps=[]
  14.  
  15. for name in os.listdir():
  16.     if name.find('tempdatalog')!=-1:
  17.         temps.append(name)
  18.  
  19. #temps=sorted(temps)
  20. temps.sort()
  21. with open(temps[0]) as f:
  22.     header = f.readline()
  23.  
  24. dflist=[]
  25.  
  26. for name in temps:
  27.     dflist.append(pd.read_csv(name, sep = '\t', skiprows=4,
  28.                                 usecols=["Date", "Time", "RTD", "TC1", "TC2", "TC3", "TC4", "TC6", "TC7", "TC9", "TC10"],
  29.                                 dtype={"RDT": np.float64, "TC1": np.float64, "TC2": np.float64, "TC3": np.float64,"TC4": np.float64, "TC6": np.float64, "TC7": np.float64, "TC9": np.float64, "TC10": np.float64}))
  30.  
  31. for frame in dflist:
  32.     frame.set_index(pd.to_datetime(frame['Date']+' '+frame['Time'], format= '%m/%d/%Y %H:%M:%S'), inplace=True)
  33.     #frame.set_index(pd.to_datetime(frame['Date']+' '+frame['Time']), inplace=True)
  34.  
  35. for frame in dflist:
  36.     frame.drop(['Date','Time'], axis=1, inplace=True)
  37.  
  38. for frame in dflist:
  39.     frame.rename(columns={'RTD':'RTD', 'TC1':'1 st suction', 'TC2':'condenser air inlet', 'TC3':'Evap in',
  40.                         'TC4':'Evap out', 'TC6':'2 stage suction', 'TC7':'Liquid line', 'TC9':'2 stage sump', 'TC10':'HX'}, inplace=True)
  41. print(enumerate(dflist))
  42. for i, frame in enumerate(dflist):
  43.     print(dflist[i].info())
  44. print(len(dflist))
  45. print(len(temps))
  46. app = dash.Dash()
  47.  
  48. app.layout = html.Div([
  49.     html.Div([
  50.         html.Label(header)
  51.     ], style={'padding':'15','border':'2px black solid'}),
  52.  
  53.     html.Div([
  54.         dcc.Graph(id='feature-graphic')
  55.         ], style={'padding':'100','border':'2px blue solid','height':'800','float':'bottom'}),
  56.     html.Div([
  57.     dcc.Dropdown(
  58.         id = 'month',
  59.         options = [{'label': i, 'value': temps.index(i)} for i in temps],
  60.         value=0
  61.     )
  62.     ], style={'padding':'15','border':'2px red solid'})
  63.     ])
  64.  
  65.  
  66. @app.callback(
  67.     Output('feature-graphic', 'figure'),
  68.     [Input('month', 'value')])
  69. def update_graph(month):
  70.     print(dflist[month].index)
  71.     return {
  72.         'data' : [
  73.             go.Scatter(
  74.                 x=dflist[month].index,
  75.                 y=dflist[month][name],
  76.                 name=name,
  77.                 mode = 'lines'
  78.             ) for name in dflist[month].columns
  79.         ],
  80.         'layout': go.Layout(
  81.             xaxis={'title': 'Time', 'type':'date'},
  82.             yaxis={'title': 'Temperature'},
  83.             title=header,
  84.             hovermode='closest',
  85.         )
  86.     }
  87.  
  88. if __name__ == '__main__':
  89.     app.run_server()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement