Documentation ¶
Overview ¶
The engine package is where the magic happens. The analysis and insightful bits of data we generate are computed by this package. It's the Glukit engine™.
Index ¶
- Constants
- Variables
- func CalculateA1CEstimate(context context.Context, reads []apimodel.GlucoseRead) (a1c *model.A1CEstimate, err error)
- func CalculateGlukitScore(context context.Context, glukitUser *model.GlukitUser, endOfPeriod time.Time) (glukitScore *model.GlukitScore, err error)
- func CalculateIndividualReadScoreWeight(context context.Context, read apimodel.GlucoseRead) (weightedScoreContribution float64)
- func CalculateUserFacingScore(internal model.GlukitScore) (external *int64)
- func EstimateA1C(context context.Context, glukitUser *model.GlukitUser, endOfPeriod time.Time) (a1c *model.A1CEstimate, err error)
- func RunA1CBatchCalculation(context context.Context, userEmail string, lowerBound time.Time)
- func RunGlukitScoreBatchCalculation(context context.Context, userEmail string, lowerBound time.Time)
- func StartA1CCalculationBatch(context context.Context, glukitUser *model.GlukitUser) (err error)
- func StartGlukitScoreBatch(context context.Context, glukitUser *model.GlukitUser) (err error)
Constants ¶
const ( A1C_READ_COVERAGE_REQUIREMENT_IN_DAYS = 90 // A1C estimation scoring period requirement A1C_ESTIMATION_SCORE_PERIOD = 95 A1C_SCORING_VERSION = 3 )
const ( PERIODS_PER_BATCH = 6 BATCH_CALCULATION_QUEUE_NAME = "batch-calculation" GLUKIT_SCORE_BATCH_CALCULATION_FUNCTION_NAME = "runGlukitScoreCalculationChunk" A1C_BATCH_CALCULATION_FUNCTION_NAME = "runA1CCalculationChunk" )
const ( // The multiplier applied to any deviation from the target, on the low spectrum (i.e. anything less than 83) LOW_MULTIPLIER = 1 // The multiplier applied to any deviation from the target, on the high spectrum (i.e. anything above 83) HIGH_MULTIPLIER = 2 // Glukit score calculation period GLUKIT_SCORE_PERIOD = 7 // One period of reads minus on day for potential data gaps READS_REQUIREMENT = 288 * (GLUKIT_SCORE_PERIOD - 1) // The current Glukit scoring version SCORING_VERSION = 1 // The max number of days to look back when starting a new batch of calculation MAX_CALCULATION_DAYS_TO_LOOK_BACK = 30 )
Variables ¶
var A1C_CALCULATION_START = time.Unix(1388534400, 0)
January 1st, 2014
var RunA1CCalculationChunk = delay.Func(A1C_BATCH_CALCULATION_FUNCTION_NAME, func(context context.Context, userEmail string, lowerBound time.Time) { log.Criticalf(context, "This function purely exists as a workaround to the \"initialization loop\" error that "+ "shows up because the function calls itself. This implementation defines the same signature as the "+ "real one which we define in init() to override this implementation!") })
var RunGlukitScoreCalculationChunk = delay.Func(GLUKIT_SCORE_BATCH_CALCULATION_FUNCTION_NAME, func(context context.Context, userEmail string, lowerBound time.Time) { log.Criticalf(context, "This function purely exists as a workaround to the \"initialization loop\" error that "+ "shows up because the function calls itself. This implementation defines the same signature as the "+ "real one which we define in init() to override this implementation!") })
Functions ¶
func CalculateA1CEstimate ¶
func CalculateA1CEstimate(context context.Context, reads []apimodel.GlucoseRead) (a1c *model.A1CEstimate, err error)
CalculateA1CEstimate calculates an estimate of a a1c given the last 3 months of data. The current algo is naively assuming that the average of the last 3 months will be an approximation of the a1c.
func CalculateGlukitScore ¶
func CalculateGlukitScore(context context.Context, glukitUser *model.GlukitUser, endOfPeriod time.Time) (glukitScore *model.GlukitScore, err error)
CalculateGlukitScore computes the GlukitScore for a given user. This is done in a few steps:
- Get the latest GLUKIT_SCORE_PERIOD days of reads
- For the most recent reads up to READS_REQUIREMENT, calculate the individual score contribution and add it to the GlukitScore.
- If we had enough reads to satisfy the requirements, we return the sum of all individual score contributions.
func CalculateIndividualReadScoreWeight ¶
func CalculateIndividualReadScoreWeight(context context.Context, read apimodel.GlucoseRead) (weightedScoreContribution float64)
An individual score is either 0 if it's straight on perfection (83) or it's the deviation from 83 weighted by whether it's high (multiplier of 2) or lower (multiplier of 1)
func CalculateUserFacingScore ¶
func CalculateUserFacingScore(internal model.GlukitScore) (external *int64)
CalculateUserFacingScore maps an internal GlukitScore to a user facing value (should be between 0 and 100)
func EstimateA1C ¶
func EstimateA1C(context context.Context, glukitUser *model.GlukitUser, endOfPeriod time.Time) (a1c *model.A1CEstimate, err error)
func RunA1CBatchCalculation ¶
func StartA1CCalculationBatch ¶
func StartA1CCalculationBatch(context context.Context, glukitUser *model.GlukitUser) (err error)
StartA1CCalculationBatch tries to calculate a1c estimates for any week following the most recent calculated glukit score (a hack, we should have the most recent a1c calculation date)
func StartGlukitScoreBatch ¶
func StartGlukitScoreBatch(context context.Context, glukitUser *model.GlukitUser) (err error)
StartGlukitScoreBatch tries to calculate glukit scores for any week following the most recent calculated score
Types ¶
This section is empty.