Ejemplo n.º 1
0
import time
import json
from common.log import LogAdapter
from common.settings import SIGMA, WRC_FLAG
from common.algorithms import FPSScore
from storage.utils import *
from common.settings import PROJECT_NAME
from storage.sql import ONE_MONTH,HALF_YEAR,THREE_MONTH, ONE_YEAR
from multiprocessing import Pool
import datetime


LOG = LogAdapter().set_log('FpsScore')


class CountFps(object):
    def __init__(self):
        self.fp = FPSScore()

    def count_score(self, Rn, Rp_file_name, m):
        if WRC_FLAG:
            score = self.fp.score2(Rn,Rp_file_name,m)
        else:
            score = self.fp.score(Rn,Rp_file_name,m)

        return score

    def main(self,Rn, Rps, Rp_viewers_all, k):
        """

        :param Rn: new review request
Ejemplo n.º 2
0
import numpy as np
from common.utils import get_file_score, split_file_length
from common.log import LogAdapter
import math

LOG = LogAdapter().set_log('Algorithms')


class FPSScore(object):
    def score(self, review_new, review_past, m, sigma=1):
        """

        :param review_new:
        :param review_past:
        :param m:
        :param sigma: time prioritization
        :return:
        """
        try:

            file_count = len(review_new) * len(review_past)
            similarity_score = self.similarity_score(review_new, review_past)
            score = similarity_score / file_count
            prioritization_score = score * pow(sigma, m)
            return prioritization_score
        except Exception as e:
            LOG.error('Failed count score cause {}'.format(e), exc_info=True)

    def similarity_score(self, review_new, review_past):
        t_s_score = []
        try:
Ejemplo n.º 3
0
import datetime
import os
import numpy
import json
import time
import networkx as nx
from common.log import LogAdapter
from multiprocessing import Pool
from core.fps_score import CountFps

from storage.sql import ONE_MONTH, HALF_YEAR, THREE_MONTH, ONE_YEAR

from common.settings import PROJECT_NAME

LOG_NAME = 'CommentNetwork'
LOG = LogAdapter().set_log(LOG_NAME)

EMPIRICAL_VALUE = 1.0
DECAY_FACTOR = 0.6

parent_dir = os.path.abspath(os.pardir)
save_path = os.path.join(parent_dir, 'result', 'IR_FPS')
print(save_path)
if not os.path.exists(save_path):
    os.mkdir(save_path)


class CosineSimilarity(object):
    def __init__(self, project_name):
        self.project_name = project_name
        self.comments = get_comments_count(self.project_name)
Ejemplo n.º 4
0
import csv
from nltk.tokenize import RegexpTokenizer
from nltk.corpus import stopwords
from itertools import chain
from collections import defaultdict
from functools import wraps
from contextlib import ExitStack
from common.log import LogAdapter
LOG = LogAdapter().set_log('CommonUtils')


def split_file_length(file_name):
    if '\\' in file_name:
        file_length = file_name.split("\\")
        return file_length
    else:
        file_length = file_name.split("/")
        if '' in file_length:
            file_length.remove('')
        return file_length


def get_file_score(new_file, past_file):
    """
    return the number of directory/file name that
    appear from the beginning of both filepath
    :param new_file: new review file
    :param past_file: past review file
    :return: the number of directory /file the same
    """