pyutils_sh package

Submodules

pyutils_sh.exam module

Functions for aggregating and analyzing exam-related data, such as calculating student exam performance.

pyutils_sh.exam.grade_scantron(input_scantron, correct_answers, drops=[], item_value=1, incorrect_threshold=0.5)[source]

Calculate student grades from scantron data.

Compiles data collected from a scantron machine (5-option multiple choice exam) and calculates grades for each student. Also provides descriptive statistics of exam performance, as well as a list of the questions “most” students got incorrect, and saves the distribution of answers for those poorly performing questions.

This function receives 1 scantron text file and produces 2 output files. Splitting of the scantron data is specific to each scantron machine. The indices used in this function are correct for the scantron machine in the UBC Psychology department as of 2015. Indices need to be adjusted for different machines.

Scantron exams can be finicky. Students who incorrectly fill out scantrons need to be considered. Make sure to manually inspect the text file output by the scantron machine for missing answers before running this. This function does not correct for human error when filling out the scantron.

Parameters:
  • input_scantron (string) – Path to the .txt file produced by the scantron machine.
  • correct_answers (list) – A list of strings containing the correct exam answers. For example: [“A”, “E”, “D”, “A”, B”]. The order must match the order of presentation on the exam (i.e. the first list item must correspond to the first exam question)
  • drops (list, optional) – List of integers containing question numbers that should be excluded from calculation of grades. For example: [1, 5] will not include questions 1 and 5 when calculating exam scores.
  • item_value (int, optional) – Integer representing how many points each exam question is worth.
  • incorrect_threshold (float between [0., 1.], optional) – Poorly performing questions are those where few students got the correct answer. This parameter sets the threshold at which an item is considered poor. For example, a threshold of 0.4 means that a poor item is considered to be one where less than 40% of students chose the correct answer.

pyutils_sh.gaze module

Functions for calculating various gaze/eye-tracking related statistics.

pyutils_sh.gaze.cross_correlation(person1, person2, framerate=25, constrain_seconds=2)[source]

Calculate cross-correlation between two gaze signals.

This function takes 2 lists/arrays of data, each containing an individual’s coded gaze data from an eye-tracker, and calculates the normalized max cross-correlation value with its associated lag.

Additionally, it will also return the cross-correlation value at 0 lag, as well as the entire normalized array as a Python list.

Negative lag value means person2 lagged behind person1 by x frames e.g. A = [0,1,1,1,0,0,0] B = [0,0,0,1,1,1,0] cross_correlation(A,B)

Positive lag value means person1 lagged behind person2 by x frames e.g. A = [0,0,0,1,1,1,0] B = [0,1,1,1,0,0,0] cross_correlation(A,B)

Parameters:
  • person1 (ndarray or list) – 1D array of person 1’s gaze over time, coded as 0 = not looking, 1 = looking. The values represent whether the person was looking at a target at a particular point in time.
  • person2 (ndarray or list) – 1D array of person 2’s gaze over time, coded as 0 = not looking, 1 = looking. The values represent whether the person was looking at a target at a particular point in time.
  • framerate (int, optional) – The framerate (frames per second) of the eye-tracker.
  • constrain_seconds (int, optional) – Number of seconds to constrain the cross-correlation values by. The returned lags and cross-correlations will be centered around 0 lag by this many seconds.
Returns:

  • max_R (float) – Maximum (normalized) cross-correlation value.
  • max_lag_adj (float) – Lag at which max cross-correlation occurs.
  • zero_R (float) – Cross-correlation value at 0 lag.
  • norm_array (list) – A list of all (normalized) cross-correlation values.

pyutils_sh.survey module

Functions for aggregating and analyzing different types of survey data.

pyutils_sh.utils module

Utility functions for general purpose Python programming.

Module contents

pyutils_sh

An assortment of Python utilities for my personal projects. For example, there are functions for aggregating different types of survey data, grading scantron exams, calculating various statistics, and other general Python helper functions.

Documentation

Documentation is available via docstrings provided with the code, and an online API reference found at ReadTheDocs.

To view documentation for a function or module, first make sure the package has been imported:

>>> import pyutils_sh

Then, use the built-in help function to view the docstring for any function or module:

>>> help(pyutils_sh.exam.grade_scantron)

Modules

exam
Functions for aggregating different types of data from school exams (e.g. student grades)
gaze
Functions for analyzing gaze/eye-tracking data
survey
Tools for aggregating and analyzing data from different surveys
utils
General utility functions used for general Python programming