Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
slacrherbst committed Jan 17, 2025
1 parent c159a12 commit e9bc44b
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 40 deletions.
19 changes: 18 additions & 1 deletion check_active_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
else:
backupDir = None

resourceTable={}

for k in args.div:

div = tid_ss_lib_v3.configuration.get_division(client=client, div=k)
Expand All @@ -114,5 +116,20 @@
lst.append(p['id'])

for p in lst:
tid_ss_lib_v3.navigate.check_project(client=client, div=div, folderId=p, doFixes=args.fix, doCost=args.doCost, doDownload=doDownload, doTask=args.doTask)

if p.... :
rt = resourceTable
else:
rt = None

tid_ss_lib_v3.navigate.check_project(client=client,
div=div,
folderId=p,
doFixes=args.fix,
doCost=args.doCost,
doDownload=doDownload,
doTask=args.doTask,
resourceTable=rt)

print(resourceTable)

12 changes: 7 additions & 5 deletions tid_ss_lib_v3/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,20 @@ def get_division(*, client, div):


def get_user_map(*, client, div):
userMap = {}
userMapByName = {}
userMapByEmail = {}

sheet = client.Sheets.get_sheet(int(div.wbs_name_lookup))

# Process the rows
for rowIdx in range(0,len(sheet.rows)):
key = sheet.rows[rowIdx].cells[0].value
value = sheet.rows[rowIdx].cells[1].value
name = sheet.rows[rowIdx].cells[0].value
email = sheet.rows[rowIdx].cells[1].value

userMap[key] = value
userMapByName[name] = email
userMapByEmail[email] = name

return userMap
return userMapByName, userMapByEmail


def add_missing_user_map(*, client, div, miss):
Expand Down
6 changes: 3 additions & 3 deletions tid_ss_lib_v3/division_actuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def parse_wbs_actuals_sheet(*, client, div, sheetId, year, paData, projData):

find_columns(client=client, sheet=sheet, cData=cData)

userMap = configuration.get_user_map(client=client, div=div)
userMapByName, userMapBYEmail = configuration.get_user_map(client=client, div=div)
missMap = set()

# Process the rows
Expand All @@ -195,8 +195,8 @@ def parse_wbs_actuals_sheet(*, client, div, sheetId, year, paData, projData):

name = entry['Employee Name']

if name in userMap:
email = userMap[name]
if name in userMapByName:
email = userMapByName[name]
else:
print(f"User name {name} not found in email map")
missMap.add(name)
Expand Down
4 changes: 2 additions & 2 deletions tid_ss_lib_v3/navigate.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_folder_data(*, client, div, folderId, path=None):
return ret


def check_project(*, client, div, folderId, doFixes, doCost="None", doDownload=False, path=None, doTask=False):
def check_project(*, client, div, folderId, doFixes, doCost=None, doDownload=False, path=None, doTask=False, resourceTable=None):
fdata = get_folder_data(client=client, div=div, folderId=folderId)

if path is not None:
Expand Down Expand Up @@ -120,7 +120,7 @@ def check_project(*, client, div, folderId, doFixes, doCost="None", doDownload=F

# Check project file
resources = set()
ret = project_sheet.check(client=client, div=div, sheet=fdata['sheets']['Project'], doFixes=doFixes, cData=cData, doCost=doCost, name=fdata['folder'].name, doDownload=doDownload, doTask=doTask, resources=resources)
ret = project_sheet.check(client=client, div=div, sheet=fdata['sheets']['Project'], doFixes=doFixes, cData=cData, doCost=doCost, name=fdata['folder'].name, doDownload=doDownload, doTask=doTask, resources=resources, resourceTable=resourceTable)

# Fix tracking file
if ret:
Expand Down
86 changes: 57 additions & 29 deletions tid_ss_lib_v3/project_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import smartsheet
from . import navigate
from . import project_sheet_columns
from . import configuration

import datetime

Expand Down Expand Up @@ -216,15 +217,18 @@ def cost_ms(*, sheet, rowIdx, cData, msTable):
msTable[k] += (qty * perItem)


def cost_labor(*, sheet, rowIdx, cData, laborTable, doCost):
def cost_labor(*, client, div, sheet, rowIdx, cData, laborTable, resourceTable, doCost):

userMapByName, userMapByEmail = configuration.get_user_map(client=client, div=div)

if sheet.rows[rowIdx].cells[cData['Task']['position']].value is None or \
sheet.rows[rowIdx].cells[cData['Task']['position']].value == '':
sheet.rows[rowIdx].cells[cData['Task']['position']].value == '' or \
sheet.rows[rowIdx].cells[cData['Assigned To']['position']].value is None or \
sheet.rows[rowIdx].cells[cData['Assigned To']['position']].value == '':
return

# Extract key columns

if doCost == "Contingency":
if doCost == 'Contingency':
hours = float(sheet.rows[rowIdx].cells[cData['Contingency Hours']['position']].value)
else:
hours = float(sheet.rows[rowIdx].cells[cData['Budgeted Quantity']['position']].value)
Expand All @@ -236,9 +240,23 @@ def cost_labor(*, sheet, rowIdx, cData, laborTable, doCost):
if endStr is None or startStr is None:
return

# Add entry to resourceTable is applicable
resource = sheet.rows[rowIdx].cells[cData['Assigned To']['position']].value

# Convert email to name
if resource in userMapByEmail:
resource = userMapByEmail[resource]

if resourceTable is not None:
if resource not in resourceTable:
resourceTable[resource] = {sheet.name: {}}

if sheet.name not in resourceTable[resource]:
resourceTable[resource][sheet.name] = {}

# Split date fields
startFields = startStr.split('T')[0].split('-') # Start date fields
endFields = endStr.split('T')[0].split('-') # End date fields
endFields = endStr.split('T')[0].split('-') # End date fields

# Convert to python date object
startDate = datetime.date(int(startFields[0]),int(startFields[1]),int(startFields[2]))
Expand Down Expand Up @@ -267,17 +285,26 @@ def cost_labor(*, sheet, rowIdx, cData, laborTable, doCost):

# Add year/month to dictionary if it does not exist
if k not in laborTable:
laborTable[k] = {rate: 0.0}
laborTable[k] = {resource: {'rate' : rate, 'hours' : 0.0}}

# Add rate to sub-dictionrary for month
elif rate not in laborTable[k]:
laborTable[k][rate] = 0.0
elif resource not in laborTable[k]:
laborTable[k][resource] = {'rate' : rate, 'hours' : 0.0}

# Increment the number of hours in that year/month, for the given rate
laborTable[k][rate] += hoursPerDay
laborTable[k][resource]['hours'] += hoursPerDay

if resourceTable is not None:

# Add year/month to dictionary if it does not exist
if k not in resourceTable[resource][sheet.name]:
resourceTable[resource][sheet.name][k] = 0.0

# Increment the number of hours in that year/month, for the given rate
resourceTable[resource][sheet.name][k] += hoursPerDay

def check(*, client, sheet, doFixes, div, cData, doCost, name, doDownload, doTask, resources):

def check(*, client, sheet, doFixes, div, cData, doCost, name, doDownload, doTask, resources, resourceTable):
inLabor = False
inMS = False
msTable = {}
Expand Down Expand Up @@ -325,7 +352,7 @@ def check(*, client, sheet, doFixes, div, cData, doCost, name, doDownload, doTas
check_row(client=client, sheet=sheet, rowIdx=rowIdx, key='ms_parent', div=div, cData=cData, doFixes=doFixes, doTask=doTask, resources=None)
else:
check_row(client=client, sheet=sheet, rowIdx=rowIdx, key='ms_task', div=div, cData=cData, doFixes=doFixes, doTask=doTask, resources=None)
if doCost != "None":
if doCost != 'None':
cost_ms(sheet=sheet, rowIdx=rowIdx, cData=cData, msTable=msTable)

elif inLabor:
Expand All @@ -336,12 +363,11 @@ def check(*, client, sheet, doFixes, div, cData, doCost, name, doDownload, doTas
else:
check_row(client=client, sheet=sheet, rowIdx=rowIdx, key='labor_task', div=div, cData=cData, doFixes=doFixes, doTask=doTask, resources=resources)

if doCost != "None":
cost_labor(sheet=sheet, rowIdx=rowIdx, cData=cData, laborTable=laborTable, doCost=doCost)

if doCost != 'None' or resourceTable is not None:
cost_labor(client=client, div=div, sheet=sheet, rowIdx=rowIdx, cData=cData, laborTable=laborTable, resourceTable=resourceTable, doCost=doCost)

# Generate excel friend view of monthly spending
if doCost != "None":
if doCost != 'None':
write_cost_table(name=name, laborTable=laborTable, msTable=msTable)

if isinstance(doDownload,str):
Expand All @@ -354,29 +380,29 @@ def write_cost_table(*, name, laborTable, msTable):

# Generate excel friend view of monthly spending
months = set([])
rates = set([])
resources = set([])

# First generate month and rate lists to create excel grid
for mnth in laborTable:
months.add(mnth)
for rte in laborTable[mnth]:
rates.add(rte)
for res in laborTable[mnth]:
resources.add(res)

for mnth in msTable:
months.add(mnth)

months = sorted(months)
rates = sorted(rates)
resources = sorted(resources)

with open(f'{name} Cost.csv', 'w') as f:

# Create Header
f.write('Month,M&S,')
f.write('Month\tM&S\t')

for rte in rates:
f.write(f'{float(rte):0.2f} Hours, {float(rte):0.2f} Dollars,')
for k in resources:
f.write(f'{k} Rate\t{k} Hours\t{k} Dollars\t')

f.write("Total Labor Hours, Total Labor Dollars, Total Dollars\n")
f.write("Total Labor Hours\tTotal Labor Dollars\tTotal Dollars\n")

# Each month
for m in months:
Expand All @@ -390,23 +416,25 @@ def write_cost_table(*, name, laborTable, msTable):
else:
val = 0.0

f.write(f'{m}, {val:0.2f},')
f.write(f'{m}\t{val:0.2f}\t')
totDollars += val

# Put in Labor
for rte in rates:
if m in laborTable and rte in laborTable[m]:
hrs = float(laborTable[m][rte])
for res in resources:
if m in laborTable and res in laborTable[m]:
rte = float(laborTable[m][res]['rate'])
hrs = float(laborTable[m][res]['hours'])
val = float(hrs) * float(rte)
else:
rte = 0.0
hrs = 0.0
val = 0.0

totLabHours += hrs
totLabDollars += val
totDollars += val

f.write(f'{hrs:0.2f}, {val:0.2f},')
f.write(f'{rte}\t{hrs:0.2f}\t{val:0.2f}\t')

f.write(f"{totLabHours:0.2f}, {totLabDollars:0.2f},{totDollars:0.2f}\n")
f.write(f"{totLabHours:0.2f}\t{totLabDollars:0.2f}\t{totDollars:0.2f}\n")

0 comments on commit e9bc44b

Please sign in to comment.