Skip to content

Commit

Permalink
♻️ refactor lambda_handler to streamline fare calculation and remove …
Browse files Browse the repository at this point in the history
…commented code
  • Loading branch information
LokoMoloko98 committed Jan 25, 2025
1 parent 0b9a405 commit de20cdb
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions swift-lift-fare-calculation/swift-lift-fare-calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ def lambda_handler(event, context):
}
try:
print("Processing")
# print(event)

# Extract passenger_id and total trips from the event
passenger_id = event.get('passenger_id')
Expand All @@ -129,32 +128,12 @@ def lambda_handler(event, context):
missed_trips = len(missed_trips_list)
total_trips = 10 # Expected Total trips in a week
print(f"Total trips for the week beginning on {target_week}: {total_trips}, Missed trips: {missed_trips}")

# # Calculate the discount threshold
# discount_threshold = ceil(total_trips * 0.4)

# # Calculate eligible missed trips for discount
# eligible_missed_trips = max(0, missed_trips - discount_threshold)
# discount_per_trip = 0.15 * 350 # 15% of R350
# total_discount = eligible_missed_trips * discount_per_trip

# # Calculate the final fare
# final_fare = 350 - total_discount
# final_fare = max(final_fare, 0) # Ensure fare is not negative
result = calculate_fare(total_trips=10, missed_trips=10, weekly_fare=350)

# Calculate the final fare
result = calculate_fare(total_trips=total_trips, missed_trips=missed_trips, weekly_fare=350) # Default weekly fare is 350 for now, will fecth from users DB later
final_fare = result['final_fare']
print(f"Final fare calculated: R{final_fare}")

# result = {
# "passenger_id": passenger_id,
# "total_trips": total_trips,
# "missed_trips": missed_trips,
# "discount_threshold": discount_threshold,
# "eligible_missed_trips": eligible_missed_trips,
# "total_discount": total_discount,
# "final_fare": final_fare
# }

return {
'statusCode': statusCode,
'body': json.dumps(result),
Expand Down

0 comments on commit de20cdb

Please sign in to comment.