You are on page 1of 6

Code -1

from tabulate import tabulate

# Define the data


data = [
[1, 'Foundation', 1000, '$80,000', 1000, '$66,667', '-', 1000,
'$66,667', '-', 1000, '$66,667'],
[1, 'Framing', 4500, '$153,333', 4500, '$143,750', '-', 4500,
'$143,750', '-', 4500, '$143,750'],
[1, 'Exterior', 1800, '$63,750', 859, '$60,846', '-', 1800,
'$127,500', '-', 1800, '$127,500'],
[1, 'Roofing', 2500, '-', 1698, '$33,960', '$50,000', 2500, '$50,000',
'-', 2500, '$50,000'],
[1, 'Mechanical', 500, '-', '-', '-', '$120,000', 500, '$60,000', '-',
500, '$60,000'],
[1, 'Interior', 2550, '-', '-', '-', '$180,000', 2550, '$180,000',
'-', 2550, '$180,000'],
[1, 'Finish', 3100, '-', '-', '-', '-', '-', '-', '$16,000', 3100,
'$9,299'],

[2, 'Foundation', 1000, '$1,000', 1000, '$66,667', '-', 1000,


'$66,667', '-', 1000, '$66,667'],
[2, 'Framing', 4500, '$4,500', 2288, '$73,089', '-', 4500, '$143,750',
'-', 4500, '$143,750'],
[2, 'Exterior', 1800, '-', '-', '-', '$127,500', 1800, '$127,500',
'-', 1800, '$127,500'],
[2, 'Roofing', 2500, '-', '-', '-', '$50,000', 2500, '$50,000', '-',
2500, '$50,000'],
[2, 'Mechanical', 500, '-', '-', '-', '$120,000', '-', '-', '-', 500,
'$60,000'],
[2, 'Interior', 2550, '-', '-', '-', '$180,000', 2550, '$180,000',
'-', 2550, '$180,000'],
[2, 'Finish', 3100, '-', '-', '-', '-', '-', '-', '$16,000', 3100,
'$9,299'],

[3, 'Foundation', 1000, '$1,000', 664, '$44,267', '-', 1000,


'$66,667', '-', 1000, '$66,667'],
[3, 'Framing', 4500, '-', '-', '-', '$153,333', 4500, '$143,750', '-',
4500, '$143,750'],
[3, 'Exterior', 1800, '-', '-', '-', '$127,500', 2500, '$177,083',
'-', 1800, '$127,500'],
[3, 'Roofing', 2500, '-', '-', '-', '$50,000', '-', '-', '-', 2500,
'$50,000'],
[3, 'Mechanical', 500, '-', '-', '-', '-', '-', '-', '$120,000', 500,
'$60,000'],
[3, 'Interior', 2550, '-', '-', '-', '-', '-', '-', '$180,000', 2550,
'$180,000'],
[3, 'Finish', 3100, '-', '-', '-', '-', '-', '-', '$16,000', 3100,
'$9,299'],

[4, 'Foundation', 1000, '$1,000', '-', '-', 1000, '$66,667', '-',


1000, '$66,667'],
[4, 'Framing', 4500, '-', '-', '-', '$153,333', 4500, '$143,750', '-',
4500, '$143,750'],
[4, 'Exterior', 1800, '-', '-', '-', '$63,750', '-', '-', '$63,750',
1800, '$127,500'],
[4, 'Roofing', 2500, '-', '-', '-', '-', '$127,500', 2500, '$50,000',
2500, '$50,000'],
[4, 'Mechanical', 500, '-', '-', '-', '-', '$120,000', 500, '$60,000',
'$60,000', '$60,000'],
[4, 'Interior', 2550, '-', '-', '-', '-', '$180,000', 2550,
'$180,000', 2550, '$180,000'],
[4, 'Finish', 3100, '-', '-', '-', '-', '$16,000', 3100, '$9,299',
3100, '$9,299'],

[5, 'Foundation', 1000, '$1,000', '-', '-', '-', '-', '$80,000', '-',
'-'],
[5, 'Framing', 4500, '-', '-', '-', '$76,667', '-', '-', '$76,667',
'-'],
[5, 'Exterior', 1800, '-', '-', '-', '-', '$127,500', '-', '-', '-'],
[5, 'Roofing', 2500, '-', '-', '-', '-', '$50,000', '-', '-', '-'],
[5, 'Mechanical', 500, '-', '-', '-', '-', '$120,000', '-', '-', '-'],
[5, 'Interior', 2550, '-', '-', '-', '-', '$180,000', '-', '-', '-'],
[5, 'Finish', 3100, '-', '-', '-', '-', '$16,000', '-', '-', '-'],

headers = [
'House', 'Task', 'Amount of Work',
'Week 5 PV (CAD)', 'Week 5 Work Comp. (Quantity)', 'Week 5 EV (CAD)',
'Week 10 PV (CAD)', 'Week 10 Work Comp. (Quantity)', 'Week 10 EV
(CAD)',
'Week 27 PV (CAD)', 'Week 27 Work Comp. (Quantity)', 'Week 27 EV
(CAD)'
]

# Calculate totals for each column


totals = ['Total', '', sum(row[2] if len(row) > 2 else 0 for row in data)]
for i in range(3, len(headers)):
total_value = sum(
int(row[i].replace('$', '').replace(',', '')) if len(row) > i and
isinstance(row[i], str) and row[i] not in ('-',) else 0
for row in data
)
totals.append('${:,}'.format(total_value))

# Extract desired values from the "Total" row


total_pv_week5 = totals[3] # 4th column - Total PV of Week 5
total_ev_week5 = totals[5] # 6th column - Total EV of Week 5
total_pv_week10 = totals[6] # 7th column - Total PV of Week 10
total_ev_week10 = totals[8] # 9th column - Total EV of Week 10
total_pv_week27 = totals[9] # 10th column - Total PV of Week 27
total_ev_week27 = totals[11] # 12th column - Total EV of Week 27

# Generate the table


table = tabulate(data, headers, tablefmt="pipe", numalign="center",
stralign="center")

# Print the table with totals


print(table)

# Print the extracted values


print(f"\nTotal PV of Week 5: {total_pv_week5}")
print(f"Total EV of Week 5: {total_ev_week5}")
print(f"Total PV of Week 10: {total_pv_week10}")
print(f"Total EV of Week 10: {total_ev_week10}")
print(f"Total PV of Week 27: {total_pv_week27}")
print(f"Total EV of Week 27: {total_ev_week27}")

# AC values for each week


ac_week5 = 7392168.00
ac_week10 = 4084895.00
ac_week27 = 15294337.00

# Extract desired values from the "Total" row


total_pv_week5 = float(totals[3].replace('$', '').replace(',', '')) # 4th
column - Total PV of Week 5
total_ev_week5 = float(totals[5].replace('$', '').replace(',', '')) # 6th
column - Total EV of Week 5

total_pv_week10 = float(totals[6].replace('$', '').replace(',', '')) #


7th column - Total PV of Week 10
total_ev_week10 = float(totals[8].replace('$', '').replace(',', '')) #
9th column - Total EV of Week 10

total_pv_week27 = float(totals[9].replace('$', '').replace(',', '')) #


10th column - Total PV of Week 27
total_ev_week27 = float(totals[11].replace('$', '').replace(',', '')) #
12th column - Total EV of Week 27

# Calculate SPI, CPI, CV, and SV for each week


spi_week5 = total_ev_week5 / total_pv_week5 if total_pv_week5 != 0 else 0
cpi_week5 = total_ev_week5 / ac_week5 if ac_week5 != 0 else 0
cv_week5 = total_ev_week5 - ac_week5
sv_week5 = total_ev_week5 - total_pv_week5

spi_week10 = total_ev_week10 / total_pv_week10 if total_pv_week10 != 0


else 0
cpi_week10 = total_ev_week10 / ac_week10 if ac_week10 != 0 else 0
cv_week10 = total_ev_week10 - ac_week10
sv_week10 = total_ev_week10 - total_pv_week10

spi_week27 = total_ev_week27 / total_pv_week27 if total_pv_week27 != 0


else 0
cpi_week27 = total_ev_week27 / ac_week27 if ac_week27 != 0 else 0
cv_week27 = total_ev_week27 - ac_week27
sv_week27 = total_ev_week27 - total_pv_week27

# Print calculated performance indices and variances for each week


print("\nWeek 5 Metrics:")
print(f"SPI of Week 5: {spi_week5:.2f}")
print(f"CPI of Week 5: {cpi_week5:.2f}")
print(f"CV of Week 5: {cv_week5:.2f}")
print(f"SV of Week 5: {sv_week5:.2f}")

print("\nWeek 10 Metrics:")
print(f"SPI of Week 10: {spi_week10:.2f}")
print(f"CPI of Week 10: {cpi_week10:.2f}")
print(f"CV of Week 10: {cv_week10:.2f}")
print(f"SV of Week 10: {sv_week10:.2f}")

print("\nWeek 27 Metrics:")
print(f"SPI of Week 27: {spi_week27:.2f}")
print(f"CPI of Week 27: {cpi_week27:.2f}")
print(f"CV of Week 27: {cv_week27:.2f}")
print(f"SV of Week 27: {sv_week27:.2f}")
# Print project status messages based on SPI and CPI for each week
print("\033[1m\nProject Status Messages:\033[0m")
print("\033[1mWeek 5:\033[0m")
if spi_week5 > 1:
print("\033[1mThe project is ahead of schedule\033[0m")
else:
print("\033[1mThe project is behind schedule\033[0m")

if cpi_week5 > 1:
print("\033[1mThe project is under budget\033[0m")
else:
print("\033[1mThe project is over budget\033[0m")

print("\033[1m\nWeek 10:\033[0m")
if spi_week10 > 1:
print("\033[1mThe project is ahead of schedule\033[0m")
else:
print("\033[1mThe project is behind schedule\033[0m")

if cpi_week10 > 1:
print("\033[1mThe project is under budget\033[0m")
else:
print("\033[1mThe project is over budget\033[0m")

print("\033[1m\nWeek 27:\033[0m")
if spi_week27 > 1:
print("\033[1mThe project is ahead of schedule\033[0m")
else:
print("\033[1mThe project is behind schedule\033[0m")

if cpi_week27 > 1:
print("\033[1mThe project is under budget\033[0m")
else:
print("\033[1mThe project is over budget\033[0m")

Code-2
from tabulate import tabulate

# Define the data


data = [
[1, 'Foundation', 1, 0, 0.29, 0.29, 1.00, 1.00, 1, 5, 1, 5],
[2, 'Framing', 2, 0, 0.29, 0.57, 1.00, 0.50, 3, 11, 3, 11],
[3, 'Exterior', 2, 0, 0.29, 0.57, 1.00, 0.50, 5, 13, 5, 13],
[4, 'Roofing', 1, 1, 0.27, 0.27, 1.00, 1.00, 4, 8, 8, 12],
[5, 'Mechnical', 1, 2, 0.25, 0.25, 1.00, 1.00, 6, 10, 10, 14],
[6, 'Interior', 3, 0, 0.29, 0.86, 1.00, 0.33, 8, 20, 11, 23],
[7, 'Finish', 1, 0, 0.29, 0.29, 1.00, 1.00, 9, 13, 20, 24],
]

headers = [
'Activity No.', 'Activity', 'Duration', 'Total Float', 'Desired Rate',
'Calculated Crews', 'Actual Crew', 'Actual Rate', 'First Unit',
'Last Unit', 'Adjusted First Unit', 'Adjusted Last Unit'
]

# Generate the table


table = tabulate(data, headers, tablefmt="pipe", numalign="center",
stralign="center")

# Print the table


print(table)

You might also like