activity-browser
activity-browser copied to clipboard
Sorting Contribution Analysis tables better
Currently, results tables in EF contributions
and Process contributions
sort the data (and also the graphs) based on the first data (numbers) column large >> small. While this is nice, it may be nicest to sort on the larges contributor in total. We could achieve this by temporarily creating a new column in the pandas df that takes the max()
of the row, and sort the table on that. As these tables are generally not large, this extra step should not take any meaningful time.
Sorting the data like this would allow AB to show data based on the most relevant contributors in general, not just for the first process shown. e.g. the figure below, which is sorted on the lowest bar in the graph (and first column):
We could instead sort on the largest contributors in total, like the excel example below:
This should be done here:
https://github.com/LCA-ActivityBrowser/activity-browser/blob/1715a175814bf12abf0d7dec25ff9f7694b42e52/activity_browser/bwutils/multilca.py#L393
ca.sort_array()
both sorts and filters the data. We can re-sort afterwards with the improved sorting.
we can sort like this (source):
maxCol = lambda x: max(x.min(), x.max(), key=abs)
For the second sorting on this col, we can assume almost sorted arrangement, and thus we should use Timsort, as explained here