From 430100f9302817d6899b1c39368df95bdcfe343b Mon Sep 17 00:00:00 2001 From: Katie Worton Date: Thu, 9 May 2024 08:49:00 +0100 Subject: [PATCH] squad-track-duration: Update sorting to fix legend order Update the sorting of the data so it is sorted by the legend lines then by created_at. This will ensure the data for each graph line is in the correct order while also putting the legend in alphabetical order. Signed-off-by: Katie Worton --- squad-track-duration | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/squad-track-duration b/squad-track-duration index f94a7d8..1ad1a30 100755 --- a/squad-track-duration +++ b/squad-track-duration @@ -313,8 +313,13 @@ def run(): mean_boottimes1 = df_grouping1["boottime"].mean() - # Convert the Series object back to a DataFrame then sort by the created_at - mean_boottimes1 = mean_boottimes1.reset_index().sort_values(by="created_at") + # Convert the Series object back to a DataFrame then sort values first by + # device, then by created_at. This will make the graph legend alphabetised + # while also ensuring the dates for each line are ordered by created_at so + # the graph's lines will be drawn correctly. + mean_boottimes1 = mean_boottimes1.reset_index().sort_values( + by=["device", "created_at"] + ) # Calculate how many boottimes we averaged over per device count_per_device1 = df_grouping1["boottime"].count().groupby("device").sum() @@ -369,10 +374,12 @@ def run(): mean_boottimes2 = df_grouping2["boottime"].mean() - # Convert the Series object back to a DataFrame then sort by the created_at - # and build_name_device + # Convert the Series object back to a DataFrame then sort values first by + # build_name_device, then by created_at. This will make the graph legend + # alphabetised while also ensuring the dates for each line are ordered by + # created_at so the graph's lines will be drawn correctly. mean_boottimes2 = mean_boottimes2.reset_index().sort_values( - by=["created_at", "build_name_device"] + by=["build_name_device", "created_at"] ) logger.debug(mean_boottimes2.info())