Пример #1
0
def process_data(site, graph, criteria, from_date, to_date, step, stamp, lang):
    rq = (db.session.query(
        Visit.day.label("key"),
        count(distinct(Visit.uuid)).label("count") if criteria == 'unique' else
        count(1).label("count")).filter(on(site)).filter(
            between(from_date, to_date)))

    if criteria == 'new':
        rq = rq.filter(Visit.last_visit == None)

    results = rq.group_by(Visit.day).order_by(Visit.day).all()
    return make_time_serie(results, criteria, from_date, to_date, lang)
Пример #2
0
def process_data(site, graph, criteria, from_date, to_date, step, stamp, lang):
    rq = (db.session
          .query(Visit.day.label("key"),
                 count(distinct(Visit.uuid)).label("count")
                 if criteria == 'unique' else count(1).label("count"))
          .filter(on(site))
          .filter(between(from_date, to_date)))

    if criteria == 'new':
        rq = rq.filter(Visit.last_visit == None)

    results = rq.group_by(Visit.day).order_by(Visit.day).all()
    return make_time_serie(results, criteria, from_date, to_date, lang)
Пример #3
0
 def sites_query(query):
     """Sites matching query"""
     sites = (db.session.query(
         Visit.host,
         count(1).label('count')).filter(Visit.host.like(
             '%%%s%%' % query)).group_by(Visit.host).order_by(
                 desc('count')))[:20]
     return render_template('sites_table.jinja2', sites=sites)
Пример #4
0
 def sites_query(query):
     """Sites matching query"""
     sites = (
         db.session
         .query(Visit.host, count(1).label('count'))
         .filter(Visit.host.like('%%%s%%' % query))
         .group_by(Visit.host)
         .order_by(desc('count')))[:20]
     return render_template('sites_table.jinja2', sites=sites)
Пример #5
0
    def populate(self):
        all = (self.filter(self.db
               .query(Visit.day, count(1), count(distinct(Visit.uuid))))
               .group_by(Visit.day)
               .order_by(Visit.day)
               .all())

        self.chart.x_labels = list(map(
            lambda x: x.strftime('%Y-%m-%d'), cut(all, 0)))
        self.chart.add(labelize('all', self.lang), cut(all, 1))
        self.chart.add(labelize('unique', self.lang), cut(all, 2))

        new = (self.filter(
            self.db
            .query(count(distinct(Visit.uuid))))
            .filter(Visit.last_visit == None)
            .group_by(Visit.day)
            .order_by(Visit.day)
            .all())
        self.chart.add(labelize('new', self.lang), cut(new, 0))
        self.chart.x_label_rotation = 45
Пример #6
0
def process_data(site, graph, criteria, from_date, to_date, step, stamp, lang):
    table, criteria, count_col = get_attribute_and_count('country_code')
    rq = (db.session
          .query(table.c.country, table.c.country_code,
                 count(1).label("count"))
          .filter(on(site, table))
          .filter(between(from_date, to_date, table))
          .group_by(table.c.country_code, table.c.country))
    visits = [{'country': visit.country,
               'code': visit.country_code,
               'count': visit.count} for visit in rq.all()]
    return {'list': visits,
                    'max': max(
                        [visit['count'] for visit in visits] + [0])}
Пример #7
0
def process_data(site, graph, criteria, from_date, to_date, step, stamp, lang):
    table, criteria, count_col = get_attribute_and_count('country_code')
    rq = (db.session.query(
        table.c.country, table.c.country_code,
        count(1).label("count")).filter(on(site, table)).filter(
            between(from_date, to_date,
                    table)).group_by(table.c.country_code, table.c.country))
    visits = [{
        'country': visit.country,
        'code': visit.country_code,
        'count': visit.count
    } for visit in rq.all()]
    return {
        'list': visits,
        'max': max([visit['count'] for visit in visits] + [0])
    }
Пример #8
0
def get_attribute_and_count(attr_name):
    """Return a tuple of (table, attr_col, count_column) according to the best
    aggregate table
    """
    if attr_name == 'day':
        # all tables work on the day column
        attr_name = 'date'
    table = get_aggregate_table(attr_name)
    if table is None:
        table = Visit.__table__
        current_app.logger.warn('No aggregate table found for %s' % attr_name)
        countcol = count(1)
        attr = getattr(Visit, attr_name)
    else:
        countcol = sum_(table.c.fact_count)
        attr = getattr(table.c, attr_name)
    return table, attr, countcol
Пример #9
0
 def index():
     all_ = db.session.query(count(1)).select_from(Visit).scalar()
     return render_template('index.jinja2', all_=all_)
Пример #10
0
 def index():
     all_ = db.session.query(count(1)).select_from(Visit).scalar()
     return render_template('index.jinja2', all_=all_)