quota

package
v0.1.39 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package quota is the quota of platform AI (R11, R12; architecture 3.6): its unit, the tariffs and their caps for a family day, the typical tasks a new task of handwriting must find room for, and the reserve of a kind of call when tutor gives no expected price.

The values are the configuration of api, and a pull request changes them, as R11 has it: they are product, not deployment, and a deployment that set its own would make two platforms of one release without a word in the log. The first values are those of the tariff of the closed slice, $0.50 a profile and $1.50 an account; the estimates behind them are in architecture 3.6.

Index

Constants

View Source
const (
	// ClosedSlice is the tariff of the closed slice, a code's by default.
	ClosedSlice = "closed_slice"
	// Probe is a tariff of a few cents a day, which the operator gives an account
	// to see the quota run out on a run with app (T52): room for a typical task
	// and a few checks after it, and no more.
	Probe = "probe"
)

The tariffs. An account gets its tariff with its invite code (R04, R34), and the operator changes it by api tariff.

Variables

This section is empty.

Functions

func Known

func Known(tariff string) bool

Known says whether tariff is one of Tariffs.

func Reached added in v0.1.34

func Reached(caps Caps, profile, account Micro) bool

Reached says whether what the profile or its account has spent has reached its cap of caps: no request of the profile on platform AI goes until the next family day.

func Share added in v0.1.34

func Share(spent, limit Micro) int32

Share is the share of the cap limit that spent takes, in whole percent rounded down, as the share of the quota gives it (the amendment of 2026-11-12 to R11): 100 is the cap reached, and spending past it is 100 too, as is any of no cap.

func Tariffs

func Tariffs() []string

Tariffs is every tariff, by its name, in the order of the table.

func ValidOffset

func ValidOffset(minutes int32) bool

ValidOffset says whether minutes is an offset of a clock from UTC that the quota takes: from −12 to +14 hours, a multiple of a quarter of an hour. Any other is ignored, and the request counts under the offset kept.

Types

type Caps

type Caps struct {
	Profile, Account Micro
}

Caps are the caps of a tariff for a family day: of each profile, which keeps the children of one account fair to each other, and of the account, which holds what the account spends (R11).

func CapsOf

func CapsOf(tariff string) (Caps, bool)

CapsOf is the caps of the tariff, and false for an account with no tariff or a tariff with no caps: platform AI is closed to it, by default, as the function of admission closes a route it does not know (R11).

type Clock

type Clock struct {
	Offset *int32
	Day    *Day
}

Clock is what an account keeps of its family day: the last offset its devices sent, in minutes, if any, and its current day, if it has had one.

func (Clock) Sent

func (c Clock) Sent(reported *int32, now time.Time) (Clock, bool)

Sent is the clock c after a request at now that sent the offset reported, if it sent one, and whether it changed: a valid offset is kept, for the days that begin from then on — the current day ends at its own end — and once the day kept is over, the clock keeps the day that holds now. An offset that is not valid is ignored.

func (Clock) Today

func (c Clock) Today(now time.Time) Day

Today is the family day of the clock c at now, as c keeps it: its day, until it ends, even when the server's clock went back before its start; else the day that holds now, by the offset kept — UTC when there is none — and after the day kept.

type Counter

type Counter struct {
	Spent, Reserved Micro
}

Counter is what a counter of a family day holds: spent, and in reserve.

type Day

type Day struct {
	Start, End time.Time
}

Day is a family day: the instant it begins, the key of its counters, and the instant it ends, the first of the next.

func (Day) Holds

func (d Day) Holds(t time.Time) bool

Holds says whether the day holds the instant t: from its start, until its end.

type Micro

type Micro int64

Micro is an amount of US dollars by tutor's estimate, in whole micro-dollars, as the export writes the counters (exportv2.QuotaCounter): a sum of them adds up the same in every order, which a float does not.

const (
	// TypicalHandwriting is a task of handwriting: two checks and the words of a
	// rung and of praise. By tutor v0.1.24's expected prices, $0.0093 a check by
	// the pair and $0.0182 the words (Tutor.Price), it is $0.055; the first app
	// measured $0.014 a check (T42), and this is $0.06.
	TypicalHandwriting Micro = 60_000
	// TypicalRubric is a task with a rubric: two readings of the essay with their
	// assessment, the first submission and one rewrite, ≈ $0.06 by the price of
	// an essay at tutor (architecture 3.4 tutor).
	TypicalRubric Micro = 60_000
)

The typical tasks (R11; the amendment of 2026-11-02 to it). A new task that platform AI checks begins only when what is left of the day holds one, so that the learner does not begin work nobody can read today.

func Reserve

func Reserve(call tutor.Call, price tutor.CallPrice, crops int) Micro

Reserve is what a call of the kind reserves before it goes: tutor's expected price, when it has one, or the value of the kind here. A page of a workbook reserves by its crops, crops of them; any other call, crops = 1.

func USD

func USD(d float64) Micro

USD is d dollars in micro-dollars, rounded up: a quota errs on the side of spending, never of letting a call through for free. Below zero, or not a number, is none.

func (Micro) Dollars

func (m Micro) Dollars() float64

Dollars is m in dollars, for a test or a line that writes it as a number.

type Spent

type Spent string

Spent is why a reserve does not fit, in the words of the log's line of an exhausted quota: the cap of the profile or of the account has too little left, or the account has no tariff with caps. Fits is none: it fits.

const (
	Fits       Spent = ""
	ProfileCap Spent = "profile"
	AccountCap Spent = "account"
	NoTariff   Spent = "tariff"
)

The reasons a reserve does not fit.

func Room

func Room(caps Caps, profile, account Counter, amount Micro) Spent

Room says whether a reserve of amount fits under caps beside the counters of the profile and of its account: on each, what is spent, what is in reserve and amount together are no more than its cap (R12). The profile's cap is asked first.

Jump to

Keyboard shortcuts

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