timetrack/cli.py
def report(ctx, week, month, graph, graph_type):
    """Summarise total time spent per project instead of per day"""
    
    
    driver = ctx.obj['DRIVER']
    
    if week:
        end = datetime.now()
        delta = timedelta(days=7)
        start = end - delta
        start_date = date(start.year, start.month, start.day)
        end_date = date(end.year, end.month, end.day)
    elif month:
        end = datetime.now()
        delta = timedelta(days=30)
        start = end - delta
        start_date = date(start.year, start.month, start.day)
        end_date = date(end.year, end.month, end.day)
    else:
        start_date = date.today()
        end_date = date.today()

    projects = defaultdict(lambda: 0)
    
    for record in driver.get_filtered_entries(start_date, end_date, project=None):

        dt = datetime.strptime(record['date'], "%Y-%m-%d")
        record_date = date(dt.year, dt.month, dt.day)

        if record_date >= start_date and record_date <= end_date:
            projects[record['project']] += record['time']

    if not graph:
        print("\nProject Breakdown: {} to {} \n----------".format(
            start_date.strftime("%Y-%m-%d"),
            end_date.strftime("%Y-%m-%d")))

        for project, spent in projects.items():
            print("{}: {}".format(project, human_time(spent)))
    else:
        fig = pyplot.figure()
        titleString = "Project Breakdown: {}".format(start_date.strftime("%Y-%m-%d"))

        if start_date != end_date:
            titleString+=" to {}".format(end_date.strftime("%Y-%m-%d"))

        fig.suptitle(titleString, fontsize=14, fontweight='bold')

        ax = fig.add_subplot(1,1,1)
        fig.subplots_adjust(top=0.85)
        num_reports = len(projects)

        my_colors = ['c','m','y','r', 'g', 'b']

        for key in projects.keys():
            projects[key] = projects[key]/60.0

        if graph_type == "pie":
            pyplot.axis('equal')
            pyplot.pie(projects.values(), labels=list(projects.keys()), autopct='%1.1f%%', colors=my_colors, startangle=90)
        else:
            ax.set_xlabel('Project')
            ax.set_ylabel('Hours')
            pyplot.barh(range(num_reports), projects.values(), align='center', color=my_colors)
            pyplot.yticks(range(num_reports), list(projects.keys()))

    pyplot.show()

    return projects
Summarise total time spent per project instead of per day
Summarise total time spent per project instead of per day
Summarise total time spent per project instead of per day
def report(ctx, week, month, graph, graph_type):
    driver = ctx.obj['DRIVER']
    if week:
        end = datetime.now()
        delta = timedelta(days=7)
        start = end - delta
        start_date = date(start.year, start.month, start.day)
        end_date = date(end.year, end.month, end.day)
    elif month:
        end = datetime.now()
        delta = timedelta(days=30)
        start = end - delta
        start_date = date(start.year, start.month, start.day)
        end_date = date(end.year, end.month, end.day)
    else:
        start_date = date.today()
        end_date = date.today()
    projects = defaultdict(lambda: 0)
    for record in driver.get_filtered_entries(start_date, end_date, project=None):
        dt = datetime.strptime(record['date'], "%Y-%m-%d")
        record_date = date(dt.year, dt.month, dt.day)
        if record_date >= start_date and record_date <= end_date:
            projects[record['project']] += record['time']
    if not graph:
        print("\nProject Breakdown: {} to {} \n----------".format(
            start_date.strftime("%Y-%m-%d"),
            end_date.strftime("%Y-%m-%d")))
        for project, spent in projects.items():
            print("{}: {}".format(project, human_time(spent)))
    else:
        fig = pyplot.figure()
        titleString = "Project Breakdown: {}".format(start_date.strftime("%Y-%m-%d"))
        if start_date != end_date:
            titleString+=" to {}".format(end_date.strftime("%Y-%m-%d"))
        fig.suptitle(titleString, fontsize=14, fontweight='bold')
        ax = fig.add_subplot(1,1,1)
        fig.subplots_adjust(top=0.85)
        num_reports = len(projects)
        my_colors = ['c','m','y','r', 'g', 'b']
        for key in projects.keys():
            projects[key] = projects[key]/60.0
        if graph_type == "pie":
            pyplot.axis('equal')
            pyplot.pie(projects.values(), labels=list(projects.keys()), autopct='%1.1f%%', colors=my_colors, startangle=90)
        else:
            ax.set_xlabel('Project')
            ax.set_ylabel('Hours')
            pyplot.barh(range(num_reports), projects.values(), align='center', color=my_colors)
            pyplot.yticks(range(num_reports), list(projects.keys()))
    pyplot.show()
    return projects
def report ( ctx , week , month , graph , graph_type ) : driver = ctx . obj [ 'DRIVER' ] if week : end = datetime . now ( ) delta = timedelta ( days = 7 ) start = end - delta start_date = date ( start . year , start . month , start . day ) end_date = date ( end . year , end . month , end . day ) elif month : end = datetime . now ( ) delta = timedelta ( days = 30 ) start = end - delta start_date = date ( start . year , start . month , start . day ) end_date = date ( end . year , end . month , end . day ) else : start_date = date . today ( ) end_date = date . today ( ) projects = defaultdict ( lambda : 0 ) for record in driver . get_filtered_entries ( start_date , end_date , project = None ) : dt = datetime . strptime ( record [ 'date' ] , "%Y-%m-%d" ) record_date = date ( dt . year , dt . month , dt . day ) if record_date >= start_date and record_date <= end_date : projects [ record [ 'project' ] ] += record [ 'time' ] if not graph : print ( "\nProject Breakdown: {} to {} \n----------" . format ( start_date . strftime ( "%Y-%m-%d" ) , end_date . strftime ( "%Y-%m-%d" ) ) ) for project , spent in projects . items ( ) : print ( "{}: {}" . format ( project , human_time ( spent ) ) ) else : fig = pyplot . figure ( ) titleString = "Project Breakdown: {}" . format ( start_date . strftime ( "%Y-%m-%d" ) ) if start_date != end_date : titleString += " to {}" . format ( end_date . strftime ( "%Y-%m-%d" ) ) fig . suptitle ( titleString , fontsize = 14 , fontweight = 'bold' ) ax = fig . add_subplot ( 1 , 1 , 1 ) fig . subplots_adjust ( top = 0.85 ) num_reports = len ( projects ) my_colors = [ 'c' , 'm' , 'y' , 'r' , 'g' , 'b' ] for key in projects . keys ( ) : projects [ key ] = projects [ key ] / 60.0 if graph_type == "pie" : pyplot . axis ( 'equal' ) pyplot . pie ( projects . values ( ) , labels = list ( projects . keys ( ) ) , autopct = '%1.1f%%' , colors = my_colors , startangle = 90 ) else : ax . set_xlabel ( 'Project' ) ax . set_ylabel ( 'Hours' ) pyplot . barh ( range ( num_reports ) , projects . values ( ) , align = 'center' , color = my_colors ) pyplot . yticks ( range ( num_reports ) , list ( projects . keys ( ) ) ) pyplot . show ( ) return projects
Summarise total time spent per project instead of per day
Summarise total time spent per project instead of per day
"""Summarise total time spent per project instead of per day"""
ctx
week
month
graph
graph_type