From d14cd1695c885df01626bb284b68d90068ddc2e0 Mon Sep 17 00:00:00 2001 From: jessicaqgomez Date: Mon, 24 Jul 2023 10:10:53 -0500 Subject: [PATCH] Get monthly average results in statistics filter if the query is less than two years --- utils/dbutils.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/utils/dbutils.go b/utils/dbutils.go index 955fe477..1abb4c7a 100644 --- a/utils/dbutils.go +++ b/utils/dbutils.go @@ -45,14 +45,15 @@ func DateFormat(startTime time.Time, endTime time.Time, columnName string) strin yearsBetween := endTime.Year() - startTime.Year() var dateFormat string switch { - // if the date range is greater than or equal to one month the values are averaged per month - case (monthsBetween >= 1 || monthsBetween < 0 || startTime.Year() == 1) && yearsBetween == 0: - dateFormat = "DATE_FORMAT(" + columnName + ",'%Y-%m-01')" - // if the date range is greater than or equal to one year the values are averaged per year - case yearsBetween > 0: + case monthsBetween == 0 && yearsBetween == 0: + dateFormat = "DATE_FORMAT(" + columnName + ",'%Y-%m-%d')" + // if the date range is greater to 2 year the values are averaged per year + case yearsBetween > 2: dateFormat = "DATE_FORMAT(" + columnName + ",'%Y-01-01')" + // if the date range is less or equal to 2 years and months between are more than one the values are + // averaged per month default: - dateFormat = "DATE_FORMAT(" + columnName + ",'%Y-%m-%d')" + dateFormat = "DATE_FORMAT(" + columnName + ",'%Y-%m-01')" } return dateFormat }