quizApp package

Submodules

quizApp.config module

Configurations for the project. These are loaded in app.py.

class quizApp.config.Config[source]

Bases: future.types.newobject.newobject

Global default config.

DEBUG = False
EXPERIMENTS_PLACEHOLDER_GRAPH = u'missing.png'
GRAPH_DIRECTORY = u'graphs'
SECURITY_CHANGEABLE = True
SECURITY_POST_LOGIN_VIEW = u'core.post_login'
SECURITY_REGISTERABLE = True
SQLALCHEMY_TRACK_MODIFICATIONS = False
TESTING = False
WTF_CSRF_ENABLED = True
WTF_CSRF_METHODS = [u'POST', u'PUT', u'PATCH', u'DELETE']
class quizApp.config.Development[source]

Bases: quizApp.config.Config

Configuration for development environments.

DEBUG = True
SECRET_KEY = u'---'
SECURITY_PASSWORD_HASH = u'bcrypt'
SECURITY_PASSWORD_SALT = u'---'
SECURITY_SEND_REGISTER_EMAIL = False
SQLALCHEMY_DATABASE_URI = u'mysql://quizapp:foobar@localhost/quizapp'
SQLALCHEMY_ECHO = True
class quizApp.config.Production[source]

Bases: quizApp.config.Config

Configuration for production environments.

DEBUG = False
SECURITY_PASSWORD_HASH = u'bcrypt'
TESTING = False
class quizApp.config.Testing[source]

Bases: quizApp.config.Config

Config used for testing.

DEBUG = True
SECRET_KEY = u'---'
SECURITY_PASSWORD_SALT = u'---'
SQLALCHEMY_DATABASE_URI = u'mysql://quizapp:foobar@localhost/quizapp_test'
TESTING = True
WTF_CSRF_ENABLED = False

quizApp.models module

Models for the quizApp.

class quizApp.models.Activity(*args, **kwargs)[source]

Bases: quizApp.models.Base

An Activity is essentially a screen that a User sees while doing an Experiment. It may be an instructional screen or show a Question, or do something else.

This class allows us to use Inheritance to easily have a variety of Activities in an Experiment, since we have a M2M between Experiment and Activity, while a specific Activity may actually be a Question thanks to SQLAlchemy’s support for polymorphism.

type

string – Discriminator column that determines what kind of Activity this is.

needs_comment

bool – True if the participant should be asked why they picked what they did after they answer the question.

category

string – A description of this assignment’s category, for the users’ convenience.

assignments

list of Assignment – What Assignments include this Activity

scorecard_settings

ScorecardSettings – Settings for scorecards after this Activity is done

include_in_scorecards

bool – Whether or not to show this Activity in scorecards

class Meta[source]

Bases: future.types.newobject.newobject

Define what kind of Result we are looking for.

result_class

alias of Result

Activity.get_score(result)[source]

Get the participant’s score for this Activity.

Given a Result object, an Activity subclass should be able to “score” the result in some way, and return an integer quantifying the Participant’s performance.

Activity.is_correct(result)[source]

Given a result, return True if the answer was correct or False otherwise.

If this activity does not have a concept of correct/incorrect, return None.

class quizApp.models.Assignment(**kwargs)[source]

Bases: quizApp.models.Base

For a given Activity, determine which MediaItems, if any, a particular Participant sees, as well as recording the Participant’s answer, or if they skipped this assignment.

comment

string – An optional comment entered by the student.

choice_order

string – A JSON object in string form that represents the order of choices that this participant was presented with when answering this question, e.g. {[1, 50, 9, 3]} where the numbers are the IDs of those choices.

time_to_submit

timedelta – Time from the question being rendered to the question being submitted.

media_items

list of MediaItem – What MediaItems should be shown

activity

Activity – Which Activity this Participant should see

assignment_set

AssignmentSet – Which AssignmentSet this Assignment belongs to

correct

Check if this assignment was answered correctly.

score

Get the score for this assignment.

This method simply passes result to the activity‘s get_score method and returns the result.

Note that if there is no activity this will raise an AttributeError.

validate_activity(_, activity)[source]

Make sure that the number of media items on the activity is the same as the number of media items this assignment has.

validate_result(_, result)[source]

Make sure that this assignment has the correct type of result.

class quizApp.models.AssignmentSet(**kwargs)[source]

Bases: quizApp.models.Base

An AssignmentSet represents a sequence of Assignments within an Experiment. All Assignments in an AssignmentSet are done in order by the same Participant.

progress

int – Which Assignment the user is currently working on.

complete

bool – True if the user has finalized their responses, False otherwise

participant

Participant – Which Participant this refers to

experiment

Experiment – Which Experiment this refers to

assignments

list of Assignment – The assignments that this Participant should do in this Experiment

class Meta[source]

Bases: future.types.newobject.newobject

Specify field order.

AssignmentSet.score

Return the cumulative score of all assignments in this AssignmentSet,

Currently this iterates through all assignments. Profiling will be required to see if this is too slow.

class quizApp.models.Base(**kwargs)[source]

Bases: flask_sqlalchemy.Model

Base class for all models.

All models have an identical id field.

id

int – A unique identifier.

import_dict(**kwargs)[source]

Populate this object using data imported from a spreadsheet or similar. This means that not all fields will be passed into this function, however there are enough fields to populate all necessary fields. Due to validators, some fields need to be populated before others. Subclasses of Base to which this applies are expected to override this method and implement their import correctly.

save(commit=True)[source]

Save this model to the database.

If commit is True, then the session will be comitted as well.

class quizApp.models.Choice(**kwargs)[source]

Bases: quizApp.models.Base

A Choice is a string that is a possible answer for a Question.

choice

string – The choice as a string.

label

string – The label for this choice (1,2,3,a,b,c etc)

correct

bool – “True” if this choice is correct, “False” otherwise

question

Question – Which Question owns this Choice

points

int – How many points the Participant gets for picking this choice

class quizApp.models.Dataset(**kwargs)[source]

Bases: quizApp.models.Base

A Dataset represents some data that MediaItems are based on.

name

string – The name of this dataset.

info

string – Some information about this dataset

media_items

list of MediaItem – Which MediaItems this Dataset owns

questions

list of Questions – Which Questions reference this Dataset

class quizApp.models.Experiment(*args, **kwargs)[source]

Bases: quizApp.models.Base

An Experiment contains a list of Activities.

name

str – The name of this experiment

created

datetime – When this experiment was created

start

datetime – When this experiment becomes accessible for answers

stop

datetime – When this experiment stops accepting answers

assignment_sets

list of ParticiapntExperiment – List of AssignmentSets that are associated with this Experiment

disable_previous

bool – If True, don’t allow Participants to view and modify previous activities.

show_timers

bool – If True, display a timer on each activity expressing how long the user has been viewing this activity.

show_scores

bool – If True, show the participant a cumulative score on every activity.

scorecard_settings

ScorecardSettings – A ScorecardSettings instance that determines how scorecards will be rendered in this Experiment.

If the display_scorecard field is False, then no scorecards will be displayed.

If the display_scorecard field is True, then scorecards will be displayed after Activities whose own ScorecardSettings objects specify that scorecards should be shown. They will be rendered according to the ScorecardSettings of that Activity.

In addition, a scorecard will be rendered after the experiment according to the Experiment’s ScorecardSettings.

flash

bool – If True, flash the MediaItem for flash_duration milliseconds

flash_duration

int – How long to display the MediaItem in milliseconds

running

Returns True if this experiment is currently running, otherwise False.

class quizApp.models.FreeAnswerQuestion(*args, **kwargs)[source]

Bases: quizApp.models.Question

A FreeAnswerQuestion allows a Participant to enter an arbitrary answer.

class Meta[source]

Bases: future.types.newobject.newobject

Define what kind of Result we are looking for.

result_class

alias of FreeAnswerQuestionResult

FreeAnswerQuestion.get_score(result)[source]

If this Question was answered, return 1.

class quizApp.models.FreeAnswerQuestionResult(**kwargs)[source]

Bases: quizApp.models.Result

What a Participant entered into a text box.

class quizApp.models.Graph(**kwargs)[source]

Bases: quizApp.models.MediaItem

A Graph is an image file located on the server that may be shown in conjunction with an Assignment.

path

str – Absolute path to this Graph on disk

directory

Return the directory this graph is located in.

If path is not empty, return the lowest directory specified by path. Otherwise, return the designated graph directory.

filename()[source]

Return the filename of this graph.

class quizApp.models.IntegerQuestion(*args, **kwargs)[source]

Bases: quizApp.models.Question

Ask participants to enter an integer, optionally bounded above/below.

All bounds are inclusive.

answer

int – The correct answer to this question

bounded_below

bool – If True, enforce a lower bound

lower_bound

int – The minimum possible answer.

bounded_above

bool – If True, enforce an upper bound

upper_bound

int – The maximum possible answer.

class Meta[source]

Bases: future.types.newobject.newobject

Specify the result class.

result_class

alias of IntegerQuestionResult

IntegerQuestion.get_score(result)[source]

If the choice is the answer, one point.

IntegerQuestion.validate_answer(_, answer)[source]

Ensure answer is within the bounds.

class quizApp.models.IntegerQuestionResult(**kwargs)[source]

Bases: quizApp.models.Result

The integer entered as an answer to an Integer Question.

integer

int – The answer entered to this question.

class quizApp.models.MediaItem(**kwargs)[source]

Bases: quizApp.models.Base

A MediaItem is any aid to be shown when displaying an assignment. It can be text, image, videos, sound, whatever. Specific types should subclass this class and define their own fields needed for rendering.

name

str – Name for this Media Item

assignments

list of Assignment – Which Assignments display this MediaItem

dataset

Dataset – Which Dataset owns this MediaItem

class quizApp.models.MultiSelectQuestion(*args, **kwargs)[source]

Bases: quizApp.models.MultipleChoiceQuestion

A MultiSelectQuestion allows any number of Choices to be selected.

class Meta[source]

Bases: future.types.newobject.newobject

Define what kind of Result we are looking for.

result_class

alias of MultiSelectQuestionResult

class quizApp.models.MultiSelectQuestionResult(**kwargs)[source]

Bases: quizApp.models.Result

The Choices that a Participant picked in a MultiSelectQuestion.

validate_choice(value, *_)[source]

Make sure this Choice is a valid option for this Question.

class quizApp.models.MultipleChoiceQuestion(*args, **kwargs)[source]

Bases: quizApp.models.Question

A MultipleChoiceQuestion has one or more choices that are correct.

class Meta[source]

Bases: future.types.newobject.newobject

Define what kind of Result we are looking for.

result_class

alias of MultipleChoiceQuestionResult

MultipleChoiceQuestion.get_score(result)[source]

If this Question was answered, return the point value of this choice. Otherwise return 0.

class quizApp.models.MultipleChoiceQuestionResult(**kwargs)[source]

Bases: quizApp.models.Result

The Choice that a Participant picked in a MultipleChoiceQuestion.

validate_choice(value, *_)[source]

Make sure this Choice is a valid option for this Question.

class quizApp.models.Participant(**kwargs)[source]

Bases: quizApp.models.User

A User that takes Experiments.

opt_in

bool – Has this user opted in to data collection?

foreign_id

str – If the user is coming from an external source (e.g. canvas, mechanical turk) it may be necessary to record their user ID on the other service (e.g. preventing multiple submission). This field holds the foreign ID of this user.

assignment_sets

list of AssignmentSets – List of AssignmentSets that this participant has

class quizApp.models.Question(*args, **kwargs)[source]

Bases: quizApp.models.Activity

A Question is related to one or more MediaItems and has one or more Choices, and is a part of one or more Experiments.

question

string – This question as a string

explantion

string – The explanation for why the correct answer is correct.

num_media_items

int – How many MediaItems should be shown when displaying this question

choices

list of Choice – What Choices this Question has

datasets

list of Dataset – Which Datasets this Question can pull MediaItems from. If this is empty, this Question can use MediaItems from any Dataset.

class quizApp.models.Result(**kwargs)[source]

Bases: quizApp.models.Base

A Result is the outcome of a Participant completing an Activity.

Different Activities have different data that they generate, so this model does not actually contain any information on the outcome of an Activity. That is something that child classes of this class must define in their schemas.

On the Assignment level, the type of Activity will determine the type of Result.

assignment

Assignment – The Assignment that owns this Result.

class quizApp.models.Role(**kwargs)[source]

Bases: quizApp.models.Base, flask_security.core.RoleMixin

A Role describes what a User can and can’t do.

class quizApp.models.ScaleQuestion(*args, **kwargs)[source]

Bases: quizApp.models.SingleSelectQuestion

A ScaleQuestion is like a SingleSelectQuestion, but it displays its options horizontally. This is useful for “strongly agree/disagree” sort of questions.

class quizApp.models.Scorecard(*args, **kwargs)[source]

Bases: quizApp.models.Activity

A Scorecard shows some kind of information about all previous activities.

title

str – The title of this scorecard

prompt

str – The prompt to show when asking for a comment

class Meta[source]

Bases: future.types.newobject.newobject

Define what kind of Result we are looking for.

result_class

alias of ScorecardResult

class quizApp.models.ScorecardResult(**kwargs)[source]

Bases: quizApp.models.Result

Result to a Scorecard activity. This class just exists to implement __str__ since there is no action to be taken in a scorecard.

class quizApp.models.ScorecardSettings(**kwargs)[source]

Bases: quizApp.models.Base

A ScorecardSettings object represents the configuration of some kind of scorecard.

Scorecards may be shown after each Activity or after each Experiment (or both). Since the configuration of the two scorecards is identical, it has been refactored to this class.

display_scorecard

bool – Whether or not to display this scorecard at all.

display_score

bool – Whether or not to display a tally of points.

display_time

bool – Whether or not to display a count of how much time elapsed.

display_correctness

bool – Whether or not to display correctness grades.

display_feedback

bool – Whether or not to display feedback on responses.

class quizApp.models.SingleSelectQuestion(*args, **kwargs)[source]

Bases: quizApp.models.MultipleChoiceQuestion

A SingleSelectQuestion allows only one Choice to be selected.

class quizApp.models.Text(**kwargs)[source]

Bases: quizApp.models.MediaItem

Text is simply a piece of text that can be used as a MediaItem.

text

str – The text of this media item.

class quizApp.models.User(**kwargs)[source]

Bases: quizApp.models.Base, flask_security.core.UserMixin

A User is used for authentication.

name

string – The username of this user.

password

string – This user’s password.

authenticated

bool – True if this user is authenticated.

type

string – The type of this user, e.g. experimenter, participant

has_any_role(roles)[source]

Given a list of Roles, return True if the user has at least one of them.

Module contents

Handle creating the app and configuring it.

quizApp.apply_default_user_role(_, user, **__)[source]

When a new user is registered, make them a participant.

quizApp.create_app(config_name, overrides=None)[source]

Create and return an instance of this application.