Skip to content

Commit

Permalink
Get monthly average results in statistics filter if the query is less…
Browse files Browse the repository at this point in the history
… than two years
  • Loading branch information
jessicaqgomez committed Jul 24, 2023
1 parent fadf074 commit 63844e3
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions utils/dbutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ 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
}

0 comments on commit 63844e3

Please sign in to comment.