Esempio n. 1
0
    def getResult(messages):
        n = 0
        sum = 0.0
        maxRelevance = 0
        minElapsedTime = datetime.timedelta.max
        actualDate = datetime.datetime.utcnow()
        actualDate = actualDate.replace(tzinfo=pytz.utc)

        for message in messages:
            publishedDate = SocialDate.getPublishedDate(message)
            elapsedTime = actualDate - publishedDate
            if elapsedTime < minElapsedTime:
                minElapsedTime = elapsedTime

        messages.rewind()

        for message in messages:
            n += 1
            relevance = Relevance.getRelevance(message)

            if relevance > maxRelevance:
                maxRelevance = relevance

            sentiment = Sentiment.getSentiment(message)
            publishedDate = SocialDate.getPublishedDate(message)
            elapsedTime = actualDate - publishedDate
            sum += relevance * sentiment / (1 + elapsedTime.total_seconds() - minElapsedTime.total_seconds())

        result = sum / (maxRelevance * n)
        return result
Esempio n. 2
0
    def getResult(messages):
        n = 0
        sum = 0.0
        maxRelevance = 0
        minElapsedTime = datetime.timedelta.max
        maxElapsedTime = datetime.timedelta.min
        actualDate = datetime.datetime.utcnow()
        actualDate = actualDate.replace(tzinfo=pytz.utc)

        for message in messages:
            publishedDate = SocialDate.getPublishedDate(message)
            elapsedTime = actualDate - publishedDate
            relevance = Relevance.getRelevance(message)
            if relevance > maxRelevance:
                maxRelevance = relevance
            if elapsedTime < minElapsedTime:
                minElapsedTime = elapsedTime
            if elapsedTime > maxElapsedTime:
                maxElapsedTime = elapsedTime

        messages.rewind()

        for message in messages:
            n += 1
            relevance = Relevance.getRelevance(message)
            sentiment = Sentiment.getSentiment(message)
            publishedDate = SocialDate.getPublishedDate(message)
            elapsedTime = actualDate - publishedDate

            normalizedTime = (elapsedTime.total_seconds() - minElapsedTime.total_seconds()) / (maxElapsedTime.total_seconds() - minElapsedTime.total_seconds())
            normalizedRelevance = float(relevance)/maxRelevance
            sum += sentiment * normalizedRelevance / (1+normalizedTime)

        result = sum / n
        return result
Esempio n. 3
0
 def getResult(messages):
     sum = 0.0
     for message in messages:
         relevance = Relevance.getRelevance(message)
         sentiment = Sentiment.getSentiment(message)
         publishedDate = SocialDate.getPublishedDate(message)
         actualDate = datetime.datetime.utcnow()
         actualDate = actualDate.replace(tzinfo=pytz.utc)
         elapsedTime = actualDate - publishedDate
         sum += relevance * sentiment / elapsedTime.total_seconds()
     return sum