def get_user_vectors(self):
        user_vectors = {}
        session = Session()
        try:
            result = session.query(Rating) \
                            .order_by(Rating.user_id, Rating.movie_id) \
                            .all()
            prev_user = None
            for row in result:
                cur_user = row.user_id
                movie_id = row.movie_id
                rating = row.rating

                if prev_user == None or prev_user != cur_user:
                    uv = {}
                    uv[movie_id] = rating
                    user_vectors[cur_user] = uv
                else:
                    user_vectors[cur_user][movie_id] = rating

                prev_user = cur_user

            return user_vectors

        except Exception as e:
            print e
            return {}

        finally:
            session.close()
Exemplo n.º 2
0
    def get_product_link(self):
        session = Session()
        find_product_link = session.query(Product).all()

        result = [(row.Link, row.ProductNo) for row in find_product_link]

        return result
Exemplo n.º 3
0
 def get_userid(self, userid):
     session = Session()
     if session.query(User).filter(User.UserId == userid).all():
         return True
     else:
         return False
     session.close()
Exemplo n.º 4
0
    def get_somedays_news(self, countdays):

        session = Session()
        somedays_news = session.query(NewsArticle).filter(NewsArticle.ReportDate >= datetime.date.today() - datetime.timedelta(days=countdays)).all()

        result = [row.Link for row in somedays_news]

        return result
Exemplo n.º 5
0
 def get_user_list(self, tt):
     session = Session()
     user_list = []
     result = session.query(User).filter(User.TrainTest == tt).all()
     for row in result:
         user_list.append(row.UserId)
     session.close()
     return user_list
Exemplo n.º 6
0
 def get_item_list(self, tt):
     session = Session()
     item_list = []
     result = session.query(Product).filter(Product.TrainTest == tt).all()
     for row in result:
         item_list.append(row.ProductNo)
     session.close()
     return item_list
Exemplo n.º 7
0
	def get(self):
		session = Session()
		stocks = session.query(Stock).all()
		
		res = []
		for s in stocks:
			res.append(s._asdict())
			
		return res
Exemplo n.º 8
0
    def get_recent_news(self):

        session = Session()
        recent_news = session.query(NewsArticle).order_by(desc(NewsArticle.ReportDate)).limit(10)

        for row in recent_news:
            CacheNews().cache_recent_news(str(row.Title.decode('utf-8')))

        session.close()
Exemplo n.º 9
0
 def get_ratings(self, place_id):
     try:
         session = Session()
         row = session.query(Ratings).filter(Ratings.place_id == place_id).first()
         if row: print '<RATING>', row, 'exists.'
         return row
     except Exception as e:
         print e
     finally:
         session.close()
Exemplo n.º 10
0
    def get_place_name(self, place_id):
        try:
            session = Session()
            row = session.query(GeoInfos).filter(GeoInfos.place_id == place_id).first()
#           if row: print '<GEOINFO>', row, 'exists.'
            return row.name
        except Exception as e:
            print e
        finally:
            session.close()
Exemplo n.º 11
0
 def get_news_contents(self, link):
     try:
         session = Session()
         result = session.query(NewsArticle).filter(NewsArticle.Link == link).first()
         return result.Content
     except Exception as e:
         print e
         return ''
     finally:
         session.close()
Exemplo n.º 12
0
 def get_movie_by_title(self, movie_title):
     try:
         session = Session()
         row = session.query(movie_info) \
                      .filter(movie_info.title == movie_title) \
                      .first()
         return row
     except Exception as e:
         print e
     finally:
         session.close()
Exemplo n.º 13
0
 def get_comment_by_id(self, comment_id):
     try:
         session = Session()
         row = session.query(comments) \
                      .filter(comments.ID == comment_id) \
                      .first()
         return row
     except Exception as e:
         print e
     finally:
         session.close()
Exemplo n.º 14
0
def session(connection):
    '''We need to ensure that there is a fresh session per test run'''
    transaction = connection.begin()
    session = Session(bind=connection)

    # SourceFactory._meta.sqlalchemy_session = session
    # TargetFactory._meta.sqlalchemy_session = session

    yield session
    session.close()
    transaction.rollback()
Exemplo n.º 15
0
    def get_news_by_keyword_in_title(self, keyword):
        data = []
        session = Session()
        result = session.query(News).filter(News.title.like('%' + keyword + '%')).all()
        for row in result:
            news = {}
            news['link'] = row.link
            news['title'] = row.title
            news['written_time'] = row.written_time

            data.append(news)
        return data
Exemplo n.º 16
0
    def get_news_by_id(self, news_id):
        try:
            session = Session()
            row = session.query(News) \
                .filter(News.link == news_id) \
                .first()

            return row
        except Exception as e:
            print e
        finally:
            session.close()
Exemplo n.º 17
0
    def find_keyword_in_contents(self, keyword):

        session = Session()
        result = session.query(NewsArticle).filter(NewsArticle.Content.like('%' + keyword + '%')).all()
        news_list = []
        for row in result:
            news_dict = {}
            news_dict['link'] = row.Link
            news_dict['title'] = row.Title
            news_dict['content'] = row.Content
            news_list.append(news_dict)
        return news_list
Exemplo n.º 18
0
    def get_comments_id(self, coId):
        session = Session()
        find_comment = session.query(CommentList).filter(
            CommentList.Id == coId).all()

        if len(find_comment) >= 1:
            return False

        else:
            return True

        session.close()
Exemplo n.º 19
0
    def get_news_content(self, news_id):

        try:
            session = Session()
            result = session.query(News)\
                            .filter(News.link == news_id).first()
            return result.content
        except Exception as e:
            print '21', e

        finally:
            session.close()
Exemplo n.º 20
0
    def get_news_id(self, news_url):

        session = Session()
        find_news = session.query(NewsArticle).filter(NewsArticle.Link == news_url).all()

        if len(find_news) >= 1:
            return False

        else:
            return True

        session.close()
Exemplo n.º 21
0
    def get_news_by_id(self, link):
        try:
            session = Session()
            result = session.query(News)\
                            .filter(News.link == link).first()
            return result

        except Exception as e:
            print '11', e

        finally:
            session.close()
Exemplo n.º 22
0
def listar():
    try:
        session = Session()

        items = session.query(Item).order_by(Item.id.asc()).all()
        items_dict = []
        for item in items:
            items_dict.append(item.to_dict())  
        return items_dict
    except Exception as e:
        return internal_error(e), 500
    finally:
        session.close()
Exemplo n.º 23
0
    def get_product_id(self, productno):
        session = Session()
        find_product = session.query(Product)\
                              .filter(Product.ProductNo == productno)\
                              .all()

        if find_product:
            return False

        else:
            return True

        session.close()
Exemplo n.º 24
0
    def get_user_average_rating(self, user_id):
        session = Session()
        try:
            result = session.query(func.avg(Rating.rating)) \
                            .filter(Rating.user_id == user_id) \
                            .one()

            return result[0]

        except Exception as e:
            print e

        finally:
            session.close()
Exemplo n.º 25
0
 def __init__(self,id):
     self.id = id 
     self.Session = Session
     self.session = Session()
     self.process = self.session.query(models.Process).options(joinedload('queues').joinedload('queues_tasks').joinedload('task')).filter(models.Process.id == self.id).first()
     if not self.process:
         raise Exception(f"Can't find process with id ='{self.id}'")
     with open('./config.yaml','r') as config:
         settings = yaml.safe_load(config)
     self.logger = create_logger('main', os.path.join(settings['logs']['test']['logpath'],self.process.name, dt.datetime.now().strftime("%Y%m%d_%H%M%S")))
     self.logger.info(f"Executor initiated for process with id = '{self.id}'")
     self.logger.debug(self.process)
     self.threads = []
     self.threads_with_errors = []
Exemplo n.º 26
0
    def get_topn_higly_rated_movies(self, n):
        session = Session()
        try:
            result = session.query(Rating.movie_id, func.avg(Rating.rating) \
                    .label('avgrating')) \
                    .group_by(Rating.movie_id) \
                    .order_by('avgrating desc') \
                    .limit(n) \

            return [(row[0], row[1]) for row in result]
        except Exception as e:
            print e
        finally:
            session.close()
Exemplo n.º 27
0
    def get_news_by_keyword_in_content(self, keyword):
        data = []
        session = Session()
        result = session.query(News) \
                        .filter(News.content.like('%' + keyword + '%')) \
                        .all()
        for row in result:
            news = {}
            news['link'] = row.link
            news['title'] = row.title
            news['content'] = row.content

            data.append(news)
        return data
Exemplo n.º 28
0
    def get_comment_info(self, productno, comment_writer):
        session = Session()
        find_comment = session.query(Comment)\
                              .filter(Comment.ProductNo == productno,
                                      Comment.Writer == comment_writer)\
                              .all()

        if find_comment:
            return False

        else:
            return True

        session.close()
Exemplo n.º 29
0
    def get_rating_array_fast(self, user_ids, movie_id):
        session = Session()
        try:
            result = session.query(Rating.rating) \
                            .filter(Rating.movie_id == movie_id) \
                            .filter(Rating.user_id.in_(user_ids)) \
                            .order_by(Rating.user_id) \
                            .all()
        except Exception as e:
            print e
        finally:
            session.close()

        return np.array([float(row[0]) for row in result])
Exemplo n.º 30
0
def deletar(id):
    try:
        session = Session()

        item = session.query(Item).get(id)
        session.delete(item)  
        session.commit()  
    except Exception as e:
        return internal_error(e), 500
    finally:
        session.close()