hifis_surveyval package

Subpackages

Submodules

hifis_surveyval.cli module

hifis_surveyval.data_container module

This module provides the definitions for a data container.

The container is meant to serve as the data source for the individual analysis functions.

class hifis_surveyval.data_container.DataContainer(settings: Settings)[source]

Bases: object

The data container holds the data read from the command line.

All data is grouped into question collections, which in turn hold the questions. During the loading, the DataContainer will keep track of answer sets which contradict the validation rules set in the metadata (e.g. no answer being given despite being mandatory.

__init__(settings: Settings)[source]

Set up an empty data container.

Args:
settings:

An object representing the current application settings.

collection_for_id(full_id: str) QuestionCollection[source]

Query for a given question collection given by its full ID.

Args:
full_id:

The full ID of the question collection to be returned.

Returns:

The question collection for the given ID.

Raises:

KeyError - if the collection for the given ID could not be found.

data_frame_for_ids(requested_ids: List[str]) <MagicMock id='139995741774992'>[source]

Compose a Data Frame form a list of question (collection) IDs.

IDs for which no question or question collection can be found will be skipped. These will be logged at debug level.

Args:
requested_ids:

A list of full question or question collection IDs, which are to be composed by participant into a single data frame.

Returns:

A single data frame containing the answers of all participants for the given questions / question collections. In case no data was available for any of the provided IDs, the result will be an empty DataFrame with the requested IDs as index.

property invalid_answer_sets: Set[str]

Get all participants who gave invalid answers.

Returns:

A set with the IDs of participants who had their answers marked as invalid.

load_metadata(yaml: List[str | Dict[str, str | List[str | YamlDict] | YamlDict]] | Dict[str, str | List[str | Dict[str, str | YamlList | YamlDict]] | Dict[str, str | List[str | YamlDict] | YamlDict]]) None[source]

Load additional metadata from YAML data.

If the given yaml is valid, the received metadata will be added to the known survey questions. QuestionCollections that fail to parse will not be added to the survey questions and the exception will instead be logged as a warning. It is safe to repeatedly call this function, if multiple sources for metadata need to be processed.

Args:
yaml:

Either a list of YamlDictionaries or a single YamlDictionary. Each YamlDictionary is expected to hold a QuestionCollection, Otherwise parsing will fail.

load_survey_data(csv_data: List[List[str]]) None[source]

Load survey data as given in a CSV file.

The data is expected to be given in such a way that the outer list represents the rows and the inner list the columns within each row

mark_answers_invalid(participant_ids: Set[str]) None[source]

Mark the answers given by participants as invalid.

Args:
participant_ids:

The IDs of participants who gave invalid answers.

mark_answers_valid(participant_ids: Set[str]) None[source]

Mark the answers given by participants as valid.

NOTE: This does not restore previously removed invalid answers. Invalid IDs are silently ignored.

Args:
participant_ids:

The IDs of participants for whom answers are to be marked as valid.

property participant_ids: List[str]

Get a list of all participant IDs in the survey data.

Note:

This list includes all participant IDs encountered while loading the survey data. It is not affected by removing invalid answer sets in any way. For those refer to the ‘invalid_answer_sets’ property.

Returns:

A list of all participant IDs as strings.

property question_collection_ids: List[str]

Get the IDs of all question collections.

Returns:

A list of question collection IDs as strings.

question_for_id(full_id: str) Question[source]

Query for a given question given by its full ID.

This is a shorthand for querying questions directly. If no hierarchy separator is included in the provided full ID, it is assumed that this refers to the anonymous question within a collection. For example, querying for “Q001” will actually yield “Q001/_”.

Args:
full_id:

The full ID of the question to be returned.

Returns:

The question for the given ID.

Raises:
KeyError:

If either the collection or the question for the given ID could not be found.

remove_invalid_answer_sets() None[source]

Remove answer sets that were marked as invalid.

The answers are removed on a per-participant basis.

property survey_questions: List[QuestionCollection]

Obtain all survey questions stored in the data container.

Returns:

A list of QuestionCollections that contain all the survey questions.

hifis_surveyval.hifis_surveyval module

This project is used to develop analysis scripts for surveys.

class hifis_surveyval.hifis_surveyval.HIFISSurveyval(settings: Settings)[source]

Bases: object

Main class for all functionalities.

Also serves as data storage.

__init__(settings: Settings)[source]

Initialize HIFISSurveyval.

Args:
settings:

A Settings container to store the setup configuration in. It will be populated with the related settings during the initialization of the HIFISSurveyval object.

settings: Settings

The settings storage

Module contents

This project is used to develop analysis scripts for the surveys.