Skip to content

Commit

Permalink
class ProjectEffort
Browse files Browse the repository at this point in the history
  • Loading branch information
andylytical committed Feb 19, 2025
1 parent df9e725 commit f91633f
Showing 1 changed file with 43 additions and 42 deletions.
85 changes: 43 additions & 42 deletions jiracmdline/task_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from simple_issue import simple_issue
import argparse
import collections
import datetime
import dateutil
import jira.exceptions
Expand All @@ -11,6 +12,28 @@
import logging
import pprint


class ProjectEffort:
'''Track effort (hours) on a project per task and per author.
'''

def __init__( self, name: str ):
self.name = name
self.tickets = collections.defaultdict( int )
self.users = collections.defaultdict( int )
self.total = 0

def add_worklog( self, ticket: str, user: str, secs: int ):
self.tickets[ticket] += secs
self.users[user] += secs
self.total += secs

def __str__( self ):
return f'<ProjectEffort ({self.name}: tickets={len(self.tickets)} time={self.total})>'

__repr__ = __str__


# Module level resources
logr = logging.getLogger( __name__ )
resources = {}
Expand Down Expand Up @@ -129,10 +152,10 @@ def issue2program( issue ):
research_system = issue.fields.customfield_10409
if prj in jira_projects:
program = jira_projects[ prj ]
elif prog_serv:
program = prog_serv[0].value
elif research_system:
program = research_system[0].value
elif prog_serv:
program = prog_serv[0].value
else:
raise UserWarning( f'No program for issue {issue}' )
pprint.pprint( f"Found program: {program}" )
Expand Down Expand Up @@ -165,60 +188,38 @@ def run( current_user=None, **kwargs ):
# raise SystemExit()

# process worklogs for each issue
user_time_per_project = {}
projects = {}
# user_time_per_project = {}
for i in issues:
pprint.pprint( [ 'ISSUE', i ] )
# if i.key != 'SVCPLAN-7069':
# continue
program = issue2program( i )
user_time = user_time_per_project.setdefault( program, {} )
project = projects.setdefault( program, ProjectEffort(program) )
# user_time = user_time_per_project.setdefault( program, {} )
# pprint.pprint( i.raw )
# raise SystemExit()
worklogs = current_user.worklogs( i )
# pprint.pprint( worklogs )
for w in worklogs:
author = w.author.name
secs = w.timeSpentSeconds
project.add_worklog( ticket=i, user=author, secs=secs )
# pprint.pprint( w.raw )
time_list = user_time.setdefault( author, [] )
time_list.append( secs )
# time_list = user_time.setdefault( author, [] )
# time_list.append( secs )
# raise SystemExit()
pprint.pprint( user_time_per_project )
# pprint.pprint( user_time_per_project )
# pprint.pprint( projects )
for k, p in projects.items():
print( f'{p.name}' )
print( f'\tTickets' )
for t, time in p.tickets.items():
print( f'\t\t{t}: {time}' )
print( f'\tUsers' )
for u, time in p.users.items():
print( f'\t\t{u}: {time}' )
print( f'\tTOTAL: {p.total}' )
raise SystemExit()

parents = {}
simple_parents = []
for key in args.issues:
try:
i = current_user.get_issue_by_key( key )
except jira.exceptions.JIRAError as e:
raise UserWarning( e.text )

i_type = current_user.get_issue_type( i )
if i_type == 'Epic':
for p in current_user.get_stories_in_epic( i ):
parents[ p.key ] = p
simple_parents.append( simple_issue.from_src( src=p, jcon=current_user.jira ) )
elif i_type == 'Story':
parents[ i.key ] = i
simple_parents.append( simple_issue.from_src( src=i, jcon=current_user.jira ) )
else:
raise UserWarning( f'Not a Story or Epic: {key}' )

simple_parents.sort()
all_issues = []

for simple_p in simple_parents:
p = parents[ simple_p.key ]
logr.debug( f"processing parent '{p}'" )
try:
children = current_user.get_linked_children( p )
except jira.exceptions.JIRAError as e:
raise UserWarning( e.text )
simple_children = [ simple_issue.from_src( src=c, jcon=current_user.jira ) for c in children ]
simple_children.sort()
all_issues.append( simple_p )
all_issues.extend( simple_children )

if args.output_format == 'text':
# for i in raw_issues:
Expand Down

0 comments on commit f91633f

Please sign in to comment.