-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sammyteillet/dat 50 aau i see a drift only for past data (#25)
* refactor: rename folder notion_database * feature: filter data after first day only for drift * refactor: remove some comments
- Loading branch information
Showing
6 changed files
with
78 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package charts | ||
|
||
import ( | ||
"log" | ||
"sort" | ||
"time" | ||
|
||
"github.com/data-drift/kpi-git-history/common" | ||
"github.com/data-drift/kpi-git-history/reports" | ||
) | ||
|
||
func FilterAndSortByCommitTimestamp(dataSortableArray []CommitData, driftDay time.Time) []CommitData { | ||
filteredArray := make([]CommitData, 0, len(dataSortableArray)) | ||
for i := range dataSortableArray { | ||
timestamp := time.Unix(dataSortableArray[i].CommitTimestamp, 0) | ||
if timestamp.After(driftDay) { | ||
filteredArray = append(filteredArray, dataSortableArray[i]) | ||
} | ||
} | ||
|
||
sort.Slice(filteredArray, func(i, j int) bool { | ||
return filteredArray[i].CommitTimestamp < filteredArray[j].CommitTimestamp | ||
}) | ||
|
||
return filteredArray | ||
} | ||
|
||
func getFirstDateOfPeriod(periodKey string) time.Time { | ||
timegrain, _ := reports.GetTimeGrain(periodKey) | ||
var lastDay time.Time | ||
switch timegrain { | ||
case common.Day: | ||
lastDay, _ = time.Parse("2006-01-02", periodKey) | ||
case common.Week: | ||
periodTime, _ := time.Parse("2006-W01", periodKey) | ||
lastDay = periodTime.AddDate(0, 0, (7 - int(periodTime.Weekday()))).Add(time.Duration(23)*time.Hour + time.Duration(59)*time.Minute + time.Duration(59)*time.Second) | ||
case common.Month: | ||
periodTime, _ := time.Parse("2006-01", periodKey) | ||
|
||
lastDay = periodTime.AddDate(0, 1, -1).Add(time.Duration(23)*time.Hour + time.Duration(59)*time.Minute + time.Duration(59)*time.Second) | ||
case common.Quarter: | ||
periodTime, _ := reports.ParseQuarterDate(periodKey) | ||
|
||
lastDay = periodTime | ||
case common.Year: | ||
periodTime, _ := time.Parse("2006", periodKey) | ||
lastDay = time.Date(periodTime.Year(), 12, 31, 23, 59, 59, 0, time.UTC) | ||
default: | ||
log.Fatalf("Invalid time grain: %s", timegrain) | ||
} | ||
return lastDay | ||
|
||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters