Example #1
0
 def test_telegram_text_message_show_favorites_for_old_user(
         self, session, clear_data):
     # Fulfilling the database for future making answer - film tomorrow
     start_time = datetime.datetime.utcnow().timestamp() + 86200
     finish_time = datetime.datetime.utcnow().timestamp() + 86300
     event = self.create_event_yandexafishacinema_cinema_venom(
         start_time, finish_time)
     session.add(event)
     rating = Rating(user_id=1, event_id=1, like=1)
     session.add(rating)
     session.commit()
     # Creating objects that I will use in calling method under testing
     controller = TelegramController()
     controller.session = session
     test_bot = BotTest()
     test_update_from_telegram = UpdateFromTelegramTest(
         text="Избранное",
         chat_id=234,
         effective_user_id=555,
         channel_post=None)
     # Check result of calling "_text_message" method (this method pass result to the 'test_bot' object)
     controller._text_message(test_bot, test_update_from_telegram)
     assert test_bot.text == "Вот список мероприятий, которые тебе понравились\n\n" \
         "⭐ <a href='https://afisha.yandex.ru/moscow/cinema/venom-2018' target='_blank'>Веном</a> " + \
         AbstractView.convert_timestamp_to_date_and_time(start_time)
Example #2
0
 def __init__(self, file_name):
     self.users = {}
     self.movies = {}
     self.ratings = {}
     for x in range(1, 6):
         self.ratings[str(x)] = Rating(str(x))
     self.data_file = file_name
     self.min_diff = -0.65
     self.max_diff = 0.65
     self.neighbourhood_size = 200
     self.stats_dict = {}
     self.csv_name = None
Example #3
0
    def get_answer(self):
        # Intent will be useful for view functions
        answer = {"intent": self.intent}

        # We will work with last queue of events for this user and we will change it in database
        last_queue_events = self.user.last_queue_events
        logging.debug('Value of last_queue_events: %s', last_queue_events)

        # If we don't know which event user has liked (or disliked), because last_queue_events is empty
        if len(last_queue_events) == 0:
            answer[
                "text"] = "Больше не осталось подходящих событий, поищем что-то еще?"
            answer["status"] = "none_event"
            return answer

        # Add like or dislike for previous event
        previous_event_id = last_queue_events[0]
        value_of_like = 1 if self.intent == "Like" else 0
        rating = Rating(user_id=self.user.user_id,
                        event_id=previous_event_id,
                        like=value_of_like)
        self.session.add(rating)

        # In queue there isn't other events
        if len(last_queue_events) == 1:
            answer[
                "text"] = "Больше не осталось подходящих событий, поищем что-то еще?"
            answer["status"] = "none_event"
            self.user.clear_last_queue_events()
            self.session.add(self.user)
            self.session.commit()
            return answer

        # If we have 2 events or more in last_queue_events
        next_event_id = last_queue_events[1]
        next_event = self.session.query(Event).filter(
            Event._id == next_event_id).first()
        if not next_event:
            logging.error('Does not exist event with id: %s', next_event_id)
            answer[
                "text"] = "Больше не осталось подходящих событий, поищем что-то еще?"
            answer["status"] = "none_event"
            self.user.clear_last_queue_events()
            self.session.add(self.user)
            self.session.commit()
            return answer
        answer.update(self.make_one_event_data_card(next_event))
        self.user.delete_previous_event_from_queue()

        # Save all changes to database
        self.session.add(self.user)
        self.session.commit()
        return answer
from Rating import Rating
from Experience import Experience
from Review import Review
from User import User
from Recomendation import Recomendation

print(0, "->", Rating(0, 0, 2))
print(1, "->", Rating(1, 0, 2))
print(2, "->", Rating(2, 0, 2))
#Rating(9,0,2)
#Rating("g")
experiencia1 = Experience("Buenas migas", "Restaurante", 1)
experiencia2 = Experience("Telepizza", "Restaurante")
experiencia2.setId(2)
valoracion1 = Rating(1)
resenya1 = Review(experiencia1, valoracion1)
recomendacion1 = Recomendation(experiencia2, Rating(2))
user1 = User("nombre", "contraseña")
user1.setId(1)
user1.addRecomendation(
    Recomendation(Experience("Dominus", "Restaurante", 1), Rating(3)))
user1.addReview(Review(Experience("Dominus", "Restaurante", 3), Rating(4)))
user1.getRecomendations()[0].setId(
    (user1.getRecomendations()[0].getExperience().getId(), user1.getId()))
user1.getReviews()[0].setId(
    (user1.getReviews()[0].getExperience().getId(), user1.getId()))

user2 = User("otroUser", "otraPassword", id=3)
user2.setRecomendations(user1.getRecomendations())
user3 = User("copion", "copionpassword", user1.getReviews(),
             user2.getRecomendations(), 3)
Example #5
0
        for c in centres:
            self._centres.append(c)

    def add_centre(self, centre):
        self._centres.append(centre)

    def get_HC_by_name(self, name):
        for c in self._centres:
            if c.name == name:
                return c


if __name__ == "__main__":
    from Booking import Booking
    from HealthCentre import HealthCentre
    from User import Patient, Provider
    from BookingSystem import BookingSystem
    from Rating import Rating
    #from utils.flaskhelpers import flash
    patient = Patient('user', 'pass', 'name')
    patient2 = Patient('lol', 'pass', 'name2')
    rate = Rating(patient, 5)
    rate2 = Rating(patient2, 4)
    print(rate.value)
    randwick = HealthCentre("medical", "2111", "Randwick da Best Hosotail",
                            "8888 8888", "Randwick")
    randwick.add_rating(rate)
    randwick.add_rating(rate2)
    for r in randwick.ratings:
        print(r.patient)
archivoEntradaRating = 'ratings.csv'
archivoEntradaMovies = 'movies.csv'

with open(archivoEntradaRating) as f1:
    ratingCSV = list(f1.readlines())

with open(archivoEntradaMovies, encoding="utf8") as f2:
    moviesCSV = list(f2.readlines())

ratings = []
movies = []

for ratingLine in ratingCSV:
    results = ratingLine.split(',')
    ratings.append(Rating(results[0], results[1], results[2], results[3]))

for moviesLine in moviesCSV:
    results = moviesLine.split(',')
    movies.append(Movie(results[0], results[1], results[2].rstrip("\n")))

userMovies = [{
    'title': 'Toy Story',
    'rating': 8
}, {
    'title': 'Seven',
    'rating': 5
}, {
    'title': 'Taxi Driver',
    'rating': 9
}, {
Example #7
0
import pandas as pd
from Rating import Rating

tags = []
tags.append("it")
tags.append("ds")
tags.append("staz")
tags.append("praca")

#scraperA = ScraperA()
#websiteA = WebsiteA(scraperA, tags)
scraper_pracuj = Scraper_pracuj()
website_pracuj = Website_pracuj(scraper_pracuj, tags)
scraper_nofluff = Scraper_nofluff()
website_nofluff = Website_nofluff(scraper_nofluff, tags)
scraper_gratka = Gratka_Initial_Scraper()
website_gratka = Gratka_Initial_Website(scraper_gratka, tags)

websites = [website_pracuj]

controller = Controller(websites)
controller.scraping()
'''
tag = ['tag']
points = [0]
df = pd.DataFrame({'tag' : tag, 'points' : points })
df.to_excel('tags.xlsx', index = False)
'''
rating = Rating()
rating.rate()
Example #8
0
                                       (lambda (ne, factors): intra_add(ne, factors)),
                                       (lambda (ne1, ne2): inter_add(ne1, ne2)))


if __name__ == "__main__":

    import os
    os.environ["PYSPARK_PYTHON"] = "/Users/az/Downloads/applications/anaconda2/bin/python"
    conf = SparkConf().set("spark.jars",
                           "/Users/az/Downloads/HKUST/Big_Data_Computing_5003/project/als/ALS/netlib-java-1.1.jar")

    sc = SparkContext(conf=conf)

    data = sc.textFile("../ALS/data/test.data", 2)
    ratings = data.map(lambda l: l.split(',')) \
        .map(lambda l: Rating(int(l[0]), int(l[1]), float(l[2])))

    # print ratings.isEmpty()
    #print ratings.collect()

    # Build the recommendation model using Alternating Least Squares
    rank = 10
    numIterations = 5

    als = NewALS()

    num_user_blocks = max(ratings.getNumPartitions(), ratings.getNumPartitions() / 2)
    #print num_user_blocks

    num_item_blocks = max(ratings.getNumPartitions(), ratings.getNumPartitions() / 2)
Example #9
0
 def __init__(self):
     self.rating = Rating()
     self.history = []
Example #10
0
from pymongo import MongoClient
from Rating import Rating
from flask import Flask, request
import json

app = Flask(__name__)

client = MongoClient(
    "mongodb://*****:*****@192.168.16.107:27017/?authSource=admin&retryWrites=false"
)
db = client.ramen_rating
collection = db.ratings
rating = Rating(collection)


@app.route('/', methods=['GET'])
def hello_world():
    return 'Hello World'


@app.route('/api/rating', methods=['GET'])
def get_all_ratings():
    return json.dumps(rating.all())


@app.route('/api/rating/search', methods=['GET'])
def search_ratings():
    query = request.args.to_dict()
    if 'stars' in query:
        query['stars'] = float(query['stars'])