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

Fix #278: Add dryrun option #89

Merged
merged 7 commits into from
Mar 2, 2022
Merged
Changes from 3 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
25 changes: 25 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,27 @@ exports.TRAPIQueryHandler = class TRAPIQueryHandler {
let current_edge = manager.getNext();
const edgeConverter = new QEdge2BTEEdgeHandler([current_edge], kg);
const sAPIEdges = edgeConverter.getSmartAPIEdges(current_edge);

if (this.options.dryrun) {
let apiNames = [...new Set(sAPIEdges.map((apiEdge) => apiEdge.association.api_name))];

let log_msg;
if (current_edge.reverse) {
log_msg = `Edge ${current_edge.qEdge.id} (reversed): ${current_edge.qEdge.object.category} > ${current_edge.qEdge.predicate ? `${current_edge.qEdge.predicate} > ` : ''}${current_edge.qEdge.subject.category}`;
} else {
log_msg = `Edge ${current_edge.qEdge.id}: ${current_edge.qEdge.subject.category} > ${current_edge.qEdge.predicate ? `${current_edge.qEdge.predicate} > ` : ''}${current_edge.qEdge.object.category}`;
}
this.logs.push(new LogEntry("INFO", null, log_msg).getLog());

let log_msg_2 = `APIs called: ${apiNames.join(',')} (${sAPIEdges.length} queries total)`;
this.logs.push(new LogEntry("INFO", null, log_msg_2).getLog());

sAPIEdges.forEach(apiEdge => {
log_msg = `${apiEdge.association.api_name}: ${apiEdge.association.input_type} > ${apiEdge.association.predicate} > ${apiEdge.association.output_type}`;
this.logs.push(new LogEntry("TRACE", null, log_msg).getLog());
ericz1803 marked this conversation as resolved.
Show resolved Hide resolved
});
}

if (!sAPIEdges.length) {
edgesMissingOps[current_edge.qEdge.id] = current_edge.reverse;
}
Expand All @@ -131,6 +152,10 @@ exports.TRAPIQueryHandler = class TRAPIQueryHandler {
// this.logs = [...this.logs, ...edgeConverter.logs];
}

if (this.options.dryrun) {
return false;
}

const len = Object.keys(edgesMissingOps).length;
// this.logs = [...this.logs, ...manager.logs];
let edgesToLog = Object.entries(edgesMissingOps).map(([edge, reversed]) => {
Expand Down