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 ( 2fcba2...ff8ead )
by
unknown
01:03
created

app.data_analysis()   B

Complexity

Conditions 5

Size

Total Lines 39
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 32
dl 0
loc 39
rs 8.6453
c 0
b 0
f 0
cc 5
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
from os import listdir,system,path,remove
7
import dash_table_experiments as dt
8
import dash_core_components as dcc
9
from os.path import isfile, join
10
import shutil
11
import time
12
import core
13
import io
14
import plotly.graph_objs as go
15
import pandas as pd
16
import numpy as np
17
18
#try:
19
#    system("rm -r uploads")
20
#except:
21
#    pass
22
23
directory = './uploads'
24
25
if path.exists(directory):
26
    system("rm -r uploads")
27
#    remove(directory)
28
else:
29
    pass    
30
31
app = dash.Dash('')
32
33
#external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css', 'https://codepen.io/rmarren1/pen/eMQKBW.css']
34
#app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
35
36
colors = {
37
    'background': '#ECF0F1',
38
    'text': '#800000'
39
}
40
41
image_filename = 'Logo.png' # replace with your own image
42
encoded_image = base64.b64encode(open(image_filename, 'rb').read()).decode('ascii')
43
44
dash_resumable_upload.decorate_server(app.server, "uploads")
45
46
app.scripts.config.serve_locally = True  # Uploaded to npm, this can work online now too.
47
48
49
app.css.append_css({
50
    "external_url": "https://codepen.io/rmarren1/pen/eMQKBW.css"
51
})
52
53
app.layout = html.Div(style={'backgroundColor': colors['background']}, children=[
54
    html.H1(
55
        children='VoltCycle',
56
        style={
57
            'textAlign': 'center',
58
            'color': colors['text']
59
        }
60
    ),
61
62
    html.Div([
63
        html.Img(draggable=True, style={
64
                'height': '20%',
65
                'width': '20%'
66
            },  src='data:image/png;base64,{}'.format(encoded_image))
67
   ], style={'textAlign': 'center'}),
68
69
    html.H2(children='A Tool for Accelerating the Analysis of Cyclic Voltammetry Data', style={
70
        'textAlign': 'center',
71
        'color': colors['text']
72
    }),
73
    html.Br(),
74
    html.Div([
75
    html.Link(rel='stylesheet', href='https://codepen.io/rmarren1/pen/eMQKBW.css'),
76
    dash_resumable_upload.Upload(
77
        id='upload',
78
        maxFiles=1,
79
        maxFileSize=1024*1024*1000,  # 100 MB
80
        service="/upload_resumable",
81
        textLabel="Upload Files",
82
        startButton=False)
83
    ]),
84
    html.Div(id='output_uploaded_file'),
85
    html.Br(),
86
    html.H2(
87
        children='Select File to Analyze',
88
        style={
89
            'textAlign': 'center',
90
            'color': colors['text']
91
        }
92
    ),
93
    html.Div([
94
       dcc.Dropdown(id='files_dropdown')
95
       ],style={'width': '70%', 'height': '40', 'display': 'inline-block', 'textAlign': 'center'}
96
    ),
97
    html.Div([
98
        html.Br(),
99
        dcc.Graph(id='CV_graph'),
100
        ],style={
101
            'columnCount': 1,
102
            'width':'70%',
103
            'height': '80%',
104
            }
105
    ),
106
       
107
    
108
    html.Div([
109
        html.Br(),
110
        html.H2(
111
            children='Redox Properties',
112
            style={
113
                'color': colors['text']
114
            }
115
        ),
116
        dt.DataTable(
117
            rows=[{}],
118
            row_selectable=True,
119
            filterable=True,
120
            selected_row_indices=[],
121
            id='datatable_initial'
122
            ),
123
        html.Div(id='selected-indexes'),
124
125
        ],
126
        style={
127
            'width': '98%',
128
            #'height': '60px',
129
            #'lineHeight': '60px',
130
            'margin': '10px'
131
            },
132
        )
133
134
])
135
136
137
def parse_contents(value):
138
139
    if path.exists(directory):
140
        lines1 = base64.b64encode(open("uploads/%s" % (value), 'rb').read())
141
        lines2 = base64.b64decode(lines1).decode('utf-8').split('\n')
142
        dict_1, n_cycle = core.read_file_dash(lines2)
143
        #print(n_cycle)
144
        df = core.data_frame(dict_1, 1)
145
        return df
146
147
148
def data_analysis(df):
149
    results_dict = {}
150
151
    # df = main.data_frame(dict_1,1)
152
    x = df['Potential']
153
    y = df['Current']
154
    # Peaks are here [list]
155
    peak_index = core.peak_detection_fxn(y)
156
    # Split x,y to get baselines
157
    x1,x2 = core.split(x)
158
    y1,y2 = core.split(y)
159
    y_base1 = core.linear_background(x1,y1)
160
    y_base2 = core.linear_background(x2,y2)
161
    # Calculations based on baseline and peak
162
    values = core.peak_values(x,y)
163
    Et = values[0]
164
    Eb = values[2]
165
    dE = core.del_potential(x,y)
166
    half_E = min(Et,Eb) + core.half_wave_potential(x,y)
167
    ia = core.peak_heights(x,y)[0]
168
    ic = core.peak_heights(x,y)[1]
169
    ratio_i = core.peak_ratio(x,y)
170
    results_dict['Peak Current Ratio'] = ratio_i
171
    results_dict['Ipc (A)'] = ic
172
    results_dict['Ipa (A)'] = ia
173
    results_dict['Epc (V)'] = Eb
174
    results_dict['Epa (V)'] = Et
175
    results_dict['∆E (V)'] = dE
176
    results_dict['Redox Potential (V)'] = half_E
177
    if dE>0.3:
178
        results_dict['Reversible'] = 'No'
179
    else:
180
        results_dict['Reversible'] = 'Yes'
181
    
182
    if half_E>0 and  'Yes' in results_dict.values():
183
        results_dict['Type'] = 'Catholyte'
184
    elif 'Yes' in results_dict.values():
185
        results_dict['Type'] = 'Anolyte'
186
    return results_dict, x1, x2, y1, y2, y_base1, y_base2, peak_index
187
    #return results_dict
188
189
190
@app.callback(Output('output_uploaded_file', 'children'),
191
              [Input('upload', 'fileNames')])
192
def display_files(fileNames):
193
    if fileNames is not None:
194
        return html.Ul([html.Li(html.A(x), style={'textAlign': 'center'}) for x in fileNames])
195
    return html.Ul(html.Li("No Files Uploaded Yet!"), style={'textAlign': 'center'})
196
197
198
@app.callback(Output('files_dropdown', 'options'),
199
              [Input('upload','fileNames')])
200
def dropdown_files(fileNames):
201
    mypath='./uploads/'
202
    onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
203
    return [{'label': i, 'value': i} for i in onlyfiles]
204
205
206
@app.callback( #update charge datatable
207
    Output('datatable_initial', 'rows'),
208
    [Input('files_dropdown', 'value')])
209
def update_table1(value):
210
    
211
    df = parse_contents(value)
212
    #print(df.head())
213
    #final_dict = data_analysis(df)
214
    final_dict, x_1, x_2, y_1, y_2, ybase_1, ybase_2, peak_i = data_analysis(df)
215
    df1=pd.DataFrame.from_records([final_dict])
216
    return df1.to_dict('records')
217
218
219
@app.callback(
220
    Output('CV_graph', 'figure'),
221
    [Input('files_dropdown', 'value')])
222
def update_figure(value):
223
    df = parse_contents(value)
224
    final_dict, x_1, x_2, y_1, y_2, ybase_1, ybase_2, peak_i = data_analysis(df)
225
    
226
    trace1 = go.Scatter(
227
            x = df['Potential'],
228
            y = df['Current'],
229
            marker={
230
                'size': 15,
231
                'opacity': 0.5,
232
                'color' : '#F00000'
233
            })
234
    trace2 = go.Scatter(
235
            x = x_1,
236
            y = ybase_1,
237
            mode = 'lines',
238
            line = dict(
239
                color = ('rgb(0, 0, 256)'),
240
                width = 3,
241
                dash = 'dash')
242
            )
243
    trace3 = go.Scatter(
244
            x = x_2,
245
            y = ybase_2,
246
            mode = 'lines',
247
            line = dict(
248
                color = ('rgb(0, 0, 256)'),
249
                width = 3,
250
                dash = 'dash')
251
            )
252
    trace4 = go.Scatter(
253
            x = np.array(x_1[peak_i[1]]),
254
            y = np.array(y_1[peak_i[1]]),
255
            mode = 'markers',
256
            marker={
257
                'size': 35,
258
                'opacity': 0.5,
259
                'color' : '#000080'
260
            })
261
    trace5 = go.Scatter(
262
            x = np.array(x_2[peak_i[0]]),
263
            y = np.array(y_2[peak_i[0]]),
264
            mode = 'markers',
265
            marker={
266
                'size': 35,
267
                'opacity': 0.5,
268
                'color' : '#000080'
269
            })
270
    data = [trace1, trace2, trace3, trace4, trace5]
271
 
272
    return {
273
        'data': data,
274
        #'layout' : {'Dash'}
275
        'layout': go.Layout(
276
            xaxis={'title': 'Voltage (V)'},
277
            yaxis={'title': 'Current (A)'},
278
            margin={'l': 40, 'b': 40, 't': 10, 'r': 10},
279
        #    #legend={'x': 0, 'y': 1},
280
            showlegend = False,
281
            hovermode='closest',
282
        )
283
    }
284
285
286
287
#    return {
288
#        'data': [
289
#                {'x': [x1[peak_index[1]]], 'y': [x1[peak_index[1]]], 'type': 'point'},
290
#                #{'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
291
#            ],
292
#    }
293
294
295
if __name__ == '__main__':
296
    app.run_server(debug=True)
297