Esempio n. 1
0
def showstats():
    """
    Show statistics about the collection
    """
    # Size of progress-bar
    COLUMNS = 40
    result = []

    session = get_db_connection()
    #session.query(Article).
    #items = session.query(extract('year', Article.time_read).label('year')).distinct().subquery()
    #items = session.query(extract('year', Article.time_read).label('year'), func.count(Article.id)).distinct().order_by('year')

    # Numbers
    items_total = nr_total(session)
    items_read = nr_read(session)
    items_unread = nr_unread(session)
    items_favourited = nr_favourited(session)
    items_deleted = nr_deleted(session)

    result.append(['Total items', str(items_total)])
    result.append(['Total read', str(items_read)])
    result.append(['Total unread', str(items_unread)])
    result.append(['Total favourited', str(items_favourited)])
    result.append(['Total deleted', str(items_deleted)])
    result.append([])

    # Progress bar
    result.append(['progress', printutil.progress_bar(items_total, items_read, COLUMNS, '.', '#', True)])
    result.append(['favourites', printutil.progress_bar(items_total, items_favourited, COLUMNS, ' ', '*')])

    result.append([])

    # Read articles per yer
    result.append(['year', 'amount of articles read'])
    items = session.query(extract('year', Article.time_read).label('year'), func.count(Article.id)).group_by('year')
    for item in items:
        if item[0] is None:
            result.append(['unknown', str(item[1])])
        elif item[0] == 1970:
            result.append(['unread', str(item[1])])
        else:
            result.append([str(item[0]), str(item[1])])

    result.append([])
    print(printutil.to_smart_columns(result))

    # List of number of items read, per date
    items_read = session.query(func.date(Article.time_read).label('thedate'), func.count(Article.id)).group_by('thedate')
    # firstseen_time_updated comes as close to 'time added' as we can get from the Pocket API
    items_added = session.query(func.date(Article.firstseen_time_updated).label('thedate'), func.count(Article.id)).group_by('thedate')
    #for item in items_added:
    #    print item
    # TODO: plot added-vs-read graph
    items_added_per_month = session.query(extract('year', Article.firstseen_time_updated).label('year'), extract('month', Article.firstseen_time_updated).label('month'), func.count(Article.id)).group_by('year', 'month')
    items_read_per_month = session.query(extract('year', Article.time_read).label('year'), extract('month', Article.time_read).label('month'), func.count(Article.id)).group_by('year', 'month')
    read_vs_added = printutil.x_vs_y(items_read_per_month, items_added_per_month, filter_none=True)
    #for item in read_vs_added:
    #    result.append(item)
    print(read_vs_added)

    # Tags
    # TODO: loop over Articles, get amount of articles/tag

    # Finally, print the stats
    #print(printutil.to_smart_columns(result))
    return

    items = session.query(extract('year', Article.time_read).label('year')).distinct()
    for item in items:
        print(item)

    per_date = session.query(func.count(Article.id), extract('date', Article.time_read).label('h')).group_by('h')
    for item in per_date:
        print(item)
    per_hour = session.query(extract('hour', Article.time_read).label('h')).group_by('h')
    for item in per_hour:
        print(item)
Esempio n. 2
0
def showstats():
    """
    Show statistics about the collection
    """
    # Size of progress-bar
    COLUMNS = 40
    result = []

    session = get_db_connection()
    #session.query(Article).
    #items = session.query(extract('year', Article.time_read).label('year')).distinct().subquery()
    #items = session.query(extract('year', Article.time_read).label('year'), func.count(Article.id)).distinct().order_by('year')

    # Numbers
    items_total = nr_total(session)
    items_read = nr_read(session)
    items_unread = nr_unread(session)
    items_favourited = nr_favourited(session)
    items_deleted = nr_deleted(session)

    result.append(['Total items', str(items_total)])
    result.append(['Total read', str(items_read)])
    result.append(['Total unread', str(items_unread)])
    result.append(['Total favourited', str(items_favourited)])
    result.append(['Total deleted', str(items_deleted)])
    result.append([])

    # Progress bar
    result.append(['progress', printutil.progress_bar(items_total, items_read, COLUMNS, '.', '#', True)])
    result.append(['favourites', printutil.progress_bar(items_total, items_favourited, COLUMNS, ' ', '*')])

    result.append([])

    # Read articles per yer
    result.append(['year', 'amount of articles read'])
    items = session.query(extract('year', Article.time_read).label('year'), func.count(Article.id)).group_by('year')
    for item in items:
        if item[0] is None:
            result.append(['unknown', str(item[1])])
        elif item[0] == 1970:
            result.append(['unread', str(item[1])])
        else:
            result.append([str(item[0]), str(item[1])])

    result.append([])
    print(printutil.to_smart_columns(result))

    # List of number of items read, per date
    items_read = session.query(func.date(Article.time_read).label('thedate'), func.count(Article.id)).group_by('thedate')
    # firstseen_time_updated comes as close to 'time added' as we can get from the Pocket API
    items_added = session.query(func.date(Article.firstseen_time_updated).label('thedate'), func.count(Article.id)).group_by('thedate')
    #for item in items_added:
    #    print item
    # TODO: plot added-vs-read graph
    items_added_per_month = session.query(extract('year', Article.firstseen_time_updated).label('year'), extract('month', Article.firstseen_time_updated).label('month'), func.count(Article.id)).group_by('year', 'month')
    items_read_per_month = session.query(extract('year', Article.time_read).label('year'), extract('month', Article.time_read).label('month'), func.count(Article.id)).group_by('year', 'month')
    read_vs_added = printutil.x_vs_y(items_read_per_month, items_added_per_month, filter_none=True)
    #for item in read_vs_added:
    #    result.append(item)
    print read_vs_added

    # Tags
    # TODO: loop over Articles, get amount of articles/tag

    # Finally, print the stats
    #print(printutil.to_smart_columns(result))
    return

    items = session.query(extract('year', Article.time_read).label('year')).distinct()
    for item in items:
        print item

    per_date = session.query(func.count(Article.id), extract('date', Article.time_read).label('h')).group_by('h')
    for item in per_date:
        print item
    per_hour = session.query(extract('hour', Article.time_read).label('h')).group_by('h')
    for item in per_hour:
        print item
Esempio n. 3
0
def get_read_progressbar(session):
    COLUMNS = 40
    items_total = nr_total(session)
    items_read = nr_read(session)
    return str(items_read) + '/' + str(items_total) + '  ' + printutil.progress_bar(items_total, items_read, COLUMNS, '.', '#', True)
Esempio n. 4
0
def get_read_progressbar(session):
    COLUMNS = 40
    items_total = nr_total(session)
    items_read = nr_read(session)
    return str(items_read) + '/' + str(items_total) + '  ' + printutil.progress_bar(items_total, items_read, COLUMNS, '.', '#', True)