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.
Test Failed
Push — master ( 69efa7...3bf7f5 )
by Sabiha
02:48 queued 11s
created

app.app   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 303
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 205
dl 0
loc 303
rs 10
c 0
b 0
f 0
wmc 12

6 Functions

Rating   Name   Duplication   Size   Complexity  
A dropdown_files() 0 6 1
A update_table1() 0 11 1
A parse_contents() 0 9 2
B data_analysis() 0 42 5
A display_files() 0 6 2
B update_figure() 0 63 1
1
"""This module consists of all the functions utilized
2
for the Dash user interface."""
3
4
import dash_resumable_upload
5
import dash
6
import dash_html_components as html
7
from dash.dependencies import Input, Output
8
import base64
9
from os import listdir,system,path,remove
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
Loading history...
10
import dash_table_experiments as dt
11
import dash_core_components as dcc
12
from os.path import isfile, join
13
import shutil
14
import time
15
import core
16
import io
17
import plotly.graph_objs as go
18
import pandas as pd
19
import numpy as np
20
21
#try:
22
#    system("rm -r uploads")
23
#except:
24
#    pass
25
26
directory = './uploads'
27
28
if path.exists(directory):
29
    system("rm -r uploads")
30
#    remove(directory)
31
else:
32
    pass
33
34
app = dash.Dash('')
35
36
#external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css', 'https://codepen.io/rmarren1/pen/eMQKBW.css']
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (116/100).

This check looks for lines that are too long. You can specify the maximum line length.

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