Class: App

App(session, id)

An app: a list of stages, played numPeriods times by its players, in groups. A stage is an
app too (see Stage): one with a screen, one with stages of its own, or an app's file added
with addApp. A queue is an app whose stages are other apps.

Constructor

new App(session, id)

Creates an App.

Parameters:
Name Type Description
session Session

description

id String

description

Source:

Members

activeScreen

Shown on all client playing screens if Stage.useAppActiveScreen = true.

Default Value:
  • null
Source:

appPath

Where the original definition of this app is stored on the server.

Source:

description :String

Description of this App.

Type:
  • String
Default Value:
  • 'No description provided.'
Source:

exchangeRate :number|undefined

Money per point in this app (z-Tree's exchange rate per treatment); if not set, the
session's (see Session#exchangeRate, Participant#payment).

Type:
  • number | undefined
Source:

finished :boolean

TODO: Description

Type:
  • boolean
Default Value:
  • false
Source:

groupByArrival :boolean

Group participants in the order they arrive in each period, groupSize at a time,
instead of by groupMatchingType (oTree's group_by_arrival_time). A group starts its
first stage when it is full. Arrival matters when participants reach this app at
different times, e.g. after an app of instructions.

Type:
  • boolean
Default Value:
  • false
Source:

groupMatchingType :string

The matching type to be used for groups in this App.

Type:
  • string
Default Value:
  • 'STRANGER'
Source:

groupSize :number

If defined, subjects are assigned randomly to groups of this size takes precedence over numGroups.

Type:
  • number
Default Value:
  • undefined
Source:

groupingType

TODO:

Source:

hasError

Indicates whether or not the code for this app compiles to an error or not.

Source:

html :String

Shown on all client screens.

Type:
  • String
Source:

htmlFile

If 'htmlFile' is not null, content of 'htmlFile' is added to client content.
Otherwise, if 'htmlFile' is null, content of this.id + ".html" is added to client content, if it exists.

Source:

id :String

The unique identifier of this App. In order of precedence, the value is given by:

  • the explicit value in the .jtt file (if it has been set)
  • the name of the .jtt file (if it is not app.jtt or app.js)
  • the name of the folder containing the .jtt file
Type:
  • String
Source:

insertJtreeRefAtStartOfClientHTML :boolean

Inserts jtree functionality to the start of client.html

Type:
  • boolean
Default Value:
  • true
Source:

isStandaloneApp

Source:

jt :jt

Type:
  • jt
Source:

keyComparisons :Array

Array of comparisons to show by default on Session -> Data tab.
Each entry consists of:

  • field name (i.e. 'player.points')
  • x-axis object (i.e. 'player')
  • y-axis object (i.e. 'period')
    Field values are aggregated using the arithmetic mean as necessary (for example, if field is player.x, but x-axis is group, then table shows arithmetic mean of all player.x in a group).
Type:
  • Array
Default Value:
  • []
Source:

listed :boolean

Whether the admin lists this App among the apps. An app that is only a part of others (a
stage another app adds, a test) sets this to false; it can still be added by its path.

Type:
  • boolean
Default Value:
  • true
Source:

messages :Object

Messages to listen for from clients.

Type:
  • Object
Default Value:
  • {}
Source:

numGroups :number

if defined, subjects are split evenly into this number of groups
overridden by groupSize.

Type:
  • number
Default Value:
  • undefined
Source:

numPeriods :number

The number of periods in this App.

Type:
  • number
Default Value:
  • 1
Source:

optionValues :Object

The option values of this app.

Type:
  • Object
Default Value:
  • {}
Source:

options :Array

The options of this app.

Type:
  • Array
Default Value:
  • []
Source:

outputHide :array

Type:
  • array
Default Value:
  • []
Source:

periods :Array

The periods of this App.

Type:
  • Array
Default Value:
  • []
Source:

playerFieldsNotInOutput :Array.<string>

Players' fields that are sent to their pages and saved, but not written to the
session's data (e.g. a page's HTML).

Type:
  • Array.<string>
Source:

screen

TODO:

Source:

session :Session

The Session that this App belongs to.

Type:
Source:

stageContentEnd :string

Ends the stages of this App.
TODO:

Type:
  • string
Default Value:
  • ''
Source:

stageContentStart :string

Starts the stages of this App.
TODO:

Type:
  • string
Default Value:
  • ''
Source:

stageTimeoutGrace :number|null

Default for Stage#timeoutGrace.

Type:
  • number | null
Default Value:
  • 5
Source:

stageWrapPlayingScreenInFormTag :String

Set default value for Stage.wrapPlayingScreenInFormTag.
If 'yes', then form is added.
If 'no', no form is added.
If 'onlyIfNoButton', then form is added only if page has no buttons.

Type:
  • String
Default Value:
  • true
Source:

stages :Array

The stages of this app.

Type:
  • Array
Default Value:
  • []
Source:

suggestedNumPlayers

If not null and this is the first App in a Session, sets the initial number of players to this amount.

Source:

textMarkerBegin

Used by the participant client to find and create dynamic text elements.

Source:

waitForAll :boolean

Whether or not to wait for all participants before starting the app.

Type:
  • boolean
Default Value:
  • true
Source:

waitingScreen

Shown on all client waiting screens if Stage.useWaitingScreen = true.

Source:

Methods

addApp(file, optionsopt, idopt) → {Stage}

Adds the app in file as a stage of this app: each time a group reaches the stage, its
players play that app, loaded afresh, with its own periods, groups and page, and then go
on to this app's next stage. Its players are those of the stage's period who play the
stage (see Stage#canPlayerParticipate). What the app's file sets of a stage's settings
(waitToStart, waitToEnd, waitForAllGroups, canPlayerParticipate, groupStart, playerStart,
playerEnd, groupEnd, allGroupsStart) is the stage's, unless this app sets them after.
A queue (.jtq) is an app whose stages are the apps it adds.

Parameters:
Name Type Attributes Description
file string

The app's file, or folder, relative to this app's folder.

options Object <optional>

The app's option values, as for Session#addApp.

id string <optional>

The id of the stage; by default, the app's. (Or addApp(file, id).)

Source:
Returns:

The new stage.

Type
Stage

addClient(client)

Overwrite to add custom functionality for when a Client starts this app.

Called from:

Parameters:
Name Type Description
client Client

The client who is connecting to this app.

Source:

addClientDefault(client)

Called when a Client connected to a Participant starts this app.

  • client subscribes to this App's channel.
  • client registers custom messages it may send.
  • client registers automatic stage submission messages it may send.
  • load custom behaviour this.addClient.

Called from:

Parameters:
Name Type Description
client Client

The client who is connecting to this app.

Source:

addStage(name, fileopt) → {Stage}

Adds a stage, with contents loaded from a .jtt (or .js) file. In that file, stage is
the new stage and app is this app.

Parameters:
Name Type Attributes Description
name string

The id of the stage.

file string <optional>

The stage's file, relative to this app's folder; by default
.jtt (or .js).

Source:
Returns:

The new stage.

Type
Stage

addStages()

TODO

Source:

address() → {Array.<number>}

Where this app is in its session: [index in the session's apps (from 1)], and for an app
within a stage (see Stage#runFor), then the period's id and the stage's index, for each
stage it is within. See Session#appAt.

Source:
Returns:
Type
Array.<number>

appFiles()

The files of the apps added as stages of this app (see addApp), and of those within them.

Source:

appStart()

Overwrite in app.jtt: called once, when the first participant starts this app, before
its first period starts.

Source:

getGroupIdsForPeriod()

TODO
Get group ids for their current period

Source:

getNextStageForPlayer()

Get next stage for player in their current period. Return null if already at last stage of period.

DUE TO:
Stage.playerEnd

Source:

getOutputFN() → {string}

Source:
Returns:

Session path + App#indexInSession + '_' + app.id

Type
string

getParticipantDuration()

Returns the amount of time this participant has to play this app.

Source:

groupMoveToNextStage(group)

  • clear group's timer.
  • if next stage exists, let the group play it.
  • for each player in the group, call App#playerMoveToNextStage.
Parameters:
Name Type Description
group Group
Source:

hostApp() → {App}

The app whose page and fields this app's players have: for an app within a stage given
stages of its own (see App#newBlock), the app it is in; otherwise this app.

Source:
Returns:
Type
App

indexInSession() → {number}

Source:
Returns:

The index of this app in its session's list of apps (first position = 1).
For an app within a stage (see Stage#newStage, App#addApp), that of the app it is in.

Type
number

initPeriod(prd)

Creates a new period with the given id + 1, saves it and adds it to this App's periods.

Called from:

  • App.participantBeginPeriod
Parameters:
Name Type Description
prd number

The index to assign to the new period.

Source:

internalEnd()

Ends this App.

  • Create headers for this app, periods, groups, group tables, players and participants.
  • Create output.
  • Write output to this session's csv file.

CALLED FROM

Source:

isFolderApp()

Whether this app is a folder: an app.jtt (or app.js), with its stages' files beside it;
or an oTree app's init.py (or models.py), with its templates.

Source:

loadAppFile()

A new App for the app in appFile (see addApp), in this app's session, with options set
before its code runs. For a queue, an app whose stages are the queue's apps.

Source:

loadStageFiles()

Adds the stages of a folder app that its app.jtt does not add itself: the folder's
other .jtt files, in name order. A leading number orders them and is not part of the
stage's id: "1_decide.jtt" is stage "decide". Called after the app's code has run.

Source:

metaData() → {type}

metaData - description

Source:
Returns:

description

Type
type

newBlock(stage) → {App}

The app that stage, a stage of this app given stages of its own (see Stage#newStage),
runs them as. It is this app with stage's stages, and periods and groups of stage's
(see Stage#runFor, which makes one for each period that reaches stage), so their code
and pages are this app's.

Parameters:
Name Type Description
stage Stage
Source:
Returns:
Type
App

newStage(id) → {Stage}

Creates a new Stage and adds it to the App.

Parameters:
Name Type Description
id string

The identifier of the stage.

Source:
Returns:

The new stage.

Type
Stage

nextStageForGroup(group) → {null|Stage}

Returns the next stage for a given group in a given stage.

  1. If stage is not the last stage of this app, return the next stage of this app.
  2. If period is not the last period of this app, return the first stage of this app.
  3. If app is not the last app of this session, return the first stage of the next app.
  4. Otherwise, return null.

TODO: Does the next stage have Stage.waitForGroup == true?

CALLED FROM

Parameters:
Name Type Description
group Group

The group

Source:
Returns:

The next stage for this group, or null.

Type
null | Stage

onPlayerFinished(player)

Called when a player finishes a stage.
By default, check whether everyone in group is finished.
If yes, then advance to next stage (this.session.gotoNextStage(player.group)).

Parameters:
Name Type Description
player Player

description

Source:

outputFields() → {Array}

The names of fields to include in an export of this object. To be included, a field must:

  • not be a function (Utils.isFunction)
  • not be included in App#outputHide
  • not be included in App#outputHideAuto
Source:
Returns:

An array of the field names.

Type
Array

outputWithRuns()

This app's data (see saveOutput), then that of the apps within its stages (see runs).

Source:

pageStages() → {Array.<Stage>}

The stages of this app's page: its stages, each followed by the stages within it, if it
has stages of its own (see Stage#newStage). An app added as a stage has a page of its own.

Source:
Returns:
Type
Array.<Stage>

participantBegin(participant)

Called when a participant begins this app.

  • For each of the Clients of this participant, call App.addClientDefault.
  • Set the participant's periodIndex to -1.
  • Participant notifies clients about appIndex.
  • Move participant to next period App.participantMoveToNextPeriod.
  • Participant notified clients about starting new app.
Parameters:
Name Type Description
participant Participant

The participant.

Source:

participantBeginPeriod(participant)

A participant begins its current period.

  • Participant notifies its clients of periodIndex.
  • If current period undefined, initialize it (App.initPeriod).
  • Participant begins period (Period.participantBegin).

Called from:

  • App.participantMoveToNextPeriod.
Parameters:
Name Type Description
participant type

The participant.

Source:

participantEndInternal(participant)

A participant finishes playing this app.

FUNCTIONALITY

  • Participant's clients unsubscribe from messages from this app.
  • Try to end the app (App#tryToEndApp).

CALLED FROM

  • xxx
Parameters:
Name Type Description
participant Participant

The participant.

Source:

participantMoveToNextPeriod(participant) → {type}

A participant moves to its next period.

FUNCTIONALITY

  • If participant is currently in a period, end it (Period.participantEnd).
  • Increment participant's period index.
  • Save participant (Participant.save).
  • If participant is has finished all periods in this app, move to next app (Session.participantMoveToNextApp).
  • Otherwise, begin new period (App.participantBeginPeriod).

CALLED FROM

Parameters:
Name Type Description
participant type

description

Source:
Returns:

description

Type
type

participantStart(participant) → {type}

Overwrite in app.jtt.

Parameters:
Name Type Description
participant type

description

Source:
Returns:

description

Type
type

periodEnd(period)

Overwrite in app.jtt: called once per period, when its last group has ended the
period's last stage.

Parameters:
Name Type Description
period Period
Source:

periodParticipants(period) → {Object.<string, Participant>}

The participants this app groups in period, by id: the session's; for an app within a
stage (see Stage#runFor), those of the stage's period who play it.

Parameters:
Name Type Description
period Period
Source:
Returns:
Type
Object.<string, Participant>

periodStart(period)

Overwrite in app.jtt: called once per period, when its groups and players have been
made, before any group starts the period's first stage. Groups of an app without a
barrier across groups may start the next period before the last group ends this one.

Parameters:
Name Type Description
period Period
Source:

playingGroupIds() → {Array.<Array.<string>>}

For an app within a stage (see Stage#runFor): the participant ids of the groups of the
period it is in, without those who do not play the stage (see
Stage#canPlayerParticipate), and without groups left empty.

Source:
Returns:
Type
Array.<Array.<string>>

pokeGroups()

For an app within a stage that participants have left before its end (see
Participant#leaveRun): its groups that were waiting for them go on.

Source:

previousGroup(group) → {Player}

Returns the group of the current player's participant from the previous period.

Parameters:
Name Type Description
group Group

The group.

Source:
Returns:

TODO: The previous player, if any.

Type
Player

previousPlayer(player) → {Player}

Returns the player of the current player's participant from the previous period.

Parameters:
Name Type Description
player Player

The player.

Source:
Returns:

The previous player, if any.

Type
Player

roomId() → {string}

roomId - description

Source:
Returns:

Session#roomId + 'app' + this.id

Type
string

rootApp()

The app of the session this app is in, through the stages it is within; or this app.

Source:

runHook()

Calls this app's hook name with args, logging an error in it instead of throwing it,
as for stages' hooks.

Source:

runs() → {Array.<App>}

The apps runs of this app's stages are (see Stage#runFor), and theirs, in the order of
this app's periods and stages.

Source:
Returns:
Type
Array.<App>

save()

Save this App to the session .gsf file.

CALLED FROM:

Source:

saveSelfAndChildren() → {type}

saveSelfAndChildren - description

CALLED FROM:

Source:
Returns:

description

Type
type

setNumParticipants()

For a queue's script run against this app (see loadAppFile): the number of participants
it suggests.

Source:

shell() → {Object}

A shell of this object. Excludes parent and children. The shell is a simplified version of an object and any of its fields.

CALLED FROM

Source:
Returns:

description

Type
Object

shellWithChildren() → {type}

A shell of this object. Excludes parent, includes child shells.

CALLED FROM:

Source:
Returns:

description

Type
type

shellWithParent() → {type}

A shell of this object. Includes parent shell, excludes child shells.

Source:
Returns:

description

Type
type

submitStage() → {Object|null}

player submits the form of the stage they are playing: values by field name ('player.x',
'group.x', 'participant.x', 'period.x' or 'app.x', or just 'x' for one of the stage's
formFields), as the page sends them. They are
checked and converted (see forms.js) and stored, and the stage ends for the player.
Once a player's time is up, what they submit is taken as it is: the values that pass, and
nothing for the others (as oTree does on a timeout).

Source:
Returns:

If the form is refused, the messages by field name; else null.

Type
Object | null

toIR()

This app as an app description (see ir/ir.js).

Source:

tryToEndApp() → {type}

If all participants have finished the app, end the app (App#end).

CALLED FROM

Source:
Returns:

description

Type
type

(static) load(json, session) → {App}

Parameters:
Name Type Description
json Object

A json object containing the properties of the app.

session Session

The session this app belongs to.

Source:
Returns:

A new app initialized with the data in json.

Type
App

(static) newSansId(jt, appPath) → {App}

Parameters:
Name Type Description
jt type

description

appPath type

The path relative to the server process. i.e. /apps/my-app.jtt or /apps/my-complex-app/app.js

Source:
Returns:

The given app.

Type
App