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 #6070: hierarchical sorting #7163

Merged
merged 19 commits into from
Aug 8, 2024
50 changes: 40 additions & 10 deletions sirepo/package_data/static/js/raydata.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ SIREPO.app.directive('scansTable', function() {
<button class="btn btn-info btn-xs raydata-button" data-ng-click="pageNext()" data-ng-disabled="! canNextPage()"><span class="glyphicon glyphicon-chevron-right"></span></button>
</div>
<div data-ng-if="columnsService.allColumns" data-column-picker=""></div>
<button data-ng-if="analysisStatus === 'allStatuses'" class="btn btn-info btn-xs raydata-button" data-ng-click="clearSort()">Clear Sort</button>
<button class="btn btn-info btn-xs raydata-button pull-right" data-ng-show="showPdfButton()" data-ng-click="downloadSelectedAnalyses()">Download Selected Analysis PDFs</button>
<table class="table table-striped table-hover">
<thead>
Expand Down Expand Up @@ -502,8 +503,7 @@ SIREPO.app.directive('scansTable', function() {
let scanArgs = {
pageCount: 0,
pageNumber: 0,
sortColumn: $scope.analysisStatus == 'queued' ? 'queue order' : 'start',
sortOrder: $scope.analysisStatus == 'queued',
sortColumns: defaultSortColumns(),
};

const errorOptions = {
Expand Down Expand Up @@ -540,6 +540,30 @@ SIREPO.app.directive('scansTable', function() {
}
}

function decodeSortColumns(encoded) {
let columns = new Map();
encoded.split(';').forEach((e) => {
rorour marked this conversation as resolved.
Show resolved Hide resolved
let z = e.split(',');
if (z[1] === 'true') {
columns.set(z[0], true);
} else {
columns.set(z[0], false);
}
});
return columns;
}

function defaultSortColumns() {
return new Map(
[
[
$scope.analysisStatus == 'queued' ? 'queue order' : 'start',
$scope.analysisStatus == 'queued'
]
]
);
}

function findScan(scanId) {
return $scope.scans[
$scope.scans.findIndex(s => s.rduid === scanId)
Expand Down Expand Up @@ -578,8 +602,7 @@ SIREPO.app.directive('scansTable', function() {
}
scanArgs.pageCount = scanInfo.pageCount || 0;
scanArgs.pageNumber = scanInfo.pageNumber;
scanArgs.sortColumn = scanInfo.sortColumn;
scanArgs.sortOrder = scanInfo.sortOrder;
scanArgs.sortColumns = decodeSortColumns(scanInfo.sortColumns);
updatePageLocation();
}

Expand Down Expand Up @@ -628,8 +651,7 @@ SIREPO.app.directive('scansTable', function() {
pageNumber: scanArgs.pageNumber,
searchText: m.searchText,
searchTerms: buildSearchTerms(m.searchTerms),
sortColumn: scanArgs.sortColumn,
sortOrder: scanArgs.sortOrder,
sortColumns: [...scanArgs.sortColumns.entries()].join(';')
}
},
errorOptions
Expand Down Expand Up @@ -677,12 +699,12 @@ SIREPO.app.directive('scansTable', function() {
}

$scope.arrowClass = column => {
if (scanArgs.sortColumn !== column) {
if (! scanArgs.sortColumns.has(column)) {
return {};
}
return {
glyphicon: true,
[`glyphicon-arrow-${scanArgs.sortOrder ? 'up' : 'down'}`]: true,
[`glyphicon-arrow-${scanArgs.sortColumns.get(column) ? 'up' : 'down'}`]: true,
};
};

Expand All @@ -694,6 +716,10 @@ SIREPO.app.directive('scansTable', function() {
return ! $scope.isLoadingNewScans && (scanArgs.pageNumber > 0);
};

$scope.clearSort = () => {
scanArgs.sortColumns = new Map();
};

$scope.deleteCol = colName => {
appState.models.metadataColumns.selected.splice(
appState.models.metadataColumns.selected.indexOf(colName),
Expand Down Expand Up @@ -815,9 +841,13 @@ SIREPO.app.directive('scansTable', function() {
$scope.sortCol = column => {
if (! $scope.columnIsSortable(column)) {
return;
} else if (scanArgs.sortColumns.has(column)) {
scanArgs.sortColumns.set(column, ! scanArgs.sortColumns.get(column));
} else if ($scope.analysisStatus !== 'allStatuses') {
scanArgs.sortColumns = new Map([[column, true]]);
} else {
scanArgs.sortColumns.set(column, true);
}
scanArgs.sortColumn = column;
scanArgs.sortOrder = ! scanArgs.sortOrder;
sendScanRequest(true, true);
};

Expand Down
49 changes: 25 additions & 24 deletions sirepo/raydata/scan_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,25 +342,6 @@ def _search_params(req_data):
}
return q

def _sort_params(req_data):
c = _default_columns(req_data.catalogName).get(
req_data.sortColumn, req_data.sortColumn
)
s = [
(
c,
pymongo.ASCENDING if req_data.sortOrder else pymongo.DESCENDING,
),
]
if c != "time":
s.append(
(
"time",
pymongo.DESCENDING,
)
)
return s

c = sirepo.raydata.databroker.catalog(req_data.catalogName)
pc = math.ceil(
len(
Expand Down Expand Up @@ -498,6 +479,26 @@ def _request_scan_fields(self, req_data):
)


def _sort_params(req_data):
r = []
has_time = False
if req_data.sortColumns != "":
for x in req_data.sortColumns.split(";"):
x = x.split(",")
if x[1] == "true":
x[1] = pymongo.ASCENDING
else:
assert x[1] == "false", f"unrecognized sort order {x}"
x[1] = pymongo.DESCENDING
x[0] = _default_columns(req_data.catalogName).get(x[0], x[0])
if x[0] == "time":
has_time = True
r.append(x)
if not has_time:
r.append(("time", pymongo.DESCENDING))
return r


async def _init_analysis_processors():
global _ANALYSIS_PROCESSOR_TASKS

Expand Down Expand Up @@ -694,9 +695,10 @@ def _get_start_field(metadata, column):

def _scan_info_result(scans, page_count, req_data):
def _compare_values(v1, v2):
sort_column = _sort_params(req_data)[0][0]
# very careful compare - needs to account for missing values or mismatched types
v1 = v1.get(req_data.sortColumn)
v2 = v2.get(req_data.sortColumn)
v1 = v1.get(sort_column)
v2 = v2.get(sort_column)
if v1 is None and v2 is None:
return 0
if v1 is None:
Expand Down Expand Up @@ -729,16 +731,15 @@ def _compare_values(v1, v2):
s = sorted(
s,
key=functools.cmp_to_key(_compare_values),
reverse=not req_data.sortOrder,
reverse=not _sort_params(req_data)[0][1],
)
return PKDict(
data=PKDict(
scans=s,
cols=_display_columns(all_columns),
pageCount=page_count,
pageNumber=req_data.pageNumber,
sortColumn=req_data.sortColumn,
sortOrder=req_data.sortOrder,
sortColumns=req_data.sortColumns,
)
)

Expand Down