def popular_classification(self): dataWeek = self.dataWeek dataMonth = self.dataMonth dataWeek['queryCondition']['fieldConditionGroup']['fieldConditions'] \ .append({"field": "type_", "value": "model_sobey_smart_story", "searchRelation": "and"}) dataMonth['queryCondition']['fieldConditionGroup']['fieldConditions'] \ .append({"field": "type_", "value": "model_sobey_smart_story", "searchRelation": "and"}) videoTopWeek = {} videoTopMonth = {} audioTopWeek = {} audioTopMonth = {} try: res = rest.get_entityinfo_url(dataWeek) for i in res['extensionResults'][0]['values']: if i['facetShowName'] == '分类': for i1 in i['facetValue'][:5]: videoTopWeek[i1['value']] = i1['count'] res = rest.get_entityinfo_url(dataMonth) for i in res['extensionResults'][0]['values']: if i['facetShowName'] == '分类': for i1 in i['facetValue'][:5]: videoTopMonth[i1['value']] = i1['count'] except: pass return videoTopWeek, videoTopMonth, audioTopWeek, audioTopMonth
def popular_classification(self): dataWeek = copy.deepcopy(self.dataTemplate) dataMonth = copy.deepcopy(self.dataTemplate) dataWeek['queryCondition']['fieldConditionGroup']['fieldConditions'] = \ [{ "field": "createDate_", "value": "[{0} TO {1}]".format(self.weekStart, self.weekEnd), "searchRelation": "and" }, {"field": "type_", "value": "model_sobey_smart_story", "searchRelation": "and"}] dataMonth['queryCondition']['fieldConditionGroup']['fieldConditions'] = \ [{ "field": "createDate_", "value": "[{0} TO {1}]".format(self.monthStart, self.monthEnd), "searchRelation": "and" }, {"field": "type_", "value": "model_sobey_smart_story", "searchRelation": "and"}] videoTopWeek = {} videoTopMonth = {} audioTopWeek = {} audioTopMonth = {} try: res = rest.get_entityinfo_url(dataWeek) for i in res['extensionResults'][0]['values']: if i['facetShowName'] == '分类': for i1 in i['facetValue'][:5]: videoTopWeek[i1['value']] = i1['count'] res = rest.get_entityinfo_url(dataMonth) for i in res['extensionResults'][0]['values']: if i['facetShowName'] == '分类': for i1 in i['facetValue'][:5]: videoTopMonth[i1['value']] = i1['count'] except: pass if len(videoTopWeek) > 0: videoTopWeekMax = math.ceil( videoTopWeek[max(videoTopWeek, key=videoTopWeek.get)] * 1.1) if len(videoTopMonth) > 0: videoTopMonthMax = math.ceil( videoTopMonth[max(videoTopMonth, key=videoTopMonth.get)] * 1.1) if len(audioTopWeek) > 0: audioTopWeekMax = math.ceil( audioTopWeek[max(audioTopWeek, key=audioTopWeek.get)] * 1.1) if len(audioTopMonth) > 0: audioTopMonthMax = math.ceil( audioTopMonth[max(audioTopMonth, key=audioTopMonth.get)] * 1.1) return videoTopWeek, videoTopMonth, audioTopWeek, audioTopMonth, \ videoTopWeekMax, videoTopMonthMax, audioTopWeekMax, audioTopMonthMax
def popular_person(self): hotPeopleWeek = {} hotPeopleMonth = {} try: tempDict = {} res = rest.get_entityinfo_url(self.dataWeek) for i in res['extensionResults'][0]['values']: if i['facetShowName'] == '人物': for i1 in i['facetValue']: k = i1['value'] if len(k.split("(")) > 0: k = k.split("(")[0] v = i1['count'] if k in tempDict.keys(): tempDict[k] = tempDict[k] + v else: tempDict[k] = v tempDict = sorted(tempDict.items(), key=lambda x: x[1], reverse=True) if len(tempDict) >= 10: for i in range(10): hotPeopleWeek[tempDict[i][0]] = tempDict[i][1] else: for i in range(len(tempDict)): hotPeopleWeek[tempDict[i][0]] = tempDict[i][1] tempDict = {} res = rest.get_entityinfo_url(self.dataMonth) for i in res['extensionResults'][0]['values']: if i['facetShowName'] == '人物': for i1 in i['facetValue']: k = i1['value'] if len(k.split("(")) > 0: k = k.split("(")[0] v = i1['count'] if k in tempDict.keys(): tempDict[k] = tempDict[k] + v else: tempDict[k] = v tempDict = sorted(tempDict.items(), key=lambda x: x[1], reverse=True) if len(tempDict) >= 10: for i in range(10): hotPeopleMonth[tempDict[i][0]] = tempDict[i][1] else: for i in range(len(tempDict)): hotPeopleMonth[tempDict[i][0]] = tempDict[i][1] except: pass return hotPeopleWeek, hotPeopleMonth
def start(self): resourcesNum = self.resources_num() resourceDuration = self.resource_duration() newResourcesToday = self.new_resources_today() analysisResourcesToday = self.analysis_resources_today() proofreadingResourcesToday = self.proofreading_resources_today() orgWeek, orgMonth = self.hot_organization() segmentsDurationDuration, segmentsDurationNum = self.segments_duration() keywordWeek, keywordMonth = self.key_word() locationsWeek, locationsMonth = self.locations_number() videoTopWeek, videoTopMonth, audioTopWeek, audioTopMonth = self.popular_classification() hotPeopleWeek, hotPeopleMonth = self.popular_person() saveToyear, saveTomonth, saveToweek, saveToday = self.savedata_quantity() readToyear, readTomonth, readToweek, readToday = self.readdata_quantity() res = {'resourcesNum': resourcesNum, 'resourceDuration': resourceDuration, 'newResourcesToday': newResourcesToday, 'analysisResourcesToday': analysisResourcesToday, 'proofreadingResourcesToday': proofreadingResourcesToday, 'hotOrganization': {'week': orgWeek, 'month': orgMonth}, 'segmentsDuration': {'duration': segmentsDurationDuration, 'num': segmentsDurationNum}, 'keyword': {'week': keywordWeek, 'month': keywordMonth}, 'locationsNumber': {'week': locationsWeek, 'month': locationsMonth}, 'popularClassification': {'videoTopWeek': videoTopWeek, 'videoTopMonth': videoTopMonth, 'audioTopWeek': audioTopWeek, 'audioTopMonth': audioTopMonth}, 'popularPerson': {'week': hotPeopleWeek, 'month': hotPeopleMonth}, 'savedataQuantity': {'year': saveToyear, 'month': saveTomonth, 'week': saveToweek, 'day': saveToday}, 'readdataQuantity': {'year': readToyear, 'month': readTomonth, 'week': readToweek, 'day': readToday} } print(rest.get_entityinfo_url(self.dataMonth)) print(json.dumps(res, ensure_ascii=False))
def key_word(self): keywordWeek = {} keywordMonth = {} try: res = rest.get_entityinfo_url(self.dataWeek) for i in res['extensionResults'][0]['values']: if i['facetShowName'] == '关键词': for i1 in i['facetValue'][:100]: keywordWeek[i1['value']] = i1['count'] res = rest.get_entityinfo_url(self.dataMonth) for i in res['extensionResults'][0]['values']: if i['facetShowName'] == '关键词': for i1 in i['facetValue'][:100]: keywordMonth[i1['value']] = i1['count'] except: pass return keywordWeek, keywordMonth
def hot_organization(self): orgWeek = {} orgMonth = {} try: res = rest.get_entityinfo_url(self.dataWeek) for i in res['extensionResults'][0]['values']: if i['facetShowName'] == '机构': for i1 in i['facetValue'][:5]: orgWeek[i1['value']] = i1['count'] res = rest.get_entityinfo_url(self.dataMonth) for i in res['extensionResults'][0]['values']: if i['facetShowName'] == '机构': for i1 in i['facetValue'][:5]: orgMonth[i1['value']] = i1['count'] except: pass return orgWeek, orgMonth
def locations_number(self): addressWeek = {} addressMonth = {} try: res = rest.get_entityinfo_url(self.dataWeek) for i in res['extensionResults'][0]['values']: if i['facetShowName'] == '地点': for i1 in i['facetValue'][:100]: if i1['value'] not in \ ['筛选过的地点词列表1', '筛选过的地点词列表2']: addressWeek[i1['value']] = i1['count'] res = rest.get_entityinfo_url(self.dataMonth) for i in res['extensionResults'][0]['values']: if i['facetShowName'] == '地点': for i1 in i['facetValue'][:100]: if i1['value'] not in \ ['筛选过的地点词列表1', '筛选过的地点词列表2']: addressMonth[i1['value']] = i1['count'] except: pass return addressWeek, addressMonth
def start(self): dataWeek = copy.deepcopy(self.dataTemplate) dataMonth = copy.deepcopy(self.dataTemplate) dataWeek['queryCondition']['fieldConditionGroup']['fieldConditions'] \ .append({ "field": "createDate_", "value": "[{0} TO {1}]".format(self.weekStart, self.weekEnd), "searchRelation": "and" }) dataMonth['queryCondition']['fieldConditionGroup']['fieldConditions'] \ .append({ "field": "createDate_", "value": "[{0} TO {1}]".format(self.monthStart, self.monthEnd), "searchRelation": "and" }) weekRes = rest.get_entityinfo_url(dataWeek) monthRes = rest.get_entityinfo_url(dataMonth) resourcesNum = self.resources_num() resourceDuration = self.resource_duration() newResourcesToday = self.new_resources_today() analysisResourcesToday = self.analysis_resources_today() proofreadingResourcesToday = self.proofreading_resources_today() segmentsDurationDuration, segmentsDurationNum, durationMax, numMax = self.segments_duration( ) orgWeek, orgMonth = self.hot_organization(weekRes, monthRes) keywordWeek, keywordMonth = self.key_word(weekRes, monthRes) # 取地区值(no) locationsWeek, locationsMonth = self.locations_number( weekRes, monthRes) # 返回最大刻度值 videoTopWeek, videoTopMonth, audioTopWeek, audioTopMonth, \ videoTopWeekMax, videoTopMonthMax, audioTopWeekMax, audioTopMonthMax = self.popular_classification() hotPeopleWeek, hotPeopleMonth = self.popular_person(weekRes, monthRes) # 返回最大刻度值 saveToyear, saveTomonth, saveToweek, saveToday, \ stoyearMax, stomonthMax, stoweekMax, stodayMax = self.savedata_quantity() # 返回最大刻度值 readToyear, readTomonth, readToweek, readToday, \ rtoyearMax, rtomonthMax, rtoweekMax, rtodayMax = self.readdata_quantity() res = { 'resourcesNum': resourcesNum, 'resourceDuration': resourceDuration, 'newResourcesToday': newResourcesToday, 'analysisResourcesToday': analysisResourcesToday, 'proofreadingResourcesToday': proofreadingResourcesToday, 'hotOrganization': { 'week': orgWeek, 'month': orgMonth }, 'segmentsDuration': { 'duration': segmentsDurationDuration, 'num': segmentsDurationNum, 'durationMax': durationMax, 'num': numMax }, 'keyword': { 'week': keywordWeek, 'month': keywordMonth }, 'locationsNumber': { 'week': locationsWeek, 'month': locationsMonth }, 'popularClassification': { 'videoTopWeek': videoTopWeek, 'videoTopMonth': videoTopMonth, 'videoTopWeekMax': videoTopWeekMax, 'videoTopWeekMax': videoTopMonthMax, 'audioTopWeek': audioTopWeek, 'audioTopMonth': audioTopMonth, 'videoTopWeek': audioTopWeekMax, 'videoTopMonth': audioTopMonthMax }, 'popularPerson': { 'week': hotPeopleWeek, 'month': hotPeopleMonth }, 'savedataQuantity': { 'year': saveToyear, 'month': saveTomonth, 'week': saveToweek, 'day': saveToday, 'yearMax': stoyearMax, 'monthMax': stomonthMax, 'weekMax': stoweekMax, 'dayMax': stodayMax }, 'readdataQuantity': { 'year': readToyear, 'month': readTomonth, 'week': readToweek, 'day': readToday, 'yearMax': rtoyearMax, 'monthMax': rtomonthMax, 'weekMax': rtoweekMax, 'dayMax': rtodayMax } } print(rest.get_entityinfo_url(dataMonth)) print(json.dumps(res, ensure_ascii=False))