示例#1
0
def wordcloud(request):
    sex = request.GET.get('sex',"")
    time = request.GET.get('time',"")
    province = request.GET.get('province',"")
    kind = request.GET.get('kind',"")
    month = request.GET.get('month',"")
    result = models.cal_pmi(kind,sex,time,province,month)

    logging.info("request info sex:%s time:%s province:%s kind:%s "%(sex,time,province,kind))


    list = {"weight":[],"color":{}}

    for index,line in enumerate(result):
        if index == 30:
            break
        list["weight"].append([line[0],35-index])
        list["color"][line[0]] = int(line[2])
        # logging.info("word:{0} frequence:{1} pmi:{2}".format(line[0],line[2],line[3]))


    sort_color = sorted(list["color"].items(),key=lambda a:a[1],reverse=False)
    for index,(key,value) in enumerate(sort_color):
        list["color"][key] = get_color(0,len(sort_color)-1,index)

    logging.info("wordcloud done!")
    return HttpResponse(json.dumps(list))
示例#2
0
def wordcloud(request):
    sex = request.GET.get('sex',"")
    time = request.GET.get('time',"")
    province = request.GET.get('province',"")
    kind = request.GET.get('kind',"")
    month = request.GET.get('month',"")
    #__________DICT_____________
    is_select_dict = True if request.GET.get('dict' , 'False') == "true" else False
    logging.info("start to cal pmi info sex:%s time:%s province:%s kind:%s is_select_dict:%s"%(sex,time,province,kind,str(is_select_dict)))
    result = models.cal_pmi(kind,sex,time,province,is_select_dict)

    logging.info("request info sex:%s time:%s province:%s kind:%s "%(sex,time,province,kind))


    list = {"weight":[],"color":{}}

    for index,line in enumerate(result):
        if index == 30:
            break
        list["weight"].append([line[0],35-index]) #read commit : let the PMI order decide the WEIGHT(SIZE)
        list["color"][line[0]] = int(line[2]) # read commit : let the "food_count" decide the COLOR
        # logging.info("word:{0} frequence:{1} pmi:{2}".format(line[0],line[2],line[3]))


    sort_color = sorted(list["color"].items(),key=lambda a:a[1],reverse=False) # ASC sorted
    for index,(key,value) in enumerate(sort_color):
        list["color"][key] = get_color(0,len(sort_color)-1,index)

    logging.info("wordcloud done!")
    return HttpResponse(json.dumps(list))
示例#3
0
def gen_cache_dict(request):
    print "begin to gen dict  cache"
    logging.info("begin to gen dict cache")

    count = 0
    kinds = ["fruit", "food", "drink", "wine", "tea", "all"]
    sexs = ["man", "woman", ""]
    times = ["morning", "noon", "afternoon", "evening", ""]
    provinces = [
        "北京".decode('utf-8'), "浙江".decode('utf-8'), "天津".decode('utf-8'),
        "安徽".decode('utf-8'), "上海".decode('utf-8'), "福建".decode('utf-8'),
        "重庆".decode('utf-8'), "江西".decode('utf-8'), "山东".decode('utf-8'),
        "河南".decode('utf-8'), "湖北".decode('utf-8'), "湖南".decode('utf-8'),
        "广东".decode('utf-8'), "海南".decode('utf-8'), "山西".decode('utf-8'),
        "青海".decode('utf-8'), "江苏".decode('utf-8'), "辽宁".decode('utf-8'),
        "吉林".decode('utf-8'), "台湾".decode('utf-8'), "河北".decode('utf-8'),
        "贵州".decode('utf-8'), "四川".decode('utf-8'), "云南".decode('utf-8'),
        "陕西".decode('utf-8'), "甘肃".decode('utf-8'), "黑龙江".decode('utf-8'),
        "香港".decode('utf-8'), "澳门".decode('utf-8'), "广西".decode('utf-8'),
        "宁夏".decode('utf-8'), "新疆".decode('utf-8'), "内蒙古".decode('utf-8'),
        "西藏".decode('utf-8'), ""
    ]
    for province in provinces:
        for sex in sexs:
            for time in times:
                for kind in kinds:
                    result = models.cal_pmi(kind, sex, time, province, True)
                    print "add cache sex:%s time:%s province:%s kind:%s " % (
                        sex, time, province, kind)
                    logging.info(
                        "add cache sex:%s time:%s province:%s kind:%s " %
                        (sex, time, province, kind))
    logging.info("gen cache end")
    print("%s:gen cache end")
示例#4
0
文件: views.py 项目: brenir/django
def wordcloud(request):
    sex = request.GET.get('sex', "")
    time = request.GET.get('time', "")
    province = request.GET.get('province', "")
    kind = request.GET.get('kind', "")
    month = request.GET.get('month', "")
    result = models.cal_pmi(kind, sex, time, province, month)

    logging.info("request info sex:%s time:%s province:%s kind:%s " %
                 (sex, time, province, kind))

    list = {"weight": [], "color": {}}

    for index, line in enumerate(result):
        if index == 30:
            break
        list["weight"].append([line[0], 35 - index])
        list["color"][line[0]] = int(line[2])
        # logging.info("word:{0} frequence:{1} pmi:{2}".format(line[0],line[2],line[3]))

    sort_color = sorted(list["color"].items(),
                        key=lambda a: a[1],
                        reverse=False)
    for index, (key, value) in enumerate(sort_color):
        list["color"][key] = get_color(0, len(sort_color) - 1, index)

    logging.info("wordcloud done!")
    return HttpResponse(json.dumps(list))
示例#5
0
def gen_cache_dict(request):
    print "begin to gen dict  cache"
    logging.info("begin to gen dict cache")

    count = 0
    kinds = ["fruit","food","drink","wine","tea","all"]
    sexs = ["man","woman",""]
    times = ["morning","noon","afternoon","evening",""]
    provinces = [
                    "北京".decode('utf-8'),
                    "浙江".decode('utf-8'),
                    "天津".decode('utf-8'),
                    "安徽".decode('utf-8'),
                    "上海".decode('utf-8'),
                    "福建".decode('utf-8'),
                    "重庆".decode('utf-8'),
                    "江西".decode('utf-8'),
                    "山东".decode('utf-8'),
                    "河南".decode('utf-8'),
                    "湖北".decode('utf-8'),
                    "湖南".decode('utf-8'),
                    "广东".decode('utf-8'),
                    "海南".decode('utf-8'),
                    "山西".decode('utf-8'),
                    "青海".decode('utf-8'),
                    "江苏".decode('utf-8'),
                    "辽宁".decode('utf-8'),
                    "吉林".decode('utf-8'),
                    "台湾".decode('utf-8'),
                    "河北".decode('utf-8'),
                    "贵州".decode('utf-8'),
                    "四川".decode('utf-8'),
                    "云南".decode('utf-8'),
                    "陕西".decode('utf-8'),
                    "甘肃".decode('utf-8'),
                    "黑龙江".decode('utf-8'),
                    "香港".decode('utf-8'),
                    "澳门".decode('utf-8'),
                    "广西".decode('utf-8'),
                    "宁夏".decode('utf-8'),
                    "新疆".decode('utf-8'),
                    "内蒙古".decode('utf-8'),
                    "西藏".decode('utf-8'),
                    ""
                    ]
    for province in provinces:
        for sex in sexs:
            for time in times:
                for kind in kinds:
                    result = models.cal_pmi(kind,sex,time,province,True)
                    print "add cache sex:%s time:%s province:%s kind:%s "%(sex,time,province,kind)
                    logging.info("add cache sex:%s time:%s province:%s kind:%s "%(sex,time,province,kind))
    logging.info("gen cache end")
    print ("%s:gen cache end")
示例#6
0
def wordcloud(request):
    sex = request.GET.get('sex', "")
    time = request.GET.get('time', "")
    province = request.GET.get('province', "")
    kind = request.GET.get('kind', "")
    month = request.GET.get('month', "")
    #__________DICT_____________
    is_select_dict = True if request.GET.get('dict',
                                             'False') == "true" else False
    logging.info(
        "start to cal pmi info sex:%s time:%s province:%s kind:%s is_select_dict:%s"
        % (sex, time, province, kind, str(is_select_dict)))
    result = models.cal_pmi(kind, sex, time, province, is_select_dict)

    logging.info("request info sex:%s time:%s province:%s kind:%s " %
                 (sex, time, province, kind))

    list = {"weight": [], "color": {}}

    for index, line in enumerate(result):
        if index == 30:
            break
        list["weight"].append([
            line[0], 35 - index
        ])  #read commit : let the PMI order decide the WEIGHT(SIZE)
        list["color"][line[0]] = int(
            line[2])  # read commit : let the "food_count" decide the COLOR
        # logging.info("word:{0} frequence:{1} pmi:{2}".format(line[0],line[2],line[3]))

    sort_color = sorted(list["color"].items(),
                        key=lambda a: a[1],
                        reverse=False)  # ASC sorted
    for index, (key, value) in enumerate(sort_color):
        list["color"][key] = get_color(0, len(sort_color) - 1, index)

    logging.info("wordcloud done!")
    return HttpResponse(json.dumps(list))