Skip to content

Instantly share code, notes, and snippets.

@asad-albadi
Created October 21, 2023 10:48
Show Gist options
  • Save asad-albadi/e18dfe9a920930f42f4d6e82404da3ac to your computer and use it in GitHub Desktop.
Save asad-albadi/e18dfe9a920930f42f4d6e82404da3ac to your computer and use it in GitHub Desktop.
def calculate_3d_printing_cost(filament_weight_grams, print_dimensions_mm3, print_time_hhmm):
# Constants (same as before)
filament_cost_per_kg_omr = 11.5
hourly_rate_it_engineer_omr = 5#9.69
electricity_cost_per_kwh_omr = 1.764
power_consumption_watts = 120
fixed_fee_per_hour_omr = 0.21
margin_percentage = 30
# Convert dimensions from mm^3 to cm^3
print_dimensions_cm3 = print_dimensions_mm3 / 1000
# Convert the time in "hh:mm" format to hours
time_parts = print_time_hhmm.split(':')
if len(time_parts) != 2:
raise ValueError("Invalid time format. Please use 'hh:mm' format.")
hours = int(time_parts[0])
minutes = int(time_parts[1])
print_time_hours = hours + minutes / 60.0
# Calculate Material Cost (in OMR)
material_cost_omr = (filament_cost_per_kg_omr / 1000) * filament_weight_grams
# Calculate Labor Cost (in OMR)
labor_cost_omr = hourly_rate_it_engineer_omr * print_time_hours
# Calculate Electricity Cost (in OMR)
electricity_cost_omr = (electricity_cost_per_kwh_omr * power_consumption_watts * print_time_hours) / 1000
# Calculate Printer Operation Cost (in OMR)
printer_operation_cost_omr = fixed_fee_per_hour_omr * print_time_hours
# Calculate Margin (in OMR)
margin_omr = (margin_percentage / 100) * material_cost_omr
# Calculate Total Cost (in OMR)
total_cost_omr = material_cost_omr + labor_cost_omr + electricity_cost_omr + printer_operation_cost_omr + margin_omr
return total_cost_omr
# Example usage:
filament_weight = 19 # grams
dimensions_mm3 = 54.4444 * 60.3941 * 60.4325 # mm^3
print_time_hhmm = "2:21" # hh:mm format
total_cost = calculate_3d_printing_cost(filament_weight, dimensions_mm3, print_time_hhmm)
print(f"Amount to charge the customer: {total_cost:.2f} OMR")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment