Advertisement
Boris_R

OpenSesame_inline_script_1

Jan 14th, 2014
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.69 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. from random import randint
  4. import csv
  5.  
  6. global final_list
  7.  
  8. word_list=['aaa', 'bbb', 'ccc', 'ddd']
  9. shape_list=['CIRCLE', 'RECTANGLE', 'RHOMBUS', 'TRIANGLE']
  10. color_list=['RED', 'GREEN', 'BLUE', 'YELLOW']
  11. color_code_list=['#fa7d00', '#00ff00', '#0000ff', '#ffff00']
  12. cr_list=['k', 'z', 'a', 'm']
  13. proportion_list=[[9, 1, 1, 1],[1, 9, 1, 1],[1, 1, 9, 1],[1, 1, 1, 9]]
  14. repeats=10
  15.  
  16.  
  17. row=0
  18. st_list=[]
  19. for ii in range(len(word_list)):
  20.     pp=randint(0,len(proportion_list)-1)
  21.     proportion=proportion_list.pop(pp)
  22.     for jj in range (len(color_list)):
  23.         for kk in range(proportion[jj]):
  24.             st_list.append([])         
  25.             st_list[row]=[word_list[ii], shape_list[ii], color_list[jj], color_code_list[jj], cr_list[jj]]
  26.             row +=1
  27.  
  28. #print st_list
  29. #print len(st_list)
  30.  
  31. tr_count=0
  32. while True:
  33.     tr_count +=1
  34.     st_list_ext=st_list*repeats
  35.     prev_color=''
  36.     count=0
  37.     tries=0
  38.     retry=0
  39.     final_list=[]
  40.     for ii in range(len(st_list)*repeats):
  41.         while True:
  42.             jj=randint(0,len(st_list_ext)-1)
  43.             if st_list_ext[jj][2] != prev_color:
  44.                 prev_color=st_list_ext[jj][2]
  45.                 final_list.append([])
  46.                 final_list[ii]=st_list_ext[jj]
  47.                 del st_list_ext[jj]
  48.                 retry=0
  49.                 tries=0
  50.                 count +=1
  51.                 break
  52.             elif tries > 10:
  53.                 retry=1
  54.                 break
  55.             else:
  56.                 tries +=1
  57.                 #retry=1
  58.         if retry == 1:
  59.             break
  60.     if retry == 0:
  61.         break
  62.    
  63.  
  64. subj_num=self.get('subject_nr')
  65. #myfile = open('test_%u.csv' % subj_num, 'wb')
  66. myfile = open('test_1.csv', 'wb')
  67. wr = csv.writer(myfile)
  68. wr.writerow(['word', 'color', 'color code', 'cr'])
  69. for ii in range(len(final_list)):
  70.     wr.writerow(final_list[ii])
  71. myfile.close()
  72.  
  73. #exp.final_list=final_list
  74. exp.items['block_1'].repeat = len(final_list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement