Commit 25a19a06 authored by Jalal Mostafa's avatar Jalal Mostafa
Browse files

epics-labview: paper analysis

parent 53ab9a7a
......@@ -38,7 +38,7 @@ async def main(url, publishing_interval):
for obj in namespace2_objects:
variables = await obj.get_children()
all_variables.extend(variables)
handler = SubHandler()
sub = await client.create_subscription(publishing_interval, handler)
print(sub.subscribe_data_change)
......@@ -68,12 +68,18 @@ async def get_all_variables(url):
return all_variables
def _one_record(pv_type, pv_name, fields):
return f'record({pv_type},{pv_name})\n' + '{\n' + '\n'.join([f'field({k}, "{v}")' for k, v in fields.items()]) + '\n}'
def to_record(node, interval):
pvname = node.nodeid.to_string().split(';')[1][2:].replace(
' ', '').replace('.', ":").lower()
issensor = True if 'write' in pvname else False
fields = {
'DTYP': 'OPCUA',
'ADEL': '-1',
'MDEL': '-1'
}
io_extra = f'timestamp=source qsize={(1000 // interval) + 1}'
......@@ -81,12 +87,16 @@ def to_record(node, interval):
fields['TSE'] = '-2'
fields['SCAN'] = 'I/O Intr'
fields['INP'] = f'@SUB1 {node.nodeid} {io_extra}'
else:
fields['OUT'] = f'@OPC1 {node.nodeid} monitor=n'
fields['MDEL'] = fields['ADEL'] = '-1'
pv_type = 'ai' if issensor else 'ao'
return f'record({pv_type},{pvname})\n' + '{\n' + '\n'.join([f'field({k}, "{v}")' for k, v in fields.items()]) + '\n}'
return _one_record('ai', pvname, fields)
fields_out = fields.copy()
fields_out['OUT'] = f'@OPC1 {node.nodeid} monitor=n'
ao = _one_record('ao', pvname, fields_out)
fields['TSE'] = '-2'
fields['SCAN'] = 'I/O Intr'
fields['INP'] = f'@SUB1 {node.nodeid} {io_extra}'
ao_rb = _one_record('ai', pvname+'_rb', fields)
return ao + '\n' + ao_rb
if __name__ == "__main__":
......
......@@ -33,7 +33,7 @@
" base_dir = f'./results/{freq}/{elm_nb}'\n",
" dataframes[freq][elm_nb] = {\n",
" 'epics': pd.read_csv(glob.glob(base_dir + '/ai0*')[0]),\n",
" 'opcua': pd.read_csv(glob.glob(base_dir + '/opcua*')[0]),\n",
"# 'opcua': pd.read_csv(glob.glob(base_dir + '/opcua*')[0]),\n",
"# 'nmon': read_nmon_file(glob.glob(base_dir + '/nmon*')[0])\n",
" }\n"
]
......@@ -44,13 +44,13 @@
"metadata": {},
"outputs": [],
"source": [
"df = dataframes['10HzW']['300']['epics'].sort_values('val0').groupby(by=['val0'])\n",
"dataframes['10HzW']['300']['epics'] = df.min()\n",
"dataframes['10HzW']['300']['epics_rb'] = df.max()\n",
"# df = dataframes['10HzW']['300']['epics'].sort_values('val0').groupby(by=['val0'])\n",
"# dataframes['10HzW']['300']['epics'] = df.min()\n",
"dataframes['10HzW']['300']['epics_rb'] = pd.read_csv('./results/10HzW/300/ai0_rb_1617991931.3135772_3600_100_300_0.csv')\n",
"\n",
"df = dataframes['2HzW']['300']['epics'].sort_values('val0').groupby(by=['val0'])\n",
"dataframes['2HzW']['300']['epics'] = df.min()\n",
"dataframes['2HzW']['300']['epics_rb'] = df.max()"
"# df = dataframes['2HzW']['300']['epics'].sort_values('val0').groupby(by=['val0'])\n",
"# dataframes['2HzW']['300']['epics'] = df.min()\n",
"# dataframes['2HzW']['300']['epics_rb'] = df.max()"
]
},
{
......@@ -84,7 +84,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9fb6f3bbcc0a4c1aac461ec8252cf4e1",
"model_id": "7c0a2dcde0c2446f83b4685d2c456851",
"version_major": 2,
"version_minor": 0
},
......@@ -131,7 +131,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "3ddf821086044f569d80af3229245c2c",
"model_id": "12c27aa89f3e4bd1857c368e648b2965",
"version_major": 2,
"version_minor": 0
},
......@@ -172,13 +172,13 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a424c847c6854edcb9b953b2a7f85f85",
"model_id": "7b5d6011d9234e42b6ebdd45f782e6c4",
"version_major": 2,
"version_minor": 0
},
......@@ -192,10 +192,10 @@
{
"data": {
"text/plain": [
"<AxesSubplot:title={'center':'EPICS'}>"
"<AxesSubplot:ylabel='Loss Rate (%)'>"
]
},
"execution_count": 8,
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
......@@ -212,31 +212,31 @@
" percentage = (expected - len(df)) * 100 / expected\n",
" return percentage if percentage > 0 else 0\n",
" \n",
"fig, ax = plt.subplots(2, 1, figsize=size)\n",
"fig.suptitle('Percentage of Missing Values')\n",
"fig, ax = plt.subplots(1, 1, figsize=(5, 5))\n",
"fig.suptitle('Loss Rate of 10Hz Output and Readback Records')\n",
"for exp in elements:\n",
" epics_real_rate[exp] = {}\n",
" opcua_real_rate[exp] = {}\n",
" for freq in frequencies:\n",
" epics_real_rate[exp][freq] = get_missing_values(dataframes[freq][exp]['epics'], freq,)\n",
" for freq in ['10HzW']:\n",
" epics_real_rate[exp]['Output Record'] = get_missing_values(dataframes[freq][exp]['epics'], freq,)\n",
" if dataframes[freq][exp].get('epics_rb', None) is not None:\n",
" epics_real_rate[exp][freq+'RB'] = get_missing_values(dataframes[freq][exp]['epics_rb'], freq,)\n",
" epics_real_rate[exp]['Readback Record'] = get_missing_values(dataframes[freq][exp]['epics_rb'], freq,)\n",
"# opcua_real_rate[exp][freq] = get_missing_values(dataframes[freq][exp]['opcua'], freq, val_field='Value')\n",
" \n",
"\n",
"pd.DataFrame(epics_real_rate).plot(figsize=size, ax=ax[0], kind='bar', title='EPICS')\n",
"pd.DataFrame(epics_real_rate).plot(figsize=size, ax=ax, kind='bar', rot=0, legend=False, ylabel='Loss Rate (%)')\n",
"# pd.DataFrame(opcua_real_rate).plot(figsize=size, ax=ax[1], kind='bar', title='OPCUA')\n"
]
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9edde82558b64a67b5f683c25cfd0ae9",
"model_id": "d816fc29b01541fea5e3c811602bc0e7",
"version_major": 2,
"version_minor": 0
},
......@@ -253,41 +253,66 @@
"from collections.abc import Iterable\n",
"\n",
"\n",
"fig, ax = plt.subplots(2,1, figsize=size)\n",
"fig.suptitle('ECDF Periods')\n",
"fig, ax = plt.subplots(1,1, figsize=(5,5))\n",
"fig.suptitle('10Hz Response Time')\n",
"\n",
"for idx, freq in enumerate(['10HzW', '2HzW']):\n",
"for idx, freq in enumerate(['10HzW']):\n",
" for exp in elements:\n",
" df = dataframes[freq][exp]['epics']\n",
" df_rb = dataframes[freq][exp]['epics_rb']\n",
" (df_rb - df).div(1e6).plot(ax=ax[idx])\n",
" df = dataframes[freq][exp]['epics'].set_index('val0')\n",
" df_rb = dataframes[freq][exp]['epics_rb'].set_index('val0')\n",
" a = df.join(df_rb, lsuffix='_epics', rsuffix='_rb')\n",
" (a['ts_epics'] - a['ts_rb']).div(1e6).plot(ax=ax, xlabel='Data Value', ylabel='Response Time (msec)')\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" ts val0\n",
"1089.0 -1.106090e+11 NaN\n",
"1090.0 -1.106025e+11 NaN\n",
"1091.0 -1.106028e+11 NaN\n",
"1092.0 -1.106027e+11 NaN\n",
"1093.0 -1.106031e+11 NaN\n",
"... ... ...\n",
"35996.0 -1.106013e+11 NaN\n",
"35997.0 -1.106013e+11 NaN\n",
"35998.0 -1.106016e+11 NaN\n",
"36000.0 -1.106013e+11 NaN\n",
"36001.0 -1.106013e+11 NaN\n",
"\n",
"[34310 rows x 2 columns]\n"
]
}
],
"source": [
"df = dataframes['10HzW']['300']['epics']\n",
"# df = df.set_index('val0')\n",
"df_rb = dataframes['10HzW']['300']['epics_rb']\n",
"df_rb = df_rb.set_index('val0')\n",
"mi = df_rb - df\n",
"\n",
"print(mi[mi['ts'].notna()])\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"val0\n",
"613.0 -0.404224\n",
"1110.0 -0.991232\n",
"1659.0 -0.537088\n",
"2267.0 -1.239040\n",
"2858.0 -0.717056\n",
" ... \n",
"34064.0 -0.536064\n",
"34674.0 -0.714240\n",
"35388.0 -0.476160\n",
"36093.0 -0.409856\n",
"36095.0 -0.101120\n",
"Name: ts, Length: 72, dtype: float64"
"Series([], Name: ts, dtype: float64)"
]
},
"execution_count": 14,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment