Skip to content

Commit

Permalink
Merge pull request #54 from UST-QuAntiL/feature/-result-quality-timel…
Browse files Browse the repository at this point in the history
…ine-filter

feature: filter timeline steps by result quality
  • Loading branch information
infacc authored Oct 25, 2023
2 parents ed93c36 + dc5e856 commit 8140161
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
7 changes: 4 additions & 3 deletions main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -640,11 +640,12 @@ service / on new http:Listener(serverPort) {
# + 'version - filter by version (name + version for exact match)
# + status - filter by status (pending/finished)
# + uncleared\-substep - filter by step status (whether there is an uncleared substep that requires user inputs) - If set to 1 (or any positive number), steps must have at least one uncleared substeps. Else, be set to -1 (or any negative number). Set to 0 if not specified.
# + result\-quality - filter by result quality (unknown/neutral/good/bad/error/unusable)
# + page - the requested page (starting with page 0)
# + 'item\-count - the number of items per page (5 <= item-count <= 500)
# + sort - 1 for asc sort, -1 for desc sort by step sequence
# + return - the list resource containing the timeline entries
resource function get experiments/[int experimentId]/timeline(string? plugin\-name, string? 'version, string? status, int? uncleared\-substep, int page = 0, int item\-count = 0, int? sort = 1) returns TimelineStepListResponse|http:BadRequest|http:NotFound|http:InternalServerError {
resource function get experiments/[int experimentId]/timeline(string? plugin\-name, string? 'version, string? status, int? uncleared\-substep, string? result\-quality, int page = 0, int item\-count = 0, int? sort = 1) returns TimelineStepListResponse|http:BadRequest|http:NotFound|http:InternalServerError {

if (page < 0) {
return <http:BadRequest>{body: "Cannot retrieve a negative page number!"};
Expand All @@ -662,13 +663,13 @@ service / on new http:Listener(serverPort) {

transaction {

stepCount = check database:getTimelineStepCount(experimentId, plugin\-name, 'version, status, uncleared\-substep);
stepCount = check database:getTimelineStepCount(experimentId, plugin\-name, 'version, status, uncleared\-substep, result\-quality);
if (offset >= stepCount) {
// page is out of range!
check commit;
return <http:NotFound>{};
} else {
steps = check database:getTimelineStepList(experimentId, plugin\-name, 'version, status, uncleared\-substep, 'limit = item\-count, offset = offset, sort = intSort);
steps = check database:getTimelineStepList(experimentId, plugin\-name, 'version, status, uncleared\-substep, result\-quality, 'limit = item\-count, offset = offset, sort = intSort);
check commit;
}

Expand Down
27 changes: 17 additions & 10 deletions modules/database/database.bal
Original file line number Diff line number Diff line change
Expand Up @@ -731,14 +731,15 @@ public isolated transactional function getStepsUsingData(int|ExperimentDataFull
# + pluginName - The plugin name
# + 'version - The plugin version
# + status - Filter for the current status of the timeline step result
# + uncleared\-substep - Filter for (un)cleared substeps. If set to 1 (or any postivie number), steps must have at least one uncleared substeps. Else, must be set to -1 (or any negative number). Set to 0 if not specified.
# + unclearedSubstep - Filter for (un)cleared substeps. If set to 1 (or any postivie number), steps must have at least one uncleared substeps. Else, must be set to -1 (or any negative number). Set to 0 if not specified.
# + resultQuality - Filter for the result quality of the timeline step result
# + return - Return timeline step count
public isolated transactional function getTimelineStepCount(int experimentId, string? pluginName, string? 'version, string? status, int? uncleared\-substep) returns int|error {
public isolated transactional function getTimelineStepCount(int experimentId, string? pluginName, string? 'version, string? status, int? unclearedSubstep, string? resultQuality) returns int|error {
sql:ParameterizedQuery query = `SELECT count(*) AS rowCount FROM TimelineStep `;

stream<RowCount, sql:Error?> result = experimentDB->query(sql:queryConcat(
query,
timelineStepListFilter(experimentId, pluginName, 'version, status, uncleared\-substep),
timelineStepListFilter(experimentId, pluginName, 'version, status, unclearedSubstep, resultQuality),
`;`
));

Expand Down Expand Up @@ -788,13 +789,14 @@ public isolated transactional function castToTimelineStepFull(TimelineStepSQL st
# + pluginName - The plugin name
# + 'version - The plugin version
# + status - Filter for the current status of the timeline step result
# + uncleared\-substep - Filter for (un)cleared substeps. If set to 1 (or any postivie number), steps must have at least one uncleared substeps. Else, must be set to -1 (or any negative number). Set to 0 if not specified.
# + unclearedSubstep - Filter for (un)cleared substeps. If set to 1 (or any postivie number), steps must have at least one uncleared substeps. Else, must be set to -1 (or any negative number). Set to 0 if not specified.
# + resultQuality - Filter for the result quality of the timeline step result
# + allAttributes - Include all attributes in result
# + 'limit - The maximum number of timline steps fetched in one call (default: `100`)
# + offset - The offset applied to the sql query (default: `0`)
# + sort - 1 for asc sort, -1 for desc sort by step sequence
# + return - The list of timpline steps or the encountered error
public isolated transactional function getTimelineStepList(int experimentId, string? pluginName, string? 'version, string? status, int? uncleared\-substep, boolean allAttributes = false, int 'limit = 100, int offset = 0, int sort = 1) returns TimelineStepFull[]|error {
public isolated transactional function getTimelineStepList(int experimentId, string? pluginName = (), string? 'version = (), string? status = (), int? unclearedSubstep = (), string? resultQuality = (), boolean allAttributes = false, int 'limit = 100, int offset = 0, int sort = 1) returns TimelineStepFull[]|error {

sql:ParameterizedQuery baseQuery = `SELECT TimelineStep.stepId, experimentId, sequence, `;
if configuredDBType == "sqlite" {
Expand All @@ -821,7 +823,7 @@ public isolated transactional function getTimelineStepList(int experimentId, str
stream<TimelineStepSQL, sql:Error?> timelineSteps;
timelineSteps = experimentDB->query(sql:queryConcat(
baseQuery,
timelineStepListFilter(experimentId, pluginName, 'version, status, uncleared\-substep),
timelineStepListFilter(experimentId, pluginName, 'version, status, unclearedSubstep, resultQuality),
` ORDER BY sequence `, sortOrder, limitFilter, `;`
));

Expand Down Expand Up @@ -1380,6 +1382,7 @@ public isolated transactional function saveTimelineSubstepInputData(int stepId,
#
# + experimentId - Experiment id
# + search - Search string to match
# + dataType - Data type to match
# + return - Return filter query fragment
public isolated function experimentDataFilter(int experimentId, string? search, string? dataType) returns sql:ParameterizedQuery {
sql:ParameterizedQuery[] filter = [` WHERE experimentId = ${experimentId} `];
Expand Down Expand Up @@ -1432,9 +1435,10 @@ public isolated function experimentListFilter(string? search) returns sql:Parame
# + pluginName - Plugin name filter
# + 'version - Plugin version filter
# + status - Plugin status filter
# + uncleared\-substep - Filter for (un)cleared substeps. If set to 1 (or any positive number), steps must have at least one uncleared substep. Else, set to -1 (or any negative number). Set to 0 if not specified.
# + unclearedSubstep - Filter for (un)cleared substeps. If set to 1 (or any positive number), steps must have at least one uncleared substep. Else, set to -1 (or any negative number). Set to 0 if not specified.
# + resultQuality - Result quality filter
# + return - Return filter query fragment
public isolated function timelineStepListFilter(int experimentId, string? pluginName, string? 'version, string? status, int? uncleared\-substep) returns sql:ParameterizedQuery {
public isolated function timelineStepListFilter(int experimentId, string? pluginName = (), string? 'version = (), string? status = (), int? unclearedSubstep = (), string? resultQuality = ()) returns sql:ParameterizedQuery {
sql:ParameterizedQuery filter = ` WHERE experimentId = ${experimentId} `;
if pluginName != () && pluginName != "" {
string pluginNameString = "%" + pluginName + "%";
Expand All @@ -1448,13 +1452,16 @@ public isolated function timelineStepListFilter(int experimentId, string? plugin
string statusString = "%" + status + "%";
filter = sql:queryConcat(filter, ` AND status LIKE ${statusString} `);
}
if uncleared\-substep != () && uncleared\-substep != 0 {
if unclearedSubstep != () && unclearedSubstep != 0 {
filter = sql:queryConcat(filter, ` AND EXISTS (SELECT * FROM TimelineSubstep WHERE TimelineSubstep.stepId = TimelineStep.stepId AND `);
if uncleared\-substep > 0 {
if unclearedSubstep > 0 {
filter = sql:queryConcat(filter, ` TimelineSubstep.cleared = 0) `);
} else {
filter = sql:queryConcat(filter, ` TimelineSubstep.cleared = 1) `);
}
}
if resultQuality != () && resultQuality != "" {
filter = sql:queryConcat(filter, ` AND resultQuality = ${resultQuality} `);
}
return filter;
}
4 changes: 2 additions & 2 deletions modules/database/export.bal
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public isolated transactional function getTimelineStepLimit(int experimentId) re
// check if < 10000 steps
int count = check experimentDB->queryRow(sql:queryConcat(
`SELECT count(*) FROM TimelineStep `,
timelineStepListFilter(experimentId, (), (), (), ()), `;`
timelineStepListFilter(experimentId), `;`
));
if count > 10000 {
log:printError(string `Exceeded limit for TimelineSteps. Limit is set to 10000. Found ${count} steps. Only return 10000 steps.`);
Expand Down Expand Up @@ -333,7 +333,7 @@ public isolated transactional function getExperimentDBExport(ExperimentFull expe

if config.restriction != "DATA" {
// iterate over timeline steps
TimelineStepFull[] timelineStepListDb = check getTimelineStepList(experiment.experimentId, (), (), (), (), allAttributes = true, 'limit = check getTimelineStepLimit(experiment.experimentId));
TimelineStepFull[] timelineStepListDb = check getTimelineStepList(experiment.experimentId, allAttributes = true, 'limit = check getTimelineStepLimit(experiment.experimentId));

int[] stepList = [];
if config.restriction == "STEPS" {
Expand Down

0 comments on commit 8140161

Please sign in to comment.