Documentation
¶
Overview ¶
Package store is api's database: its schema, the migrations that make it, the pool requests take their connections from, and the transaction a write under an account runs in.
Index ¶
- Constants
- Variables
- func AcceptTexts(ctx context.Context, tx pgx.Tx, accountID string, texts []TextRef, ...) error
- func AllowCountry(ctx context.Context, db Querier, country string) (bool, error)
- func AppendCorrection(ctx context.Context, tx pgx.Tx, profileID, packageDigest, moduleID string, ...) (int64, error)
- func AppendEvidence(ctx context.Context, tx pgx.Tx, profileID string, o Owed, evidence []byte, ...) (int64, error)
- func AskedQuestions(ctx context.Context, db pgx.Tx, profileID, attemptID string) ([]string, error)
- func AttemptOfProfile(ctx context.Context, db Querier, profileID, attemptID string) (bool, error)
- func AttemptTask(ctx context.Context, db Querier, profileID, attemptID string) (digest, taskID string, err error)
- func BeginAttempt(ctx context.Context, tx pgx.Tx, profileID string, a NewAttempt, at time.Time) (string, error)
- func BeginLessonRun(ctx context.Context, tx pgx.Tx, profileID string, r NewRun, at time.Time) (string, error)
- func BeginPaperAttempts(ctx context.Context, tx pgx.Tx, profileID, pageID string, tasks []SheetTask, ...) ([]string, error)
- func CancelChildConsent(ctx context.Context, tx pgx.Tx, accountID, consentID string) (bool, error)
- func CanonicalID(id string) bool
- func ChoiceBegun(ctx context.Context, db Querier, profileID, choiceID string) (bool, error)
- func ClearAccount(ctx context.Context, tx pgx.Tx, accountID string) error
- func CloseAbandonedAttempts(ctx context.Context, db Querier, before, at time.Time) (int64, error)
- func CloseAttempt(ctx context.Context, tx pgx.Tx, profileID, attemptID, reason string, ...) error
- func ClosePlatformAI(ctx context.Context, q Querier, now time.Time) (bool, error)
- func ConnectModule(ctx context.Context, db Querier, profileID, moduleID string) error
- func Countries(ctx context.Context, db Lister) ([]string, error)
- func CountryAccepted(ctx context.Context, db Querier, country string) (bool, error)
- func CreateAccount(ctx context.Context, db Beginner, uid string, codeSHA256 []byte, ...) (string, error)
- func CreateInvite(ctx context.Context, db Querier, codeSHA256 []byte, tariff string) error
- func DeleteAccountRow(ctx context.Context, db Beginner, accountID string) error
- func DeleteProfileRows(ctx context.Context, tx pgx.Tx, profileID string) error
- func DeleteWork(ctx context.Context, db Querier, profileID, attemptID string) error
- func DisconnectModule(ctx context.Context, db Querier, profileID, moduleID string) error
- func DropConsentRecords(ctx context.Context, db Querier, before time.Time) (int64, error)
- func DropForm(ctx context.Context, db Querier, object string) error
- func DropKeys(ctx context.Context, db Querier, before time.Time) (int64, error)
- func DropQuotaCounters(ctx context.Context, db Querier, before time.Time) (int64, error)
- func DropRecord(ctx context.Context, tx pgx.Tx, accountID, key string, made time.Time) error
- func DropReports(ctx context.Context, db Querier, before time.Time) (int64, error)
- func EndAbandonedRuns(ctx context.Context, db Querier, before, at time.Time) (int64, error)
- func EndLessonRun(ctx context.Context, tx pgx.Tx, profileID, runID, reason string, at time.Time) error
- func EndedSegments(ctx context.Context, tx pgx.Tx, profileID, runID string) ([]int, error)
- func ExplainRung(ctx context.Context, tx pgx.Tx, profileID, attemptID string, rung int, ...) error
- func ExportAccount(ctx context.Context, tx pgx.Tx, accountID string) (exportv7.Account, error)
- func FamilyDay(ctx context.Context, tx pgx.Tx, accountID string, reported *int32, ...) (quota.Day, error)
- func FinishRecord(ctx context.Context, tx pgx.Tx, accountID, key string, made time.Time, ...) error
- func FormsPastTerm(ctx context.Context, db Lister, today time.Time, after string, limit int) ([]string, error)
- func GiveCorrectWords(ctx context.Context, tx pgx.Tx, profileID, attemptID string) error
- func GiveOwnConsent(ctx context.Context, tx pgx.Tx, profileID string, textVersion *int32) (bool, error)
- func GiveRequested(ctx context.Context, tx pgx.Tx, profileID, attemptID string, ...) error
- func HasOwnerProfile(ctx context.Context, tx pgx.Tx, accountID string) (bool, error)
- func HaveAccounts(ctx context.Context, db Lister, uids []string) (map[string]bool, error)
- func HoldAccount(ctx context.Context, tx pgx.Tx, accountID string) error
- func HoldAttemptRun(ctx context.Context, tx pgx.Tx, profileID, attemptID string) error
- func HoldKeyChecks(ctx context.Context, tx pgx.Tx, accountID string) ([]time.Time, error)
- func HoldPin(ctx context.Context, tx pgx.Tx, accountID string) (pin.State, error)
- func HoldProfile(ctx context.Context, tx pgx.Tx, accountID, profileID string) error
- func JournalModules(ctx context.Context, tx pgx.Tx, profileID string) ([]string, error)
- func JudgeForm(ctx context.Context, db Querier, code string, accept bool) error
- func KeepPaperCheck(ctx context.Context, tx pgx.Tx, profileID, attemptID string, ...) error
- func KeptWorkKind(ctx context.Context, db Querier, profileID, attemptID string) (string, error)
- func LastAttempt(ctx context.Context, db Querier, profileID, attemptID string) (bool, error)
- func LastSubmission(ctx context.Context, db Querier, profileID, attemptID string) ([]byte, bool, error)
- func MarkDeleting(ctx context.Context, tx pgx.Tx, accountID string) error
- func MarkGrownUp(ctx context.Context, tx pgx.Tx, profileID, attemptID string, at time.Time) error
- func MarkIdle(ctx context.Context, tx pgx.Tx, accountID string, before time.Time) (bool, error)
- func Migrate(ctx context.Context, url string) (applied int, version int64, err error)
- func MigrateFiles(ctx context.Context, url string, files fs.FS) (applied int, version int64, err error)
- func ModuleConnected(ctx context.Context, db Querier, profileID, moduleID string) (bool, error)
- func NoteModel(ctx context.Context, tx pgx.Tx, accountID, key string, made time.Time, ...) error
- func Open(ctx context.Context, url string) (*pgxpool.Pool, error)
- func OpenPlatformAI(ctx context.Context, q Querier) (bool, error)
- func PaperWordsOf(ctx context.Context, db Querier, profileID string) (language string, showWhere bool, err error)
- func PendForm(ctx context.Context, db Querier, object, mediaType string, at time.Time) error
- func PlatformAIClosed(ctx context.Context, q Querier) (bool, error)
- func ProfileGrade(ctx context.Context, db Querier, profileID string) (*int, error)
- func ProfileIdle(ctx context.Context, tx pgx.Tx, accountID, profileID string, before time.Time) (bool, error)
- func ProfileOf(ctx context.Context, db Querier, accountID, profileID string) (bool, time.Time, error)
- func ProfilesOwingEvidence(ctx context.Context, db Lister, digests []string, after string, n int) ([]string, error)
- func ProfilesThere(ctx context.Context, db Lister, ids []string) (map[string]string, error)
- func PutWork(ctx context.Context, tx pgx.Tx, accountID, profileID string, w Work) error
- func QuotaFits(ctx context.Context, q Querier, c Charge) (quota.Spent, error)
- func RecordDone(ctx context.Context, tx pgx.Tx, accountID, key, method, fingerprint string, ...) error
- func RecordGoing(ctx context.Context, tx pgx.Tx, accountID, key, method, fingerprint string, ...) (time.Time, error)
- func RemoveCountry(ctx context.Context, db Querier, country string) (bool, error)
- func ReserveQuota(ctx context.Context, tx pgx.Tx, c Charge) (quota.Spent, error)
- func RestateAge(ctx context.Context, tx pgx.Tx, c Consent, r Restated) error
- func ReviewReport(ctx context.Context, db Querier, reportID string) error
- func RunLesson(ctx context.Context, db Querier, profileID, runID string) (string, error)
- func RunModule(ctx context.Context, db Querier, profileID, runID string) (string, error)
- func SendForm(ctx context.Context, tx pgx.Tx, c Consent, object string) error
- func SetDebugModels(ctx context.Context, db Querier, uid string, right bool) error
- func SetPaperReading(ctx context.Context, tx pgx.Tx, profileID, attemptID string, reading []byte) error
- func SetTariff(ctx context.Context, db Querier, codeSHA256 []byte, tariff string) error
- func SetTaskSkill(ctx context.Context, db Querier, profileID, moduleID, skill string) error
- func SettleQuota(ctx context.Context, db Beginner, c Charge, spent quota.Micro) error
- func ShownRungs(ctx context.Context, db pgx.Tx, profileID, attemptID string) ([]string, error)
- func SubmissionAnswer(ctx context.Context, db Querier, profileID, submissionID string) ([]byte, error)
- func Submit(ctx context.Context, tx pgx.Tx, profileID, attemptID string, ...) (string, error)
- func SubmitEssay(ctx context.Context, tx pgx.Tx, profileID, attemptID string, answer []byte, ...) (string, error)
- func Submitted(ctx context.Context, db Querier, profileID, attemptID string) (bool, error)
- func SwitchWorkStorageOff(ctx context.Context, tx pgx.Tx, profileID string, at time.Time) error
- func SwitchWorkStorageOn(ctx context.Context, tx pgx.Tx, profileID, giver string, textVersion *int32, ...) error
- func Today(ctx context.Context, q Querier, accountID string, now time.Time) (quota.Day, error)
- func TodayByUTC(on, now time.Time) bool
- func TouchAccount(ctx context.Context, db Querier, accountID string) error
- func TouchLessonRun(ctx context.Context, tx pgx.Tx, profileID, runID string, at time.Time) error
- func TouchProfile(ctx context.Context, db Querier, profileID string) error
- func WaitingConsents(ctx context.Context, tx pgx.Tx, accountID string) (int, error)
- func WorkDecider(ctx context.Context, db Querier, accountID, profileID string) (string, error)
- func WorkStorageOn(ctx context.Context, tx pgx.Tx, profileID string) (giver string, on bool, err error)
- func WriteChoice(ctx context.Context, tx pgx.Tx, profileID string, c NewChoice, at time.Time) (string, error)
- func WriteKeyChecks(ctx context.Context, tx pgx.Tx, accountID string, checked []time.Time) error
- func WritePin(ctx context.Context, tx pgx.Tx, accountID string, state pin.State) error
- func WriteProfile(ctx context.Context, tx pgx.Tx, p Profile) error
- func WriteReport(ctx context.Context, tx pgx.Tx, accountID, profileID string, r Report) (string, error)
- func WriteRung(ctx context.Context, tx pgx.Tx, profileID, attemptID string, rung int, w Words) error
- func WriteSkillState(ctx context.Context, tx pgx.Tx, profileID string, s SkillState) error
- func WriteUnderAccount(ctx context.Context, db Beginner, accountID string, fn func(pgx.Tx) error) error
- type Account
- type AccountRef
- type Answer
- type Attempt
- type Beginner
- type Charge
- type ChildConsent
- type Choice
- type ClosedAttempt
- type ConnectedModule
- type Consent
- type Correction
- type Cursor
- type Entry
- type Essay
- type EssaySubmission
- type ExportedAttempt
- type ExportedPaperAttempt
- type ExportedProfile
- type Issued
- type KeyRecord
- type KeyTarget
- type Learner
- type LessonRun
- type Lister
- type MadeChoice
- type Mark
- type ModuleChoices
- type NewAttempt
- type NewChoice
- type NewConsent
- type NewRun
- type OpenAttempt
- type OpenLessonRun
- type OpenOn
- type Owed
- type Profile
- func CreateChildProfile(ctx context.Context, tx pgx.Tx, accountID string, c Consent, p Profile) (Profile, error)
- func CreateOwnerProfile(ctx context.Context, tx pgx.Tx, accountID string, p Profile) (Profile, error)
- func ProfileFor(ctx context.Context, tx pgx.Tx, accountID, profileID string) (Profile, error)
- func ProfileWithConsent(ctx context.Context, db Querier, accountID, profileID string) (Profile, error)
- type ProfileRef
- type Progress
- type Querier
- type Record
- type Report
- type ReportToReview
- type Restated
- type Run
- type Rung
- type Scope
- type SentForm
- type Settled
- type SheetTask
- type SkillState
- type Solution
- type TextRef
- type TxBeginner
- type View
- type Words
- type Work
Constants ¶
const ( GiverOwner = "owner" GiverParent = "parent" GiverLearner = "learner" )
Who gives a consent: the owner of the account, of their own profile; a parent, by a signed form; or the learner, from the age of digital consent of their country.
const ( FormNotSent = "not_sent" FormSent = "sent" FormNotAccepted = "not_accepted" )
The states of the form of a parent's consent.
const ( ConsentBySignedForm = "signed_form" ConsentByLearner = "own_consent" )
How a consent for a child was checked, as its minimal record keeps it: a parent's by the signed form, the learner's by their own consent.
const ( EssayFeedback = "feedback" EssayUnreadable = "unreadable" EssayUnchecked = "unchecked" // The marks of a criterion. MarkMet = "met" MarkNotMet = "not_met" MarkNotAssessed = "not_assessed" // SourceNoFeedback is the phrase "no feedback this time" in place of words // that failed a check; the model's words are SourceModel. SourceNoFeedback = "no_feedback" )
How a submission of an essay ends, and the source of its words, as the schema writes them.
const ( NothingNotAdmitted = "not_admitted" NothingQuota = "quota" NothingPlatformLimit = "platform_limit" )
The causes of a choice of nothing to give whose pool the closed AI narrowed.
const ( ConsentWaiting = "waiting" ConsentConfirmed = "confirmed" )
The states of a consent.
const ( // SourceModel is the tutor's question, which passed the leak check and the // form check. SourceModel = "model" // SourceFallback is the rung's fallback text. SourceFallback = "fallback" )
The sources of a rung's words, as the schema writes them.
const ( // KeyGoing is a request that is still going. KeyGoing = "going" // KeyDone is a request done, whose answer the record holds. KeyDone = "done" )
The states of a record of an idempotency key.
const ( RunPassed = "passed" RunUnchecked = "unchecked" RunNotSuitable = "not_suitable" RunAbandoned = "abandoned" )
The end reasons of a lesson run, as the schema writes them.
const ( WorkHandwriting = "handwriting" WorkEssay = "essay" WorkDrawing = "drawing" )
The kinds of a stored work, by the attempt's task.
const AbandonedAfter = 7 * 24 * time.Hour
AbandonedAfter is how long an open attempt goes with no action before it is abandoned: the check of a request closes it then, and so does the daily job.
const ConsentByOwnerStatement = "owner_statement"
The ways a consent was given. The owner's own is the statement that they are 18 or older, dated with the account.
const ExportFormat = 7
ExportFormat is the integer of export/VERSION of spec's tag.
const HintModeShowWhere = "show_where"
HintModeShowWhere is the hint mode of a new profile.
const ReviewWithin = 3 * 24 * time.Hour
ReviewWithin is the term the operator reviews a problem report in.
const RunAbandonedAfter = 30 * 24 * time.Hour
RunAbandonedAfter is how long an open lesson run goes with no request on it or its attempts before it is abandoned.
Variables ¶
var ( // ErrNotFound is an attempt, a lesson run or an engine's choice that the // profile does not have: another profile's is the same. ErrNotFound = errors.New("store: the profile has no such row") // ErrChoiceBegun is an engine's choice of a task that has begun an attempt // already. ErrChoiceBegun = errors.New("store: the choice has begun an attempt already") // ErrPaper is an attempt of a task from paper, which has no package and no // task of a module. ErrPaper = errors.New("store: the attempt is of a task from paper") )
The refusals of the rows of an attempt.
var ( // ErrAccountExists is a user who has an account already. ErrAccountExists = errors.New("store: the account exists") // ErrCodeNotAccepted is a code that is not there, or was redeemed. ErrCodeNotAccepted = errors.New("store: the code is not accepted") )
The refusals of the creation of an account.
var ( // ErrProfileExists is a profile there already: the owner's second, or the // profile of a consent that has one. ErrProfileExists = errors.New("store: the profile exists") // ErrNoProfile is a profile that is not the account's. ErrNoProfile = errors.New("store: no such profile") )
The refusals of a profile.
var ( // ErrNoAccount is a write under an account that is not there. ErrNoAccount = errors.New("store: no account") // ErrAccountDeleting is a write under an account marked "deleting". ErrAccountDeleting = errors.New("store: the account is being deleted") )
The refusals of a write under an account.
var ErrCodeTaken = errors.New("store: the code of the request is taken")
ErrCodeTaken is a code of a request that another waiting consent has: the caller draws another.
var ErrNoConsent = errors.New("store: no such consent")
ErrNoConsent is a consent for a child that is not the account's.
var ErrNoForm = errors.New("store: no form of the code waits")
ErrNoForm is a code of a request with no consent that waits for its form to be checked.
var ErrRecordGone = errors.New("store: the key's record going is gone")
ErrRecordGone is a record going that is no longer there, or no longer this request's, when its request comes to finish: a repeat found it fallen and went again.
var ErrRunBegun = errors.New("store: the profile has an open run of the lesson")
ErrRunBegun is a lesson run that could not begin because another request began one meanwhile — the profile's open run of the lesson, or the run of the same choice: the request reads it again.
var ErrStorageOff = errors.New("store: the storage of the profile's works is off")
ErrStorageOff is a work put while the storage of the profile's works is off.
Functions ¶
func AcceptTexts ¶ added in v0.1.21
func AcceptTexts(ctx context.Context, tx pgx.Tx, accountID string, texts []TextRef, at time.Time) error
AcceptTexts records the texts the owner accepted with the account, at at.
func AllowCountry ¶ added in v0.1.7
AllowCountry adds country to the list, and says whether it was not there.
func AppendCorrection ¶ added in v0.1.59
func AppendCorrection(ctx context.Context, tx pgx.Tx, profileID, packageDigest, moduleID string, evidence []byte, at time.Time) (int64, error)
AppendCorrection adds an adult's correction of the level of the profile's module to its journal at at, under an ID of its own and the number after the journal's last, and gives the number: evidence, as learner-model's codec gives it, of no attempt, on the package of the module's current version. The caller holds the profile's row of the cache, as for AppendEvidence.
func AppendEvidence ¶ added in v0.1.18
func AppendEvidence(ctx context.Context, tx pgx.Tx, profileID string, o Owed, evidence []byte, at time.Time) (int64, error)
AppendEvidence adds the evidence of the profile's attempt to its journal at at, under the number after the journal's last, and gives the number. The caller holds the profile's row of the cache, which orders the numbers.
func AskedQuestions ¶ added in v0.1.17
AskedQuestions is the tutor's questions on the attempt so far, in order: the words of its rungs that came of a model, which every call of the words gets, so as not to ask them again.
func AttemptOfProfile ¶ added in v0.1.21
AttemptOfProfile says whether the attempt, open or closed, is the profile's.
func AttemptTask ¶ added in v0.1.17
func AttemptTask(ctx context.Context, db Querier, profileID, attemptID string) (digest, taskID string, err error)
AttemptTask is the package and the task of the profile's attempt, read with no lock: what an attempt is of never changes, so a request may choose its way by it before it holds the attempt. One of a task from paper is ErrPaper.
func BeginAttempt ¶ added in v0.1.15
func BeginAttempt(ctx context.Context, tx pgx.Tx, profileID string, a NewAttempt, at time.Time) (string, error)
BeginAttempt begins a at at, in tx, once the profile's open attempt is closed: the profile has one open attempt of a module. A choice that has begun an attempt already is ErrChoiceBegun.
func BeginLessonRun ¶ added in v0.1.17
func BeginLessonRun(ctx context.Context, tx pgx.Tx, profileID string, r NewRun, at time.Time) (string, error)
BeginLessonRun begins the run r at at, in tx, and gives its ID. A profile that has an open run of the lesson already is ErrRunBegun, and tx can go on: the insert runs in a savepoint of its own.
func BeginPaperAttempts ¶ added in v0.1.72
func BeginPaperAttempts(ctx context.Context, tx pgx.Tx, profileID, pageID string, tasks []SheetTask, renews string, at time.Time) ([]string, error)
BeginPaperAttempts begins the attempts of a page, one for each of tasks, its task of a module on the sheet or none, and gives their IDs in that order. It first closes "left" the profile's open attempts of tasks from paper on another page than pageID. With renews, the attempt of the profile from paper that the one attempt of tasks begins anew, the new attempt is of the task the renewed one was of; an ID that is no such attempt is ErrNotFound. An attempt of paper gives no evidence, so the close settles none. Its caller holds the account's row FOR NO KEY UPDATE (HoldAccount), so that two beginnings of one profile go one after the other and the second sees the first's attempts.
func CancelChildConsent ¶ added in v0.1.21
CancelChildConsent takes back the account's consent for a child with no profile, and says whether there was one: one that waits is erased, with its form; one confirmed leaves its minimal record and its form for their term. Neither counts toward the limit after.
func CanonicalID ¶ added in v0.1.7
CanonicalID says whether id is a UUID as the database writes one: lowercase, with its dashes. Any other ID names no row, and nothing is asked of it: OpenFGA would refuse the colons of urn:uuid:, and hold no tuple of an uppercase one.
func ChoiceBegun ¶ added in v0.1.15
ChoiceBegun says whether the engine's choice has begun an attempt.
func ClearAccount ¶ added in v0.1.8
ClearAccount deletes, in the transaction that marked the account "deleting", all the database keeps of it but its ID, its UID and the time of the mark: every profile as DeleteProfileRows deletes one, the consents that wait and the adults', the records of its keys, its counters of the quota, the texts it was made on, its fields, the binding of its invite code — the code stays redeemed — and of its problem reports, which stay to their term.
func CloseAbandonedAttempts ¶ added in v0.1.14
CloseAbandonedAttempts closes "abandoned", at at, the open attempts with no action since before, a batch at a time, and says how many it closed. One clock judges the term and dates the close: the pass's. An attempt a request holds is skipped, and the next pass finds it if it is still idle; the term is checked again on the row the UPDATE takes, so an action that came meanwhile keeps the attempt open. The close moves no date of the profile's activity.
func CloseAttempt ¶ added in v0.1.15
func CloseAttempt(ctx context.Context, tx pgx.Tx, profileID, attemptID, reason string, at time.Time) error
CloseAttempt closes the open attempt with reason at at; one closed already keeps its close.
func ClosePlatformAI ¶ added in v0.1.23
ClosePlatformAI sets the flag "platform AI closed" at now, and says whether this call set it: one set already keeps its time.
func ConnectModule ¶ added in v0.1.13
ConnectModule connects the module to the profile, now; a module connected already keeps the time it was connected. A profile that is gone is ErrNoProfile: the row refers to it.
func CountryAccepted ¶ added in v0.1.7
CountryAccepted says whether the deployment takes learners from country. None is taken until the operator adds it.
func CreateAccount ¶ added in v0.1.5
func CreateAccount(ctx context.Context, db Beginner, uid string, codeSHA256 []byte, texts []TextRef) (string, error)
CreateAccount creates the account of the sign-in service's UID by the code of codeSHA256, with the owner's statement that they are 18 or older dated now, and returns its ID. It is one transaction, in the order of the contract: an account the UID has already is ErrAccountExists — or ErrAccountDeleting, when it is marked — before the code is looked at, so that a repeat is not refused for the code it redeemed; then a code not there or redeemed is ErrCodeNotAccepted, and no account is left. The code is bound to the account, and its tariff passes to it, and the texts the owner accepted are recorded with it.
Two creations race safely. Two by one UID: the second waits on the UID's unique index and finds the first's account. Two for one code: the second waits on the code's row and finds it redeemed. Either way, a first one that rolls back leaves the second to go on.
func CreateInvite ¶ added in v0.1.5
CreateInvite keeps a new invite code by its SHA-256 alone, with the tariff it passes to the account that redeems it.
func DeleteAccountRow ¶ added in v0.1.8
DeleteAccountRow is the last step of the deletion of an account: in one transaction, it clears again what a row written late may have left, and deletes the account's row. An account that is not there is deleted already.
func DeleteProfileRows ¶ added in v0.1.8
DeleteProfileRows deletes, in the transaction that holds the profile, all that the database keeps of it: its consent — for a child into its minimal record, an adult's whole — its records of idempotency keys, and the profile. Every other row of a profile goes with it by its keys.
func DeleteWork ¶ added in v0.1.39
DeleteWork erases the profile's stored work of the attempt, when one is kept.
func DisconnectModule ¶ added in v0.1.13
DisconnectModule disconnects the module from the profile; a module not connected changes nothing.
func DropConsentRecords ¶ added in v0.1.11
DropConsentRecords deletes the minimal records of consents for children whose account or profile was deleted before before, a batch at a time, and says how many went: a record is kept 5 years after the deletion and then erased. A stop between batches keeps what went.
func DropForm ¶ added in v0.1.21
DropForm deletes the row of a scan the store erased, unless its consent took it back meanwhile.
func DropKeys ¶ added in v0.1.9
DropKeys deletes the records of idempotency keys made before before, a batch at a time, and says how many went: a key is kept for a day. A stop between batches keeps what went.
func DropQuotaCounters ¶ added in v0.1.23
DropQuotaCounters deletes the counters of the quota whose day ended before before, of the profiles and of the accounts, a batch at a time, and says how many it deleted: a counter is needed for its day and for a day after it, to settle the requests that went over midnight.
func DropRecord ¶ added in v0.1.17
DropRecord deletes the account's record going made at made — of a request refused after its call, which records nothing — or, with made zero, whichever is going: of a request that fell, which a repeat runs again.
func DropReports ¶ added in v0.1.21
DropReports deletes the reports reviewed before before, a batch at a time.
func EndAbandonedRuns ¶ added in v0.1.14
EndAbandonedRuns ends "abandoned", at at, the open lesson runs with no action since before, a batch at a time, as CloseAbandonedAttempts closes attempts: no request on the run, and no action on its attempts, which is the run's too.
func EndLessonRun ¶ added in v0.1.17
func EndLessonRun(ctx context.Context, tx pgx.Tx, profileID, runID, reason string, at time.Time) error
EndLessonRun ends the profile's open run with reason at at; one ended already keeps its end. A run that ends "not suitable" closes its open attempt "not suitable" with it.
func EndedSegments ¶ added in v0.1.17
EndedSegments is the places of the run's task segments that have ended, in order: those whose attempt was closed by a correct answer, by the solution shown or by "Done".
func ExplainRung ¶ added in v0.1.17
func ExplainRung(ctx context.Context, tx pgx.Tx, profileID, attemptID string, rung int, read, other Words, at time.Time) error
ExplainRung records, at at, that "explain differently" was asked for on the attempt's rung, and the words that came of it. A rung whose words never came is recorded with read, the words the learner read before: its fallback text.
func ExportAccount ¶ added in v0.1.21
ExportAccount is the account's part of the export: its fields that are no secret and every consent of it, in full, and the IDs of its profiles.
func FamilyDay ¶ added in v0.1.23
func FamilyDay(ctx context.Context, tx pgx.Tx, accountID string, reported *int32, now time.Time) (quota.Day, error)
FamilyDay is the account's family day at now, once a request on platform AI sent the offset reported, if any: the offset, when valid, kept for the days to come, and the day that holds now, kept once the day before is over. It writes in tx, which holds the account's row already, as a request under a key does (HoldAccount), and only what changed. The offset is no field of any line of the log.
func FinishRecord ¶ added in v0.1.17
func FinishRecord(ctx context.Context, tx pgx.Tx, accountID, key string, made time.Time, target KeyTarget) error
FinishRecord turns the account's record going, the one made at made, into done with its target, in the transaction of what the request writes after its call.
func FormsPastTerm ¶ added in v0.1.21
func FormsPastTerm(ctx context.Context, db Lister, today time.Time, after string, limit int) ([]string, error)
FormsPastTerm is up to limit objects of scans whose consent is gone and whose term ended by today, the day by UTC, in the order of their names after after.
func GiveCorrectWords ¶ added in v0.1.46
GiveCorrectWords records that the tutor's words after a correct answer were given on the attempt, which a correct answer closed: once.
func GiveOwnConsent ¶ added in v0.1.21
func GiveOwnConsent(ctx context.Context, tx pgx.Tx, profileID string, textVersion *int32) (bool, error)
GiveOwnConsent confirms the learner's own consent of the profile, which waits, to the version of teen-consent, and says whether it waited.
func GiveRequested ¶ added in v0.1.17
func GiveRequested(ctx context.Context, tx pgx.Tx, profileID, attemptID string, techniques, leading bool, at time.Time) error
GiveRequested records, at at, that a hint asked for gave the techniques of the attempt's task, when techniques — it has some —, and its leading question, when leading, each the first time it did, and that the attempt's last action is at.
func HasOwnerProfile ¶ added in v0.1.7
HasOwnerProfile says whether the account has the owner's profile.
func HaveAccounts ¶ added in v0.1.9
HaveAccounts is the UIDs, of uids, that have an account, marked or not: the daily job removes the users of the sign-in service that have none.
func HoldAccount ¶ added in v0.1.7
HoldAccount takes the account's row FOR NO KEY UPDATE in tx: what a request under an idempotency key holds first, so that a repeat beside it waits and finds its record. The lock conflicts with itself and not with FOR KEY SHARE, so the other writes under the account do not wait for it.
func HoldAttemptRun ¶ added in v0.1.17
HoldAttemptRun holds FOR UPDATE, in tx, the lesson run of the profile's attempt, when it is one of a run, or of the profile's open attempt when attemptID is empty: a request on an attempt holds its run first, as the requests on the run do, so that the close of the attempt, which may end the run, takes the two rows in the order every request takes them.
func HoldKeyChecks ¶ added in v0.1.47
HoldKeyChecks takes the account's row FOR NO KEY UPDATE and reads when each check of an own key it keeps was made, in the order they were counted; it may hold checks older than the window, which no longer count. The lock conflicts with itself and not with FOR KEY SHARE: the checks of one account — from two devices, or two tabs — are counted one after the other, and none is lost, while the other writes under the account do not wait for them.
func HoldPin ¶ added in v0.1.6
HoldPin takes the account's row FOR NO KEY UPDATE and reads its PIN. The lock conflicts with itself and not with FOR KEY SHARE: the requests of the PIN of one account — from two devices, or a repeat beside its first — go one after the other, and its count loses no wrong PIN, while the other writes under the account do not wait for them.
func HoldProfile ¶ added in v0.1.43
HoldProfile holds the account's profile FOR NO KEY UPDATE in tx, or is ErrNoProfile: what a write takes before the profile's consent, so that it holds the two rows in the order of the deletion of a profile, which takes the profile FOR UPDATE and reaches the consent by the cascade, and the two wait rather than deadlock. NO KEY UPDATE is the lock an UPDATE of the row takes anyway, and it lets a row that references the profile be written.
func JournalModules ¶ added in v0.1.18
JournalModules is the modules of the profile's journal, by ID.
func JudgeForm ¶ added in v0.1.21
JudgeForm confirms, when accept, the parent's consent of the code, which waits with its form sent, as checked by its signed form; otherwise it marks the form not accepted, and the adult sends a new one. A code of no such consent is ErrNoForm.
func KeepPaperCheck ¶ added in v0.1.80
func KeepPaperCheck(ctx context.Context, tx pgx.Tx, profileID, attemptID string, check, turn []byte) error
KeepPaperCheck keeps check, the message Check of novatrail.paper.v1, on the profile's open attempt of a task from paper in place of the Check before, until the attempt closes. turn is what the history keeps of the Check before, nil when there was none, and goes to its end; the rungs the learner was shown of the ladder before go, so that each rung of the new ladder is given anew. An attempt that is not of paper, or closed, keeps none.
func KeptWorkKind ¶ added in v0.1.39
KeptWorkKind is the kind of the profile's stored work of the attempt, or ErrNotFound when none is kept.
func LastAttempt ¶ added in v0.1.17
LastAttempt says whether the attempt is the last the profile began of its kind: the words after a correct answer are given while the profile has begun no other, and an attempt of a module and the attempts of a page go beside each other.
func LastSubmission ¶ added in v0.1.15
func LastSubmission(ctx context.Context, db Querier, profileID, attemptID string) ([]byte, bool, error)
LastSubmission is the answer of the attempt's last submission with a verdict, and whether it has one.
func MarkDeleting ¶
MarkDeleting takes the account's row FOR UPDATE in tx and marks it "deleting", the first step of the deletion of an account. FOR UPDATE is what waits for every write that holds the row by FOR KEY SHARE: a plain UPDATE of the mark takes FOR NO KEY UPDATE, which does not conflict with FOR KEY SHARE, and would let a write that does not touch the row commit after the mark. The deletion clears the account's data in the same tx, after this.
func MarkGrownUp ¶ added in v0.1.84
MarkGrownUp records that grown-up mode acted on the profile's attempt of a task of a module, the first time it did, at: such an attempt owes no evidence. It is the one thing kept of the grown-up's request, and it moves no last action, as the learner did not act.
func MarkIdle ¶ added in v0.1.9
MarkIdle marks the account "deleting" in tx, as MarkDeleting does, only if it still had no request since before, and says whether it did. The term is read under the row's lock: a request that wrote today's date while the job chose the account keeps it, since FOR UPDATE waits for that write and reads the row again (П-9).
func Migrate ¶
Migrate applies to the database at url every migration of api it has not had, and returns how many it applied and the version the schema is at.
func MigrateFiles ¶ added in v0.1.2
func MigrateFiles(ctx context.Context, url string, files fs.FS) (applied int, version int64, err error)
MigrateFiles applies the migrations in files — api's, or OpenFGA's for the rights — to the database at url that it has not had. url is the direct connection: goose holds an advisory lock of the session while it migrates, so that two runs never migrate at once, and Neon's pooler keeps no session. Each migration runs in a transaction of its own, but one its file says may not.
func ModuleConnected ¶ added in v0.1.15
ModuleConnected says whether the module is connected to the profile.
func NoteModel ¶ added in v0.1.83
func NoteModel(ctx context.Context, tx pgx.Tx, accountID, key string, made time.Time, model, models int) error
NoteModel writes into the account's record going made at made the place of the model that now reads its request's work, from 0, and the length of the call's list: what CheckProgress gives while the request goes on. A record no longer going, or no longer this request's, is left as it is.
func Open ¶
Open is a pool of connections to the database at url. The pool takes them as it needs them, and pgx keeps its prepared statements by the protocol, which Neon's pooler keeps too.
func OpenPlatformAI ¶ added in v0.1.23
OpenPlatformAI clears the flag "platform AI closed", and says whether it was set: the operator's command, once the provider's limit is lifted.
func PaperWordsOf ¶ added in v0.1.72
func PaperWordsOf(ctx context.Context, db Querier, profileID string) (language string, showWhere bool, err error)
PaperWordsOf is what the tutor's words of a task from paper read of the profile: the language of its interface, "" when it has none, and whether its hint mode is "Show where".
func PendForm ¶ added in v0.1.21
PendForm records the object a scan is about to go to, before it goes: a row of no consent, erased by the daily job today, so that a scan whose request failed after it went is erased too, and none lies in the store unknown to the database.
func PlatformAIClosed ¶ added in v0.1.23
PlatformAIClosed says whether the flag "platform AI closed" of the deployment is set: read on every request that would call platform AI, so that one set by any instance, or cleared by the operator, holds at once on all.
func ProfileGrade ¶ added in v0.1.18
ProfileGrade is the profile's school grade, nil when it names none.
func ProfileIdle ¶ added in v0.1.9
func ProfileIdle(ctx context.Context, tx pgx.Tx, accountID, profileID string, before time.Time) (bool, error)
ProfileIdle holds the account's profile FOR UPDATE in tx if it was still active last before before, and says whether it was: a request that touched it today while the job chose it keeps it (П-9).
func ProfileOf ¶ added in v0.1.4
func ProfileOf(ctx context.Context, db Querier, accountID, profileID string) (bool, time.Time, error)
ProfileOf says whether the account has the profile, and the date of the profile's last activity. It is read after the right to the profile, never before: a tuple whose profile is gone — dangling — gives a right to nothing.
func ProfilesOwingEvidence ¶ added in v0.1.18
func ProfilesOwingEvidence(ctx context.Context, db Lister, digests []string, after string, n int) ([]string, error)
ProfilesOwingEvidence is up to n of the profiles with an attempt that owes its evidence, on the packages digests names, by ID after the ID after, for the daily job.
func ProfilesThere ¶ added in v0.1.9
ProfilesThere is the profiles, of ids, that are there, each with its account: a tuple whose profile is not, or is another account's, is dangling. An ID that is no UUID as the database writes one names no row, and is not asked.
func PutWork ¶ added in v0.1.39
PutWork keeps w in tx, in the place of the work kept of its attempt before, while the storage of the profile's works is on: ErrStorageOff when it is off, ErrNoProfile when the account has no such profile, ErrNotFound when the attempt is not the profile's. The profile's row is held FOR SHARE, which a switch of the storage off waits for and waits on — SetWorkStorage at its HoldProfile, before the consent, and SwitchWorkStorageOff at its UPDATE in any case: a work put before the switch is erased by it, and one after it is refused. FOR KEY SHARE would not do: both take FOR NO KEY UPDATE, which does not conflict with it.
func QuotaFits ¶ added in v0.1.23
QuotaFits says whether the charge c would fit, reserving nothing: what is left of the day holds a typical task, at the beginning of an attempt.
func RecordDone ¶ added in v0.1.6
func RecordDone(ctx context.Context, tx pgx.Tx, accountID, key, method, fingerprint string, target KeyTarget) error
RecordDone records a request done under the account's key, with its target, in the transaction of the action, so that the action and its record commit together or not at all. A request on the account itself names no profile.
func RecordGoing ¶ added in v0.1.17
func RecordGoing(ctx context.Context, tx pgx.Tx, accountID, key, method, fingerprint string, target KeyTarget) (time.Time, error)
RecordGoing records a request under the account's key as going, with what it acts on, and commits with the checks before its call of AI: a repeat beside it is "still going" until it is done, or until it outlives the longest a request may run. It gives when the record was made, by the database's clock: the mark by which the request finishes or drops its own record, and never a repeat's that took its place.
func RemoveCountry ¶ added in v0.1.7
RemoveCountry takes country off the list, and says whether it was there. The profiles of the country stay: a new one is refused.
func ReserveQuota ¶ added in v0.1.23
ReserveQuota reserves the charge c on the counters of the profile and of the account of its day, in tx, when it fits beside what each has spent and holds in reserve, and says why it does not when it does not, writing nothing. The counters of a day are made by its first reserve. tx holds the account's row already, as a request under a key does, so that two reserves of one account — two devices, a profile and its owner — go one after the other, and the counters are held besides against a settlement going on.
func RestateAge ¶ added in v0.1.21
RestateAge writes the age given again of the profile c is the consent of, held: its category, country and the day the age was given, today; and, when r names a new giver, a new consent in the place of c, which waits. A code another waiting consent has is ErrCodeTaken, in a savepoint of its own, and the caller asks again with c: what was done before it holds.
func ReviewReport ¶ added in v0.1.21
ReviewReport marks the report reviewed now, which starts its year; a report not there, or reviewed already, is ErrNotFound.
func RunLesson ¶ added in v0.1.17
RunLesson is the full ID of the lesson of the profile's run, read with no lock: what a run is of never changes.
func SendForm ¶ added in v0.1.21
SendForm makes the scan at object, pended, the form of the consent c, a parent's that waits, held, and the form sent; the scan it sent before is no longer its form, and goes today.
func SetDebugModels ¶ added in v0.1.74
SetDebugModels gives the account of the sign-in service's UID the right of the debug mode, or takes it. An account marked "deleting", whose fields are cleared, is none — ErrNoAccount, as is a UID with no account.
func SetPaperReading ¶ added in v0.1.74
func SetPaperReading(ctx context.Context, tx pgx.Tx, profileID, attemptID string, reading []byte) error
SetPaperReading keeps the reading of the statement of the profile's open attempt of a task from paper, the message Reading of novatrail.paper.v1, until the attempt closes. An attempt that is not of paper, or closed, keeps none.
func SetTariff ¶ added in v0.1.23
SetTariff gives the account that redeemed the code of codeSHA256 the tariff: one statement finds the account by the code it is bound to, and an account marked "deleting", whose code is unbound already or soon, is none — ErrNoAccount, as is a code that no account redeemed. The code keeps the tariff it was made with: it passes on only when redeemed, which it is already.
func SetTaskSkill ¶ added in v0.1.84
SetTaskSkill sets the task skill of the module connected to the profile, empty to give the choice back to the tutor; a module not connected is ErrNotFound.
func SettleQuota ¶ added in v0.1.23
SettleQuota settles the reserve of the charge c, on the day of its reserve, by what the call cost: the reserve leaves the counters of the profile and of the account, and spent is added to what each has spent, in one transaction of its own on db. A counter gone meanwhile — the profile deleted, the account — is no failure: there is nothing left to settle.
func ShownRungs ¶ added in v0.1.80
ShownRungs is the words the learner was shown on the attempt's rungs, in order, whatever they came of: each rung's words, and the words "explain differently" gave it after them.
func SubmissionAnswer ¶ added in v0.1.15
func SubmissionAnswer(ctx context.Context, db Querier, profileID, submissionID string) ([]byte, error)
SubmissionAnswer is the answer of the profile's submission by its ID.
func Submit ¶ added in v0.1.15
func Submit(ctx context.Context, tx pgx.Tx, profileID, attemptID string, answer, observation []byte, wrong bool, at time.Time) (string, error)
Submit records a submission with a verdict of the attempt, by its answer and the observation of its work, as the attempt's next, and counts it a wrong answer when wrong: the attempt's last action is at. It gives the submission's ID.
func SubmitEssay ¶ added in v0.1.49
func SubmitEssay(ctx context.Context, tx pgx.Tx, profileID, attemptID string, answer []byte, e Essay, at time.Time) (string, error)
SubmitEssay records a submission of an essay of the attempt, by its answer — without the text read and the words of the feedback — and how it ended, as the attempt's next, whose last action is at. It gives the submission's ID.
func Submitted ¶ added in v0.1.49
Submitted says whether the profile's attempt has a submission, however it ended: what "Done" asks of an attempt with a rubric.
func SwitchWorkStorageOff ¶ added in v0.1.21
SwitchWorkStorageOff switches the storage of the profile's works off at at, records when, and erases every work the server keeps of the profile, in tx: one step. The works go after the profile's row is updated, which waits for a PutWork holding it FOR SHARE, unless tx waited for it before, at HoldProfile: the DELETE then sees the work that PutWork kept. In the other order the DELETE would lock the rows that PutWork waits to update while the UPDATE waits for PutWork.
func SwitchWorkStorageOn ¶ added in v0.1.21
func SwitchWorkStorageOn(ctx context.Context, tx pgx.Tx, profileID, giver string, textVersion *int32, at time.Time) error
SwitchWorkStorageOn switches the storage of the profile's works on at at, by the consent of giver to the version of storage-consent: a record of its own, in the place of an open one of another giver.
func Today ¶ added in v0.1.23
Today is the account's family day at now as it keeps it, writing nothing: for a request that sends no offset, such as the beginning of an attempt.
func TodayByUTC ¶ added in v0.1.7
TodayByUTC says whether on is the date of now by UTC: the date written once a day, of an account or a profile, that needs no writing again.
func TouchAccount ¶ added in v0.1.4
TouchAccount writes today, by UTC, as the date of the account's last request, once a day at most: the date the account is deleted by after 12 months with no request. A plain UPDATE takes FOR NO KEY UPDATE, which the writes under the account, by FOR KEY SHARE, do not wait for.
func TouchLessonRun ¶ added in v0.1.17
TouchLessonRun records a request on the profile's open run at at: its last action. A request on an attempt of the run is its attempt's action, which the run's last action reads too.
func TouchProfile ¶ added in v0.1.7
TouchProfile writes today, by UTC, as the date of the profile's last activity, once a day at most: the date a profile is deleted by after 12 months with none (П-9), as TouchAccount writes the account's.
func WaitingConsents ¶ added in v0.1.11
WaitingConsents is how many consents for a child wait under the account with no profile: those the limit of CAUSE_TOO_MANY_CONSENTS counts. It takes no lock: its caller holds the account's row FOR NO KEY UPDATE, by HoldAccount, as every request under a key does, so that two requests beside each other count one after the other.
func WorkDecider ¶ added in v0.1.39
WorkDecider is who gave the consent of the account's profile, and so decides the storage of its works, read without a lock, or ErrNoProfile: a profile has a consent always. A lock on the consent would wait in another order than the deletion of the profile, which holds the profile first.
func WorkStorageOn ¶ added in v0.1.21
func WorkStorageOn(ctx context.Context, tx pgx.Tx, profileID string) (giver string, on bool, err error)
WorkStorageOn is the open record of the storage of the profile's works: who gave its consent, and whether it is on.
func WriteChoice ¶ added in v0.1.19
func WriteChoice(ctx context.Context, tx pgx.Tx, profileID string, c NewChoice, at time.Time) (string, error)
WriteChoice writes the profile's choice c, made at at, and gives its ID.
func WriteKeyChecks ¶ added in v0.1.47
WriteKeyChecks writes when each check of an own key the account keeps was made, after HoldKeyChecks held its row.
func WritePin ¶ added in v0.1.6
WritePin writes the account's PIN as state has it: after an action that left one set, which every action of the PIN does.
func WriteProfile ¶ added in v0.1.7
WriteProfile writes the settings of p, the profile ProfileFor held: what an adult changes, and nothing the profile was created with.
func WriteReport ¶ added in v0.1.21
func WriteReport(ctx context.Context, tx pgx.Tx, accountID, profileID string, r Report) (string, error)
WriteReport records the report of the account's profile, at its CreatedAt, and gives its ID.
func WriteRung ¶ added in v0.1.17
func WriteRung(ctx context.Context, tx pgx.Tx, profileID, attemptID string, rung int, w Words) error
WriteRung records the words of the attempt's rung, the first that came for it.
func WriteSkillState ¶ added in v0.1.18
WriteSkillState writes the profile's cache: its state, the mark it was computed on and the number of the last evidence it holds.
func WriteUnderAccount ¶
func WriteUnderAccount(ctx context.Context, db Beginner, accountID string, fn func(pgx.Tx) error) error
WriteUnderAccount runs fn in a transaction that holds the account's row by FOR KEY SHARE and has found it not marked "deleting". The deletion of an account takes the row FOR UPDATE, so a write that got here before the mark commits before the mark is set, and one after it sees the mark and writes nothing. FOR KEY SHARE, rather than FOR SHARE, lets fn itself update fields of the row — the date of the request, the PIN's count — without locking out a neighbouring request of the same account. The transaction commits when fn returns nil, and rolls back on its error, which it returns as it is.
Types ¶
type Account ¶ added in v0.1.4
type Account struct {
// ID is the account's own ID, the subject of the rights.
ID string
// Deleting says the account is marked "deleting".
Deleting bool
// LastRequestOn is the date, by UTC, of the account's last request; zero if
// none was written yet.
LastRequestOn time.Time
// DebugModels says the account has the right of the debug mode.
DebugModels bool
}
Account is what a request knows of the account of its token.
func AccountByUID ¶ added in v0.1.4
AccountByUID is the account of the sign-in service's UID, or ErrNoAccount.
type AccountRef ¶ added in v0.1.9
AccountRef is an account the daily job works on: its ID and its UID at the sign-in service.
func IdleAccounts ¶ added in v0.1.9
func IdleAccounts(ctx context.Context, db Lister, before time.Time, after string, limit int) ([]AccountRef, error)
IdleAccounts is up to limit accounts not marked whose last request was before before, whose ID comes after after, by ID: those the daily job deletes after 12 months without a request (П-9). An account with no date of a request yet is none of them.
func MarkedBefore ¶ added in v0.1.9
func MarkedBefore(ctx context.Context, db Lister, before time.Time, after string, limit int) ([]AccountRef, error)
MarkedBefore is up to limit accounts marked "deleting" before before, whose ID comes after after — empty for the first page —, by ID: the marks a request left unfinished, which the daily job finishes. The job pages by the last ID it saw, so that an account it fails on is not chosen again in the same pass.
type Answer ¶ added in v0.1.85
Answer is the answer of a submission with a verdict, and whether the submission keeps an observation of what AI read.
type Attempt ¶ added in v0.1.15
type Attempt struct {
ID string
Paper bool
PackageDigest string
ModuleID string
ModuleVersion string
FormatVersion string
ModuleKit string
TaskID string
Seed uint64
Instance *int
ChoiceID *string
LessonRunID *string
Segment *int
PreviousID *string
LastActionAt time.Time
CloseReason *string
WrongAnswers int
// RequestedTechniques and LeadingQuestion say whether a hint asked for gave
// the task's techniques, and its leading question.
RequestedTechniques bool
LeadingQuestion bool
// CorrectWordsGiven says whether the tutor's words after a correct answer were
// given on it.
CorrectWordsGiven bool
// PaperCheck is the last Check of an attempt of a task from paper, the
// message Check of novatrail.paper.v1, while the attempt is open: nil before
// its first Check.
PaperCheck []byte
// PaperHistory is the Checks of an attempt of a task from paper before its
// last, in order, while it is open: each a message Check of its verdicts, its
// tutor's words and, in its hints, the rungs of its ladder the learner was
// shown.
PaperHistory [][]byte
// PaperReading is the reading of the statement of an attempt of a task from
// paper, the message Reading of novatrail.paper.v1, while the attempt is open:
// nil before "Recognise" made it.
PaperReading []byte
}
Attempt is an attempt's row, as the requests on it read it. One of a task from paper has Paper, and the fields of a module, its package, its task and its seed empty.
func HoldAttempt ¶ added in v0.1.15
HoldAttempt is the profile's attempt by its ID, its row held FOR UPDATE in tx, so that the requests on one attempt go one after the other; ErrNotFound when the profile has none.
func HoldOpenAttempt ¶ added in v0.1.15
HoldOpenAttempt is the profile's open attempt of a task of a module, its row held FOR UPDATE in tx, and whether it has one: the open attempts of a page from paper stay beside it.
type Charge ¶ added in v0.1.23
type Charge struct {
AccountID, ProfileID string
Day quota.Day
Amount quota.Micro
// OffDeployment says api runs off a deployment, where alone a tariff of the
// dev projects has its caps (quota.CapsOf): unset, it has none.
OffDeployment bool
}
Charge is what a request takes of the quota of platform AI: of the profile and its account, on the family day of its reserve, the amount reserved.
type ChildConsent ¶ added in v0.1.5
type ChildConsent struct {
ID string
AgeCategory string
Country string
// State is "waiting" or "confirmed".
State string
// Giver is who gives it: GiverOwner, GiverParent or GiverLearner.
Giver string
// RequestCode and FormState are a parent's: the code of the request and the
// state of the form.
RequestCode string
FormState string
// Applied is the age of digital consent of the country on the day the age was
// given, by which the category was; 0 for the owner's.
Applied int
}
ChildConsent is a consent for a child that waits for its profile.
func AskChildConsent ¶ added in v0.1.21
func AskChildConsent(ctx context.Context, tx pgx.Tx, accountID string, c NewConsent) (ChildConsent, error)
AskChildConsent records a consent for a child that waits, under the account: with no pseudonym, no other field of the profile, and not the age in years. A code of a request another waiting consent has is ErrCodeTaken, and tx can go on: the insert runs in a savepoint of its own.
type Choice ¶ added in v0.1.15
Choice is what an engine's choice names, as far as the beginning of an attempt or a lesson run reads it: its kind, its module, and the task of a choice of a task or the lesson's local ID of a choice of a lesson.
type ClosedAttempt ¶ added in v0.1.19
type ClosedAttempt struct {
ID string
PackageDigest string
ModuleID string
TaskID string
CloseReason string
ClosedAt time.Time
LessonID *string
ReasonCode *int
Evidence []byte
}
ClosedAttempt is a closed attempt of the profile as the engine's input reads it: what it was of, how and when it closed, the full ID of the lesson of its run, the reason code of the choice that began it — of its run's, for a segment; none for an attempt begun again or by a choice with no reason code —, and its evidence, when the journal has it.
func ClosedAttempts ¶ added in v0.1.19
func ClosedAttempts(ctx context.Context, db Lister, profileID, module string) ([]ClosedAttempt, error)
ClosedAttempts is the profile's closed attempts of modules, the last closed first: of the module of the ID module alone, when it names one.
type ConnectedModule ¶ added in v0.1.13
type ConnectedModule struct {
ModuleID string
ConnectedAt time.Time
TaskSkill string
SheetSolved []string
}
ConnectedModule is a module connected to a profile: its ID and when it was connected, with no version, its task skill, empty while the tutor chooses, and, of a module solved on the sheet, the local IDs of the tasks the learner has solved, an attempt of each closed correct, on any version, in the order of their bytes.
func ConnectedModules ¶ added in v0.1.13
ConnectedModules is the modules connected to the profile, in the order they were connected, and by ID among those connected at one time.
type Consent ¶ added in v0.1.7
type Consent struct {
ChildConsent
// ProfileID is the profile created by it, or empty while there is none.
ProfileID string
}
Consent is a consent for a child, as its profile is created by it.
func ConsentFor ¶ added in v0.1.7
ConsentFor is the account's consent for a child, held FOR UPDATE in tx, or ErrNoConsent.
type Correction ¶ added in v0.1.59
Correction is a correction of a module's level in a profile's journal: the module and the evidence, as learner-model's codec gives it.
func Corrections ¶ added in v0.1.59
Corrections is the corrections of the level of the module of the profile's journal, or with module empty of every module, connected or not since, in the order of the modules' IDs byte by byte and of the journal.
type Cursor ¶ added in v0.1.18
Cursor is where a page of the progress goes on from: the attempt last on the page before, by its beginning and its ID.
type Entry ¶ added in v0.1.18
type Entry struct {
Seq int64
AttemptID string
PackageDigest string
ModuleID string
ClosedAt time.Time
Evidence []byte
}
Entry is a row of a profile's journal of evidence: its number, its attempt, the package and the module of the attempt, when the attempt closed, and the evidence as learner-model's codec gives it. A row of an adult's correction of a module's level has no attempt, AttemptID empty and ClosedAt zero, and its package is that of the module's current version when the level was set.
type Essay ¶ added in v0.1.49
Essay is how a submission of an essay ended: its end, and beside feedback the mark of each criterion by its number in the rubric, from 1, and the source of the words. Neither the text read nor the words are in it.
type EssaySubmission ¶ added in v0.1.49
EssaySubmission is a submission of an essay as the server keeps it: when it came, and how it ended.
func EssaySubmissions ¶ added in v0.1.49
func EssaySubmissions(ctx context.Context, db Lister, profileID string, attemptIDs []string) ([]EssaySubmission, error)
EssaySubmissions is the submissions of the profile's attempts of attemptIDs that are essays, by attempt and in order.
type ExportedAttempt ¶ added in v0.1.21
type ExportedAttempt struct {
exportv7.Attempt
Owed Owed
// LeadingQuestionGiven says the task's leading question was given on
// request, which its package words.
LeadingQuestionGiven bool
}
ExportedAttempt is an attempt as the export reads it, with the rows the package of its module turns into what it tells: its task, its instance and the bytes of the answers of its submissions.
type ExportedPaperAttempt ¶ added in v0.1.72
type ExportedPaperAttempt struct {
Attempt exportv7.PaperAttempt
Answers [][]byte
}
ExportedPaperAttempt is an open attempt of a task from paper as the export reads it, with the bytes of the answers of its submissions. The Check it keeps, with the model's hidden solution and answer, never reaches the device, and the export reads none of it.
type ExportedProfile ¶ added in v0.1.21
type ExportedProfile struct {
Profile exportv7.Profile
Attempts []ExportedAttempt
PaperAttempts []ExportedPaperAttempt
Evidence [][]byte
State []byte
Observations map[string]map[int64][]byte
}
ExportedProfile is a profile's part of the export as the database holds it, with the bytes of its records of protobuf: each piece of evidence, by the order of the log, the state, and each submission's observation, by the attempt and the number of the submission. The stored works it names in the profile alone, without their bytes.
func ExportProfile ¶ added in v0.1.21
func ExportProfile(ctx context.Context, tx pgx.Tx, accountID, profileID string) (ExportedProfile, error)
ExportProfile is the profile's part of the export, of the account's profile, or ErrNoProfile. Its mode is noMode, its "ask before showing" off, and its attempts name no technique given at a step: none of them is kept any more.
type Issued ¶ added in v0.1.19
Issued is when a skill was last handed out by a choice, by its full ID.
type KeyRecord ¶ added in v0.1.6
type KeyRecord struct {
Method string
Fingerprint string
State string
Response []byte
SubmissionID string
// Age is how long ago the record was made, by the database's clock: a record
// still going past the longest a request may run is of a request that fell.
Age time.Duration
}
KeyRecord is what is recorded of a request under its idempotency key: its method, its fingerprint, its state and, once done, its answer — or, for an answer that holds what the learner sent, the submission it recorded.
type KeyTarget ¶ added in v0.1.15
KeyTarget is what a request done under a key acted on, and what its record holds of the answer: the profile and the attempt it acted on, when it did, and either the answer or the submission whose answer a repeat gets.
type Learner ¶ added in v0.1.13
type Learner struct {
AgeCategory string
Consented bool
// Country and Applied are the country of the learner and the age of digital
// consent their category was given by, by which their age may be asked again.
Country string
Applied int
}
Learner is what a learning request reads of its profile, in one query: the age category, by which a module's audience suits it, and whether its consent is confirmed: a profile has one consent at most, which a learner who consents themselves, or whose age was given again, waits for.
type LessonRun ¶ added in v0.1.17
type LessonRun struct {
ID string
LessonID string
ModuleID string
ModuleVersion string
PackageDigest string
ChoiceID string
LastActionAt time.Time
EndReason *string
}
LessonRun is a lesson run's row, as the requests on it read it.
func HoldLessonRun ¶ added in v0.1.17
HoldLessonRun is the profile's lesson run by its ID, its row held FOR UPDATE in tx, so that the requests on one run go one after the other; ErrNotFound when the profile has none.
type Lister ¶ added in v0.1.7
Lister is what a list is read from: a pool, a connection or a transaction.
type MadeChoice ¶ added in v0.1.19
MadeChoice is a choice written: its ID and kind, and, beside nothing to give, whether its answer said the AI was closed — and why, by a word of NothingCauses, with when the next family day begins beside the quota.
func ChoiceAfterAttempt ¶ added in v0.1.19
func ChoiceAfterAttempt(ctx context.Context, db Querier, profileID, attemptID string) (MadeChoice, bool, error)
ChoiceAfterAttempt is the choice the close of the profile's attempt gave as what comes next, and whether it gave one: a repeat of the request that closed it gives it again.
func ChoiceAfterRun ¶ added in v0.1.19
func ChoiceAfterRun(ctx context.Context, db Querier, profileID, runID string) (MadeChoice, bool, error)
ChoiceAfterRun is the choice the end of the profile's lesson run gave, and whether it gave one.
type Mark ¶ added in v0.1.18
Mark is what the cache of a profile's skill state was computed on: the version of learner-model, the release of modules and the window of the format's versions. An empty field is a cache never written.
type ModuleChoices ¶ added in v0.1.19
ModuleChoices is how many choices of a module the profile had, a lesson's counted once.
func ChoicesByModule ¶ added in v0.1.19
ChoicesByModule is how many choices the profile had of each module.
type NewAttempt ¶ added in v0.1.15
type NewAttempt struct {
PackageDigest string
ModuleID string
ModuleVersion string
FormatVersion string
ModuleKit string
TaskID string
Seed uint64
Instance *int
ChoiceID *string
PreviousID *string
// LessonRunID and Segment are the run and the place of the segment of an
// attempt of a lesson's task.
LessonRunID *string
Segment *int
}
NewAttempt is what an attempt begins with: its package, the versions its verdict repeats by, its task, seed and instance, and one of the three ways it begins.
type NewChoice ¶ added in v0.1.19
type NewChoice struct {
Kind string
ModuleID string
TaskID string
LessonID string
NotAdmitted bool
// Closed is why the AI that checks the tasks was closed, beside nothing to
// give when it left a task out: a word of NothingCauses, with NextDay beside
// the quota.
Closed string
NextDay *time.Time
ReasonCode int
IssuedSkills []string
PackageDigest string
MapSkill string
// ScopeModule is the module the choice was among: of its tasks alone, or the
// module of a lesson the learner chose; empty among all the modules.
ScopeModule string
AgeCategory string
Grade *int
PoolLimited bool
Mark Mark
EngineVersion string
LastSeq int64
Digests []string
EngineDigests []string
// AfterAttemptID and AfterLessonRunID name the close of an attempt or the end
// of a run that gave the choice as what comes next.
AfterAttemptID *string
AfterLessonRunID *string
}
NewChoice is an engine's choice as it is written: what it gives — a task, a lesson or nothing, with the outcome "not admitted" or none —, its reason code, the skills it handed out and the package it was made on, and the input a replay needs — the skill chosen on the skill map, the age category and the grade of the profile, whether the pool was limited to the tasks a tap checks, the versions, the release and the window, the number of the last evidence read, and the digests of the graphs —, with the close or the end of a run whose next it is, when it is one.
type NewConsent ¶ added in v0.1.21
type NewConsent struct {
AgeCategory string
Country string
Applied int
Giver string
RequestCode string
TextVersion *int32
}
NewConsent is a consent for a child as it is asked for: the category of the learner, the country, the age of the country it was given by, who gives it, and, for a parent's, the code of its request and the version of parent-consent.
type NewRun ¶ added in v0.1.17
type NewRun struct {
LessonID string
ModuleID string
ModuleVersion string
PackageDigest string
ChoiceID string
}
NewRun is what a lesson run begins with: the lesson, its module and version, the package, and the engine's choice that opens it.
type OpenAttempt ¶ added in v0.1.15
OpenAttempt is a profile's open attempt, as the list of profiles names it: its ID, and its lesson run and segment when it is one of a run.
func RunAttempt ¶ added in v0.1.17
RunAttempt is the run's open attempt and the place of its segment, and whether it has one.
type OpenLessonRun ¶ added in v0.1.17
OpenLessonRun is a profile's open lesson run, as the list of profiles names it: its ID, the lesson's full ID and its package.
type OpenOn ¶ added in v0.1.20
OpenOn is an open attempt or lesson run the job after a rollout closes: its ID, with its profile and account.
func OpenAttemptsOn ¶ added in v0.1.20
func OpenAttemptsOn(ctx context.Context, db Lister, digests []string, after string, limit int) ([]OpenOn, error)
OpenAttemptsOn is up to limit open attempts on the packages of digests, whose ID comes after after, by ID, of accounts no deletion marked: those whose package the image does not give. An account marked goes with its attempts.
type Owed ¶ added in v0.1.18
type Owed struct {
ID string
PackageDigest string
ModuleID string
TaskID string
Instance *int
CloseReason string
WrongAnswers int
LastActionAt time.Time
RequestedTechniques bool
LeadingQuestion bool
ExplainedAgain int
SolutionSeenBefore bool
Answers [][]byte
}
Owed is a closed attempt whose evidence is not in the journal yet, with what its evidence is built of: what it was of, how it closed, its last action, the techniques given on request, whether a hint asked for gave the task's leading question, how many times "explain differently" was asked for, whether the solution of its task reached the device before it began, and the answers of its submissions, in order.
func OwedAttempts ¶ added in v0.1.18
func OwedAttempts(ctx context.Context, tx pgx.Tx, profileID string, digests []string) ([]Owed, error)
OwedAttempts is the profile's attempts that owe their evidence, on the packages digests names — those the image holds: one whose package left the image gives none, as its evidence is built from the package —, in the order they closed.
type Profile ¶ added in v0.1.5
type Profile struct {
ID string
Owner bool
Pseudonym string
Avatar string
AgeCategory string
Country string
VoicingEnabled bool
VoicingSpeed string
InterfaceLanguage *string
Grade *int16
// HintMode is "show_where" or "questions_only".
HintMode string
// WorkStorage says the storage of the learner's works on the server is on.
WorkStorage bool
// AgeStatedOn is the day the age was last given, by UTC: a year after it, the
// category is refined.
AgeStatedOn *time.Time
// Consent is the profile's consent, which AccountView and ProfileWithConsent
// read.
Consent Consent
// OpenAttempt is the profile's open attempt, which the view of the account
// alone reads: nil when it has none.
OpenAttempt *OpenAttempt
// OpenLessonRuns are the profile's open lesson runs, one at most for each
// lesson, which the view of the account alone reads.
OpenLessonRuns []OpenLessonRun
}
Profile is a profile's row, with the contract's codes as the schema keeps them.
func CreateChildProfile ¶ added in v0.1.7
func CreateChildProfile(ctx context.Context, tx pgx.Tx, accountID string, c Consent, p Profile) (Profile, error)
CreateChildProfile makes the profile of a confirmed consent, which ConsentFor held, of its category and country, binds the consent to it, and makes the row of its skill state. The date the age was given is the date the consent was asked for, by UTC.
func CreateOwnerProfile ¶ added in v0.1.7
func CreateOwnerProfile(ctx context.Context, tx pgx.Tx, accountID string, p Profile) (Profile, error)
CreateOwnerProfile makes the owner's profile in tx, of the category adult by the owner's statement, with its consent: confirmed now, given by that statement, and the row of its skill state. The date the age was given is the date of the statement, and every date is by UTC, as TouchProfile writes it. The account has one owner's profile: a second is ErrProfileExists.
func ProfileFor ¶ added in v0.1.7
ProfileFor is the account's profile, held FOR UPDATE in tx for a change, or ErrNoProfile.
type ProfileRef ¶ added in v0.1.9
ProfileRef is a profile the daily job works on, with its account.
func IdleProfiles ¶ added in v0.1.9
func IdleProfiles(ctx context.Context, db Lister, before time.Time, after string, limit int) ([]ProfileRef, error)
IdleProfiles is up to limit profiles of accounts not marked, active last before before, whose ID comes after after, by ID: those the daily job deletes after 12 months without activity (П-9).
type Progress ¶ added in v0.1.83
Progress is how far a request going has got: whether one is going, and the place of the model that reads its work, from 0, of a list of models; both 0 while it has noted none.
func CheckProgress ¶ added in v0.1.83
func CheckProgress(ctx context.Context, db Querier, accountID, profileID, attemptID, method string, goingFor time.Duration) (Progress, error)
CheckProgress is the progress of the request of method going on the profile's attempt under the account, the latest of them, made less than goingFor ago: an older one is of a request that fell. None is going false.
type Querier ¶ added in v0.1.4
type Querier interface {
QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
}
Querier is what a read runs on: a pool, a connection or a transaction.
type Record ¶ added in v0.1.18
type Record struct {
ID string
PackageDigest string
TaskID string
ModuleID string
ModuleVersion string
LessonID *string
CloseReason *string
WrongAnswers int
StartedAt time.Time
ClosedAt *time.Time
ChosenAt *time.Time
ReasonCode *int
}
Record is an attempt in the progress of a profile: what it was of, on which package, the lesson of its run, how it closed, when it began and closed, and when the engine chose its task — or its run's lesson — and why: none for an attempt begun again, or by a choice with no reason code.
type Report ¶ added in v0.1.21
type Report struct {
ID string
AttemptID string
Reply string
Rung *int16
Words string
Kind string
Text string
CreatedAt time.Time
}
Report is a problem report of an adult on a reply of the tutor.
type ReportToReview ¶ added in v0.1.21
ReportToReview is a problem report the operator reads, with the day it is to be reviewed by.
func ReportsToReview ¶ added in v0.1.21
func ReportsToReview(ctx context.Context, db Lister, within time.Duration) ([]ReportToReview, error)
ReportsToReview is every report not reviewed yet, by when it came.
type Restated ¶ added in v0.1.21
type Restated struct {
AgeCategory string
Country string
Applied int
// Giver is who gives the consent the profile needs after; empty keeps the
// one it has.
Giver string
RequestCode string
TextVersion *int32
}
Restated is what a profile's age given again sets: the category and the country, the age of the country it was given by, and the consent it needs after — the one it has, kept, or a new one, which waits: the learner's, or a parent's by a new code.
type Run ¶ added in v0.1.19
type Run struct {
ID string
LessonID string
ModuleID string
PackageDigest string
EndReason *string
EndedAt *time.Time
}
Run is a lesson run of the profile as the engine's input reads it: its ID, its lesson, its package, and how and when it ended, while it has.
type Rung ¶ added in v0.1.17
Rung is what an attempt keeps of one of its rungs: its words, and, once "explain differently" was asked for on it, the words that came of it, which the learner reads from then on. The words are empty once the attempt has closed.
type Scope ¶ added in v0.1.84
Scope is what a choice was made among: the skill a choice named alone, and the module whose tasks alone it was among; neither when the engine led among all the modules.
type SentForm ¶ added in v0.1.21
SentForm is a parent's consent whose form the operator checks: its code and where its scan lies.
type Settled ¶ added in v0.1.34
type Settled struct {
Day quota.Day
// Caps are the caps of the account's tariff, and Capped is false when it has
// none: platform AI is closed to it, and there is no share.
Caps quota.Caps
Capped bool
Profile, Account quota.Micro
}
Settled is what a profile and its account have spent of the quota of a family day, as their calls were settled, without the reserves of calls still going, beside the caps of the account's tariff: what the share of the quota counts by.
func QuotaSettled ¶ added in v0.1.34
func QuotaSettled(ctx context.Context, q Querier, accountID, profileID string, now time.Time, offDeployment bool) (Settled, error)
QuotaSettled is what the account's profile and the account have spent of the quota on the family day the account keeps at now, read in q and writing nothing, as Today: the request carries no offset. A profile the account does not have is ErrNoProfile. q is best a snapshot, so that the day, the tariff and the counters are of one moment. A tariff of the dev projects alone has caps only offDeployment, as for a reserve.
type SheetTask ¶ added in v0.1.87
type SheetTask struct {
Module, Task string
}
SheetTask is a task of a module solved on the sheet: the module's ID and the task's local ID. Its zero value is a task from paper, of no module.
type SkillState ¶ added in v0.1.18
SkillState is a profile's row of the cache of the skill state: the state as learner-model's codec gives it, empty while it was never written, its mark, and the number of the last evidence it holds.
func HoldSkillState ¶ added in v0.1.18
HoldSkillState holds the profile's row of the cache FOR UPDATE in tx, so that the evidence of one profile is numbered and folded one piece after another. The profile's own row is held FOR KEY SHARE first, as the rows of the journal that the caller then adds refer to it: a deletion of the profile, which takes it FOR UPDATE before its cascade reaches the cache, waits, rather than locking the two rows in the other order. A profile may have no row of the cache, so the row is made first, empty, when it is not there; a profile gone is ErrNoProfile.
type Solution ¶ added in v0.1.19
Solution is when the solution of a task of a module last went to the profile's device: an attempt of it closed correct or with the solution shown.
type TxBeginner ¶ added in v0.1.5
TxBeginner is what a transaction with its options starts from: a pool, or a connection.
type View ¶ added in v0.1.5
type View struct {
// ID is the account's ID.
ID string
// PinSet says the PIN of the section for adults is set.
PinSet bool
// Profiles are the account's profiles: the owner's first, then by when they
// were created.
Profiles []Profile
// ChildConsents are the consents for a child that have no profile, by when
// they were asked for.
ChildConsents []ChildConsent
}
View is the account as GetAccount gives it: whether its PIN is set, its profiles with their open attempts and lesson runs, and its consents for a child with no profile yet.
func AccountView ¶ added in v0.1.5
AccountView reads the account in one snapshot, so that its profiles and its consents are of one moment: a device erases the profiles the list does not hold. An account that is not there is ErrNoAccount, and one marked "deleting" ErrAccountDeleting.
type Work ¶ added in v0.1.39
Work is a stored work of a profile: the attempt whose work it is, what it is, its size as the contract counts it, when api kept it, and, where it is read whole, its bytes — the contract's StoredWork in binary protobuf, which the store does not read.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package storetest runs the tests of api's database on a real PostgreSQL with no Docker, as the devcontainer and CI have none: embedded-postgres starts one server for a test binary, when its first test asks for a database, migrates a template database once, and gives each test a database of its own made from it, which is a copy and takes milliseconds.
|
Package storetest runs the tests of api's database on a real PostgreSQL with no Docker, as the devcontainer and CI have none: embedded-postgres starts one server for a test binary, when its first test asks for a database, migrates a template database once, and gives each test a database of its own made from it, which is a copy and takes milliseconds. |