Surveys
- class soccon.survey.BeiweSurvey(file, key_path='', key=None, id='', subject_id='', parse_err=-201, skip_ans=-101, validation_err=-301, file_df='')
Bases:
object
Object that contains all relevant information for a given survey
- clean_to_save()
Drops ‘score_flag’ column and ‘info_text_box’ rows, resets index.
- eval_question(opts, ans, q_num, score_flag, question_id)
Splits answer options and returns answer score
- Parameters:
opts (str) – String of answer options split by semicolons
ans (str) – Answer for this question
q_num (int) – This question’s number
score_flag (bool) – True if this question should be score, Flase if not
- Returns:
int – Scored answer
- export(out_dir, out_prefix='')
- Saves self.df to specified location.
Appends “_OUT” always. Appends “_OUT_SKIPPED_ANS” and “_OUT_PARSE_ERR” if self.skipped_ans or self.parse_err are in self.df.score.
- Parameters:
out_dir (str) – Path to directory into which self.df should be saved.
out_prefix (str, optional) – Prefix to prepend to filename. Defaults to “”.
- static load_key(fpath)
Loads and processes survey key
- Parameters:
fpath (str) – Path to survey key CSV or XLSX.
- Returns:
DataFrame – Key formatted such that columns are survey ids
- mark_to_score()
Adds a “score_flag” column to self.df containing boolean values indicating whether this question should be scored or not. Marks as false: “not presented, only answer if + no answer selected, yes/no question rows, info_text_box, free_response, and slider rows.
- parse_and_score()
Parses a given survey and stores a cleaned and scored csv file
- preprocess()
Cleans the survey dataframe by removing brackets and replacing “ ;” and “ ; “ with “;” in question answer options.
- score(ans_opts, answer, q_num)
Survey scoring algorithm
- Parameters:
ans_opts (list) – List of answer options (strings)
answer (string) – The answer to score
q_num (int) – Index of this question
- Returns:
int – Scored value
- class soccon.survey.RedcapSurvey(file, key_path='', key=None, id='', file_df='')
Bases:
object
- export(out_dir, out_prefix='')
- Saves self.df to specified location.
Appends “_OUT” always.
- Parameters:
out_dir (str) – Path to directory into which self.df should be saved.
out_prefix (str, optional) – Prefix to prepend to filename. Defaults to “”.
- static load_key(fpath)
Loads and processes survey key
- Parameters:
fpath (str) – Path to survey key CSV or XLSX.
- Returns:
DataFrame – Key parsed for use in survey processing
- process()
- soccon.survey.aggregate_beiwe(data_dir, key_path)
Take all processed data and create a summary Excel doc saved to out_dir. First tab is a data summary, second tab is a basic statistics summary, remaining tabs contain detailed scoring for each individual survey
- Parameters:
data_dir (str) – Path to directory in which processed data exists.
out_dir (str) – Directory to which summary sheet should be saved.
key_path (str) – Path to CSV key containing survey scoring rules
out_name (str, optional) – Name of output file. Defaults to “SURVEY_SUMMARY”.
- soccon.survey.aggregate_redcap(data_dir, key_path)