subt

package
Version: v0.0.0-...-4436486 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2020 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const SubTPortalName = "subt"

SubTPortalName is the name of the Org that represents the competition.

Variables

This section is empty.

Functions

func Initialize

func Initialize(ctx context.Context, db *gorm.DB)

Initialize initializes the SubT bundle

func QueryForRegistrations

func QueryForRegistrations(q *gorm.DB) *gorm.DB

QueryForRegistrations returns a gorm query configured to query Registrations.

Types

type BucketServer

type BucketServer interface {
	GetBucketName(bucket string) string
	Upload(ctx context.Context, f io.Reader, bucket, fPath string) (*string, error)
	RemoveFile(ctx context.Context, bucket, fPath string) error
	GetPresignedURL(ctx context.Context, bucket, fPath string) (*string, error)
}

BucketServer is an interface to be followed by Bucket server implementations. Eg. S3

var BucketServerImpl BucketServer

BucketServerImpl holds the bucket server to be used.

type CompetitionParticipant

type CompetitionParticipant struct {
	// Override default GORM Model fields
	ID uint `gorm:"primary_key" json:"-"`
	// The participant name
	// Required. Manage the relationship with Organization.
	// Impl note: It is named Owner to support generic DB query modifiers that
	// expect the field Owner to represent organizations or users.
	Owner *string `gorm:"not null;unique_index:idx_active_owner" json:"owner"`
	// Competition name. Note: A competition is an Organization.
	Competition *string `json:"competition"`
	// GORM fields
	CreatedAt time.Time `gorm:"type:timestamp(3) NULL" json:"created_at"`
	// Added 2 milliseconds to DeletedAt field
	DeletedAt *time.Time `gorm:"type:timestamp(2) NULL; unique_index:idx_active_owner" sql:"index" json:"-"`
	// Private - True to make this a private resource
	// Impl note: we added the Private field to support generic query modifiers that
	// expect the private field.
	Private *bool `json:"private,omitempty"`
}

CompetitionParticipant contains the SubT participants extra fields

type CompetitionParticipants

type CompetitionParticipants []CompetitionParticipant

CompetitionParticipants is an slice of CompetitionParticipant

type CompetitionScore

type CompetitionScore struct {
	gorm.Model
	// Simulation unique identifier. For multisims, this should be the parent's group id.
	GroupId     *string `gorm:"not null" json:"group_id"`
	Competition *string `gorm:"not null" json:"competition"`
	Circuit     *string `gorm:"not null" json:"circuit"`
	Owner       *string `gorm:"not null" json:"owner"`
	// Simulation score
	Score *float64 `gorm:"not null" json:"score"`
	// Source includes the GroupIds of all simulations that produced this score entry
	Sources *string `gorm:"size:10000" json:"sources"`
}

CompetitionScore contains scores for competition circuits.

type CompetitionScores

type CompetitionScores []CompetitionScore

CompetitionScores is a list of CompetitionScore

type LeaderboardParticipant

type LeaderboardParticipant struct {
	CompetitionParticipant
	Score   *float32 `json:"score,omitempty"`
	Circuit *string  `json:"circuit"`
}

LeaderboardParticipant is a struct that contains participant data and their score

type LogFile

type LogFile struct {
	// Override default GORM Model fields
	ID        uint      `gorm:"primary_key" json:"id"`
	CreatedAt time.Time `gorm:"type:timestamp(3) NULL" json:"created_at"`
	UpdatedAt time.Time `json:"updated_at,omitempty"`
	// Added 2 milliseconds to DeletedAt field, and added it to the unique index to help disambiguate
	// when soft deleted rows are involved.
	DeletedAt *time.Time `gorm:"type:timestamp(2) NULL" sql:"index" json:"-"`
	// Unique identifier
	UUID *string `json:"-"`
	// Location in bucket
	Location *string `json:"location,omitempty"`
	// The owner of this resource (must exist in UniqueOwners). Can be user or org.
	Owner *string `json:"owner,omitempty"`
	// The username of the User that created this resource (usually got from the JWT)
	Creator *string `json:"creator,omitempty"`
	// Private - True to make this a private resource
	Private *bool `json:"private,omitempty"`

	// Competition name. A competition is an Organization
	Competition *string `json:"competition,omitempty"`
	// Submission status. A value from St* contants
	Status *int     `validate:"omitempty,gte=0,lte=2" json:"status"`
	Score  *float32 `json:"score,omitempty"`
	// Resolution Date
	ResolvedAt *time.Time `gorm:"type:timestamp(3) NULL" json:"resolved_at,omitempty"`
	// Optional comments
	// Interesting post about TEXT vs VARCHAR(30000) performance:
	// https://nicj.net/mysql-text-vs-varchar-performance/
	Comments *string `gorm:"type:text" json:"comments,omitempty"`
}

LogFile represents a Log file submitted in a competition.

type LogFiles

type LogFiles []LogFile

LogFiles is a list of LogFile

type LogService

type LogService struct{}

LogService is the main struct exported by this service.

func (*LogService) CreateLog

func (s *LogService) CreateLog(ctx context.Context, tx *gorm.DB, f io.Reader,
	filename, comp string, ls *LogSubmission, user *users.User) (*LogFile, *ign.ErrMsg)

CreateLog submits a new (pending) log file. user argument is the active user requesting the operation.

func (*LogService) GetLogFile

func (s *LogService) GetLogFile(ctx context.Context, tx *gorm.DB,
	comp string, id uint, user *users.User) (*LogFile, *ign.ErrMsg)

GetLogFile returns a single log file record. user argument is the active user requesting the operation.

func (*LogService) GetLogFileForDownload

func (s *LogService) GetLogFileForDownload(ctx context.Context, tx *gorm.DB,
	comp string, id uint, user *users.User) (*string, *ign.ErrMsg)

GetLogFileForDownload returns an URL (for downloading) a log file. user argument is the active user requesting the operation.

func (*LogService) LogFileList

func (s *LogService) LogFileList(pr *ign.PaginationRequest, tx *gorm.DB, comp string,
	owner *string, status SubmissionStatus, reqUser *users.User) (*LogFiles, *ign.PaginationResult, *ign.ErrMsg)

LogFileList returns a list of paginated log files. Members of the submitting team can see the list of log files they submitted. Members of the organizing group (eg. SubT) can see all log files.

func (*LogService) RemoveLogFile

func (s *LogService) RemoveLogFile(ctx context.Context, tx *gorm.DB, comp string,
	id uint, user *users.User) (*LogFile, *ign.ErrMsg)

RemoveLogFile removes a log file. user argument is the active user requesting the operation. Returns the removed log file

func (*LogService) UpdateLogFile

func (s *LogService) UpdateLogFile(ctx context.Context, tx *gorm.DB, comp string,
	id uint, su *SubmissionUpdate, user *users.User) (*LogFile, *ign.ErrMsg)

UpdateLogFile updates a log file. Eg. sets score and status. user argument is the active user requesting the operation.

type LogSubmission

type LogSubmission struct {
	// Optional Owner. Must be a user or an org.
	// If not set, the current user will be used as owner
	Owner string `validate:"required" form:"owner"`
	// Optional description
	Description string `form:"description"`
	// One or more files
	// required: true
	File string `json:"file" validate:"omitempty,gt=0" form:"-"`
	// Optional privacy/visibility setting.
	Private *bool `validate:"omitempty" form:"private"`
}

LogSubmission encapsulates data required to submit a log file from a client

type Portal

type Portal struct {
	// Override default GORM Model fields
	ID        uint      `gorm:"primary_key" json:"-"`
	CreatedAt time.Time `gorm:"type:timestamp(3) NULL" json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	// Adds deletedAt to the unique index to help disambiguate when soft deleted rows are involved.
	DeletedAt *time.Time `gorm:"type:timestamp(2) NULL; unique_index:idx_name_owner" sql:"index" json:"-"`
	// Unique identifier
	UUID *string `json:"-"`
	// Location on disk
	Location *string `json:"-"`
	// The name of the resource
	// Added to the name_owner unique index.
	Name *string `gorm:"unique_index:idx_name_owner" json:"name,omitempty"`
	// The owner of this resource (must exist in UniqueOwners). Can be user or org.
	// Also added to the name_owner unique index
	Owner *string `gorm:"unique_index:idx_name_owner" json:"owner,omitempty"`
	// The username of the User that created this resource (usually got from the JWT)
	Creator *string `json:"creator,omitempty"`
	// Private - True to make this a private resource
	Private *bool `json:"private,omitempty"`
	// A description of the model (max 65,535 chars)
	// Interesting post about TEXT vs VARCHAR(30000) performance:
	// https://nicj.net/mysql-text-vs-varchar-performance/
	Description *string `gorm:"type:text" json:"description,omitempty"`
}

Portal contains the data for portals TODO: extract this into a "super" Resource struct.

type RegStatus

type RegStatus uint

RegStatus are possible status values of registrations

const (
	RegOpPending RegStatus = iota
	RegOpDone
	RegOpRejected
)

Registration operation related constants

type Registration

type Registration struct {

	// ID is public as we want to use it in requests from clients
	ID        uint      `gorm:"primary_key" json:"-"`
	CreatedAt time.Time `gorm:"type:timestamp(3) NULL" json:"created_at"`
	// Added 2 milliseconds to DeletedAt field
	DeletedAt *time.Time `gorm:"type:timestamp(2) NULL" sql:"index" json:"-"`
	// Competition name. Note: A competition is an Organization.
	Competition *string `json:"competition"`
	// Resolution Date
	ResolvedAt *time.Time `gorm:"type:timestamp(3) NULL" json:"resolved_at,omitempty"`
	// The status of the registration. Expects one of the RegOp* constants.
	Status *int `json:"status"`
	// Related Fuel Organization (by name). It is the "team".
	Participant *string `json:"participant"`
	// The username of the User that requested this
	Creator *string `json:"creator"`
}

Registration models the table that tracks a team registration for SubT.

type RegistrationCreate

type RegistrationCreate struct {
	Participant string `validate:"required,alphanumspace"`
}

RegistrationCreate encapsulates data required to create a new pending registration.

type RegistrationUpdate

type RegistrationUpdate struct {
	Competition string    `json:"-"`
	Participant string    `json:"-"`
	Resolution  RegStatus `validate:"required,gte=1,lte=2"`
}

RegistrationUpdate encapsulates data required to resolve a pending registration

type Registrations

type Registrations []Registration

Registrations is a list of registrations

type S3Bucket

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

S3Bucket is responsible of interacting with AWS S3. The following environment variables must be set: AWS_REGION AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY

func NewS3Bucket

func NewS3Bucket(pre string) *S3Bucket

NewS3Bucket initializes a new S3Bucket. arg pre is the prefix to use in Bucket names.

func (*S3Bucket) GetBucketName

func (s3b *S3Bucket) GetBucketName(bucket string) string

GetBucketName is an s3 implementation to get a bucket name in the cloud

func (*S3Bucket) GetPresignedURL

func (s3b *S3Bucket) GetPresignedURL(ctx context.Context, bucket,
	fPath string) (*string, error)

GetPresignedURL returns presigned urls from S3 buckets.

func (*S3Bucket) RemoveFile

func (s3b *S3Bucket) RemoveFile(ctx context.Context, bucket, fPath string) error

RemoveFile is an implementation to remove files from a bucket in S3

func (*S3Bucket) Upload

func (s3b *S3Bucket) Upload(ctx context.Context, f io.Reader, bucket,
	fPath string) (*string, error)

Upload is an s3 implementation to upload files to a bucket

type Service

type Service struct{}

Service is the main struct exported by this service.

func (*Service) ApplyToSubT

func (s *Service) ApplyToSubT(ctx context.Context, tx *gorm.DB,
	orgName string, user *users.User) (*Registration, *ign.ErrMsg)

ApplyToSubT registers a new (pending) registration to join SubT. user argument is the active user requesting the operation. The orgName argument is the organization that will be registered as a 'participant team'.

func (*Service) CreateRegistration

func (s *Service) CreateRegistration(ctx context.Context, tx *gorm.DB,
	comp, orgName string, user *users.User) (*Registration, *ign.ErrMsg)

CreateRegistration registers a new (pending) registration to join a competition. user argument is the active user requesting the operation. The orgName argument is the organization that will be registered as a 'team'. TODO: this should be moved to generic a Registrations bundle.

func (*Service) DeleteParticipant

func (s *Service) DeleteParticipant(ctx context.Context, tx *gorm.DB,
	comp, orgName string, requestor *users.User) (*CompetitionParticipant, *ign.ErrMsg)

DeleteParticipant removes a registered participant. The requestor argument is the active user requesting the operation. Returns the deleted participant

func (*Service) DeleteRegistration

func (s *Service) DeleteRegistration(ctx context.Context, tx *gorm.DB,
	comp, orgName string, requestor *users.User) (*Registration, *ign.ErrMsg)

DeleteRegistration cancels a pending registration. The requestor argument is the active user requesting the operation. Returns the canceled registration

func (*Service) Leaderboard

func (s *Service) Leaderboard(pr *ign.PaginationRequest, tx *gorm.DB, comp string, circuit *string,
	owner *string) (interface{}, *ign.PaginationResult, *ign.ErrMsg)

Leaderboard returns a paginated list with all competition participants sorted by their score.

func (*Service) ParticipantsList

func (s *Service) ParticipantsList(pr *ign.PaginationRequest, tx *gorm.DB, comp string,
	reqUser *users.User) (*users.OrganizationResponses, *ign.PaginationResult, *ign.ErrMsg)

ParticipantsList returns a list of paginated participants (organizations).

func (*Service) RegistrationList

func (s *Service) RegistrationList(pr *ign.PaginationRequest, tx *gorm.DB, comp string,
	status RegStatus, reqUser *users.User) (*Registrations, *ign.PaginationResult, *ign.ErrMsg)

RegistrationList returns a list of paginated registrations. Only the admins of the competition and the user that applied the registration should be able to see registrations.

func (*Service) ResolveRegistration

func (s *Service) ResolveRegistration(ctx context.Context, tx *gorm.DB,
	ru *RegistrationUpdate, requestor *users.User) (*Registration, *ign.ErrMsg)

ResolveRegistration updates a registration. Usually to set a resolution (approve / reject). The requestor argument is the active user requesting the operation (an admin).

type SubmissionStatus

type SubmissionStatus uint

SubmissionStatus are possible status values of LogFile submissions.

const (
	StForReview SubmissionStatus = iota
	StDone
	StRejected
)

Submission status related constants

type SubmissionUpdate

type SubmissionUpdate struct {
	// Submission status. A value from St* contants
	Status SubmissionStatus `validate:"gte=0,lte=2"`
	Score  float32
	// Optional comments
	// Interesting post about TEXT vs VARCHAR(30000) performance:
	// https://nicj.net/mysql-text-vs-varchar-performance/
	Comments *string `json:"comments,omitempty"`
}

SubmissionUpdate encapsulates data required to score an existing a log file.

Jump to

Keyboard shortcuts

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