The Data Farm

Notebook for Creating Questionaire


In [1]:
import pods


/Users/neil/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pytz/__init__.py:29: UserWarning: Module pods was already imported from /Users/neil/sods/ods/pods/__init__.pyc, but /Users/neil/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages is being added to sys.path
  from pkg_resources import resource_stream

In [2]:
data = pods.datasets.movielens100k()

In [16]:
ratings = data['Y'].groupby('item').count().rating.copy()
ratings.sort(ascending=False)

In [18]:
ratings[:100]


Out[18]:
item
50      4081
258     3563
100     3556
181     3549
294     3395
286     3367
288     3346
1       3164
300     3017
121     3003
174     2940
127     2891
56      2758
7       2744
98      2730
...
265     1589
655     1589
182     1582
273     1561
143     1554
179     1547
180     1547
471     1547
161     1540
71      1540
8       1533
95      1533
427     1533
678     1533
322     1526
Name: rating, Length: 100, dtype: int64

In [39]:
import json
file = open('/Users/neil/Downloads/The_Data_Farm_Movie_Ratings.qsf', 'r')
survey = json.load(file)

In [41]:
survey['SurveyElements']


Out[41]:
[{u'Element': u'BL',
  u'Payload': [{u'BlockElements': [{u'QuestionID': u'QID1',
      u'Type': u'Question'}],
    u'Description': u'Default Question Block',
    u'ID': u'BL_eb4nekAfriDrzpj',
    u'Options': {u'BlockLocking': u'false', u'RandomizeQuestions': u'false'},
    u'Type': u'Default'},
   {u'Description': u'Trash / Unused Questions',
    u'ID': u'BL_9TgnRiuM9SdG1Cd',
    u'Type': u'Trash'},
   {u'BlockElements': [{u'QuestionID': u'QID2', u'Type': u'Question'},
     {u'QuestionID': u'QID3', u'Type': u'Question'}],
    u'Description': u'Block 1',
    u'ID': u'BL_8ozg4NKsGHnm0mh',
    u'Options': {u'BlockLocking': u'false',
     u'Randomization': {u'Advanced': {u'FixedOrder': [u'QID3'],
       u'QuestionsPerPage': 0,
       u'TotalRandSubset': u'30'}},
     u'RandomizeQuestions': u'RandomWithOnlyX'},
    u'SubType': u'',
    u'Type': u'Standard'}],
  u'PrimaryAttribute': u'Survey Blocks',
  u'SecondaryAttribute': None,
  u'SurveyID': u'SV_1U1noGyaO8oMqP3',
  u'TertiaryAttribute': None},
 {u'Element': u'FL',
  u'Payload': {u'Flow': [{u'FlowID': u'FL_2',
     u'ID': u'BL_eb4nekAfriDrzpj',
     u'Type': u'Block'},
    {u'FlowID': u'FL_3', u'ID': u'BL_8ozg4NKsGHnm0mh', u'Type': u'Standard'}],
   u'FlowID': u'FL_1',
   u'Properties': {u'Count': 3},
   u'Type': u'Root'},
  u'PrimaryAttribute': u'Survey Flow',
  u'SecondaryAttribute': None,
  u'SurveyID': u'SV_1U1noGyaO8oMqP3',
  u'TertiaryAttribute': None},
 {u'Element': u'SO',
  u'Payload': {u'BackButton': u'false',
   u'BallotBoxStuffingPrevention': u'false',
   u'Footer': u'',
   u'Header': u'',
   u'NewScoring': 1,
   u'NextButton': u'  >>  ',
   u'NoIndex': u'Yes',
   u'PartialData': u'+1 week',
   u'PreferJFE': True,
   u'PreviousButton': u'  <<  ',
   u'ProgressBarDisplay': u'None',
   u'SaveAndContinue': u'true',
   u'Skin': u'qtrial1',
   u'SkinLibrary': u'qtrial2015az1',
   u'SkinType': u'MQ',
   u'SurveyExpiration': u'None',
   u'SurveyProtection': u'PublicSurvey',
   u'SurveyTermination': u'DefaultMessage',
   u'ValidationMessage': u''},
  u'PrimaryAttribute': u'Survey Options',
  u'SecondaryAttribute': None,
  u'SurveyID': u'SV_1U1noGyaO8oMqP3',
  u'TertiaryAttribute': None},
 {u'Element': u'SCO',
  u'Payload': {u'AutoScoringCategory': None,
   u'DefaultScoringCategory': None,
   u'ScoringCategories': [],
   u'ScoringCategoryGroups': [],
   u'ScoringSummaryAfterQuestions': 0,
   u'ScoringSummaryAfterSurvey': 0,
   u'ScoringSummaryCategory': None},
  u'PrimaryAttribute': u'Scoring',
  u'SecondaryAttribute': None,
  u'SurveyID': u'SV_1U1noGyaO8oMqP3',
  u'TertiaryAttribute': None},
 {u'Element': u'STAT',
  u'Payload': {u'ID': u'Survey Statistics', u'MobileCompatible': False},
  u'PrimaryAttribute': u'Survey Statistics',
  u'SecondaryAttribute': None,
  u'SurveyID': u'SV_1U1noGyaO8oMqP3',
  u'TertiaryAttribute': None},
 {u'Element': u'QC',
  u'Payload': None,
  u'PrimaryAttribute': u'Survey Question Count',
  u'SecondaryAttribute': u'3',
  u'SurveyID': u'SV_1U1noGyaO8oMqP3',
  u'TertiaryAttribute': None},
 {u'Element': u'SQ',
  u'Payload': {u'AnswerOrder': [u'1', u'2', u'3'],
   u'Answers': {u'1': {u'Display': u'Click to write Scale point 1'},
    u'2': {u'Display': u'Click to write Scale point 2'},
    u'3': {u'Display': u'Click to write Scale point 3'}},
   u'ChoiceDataExportTags': False,
   u'ChoiceOrder': [u'1', u'2', u'3'],
   u'Choices': {u'1': {u'Display': u'Click to write Statement 1'},
    u'2': {u'Display': u'Click to write Statement 2'},
    u'3': {u'Display': u'Click to write Statement 3'}},
   u'Configuration': {u'ChoiceColumnWidth': 25,
    u'MobileFirst': True,
    u'QuestionDescriptionOption': u'UseText',
    u'RepeatHeaders': u'none',
    u'TextPosition': u'inline',
    u'WhiteSpace': u'OFF'},
   u'DataExportTag': u'Q3',
   u'DefaultChoices': False,
   u'GradingData': [],
   u'Language': [],
   u'QuestionDescription': u'Click to write the question text',
   u'QuestionID': u'QID3',
   u'QuestionText': u'Click to write the question text',
   u'QuestionType': u'Matrix',
   u'Selector': u'Likert',
   u'SubSelector': u'SingleAnswer',
   u'Validation': {u'Settings': {u'ForceResponse': u'OFF',
     u'ForceResponseType': u'ON',
     u'Type': u'None'}}},
  u'PrimaryAttribute': u'QID3',
  u'SecondaryAttribute': u'Click to write the question text',
  u'SurveyID': u'SV_1U1noGyaO8oMqP3',
  u'TertiaryAttribute': None},
 {u'Element': u'RS',
  u'Payload': None,
  u'PrimaryAttribute': u'RS_0VavNMpeMQaixpz',
  u'SecondaryAttribute': u'Default Response Set',
  u'SurveyID': u'SV_1U1noGyaO8oMqP3',
  u'TertiaryAttribute': None},
 {u'Element': u'SQ',
  u'Payload': {u'AnswerOrder': [1, 2, 3, 4, 5, 6],
   u'Answers': {u'1': {u'Display': u"Haven't Seen It"},
    u'2': {u'Display': u'1 Star'},
    u'3': {u'Display': u'2 Star'},
    u'4': {u'Display': u'3 Star'},
    u'5': {u'Display': u'4 Star'},
    u'6': {u'Display': u'5 Star'}},
   u'ChoiceDataExportTags': False,
   u'ChoiceOrder': [1, 2, 3, 4, 5],
   u'Choices': {u'1': {u'Display': u'Star Wars (1977)'},
    u'2': {u'Display': u'Contact (1997)'},
    u'3': {u'Display': u'Fargo (1996)'},
    u'4': {u'Display': u'Return of the Jedi (1983)'},
    u'5': {u'Display': u'Liar Liar (1997)'}},
   u'Configuration': {u'ChoiceColumnWidth': 25,
    u'MobileFirst': True,
    u'QuestionDescriptionOption': u'UseText',
    u'RepeatHeaders': u'none',
    u'TextPosition': u'inline',
    u'WhiteSpace': u'OFF'},
   u'DataExportTag': u'Q2',
   u'DefaultChoices': {u'1': {u'1': {u'Selected': True}},
    u'2': {u'1': {u'Selected': True}},
    u'3': {u'1': {u'Selected': True}},
    u'4': {u'1': {u'Selected': True}},
    u'5': {u'1': {u'Selected': True}}},
   u'GradingData': [],
   u'Language': [],
   u'QuestionDescription': u'Please rate the following movies between 1 and 5 stars. ',
   u'QuestionID': u'QID2',
   u'QuestionText': u'Please rate the following movies between 1 and 5 stars.&nbsp;',
   u'QuestionType': u'Matrix',
   u'Selector': u'Likert',
   u'SubSelector': u'SingleAnswer',
   u'Validation': {u'Settings': {u'ForceResponse': u'OFF',
     u'ForceResponseType': u'ON',
     u'Type': u'None'}}},
  u'PrimaryAttribute': u'QID2',
  u'SecondaryAttribute': u'Please rate the following movies between 1 and 5 stars. ',
  u'SurveyID': u'SV_1U1noGyaO8oMqP3',
  u'TertiaryAttribute': None},
 {u'Element': u'SQ',
  u'Payload': {u'Configuration': {u'QuestionDescriptionOption': u'UseText'},
   u'DataExportTag': u'Q1',
   u'DefaultChoices': False,
   u'GradingData': [],
   u'Language': [],
   u'QuestionDescription': u"Username Please give us a name that you'd like to use as a 'handle' or\n'nickname'. This name shou...",
   u'QuestionID': u'QID1',
   u'QuestionText': u"<b>Username</b> Please give us a name that you'd like to use as a 'handle' or 'nickname'. This name should be something special to you, but it shouldn't reveal your identity. These names will be publicly available in the lecture.",
   u'QuestionType': u'TE',
   u'Selector': u'SL',
   u'Validation': {u'Settings': {u'ForceResponse': u'ON',
     u'ForceResponseType': u'ON',
     u'MinChars': u'4',
     u'TotalChars': u'10',
     u'Type': u'None'}}},
  u'PrimaryAttribute': u'QID1',
  u'SecondaryAttribute': u"Username Please give us a name that you'd like to use as a 'handle' or\n'nickname'. This name shou...",
  u'SurveyID': u'SV_1U1noGyaO8oMqP3',
  u'TertiaryAttribute': None}]

In [61]:
file = open('/Users/neil/answers2.txt', 'w+')
file.write("""[[AdvancedFormat]]

[[ED:State]]
[[ED:Gender]]
[[ED:SawSurvey:1]]

[[Block:MC Block]])
""")
for index, film in data['film_info'].loc[ratings[:200].index].iterrows():
    file.write('[[Question:MC]]\n')
    file.write('[[ID:q' + str(index)+']]\n')
    file.write(film.title + '\n')
    file.write('\n')
    file.write('[[AdvancedChoices]]\n')
    file.write('[[Choice:-1]]\n')
    file.write('Never Seen It\n')
    file.write('[[Choice:1]]\n')
    file.write('1 star\n')
    file.write('[[Choice:2]]\n')
    file.write('2 star\n')
    file.write('[[Choice:3]]\n')
    file.write('3 star\n')
    file.write('[[Choice:4]]\n')
    file.write('4 star\n')
    file.write('[[Choice:5]]\n')
    file.write('5 star\n')
    file.write('\n\n')

In [59]:
open?

In [60]:
file.__doc__


Out[60]:
"file(name[, mode[, buffering]]) -> file object\n\nOpen a file.  The mode can be 'r', 'w' or 'a' for reading (default),\nwriting or appending.  The file will be created if it doesn't exist\nwhen opened for writing or appending; it will be truncated when\nopened for writing.  Add a 'b' to the mode for binary files.\nAdd a '+' to the mode to allow simultaneous reading and writing.\nIf the buffering argument is given, 0 means unbuffered, 1 means line\nbuffered, and larger numbers specify the buffer size.  The preferred way\nto open a file is with the builtin open() function.\nAdd a 'U' to mode to open the file for input with universal newline\nsupport.  Any line ending in the input file will be seen as a '\\n'\nin Python.  Also, a file so opened gains the attribute 'newlines';\nthe value for this attribute is one of None (no newline read yet),\n'\\r', '\\n', '\\r\\n' or a tuple containing all the newline types seen.\n\n'U' cannot be combined with 'w' or '+' mode.\n"

In [ ]: