Constructor
new App(session, id)
Creates an App.
Parameters:
| Name | Type | Description |
|---|---|---|
session |
Session | description |
id |
String | description |
Members
activeScreen
Shown on all client playing screens if Stage.useAppActiveScreen = true.
appPath
Where the original definition of this app is stored on the server.
description :String
Description of this App.
Type:
- String
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
finished :boolean
TODO: Description
Type:
- boolean
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
groupMatchingType :string
The matching type to be used for groups in this App.
Type:
- string
groupSize :number
If defined, subjects are assigned randomly to groups of this size takes precedence over numGroups.
Type:
- number
groupingType
TODO:
hasError
Indicates whether or not the code for this app compiles to an error or not.
html :String
Shown on all client screens.
Type:
- String
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.
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
insertJtreeRefAtStartOfClientHTML :boolean
Inserts jtree functionality to the start of client.html
Type:
- boolean
isStandaloneApp
jt :jt
Type:
- jt
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
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
messages :Object
Messages to listen for from clients.
Type:
- Object
numGroups :number
if defined, subjects are split evenly into this number of groups
overridden by groupSize.
Type:
- number
numPeriods :number
The number of periods in this App.
Type:
- number
optionValues :Object
The option values of this app.
Type:
- Object
options :Array
The options of this app.
Type:
- Array
outputHide :array
Type:
- array
periods :Array
The periods of this App.
Type:
- Array
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>
screen
TODO:
session :Session
The Session that this App belongs to.
Type:
stageContentEnd :string
Ends the stages of this App.
TODO:
Type:
- string
stageContentStart :string
Starts the stages of this App.
TODO:
Type:
- string
stageTimeoutGrace :number|null
Default for Stage#timeoutGrace.
Type:
- number | null
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
stages :Array
The stages of this app.
Type:
- Array
suggestedNumPlayers
If not null and this is the first App in a Session, sets the initial number of players to this amount.
textMarkerBegin
Used by the participant client to find and create dynamic text elements.
waitForAll :boolean
Whether or not to wait for all participants before starting the app.
Type:
- boolean
waitingScreen
Shown on all client waiting screens if Stage.useWaitingScreen = true.
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).) |
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. |
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. |
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 |
Returns:
The new stage.
- Type
- Stage
addStages()
TODO
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.
Returns:
- Type
- Array.<number>
appFiles()
The files of the apps added as stages of this app (see addApp), and of those within them.
appStart()
Overwrite in app.jtt: called once, when the first participant starts this app, before
its first period starts.
getGroupIdsForPeriod()
TODO
Get group ids for their current period
getNextStageForPlayer()
Get next stage for player in their current period. Return null if already at last stage of period.
DUE TO:
Stage.playerEnd
getOutputFN() → {string}
Returns:
Session path + App#indexInSession + '_' + app.id
- Type
- string
getParticipantDuration()
Returns the amount of time this participant has to play this app.
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 |
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.
Returns:
- Type
- App
indexInSession() → {number}
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. |
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
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.
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.
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.
metaData() → {type}
metaData - description
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 |
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. |
Returns:
The new stage.
- Type
- Stage
nextStageForGroup(group) → {null|Stage}
Returns the next stage for a given group in a given stage.
- If stage is not the last stage of this app, return the next stage of this app.
- If period is not the last period of this app, return the first stage of this app.
- If app is not the last app of this session, return the first stage of the next app.
- Otherwise, return null.
TODO: Does the next stage have Stage.waitForGroup == true?
CALLED FROM
Parameters:
| Name | Type | Description |
|---|---|---|
group |
Group | The group |
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 |
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
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).
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.
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. |
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. |
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. |
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
- App#playerMoveToNextStage
- App#participantBegin
Parameters:
| Name | Type | Description |
|---|---|---|
participant |
type | description |
Returns:
description
- Type
- type
participantStart(participant) → {type}
Overwrite in app.jtt.
Parameters:
| Name | Type | Description |
|---|---|---|
participant |
type | description |
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 |
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 |
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 |
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.
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.
previousGroup(group) → {Player}
Returns the group of the current player's participant from the previous period.
Parameters:
| Name | Type | Description |
|---|---|---|
group |
Group | The group. |
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. |
Returns:
The previous player, if any.
- Type
- Player
roomId() → {string}
roomId - description
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.
runHook()
Calls this app's hook name with args, logging an error in it instead of throwing it,
as for stages' hooks.
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.
Returns:
- Type
- Array.<App>
save()
saveSelfAndChildren() → {type}
Returns:
description
- Type
- type
setNumParticipants()
For a queue's script run against this app (see loadAppFile): the number of participants
it suggests.
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
Returns:
description
- Type
- Object
shellWithChildren() → {type}
Returns:
description
- Type
- type
shellWithParent() → {type}
A shell of this object. Includes parent shell, excludes child shells.
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).
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).
tryToEndApp() → {type}
If all participants have finished the app, end the app (App#end).
CALLED FROM
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. |
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 |
Returns:
The given app.
- Type
- App