domain

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2023 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// env
	EnvDev = "dev"
	// locales
	LocaleRu = "ru"
	LocaleEn = "en"
	// generate questions methods
	GenerateQuestionsNone     = "none"
	GenerateQuestionsEachItem = "each-item"
	// scale types
	ScaleTypeSten   = "sten"
	ScaleTypeSum    = "sum"
	ScaleTypePerc   = "perc"
	ScaleTypeZScore = "zscore"
	ScaleTypeMean   = "mean"
	// question types
	QuestionTypeSimple = "simple"
	// test steps
	TestStepIntro     = "intro"
	TestStepQuestions = "questions"
	TestStepFinish    = "finish"
	TestStepResult    = "result"
	// samples
	SampleAllCode              = "all"
	SampleAllNonSuspiciousCode = "all-not-suspicious"
	// norms
	NormMinBase  = 10
	NormOKBase   = 50
	NormGoodBase = 100
	// take
	TakeMinTime = 8 * time.Second
	TakeMaxTime = 2 * time.Hour
	TakeMinMark = 1
	TakeMaxMark = 5
	// tags
	TagTypeTheme   = "theme"
	TagTypeLen     = "len"
	TagTypeFeature = "feature"
	TagCodeShort   = "short"
	TagCodeMedium  = "medium"
	TagCodeLong    = "long"
	TagLenShort    = 10
	TagLenLong     = 50
	// time
	DefaultDisplayTime = time.RFC822
	// app
	AppMaxEvents        = 30
	ShareScaleLen       = 5
	ShareScaleUnit      = "🟪"
	ShareScaleUnitEmpty = "⬜️"
)

Variables

This section is empty.

Functions

func AreValidLocales

func AreValidLocales(locales []string) bool

func DefaultLocale

func DefaultLocale() string

func IsValidLocale

func IsValidLocale(locale string) bool

func LocaleIcon

func LocaleIcon(locale string) string

func Locales

func Locales() []string

func UILocales

func UILocales() []string

Types

type CreateInterpretationArgs

type CreateInterpretationArgs struct {
	Range        [2]float64
	Translations []InterpretationTranslation
}

test import args

type CreateItemArgs

type CreateItemArgs struct {
	Code         string
	Steps        int
	Reverse      bool
	Translations []ItemTranslation
}

test import args

type CreateQuestionArgs

type CreateQuestionArgs struct {
	Code         string
	Type         string
	Order        int
	Translations []QuestionTranslation
	Items        []CreateItemArgs
}

test import args

type CreateScaleArgs

type CreateScaleArgs struct {
	Type            string
	Code            string
	Translations    []ScaleTranslation
	Items           []CreateItemArgs
	Interpretations []CreateInterpretationArgs
}

test import args

type CreateTagArgs

type CreateTagArgs struct {
	Code         string
	Type         string
	Translations []TagTranslation
}

test import args

func (*CreateTagArgs) ValidateTranslations

func (t *CreateTagArgs) ValidateTranslations() error

type CreateTestArgs

type CreateTestArgs struct {
	Code             string
	Published        bool
	AvailableLocales []string `yaml:"availableLocales"`
	ForceUpdate      bool     `yaml:"forceUpdate"`
	Generate         GenerateQuestionsArgs
	Image            string
	Tags             []string
	Translations     []TestTranslation
	Questions        []CreateQuestionArgs
	Scales           []CreateScaleArgs
	Display          CreateTestDisplayArgs
}

test import args

func (*CreateTestArgs) ValidateTranslations

func (t *CreateTestArgs) ValidateTranslations() error

type CreateTestDisplayArgs

type CreateTestDisplayArgs struct {
	QuestionsPerPage int  `yaml:"questionsPerPage"`
	RandomizeOrder   bool `yaml:"randomizeOrder"`
}

test import args

type Event

type Event struct {
	Name      string
	StartTime time.Time
	EndTime   time.Time
	Elapsed   time.Duration
}

system types

type GenerateQuestionsArgs

type GenerateQuestionsArgs struct {
	Method   string
	Template CreateQuestionArgs
}

test import args

type Interpretation

type Interpretation struct {
	ID      uuid.UUID
	Content template.HTML // translatable
	Range   [2]float64
}

test logic types

type InterpretationTranslation

type InterpretationTranslation struct {
	Locale  string
	Content string
}

test import args

type Item

type Item struct {
	ID         uuid.UUID
	TestID     uuid.UUID
	ScaleID    uuid.UUID
	QuestionID uuid.UUID
	Code       string
	Content    string // translatable
	Steps      int    // number of steps in response scale
	Reverse    bool
	// Type       string
	Response *Response // for use in handler, not for saving
}

test logic types

func (*Item) AddResponse

func (i *Item) AddResponse(takeID uuid.UUID, value int, meta map[string]interface{}) error

func (*Item) CurrentResponseValue

func (i *Item) CurrentResponseValue() int

type ItemTranslation

type ItemTranslation struct {
	Locale  string
	Content string
}

test import args

type Norm

type Norm struct {
	ID       uuid.UUID
	SampleID uuid.UUID
	ScaleID  uuid.UUID
	Name     string
	Base     int
	Mean     float64
	Sigma    float64
	Rank     int
	Meta     map[string]interface{}
}

test logic types

type NormCalculationData

type NormCalculationData struct {
	ScaleID   uuid.UUID
	ScaleCode string
	Results   []float64
}

norm calculation args

type PrepareTestArgs

type PrepareTestArgs struct {
	UserID  uuid.UUID
	Session string
}

function args

type QueryTestsArgs

type QueryTestsArgs struct {
	Locale        string
	Tags          []*Tag
	TagIDs        []uuid.UUID
	FilterModeAny bool
}

query args

type Question

type Question struct {
	ID            uuid.UUID
	TestID        uuid.UUID
	Code          string
	Order         int
	Content       string // translatable
	HeaderContent string // translatable
	FooterContent string // translatable
	Items         []*Item
}

test logic types

func (*Question) IsDone

func (q *Question) IsDone() bool

type QuestionTranslation

type QuestionTranslation struct {
	Locale        string
	Content       string
	HeaderContent string
	FooterConent  string
}

test import args

type Response

type Response struct {
	ID         uuid.UUID
	ItemID     uuid.UUID
	TakeID     uuid.UUID
	Value      int
	CreateTime time.Time
	UpdateTime time.Time
	Meta       map[string]interface{}
}

test logic types

type Result

type Result struct {
	ID         uuid.UUID
	TakeID     uuid.UUID
	ScaleID    uuid.UUID
	RawScore   float64
	FinalScore float64
	CreateTime time.Time
	UpdateTime time.Time
	Meta       map[string]interface{}
}

Result is saved to db and used for norms calculation there's no need as yet to save calculatable data like min, max, etc.

type Sample

type Sample struct {
	ID       uuid.UUID
	Code     string
	Criteria SampleCriteria
}

test logic types

func (*Sample) NormRank

func (s *Sample) NormRank(n *Norm) int

type SampleCriteria

type SampleCriteria struct {
	NotSuspicious bool   `json:"notSuspicious,omitempty"`
	Locale        string `json:"locale,omitempty"`
}

test logic types

type Scale

type Scale struct {
	ID              uuid.UUID
	Code            string
	Type            string
	Title           string // translatable
	Description     string // translatable
	Abbreviation    string // translatable
	Global          bool   // if scale can be used by more than one test
	Items           []*Item
	Interpretations []*Interpretation
	Result          *ScaleResult // not save in db as yet
	Norm            *Norm        // to use in calculation
}

test logic types

func (*Scale) CalculateResult

func (s *Scale) CalculateResult(overrideMethod string) error

func (*Scale) ResultShareText

func (s *Scale) ResultShareText() string

type ScaleResult

type ScaleResult struct {
	RawScore       float64
	Score          float64
	Min            float64
	Max            float64
	Interpretation *Interpretation
	Formula        string
	Elapsed        time.Duration
	Unit           string
	Meta           map[string]interface{}
}

test logic types

type ScaleTranslation

type ScaleTranslation struct {
	Locale       string
	Title        string
	Description  string
	Abbreviation string
}

test import args

type SystemSummary

type SystemSummary struct {
	ID            int
	Users         int
	Tests         int
	FinishedTakes int
	Responses     int
	CreateTime    time.Time
}

system types

type Tag

type Tag struct {
	ID      uuid.UUID
	Code    string
	Type    string
	Content string
}

test logic types

type TagTranslation

type TagTranslation struct {
	Locale  string
	Content string
}

test import args

type Take

type Take struct {
	ID         uuid.UUID
	UserID     uuid.UUID
	TestID     uuid.UUID
	Seed       int64
	StartTime  *time.Time
	EndTime    *time.Time
	Suspicious bool
	InLocale   string
	CreateTime time.Time
	UpdateTime time.Time
	Page       int
	Status     string
	Progress   int
	Mark       *int
	Meta       map[string]interface{}
}

Take is one instance of user taking a test

func (*Take) Begin

func (t *Take) Begin() error

func (*Take) Elapsed

func (t *Take) Elapsed() time.Duration

func (*Take) End

func (t *Take) End() error

type Test

type Test struct {
	ID                uuid.UUID
	Code              string        // unique code for url
	Title             string        // translatable
	Description       string        // translatable
	Details           template.HTML // translatable
	Instruction       template.HTML // translatable
	ResultPreambule   template.HTML // translatable
	Locale            string
	AvailableLocales  []string
	GenerateQuestions string
	Published         bool
	Questions         []*Question
	Scales            []*Scale
	Tags              []*Tag
	Image             string
	Display           TestDisplay
	Mark              float64
	Duration          time.Duration
	QuestionCount     int     // for display (and less joins in requests)
	Take              *Take   // for use in handler
	Takes             []*Take // for calculations
}

test logic types

func (*Test) CalculateDuration

func (t *Test) CalculateDuration() time.Duration

func (*Test) CalculateMark

func (t *Test) CalculateMark() float64

func (*Test) CalculateResult

func (t *Test) CalculateResult(overrideMethod string) error

func (*Test) DefaultDuration

func (t *Test) DefaultDuration() time.Duration

func (*Test) GetItem

func (t *Test) GetItem(code string) *Item

func (*Test) IsDone

func (t *Test) IsDone() bool

func (*Test) IsNotDone

func (t *Test) IsNotDone() bool

func (*Test) IsPageDone

func (t *Test) IsPageDone(page int) bool

func (*Test) IsPageNotDone

func (t *Test) IsPageNotDone(page int) bool
func (t *Test) Link(domain string) string

func (*Test) LinkSafe

func (t *Test) LinkSafe(domain string) string

func (*Test) OrderQuestions

func (t *Test) OrderQuestions(seed int64)

func (*Test) PageCount

func (t *Test) PageCount() int

func (*Test) QuestionsForPage

func (t *Test) QuestionsForPage(page int) []*Question

func (*Test) ResultShareText

func (t *Test) ResultShareText() string

type TestDisplay

type TestDisplay struct {
	RandomizeOrder   bool
	QuestionsPerPage int
}

test logic types

type TestTranslation

type TestTranslation struct {
	Locale      string
	Title       string
	Description string
	Details     string
	Instruction string
	Preambule   string
}

test import args

type User

type User struct {
	ID           uuid.UUID
	Name         string
	Email        string
	Admin        bool
	Picture      string
	Password     string
	PasswordHash string
	Locale       string
	Anonymous    bool
	UseDarkTheme bool
	AnonymousID  []uuid.UUID
	Meta         map[string]interface{}
}

user types

type UserSession

type UserSession struct {
	ID           int    // probably uuid not needed here, sessions are temporary anyways
	SID          string // code to identify the session
	UserID       uuid.UUID
	IP           string
	UserAgent    string
	CreateTime   time.Time
	UpdateTime   time.Time
	LastActivity time.Time
	Meta         map[string]interface{}
	Active       bool
}

user types

type UserSummary

type UserSummary struct {
	UserID uuid.UUID
}

user types

Jump to

Keyboard shortcuts

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