ITR data model

From ITR Wiki

Everything the ITR knows about a test, a report, a session or a candidate lives in a small set of JavaScript objects: the data model. Test authors never see these objects, but every editor fills them, test taking runs on them, and scoring, norming and reports read them. If you understand the data model, you understand most of the ITR.

This page is for developers, architects and AI tools that work on the ITR. It describes the main objects, what each property does, and how objects are saved and loaded. For the bigger picture, see ITR application architecture. As always, the code is leading: when this page and the code differ, the code is right.

Where the data model lives

The data model is in the folder ITSScript/DataModel of the web client (repository ITR-webclient). The same files are also used by the public API: its ScoreTest call runs the scoring code in Node.js (score_test.js), so a test is scored the same way everywhere.

File Main objects What they hold
ITSTest.js ITSTest, ITSTestScreen, ITSTestScreenComponent, ITSTestScreenDynamics, ITSTestScale, ITSScaleScore, ITSTestNorm, ITSTestNormColumns, ITSTestNormColumn, ITSTestDocument Test definitions, with all the code for scoring and norming
ITSScreenTemplates.js ITSScreenTemplate, ITSScreenTemplateVariable Screen templates and the HTML generation for test taking, editing, PnP and summaries
ITSReport.js, ITSGraph.js ITSReport, ITSGraph Report definitions and their graphs
ITSBattery.js ITSBattery, ITSBatteryTest, ITSBatteryReport Batteries: fixed sets of tests and reports
ITSCandidateSession.js ITSCandidateSession, ITSCandidateSessionTest, ITSCandidateSessionGeneratedReport Sessions, the tests in a session with the answers and scores, and saved reports
ITSCandidate.js ITSCandidate Candidates (persons)
ITSCompanies.js, ITSUsers.js, ITSCreditUsages.js ITSCompany, ITSUser, ITSCreditGrant Organisations, logins and credits

Most files also have a list object, such as ITSTests or ITSReports, that loads and caches the list from the server.

The object tree

There are two kinds of relations:

  • Contains: an object holds its children in an array or a sub object, and they are saved together. A test contains its screens, a screen its components, and so on. One test definition is saved as one whole.
  • Refers to: an object stores the ID of another object. A component stores the templateID of its screen template, a test in a session stores the TestID of its test and the IDs of up to three norms, and a saved report stores its ReportID.

All IDs are GUIDs, made in the browser with newGuid(). An empty reference is 00000000-0000-0000-0000-000000000000.

Every object also has runtime links that are never saved: myParent (or parent) points to the object it belongs to, and ITSSession points to the running ITR instance (ITSInstance).

Saving and loading

persistentProperties

Every object that is saved has a list persistentProperties in its constructor. Only the properties in this list are saved; everything else is runtime only. In the tables below, Saved means that the property is in this list.

A few objects use "*ALL*" instead of a list. For those every property is saved. This is used for free form objects: PluginData, Results, Scores, the norm parameters and ITSGraph.

ITSJSONStringify

ITSJSONStringify(object) in ITSHelpers.js turns an object into JSON text:

  • It writes _objectType first: the name of the constructor, for example "ITSTestScreen".
  • It writes only the properties from persistentProperties, in that order.
  • For an array it calls itself for every item, so every item gets its own _objectType.
  • Dates are written in the ITR date format (ITSDateTimeToProgressDateTime).
  • A PluginData object is always written completely ("*ALL*").
  • An object with "*ALL*" is written with the normal JSON.stringify.

The same text is used for saving to the server, for the download files (.itrtesttemplate, .itrreporttemplate and .itrscreentemplate, see ITR file formats) and for detecting changes: editors keep lastSavedJSON and compare it with a fresh ITSJSONStringify to see whether there are unsaved changes.

ITSJSONLoad

ITSJSONLoad(object, jsonText, parent, ITSInstance, defaultType) does the reverse:

  1. It parses the JSON. If no object is given, it creates one of the type in _objectType, or of the default type.
  2. It copies all simple values (text, numbers, booleans) onto the object.
  3. For every array it creates a new object per item, of the type in the item's _objectType (or the default type, usually ITSObject), and adds it to the array that is already there. Then it loads the item in the same way.
  4. For every sub object it creates a new object and loads it in the same way.
  5. Empty arrays and empty objects in the JSON are skipped, so the defaults of the constructor stay.
  6. At the end it calls postLoad() if the object has one, for example to turn date texts into dates.

Because arrays are added to and not replaced, loading into an object that already has screens adds the new screens to the old ones. This is the reason behind the merging of tests with a ZIP upload. Load into a fresh object when you want a clean copy.

On the server

The internal API stores every object in a table with one column per top level property. Nested parts are stored as JSON text in a text column. The API turns them into text when saving and back into JSON when reading (the pass_through_fields in ITSRestAPIORMExtensions.py):

Table Columns stored as JSON text
Tests screens, scales, norms, documents, scoreRules, graphs, media, files, PluginData
ClientSessionTests Results, Scores, PluginData
TestScreenTemplates TemplateVariables, PluginData
Reports ReportGraphs, PluginData
ClientBatteries BatteryTests, BatteryReports, PluginData
ClientPersons, ClientSessions, ClientGeneratedReports, SecurityUsers and others PluginData

Some things to know:

  • A top level property without a column is silently ignored when saving. A new top level property therefore needs a new column, through a database migration script. A new value inside PluginData, Results or Scores needs no database change at all. That is why PluginData exists.
  • Passwords are never sent back by the API.
  • Protected tests. When a test taking login (without office rights) loads a test with TestDefinitionIsProtected switched on, the API leaves out the norms, documents, score lines, graphs, the scoring and norming scripts, the 360 scripts and the RequiredPars fields. The candidate's browser never sees the scoring and norming rules of such a test.
  • Tests, reports and screen templates can live in the central (master) database or in the database of the organisation. The runtime property dbsource tells where an object was loaded from.

Test definition: ITSTest

Property Default Saved What it does
ID new GUID yes The ID of the test.
TestName yes The short name of the test (at most 50 characters in the database). Used in lists, file names and log messages.
Description yes The name shown to users (at most 200 characters).
Explanation, Copyrights, CatalogInformation yes Texts for the test catalog and the test editor.
AuthorInfo yes Stored; no use found in the current code.
Costs 0 yes The credits charged when a candidate finishes the test, see Credits.
InvoiceCode yes A code for invoices and credit overviews.
Remarks yes Notes for the author, only shown in the editor.
TestType -1 yes 0 for a test. Values from 1000 are used for education and are not documented here yet. Editors for batteries, group sessions and public sessions only offer tests of the right type.
Active false yes Content can be used. Only active tests can be chosen for sessions.
TestDefinitionIsProtected true yes Hides the scoring and norming rules from candidates, see above.
ShowTestClosureScreen yes Shows a closure screen after the test.
TotalTimeAvailableForThisTest -1 yes The time for the test in seconds. At the start of the test it is copied to Results.testTimeLeft. Not editable in the test editor.
Supports360Degrees yes When on, the scripts Pre360 (once per session), Per360 (at the start of the test) and Post360 (at the end) run during test taking.
LanguageSupport yes The language code of the test.
Generation yes Raised by one on every save.
TestStartDate, TestEndDate 2000-01-01, 2100-01-01 yes Stored; no use found in the current code.
TestDefinitionFrozen, TestDefinitionIsReleased, SupportsTestTaking, SupportsTestScoring, SupportsOnlyRenorming, IsRestartable, CandidateCanDo360Too, MinPercentageOfAnswersRequired, TotalNumberOfExperiments yes Stored; no use found in the current code. They are kept for compatibility with existing tests.
RequiredParsPerson, RequiredParsSession, RequiredParsGroup, RequiredParsOrganisation yes Stored and protected; no use found in the web client.
ScoringScript comment yes The complex scoring script, see Scripting reference.
BeforeNormingScript, AfterNormingScript comment yes Run before and after the norm tables of every norm.
BeforeScript, AfterScript comment yes Run at the start and at the end of test taking. Not editable in the test editor.
Pre360, Per360, Post360 comment yes The 360 degrees scripts, see Supports360Degrees.
PluginData {} yes Free storage. The test editor keeps its tab switches here: testHasScoring, testHasNorms, testHasScreenDynamics, testHasMultipleScreens, testHasMedia, testHasCatalog, testHasArchiveImages.
screens, scales, scoreRules, norms, documents [ ] yes The content of the test, see below.
graphs [ ] yes Saved with the test, but not filled by the test editor. Report graphs belong to the report.
media, files no Lists of the media and files of the test, loaded separately from the server.
newTest, detailsLoaded, currentlyLoading, dbsource no Runtime state. A test list first loads only the main fields; loadTestDetailDefinition loads the rest and sets detailsLoaded.

Screens: ITSTestScreen

Property Saved What it does
id yes The ID of the screen. Answers are stored under this ID.
varName yes The screen name, used in scripts and scoring (sessiontest.Results.Question5).
explanation, remarks yes Notes for office users and authors.
screenGroup yes Stored; no use found in the current code.
show yes Whether the screen is shown. Screen scripts can switch it off to skip the screen.
beforeScreenScript, afterScreenScript yes The screen pre and post scripts, see Scripting reference.
screenComponents yes The components on the screen.
screenDynamics yes The screen dynamics rules.
UseLayoutsFromPreviousScreen yes Reuses the layout components of the previous screen.
LayoutsFromPreviousScreensExpanded, insertedElementByPreviousLayout no Runtime state for the reused layouts.

Components: ITSTestScreenComponent

Property Saved What it does
id yes The ID of the component. Its answer is stored under this ID.
varComponentName yes The component name, used in scripts and for session storage.
templateID yes The screen template this component uses.
templateValues yes The values the author filled in for the template variables, by variable name. RepeatBlockCount holds the number of repeat blocks; variables of the second and later repeat blocks get _2, _3 and so on after their name.
placeholderName yes The placeholder of a layout component that this component is shown in.
show yes Whether the component is shown at the start. Screen dynamics and scripts can change it.
storeAtSessionLevel yes Also stores the answer in the session, see below.
excludeFromAnonimisedTestResults yes Leaves the answer out of the anonymised research data.
runtimeValues no Runtime values for the template during test taking.

Screen dynamics: ITSTestScreenDynamics

Each rule compares the value of a source component with a value and shows or hides a target component. During test taking the rules of the current screen are checked every 350 ms.

Property Saved What it does
sourceScreenID, sourceVariableID yes The component whose answer is checked.
comparison yes The JavaScript comparison, for example ==, != or >. A single = is read as ==.
sourceValue yes The value to compare with.
targetScreenID, targetVariableID yes The component that is shown or hidden.
targetVisible yes Whether the target is shown (true) or hidden (false) when the comparison is true.
targetScript no Runs instead of targetVisible when set. It is not saved, so after loading it is always empty.

Scales: ITSTestScale

Property Saved What it does
id yes The ID of the scale. Its score is stored under this ID.
scaleVarName yes The scale name, used in scripts and reports.
scaleDescription, scaleExplanation yes The name and explanation shown to users.
scaleType yes N for a number (default) or T for text.
defaultValue yes The starting score, "0" by default. Also used in score lists when there is no score.
minimumScore, maximumScore yes The range of the scale. The minimum also matters for the border treatment of norms.
scalePrecision yes The number of decimals a numeric score is rounded to after scoring.
showScale yes When off, the scale is a hidden helper scale. Score lists such as getScaleScores() skip it.
calculateSequence yes Stored; no use found in the current code. Scales are scored in the order of the score lines.
remarks yes Notes for the author.

Score lines: ITSScaleScore

Each line says: if this answer has this value, change this scale.

Property Saved What it does
SourceScreenID, SourceQuestionID yes The screen and component of the answer.
SourceValue yes The answer value that triggers the line. With %%QuestionValue%% here and in the score, the line applies to every answer.
TargetScale yes The ID of the scale.
TargetScaleValue yes What happens to the scale. A plain value is added to a numeric scale. For a text scale it is evaluated as a JavaScript expression and becomes the new score, so put text in quotes. A value that starts with = is a formula on the current score. %%QuestionValue%% is replaced by the answer.

See Test editor tips for examples.

Norms: ITSTestNorm, ITSTestNormColumns and ITSTestNormColumn

A norm has one column per scale, and each column has rows that turn a raw score into a norm score.

Property Saved What it does
id, active yes The ID of the norm and whether it can be chosen.
NormVarName, normDescription, explanation, remarks yes Name and texts. The name ends up in AppliedNorm of every score.
normMetric yes S stanine, D decile (default), V vigintile, P percentile, T text or O other. It sets the maximum for graphs: 9, 10, 20 or 100, otherwise 10.
percentileValuesFilled yes When on, the rows also hold percentiles.
beforeNormScript, afterNormScript yes Scripts of this norm, run around the norm tables.
parameters yes Free settings of the norm. Known ones: DefaultNormOrder (-1 = not selected by default) and BorderValueTreatment (1 = the border is included, the default; 2 = the score must be above the border).
normColumns yes One ITSTestNormColumns per scale, with scaleID and the rows in normColumnValues.
Row: rawScoreBorder, normValue, percentileValue yes A row of the norm table. For numbers the border is a lower bound and the last row that matches wins; text scores must match the border exactly.

Documents: ITSTestDocument

Documents that belong to the test, such as a manual: documentName, documentLanguage, documentType, documentDescription (text, HTML or a link) and documentExposureLevel (who may see it). Note that the persistent list names Remarks while the object uses remarks, so the remarks of a document are not saved.

Answers and scores

The answers and scores of one candidate for one test are kept in the session test (ITSCandidateSessionTest), in two free form objects: Results and Scores. Their structure follows the test definition and is built by prepareTestStorage().

Results

Results holds the full state of the test:

  • For every screen there is an object under the key "__" + screen id.
  • In it, for every component there is an object under the key "__" + component id.
  • That object holds Value (the answer, as returned by the template's get value snippet), Visible (whether the component is shown), VisibleOriginal and Anonimise (a copy of excludeFromAnonimisedTestResults).
  • Next to the screens, testTimeLeft holds the time left for timed tests.

For convenience every screen and component can also be reached by its name, so sessiontest.Results.Question5.Answer.Value works. These name keys point to the same objects. Because the whole object is saved with JSON.stringify, the saved JSON contains both the ID keys and the name keys. After loading, prepareResultsStorage() links the name keys to the objects under the ID keys again. The ID keys are leading. Renaming a screen or component therefore does not lose answers.

Scores

Scores holds a score object per scale under the key "__" + scale id, and again under the scale name. A score object holds:

  • Score: the raw score;
  • NormScore, PercentileScore, PercentileScoreSet, AppliedNorm and AppliedNormDescription for the first norm, and the same with 2 and 3 at the end for the second and third norm. Before a norm is applied these are set to -.

Next to the scales, testResultAddition can hold an addition to the result, for example that the timer ended. Scripts can set it.

How scores are calculated

calculateScores() on the session test runs scoreTest() of the test and then normTest() for NormID1, NormID2 and NormID3:

  1. All scales are reset to their default value.
  2. The score lines are applied in their order.
  3. The complex scoring script runs.
  4. Numeric scales are rounded to their precision.
  5. For every chosen norm: the test's before norming script, the norm's before script, the norm tables, the norm's after script and the test's after norming script.

Errors in scripts are written to the browser console and do not stop the scoring. Note the parameter names of these scripts: the parameter scores holds the answers and scales holds the scores. See the Scripting reference for the details.

Store at session level

For a component with storeAtSessionLevel, the answer is also copied to session.PluginData.sessionStorage, under the component name. When another test in the same session has a component with the same name and this option, it takes the answer from there. In poll mode the answer is also kept in a cookie. See Test editor tips for an example.

Sessions

ITSCandidateSession

Property Saved What it does
ID, PersonID yes The session and its candidate. The candidate itself is loaded as Person.
SessionType yes 0 individual session, 1 a session made from a public session, 3 paper and pencil, 100 group session, 200 public session. Values from 1000 are used for education.
GroupSessionID, GroupID yes The group session and group this session belongs to.
Description, Goal, Remarks, UserDefinedFields yes Texts of the session.
UsedBatteryIDs yes The batteries the tests came from.
AllowedStartDateTime, AllowedEndDateTime, EnforceSessionEndDateTime yes When the candidate may take the tests.
StartedAt, EndedAt, CreateDate yes When the session started, ended and was made.
Status, SessionState yes 10 ready, 20 in progress, 30 done, 31 done and processed by the server. SessionState is a text version.
Active yes False for an archived session.
EMailNotificationAdresses, EmailNotificationIncludeResults yes Who gets a mail when the session is done, and whether it includes results.
ShortLoginCode yes The short code a candidate can log in with.
ManagedByUserID yes The consultant who manages the session.
PluginData yes Free storage, for example sessionStorage (answers stored at session level), Vars (session variables of screen actions), GroupMembers (group sessions), sessionParameters and CandidateParameters (public sessions) and MailSettings.
SessionTests no The tests of the session. They are saved separately, one row each.
AuditTrail, generatedReports no Loaded on demand.

ITSCandidateSessionTest

Property Default Saved What it does
ID, SessionID yes The session test and its session.
TestID yes The test definition. At runtime the test itself is linked as testDefinition.
PersID yes The person who takes the test: the candidate, or another person in a 360 degrees session.
Sequence 0 yes The order of the tests in the session.
TestLanguage yes The language of the test.
NormID1, NormID2, NormID3 empty GUID yes Up to three norms that are applied when scoring.
Status 10 yes 10 ready, 20 in progress, 30 done. Credits are charged when a test reaches 30.
TestStart, TestEnd 2000-01-01 yes When the test was started and finished.
TotalTestTime 0 yes Stored and returned by the API; not filled by the current web client.
CurrentPage, TotalPages 0 yes The index of the current screen and the number of screens. After a page refresh, test taking continues at CurrentPage.
PercentageOfQuestionsAnswered 0 yes Stored and returned by the API; not filled by the current web client.
HowTheTestIsTaken 10 yes 10 online, 20 on paper.
Results, Scores {} yes The answers and the scores, see above.
PluginData {} yes Free storage, for example Vars (test variables of screen actions) and DataGathering (Allowed: the consent setting of the test; it is stored, but the research data is saved for every finished test, see ITR database model).

During test taking the session test is saved through sessionteststaking/, otherwise through sessiontests/.

Size limits

To keep the server healthy, the size of the flexible fields is limited when a candidate saves a test or a session. The limits are server settings (see Server settings and tools) and are the same for every organisation on the server:

Setting Default Limits
MAX_RESULTS_LIMIT 1,000,000 Results of a session test: all answers of one test
MAX_SCORES_LIMIT 100,000 Scores of a session test
MAX_PLUGINDATA_LIMIT 10,000 PluginData of a session test, and PluginData of the session

Good to know:

  • The limits count characters, not bytes: the length of the field as text after the server has read the JSON. A letter with an accent counts as one character.
  • The limits apply to saves during test taking. Saves from the office, for example when a consultant corrects answers, are not limited.
  • 0 switches a limit off. A new value applies from the next save; no restart is needed.
  • When a field is too large, the server refuses the save. The web client tries again a few times and then shows the candidate the message that saving the test failed. The server log shows which field was too large, for example Results field limit exceeded.

For test authors, PluginData is the one to keep an eye on. Answers stored at session level (see Store at session level) and the variables of screen actions (Vars) are kept there, and its limit is the smallest. A test with many long answers stored at session level, or with large variables, can reach it. If that happens, raise the limit in the server settings.

Text columns in the database have limits of their own, such as 50 characters for TestName and 200 for Description, see the property tables above.

Other objects

ITSScreenTemplate
TemplateType (0 component, 10 layout), TemplateVariables, the HTML for the default, PnP and summary views (HTMLContent, HTMLContentPnP, HTMLContentSummary) and the snippets (get_value_snippet, set_value_snippet, init_value_snippet, validation_snippet, isanswered_snippet, the generator snippets and custom_template_actions_snippet). PluginData.LegacyTemplate is the Discourage use of template option. See Test screen template introduction.
ITSScreenTemplateVariable
variableName, description, defaultValue, translatable and variableType: T text, TN number, A text (multiple lines), H HTML text, L list of choices, LX list of actions, B on/off switch, C colour picker, I image, P placeholder, E explanation.
ITSReport
TestID, ReportText, BeforeReportScript, ReportGraphs (ITSGraph objects), ReportLanguage, Active, and ReportType (0 test report, 10 session report, 20 group report, 30 360 degrees group report). See Report editor introduction.
ITSBattery
BatteryName, BatteryType (10 test battery; values from 1000 are used for education), BatteryTests (ITSBatteryTest: TestID and the default norms NormID1 to NormID3) and BatteryReports (ITSBatteryReport: ReportID).
ITSCandidate, ITSCompany, ITSUser, ITSCreditGrant
Mostly plain fields that match the screens where they are edited. See Candidates menu, Manage organisations, Manage consultants, User rights and roles and Credits.

Good to know for developers

  • Adding a property: give it a default in the constructor and add it to persistentProperties. For a new top level property also add a database column; otherwise use PluginData.
  • Never rename or remove a saved property or a key in Results or Scores. Existing tests, scripts and reports may use it.
  • Do not rely on the name keys in Results and Scores when you save data yourself: the ID keys are leading.
  • Several properties are stored but not used by the current code. Keep them: they are part of the saved format of existing tests.
  • The web client loads the Datejs library, which replaces Date.now() with a function that returns a Date object instead of a number. Code such as new Date.now() and TestStart = Date.now() relies on this. Outside the web client, for example in Node.js, Date.now() returns a number again.

Where to go next