Skip to content

Commit 80bf11e

Browse files
d-linkolinkodm1
and
linkodm1
authored
113 anms fun bld 002 generate reports report displays (#120)
* adding multiprocessing * updated table display and processing * uncommented code --------- Co-authored-by: linkodm1 <[email protected]>
1 parent 92295e2 commit 80bf11e

File tree

2 files changed

+65
-46
lines changed

2 files changed

+65
-46
lines changed

anms-core/anms/routes/ARIs/reports.py

+49-38
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
from sqlalchemy.engine import Result
3232
import re
3333
from datetime import datetime
34+
import multiprocessing as mp
35+
import asyncio
3436

3537
from anms.components.schemas import ARIs
3638
from anms.models.relational import get_async_session, get_session
@@ -102,6 +104,37 @@ async def find_var_type(obj_metadata):
102104

103105
return data_type_id
104106

107+
async def _process_report_entries(x):
108+
entry, ac_types_and_id = x
109+
# for entry in entries:
110+
curr_values = []
111+
time = datetime.fromtimestamp(int(entry.time)).strftime('%Y-%m-%d %H:%M:%S')
112+
113+
string_values = list(filter(None, re.split(r",|'(.*?)'", entry.string_values))) if entry.string_values else []
114+
uint_values = entry.uint_values.split(',') if entry.uint_values else []
115+
int_values = entry.int_values.split(',') if entry.int_values else []
116+
real32_values = entry.real32_values.split(',') if entry.real32_values else []
117+
real64_values = entry.real64_values.split(',') if entry.real64_values else []
118+
uvast_values = entry.uvast_values.split(',') if entry.uvast_values else []
119+
vast_values = entry.vast_values.split(',') if entry.vast_values else []
120+
value_matchup = {18: string_values, 19: int_values, 20: uint_values, 21: vast_values, 22: uvast_values,
121+
23: real32_values, 24: real64_values}
122+
curr_values.append(time)
123+
for type_id, obj_id in ac_types_and_id:
124+
# find the type of ari
125+
curr_type = type_id
126+
if value_matchup[curr_type]:
127+
curr_values.append(value_matchup[curr_type].pop(0))
128+
if not ac_types_and_id:
129+
if string_values: curr_values.append(','.join(string_values))
130+
if uint_values: curr_values.append(','.join(uint_values))
131+
if int_values: curr_values.append(','.join(int_values))
132+
if real32_values: curr_values.append(','.join(real32_values))
133+
if real64_values: curr_values.append(','.join(real64_values))
134+
if uvast_values: curr_values.append(','.join(uvast_values))
135+
if vast_values: curr_values.append(','.join(vast_values))
136+
return curr_values
137+
105138

106139
# entries tabulated returns header and values in correct order
107140
@router.get("/entries/table/{agent_id}/{adm}/{report_name}", status_code=status.HTTP_200_OK,
@@ -147,52 +180,30 @@ async def report_ac(agent_id: str, adm: str, report_name: str):
147180
curr_name = result.one_or_none()
148181

149182
ac_names.append(curr_name)
150-
ac_types_and_id.append((entry.data_type_id, entry.obj_metadata_id))
151-
# unknown template
152-
if ac_names == []:
153-
ac_names = ["time","string_values", "uint_values", "int_values", "real32_values", "real64_values", "uvast_values","vast_values"]
154-
183+
curr_type = entry.data_type_id
184+
if curr_type == 2:
185+
curr_type = await find_edd_type(entry.obj_metadata_id)
186+
elif curr_type == 12:
187+
curr_type = await find_var_type(entry.obj_metadata_id)
188+
ac_types_and_id.append((curr_type, entry.obj_metadata_id))
189+
155190
stmt = select(Report).where(Report.agent_id == agent_id , Report.ADM == adm_name
156191
, Report.report_name == report_name)
157-
# find the type of ari
158-
type_matchup = {2: find_edd_type, 12: find_var_type, }
192+
# if a none formal report
193+
if ac_id == None:
194+
ac_names.append(report_name)
195+
159196
final_values = []
160197
final_values.append(ac_names)
161198
async with get_async_session() as session:
162199
result: Result = await session.scalars(stmt)
163200
entries = result.all()
164-
201+
args_to_use = []
165202
for entry in entries:
166-
curr_values = []
167-
time = datetime.fromtimestamp(int(entry.time)).strftime('%Y-%m-%d %H:%M:%S')
168-
169-
string_values = list(filter(None, re.split(r",|'(.*?)'", entry.string_values))) if entry.string_values else []
170-
uint_values = entry.uint_values.split(',') if entry.uint_values else []
171-
int_values = entry.int_values.split(',') if entry.int_values else []
172-
real32_values = entry.real32_values.split(',') if entry.real32_values else []
173-
real64_values = entry.real64_values.split(',') if entry.real64_values else []
174-
uvast_values = entry.uvast_values.split(',') if entry.uvast_values else []
175-
vast_values = entry.vast_values.split(',') if entry.vast_values else []
176-
value_matchup = {18: string_values, 19: int_values, 20: uint_values, 21: vast_values, 22: uvast_values,
177-
23: real32_values, 24: real64_values}
178-
curr_values.append(time)
179-
for type_id, obj_id in ac_types_and_id:
180-
if type_id in type_matchup:
181-
curr_type = await type_matchup[type_id](obj_id)
182-
else:
183-
curr_type = type_id
184-
if value_matchup[curr_type]:
185-
curr_values.append(value_matchup[curr_type].pop(0))
186-
if ac_types_and_id is []:
187-
curr_values.append(','.join(string_values))
188-
curr_values.append(','.join(uint_values))
189-
curr_values.append(','.join(int_values))
190-
curr_values.append(','.join(real32_values))
191-
curr_values.append(','.join(real64_values))
192-
curr_values.append(','.join(uvast_values))
193-
curr_values.append(','.join(vast_values))
194-
195-
final_values.append(curr_values)
203+
args_to_use.append(_process_report_entries([entry, ac_types_and_id]))
204+
result = await asyncio.gather(*args_to_use)
205+
for res in result:
206+
final_values.append(res)
196207

197208
return final_values
198209

anms-ui/public/app/components/management/agents/reports.vue

+16-8
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
:key="index"
1919
:value="index">{{ rpt.adm }}.{{ rpt.name }}</b-form-select-option>
2020
</b-form-select>
21-
<b-table v-if="!loading && selected != -1"
21+
<b-table sticky-header
22+
hover
23+
bordered
24+
responsive
25+
v-if="!loading && selected != -1"
2226
id="report-table"
2327
:fields="tableHeaders"
2428
:items="tableItems"
25-
class="spacing-table"
26-
hover
27-
bordered
28-
responsive>
29+
>
2930
</b-table>
3031
</div>
3132
</template>
@@ -74,11 +75,15 @@ export default {
7475
this.loading = false;
7576
},
7677
processReport(report) {
77-
this.tableHeaders = report.shift();
78+
let holdHeader = report.shift();
79+
this.tableHeaders = [];
80+
for (let i = 0; i < holdHeader.length; i++) {
81+
this.tableHeaders.push({"key":holdHeader[i]});
82+
}
7883
for (let item of report) {
7984
let row = {};
80-
for (let i = 0; i < this.tableHeaders.length; i++) {
81-
row[this.tableHeaders[i]] = item[i];
85+
for (let i = 0; i < holdHeader.length; i++) {
86+
row[holdHeader[i]] = item[i];
8287
}
8388
this.tableItems.push(row);
8489
}
@@ -117,4 +122,7 @@ export default {
117122
.select-max-width {
118123
max-width: 600px;
119124
}
125+
.b-table-sticky-header > .table.b-table > thead > tr > th {
126+
position: sticky !important;
127+
}
120128
</style>

0 commit comments

Comments
 (0)