From 5140aa708b8a6743e89b29b64a4f87a4de9baed6 Mon Sep 17 00:00:00 2001 From: Xevion Date: Thu, 1 Feb 2024 15:21:26 -0600 Subject: [PATCH] Make slope calculation part of baseExpiry I realized that archived classes would have unusually low expiry times without the multiplier in plce Also changed the IsViewOnlyTerm func name, new term "Archive" for this --- helpers.go | 2 +- scrape.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/helpers.go b/helpers.go index dcd6f93..eca8a6b 100644 --- a/helpers.go +++ b/helpers.go @@ -370,7 +370,7 @@ func EncodeParams(params map[string]*[]string) string { } // TODO: Add a function to check if a term is view-only -func IsViewOnlyTerm(term string) bool { +func IsTermArchived(term string) bool { return false } diff --git a/scrape.go b/scrape.go index d350b15..09315a3 100644 --- a/scrape.go +++ b/scrape.go @@ -171,24 +171,24 @@ func ScrapeMajor(subject string) error { // count is the number of courses that were scraped. // priority is a boolean indicating whether the major is a priority major. func CalculateExpiry(term string, count int, priority bool) time.Duration { + // An hour for every 100 classes + baseExpiry := time.Hour * time.Duration(count/100) + // Subjects with less than 50 classes have a reversed expiry (less classes, longer interval) // 1 class => 12 hours, 49 classes => 1 hour if count < 50 { hours := Slope(Point{1, 12}, Point{49, 1}, float64(count)).Y - return time.Duration(hours * float64(time.Hour)) + baseExpiry = time.Duration(hours * float64(time.Hour)) } - // An hour for every 100 classes - baseExpiry := time.Hour * time.Duration(count/100) - // If the subject is a priority, then the expiry is halved without variance if priority { return baseExpiry / 3 } - // If the term is considered "view only", then the expiry is multipled by 5 + // If the term is considered "view only" or "archived", then the expiry is multiplied by 5 var expiry = baseExpiry - if IsViewOnlyTerm(term) { + if IsTermArchived(term) { expiry *= 5 }