def addMaxNum(dict, actid, listennum): logging.debug('add max num ,the dict is %s', dict) actid = str(actid) if dict.has_key(actid): if listennum > dict[actid]: dict[actid] = listennum else: dict[actid] = listennum
def getMaxScore(dict): max = 0 if len(dict.values()) > 0: for v in dict.values(): if v > max: max = v logging.debug('the max is %s', max) else: continue logging.debug('end ,the max is %s', max) return max
def getVirtualNum(songinfo, startsong, endsong): #songinfo.order_no = startsong.order_no + 1 #if startsong.visible_rank_score > endsong.visible_rank_score + 0.01: f = (startsong.visible_rank_score - 0.01) == endsong.visible_rank_score or (startsong.visible_rank_score == endsong.visible_rank_score) logging.debug( 'get the virtual score and num ,the songinfo is [%s],the startsong info is [%s] ,the endsong info is [%s],the com res is [%s]', songinfo, startsong, endsong, f) #正常情况下,分数-0.01 #if f: #if (startsong.visible_rank_score - 0.01) == endsong.visible_rank_score or (startsong.visible_rank_score == endsong.visible_rank_score): # logging.debug('the visible_rank_score of the start song [%s] and the end song[%s] is same ',startsong,endsong) # songinfo.visible_rank_score = startsong.visible_rank_score #else: songinfo.visible_rank_score = startsong.visible_rank_score songinfo.visible_vote_num = startsong.visible_vote_num songinfo.visible_listen_num = startsong.visible_listen_num songinfo.visible_thumb_num = startsong.visible_thumb_num #if startsong.visible_listen_score != 0: songinfo.visible_listen_score = startsong.visible_listen_score songinfo.visible_collect_score = startsong.visible_collect_score songinfo.visible_vote_score = startsong.visible_vote_score #elif startsong.visible_listen_score == 0 and startsong.visible_collect_score != 0: # songinfo.visible_listen_score = startsong.visible_listen_score # songinfo.visible_collect_score = startsong.visible_collect_score - 0.01 # songinfo.visible_vote_score = startsong.visible_vote_score #elif startsong.visible_collect_score == 0 and startsong.visible_vote_score != 0: # songinfo.visible_listen_score = startsong.visible_listen_score # songinfo.visible_collect_score = startsong.visible_collect_score # songinfo.visible_vote_score = startsong.visible_vote_score - 0.01 #else: # if (startsong.visible_vote_num + 1) < endsong.visible_vote_num : # songinfo.visible_rank_score = startsong.visible_rank_score # songinfo.visible_vote_num = startsong.visible_vote_num - 1 # songinfo.visible_listen_num = startsong.visible_listen_num # songinfo.visible_thumb_num = startsong.visible_thumb_num # #投票量相同的情况下,点赞数+1 # songinfo.visible_vote_num = startsong.visible_vote_num # songinfo.visible_listen_num = startsong.visible_listen_num + 1 # songinfo.visible_thumb_num = startsong.visible_listen_num # #elif (startsong.visible_thumb_num +1 ) >= endsong.visible_thumb_num and (startsong.visible_listen_num +1 ) < endsong.visible_listen_num: # songinfo.visible_vote_num = startsong.visible_vote_num # songinfo.visible_listen_num = startsong.visible_listen_num # songinfo.visible_thumb_num = startsong.visible_listen_num + 1 return songinfo
def calcNumScore(db, actid, num, type, songid=0): logging.debug('calcScore ,the actid is %s ,num is %s ', actid, num) base = getRatio(db, actid, type) if base == 0: return 0 res = 0 if int(num) == 0: res = 0 else: res = num * base #res = '{:.2f}'.format(Decimal(r)) logging.info( 'begin to calc score,type is %s , base is %s ,the songid is %s , the current num is %s,and the score is %s', type, base, songid, num, res) return res
def calcScore(db, actid, maxnum, num, type, songid=0): logging.debug('calcScore ,the actid is %s ,the maxnum is %s ,num is %s ', actid, maxnum, num) base = getRatio(db, actid, type) if base == 0: return 0 res = 0 if (maxnum) == 0 or int(num) == 0: res = 0 elif int(maxnum) == int(num): res = base else: r = math.log(float(num)) / math.log(float(maxnum)) * base res = '{:.2f}'.format(Decimal(r)) logging.info( 'begin to calc score,type is %s , base is %s ,the songid is %s ,the maxnum is %s,and the current num is %s,and the score is %s', type, base, songid, maxnum, num, res) return res
def processPromotionSong(db, resdict, prodict): actLimitDict = db.getActLimitSong() logging.info('the actLimitDict is %s ', actLimitDict) logging.info('the promotion dict info is %s', prodict) for k, v in resdict.items(): #该活动下面有手工调整的晋`升人员 if prodict.has_key(k) and len( prodict[k]) > 0 and actLimitDict.has_key(k): logging.debug('----------k is %s-----actLimitDict %s', k, actLimitDict) #该活动下的歌曲数需要大于设置的晋级总数 proNum = len(prodict[k]) #该活动下面人工设置的需要晋级的人数 limitNum = actLimitDict[k] #该活动下可以晋级的总歌曲数 logging.info( 'the actid is %s,the promotion num is %s ,the limitnum is %s,the promotion songids is %s', k, proNum, limitNum, prodict[k]) #if proNum > actLimitDict[k]: dict = {} for r in v: dict[str(r.songid)] = r #startnum = limitNum - proNum #songlist = calcVirtualScore(startnum,startnum+1,v,prodict[k]) resdict[k] = calcVirOrderNo(v, dict, limitNum, proNum, prodict[k]) #debug for s in resdict[k]: if s.songid == 10176: logging.debug('------debug info------%s------', s) #else: #logging.info('the activity (actid:%s), the promotion song num is %s,greater than the song num(%s)',proNum,actLimitDict[k],len(v)) else: logging.info( 'the activity[actid:%s] has no promotion song or the match_no of the activity is not match ', k) return resdict
songids = getSongids(content) #logging.debug('---songids----%s--',songids) taskids.append(taskid) if tasktype == 0: if addDict.has_key(actid): addDict[actid].extend(songids) else: addDict[actid] = songids elif tasktype == 1: if delDict.has_key(actid): delDict[actid].extend(songids) else: delDict[actid] = songids logging.debug('---re calc default list ,the addDict is %s', addDict) logging.debug('---re calc default list ,the delDict is %s', delDict) redis = redislib.RedisTools() pipe = redis.getPipeLine() for actid, songids in addDict.items(): songids = list(set(songids)) size = redis.hget('default_' + str(actid), 'size') logging.debug('the size is %s', size) index = random.randint(0, int(size)) logging.debug('the random is %s ', index) for num in range(1, 1001): #logging.info('begin to insert data to redis ,the key is %s','default_'+str(actid)+'_'+str(num)) key = redis.lindex('default_' + str(actid) + '_' + str(num), index) #logging.debug('the refvalue of the redis (key:%s) is %s','default_'+str(actid)+'_'+str(num),key) for sid in songids: pipe.linsert('default_' + str(actid) + '_' + str(num),
def calcVirOrderNo(songinfoarray, songinfos, limitNum, proNum, prosongids): if len(songinfoarray) < limitNum: return songinfoarray #for s in songinfos.values(): # if s.songid == 10165: # logging.debug('the ori songinfo array is %s',s) newOrderNo = [] hasPromotion = {} startIndex = limitNum - proNum + 1 logging.info( 'the limitNum is %s,the pronum is %s,the promotion songids is %s', limitNum, proNum, prosongids) prosongidsbak = [] for p in prosongids: logging.info('the promotion song (%s) info is %s', p, songinfos[p]) if songinfos[p].order_no <= limitNum: #如果该歌曲的排名已经晋级,将不再处理,将其从待晋级的歌曲列表中移除 if songinfos[p].order_no <= limitNum - proNum + 1: hasPromotion[songinfos[p].songid] = songinfos[p].order_no startIndex = startIndex + 1 logging.info( 'the song[songid:%s,real orderno:%s] has promotioned ,remove id from promotion list,startIndex ++ ', songinfos[p], songinfos[p].order_no) elif songinfos[p].order_no > limitNum - proNum + 1: logging.info( 'the song[songid:%s,real orderno:%s] need to deal by head,startIndex--', songinfos[p], songinfos[p].order_no) prosongidsbak.append(p) #startIndex = startIndex - 1 else: prosongidsbak.append(p) logging.debug('the promotion song len is %s,and the songinfo is %s', len(prosongidsbak), prosongidsbak) logging.debug( 'hasPromotion songid length is %s, and the ids is ------%s---', len(hasPromotion), hasPromotion) startIndex = startIndex - 2 if startIndex < 0: startIndex = 0 startsong = songinfoarray[startIndex] logging.debug('the startIndex is %s,the start song is %s', startIndex, startsong) for songid in prosongidsbak: songinfos[songid].visible_rank_score = startsong.visible_rank_score songinfos[songid].visible_vote_num = startsong.visible_vote_num songinfos[songid].visible_listen_num = startsong.visible_listen_num songinfos[songid].visible_thumb_num = startsong.visible_thumb_num songinfos[songid].visible_listen_score = startsong.visible_listen_score songinfos[ songid].visible_collect_score = startsong.visible_collect_score songinfos[songid].visible_vote_score = startsong.visible_vote_score songinfos[songid].visible_score_1 = startsong.visible_score_1 songinfos[songid].visible_score_2 = startsong.visible_score_2 songinfos[songid].visible_score_3 = startsong.visible_score_3 songinfos[songid].visible_score_4 = startsong.visible_score_4 songinfos[songid].visible_score_5 = startsong.visible_score_5 songinfos[songid].visible_score_6 = startsong.visible_score_6 songinfoarray = songinfos.values() songinfoarray.sort(cmp=sortByVirNum) for num in range(startIndex, limitNum + 1): newOrderNo.append(num) #生成新的排名 logging.debug('========newOrderNo=start %s===', newOrderNo) newOrderNo = list(set(newOrderNo).difference(set(hasPromotion.values()))) newOrderNo.sort() logging.debug('=========newOrderNo end =====%s===', newOrderNo) #newOrderNo.sort() #startsong = songinfoarray[newOrderNo[0] - 2] #endsong = songinfoarray[newOrderNo[0] - 1 ] i = 0 #改了算法,这个段代码用不着了,先留着。 #songinfoarray.sort(cmp = sortByVirNum) #songinfoarray = calcOrderNo(songinfoarray) ##for song in songinfoarray: ## logging.debug('-------test song %s--------------',song) #for songid in prosongidsbak: # order_no = newOrderNo[i] # startsong = songinfoarray[order_no-2] # endsong = songinfoarray[order_no-1] # logging.debug('order_no is %s --old song - [%s] ----startsong--[%s] endsong -- [%s]-' ,order_no,songinfos[songid],startsong ,endsong) # newsong = getVirtualNum(songinfos[songid],startsong,endsong) # #songinfoarray[index+1] = newsong # songinfos[songid] = newsong # logging.debug('----new song %s-------- ',songinfos[songid]) # songinfoarray = songinfos.values() # songinfoarray.sort(cmp = sortByVirNum) # songinfoarray = calcOrderNo(songinfoarray) # for song in songinfoarray: # logging.debug('-------test pro songid %s-------songinfo-----%s--',songid,song) # i = i+1 return songinfoarray
dict = {} hu = HttpUtils.HttpUtils() for k, listennum in listendict.items(): r = k.split(",") topicid = r[0] activityid = r[1] songid = r[2] #将解析后的数据放到dict里,用于下面的合并操作 tmpdict = {} tmpdict['listenNum'] = listennum dict[topicid + ',' + activityid + ',' + songid] = tmpdict logging.debug('parse log finish ,the res is %s----------', dict) #定义一个resdict,key为活动id,value为该活动合并后的数组 resdict = {} maxListenNumDict = {} maxVoteNumDict = {} maxCollectNumDict = {} maxQuantity_1_Dict = {} maxQuantity_2_Dict = {} maxQuantity_3_Dict = {} maxQuantity_4_Dict = {} maxQuantity_5_Dict = {} maxQuantity_6_Dict = {} actsongs = db.getActSongInfo() for k, matchsong in actsongs.items(): logging.debug( 'the activity (actid :%s) songinfos (select from db) is %s', k,
def calcVirOrderNo(songinfoarray, songinfos, limitNum, proNum, prosongids): if len(songinfoarray) < limitNum: return songinfoarray #for s in songinfos.values(): # if s.songid == 10165: # logging.debug('the ori songinfo array is %s',s) newOrderNo = [] hasPromotion = {} startIndex = limitNum - proNum + 1 logging.info( 'the limitNum is %s,the pronum is %s,the promotion songids is %s', limitNum, proNum, prosongids) prosongidsbak = [] for p in prosongids: logging.info('the promotion song (%s) info is %s', p, songinfos[p]) if songinfos[p].order_no <= limitNum: hasPromotion[songinfos[p].songid] = songinfos[p].order_no #如果该歌曲的排名已经晋级,将不再处理,将其从待晋级的歌曲列表中移除 if songinfos[p].order_no < (limitNum - proNum + 1): startIndex = startIndex + 1 logging.info( 'the song[songid:%s,real orderno:%s] has promotioned ,remove id from promotion list', songinfos[p], songinfos[p].order_no) elif songinfos[p].order_no >= (limitNum - proNum + 1): prosongidsbak.append(p) startIndex = startIndex - 1 else: prosongidsbak.append(p) logging.debug('--prosongidsbak-----%s---', prosongidsbak) logging.debug('-----hasPromotion------%s---', hasPromotion) #if len(hasPromotion) == 0: # return songinfos.values() #else: for num in range(startIndex, limitNum + 1): newOrderNo.append(num) #生成新的排名 logging.debug('========newOrderNo=start %s===', newOrderNo) newOrderNo = list(set(newOrderNo).difference(set(hasPromotion.values()))) newOrderNo.sort() logging.debug('=========newOrderNo end =====%s===', newOrderNo) #newOrderNo.sort() #startsong = songinfoarray[newOrderNo[0] - 2] #endsong = songinfoarray[newOrderNo[0] - 1 ] i = 0 songinfoarray.sort(cmp=sortByVirNum) songinfoarray = calcOrderNo(songinfoarray) for song in songinfoarray: logging.debug('-------test song %s--------------', song) for songid in prosongidsbak: order_no = newOrderNo[i] startsong = songinfoarray[order_no - 2] endsong = songinfoarray[order_no - 1] logging.debug( 'order_no is %s --old song - [%s] ----startsong--[%s] endsong -- [%s]-', order_no, songinfos[songid], startsong, endsong) newsong = getVirtualNum(songinfos[songid], startsong, endsong) #songinfoarray[index+1] = newsong songinfos[songid] = newsong logging.debug('----new song %s-------- ', songinfos[songid]) songinfoarray = songinfos.values() songinfoarray.sort(cmp=sortByVirNum) songinfoarray = calcOrderNo(songinfoarray) for song in songinfoarray: logging.debug('-------test pro songid %s-------songinfo-----%s--', songid, song) i = i + 1 for s in songinfos.values(): if s.songid == 10165: logging.debug('the end songinfo array is %s', s) return songinfoarray