Skip to content

Commit 443c183

Browse files
authored
Merge pull request #6 from grove-platform/gdcd-fixups-date-handling
GDCD and DODEC fixups: date handling
2 parents 58b5a85 + cc3dbc4 commit 443c183

4 files changed

Lines changed: 37 additions & 6 deletions

File tree

audit/dodec/src/PerformAggregation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func PerformAggregation(db *mongo.Database, ctx context.Context) {
3838
}
3939
//substringToFindInCodeExamples := "defaultauthdb"
4040
//substringToFindInPageURL := "code-examples"
41-
monthForReporting := time.November
41+
monthForReporting := time.January
4242

4343
for _, collectionName := range collectionNames {
4444
//simpleMap = aggregations.GetCategoryCounts(db, collectionName, simpleMap, ctx)

audit/dodec/src/aggregations/FindUsageExamplesForMonth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
// track the product and sub-product in the types.NewAppliedUsageExampleCounterByProductSubProduct
1818
func FindUsageExamplesForMonth(db *mongo.Database, collectionName string, productSubProductCounter types.NewAppliedUsageExampleCounterByProductSubProduct, monthForReporting time.Month, ctx context.Context) types.NewAppliedUsageExampleCounterByProductSubProduct {
1919
// Target a specific month (example for November 2025):
20-
targetYear := 2025
20+
targetYear := 2026
2121
monthStart := time.Date(targetYear, monthForReporting, 1, 0, 0, 0, 0, time.UTC)
2222
monthEnd := monthStart.AddDate(0, 1, 0) // First day of next month
2323
// Define the aggregation pipeline

audit/gdcd/db/BackUpDB.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,10 @@ func getBackupDbNames(client *mongo.Client, ctx context.Context) []string {
120120

121121
// Parse the dates from the backup database names to find the oldest backup database.
122122
func findOldestBackup(backupNames []string) string {
123-
// Define a reference year (we need a year to work with Go's time package)
124-
const year = 2025 // Arbitrary year for comparison purposes
123+
// Get the current date to determine the year for each backup
124+
now := time.Now()
125+
currentMonth := now.Month()
126+
currentYear := now.Year()
125127

126128
// Variables to track the oldest date and its corresponding string
127129
var oldestDate time.Time
@@ -151,6 +153,13 @@ func findOldestBackup(backupNames []string) string {
151153
continue
152154
}
153155

156+
// Determine the year for this backup
157+
// If the backup month is after the current month, it must be from the previous year
158+
year := currentYear
159+
if month > currentMonth {
160+
year = currentYear - 1
161+
}
162+
154163
// Create a time.Time object for the given month and day
155164
date := time.Date(year, month, day, 0, 0, 0, 0, time.UTC)
156165

audit/gdcd/scripts/parse-log.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@ func main() {
5656
codeExampleRemovedRegex := regexp.MustCompile(`Code example removed: Page ID: (.+), (\d+) code examples removed`)
5757
codeExampleCreatedRegex := regexp.MustCompile(`Code example created: Page ID: (.+), (\d+) new code examples added`)
5858
appliedUsageRegex := regexp.MustCompile(`Applied usage example added: Page ID: (.+), (\d+) new applied usage examples added`)
59+
claimedAppliedUsageRegex := regexp.MustCompile(`New applied usage examples for (.+): (\d+)`)
5960

6061
removedPages := make(map[string]PageEvent)
6162
createdPages := make(map[string]PageEvent)
6263
appliedUsageMap := make(map[string]AppliedUsageExample)
64+
claimedAppliedUsageByProject := make(map[string]int)
6365

6466
currentProject := ""
6567

@@ -133,6 +135,13 @@ func main() {
133135
Count: count,
134136
}
135137
}
138+
139+
// Parse claimed applied usage examples per project
140+
if matches := claimedAppliedUsageRegex.FindStringSubmatch(line); matches != nil {
141+
project := matches[1]
142+
count, _ := strconv.Atoi(matches[2])
143+
claimedAppliedUsageByProject[project] = count
144+
}
136145
}
137146

138147
if err := scanner.Err(); err != nil {
@@ -185,7 +194,7 @@ func main() {
185194
}
186195

187196
// Print results
188-
printResults(movedPages, trulyCreatedPages, trulyRemovedPages, appliedUsageMap)
197+
printResults(movedPages, trulyCreatedPages, trulyRemovedPages, appliedUsageMap, claimedAppliedUsageByProject)
189198
}
190199

191200
// isPageMoved checks if a removed page and created page represent the same page that was moved
@@ -213,7 +222,7 @@ func isPageMoved(removedID, createdID string, removedCodeExamples, createdCodeEx
213222
return false
214223
}
215224

216-
func printResults(movedPages []MovedPage, trulyCreatedPages []PageEvent, trulyRemovedPages []PageEvent, appliedUsageMap map[string]AppliedUsageExample) {
225+
func printResults(movedPages []MovedPage, trulyCreatedPages []PageEvent, trulyRemovedPages []PageEvent, appliedUsageMap map[string]AppliedUsageExample, claimedAppliedUsageByProject map[string]int) {
217226
fmt.Println("=== MOVED PAGES ===")
218227
if len(movedPages) == 0 {
219228
fmt.Println("No moved pages found.")
@@ -277,4 +286,17 @@ func printResults(movedPages []MovedPage, trulyCreatedPages []PageEvent, trulyRe
277286
}
278287
fmt.Printf("\nTotal new applied usage examples: %d\n", totalNewAppliedUsage)
279288
}
289+
290+
// Print claimed applied usage examples per project from the logs
291+
fmt.Println("\n=== CLAIMED APPLIED USAGE EXAMPLES PER PROJECT ===")
292+
if len(claimedAppliedUsageByProject) == 0 {
293+
fmt.Println("No claimed applied usage examples found in logs.")
294+
} else {
295+
totalClaimed := 0
296+
for project, count := range claimedAppliedUsageByProject {
297+
fmt.Printf("CLAIMED [%s]: %d applied usage examples\n", project, count)
298+
totalClaimed += count
299+
}
300+
fmt.Printf("\nTotal claimed applied usage examples: %d\n", totalClaimed)
301+
}
280302
}

0 commit comments

Comments
 (0)