コード例 #1
0
ファイル: data.py プロジェクト: arthru/pystil
def register_data_routes(app, route):
    """Defines data routes"""
    from pystil.db import Visit, fields
    from pystil.data import process_data
    from pystil.data.utils import date_to_time

    url_base = "/<string:site>/<any%r:graph>_by_<any%r:criteria>_in_<lang>" % (
        ("pie", "bar", "line", "table", "map", "last", "top"),
        tuple(fields(Visit)) + ("all", "unique", "new"),
    )
    url_with_at = "%s_at_<int:stamp>" % url_base
    url_with_from = "%s_from_<int:from_date>" % url_base
    url_with_to = "%s_to_<int:to_date>" % url_with_from
    url_with_step = "%s_step_<any%r:step>" % (url_with_to, ("hour", "day", "week", "year"))

    @route("%s.json" % url_base)
    @route("%s.json" % url_with_at)
    @route("%s.json" % url_with_from)
    @route("%s.json" % url_with_to)
    @route("%s.json" % url_with_step)
    @jsonp
    def data(site, graph, criteria, lang, from_date=None, to_date=None, step="day", stamp=None):
        today = date.today()
        month_start = datetime(today.year, today.month, 1)
        from_date = from_date or date_to_time(month_start)
        to_date = to_date or date_to_time(today)
        return json.dumps(process_data(site, graph, criteria, from_date, to_date, step, stamp, lang), cls=PystilEncoder)
コード例 #2
0
def register_data_routes(app, route):
    """Defines data routes"""
    from pystil.db import Visit, fields
    from pystil.data import process_data
    from pystil.data.utils import date_to_time

    url_base = '/<string:site>/<any%r:graph>_by_<any%r:criteria>_in_<lang>' % (
        ('pie', 'bar', 'line', 'table', 'map', 'last', 'top'),
        tuple(fields(Visit)) + ('all', 'unique', 'new'))
    url_with_at = '%s_at_<int:stamp>' % url_base
    url_with_from = '%s_from_<int:from_date>' % url_base
    url_with_to = '%s_to_<int:to_date>' % url_with_from
    url_with_step = '%s_step_<any%r:step>' % (url_with_to,
                                              ('hour', 'day', 'week', 'year'))

    @route('%s.json' % url_base)
    @route('%s.json' % url_with_at)
    @route('%s.json' % url_with_from)
    @route('%s.json' % url_with_to)
    @route('%s.json' % url_with_step)
    @jsonp
    def data(site,
             graph,
             criteria,
             lang,
             from_date=None,
             to_date=None,
             step='day',
             stamp=None):
        today = date.today()
        month_start = datetime(today.year, today.month, 1)
        from_date = from_date or date_to_time(month_start)
        to_date = to_date or date_to_time(today)
        return json.dumps(process_data(site, graph, criteria, from_date,
                                       to_date, step, stamp, lang),
                          cls=PystilEncoder)
コード例 #3
0
ファイル: utils.py プロジェクト: arthru/pystil
def visit_to_dict(visit):
    visit_dict = {}
    for key in fields(Visit):
        visit_dict[key] = getattr(visit, key)
    return visit_dict
コード例 #4
0
def visit_to_dict(visit):
    visit_dict = {}
    for key in fields(Visit):
        visit_dict[key] = getattr(visit, key)
    return visit_dict