Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- from random import randint
- import csv
- global final_list
- word_list=['aaa', 'bbb', 'ccc', 'ddd']
- shape_list=['CIRCLE', 'RECTANGLE', 'RHOMBUS', 'TRIANGLE']
- color_list=['RED', 'GREEN', 'BLUE', 'YELLOW']
- color_code_list=['#fa7d00', '#00ff00', '#0000ff', '#ffff00']
- cr_list=['k', 'z', 'a', 'm']
- proportion_list=[[9, 1, 1, 1],[1, 9, 1, 1],[1, 1, 9, 1],[1, 1, 1, 9]]
- repeats=10
- row=0
- st_list=[]
- for ii in range(len(word_list)):
- pp=randint(0,len(proportion_list)-1)
- proportion=proportion_list.pop(pp)
- for jj in range (len(color_list)):
- for kk in range(proportion[jj]):
- st_list.append([])
- st_list[row]=[word_list[ii], shape_list[ii], color_list[jj], color_code_list[jj], cr_list[jj]]
- row +=1
- #print st_list
- #print len(st_list)
- tr_count=0
- while True:
- tr_count +=1
- st_list_ext=st_list*repeats
- prev_color=''
- count=0
- tries=0
- retry=0
- final_list=[]
- for ii in range(len(st_list)*repeats):
- while True:
- jj=randint(0,len(st_list_ext)-1)
- if st_list_ext[jj][2] != prev_color:
- prev_color=st_list_ext[jj][2]
- final_list.append([])
- final_list[ii]=st_list_ext[jj]
- del st_list_ext[jj]
- retry=0
- tries=0
- count +=1
- break
- elif tries > 10:
- retry=1
- break
- else:
- tries +=1
- #retry=1
- if retry == 1:
- break
- if retry == 0:
- break
- subj_num=self.get('subject_nr')
- #myfile = open('test_%u.csv' % subj_num, 'wb')
- myfile = open('test_1.csv', 'wb')
- wr = csv.writer(myfile)
- wr.writerow(['word', 'color', 'color code', 'cr'])
- for ii in range(len(final_list)):
- wr.writerow(final_list[ii])
- myfile.close()
- #exp.final_list=final_list
- exp.items['block_1'].repeat = len(final_list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement