Example #1
0
    def get_reviews_count_in_period(cls,
                                    db,
                                    from_date,
                                    domain_filter=None,
                                    to_date=None):
        if to_date is None:
            to_date = datetime.utcnow()

        reviews = db \
            .query(Review.completed_date) \
            .filter(Review.is_active == True) \
            .filter(Review.completed_date.between(from_date, to_date))

        if domain_filter:
            from holmes.models.domain import Domain
            domain = Domain.get_domain_by_name(domain_filter, db)
            if domain:
                reviews = reviews.filter(Review.domain_id == domain.id)

        reviews = reviews.order_by(Review.completed_date.asc()).all()

        count = len(reviews)

        first_date = None
        if count > 0:
            first_date = reviews[0].completed_date

        return count, first_date
Example #2
0
    def _filter_by_violation_key_name(cls,
                                      db,
                                      query,
                                      key_id,
                                      domain_filter=None,
                                      page_filter=None):
        from holmes.models.violation import Violation  # to avoid circular dependency
        from holmes.models.page import Page  # to avoid circular dependency

        query = query \
            .filter(Page.last_review_id == Violation.review_id) \
            .filter(Violation.review_is_active == 1) \
            .filter(Violation.key_id == key_id)

        if domain_filter:
            from holmes.models.domain import Domain  # to avoid circular dependency
            domain = Domain.get_domain_by_name(domain_filter, db)
            if domain:
                query = query.filter(Page.domain_id == domain.id)

                if page_filter:
                    query = query.filter(
                        Page.url.like(u'{0}/{1}%'.format(
                            domain.url, page_filter)))

        return query
Example #3
0
    def get_reviews_count_in_period(cls, db, from_date, domain_filter=None, to_date=None):
        if to_date is None:
            to_date = datetime.utcnow()

        reviews = (
            db.query(Review.completed_date)
            .filter(Review.is_active == True)
            .filter(Review.completed_date.between(from_date, to_date))
        )

        if domain_filter:
            from holmes.models.domain import Domain

            domain = Domain.get_domain_by_name(domain_filter, db)
            if domain:
                reviews = reviews.filter(Review.domain_id == domain.id)

        reviews = reviews.order_by(Review.completed_date.asc()).all()

        count = len(reviews)

        first_date = None
        if count > 0:
            first_date = reviews[0].completed_date

        return count, first_date
Example #4
0
    def count_by_violation_key_name(cls, db, key_id, domain_filter=None, page_filter=None):
        from holmes.models.review import Review  # to avoid circular dependency
        from holmes.models.violation import Violation  # to avoid circular dependency

        query = db \
            .query(sa.func.count(Violation.id)) \
            .filter(Violation.review_is_active == 1) \
            .filter(Violation.key_id == key_id)

        page_filter_prefix = '%'
        if domain_filter:
            from holmes.models.domain import Domain  # to avoid circular dependency
            domain = Domain.get_domain_by_name(domain_filter, db)
            if domain:
                query = query.filter(Review.domain_id == domain.id)
                page_filter_prefix = domain.url

        if page_filter:
            from holmes.models.page import Page  # to avoid circular dependency
            query = query.filter(Review.id == Violation.review_id) \
                .filter(Page.id == Review.page_id) \
                .filter(
                    Page.url.like(
                        '{0}{1}%'.format(page_filter_prefix, page_filter)
                    )
                )

        return query.scalar()
Example #5
0
    def get_all(cls, db, domain_filter=None):
        query = db.query(Limiter)

        if domain_filter:
            domain = Domain.get_domain_by_name(domain_filter, db)
            if domain:
                query = query.filter(Limiter.url.startswith(domain.url))

        return query.order_by(sa.func.char_length(Limiter.url)).all()
Example #6
0
    def get_last_reviews(cls, db, domain_filter=None, limit=12):
        query = db.query(Review).filter(Review.is_active == True)

        if domain_filter:
            from holmes.models.domain import Domain
            domain = Domain.get_domain_by_name(domain_filter, db)
            if domain:
                query = query.filter(Review.domain_id == domain.id)

        return query.order_by(Review.completed_date.desc())[:limit]
Example #7
0
    def get_last_reviews(cls, db, domain_filter=None, limit=12):
        query = db.query(Review).filter(Review.is_active == True)

        if domain_filter:
            from holmes.models.domain import Domain
            domain = Domain.get_domain_by_name(domain_filter, db)
            if domain:
                query = query.filter(Review.domain_id == domain.id)

        return query.order_by(Review.completed_date.desc())[:limit]
Example #8
0
    def get_all(cls, db, domain_filter=None):
        query = db.query(Limiter)

        if domain_filter:
            domain = Domain.get_domain_by_name(domain_filter, db)
            if domain:
                query = query.filter(Limiter.url.startswith(domain.url))

        return query \
               .order_by(sa.func.char_length(Limiter.url)) \
               .all()
Example #9
0
    def get_last_requests(self, db, current_page=1, page_size=10,
                          domain_filter=None, status_code_filter=None):
        lower_bound = (current_page - 1) * page_size
        upper_bound = lower_bound + page_size

        query = db.query(Request)

        if domain_filter:
            from holmes.models.domain import Domain
            domain = Domain.get_domain_by_name(domain_filter, db)
            if domain:
                query = query.filter(Request.domain_name == domain.name)

        if status_code_filter and int(status_code_filter):
            query = query.filter(Request.status_code == status_code_filter)

        return query.order_by('id desc')[lower_bound:upper_bound]
Example #10
0
    def get_last_requests(self, db, current_page=1, page_size=10,
                          domain_filter=None, status_code_filter=None):
        lower_bound = (current_page - 1) * page_size
        upper_bound = lower_bound + page_size

        query = db.query(Request)

        if domain_filter:
            from holmes.models.domain import Domain
            domain = Domain.get_domain_by_name(domain_filter, db)
            if domain:
                query = query.filter(Request.domain_name == domain.name)

        if status_code_filter and int(status_code_filter):
            query = query.filter(Request.status_code == status_code_filter)

        return query.order_by('id desc')[lower_bound:upper_bound]
Example #11
0
    def _filter_by_violation_key_name(cls, db, query, key_id, domain_filter=None, page_filter=None):
        from holmes.models.violation import Violation  # to avoid circular dependency
        from holmes.models.page import Page  # to avoid circular dependency

        query = (
            query.filter(Page.last_review_id == Violation.review_id)
            .filter(Violation.review_is_active == 1)
            .filter(Violation.key_id == key_id)
        )

        if domain_filter:
            from holmes.models.domain import Domain  # to avoid circular dependency

            domain = Domain.get_domain_by_name(domain_filter, db)
            if domain:
                query = query.filter(Page.domain_id == domain.id)

                if page_filter:
                    query = query.filter(Page.url.like(u"{0}/{1}%".format(domain.url, page_filter)))

        return query
Example #12
0
    def get_by_violation_key_name(cls, db, key_id, current_page=1, page_size=10, domain_filter=None, page_filter=None):
        from holmes.models.page import Page  # to avoid circular dependency
        from holmes.models.review import Review  # to avoid circular dependency
        from holmes.models.violation import Violation  # to avoid circular dependency

        lower_bound = (current_page - 1) * page_size
        upper_bound = lower_bound + page_size

        query = db \
            .query(
                Review.uuid.label('review_uuid'),
                Page.url,
                Page.uuid.label('page_uuid'),
                Review.completed_date
            ) \
            .filter(Violation.key_id == key_id) \
            .filter(Review.id == Violation.review_id) \
            .filter(Review.is_active == 1) \
            .filter(Page.id == Review.page_id) \

        page_filter_prefix = '%'
        if domain_filter:
            from holmes.models.domain import Domain  # to avoid circular dependency
            domain = Domain.get_domain_by_name(domain_filter, db)
            if domain:
                query = query.filter(Review.domain_id == domain.id)
                page_filter_prefix = domain.url

        if page_filter:
            query = query.filter(
                Page.url.like(
                    '{0}{1}%'.format(page_filter_prefix, page_filter)
                )
            )

        return query.order_by(Review.completed_date.desc())[lower_bound:upper_bound]