types

package
v0.0.0-...-8355f41 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAccountAlreadyExists = errors.New("Account already exists")
View Source
var ErrAccountDoesNotExist = errors.New("Account not found")
View Source
var ErrStudyAlreadyExist = errors.New("Study already exist")
View Source
var ErrStudyNotFound = errors.New("Study not found")
View Source
var ErrUserAlreadyExists = errors.New("User Already Exists")

Functions

This section is empty.

Types

type Account

type Account struct {
	UserID   string      `json:"userId"`
	Name     string      `json:"name" validate:"required"`
	AuthType AccountType `json:"authType" validate:"required"`
	// Interim structure to hold credential values until account type can be determined
	Account          json.RawMessage  `json:"connectedAccount"`
	ConnectedAccount ConnectedAccount `json:"-"`
}

func (*Account) SetConnectedAccount

func (a *Account) SetConnectedAccount() error

Takes the account and sets it to a connected account

type AccountRepository

type AccountRepository interface {
	Create(ctx context.Context, a Account) error
	Delete(ctx context.Context, a Account) error
	List(ctx context.Context, offset, limit int, userID, accType string) ([]Account, error)
}

type AccountType

type AccountType string
const (
	TypeformAccount AccountType = "typeform"
	FlyAccount      AccountType = "fly"
	AlchemerAccount AccountType = "alchemer"
	FacebookAccount AccountType = "facebook"
)

type AlchemerConnectedAccount

type AlchemerConnectedAccount struct {
	CreatedAt   int                       `json:"createdAt"`
	Credentials sourcetypes.AlchemerCreds `json:"credentials" validate:"required"`
}

Used to connect Virtual Lab to a Facebook ad account

func (AlchemerConnectedAccount) MarshalCredentials

func (a AlchemerConnectedAccount) MarshalCredentials() (string, error)

Used to input data into the database as a JSONB field

type AppDestination

type AppDestination struct {
	Type             string   `json:"type"`
	Name             string   `json:"name"`
	FacebookAppID    string   `json:"facebook_app_id"`
	AppInstallLink   string   `json:"app_install_link"`
	DeeplinkTemplate string   `json:"deeplink_template"`
	AppInstallState  string   `json:"app_install_state"`
	UserDevice       []string `json:"user_device"`
	UserOS           []string `json:"user_os"`
}

AppDestination

type AudienceConf

type AudienceConf struct {
	Name              string             `json:"name"`
	SubType           string             `json:"subtype"`
	Lookalike         *Lookalike         `json:"lookalike,omitempty"`
	QuestionTargeting *QuestionTargeting `json:"question_targeting,omitempty"`
	Partioning        *Partioning        `json:"partioning,omitempty"`
}

AudienceConf is how the audience is configured for the study

type ConnectedAccount

type ConnectedAccount interface {
	MarshalCredentials() (string, error)
}

Used as a concept to avoid complex logic on the frontend If null then the account is considered not yet connected

type CreativeConf

type CreativeConf struct {
	Body           string   `json:"body"`
	ButtonText     string   `json:"button_text"`
	Destination    string   `json:"destination"`
	ImageHash      string   `json:"image_hash"`
	LinkText       string   `json:"link_text"`
	Name           string   `json:"name"`
	WelcomeMessage string   `json:"welcome_message"`
	Tags           []string `json:"tags"`
}

CreativeConf these are essential fields that relate to an ad and link to a destination

type DatabaseStudyConf

type DatabaseStudyConf struct {
	Created  time.Time
	StudyID  string
	ConfType string
	Conf     json.RawMessage
}

DatabaseStudyConf is the structure used to store data in the database

type Destination

type Destination interface{}

Destination is where to send a recruitee to we use a blank interface as it could be different types

type DestinationConf

type DestinationConf []Destination

DestinationConf as we have multiple types of destination

func (*DestinationConf) UnmarshalJSON

func (d *DestinationConf) UnmarshalJSON(data []byte) error

UnmarshalJSON is a custom unmarshaller to handle the different types of destinations

type DistributionVar

type DistributionVar string
const (
	Location DistributionVar = "location"
	Gender   DistributionVar = "gender"
	Age      DistributionVar = "age"
)

type FacebookConnectedAccount

type FacebookConnectedAccount struct {
	CreatedAt   int                 `json:"createdAt"`
	Credentials FacebookCredentials `json:"credentials" validate:"required"`
}

Used to connect Virtual Lab to a Facebook ad account

func (FacebookConnectedAccount) MarshalCredentials

func (f FacebookConnectedAccount) MarshalCredentials() (string, error)

Used to input data into the database as a JSONB field

type FacebookCredentials

type FacebookCredentials struct {
	ExpiresIn   int    `json:"expires_in"`
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
}

type FacebookTargeting

type FacebookTargeting map[string]interface{}

FacebookTargeting

type FlyConnectedAccount

type FlyConnectedAccount struct {
	CreatedAt   int                        `json:"createdAt"`
	Credentials sourcetypes.FlyCredentials `json:"credentials" validate:"required"`
}

func (FlyConnectedAccount) MarshalCredentials

func (f FlyConnectedAccount) MarshalCredentials() (string, error)

Used to input data into the database as a JSONB field

type FlyDestination

type FlyDestination struct {
	Type             string `json:"type"`
	Name             string `json:"name"`
	InitialShortcode string `json:"initial_shortcode"`
}

FlyDestination is used to direct users to the Fly survey

type GeneralConf

type GeneralConf struct {
	Name             string  `json:"name"`
	Objective        string  `json:"objective"`
	OptimizationGoal string  `json:"optimization_goal"`
	DestinationType  string  `json:"destination_type"`
	PageID           string  `json:"page_id"`
	MinBudget        float32 `json:"min_budget"`
	OptInWindow      int     `json:"opt_window"`
	InstagramID      string  `json:"instagram_id"`
	AdAccount        string  `json:"ad_account"`
}

GeneralConf is used to hold all general configuration for a study

type Level

type Level struct {
	Name              string             `json:"name"`
	TemplateCampaign  string             `json:"template_campaign"`
	TemplateAdset     string             `json:"template_adset"`
	FacebookTargeting *FacebookTargeting `json:"facebook_targeting"`
	Quota             float64            `json:"quota"`
}

type Lookalike

type Lookalike struct {
	Target int           `json:"target"`
	Spec   LookalikeSpec `json:"spec"`
}

Lookalike is reflective of the lookalike capabilities in facebook ads

type LookalikeSpec

type LookalikeSpec struct {
	Country       string  `json:"country"`
	Ratio         float64 `json:"ratio"`
	StartingRatio float64 `json:"starting_ratio"`
}

LookalikeSpec is the specifications used in a lookalike

type Metadata

type Metadata map[string]string

Metadata used to keep instance information

type Org

type Org struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

type Partioning

type Partioning struct {
	MinUsers *int `json:"min_users"`
	MinDays  *int `json:"min_days,omitempty"`
	MaxDays  *int `json:"max_days,omitempty"`
	MaxUsers *int `json:"max_users,omitempty"`
}

Partioning

type QuestionTargeting

type QuestionTargeting map[string]interface{}

QuestionTargeting is set as an interface as it allows for a nested type structure with various types we use map[string]interface{} as we should be dealing with json

type RecruitmentConf

type RecruitmentConf struct {
	// Common Fields
	// These are set to strings as they are in the following format
	// 2022-08-05T00:00:00
	// Which is none standard in Golang and makes it cumbersome to
	// unmarshall to time.Time. We have no need for them to be
	// unmarshalled for now
	EndDate   string `json:"end_date"`
	StartDate string `json:"start_date"`

	// Simple Recruitment Fields
	AdCampaignName string `json:"ad_campaign_name,omitempty"`
	Budget         int    `json:"budget,omitempty"`
	MaxSample      int    `json:"max_sample,omitempty"`

	// Experiment Recruitment Fields
	Arms            int `json:"arms,omitempty"`
	RecruitmentDays int `json:"recruitment_days,omitempty"`
	OffsetDays      int `json:"offset_days,omitempty"`

	//Destination Recruitment Fields
	Destinations []string `json:"destinations,omitempty"`

	//Common Destination and Experiment Fields
	AdCampaignNameBase string `json:"ad_campaign_name_base,omitempty"`
	BudgetPerArm       int    `json:"budget_per_arm,omitempty"`
	MaxSamplePerArm    int    `json:"max_sample_per_arm,omitempty"`
}

Recruitment is the configuration used to work with the facebook campaign

type SegmentProgress

type SegmentProgress struct {
	ID                          string  `json:"id"`
	Name                        string  `json:"name"`
	Datetime                    int64   `json:"datetime"`
	CurrentBudget               float64 `json:"currentBudget"`
	DesiredPercentage           float64 `json:"desiredPercentage"`
	CurrentPercentage           float64 `json:"currentPercentage"`
	ExpectedPercentage          float64 `json:"expectedPercentage"`
	DesiredParticipants         *int64  `json:"desiredParticipants"`
	ExpectedParticipants        int64   `json:"expectedParticipants"`
	CurrentParticipants         int64   `json:"currentParticipants"`
	CurrentPricePerParticipant  float64 `json:"currentPricePerParticipant"`
	PercentageDeviationFromGoal float64 `json:"percentageDeviationFromGoal"`
}

type SegmentsProgress

type SegmentsProgress struct {
	Segments []SegmentProgress `json:"segments"`
	Datetime int64             `json:"datetime"`
}

type StratumConf

type StratumConf struct {
	ID                string             `json:"id"`
	Quota             float64            `json:"quota"`
	Audiences         []string           `json:"audiences"`
	ExcludedAudiences []string           `json:"excluded_audiences"`
	Creatives         []string           `json:"creatives"`
	FacebookTargeting *FacebookTargeting `json:"facebook_targeting"`
	QuestionTargeting *QuestionTargeting `json:"question_targeting,omitempty"`
	Metadata          *Metadata          `json:"metadata"`
}

StratumConf is groups that we divide our targeting groups into

type Study

type Study struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	Slug      string `json:"slug"`
	CreatedAt int64  `json:"createdAt"`
}

func NewStudy

func NewStudy(id, name, slug string, createdAt int64) Study

type StudyConf

type StudyConf struct {
	StudyID      string           `json:"-"`
	UserID       string           `json:"-"`
	General      *GeneralConf     `json:"general"`
	Recruitment  *RecruitmentConf `json:"recruitment"`
	Destinations *DestinationConf `json:"destinations"`
	Creatives    []*CreativeConf  `json:"creatives"`
	Audiences    []*AudienceConf  `json:"audiences"`
	Variables    []*VariableConf  `json:"variables"`
	Strata       []*StratumConf   `json:"strata"`
}

StudyConf is the root config that holds the various different types of study configuration that can be applied to a study that gets sent by the frontend

func (*StudyConf) TransformForDatabase

func (sc *StudyConf) TransformForDatabase() (res []DatabaseStudyConf, err error)

TransformForDatabase will take the StudyConfig that is passed from the frontend and transform it into a list that will be accepted by the database This is a Generic implementation as we have various types of configs that require the same transform to be done.

func (*StudyConf) TransformFromDatabase

func (sc *StudyConf) TransformFromDatabase(dcs []*DatabaseStudyConf) error

TransformFromDatabase gets a list of DatabaseStudyConf and iterates through it, adding the relevant configs to the StudyConf struct

type StudyConfRepository

type StudyConfRepository interface {
	Create(ctx context.Context, dsc DatabaseStudyConf) error
	GetByStudySlug(
		ctx context.Context,
		slug, userID string,
	) ([]*DatabaseStudyConf, error)
}

type StudyRepository

type StudyRepository interface {
	GetStudyBySlug(ctx context.Context, slug, userID, orgID string) (Study, error)
	GetStudies(
		ctx context.Context,
		offset int, limit int,
		userID, orgID string,
	) ([]Study, error)
	CreateStudy(ctx context.Context, name, userID, orgID string) (Study, error)
}

type StudySegmentsRepository

type StudySegmentsRepository interface {
	GetByStudySlug(
		ctx context.Context,
		slug, userID, orgID string,
	) ([]SegmentsProgress, error)
}

type TypeformConnectedAccount

type TypeformConnectedAccount struct {
	CreatedAt   int                             `json:"createdAt"`
	Credentials sourcetypes.TypeformCredentials `json:"credentials" validate:"required"`
}

func (TypeformConnectedAccount) MarshalCredentials

func (t TypeformConnectedAccount) MarshalCredentials() (string, error)

Used to input data into the database as a JSONB field

type User

type User struct {
	ID   string `json:"id"`
	Orgs []Org  `json:"orgs"`
}

type UserRepository

type UserRepository interface {
	Create(ctx context.Context, userID string) (User, error)
	GetUserOrgIDs(ctx context.Context, userID string) ([]Org, error)
}

type VariableConf

type VariableConf struct {
	Name       string   `json:"name"`
	Properties []string `json:"properties"`
	Levels     []*Level `json:"levels"`
}

Variables is used to create strata

type WebDestination

type WebDestination struct {
	Type        string `json:"type"`
	Name        string `json:"name"`
	URLTemplate string `json:"url_template"`
}

WebDestination is a destination that you can pass a url to in order to redirect users to a specific survey platform

Jump to

Keyboard shortcuts

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