Last active
August 29, 2015 13:56
-
-
Save puterleat/9190681 to your computer and use it in GitHub Desktop.
symptoms combinations program
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!python | |
| import random | |
| import csv | |
| from itertools import combinations | |
| def chunks(l, n): | |
| """ Yield successive n-sized chunks from l. | |
| """ | |
| for i in xrange(0, len(l), n): | |
| yield l[i:i+n] | |
| items = filter(lambda x: bool(x.get('text',None)), list(csv.DictReader(open('items3.csv', 'rU'), dialect='excel'))) | |
| _ = [i.update({'id': j}) for j, i in enumerate(items)] | |
| with open('itemdata.txt', 'w') as f: | |
| sd = csv.DictWriter(f, fieldnames=items[0].keys()) | |
| sd.writeheader() | |
| sd.writerows(items) | |
| allpairs = list(combinations(items, 2)) | |
| random.shuffle(allpairs) | |
| chunksofpairs = map(list, chunks(allpairs, (len(allpairs)/5) + 1)) | |
| template = """ | |
| ~~~{{#asthmamds1_{0[id]}_{1[id]} .likert}} | |
| <br><br><br> | |
| -------------------------------- | |
| How similar are the following situations? | |
| - {0[text]} | |
| - {1[text]} | |
| >>> | |
| 1=Not similar at all | |
| 2=2 | |
| 3=3 | |
| 4=4 | |
| 5=5 | |
| 6=6 | |
| 7=7 | |
| 8=8 | |
| 9=9 | |
| 10=Very similar | |
| ~~~ | |
| """ | |
| header = """--- | |
| finish_on_last_page: false | |
| name: asthmasymptoms1 | |
| redirect_url: /profile/ | |
| show_progress: false | |
| slug: asthmasymptoms{0} | |
| step_navigation: true | |
| steps_are_sequential: true | |
| success_message: Questionnaire complete. | |
| --- | |
| # Introduction | |
| ~~~ | |
| On the following pages we will ask you to rate how ***similar*** two situations are. | |
| All the situations will be related to asthma, or the side effects of asthma. | |
| You might find the questions odd, or find it hard to say how similar the two situations are - they may seem totally unrelated. In this case just indicate that they are not very similar. | |
| ~~~ | |
| # Questions | |
| """ | |
| for k, pairs in list(enumerate(chunksofpairs)): | |
| with open('survey{0}.mdown'.format(k), 'w') as f: | |
| f.write(header.format(k)) | |
| f.write("\n".join([template.format(i, j) for i, j in pairs])) | |
| # Remember to make page 2 random order |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment