Skip to content

Commit

Permalink
feat: add activity calc days in config file (#173)
Browse files Browse the repository at this point in the history
* feat: add activity days in config file

* style: apply fmt formatting

* refactor: add IsSet check on config value

* feat: defaulting to 60 days for vitality calc
  • Loading branch information
libremente authored Sep 7, 2020
1 parent 8e5f8cf commit bf858f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions crawler/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ OUTPUT_DIR = "/var/crawler/output"
# Blacklist folder
BLACKLIST_FOLDER = "blacklist/"
BLACKLIST_PATTERN = "*.yml"

# Number of days for activity (vitality index) calculation
ACTIVITY_DAYS = 60
10 changes: 7 additions & 3 deletions crawler/crawler/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,16 @@ func (c *Crawler) ProcessRepo(repository Repository) {
log.Errorf("[%s] error while cloning: %v", repository.Name, err)
}

// Calculate Repository activity index and vitality.
activityIndex, vitality, err := repository.CalculateRepoActivity(60)
// Calculate Repository activity index and vitality. Defaults to 60 days.
var activityDays int = 60
if viper.IsSet("ACTIVITY_DAYS") {
activityDays = viper.GetInt("ACTIVITY_DAYS")
}
activityIndex, vitality, err := repository.CalculateRepoActivity(activityDays)
if err != nil {
log.Errorf("[%s] error calculating activity index: %v", repository.Name, err)
}
log.Infof("[%s] activity index: %f", repository.Name, activityIndex)
log.Infof("[%s] activity index in the last %d days: %f", repository.Name, activityDays, activityIndex)
var vitalitySlice []int
for i := 0; i < len(vitality); i++ {
vitalitySlice = append(vitalitySlice, int(vitality[i]))
Expand Down

0 comments on commit bf858f4

Please sign in to comment.