def update_output(records): pkd = utils.dt2pkdata(records) if not pkd.empty: subjects = pkd.subject_index.unique() else: subjects = [] fig_data = [] results = {} for subject in subjects: df = pkd.loc[pkd.subject_index == subject, ["time", "conc"]] fig_data.append( go.Scatter( x=df["time"], y=df["conc"], name="Subj{}".format(subject + 1), mode="lines+markers", )) results[subject] = utils.calc_pk(df["time"], df["conc"]) figure = go.Figure( data=fig_data, layout=go.Layout( xaxis=dict(zeroline=False), yaxis=dict( title=dict( text="Conc (uM)", font=dict( family='"Open Sans", "HelveticaNeue", "Helvetica Neue",' " Helvetica, Arial, sans-serif", size=12, ), ), type="log", rangemode="tozero", zeroline=False, showticklabels=False, ), margin=dict(l=40, r=30, b=50, t=50), showlegend=False, height=294, paper_bgcolor="rgb(245, 247, 249)", plot_bgcolor="rgb(245, 247, 249)", ), ) columns = ([{ "name": "Parameter", "id": "param" }] + [{ "name": "Subj{}".format(subject + 1), "id": subject, "type": "numeric" } for subject in subjects] + [{ "name": "Mean", "id": "mean" }, { "name": "StDev", "id": "stdev" }]) result_names = OrderedDict( t_half="T½ (hr)", auc0_t="AUC_0-t (uM*hr)", auc0_inf="AUC_0-inf (uM*hr)", percent_extrap="%Extrap", c_max="Cmax (uM)", t_max="Tmax (hr)", ) data = [] for key, name in result_names.items(): d = dict(param=name) for subject in subjects: try: d[int(subject)] = round(getattr(results[subject], key), 1) except (AttributeError, TypeError): d[int(subject)] = None try: d["mean"] = round( statistics.mean([getattr(results[s], key) for s in subjects]), 1) d["stdev"] = round( statistics.stdev([getattr(results[s], key) for s in subjects]), 2) except (statistics.StatisticsError, AttributeError, TypeError): d["mean"] = None d["stdev"] = None data.append(d) return figure, columns, data
def update_output(records): pkd = utils.dt2pkdata(records) if not pkd.empty: subjects = pkd.subject_index.unique() else: subjects = [] fig_data = [] results = {} for subject in subjects: df = pkd.loc[pkd.subject_index == subject, ['time', 'conc']] fig_data.append( go.Scatter( x=df['time'], y=df['conc'], name='Subj{}'.format(subject + 1), mode='lines+markers' ) ) results[subject] = utils.calc_pk(df['time'], df['conc']) figure = go.Figure( data=fig_data, layout=go.Layout( xaxis=dict(zeroline=False), yaxis=dict(title=dict(text='Conc (uM)', font=dict( family='"Open Sans", "HelveticaNeue", "Helvetica Neue",' ' Helvetica, Arial, sans-serif', size=12) ), type='log', rangemode='tozero', zeroline=False, showticklabels=False ), margin=dict( l=40, r=30, b=50, t=50, ), showlegend=False, height=294, paper_bgcolor='rgb(245, 247, 249)', plot_bgcolor='rgb(245, 247, 249)', ) ) columns = [{"name": "Parameter", "id": 'param'}] + \ [{"name": 'Subj{}'.format(subject + 1), 'id': subject, 'type': 'numeric'} for subject in subjects] + \ [{'name': 'Mean', 'id': 'mean'}, {'name': 'StDev', 'id': 'stdev'}] result_names = OrderedDict(t_half='T½ (hr)', auc0_t='AUC_0-t (uM*hr)', auc0_inf='AUC_0-inf (uM*hr)', percent_extrap='%Extrap', c_max='Cmax (uM)', t_max='Tmax (hr)') data = [] for key, name in result_names.items(): d = dict(param=name) for subject in subjects: try: d[int(subject)] = round(getattr(results[subject], key), 1) except (AttributeError, TypeError): d[int(subject)] = None try: d['mean'] = round(statistics.mean([getattr(results[s], key) for s in subjects]), 1) d['stdev'] = round(statistics.stdev([getattr(results[s], key) for s in subjects]), 2) except (statistics.StatisticsError, AttributeError, TypeError): d['mean'] = None d['stdev'] = None data.append(d) return figure, columns, data