Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

117 anms fun bld 010 state based rule no limits #122

Merged
merged 7 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 49 additions & 38 deletions anms-core/anms/routes/ARIs/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
from sqlalchemy.engine import Result
import re
from datetime import datetime
import multiprocessing as mp
import asyncio

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

return data_type_id

async def _process_report_entries(x):
entry, ac_types_and_id = x
# for entry in entries:
curr_values = []
time = datetime.fromtimestamp(int(entry.time)).strftime('%Y-%m-%d %H:%M:%S')

string_values = list(filter(None, re.split(r",|'(.*?)'", entry.string_values))) if entry.string_values else []
uint_values = entry.uint_values.split(',') if entry.uint_values else []
int_values = entry.int_values.split(',') if entry.int_values else []
real32_values = entry.real32_values.split(',') if entry.real32_values else []
real64_values = entry.real64_values.split(',') if entry.real64_values else []
uvast_values = entry.uvast_values.split(',') if entry.uvast_values else []
vast_values = entry.vast_values.split(',') if entry.vast_values else []
value_matchup = {18: string_values, 19: int_values, 20: uint_values, 21: vast_values, 22: uvast_values,
23: real32_values, 24: real64_values}
curr_values.append(time)
for type_id, obj_id in ac_types_and_id:
# find the type of ari
curr_type = type_id
if value_matchup[curr_type]:
curr_values.append(value_matchup[curr_type].pop(0))
if not ac_types_and_id:
if string_values: curr_values.append(','.join(string_values))
if uint_values: curr_values.append(','.join(uint_values))
if int_values: curr_values.append(','.join(int_values))
if real32_values: curr_values.append(','.join(real32_values))
if real64_values: curr_values.append(','.join(real64_values))
if uvast_values: curr_values.append(','.join(uvast_values))
if vast_values: curr_values.append(','.join(vast_values))
return curr_values


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

ac_names.append(curr_name)
ac_types_and_id.append((entry.data_type_id, entry.obj_metadata_id))
# unknown template
if ac_names == []:
ac_names = ["time","string_values", "uint_values", "int_values", "real32_values", "real64_values", "uvast_values","vast_values"]

curr_type = entry.data_type_id
if curr_type == 2:
curr_type = await find_edd_type(entry.obj_metadata_id)
elif curr_type == 12:
curr_type = await find_var_type(entry.obj_metadata_id)
ac_types_and_id.append((curr_type, entry.obj_metadata_id))

stmt = select(Report).where(Report.agent_id == agent_id , Report.ADM == adm_name
, Report.report_name == report_name)
# find the type of ari
type_matchup = {2: find_edd_type, 12: find_var_type, }
# if a none formal report
if ac_id == None:
ac_names.append(report_name)

final_values = []
final_values.append(ac_names)
async with get_async_session() as session:
result: Result = await session.scalars(stmt)
entries = result.all()

args_to_use = []
for entry in entries:
curr_values = []
time = datetime.fromtimestamp(int(entry.time)).strftime('%Y-%m-%d %H:%M:%S')

string_values = list(filter(None, re.split(r",|'(.*?)'", entry.string_values))) if entry.string_values else []
uint_values = entry.uint_values.split(',') if entry.uint_values else []
int_values = entry.int_values.split(',') if entry.int_values else []
real32_values = entry.real32_values.split(',') if entry.real32_values else []
real64_values = entry.real64_values.split(',') if entry.real64_values else []
uvast_values = entry.uvast_values.split(',') if entry.uvast_values else []
vast_values = entry.vast_values.split(',') if entry.vast_values else []
value_matchup = {18: string_values, 19: int_values, 20: uint_values, 21: vast_values, 22: uvast_values,
23: real32_values, 24: real64_values}
curr_values.append(time)
for type_id, obj_id in ac_types_and_id:
if type_id in type_matchup:
curr_type = await type_matchup[type_id](obj_id)
else:
curr_type = type_id
if value_matchup[curr_type]:
curr_values.append(value_matchup[curr_type].pop(0))
if ac_types_and_id is []:
curr_values.append(','.join(string_values))
curr_values.append(','.join(uint_values))
curr_values.append(','.join(int_values))
curr_values.append(','.join(real32_values))
curr_values.append(','.join(real64_values))
curr_values.append(','.join(uvast_values))
curr_values.append(','.join(vast_values))

final_values.append(curr_values)
args_to_use.append(_process_report_entries([entry, ac_types_and_id]))
result = await asyncio.gather(*args_to_use)
for res in result:
final_values.append(res)

return final_values

34 changes: 21 additions & 13 deletions anms-ui/public/app/components/management/agents/reports.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
:key="index"
:value="index">{{ rpt.adm }}.{{ rpt.name }}</b-form-select-option>
</b-form-select>
<b-table v-if="!loading && selected != -1"
<b-table sticky-header
hover
bordered
responsive
v-if="!loading && selected != -1"
id="report-table"
:fields="tableHeaders"
:items="tableItems"
class="spacing-table"
hover
bordered
responsive>
>
</b-table>
</div>
</template>
Expand All @@ -52,7 +53,7 @@ export default {
this.loading = true;
this.tableHeaders = [];
this.tableItems = [];
if (this.reports[this.selected] == undefined) {
// if (this.reports[this.selected] == undefined) {
d-linko marked this conversation as resolved.
Show resolved Hide resolved
this.loading = true;
let rpt_name = this.rptts[this.selected].name;
let rpt_adm = this.rptts[this.selected].adm;
Expand All @@ -66,19 +67,23 @@ export default {
console.error("reports error", error);
console.info("error obj:", error);
});
} else{
this.tableHeaders = this.reportsHeader[this.selected];
this.tableItems = this.reports[this.selected];
}
// } else{
// this.tableHeaders = this.reportsHeader[this.selected];
// this.tableItems = this.reports[this.selected];
// }

this.loading = false;
},
processReport(report) {
this.tableHeaders = report.shift();
let holdHeader = report.shift();
this.tableHeaders = [];
for (let i = 0; i < holdHeader.length; i++) {
this.tableHeaders.push({"key":holdHeader[i]});
}
for (let item of report) {
let row = {};
for (let i = 0; i < this.tableHeaders.length; i++) {
row[this.tableHeaders[i]] = item[i];
for (let i = 0; i < holdHeader.length; i++) {
row[holdHeader[i]] = item[i];
}
this.tableItems.push(row);
}
Expand Down Expand Up @@ -117,4 +122,7 @@ export default {
.select-max-width {
max-width: 600px;
}
.b-table-sticky-header > .table.b-table > thead > tr > th {
position: sticky !important;
}
</style>
2 changes: 1 addition & 1 deletion ion/src
Submodule src updated from 6e95a2 to 040584
Loading