model

package
v0.0.0-...-1011682 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2021 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	IsuStateChangeNone IsuStateChange = iota
	IsuStateChangeBad
	IsuStateChangeClear            = 1 << 3
	IsuStateChangeDetectOverweight = 1 << 4
	IsuStateChangeRepair           = 1 << 5
)

Variables

This section is empty.

Functions

func NewIsuRawForInitData

func NewIsuRawForInitData(isu *Isu, owner *User, jiaIsuUUID string)

func NewRandomIsuRaw

func NewRandomIsuRaw(owner *User) (*Isu, *StreamsForPoster, error)

新しいISUの生成 scenarioのNewIsu以外からは呼び出さないこと! 戻り値を使ってbackendにpostする必要あり 戻り値をISU協会にIsu*を登録する必要あり 戻り値をownerに追加する必要あり

Types

type ConditionLevel

type ConditionLevel int

enum

const (
	ConditionLevelNone     ConditionLevel = 0
	ConditionLevelInfo     ConditionLevel = 1
	ConditionLevelWarning  ConditionLevel = 2
	ConditionLevelCritical ConditionLevel = 4
)

func (ConditionLevel) Equal

func (cl ConditionLevel) Equal(conditionLevel string) bool

type Graph

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

Graph Model は verifyGraph にて利用される。 getGraph のレスポンスボディのうち condition_timestamps を元にモデルを組み立て、 モデルを用いて getGraph のレスポンスボディの他フィールドが適切な値かどうかを検証する。

func NewGraph

func NewGraph(c []*IsuCondition) Graph

func (Graph) Match

func (g Graph) Match(
	score int,
	sittingPercentage int,
	isBrokenPercentage int,
	isDirtyPercentage int,
	isOverweightPercentage int,
) bool

type GraphDetail

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

type Isu

type Isu struct {
	Owner                          *User               `json:"-"`
	ID                             int                 `json:"id"`
	JIAIsuUUID                     string              `json:"jia_isu_uuid"`
	Name                           string              `json:"name"`
	ImageHash                      [md5.Size]byte      `json:"image_file_hash"` // 画像の検証用
	Character                      string              `json:"character"`
	CharacterID                    int                 `json:"-"`
	StreamsForScenario             *StreamsForScenario `json:"-"`          //poster Goroutineとの通信
	Conditions                     IsuConditionArray   `json:"conditions"` //シナリオ Goroutineからのみ参照
	CondMutex                      sync.RWMutex
	LastCompletedGraphTime         int64                         //シナリオ Goroutineからのみ参照
	PostTime                       time.Time                     //POST /isu/:id を叩いた仮想時間
	LastReadConditionTimestamps    [service.ConditionLimit]int64 //シナリオ Goroutineからのみ参照
	LastReadBadConditionTimestamps [service.ConditionLimit]int64 //シナリオ Goroutineからのみ参照
	CreatedAt                      time.Time                     `json:"created_at"`
}

一つのIsuにつき、一つの送信用 Goroutineがある IsuはISU協会 Goroutineからも読み込まれる

func (*Isu) AddIsuConditions

func (i *Isu) AddIsuConditions(conditions []IsuCondition)

func (*Isu) IsNoPoster

func (isu *Isu) IsNoPoster() bool

func (*Isu) SetImage

func (isu *Isu) SetImage(image []byte)

type IsuCharacterID

type IsuCharacterID int

func NewIsuCharacter

func NewIsuCharacter(character string) (IsuCharacterID, error)

type IsuCharacterSet

type IsuCharacterSet []IsuCharacterID

func (IsuCharacterSet) Append

func (cs IsuCharacterSet) Append(newCharacter IsuCharacterID) IsuCharacterSet

重複チェック & append

func (IsuCharacterSet) IsFull

func (cs IsuCharacterSet) IsFull() bool

IsuCharacterSet の要素が全ての性格を持つのかの判定

type IsuCondition

type IsuCondition struct {
	StateChange   IsuStateChange
	TimestampUnix int64 `json:"timestamp"`
	IsSitting     bool  `json:"is_sitting"`
	//Condition      string         `json:"condition"`
	IsDirty        bool           `json:"is_dirty"`
	IsOverweight   bool           `json:"is_overweight"`
	IsBroken       bool           `json:"is_broken"`
	ConditionLevel ConditionLevel `json:"condition_level"`
	Message        string         `json:"message"`

	ReadTime int64 `json:"-"` // GET /api/condition/:id や GET /api/isu/:id/graph で読まれた実際の時間(仮想時間ではない)
}

func (*IsuCondition) ConditionString

func (cond *IsuCondition) ConditionString() string

func (*IsuCondition) Less

func (left *IsuCondition) Less(right *IsuCondition) bool

left < right

func (*IsuCondition) Less2

func (left *IsuCondition) Less2(right *IsuConditionCursor) bool

left < right

type IsuConditionArray

type IsuConditionArray struct {
	Info     []IsuCondition
	Warning  []IsuCondition
	Critical []IsuCondition
}

conditionをcreated atの大きい順で見る

func NewIsuConditionArray

func NewIsuConditionArray() IsuConditionArray

func (*IsuConditionArray) Add

func (ia *IsuConditionArray) Add(cond *IsuCondition)

func (*IsuConditionArray) Back

func (ia *IsuConditionArray) Back() *IsuCondition

func (*IsuConditionArray) End

func (*IsuConditionArray) LowerBound

func (ia *IsuConditionArray) LowerBound(filter ConditionLevel, targetTimestamp int64) IsuConditionArrayIterator

IsuConditionArrayは、後ろの方が新しい LowerBound は IsuConditionArray から特定の時間「以上の」最も古い(手前の)コンディションを指すイテレータを返す

func (*IsuConditionArray) UpperBound

func (ia *IsuConditionArray) UpperBound(filter ConditionLevel, targetTimestamp int64) IsuConditionArrayIterator

IsuConditionArrayは、後ろの方が新しい UpperBound は IsuConditionArray から特定の時間「より新しい」最も古い(手前の)コンディションを指すイテレータを返す

type IsuConditionArrayIterator

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

conditionをcreated atの大きい順で見る

func (*IsuConditionArrayIterator) Prev

return: nil:もう要素がない

type IsuConditionCursor

type IsuConditionCursor struct {
	TimestampUnix int64
}

func (*IsuConditionCursor) Less

func (left *IsuConditionCursor) Less(right *IsuConditionCursor) bool

left < right

func (*IsuConditionCursor) Less2

func (left *IsuConditionCursor) Less2(right *IsuCondition) bool

left < right

type IsuConditionIterator

type IsuConditionIterator interface {
	Prev() *IsuCondition
}

conditionをcreated atの大きい順で見る

type IsuStateChange

type IsuStateChange int

enum

type StreamsForPoster

type StreamsForPoster struct {
	StateChan <-chan IsuStateChange
}

poster Goroutineとシナリオ Goroutineとの通信に必要な情報 ISU協会はこれを使ってposter Goroutineを起動、poster Goroutineはこれを使って通信 複数回poster Goroutineが起動するかもしれないのでcloseしない 当然リソースリークするがベンチマーカーは毎回落とすので問題ない

type StreamsForScenario

type StreamsForScenario struct {
	StateChan chan<- IsuStateChange
}

poster Goroutineとシナリオ Goroutineとの通信に必要な情報 複数回poster Goroutineが起動するかもしれないのでcloseしない 当然リソースリークするがベンチマーカーは毎回落とすので問題ない

type User

type User struct {
	UserID                  string `json:"jia_user_id"`
	Type                    UserType
	IsuListOrderByCreatedAt []*Isu          //CreatedAtは厳密にはわからないので、並列postの場合はpostした後にgetをした順番を正とする
	IsuListByID             map[string]*Isu `json:"isu_list_by_id"` //IDをkeyにアクセス
	PostIsuFinish           int32

	Agent *agent.Agent

	StaticCachedHash map[string]uint32
	// contains filtered or unexported fields
}

基本的には一つのシナリオ Goroutineが一つのユーザーを占有する =>Isuの追加操作と、参照操作が同時に必要になる場面は無いはずなので、

IsuListのソートは追加が終わってからソートすれば良い

func NewRandomUserRaw

func NewRandomUserRaw(userType UserType, isIsuconUser bool) (*User, error)

func (*User) AddIsu

func (u *User) AddIsu(isu *Isu)

CreatedAt順で挿入すること

func (*User) ClearStaticCache

func (u *User) ClearStaticCache()

func (*User) CloseAllIsuStateChan

func (user *User) CloseAllIsuStateChan()

func (*User) GetAgent

func (u *User) GetAgent() *agent.Agent

func (*User) GetStaticCache

func (u *User) GetStaticCache(path string, req *http.Request) (uint32, bool)

func (*User) SetStaticCache

func (u *User) SetStaticCache(path string, hash uint32)

type UserType

type UserType int

enum

const (
	UserTypeNormal UserType = iota
)

type Viewer

type Viewer struct {
	ErrorCount         uint
	ViewedUpdatedCount uint
	Agent              *agent.Agent

	StaticCachedHash map[string]uint32
	// contains filtered or unexported fields
}

基本的には一つのシナリオ Goroutine が一つの Viewer を占有する

func NewViewer

func NewViewer(agent *agent.Agent) Viewer

func (*Viewer) ClearStaticCache

func (v *Viewer) ClearStaticCache()

func (*Viewer) ConditionAlreadyVerified

func (v *Viewer) ConditionAlreadyVerified(id int, timestamp int64) bool

func (*Viewer) ConditionIsUpdated

func (v *Viewer) ConditionIsUpdated(id int, timestamp int64) bool

func (*Viewer) GetAgent

func (v *Viewer) GetAgent() *agent.Agent

func (*Viewer) GetStaticCache

func (v *Viewer) GetStaticCache(path string, _ *http.Request) (uint32, bool)

func (*Viewer) NumOfIsu

func (v *Viewer) NumOfIsu() int

func (*Viewer) SetStaticCache

func (v *Viewer) SetStaticCache(path string, hash uint32)

func (*Viewer) SetVerifiedCondition

func (v *Viewer) SetVerifiedCondition(id int, timestamp int64)

Jump to

Keyboard shortcuts

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