def calc_frequency(areaNum, word_counts, curr_timeslot_word_counts):
timeslot_area_percentage = {}
for i in word_counts:
for j in curr_timeslot_word_counts:
#on same word (key) calculate actual percent
if i == j:
timeslot_area_percentage[i] = (word_counts[i]/(curr_timeslot_word_counts[j] + 0.00)) * 100
timeslot_area_percentage[i] = round(timeslot_area_percentage[i], 2)
return timeslot_area_percentage
# if areaNum == 1:
# return {"area1" : timeslot_area_percentage} # TODO: convert to django friendly using below??
# elif areaNum == 2:
# return {"area2" : timeslot_area_percentage}
# elif areaNum == 3:
# return {"area3" : timeslot_area_percentage}
#convert site percents to django friendly JSON
# site1_percentage_json = json.dumps(dict(site1_percentage), cls=DjangoJSONEncoder)
# site2_percentage_json = json.dumps(dict(site2_percentage), cls=DjangoJSONEncoder)
# takes a url as a string and returns a SET of TUPLES of all of the words
# that are used on that webpage in order of frequency
评论列表
文章目录