Skip to content

Commit

Permalink
fix: assorted hotfixes from demo review
Browse files Browse the repository at this point in the history
  • Loading branch information
PThorpe92 committed Dec 14, 2024
1 parent d2264b8 commit 73bbfb8
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions backend/src/database/seed_demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,32 @@ func (db *DB) RunDemoSeed(facilityId uint) error {
return newCreateDBError(err, "open_content_urls")
}
}
sixMonthsAgo := time.Now().AddDate(0, 0, -180)
sixMonthsAgo := time.Now().AddDate(0, -6, 0)
for _, user := range users {
// seed user activity for six months for each user
mpu := 0 // milestones per user
for _, course := range courses {
mpu = 0
startDate := course.StartDt
if startDate == nil {
startDate = &sixMonthsAgo
}
diffTillNow := (time.Since(*startDate).Hours() / 24)
courseTotalTime := int64(0)
for i := 0; i < 180; i++ {
randTime := rand.Int63n(500)
for i := 0; i < int(diffTillNow); i++ {
randTime := rand.Int63n(50)
externalID := ""
if i == 0 {
externalID = "SEEDED_ACTIVITY"
} else {
externalID = uuid.NewString()
}
if err := db.Exec("SELECT insert_daily_activity(?, ?, ?, ?, ?)", user.ID, course.ID, models.ContentInteraction, courseTotalTime, externalID).Error; err != nil {
nDaysAgo := time.Now().AddDate(0, 0, -i)
if err := db.Exec("INSERT INTO activities (user_id, course_id, total_time, time_delta, type, created_at, external_id) values (?, ?, ?, ?, ?, ?, ?)", user.ID, course.ID, courseTotalTime, randTime, models.ContentInteraction, nDaysAgo, externalID).Error; err != nil {
continue
}
courseTotalTime += randTime
if i%(rand.Intn(30)+1) == 0 {
if course.TotalProgressMilestones >= uint(mpu) {
if i%(rand.Intn(8)+1) == 0 {
if course.TotalProgressMilestones <= uint(mpu+rand.Intn(3)) {
continue
}
milestone := models.Milestone{UserID: user.ID, CourseID: course.ID, ExternalID: uuid.NewString(), Type: models.AssignmentSubmission, IsCompleted: false}
Expand Down

0 comments on commit 73bbfb8

Please sign in to comment.