Пример #1
0
def download_def(openfile):
    checked = []
    
    for line in openfile:
        try:
            word_def = check.checkwords(line.rstrip('\n'))
            definition = '*'+line.rstrip('\n')+': '+word_def
            print definition + '\n'
            
            checked.append([line.rstrip('\n'),word_def.encode('UTF-8')])
        except TypeError:
            print "*****Wrong word(Longman): " + line.rstrip('\n')
            pass   
    openfile.close()
    
    outfilepath = os.path.join(exerpath,"def")
    outfile = os.path.join(outfilepath,openfile.name+'.def')
    
    if not os.path.exists(outfilepath):
        os.makedirs(outfilepath) 
        
    with open(outfile,'wb') as csvfile:
        swriter = csv.writer(csvfile,delimiter=',')
        swriter.writerows(checked)
        
    return checked
def dictdef(words):
    try:
        test = data[words]['exp']
    except:
        test = None
        
    if test != None:
        return test
    else:
        return check.checkwords(words)
 def study(self):
     self.spool = []
     for item in self.filelist:
         print self.spool
         self.spool.append(item)
         self.showimg(item)
         raw_input()
         print item
         subprocess.Popen(['afplay','/Users/y1275963/v2a/audio/'+item+'.mp3'])
         print item,' Dic, ', self.data[item]['exp']
         print item,' lon, ', check.checkwords(item)
         if len(self.spool)>=10:
             self.spool.reverse()
             self.test(self.spool)
def returndic(listname,dicname):

    dic = pickle.load(open('data8003000.pick','rb'))
    new_dic = {}

    for line in open(listname):
        query = line.encode('utf-8').strip().lower()

        if not query.startswith('#'):
            
            if not dic.has_key(query):
                try: 
                    ans2 = check.checkwords(query)
                    new_dic[query] = {'class':dicname,'exp':ans2,'right':[],'wrong':[]}
                    print query
                except TypeError:
                    pass
    return new_dic
def import_main(query):
    dic = pickle.load(open('data8003000.pick','rb'))
    rec =[]
    if query.startswith('#'):
        # Denote the comments
        print query
    else:
        ans1 = None
        ans2 = None
        
        try:
            ans1 = 'Dic, ',dic[query]
        except KeyError:
            pass
        
        try: 
            tk= check.checkwords(query)
            ans2 = 'Lon, ', tk
        except :
            pass
            
        if ans1 != None or ans2 != None:
            print query
        if ans1 != None:
            print ans1
            rec.append(r'Dic, '+dic[query].encode('utf8')+'\n')
        if ans2 != None:
            print ans2
            rec.append(r'Lon, '+tk.encode('utf8')+'\n')
        if ans1 == None and ans2 == None:
            print "###None found", query
            rec.append('"###None found", query')
        print '\n'
        filename = query+'.txt'
         
        with open(filename, "w") as text_file:
            text_file.write('***'.join(rec))
        return rec
        query = line.encode('utf-8').strip().lower()

        if query.startswith('#'):
            # Denote the comments
            print query
        else:
            ans1 = None
            ans2 = None
            
            try:
                ans1 = 'Dic, ',dic[query]
            except KeyError:
                pass
            
            try: 
                ans2 = 'Lon, ', check.checkwords(query)
            except TypeError:
                pass
                
            if ans1 != None or ans2 != None:
                print query
            if ans1 != None:
                print ans1
            if ans2 != None:
                print ans2
            if ans1 == None and ans2 == None:
                print "###None found", query
            print '\n'
        
         
         
    def genq(self,num):
        b800 = [x for x in self.data if self.data[x]['class'] =='b800' ]
        # Untouthed 
        ut = [x for x in b800 if len(self.data[x]['right'])==0 and len(self.data[x]['wrong'])==0]
        
        yesterday = datetime.datetime.today() - timedelta(days = 1)
        today = datetime.datetime.today() -  timedelta(days = 0)
        
        right = [x for x in self.data if len(self.data[x]['right']) >0 ]
        wrong = [x for x in self.data if len(self.data[x]['wrong']) >0 ] # with wrong records
        
        notright = [x for x in b800 if len(self.data[x]['right'])==0]# Without right records
        # Yesterday wrong and today_wrong check the last recordes
        # [-1] : Check the last the recoddes, 0 : only concern the date wrong the time etc.
        yest_wrong = [x for x in wrong if sameday(self.data[x]['wrong'][-1][0],yesterday)]
        today_wrong = [x for x in wrong if sameday(self.data[x]['wrong'][-1][0],today)]
        
#        f_slow = lambda x: np.mean([x[-1] for x in tk.data[x]['right']])
#        # If the average response time is larger than %
#        av_slow = [x for x in right if f_slow(x) > self.getdraw(90) ]   
        
        last_slow = [x for x in right if self.data[x]['right'][-1][-1] > self.getdraw(70)]
        
        list_a4 = [x for x in self.data if self.data[x]['class'] == 'check_a4']
        
        #from list:
        if True:
            def fromlist(filename):
                with open(filename) as f:
                    lines = f.read().splitlines()
                    lines = [item.lower() for item in lines]
                    lines = [item for item in lines if not item.startswith('#')]
                return lines
                
            li = fromlist('/Users/y1275963/v2a/rev3_4')
            poollist = [x for x in self.data]
            
            filelist = list(set(li) & set(poollist))
            notinlist = list(set(li) - set(filelist))
            for item in notinlist:
                try:               
                    self.data[item] = {'class':'added','exp':check.checkwords(item),'right' : [],'wrong':[]}
                    print item
                except TypeError:
                    pass   
            pickle.dump(self.data,open('bigpool.pick','wb'))
            pickle.dump(self.data,open(os.path.join('rec',time.strftime("%Y%m%d-%H%M%S")),'wb'))                         
                
        p3000 = [x for x in self.data if self.data[x]['class'] =='p3000' ]  
        qpool = filelist
        self.filelist = li

        random.shuffle(qpool)
        
        
  #      for item in self.data :
#          if self.data[item]['class'] == 'p3000' and len(self.data[item]['wrong']) == 0 and len(self.data[item]['right']) == 0 and item in [x for x in self.p3000[34]]:
#          if self.data[item]['class'] =='b800' and len(self.data[item]['wrong']) == 0 and  len(self.data[item]['right']) == 0:
         #   if self.data[item]['class'] =='b800' and  len(self.data[item]['right'])==0 and len(self.data[item]['wrong'])== 0:
#                qpool.append(item)  
        
        self.poll = qpool
        
        if len(qpool) >num:
            self.qpool = list(random.sample(set(qpool),num))
        else:
            self.qpool = qpool
            
        # To avoid len(qpool) == 0:
        try:
            print "sample data: ",self.data[self.qpool[0]]
        except:
            pass