func CalculateGlukitScore(context context.Context, glukitUser *model.GlukitUser, endOfPeriod time.Time) (glukitScore *model.GlukitScore, err error) {
	upperBound := util.GetMidnightUTCBefore(endOfPeriod)
	lowerBound := upperBound.AddDate(0, 0, -1*GLUKIT_SCORE_PERIOD)
	score := model.UNDEFINED_SCORE_VALUE
	log.Debugf(context, "Getting reads for glukit score calculation from [%s] to [%s]", lowerBound, upperBound)
	if reads, err := store.GetGlucoseReads(context, glukitUser.Email, lowerBound, upperBound); err != nil {
		return &model.UNDEFINED_SCORE, err
	} else {
		readCount := 0
		score = 0
		for i := 0; i < len(reads) && i < READS_REQUIREMENT; i++ {
			score = score + int64(CalculateIndividualReadScoreWeight(context, reads[i]))
			readCount = readCount + 1
		}
		log.Infof(context, "Readcount of [%d] used for glukit score calculation of [%d]", readCount, score)
		if readCount < READS_REQUIREMENT {
			log.Infof(context, "Received only [%d] but required [%d] to calculate valid GlukitScore", readCount, READS_REQUIREMENT)
			return &model.UNDEFINED_SCORE, nil
		}
	}
	if score == model.UNDEFINED_SCORE_VALUE {
		glukitScore = &model.UNDEFINED_SCORE
	} else {
		glukitScore = &model.GlukitScore{
			Value:          score,
			LowerBound:     lowerBound,
			UpperBound:     upperBound,
			CalculatedOn:   time.Now(),
			ScoringVersion: SCORING_VERSION}
	}
	return glukitScore, nil
}
CalculateGlukitScore computes the GlukitScore for a given user. This is done in a few steps:
1. Get the latest GLUKIT_SCORE_PERIOD days of reads
2. For the most recent reads up to READS_REQUIREMENT, calculate the individual score
contribution and add it to the GlukitScore.
3. If we had enough reads to satisfy the requirements, we return the sum of
all individual score contributions.
package engine
import (
	"github.com/alexandre-normand/glukit/app/apimodel"
	"github.com/alexandre-normand/glukit/app/model"
	"github.com/alexandre-normand/glukit/app/store"
	"github.com/alexandre-normand/glukit/app/util"
	"context"
	"google.golang.org/appengine/log"
	"google.golang.org/appengine/taskqueue"
	"math"
	"time"
)
const (
	LOW_MULTIPLIER = 1
	HIGH_MULTIPLIER = 2
	GLUKIT_SCORE_PERIOD = 7
	READS_REQUIREMENT = 288 * (GLUKIT_SCORE_PERIOD - 1)
	SCORING_VERSION = 1
	MAX_CALCULATION_DAYS_TO_LOOK_BACK = 30
)
var A1C_CALCULATION_START = time.Unix(1388534400, 0)