def expStatus(csvname, impcsvfile): reScore = redis.Redis(host='10.96.142.109', port=6380, db=8) reSign = redis.Redis(host='10.96.142.109', port=6380, db=7) with open(csvname, 'w', newline='', encoding='gb2312') as csvfile: wr = csv.writer(csvfile, quoting=csv.QUOTE_NONE, quotechar='', escapechar='\\') #progress impcsv = open(impcsvfile, 'r') csvline = len(impcsv.readlines()) impcsv = open(impcsvfile, 'r') reader = csv.reader(impcsv, delimiter=',') i = 0 printProgress(i, csvline, prefix='Process', suffix='Complete', barLength=50) for row in reader: exprow = [1 for x in range(9)] exprow[1] = row[0] #studentcode exprow[2] = row[1] #courseid #get score score = reScore.hget('maxscore', ''.join(row)) #print("{}:{}".format(''.join(row),score)) if score is not None: scorelist = score.decode('utf-8').split(',') if float(scorelist[0]) > 59: exprow[3] = '4' #studystatus exprow[5] = scorelist[0] #score exprow[6] = scorelist[1] #scorecode exprow[7] = scorelist[2] #scoretype #get signnum sign = reSign.get(''.join(row)) if sign is not None: exprow[4] = sign.decode('utf-8') wr.writerow(exprow) i += 1 printProgress(i, csvline, prefix='Process', suffix='Complete', barLength=50) impcsv.close()
def expStatus(csvname,impcsvfile): reScore = redis.Redis(host='10.96.142.109',port=6380,db=8) reSign = redis.Redis(host='10.96.142.109',port=6380,db=7) with open(csvname,'w',newline='',encoding='gb2312') as csvfile: wr = csv.writer(csvfile,quoting=csv.QUOTE_NONE,quotechar='',escapechar='\\') #progress impcsv=open(impcsvfile,'r') csvline = len(impcsv.readlines()) impcsv=open(impcsvfile,'r') reader = csv.reader(impcsv,delimiter=',') i=0 printProgress(i,csvline,prefix='Process',suffix='Complete',barLength=50) for row in reader: exprow=[1 for x in range(9)] exprow[1]=row[0] #studentcode exprow[2]=row[1] #courseid #get score score = reScore.hget('maxscore',''.join(row)) #print("{}:{}".format(''.join(row),score)) if score is not None: scorelist=score.decode('utf-8').split(',') if float(scorelist[0])>59: exprow[3]='4' #studystatus exprow[5]=scorelist[0]#score exprow[6]=scorelist[1] #scorecode exprow[7]=scorelist[2] #scoretype #get signnum sign = reSign.get(''.join(row)) if sign is not None: exprow[4]=sign.decode('utf-8') wr.writerow(exprow) i +=1 printProgress(i,csvline,prefix='Process',suffix='Complete',barLength=50) impcsv.close()
def expScore(csvname,xlsfile,papercodetype='4'): # get date from score***xls to create composescore #filename is format that is name such as elc90* or signup90* or score90* #deal with numeric studict=getstuinfoDic() scoredic=getscoreDic() col_score=['学号','课程ID','考试代码','考试类别代码','试卷号','试卷成绩代码','形考成绩代码','形考比例','综合成绩代码','教学点代码','考试单位类型','考试次数'] batlist={"秋季":"09","春季":"03"} examunitlist={"中央":"1","省":"2","国开":"1","省开":"2"} rnNum =[0,1,2,3,4,5] # deal \n intnum=[11,12,13,14,15,16,17,23,24] blknum=[18,19,20,21,22] with open(csvname,'w',newline='',encoding='gb2312') as csvfile: wr = csv.writer(csvfile,quoting=csv.QUOTE_NONE,quotechar='',escapechar='\\') wb = xlrd.open_workbook(xlsfile) tmpCol2="" tmpCol3="" tmpCol4="" tmpCol5="" for sh in wb.sheets(): if sh.nrows==0: print("{} is empty".format(sh.name)) continue # return top to get next sheet # deal with mutilpline # from the second line #begin to process bColOrder=True rowcollist=sh.row_values(0) #get the column's name from the first row for i in range(len(col_score)): rowcollist[i]=rowcollist[i].replace('\n','') if col_score[i] not in rowcollist[i]: bColOrder=False print ("sheet:{} {}'s {} is not current order".format(xlsfile,sh.name,col_score[i])) break if bColOrder==False: # if the order of column is not current ,return to get next sheet continue lins = [x for x in range(1,sh.nrows)] iTotal=0 iValid=0 totalLines=len(lins) # total rows printProgress(0,totalLines,prefix='Process',suffix='Complete',barLength=50) for rownum in lins: #print("rownum:{}".format(rownum)) bvalid=True csvlist=["" for x in range(23)] rowlist =[str(item).replace('\n',' ').replace(',',' ').strip() for item in sh.row_values(rownum)] #print("{},{}".format(rownum,rowlist)) # get current student's info dicts dic_current=studict[removelast(rowlist[0])] csvlist[0]="1" # SN csvlist[1]=dic_current['LEARNINGCENTERCODE'][:3] #segmentcode csvlist[2]=dic_current['LEARNINGCENTERCODE'][:5] #collegecode #get info by dic if removelast(rowlist[0]) not in studict.keys(): bvalid=False print("{}:{},{}:{} no find".format(sh.name,rownum+1,rowlist[0],rowlist[9])) else: #dic = eval(infodic[1]) # get current student's info dicts csvlist[3]=dic_current['CLASSCODE'] #classcode csvlist[4]=rowlist[2].rstrip('0').rstrip('.') #examPlanCode csvlist[5]=str(rowlist[3].rstrip('0').rstrip('.')).zfill(2) #ExamCategory csvlist[6]=examunitlist[rowlist[10]] csvlist[7]=str(removelast(rowlist[1])).zfill(5) #courseid if papercodetype=='4': oldpapercode=str(removelast(rowlist[4])) # if papercode 's lenght is 3 or 4 if len(oldpapercode)<4: oldpapercode=oldpapercode.zfill(4) csvlist[8]=newPaperCode(oldpapercode) if len(oldpapercode)==4 else oldpapercode else: csvlist[8]=str(removelast(rowlist[4])).zfill(5) csvlist[9]=dic_current['LEARNINGCENTERCODE'] #learningcentercode csvlist[10]=removelast(rowlist[0]) #studentcode scorelist=() #print("{key}{val}".format(key=rowlist[5],val=getRedis(rowlist[5]))) #get score by scoredic #print (rowlist[5]) if rowlist[5]!='': csvlist[12]=score2round(rowlist[5])# PaperScoreCode csvlist[11]=scoredic[csvlist[12]] #PaperScore if rowlist[6]!='': csvlist[14]=score2round(rowlist[6]) #xkscorecode csvlist[13]=scoredic[csvlist[14]] #XKscore #xk scale valscale='0' #print (rowlist[7]) if is_number(rowlist[7]): if float(rowlist[7])<=1.0: valscale='%d'%(float(rowlist[7])*100) else: valscale='%d'%float(rowlist[7]) else : valscale=rowlist[7].rstrip('%') csvlist[15]=valscale #xkscale # composescore if rowlist[8]!='': csvlist[17]=score2round(rowlist[8]) #composescorecode csvlist[16]=scoredic[csvlist[17]] #composescore #csvlist[18] #composeDate #csvlist[19] #publistdate csvlist[20]="1" csvlist[21]="1" csvlist[22]="end" iTotal+=1 printProgress(iTotal,totalLines,prefix='Process',suffix='Complete',barLength=50) #print(iTotal) if bvalid==True: iValid+=1 wr.writerow(csvlist) print("{}:Totla{},valid{}".format(sh.name,iTotal,iValid))
currelfreq = float(countdict[word])/total maxsofar = currelfreq bestsplit = word toks = tokenize(word) for tokenization in toks[1:]: if tokenization: score = reduce(mul, [countdict[j]/float(total) for j in tokenization]) if score>maxsofar: maxsofar = score bestsplit = tokenization if maxsofar > currelfreq: wtd[word] = bestsplit for token in bestsplit: if token in wtd.keys(): del wtd[token] #sys.stdout.write("\nGoing to delete "+word);sys.stdout.flush() if not i%500: progressbar.printProgress(i,length) print "done!" sys.stdout.write("Deleting uncommons...");sys.stdout.flush() for word,split in wtd.items(): val = countdict[word] del countdict[word] for token in split: countdict[token] += val print "done!" sys.stdout.write("Saving new model...");sys.stdout.flush() with gzip.open('engmodel3.json.gz', 'wb') as f: f.write(json.dumps(countdict, f, separators=(',',':'))) print "done!"""
and arrivals.created_at <= '{time_now}' '''.format(**locals()) #TODO: recalculate high water mark based on all dependant table updates #TODO: ^rather, maybe run a cron job that sets given arrivals to updates if one # of their dependant tables is updated es_cursor = easiersolar.cursor(buffered=True) es_cursor.execute(query_sql) rows = es_cursor.fetchall() print '%d arrivals found for given timeframe' % len(rows) #for each row in easiersolar arrivals db for index, row in enumerate(rows): progressbar.printProgress(index, len(rows), prefix = 'Progress:', suffix = 'Complete', barLength = 25) _w.arrival_facts.clear_data() ##################### #get data from current easiersolar arrival row row = list(row) arrival_id_internal = row[0] arrival_id_external = row[1] _w.created_at.data = row[2] _w.updated_at.data = row[3] _w.user_agent.data = row[4] _w.ip_address.data = row[5] _w.gclid.data = row[6] if _w.gclid.data: _w.has_gclid.data = 1 else:
def main(): player_score_sums = dict.fromkeys(player_id_list) player_num_samples = dict.fromkeys(player_id_list) player_names = dict.fromkeys(player_id_list) player_status = dict.fromkeys(player_id_list) #initialize dictionaries for s in player_id_list: player_score_sums[s] = 0.0 player_num_samples[s] = 0 player_names[s] = nflgame.players[s].name player_status[s] = nflgame.players[s].status current_year, current_week = nflgame.live.current_year_and_week() years = range(current_year - 2, current_year + 1) weeks = dict.fromkeys(years) weeks[current_year] = range(1, current_week + 1) for y in years[:-1]: weeks[y] = range(1, 18) #set up probabilities for choosing a given season (more weight given to current year, scaled based on how many weeks have passed in season) p_current_year = 0.5 * float(current_week) / 17.0 p_previous_years = 1.0 - p_current_year N = 10000 #number of Monte Carlo samples for j in xrange(N): year = np.random.choice(years, p=[ 0.25 * p_previous_years, 0.75 * p_previous_years, p_current_year ]) if year == current_year: week = np.random.randint(1, current_week + 1) else: week = np.random.randint(1, 18) for p in get_games(year, week): #p is a nflgame.player.GamePlayerStats object if p.player is None: continue else: player_score_sums[p.playerid] += score_player(p) player_num_samples[p.playerid] += 1 progressbar.printProgress(j + 1, N, prefix="Monte Carlo sample {}".format(j + 1), barLength=40) score_sums = pd.DataFrame(player_score_sums.items(), columns=["playerid", "sum_scores"]) num_samples = pd.DataFrame(player_num_samples.items(), columns=["playerid", "num_samples"]) ave_player_scores = score_sums.copy() ave_player_scores['name'] = ave_player_scores['playerid'].map( player_names) #add player names to data frame ave_player_scores['num_samples'] = num_samples['num_samples'] ave_player_scores['status'] = ave_player_scores['playerid'].map( player_status) ave_player_scores.columns = [ 'playerid', 'ave score', 'name', 'num_samples', 'status' ] ave_player_scores['ave score'] /= num_samples['num_samples'] ave_player_scores = ave_player_scores[np.isfinite( ave_player_scores['ave score'])] ave_player_scores = ave_player_scores.sort_values(by='ave score', ascending=False) ave_player_scores = ave_player_scores[ave_player_scores['status'] == "ACT"] print ave_player_scores.head(n=50)
def run(self): '''this function runs the annealing protocol and creates attributes to store the data within the class''' # find the ground state of the base hamiltonian base_eigen_vals0, base_eigen_vecs0 = np.linalg.eigh( self.H(0) ) # the minus sign before the base hamiltonian is because we use H(s) = -A(s)Hb + B(s)Hp and H(0) = -Hb self.base_x0 = base_eigen_vecs0[:, base_eigen_vals0.argmin( )] + 0.j * base_eigen_vecs0[:, base_eigen_vals0.argmin()] # we need to distinguish between the ground state of the base hamiltonian and the base state of the hamiltonian at t=0 because these may be different start_eigen_vals0, start_eigen_vecs0 = np.linalg.eigh(self.H(0)) self.start_x0 = start_eigen_vecs0[:, start_eigen_vals0.argmin( )] + 0.j * start_eigen_vecs0[:, start_eigen_vals0.argmin()] # find the ground state of the problem hamiltonian d, P = np.linalg.eigh(self.Hp) self.problem_x0s = [ P[:, d == min(d)][:, i] for i in range(P[:, d == min(d)].shape[1]) ] # set the time steps dt = self.T / self.points # set up data stores for the anneal whilst setting the inital state to be th ground state on the base hamiltonian self.states = [self.base_x0] # store the vector wavestates self.instant_x0s = [] # store the instantaneous ground state self.eigenvals = [] # store the energy eigenvalues self.delta_eigenvals = [] self.problem_x0_prob = [ ] # store the probabilities of being measured in the problem base state self.instant_x0s_prob = [ ] # store the probabilities of being measured in the instantaneous base state # carry out the anneal whilst storing the state and the energy eigenvalues thoughout the process l = len(self.ss) - 1 if self.method == 'Euler': for i in range(len(self.ss)): # print loading bar but only update after each full percent has been completed if (((i + 1) * 100 % (l + 1) <= 100) or i == l) and self.show_bar: printProgress(i, l, prefix='Annealing: ', suffix='est_time', decimals=0, barLength=50, PROGRESS_IT_NUMBER=self.PITNUM) self.euler_update(dt, i) if self.light and i == self.points - 1: # calculate only the last probability of success self.problem_x0_prob.append( sum([ abs( np.dot(self.states[-1].getH(), prob_x0_pos)**2).item(0) for prob_x0_pos in self.problem_x0s ])) elif self.method == 'RK4': for i in range(len(self.ss)): # print loading bar but only update after each full percent has been completed if (((i + 1) * 100 % (l + 1) <= 100) or i == l) and self.show_bar: printProgress(i, l, prefix='Annealing: ', suffix='est_time', decimals=0, barLength=50, PROGRESS_IT_NUMBER=self.PITNUM) # update and store the data with this function if i != self.points - 1: # the Runge Kutta technique won't work on the last step since it needs to index i+1 self.rk4_update(dt, i) else: self.euler_update(dt, i) if self.light and i == self.points - 1: # calculate only the last probability of success self.problem_x0_prob.append( sum([ abs( np.dot(self.states[-1].getH(), prob_x0_pos)**2).item(0) for prob_x0_pos in self.problem_x0s ])) # set attributes to store the data self.states = self.states[1:] # self.instant_x0s = instant_x0s I have decided I don't need these stored self.eigenvals = np.asarray(self.eigenvals) self.delta_eigenvals = np.asarray(self.delta_eigenvals) self.problem_x0_prob = np.asarray(self.problem_x0_prob) self.instant_x0s_prob = np.asarray(self.instant_x0s_prob) del self.PITNUM # Don't need this anymore. It was just to see when running del self.show_bar
def expScore(csvname, xlsfile, papercodetype='4'): # get date from score***xls to create composescore #filename is format that is name such as elc90* or signup90* or score90* #deal with numeric studict = getstuinfoDic() scoredic = getscoreDic() col_score = [ '学号', '课程ID', '考试代码', '考试类别代码', '试卷号', '试卷成绩代码', '形考成绩代码', '形考比例', '综合成绩代码', '教学点代码', '考试单位类型', '考试次数' ] batlist = {"秋季": "09", "春季": "03"} examunitlist = {"中央": "1", "省": "2", "国开": "1", "省开": "2"} rnNum = [0, 1, 2, 3, 4, 5] # deal \n intnum = [11, 12, 13, 14, 15, 16, 17, 23, 24] blknum = [18, 19, 20, 21, 22] with open(csvname, 'w', newline='', encoding='gb2312') as csvfile: wr = csv.writer(csvfile, quoting=csv.QUOTE_NONE, quotechar='', escapechar='\\') wb = xlrd.open_workbook(xlsfile) tmpCol2 = "" tmpCol3 = "" tmpCol4 = "" tmpCol5 = "" for sh in wb.sheets(): if sh.nrows == 0: print("{} is empty".format(sh.name)) continue # return top to get next sheet # deal with mutilpline # from the second line #begin to process bColOrder = True rowcollist = sh.row_values( 0) #get the column's name from the first row for i in range(len(col_score)): rowcollist[i] = rowcollist[i].replace('\n', '') if rowcollist[i] not in str(col_score[i]).split(','): bColOrder = False print("sheet:{} {}'s number:{} column,{} is not match {}". format(xlsfile, sh.name, i, col_score[i], rowcollist[i])) break if bColOrder == False: # if the order of column is not current ,return to get next sheet continue lins = [x for x in range(1, sh.nrows)] iTotal = 0 iValid = 0 totalLines = len(lins) # total rows printProgress(0, totalLines, prefix='Process', suffix='Complete', barLength=50) for rownum in lins: #print("rownum:{}".format(rownum)) bvalid = True csvlist = ["" for x in range(23)] rowlist = [ str(item).replace('\n', ' ').replace(',', ' ').strip() for item in sh.row_values(rownum) ] #print("{},{}".format(rownum,rowlist)) # get current student's info dicts if removelast(rowlist[0]) not in studict.keys(): bvalid = False print("{}:{},{}:{} no find".format(sh.name, rownum + 1, rowlist[0], rowlist[9])) else: #dic = eval(infodic[1]) # get current student's info dicts dic_current = studict[removelast(rowlist[0])] csvlist[0] = "1" # SN csvlist[1] = dic_current[ 'LEARNINGCENTERCODE'][:3] #segmentcode csvlist[2] = dic_current[ 'LEARNINGCENTERCODE'][:5] #collegecode #get info by dic csvlist[3] = dic_current['CLASSCODE'] #classcode csvlist[4] = rowlist[2].rstrip('0').rstrip( '.') #examPlanCode csvlist[5] = str(rowlist[3].rstrip('0').rstrip('.')).zfill( 2) #ExamCategory csvlist[6] = examunitlist[rowlist[10]] csvlist[7] = str(removelast(rowlist[1])).zfill( 5) #courseid if papercodetype == '4': oldpapercode = str(removelast( rowlist[4])) # if papercode 's lenght is 3 or 4 if len(oldpapercode) < 4: oldpapercode = oldpapercode.zfill(4) try: csvlist[8] = newPaperCode(oldpapercode) if len( oldpapercode) == 4 else oldpapercode except (ValueError): print("papercode error: line number {}".format( rownum + 1)) pass else: csvlist[8] = str(removelast(rowlist[4])).zfill(5) csvlist[9] = dic_current[ 'LEARNINGCENTERCODE'] #learningcentercode csvlist[10] = removelast(rowlist[0]) #studentcode scorelist = () #print("{key}{val}".format(key=rowlist[5],val=getRedis(rowlist[5]))) #get score by scoredic #print (rowlist[5]) if rowlist[5] != '' and str(rowlist[5]).upper() != 'NULL': csvlist[12] = score2round(rowlist[5]) # PaperScoreCode csvlist[11] = scoredic[csvlist[12]] #PaperScore if rowlist[6] != '' and str(rowlist[6]).upper() != 'NULL': csvlist[14] = score2round(rowlist[6]) #xkscorecode try: csvlist[13] = scoredic[csvlist[14]] #XKscore except: print("score error line:{}".format(rownum + 1)) pass #xk scale valscale = '0' #print (rowlist[7]) if is_number(rowlist[7]): if float(rowlist[7]) <= 1.0: valscale = '%d' % (float(rowlist[7]) * 100) else: valscale = '%d' % float(rowlist[7]) else: valscale = rowlist[7].rstrip('%') csvlist[15] = valscale #xkscale # composescore if rowlist[8] != '' and str(rowlist[8]).upper() != 'NULL': csvlist[17] = score2round( rowlist[8]) #composescorecode try: csvlist[16] = scoredic[csvlist[17]] #composescore except: print("composescore error line:{}".format(rownum + 1)) pass #csvlist[18] #composeDate #csvlist[19] #publistdate csvlist[20] = "1" csvlist[21] = "1" csvlist[22] = "end" iTotal += 1 printProgress(iTotal, totalLines, prefix='Process', suffix='Complete', barLength=50) #print(iTotal) if bvalid == True: iValid += 1 wr.writerow(csvlist) print("{}:Totla{},valid{}".format(sh.name, iTotal, iValid))
def expScore(csvname,xlsfile): # get date from score***xls to create composescore #filename is format that is name such as elc90* or signup90* or score90* #deal with numeric col_score=['学号','课程ID','考试代码','考试类别代码','试卷号','试卷成绩代码','形考成绩代码','形考比例','综合成绩代码','教学点代码','考试单位类型','考试次数'] batlist={"秋季":"09","春季":"03"} examunitlist={"中央":"1","省":"2"} rnNum =[0,1,2,3,4,5] # deal \n intnum=[11,12,13,14,15,16,17,23,24] blknum=[18,19,20,21,22] with open(csvname,'w',newline='',encoding='gb2312') as csvfile: wr = csv.writer(csvfile,quoting=csv.QUOTE_NONE,quotechar='',escapechar='\\') wb = xlrd.open_workbook(xlsfile) tmpCol2="" tmpCol3="" tmpCol4="" tmpCol5="" for sh in wb.sheets(): if sh.nrows==0: print("{} is empty".format(sh.name)) continue # deal with mutilpline # from the second line bColOrder=True rowcollist=sh.row_values(0) for i in range(len(col_score)): rowcollist[i]=rowcollist[i].replace('\n','') if col_score[i] not in rowcollist[i]: bColOrder=False print ("sheet:{} {}'s {} is not current order".format(xlsfile,sh.name,col_score[i])) break if bColOrder==False: continue lins = [x for x in range(1,sh.nrows)] iTotal=0 iValid=0 totalLines=len(lins) printProgress(0,totalLines,prefix='Process',suffix='Complete',barLength=50) for rownum in lins: bvalid=True csvlist=["" for x in range(22)] rowlist =[str(item).replace('\n',' ').replace(',',' ').strip() for item in sh.row_values(rownum)] #print("{},{}".format(rownum,rowlist)) csvlist[0]="1" # SN csvlist[1]=rowlist[9][:3] #segmentcode csvlist[2]=rowlist[9][:5] #collegecode #get info by redis infodic=getRedis(rowlist[0]) if infodic[1]=='': bvalid=False print("{}:{},{} no find".format(sh.name,rownum,rowlist[0])) else: dic = eval(infodic[1]) csvlist[3]=dic['classcode'] #classcode csvlist[4]=rowlist[2].rstrip('0').rstrip('.') #examPlanCode csvlist[5]=rowlist[3] #ExamCategory csvlist[6]=examunitlist[rowlist[10]] csvlist[7]=removelast(rowlist[1]) #courseid csvlist[8]=newPaperCode('%d'%float(rowlist[4])) csvlist[9]=dic['learningcentercode'] #learningcentercode csvlist[10]=removelast(rowlist[0]) #studentcode scorelist=() #print("{key}{val}".format(key=rowlist[5],val=getRedis(rowlist[5]))) scorelist=getRedis(rowlist[5]) csvlist[11]=scorelist[1] #PaperScore csvlist[12]=scorelist[0] # PaperScoreCode scorelist=getRedis(rowlist[6]) csvlist[13]=scorelist[1] #XKscore csvlist[14]=scorelist[0] #xkscorecode valscale='0' #print (rowlist[7]) if is_number(rowlist[7]): if float(rowlist[7])<=1.0: valscale='%d'%(float(rowlist[7])*100) else: valscale='%d'%float(rowlist[7]) else : valscale=rowlist[7].rstrip('%') csvlist[15]=valscale #xkscale scorelist=getRedis(rowlist[8]) csvlist[16]=scorelist[1] #composescore csvlist[17]=scorelist[0] #csvlist[18] #composeDate #csvlist[19] #publistdate csvlist[20]="1" csvlist[21]="1" iTotal+=1 printProgress(iTotal,totalLines,prefix='Process',suffix='Complete',barLength=50) if bvalid==True: iValid+=1 wr.writerow(csvlist) print("{}:Totla{},valid{}".format(sh.name,iTotal,iValid))