Exemple #1
0
 def __init__(self,
              min_question_num=100,
              min_weight=0.1,
              update=False,
              from_db=True,
              from_api=True,
              from_cache=True,
              related_cache=False,
              save_db=True):
     self.min_question_num = min_question_num
     self.tag_clf = CoreTagClfCache.get()
     self.core_tag_index = dict([(tag, c) for c in self.tag_clf
                                 for tag in self.tag_clf[c]])
     self.tag_questions = QuestionsCDN.get_tag_questions_cached()
     self.from_db = from_db
     self.from_api = from_api
     self.from_cache = from_cache
     self.update = update
     self.min_weight = min_weight
     self.related_cache = related_cache
     self.save_db = save_db
Exemple #2
0
def save_to_db():
    # QuestionsCDN.load_to_cache()
    QuestionsCDN.save_to_db()


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='cache tools')
    parser.add_argument('command')
    args = parser.parse_args()
    if args.command == 'save':
        save()
    elif args.command == 'save_to_db':
        save_to_db()
    elif args.command == 'tags_have_question':
        tag_questions = QuestionsCDN.get_tag_questions_cached()
        n0 = 0
        n50 = 0
        n100 = 0
        for tag in tag_questions:
            if len(tag_questions[tag]) > 0:
                n0 += 1
            if len(tag_questions[tag]) >= 50:
                n50 += 1
            if len(tag_questions[tag]) >= 100:
                n100 += 1
        print(f'more than 100 questions: {n100}')
        print(f'more than 50 questions: {n50}')
        print(f'more than 0 questions: {n0}')
    elif args.command == 'tag_related':
        tag_related = TagRelatedCDN.get_related_weight_all()