<commit_before>package unusedaccounts

import (
	"time"

	"github.com/trackit/trackit/db"
	"github.com/trackit/trackit/models"
)

const unusedThreshold = time.Second * 15
const deleteThreshold = unusedThreshold + time.Second*45

var remaindersThresholds = []time.Duration{unusedThreshold, unusedThreshold + time.Second*15, unusedThreshold + time.Second*30}

// CheckUnusedAccounts checks for unused accounts, sends reminders and delete unused data
func CheckUnusedAccounts() error {
	users, err := models.GetUnusedAccounts(db.Db, unusedThreshold)

	if err != nil {
		return err
	}

	for _, user := range users {
		if user != nil {
			checkUnusedAccount(*user)
		}
	}

	return nil
}

func checkUnusedAccount(user models.User) error {
	unusedTime := time.Now().Sub(user.LastSeen)

	if unusedTime > deleteThreshold {
		return deleteData(user)
	}

	thresholdStage := 0
	for i, remainderThreshold := range remaindersThresholds {
		if unusedTime > remainderThreshold {
			thresholdStage = i
		} else {
			break
		}
	}

	var err error = nil

	if user.LastUnusedReminder.Sub(user.LastSeen) < remaindersThresholds[thresholdStage] {
		err = sendRemainder(user)

		user.LastUnusedReminder = time.Now()
		user.Update(db.Db)
	}

	return err
}
<commit_msg>Defined realistic thresholds for unused accounts<commit_after>package unusedaccounts

import (
	"time"

	"github.com/trackit/trackit/db"
	"github.com/trackit/trackit/models"
)

const day = time.Hour * 24
const month = day * 30

const unusedThreshold = month
const deleteThreshold = unusedThreshold + month

var remaindersThresholds = []time.Duration{unusedThreshold, unusedThreshold + (month - day*7), unusedThreshold + (month - day*3), unusedThreshold + (month - day*1)}

// CheckUnusedAccounts checks for unused accounts, sends reminders and delete unused data
func CheckUnusedAccounts() error {
	users, err := models.GetUnusedAccounts(db.Db, unusedThreshold)

	if err != nil {
		return err
	}

	for _, user := range users {
		if user != nil {
			checkUnusedAccount(*user)
		}
	}

	return nil
}

func checkUnusedAccount(user models.User) error {
	unusedTime := time.Now().Sub(user.LastSeen)

	if unusedTime > deleteThreshold {
		return deleteData(user)
	}

	thresholdStage := 0
	for i, remainderThreshold := range remaindersThresholds {
		if unusedTime > remainderThreshold {
			thresholdStage = i
		} else {
			break
		}
	}

	var err error = nil

	if user.LastUnusedReminder.Sub(user.LastSeen) < remaindersThresholds[thresholdStage] {
		err = sendRemainder(user)

		user.LastUnusedReminder = time.Now()
		user.Update(db.Db)
	}

	return err
}

{'fraction_non_alphanumeric': 0.10166215693853885, 'fraction_numerical': 0.006571318129107074, 'mean_word_length': 4.347107438016529, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4923302', 'n_tokens_mistral': 890, 'n_tokens_neox': 822, 'n_words': 203}