store

package
v0.0.0-...-a2a2cd2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2023 License: MIT, MIT Imports: 15 Imported by: 0

Documentation

Overview

This package provides the interface and functions to deal with the storage of data.

Index

Constants

View Source
const (
	// Number of GlukitScores to batch in a single PutMulti
	GLUKIT_SCORE_PUT_MULTI_SIZE = 10
)

Variables

View Source
var (
	// ErrNoImportedDataFound is returned when the user doesn't have data imported yet.
	ErrNoImportedDataFound = StoreError{"store: no imported data found", true}

	// ErrNoSteadySailorMatchFound is returned when the user doesn't have any steady sailor matching his profile
	ErrNoSteadySailorMatchFound = StoreError{"store: no match for a steady sailor found", true}
)

Functions

func FindSteadySailor

func FindSteadySailor(context context.Context, recipientEmail string) (sailorProfile *model.GlukitUser, key *datastore.Key, upperBound time.Time, err error)

FindSteadySailor queries the datastore for others users of the same type of diabetes. It will then select the match that has a top glukit score and return that user profile along with the upper boundary for its most recent day of reads. The steps involved are:

  • Find the user profile of the recipient
  • Query the data store for profile data that matches (using the type of diabetes) in ascending order of score value
  • A first time for users that are NOT internal
  • A second time including internal users (if the first one returns no match)
  • Filter out the recipient profile that could be returned in the search
  • If match found, get the profile of the steady sailor

func GetA1CEstimates

func GetA1CEstimates(context context.Context, email string, scanQuery ScoreScanQuery) (scores []model.A1CEstimate, err error)

GetA1CEstimates returns all a1c calculations for the given email address and matching the query parameters

func GetCalibrations

func GetCalibrations(context context.Context, email string, lowerBound time.Time, upperBound time.Time) (meals []apimodel.CalibrationRead, err error)

GetCalibrations returns all Calibration entries given a user's email address and the time boundaries. Not that the boundaries are both inclusive.

func GetExercises

func GetExercises(context context.Context, email string, lowerBound time.Time, upperBound time.Time) (exercises []apimodel.Exercise, err error)

GetExercises returns all Exercise entries given a user's email address and the time boundaries. Not that the boundaries are both inclusive.

func GetFileImportLog

func GetFileImportLog(context context.Context, userProfileKey *datastore.Key, fileId string) (fileImport *model.FileImportLog, err error)

GetFileImportLog retrieves a FileImportLog entry for a given file id. If it's the first time we import this file id, a zeroed FileImportLog element is returned

func GetGlucoseReads

func GetGlucoseReads(context context.Context, email string, lowerBound time.Time, upperBound time.Time) (reads []apimodel.GlucoseRead, err error)

GetGlucoseReads returns all GlucoseReads given a user's email address and the time boundaries. Not that the boundaries are both inclusive.

func GetGlukitScores

func GetGlukitScores(context context.Context, email string, scanQuery ScoreScanQuery) (scores []model.GlukitScore, err error)

GetGlukitScores returns all GlukitScores for the given email address and matching the query parameters

func GetGlukitUser

func GetGlukitUser(context context.Context, email string) (key *datastore.Key, userProfile *model.GlukitUser, err error)

func GetGlukitUserWithKey

func GetGlukitUserWithKey(context context.Context, key *datastore.Key) (userProfile *model.GlukitUser, err error)

func GetInjections

func GetInjections(context context.Context, email string, lowerBound time.Time, upperBound time.Time) (meals []apimodel.Injection, err error)

GetInjections returns all Injection entries given a user's email address and the time boundaries. Not that the boundaries are both inclusive.

func GetMeals

func GetMeals(context context.Context, email string, lowerBound time.Time, upperBound time.Time) (carbs []apimodel.Meal, err error)

GetMeals returns all Meal entries given a user's email address and the time boundaries. Not that the boundaries are both inclusive.

func GetUserData

func GetUserData(context context.Context, email string) (userProfile *model.GlukitUser, key *datastore.Key, upperBound time.Time, err error)

GetUserData returns a GlukitUser entry and the boundaries of its most recent complete reads. If the user doesn't have any imported data yet, GetUserData returns ErrNoImportedDataFound

func GetUserKey

func GetUserKey(context context.Context, email string) (key *datastore.Key)

GetUserKey returns the GlukitUser datastore key given its email address.

func GetUserProfile

func GetUserProfile(context context.Context, key *datastore.Key) (userProfile *model.GlukitUser, err error)

GetUserProfile returns the GlukitUser entry associated with the given datastore key. This can be obtained by calling GetUserKey.

func LogFileImport

func LogFileImport(context context.Context, userProfileKey *datastore.Key, fileImport model.FileImportLog) (key *datastore.Key, err error)

LogFileImport persist a log of a file import operation. A log entry is actually kept for each distinct file and NOT for every log import operation. That is, if we re-import and updated file, we should update the FileImportLog for that file but not create a new one. This is used to optimize and not reimport a file that hasn't been updated.

func StoreA1CBatch

func StoreA1CBatch(context context.Context, userEmail string, a1cs []model.A1CEstimate) error

StoreA1CBatch stores a batch of A1C calculations. The array could be of any size. A large batch of A1CEstimates will be internally split into multiple PutMultis.

func StoreCalibrationReads

func StoreCalibrationReads(context context.Context, userProfileKey *datastore.Key, daysOfCalibrationReads []apimodel.DayOfCalibrationReads) (keys []*datastore.Key, err error)

StoreCalibrationReads stores a batch of DayOfCalibrations elements. It is a optimized operation in that:

  1. One element represents a relatively short-and-wide entry of all calibration reads for a single day.
  2. We have multiple DayOfReads elements and we use a PutMulti to make this faster.

For details of how a single element of DayOfReads is physically stored, see the implementation of apimodel.Store and apimodel.Load.

func StoreDaysOfExercises

func StoreDaysOfExercises(context context.Context, userProfileKey *datastore.Key, daysOfExercises []apimodel.DayOfExercises) (keys []*datastore.Key, err error)

StoreDaysOfExercises stores a batch of DayOfExercises elements. It is a optimized operation in that:

  1. One element represents a relatively short-and-wide entry of all Exercises for a single day.
  2. We have multiple DayOfExercises elements and we use a PutMulti to make this faster.

For details of how a single element of DayOfExercises is physically stored, see the implementation of apimodel.Store and apimodel.Load.

func StoreDaysOfInjections

func StoreDaysOfInjections(context context.Context, userProfileKey *datastore.Key, daysOfInjections []apimodel.DayOfInjections) (keys []*datastore.Key, err error)

StoreDaysOfInjections stores a batch of DayOfInjections elements. It is a optimized operation in that:

  1. One element represents a relatively short-and-wide entry of all meals for a single day.
  2. We have multiple DayOfInjections elements and we use a PutMulti to make this faster.

For details of how a single element of DayOfInjections is physically stored, see the implementation of apimodel.Store and apimodel.Load.

func StoreDaysOfMeals

func StoreDaysOfMeals(context context.Context, userProfileKey *datastore.Key, daysOfMeals []apimodel.DayOfMeals) (keys []*datastore.Key, err error)

StoreDaysOfMeals stores a batch of DayOfMeals elements. It is a optimized operation in that:

  1. One element represents a relatively short-and-wide entry of all Meals for a single day.
  2. We have multiple DayOfMeals elements and we use a PutMulti to make this faster.

For details of how a single element of DayOfMeals is physically stored, see the implementation of apimodel.Store and apimodel.Load.

func StoreDaysOfReads

func StoreDaysOfReads(context context.Context, userProfileKey *datastore.Key, daysOfReads []apimodel.DayOfGlucoseReads) (keys []*datastore.Key, err error)

StoreDaysOfReads stores a batch of DayOfReads elements. It is a optimized operation in that:

  1. One element represents a relatively short-and-wide entry of all reads for a single day.
  2. We have multiple DayOfReads elements and we use a PutMulti to make this faster.

For details of how a single element of DayOfReads is physically stored, see the implementation of apimodel.Store and apimodel.Load. Also important to note, this store operation also handles updating the GlukitUser entry with the most recent read, if applicable.

func StoreGlukitScoreBatch

func StoreGlukitScoreBatch(context context.Context, userEmail string, glukitScores []model.GlukitScore) error

StoreGlukitScoreBatch stores a batch of GlukitScores. The array could be of any size. A large batch of GlukitScores will be internally split into multiple PutMultis.

func StoreUserProfile

func StoreUserProfile(context context.Context, updatedAt time.Time, userProfile model.GlukitUser) (key *datastore.Key, err error)

StoreUserProfile stores a GlukitUser profile to the datastore. If the entry already exists, it is overriden and it is created otherwise

Types

type DataStoreCalibrationBatchWriter

type DataStoreCalibrationBatchWriter struct {
	// contains filtered or unexported fields
}

func NewDataStoreCalibrationBatchWriter

func NewDataStoreCalibrationBatchWriter(context context.Context, userProfileKey *datastore.Key) *DataStoreCalibrationBatchWriter

NewDataStoreCalibrationBatchWriter creates a new CalibrationBatchWriter that persists to the datastore

func (*DataStoreCalibrationBatchWriter) Flush

func (*DataStoreCalibrationBatchWriter) WriteCalibrationBatch

func (*DataStoreCalibrationBatchWriter) WriteCalibrationBatches

type DataStoreExerciseBatchWriter

type DataStoreExerciseBatchWriter struct {
	// contains filtered or unexported fields
}

func NewDataStoreExerciseBatchWriter

func NewDataStoreExerciseBatchWriter(context context.Context, userProfileKey *datastore.Key) *DataStoreExerciseBatchWriter

NewDataStoreExerciseBatchWriter creates a new ExerciseBatchWriter that persists to the datastore

func (*DataStoreExerciseBatchWriter) Flush

func (*DataStoreExerciseBatchWriter) WriteExerciseBatch

func (*DataStoreExerciseBatchWriter) WriteExerciseBatches

type DataStoreGlucoseReadBatchWriter

type DataStoreGlucoseReadBatchWriter struct {
	// contains filtered or unexported fields
}

func NewDataStoreGlucoseReadBatchWriter

func NewDataStoreGlucoseReadBatchWriter(context context.Context, userProfileKey *datastore.Key) *DataStoreGlucoseReadBatchWriter

NewDataStoreGlucoseReadBatchWriter creates a new GlucoseReadBatchWriter that persists to the datastore

func (*DataStoreGlucoseReadBatchWriter) Flush

func (*DataStoreGlucoseReadBatchWriter) WriteGlucoseReadBatch

func (*DataStoreGlucoseReadBatchWriter) WriteGlucoseReadBatches

type DataStoreInjectionBatchWriter

type DataStoreInjectionBatchWriter struct {
	// contains filtered or unexported fields
}

func NewDataStoreInjectionBatchWriter

func NewDataStoreInjectionBatchWriter(context context.Context, userProfileKey *datastore.Key) *DataStoreInjectionBatchWriter

NewDataStoreInjectionBatchWriter creates a new InjectionBatchWriter that persists to the datastore

func (*DataStoreInjectionBatchWriter) Flush

func (*DataStoreInjectionBatchWriter) WriteInjectionBatch

func (*DataStoreInjectionBatchWriter) WriteInjectionBatches

type DataStoreMealBatchWriter

type DataStoreMealBatchWriter struct {
	// contains filtered or unexported fields
}

func NewDataStoreMealBatchWriter

func NewDataStoreMealBatchWriter(context context.Context, userProfileKey *datastore.Key) *DataStoreMealBatchWriter

NewDataStoreMealBatchWriter creates a new MealBatchWriter that persists to the datastore

func (*DataStoreMealBatchWriter) Flush

func (*DataStoreMealBatchWriter) WriteMealBatch

func (*DataStoreMealBatchWriter) WriteMealBatches

type OsinAppEngineStore

type OsinAppEngineStore struct {
}

func NewOsinAppEngineStoreWithContext

func NewOsinAppEngineStoreWithContext(c context.Context) *OsinAppEngineStore

func NewOsinAppEngineStoreWithRequest

func NewOsinAppEngineStoreWithRequest(r *http.Request) *OsinAppEngineStore

func (*OsinAppEngineStore) GetClient

func (s *OsinAppEngineStore) GetClient(id string, r *http.Request) (*osin.Client, error)

func (*OsinAppEngineStore) GetClientWithContext

func (s *OsinAppEngineStore) GetClientWithContext(id string, context context.Context) (*osin.Client, error)

func (*OsinAppEngineStore) LoadAccess

func (s *OsinAppEngineStore) LoadAccess(code string, r *http.Request) (*osin.AccessData, error)

func (*OsinAppEngineStore) LoadAccessWithContext

func (s *OsinAppEngineStore) LoadAccessWithContext(code string, context context.Context) (*osin.AccessData, error)

func (*OsinAppEngineStore) LoadAuthorize

func (s *OsinAppEngineStore) LoadAuthorize(code string, r *http.Request) (*osin.AuthorizeData, error)

func (*OsinAppEngineStore) LoadAuthorizeWithContext

func (s *OsinAppEngineStore) LoadAuthorizeWithContext(code string, context context.Context) (*osin.AuthorizeData, error)

func (*OsinAppEngineStore) LoadRefresh

func (s *OsinAppEngineStore) LoadRefresh(code string, r *http.Request) (*osin.AccessData, error)

func (*OsinAppEngineStore) LoadRefreshWithContext

func (s *OsinAppEngineStore) LoadRefreshWithContext(code string, context context.Context) (*osin.AccessData, error)

func (*OsinAppEngineStore) RemoveAccess

func (s *OsinAppEngineStore) RemoveAccess(code string, r *http.Request) error

func (*OsinAppEngineStore) RemoveAccessWithContext

func (s *OsinAppEngineStore) RemoveAccessWithContext(code string, context context.Context) error

func (*OsinAppEngineStore) RemoveAuthorize

func (s *OsinAppEngineStore) RemoveAuthorize(code string, r *http.Request) error

func (*OsinAppEngineStore) RemoveAuthorizeWithContext

func (s *OsinAppEngineStore) RemoveAuthorizeWithContext(code string, context context.Context) error

func (*OsinAppEngineStore) RemoveRefresh

func (s *OsinAppEngineStore) RemoveRefresh(code string, r *http.Request) error

func (*OsinAppEngineStore) RemoveRefreshWithContext

func (s *OsinAppEngineStore) RemoveRefreshWithContext(code string, context context.Context) error

func (*OsinAppEngineStore) SaveAccess

func (s *OsinAppEngineStore) SaveAccess(data *osin.AccessData, r *http.Request) error

func (*OsinAppEngineStore) SaveAccessWithContext

func (s *OsinAppEngineStore) SaveAccessWithContext(data *osin.AccessData, context context.Context) error

func (*OsinAppEngineStore) SaveAuthorize

func (s *OsinAppEngineStore) SaveAuthorize(data *osin.AuthorizeData, r *http.Request) error

func (*OsinAppEngineStore) SaveAuthorizeWithContext

func (s *OsinAppEngineStore) SaveAuthorizeWithContext(data *osin.AuthorizeData, context context.Context) error

type ScoreScanQuery

type ScoreScanQuery struct {
	Limit *int
	From  *time.Time
	To    *time.Time
}

type StoreError

type StoreError struct {
	Temporary bool // Is the error temporary?
	// contains filtered or unexported fields
}

Error interface to distinguish between temporary errors from permanent ones

func (StoreError) Error

func (e StoreError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL