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

Fixing report db #82

Merged
merged 3 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 17 additions & 3 deletions anms-core/anms/routes/ARIs/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from sqlalchemy import select, and_
from sqlalchemy.engine import Result
import re
from datetime import datetime

from anms.components.schemas import ARIs
from anms.models.relational import get_async_session, get_session
Expand Down Expand Up @@ -132,7 +133,7 @@ async def report_ac(agent_id: str, adm: str, report_name: str):
ac_id = result.one_or_none()

# get AC
ac_names = []
ac_names = ["time"]
ac_types_and_id = []
ac_stmt = select(ARICollection).where(ARICollection.ac_id == ac_id).order_by(ARICollection.order_num)
async with get_async_session() as session:
Expand All @@ -147,7 +148,10 @@ async def report_ac(agent_id: str, adm: str, report_name: str):

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"]

stmt = select(Report).where(Report.agent_id == agent_id , Report.ADM == adm_name
, Report.report_name == report_name)
# find the type of ari
Expand All @@ -160,6 +164,8 @@ async def report_ac(agent_id: str, adm: str, report_name: str):

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 []
Expand All @@ -169,14 +175,22 @@ async def report_ac(agent_id: str, adm: str, report_name: str):
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)

Expand Down
33 changes: 33 additions & 0 deletions anms-core/anms/shared/ace_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,37 @@ def get_adms():
if not hasattr(LOCALDATA, 'adms'):
LOCALDATA.adms = ace.AdmSet(cache_dir=False)
LOCALDATA.adms.load_default_dirs()
_adm_reload(None)
return LOCALDATA.adms


def _adm_reload(adm_name):
with get_session() as db_conn:
if adm_name:
LOGGER.info('Reloading one ADM: %s', adm_name)
curs = db_conn.execute('''\
SELECT adm.adm_name, adm_data.updated_at, adm_data.data
FROM adm_data
INNER JOIN adm ON adm_data.adm_enum = adm.adm_enum
WHERE adm_name = ?
''', [adm_name])
for row in curs.all():
_handle_adm(*row)

else:
LOGGER.info('Reloading all ADMS...')

curs = db_conn.execute('''\
SELECT adm.adm_name, adm_data.updated_at, adm_data.data
FROM adm_data
INNER JOIN adm ON adm_data.adm_enum = adm.adm_enum
''')
for row in curs.all():
_handle_adm(*row)

LOGGER.info('ADMS present for: %s', LOCALDATA.adms.names())

def _handle_adm(adm_name, timestamp, data):
LOGGER.info('Handling ADM: %s', adm_name)
LOCALDATA.adms.load_from_data(io.BytesIO(data))
LOGGER.info('Handling finished')
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default {
props: ["listComponents", "name", "parms", "type", "index"],
data() {
return {
expressionReturnTypes: ["BYTE", "INT", "UINT", "VAST", "UVAST", "REAL32", "REAL64", "STRING", "BOOLEAN"],
expressionReturnTypes: ["BYTE", "INT", "UINT", "VAST", "UVAST", "REAL32", "REAL64", "STRING", "BOOL"],
selectedExpressionReturnType: undefined,
expressionList: [],
ariKey: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export default {
currValue.push(ari.replaceAll('"', "'"));
});

testResult.push(JSON.stringify(currValue).replaceAll('"', ""));
testResult.push(JSON.stringify(currValue).replaceAll('"', "").replaceAll("'",'"'));

break;

Expand Down Expand Up @@ -224,4 +224,4 @@ export default {
.card.border-grey {
border-color: grey;
}
</style>
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
@click="addNewTnvc"><i class="fas fa-plus"></i></b-button>
</b-col>
</b-row>

<b-list-group class="my-2">
<b-list-group-item v-for="(TNVC, index) in TNVCs"
:key="index">
Expand All @@ -57,11 +56,12 @@ export default {
props: ["name", "type", "types", "index"],
data() {
return {
TNVCType: undefined,
TNVCName: undefined,
TNVCValue: undefined,
TNVCType: "",
TNVCName: "",
TNVCValue: "",
final: { "index": this.index, "type": "TNVC", "value": [] },
TNVCs: [],
test: {},
}
},
methods: {
Expand All @@ -77,9 +77,9 @@ export default {
this.$emit("updateResult", this.final);
},
clearInputs() {
this.TNVCType = undefined;
this.TNVCName = undefined;
this.TNVCValue = undefined;
this.TNVCType = "";
this.TNVCName = "";
this.TNVCValue = "";
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ion/src
Submodule src updated from 416130 to 7905cc
Loading