GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 0c3829...de7c60 )
by Keertana
02:25
created

dash_working.update_figure()   A

Complexity

Conditions 1

Size

Total Lines 20
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 1
nop 1
1
import dash_resumable_upload
2
import dash
3
import dash_html_components as html
4
from dash.dependencies import Input, Output
5
import base64
6
import dash_table_experiments as dt
7
import dash_core_components as dcc
8
from os.path import isfile, join
9
from os import listdir,system
10
import shutil
11
import time
12
import main
13
import io
14
import plotly.graph_objs as go
15
16
try:
17
    system("rm -r uploads")
18
except:
19
    pass
20
21
app = dash.Dash('')
22
23
dash_resumable_upload.decorate_server(app.server, "uploads")
24
25
app.scripts.config.serve_locally = True  # Uploaded to npm, this can work online now too.
26
27
28
app.css.append_css({
29
    "external_url": "https://codepen.io/rmarren1/pen/eMQKBW.css"
30
})
31
32
app.layout = html.Div([
33
    dash_resumable_upload.Upload(
34
        id='upload',
35
        maxFiles=1,
36
        maxFileSize=1024*1024*1000,  # 100 MB
37
        service="/upload_resumable",
38
        textLabel="Drag and Drop Here to upload!",
39
        startButton=False
40
    ),
41
    html.Div(id='output_uploaded_file'),
42
    html.Div([
43
       dcc.Dropdown(id='files_dropdown')
44
       ],style={'width': '20%', 'display': 'inline-block'}
45
    ),
46
    html.Div([
47
        html.Br(),
48
        dcc.Graph(id='CV_graph'),
49
        ],style={
50
            'columnCount': 1,
51
            'width':'70%',
52
            'height': '80%',
53
            }
54
    ),
55
       
56
57
    html.Div([
58
        html.H4('CV DataTable'),
59
        dt.DataTable(
60
            #rows=charge.to_dict('records'), #converts df to dict
61
            rows=[{}],
62
            #columns=sorted(charge.columns), #sorts columns
63
            row_selectable=True,
64
            filterable=True,
65
            selected_row_indices=[],
66
            id='datatable_initial'
67
            ),
68
        html.Div(id='selected-indexes'),
69
70
        ],
71
        style={
72
            'width': '98%',
73
            #'height': '60px',
74
            #'lineHeight': '60px',
75
            'margin': '10px'
76
            },
77
        )
78
79
])
80
81
82
    #encode = base64.b64encode(
83
    #    open("uploads/%s" % (x), 'rb').read()).decode('ascii')
84
    #return "data:image/jpg;base64,{}".format(encode)
85
86
87
@app.callback(Output('output_uploaded_file', 'children'),
88
              [Input('upload', 'fileNames')])
89
def display_files(fileNames):
90
    if fileNames is not None:
91
        #return html.Ul([html.Li(
92
         #   html.Img(height="50", width="100", src=get_img(x))) for x in fileNames])
93
        return html.Ul([html.Li(html.A(x)) for x in fileNames])
94
    return html.Ul(html.Li("No Files Uploaded Yet!"))
95
96
97 View Code Duplication
@app.callback(Output('files_dropdown', 'options'),
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
98
              [Input('upload','fileNames')])
99
def dropdown_files(fileNames):
100
#    time.sleep(5)
101
    mypath='./uploads/'
102
    onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
103
   #print(onlyfiles)
104
        #onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
105
    #options=[{'label': i, 'value': i} for i in onlyfiles]
106
    #print(options)
107
    #return {'options':options}
108
    return [{'label': i, 'value': i} for i in onlyfiles]
109
110
111
def parse_contents(value):
112
113
    lines1 = base64.b64encode(open("uploads/%s" % (value), 'rb').read())
114
    lines2 = base64.b64decode(lines1).decode('utf-8').split('\n')
115
    #lines2 = lines1.decode('utf-8')
116
    #lines = io.StringIO(lines2)
117
    dict_1, n_cycle = main.read_file(lines2)
118
    df = main.data_frame(dict_1, 1)
119
    return df
120
121
@app.callback( #update charge datatable
122
    Output('datatable_initial', 'rows'),
123
    [Input('files_dropdown', 'value')])
124
125
def update_table1(value):
126
    #for line in lines3:
127
    #    print(line)
128
    #print(type(lines3))
129
    df = parse_contents(value)
130
    print(df.head())
131
    #data = parse_contents(contents, filename, date)
132
    #charge, discharge = ccf.sep_char_dis(data)
133
    return df.to_dict('records')
134
135
@app.callback(
136
    Output('CV_graph', 'figure'),
137
    [Input('files_dropdown', 'value')])
138
def update_figure(value):
139
    df = parse_contents(value)
140
141
    return {
142
        'data': [go.Scatter(
143
            x = df['Potential'],
144
            y = df['Current'],
145
            marker={
146
                'size': 15,
147
                'opacity': 0.5,
148
                'color' : '#FF851B'
149
            }
150
        )],
151
        #'layout' : {'Dash'}
152
        'layout': go.Layout(
153
            xaxis={'title': 'Voltage (V)'},
154
            yaxis={'title': 'Current (A)'},
155
        #    #margin={'l': 40, 'b': 40, 't': 10, 'r': 10},
156
        #    #legend={'x': 0, 'y': 1},
157
        #    hovermode='closest'
158
        )
159
    }
160
161
162
if __name__ == '__main__':
163
    app.run_server(debug=True)
164