mirror of
https://github.com/temporal-community/temporal-ai-agent.git
synced 2026-03-16 22:48:09 +01:00
Enhance Dev Experience and Code Quality (#41)
* Format codebase to satisfy linters * fixing pylance and ruff-checked files * contributing md, and type and formatting fixes * setup file capitalization * test fix
This commit is contained in:
committed by
GitHub
parent
e35181b5ad
commit
eb06cf5c8d
@@ -1,11 +1,10 @@
|
||||
def book_pto(args: dict) -> dict:
|
||||
|
||||
email = args.get("email")
|
||||
start_date = args.get("start_date")
|
||||
end_date = args.get("end_date")
|
||||
|
||||
print(f"[BookPTO] Totally would send an email confirmation of PTO from {start_date} to {end_date} to {email} here!")
|
||||
print(
|
||||
f"[BookPTO] Totally would send an email confirmation of PTO from {start_date} to {end_date} to {email} here!"
|
||||
)
|
||||
|
||||
return {
|
||||
"status": "success"
|
||||
}
|
||||
return {"status": "success"}
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
from pathlib import Path
|
||||
import json
|
||||
|
||||
|
||||
def checkpaybankstatus(args: dict) -> dict:
|
||||
|
||||
email = args.get("email")
|
||||
|
||||
if email == "grinch@grinch.com":
|
||||
@@ -12,4 +7,4 @@ def checkpaybankstatus(args: dict) -> dict:
|
||||
|
||||
# could do logic here or look up data but for now everyone but the grinch is getting paid
|
||||
return_msg = "connected"
|
||||
return {"status": return_msg}
|
||||
return {"status": return_msg}
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
from pathlib import Path
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def current_pto(args: dict) -> dict:
|
||||
|
||||
email = args.get("email")
|
||||
|
||||
file_path = Path(__file__).resolve().parent.parent / "data" / "employee_pto_data.json"
|
||||
file_path = (
|
||||
Path(__file__).resolve().parent.parent / "data" / "employee_pto_data.json"
|
||||
)
|
||||
if not file_path.exists():
|
||||
return {"error": "Data file not found."}
|
||||
|
||||
|
||||
data = json.load(open(file_path))
|
||||
employee_list = data["theCompany"]["employees"]
|
||||
|
||||
for employee in employee_list:
|
||||
if employee["email"] == email:
|
||||
num_hours = int(employee["currentPTOHrs"])
|
||||
num_days = float(num_hours/8)
|
||||
num_days = float(num_hours / 8)
|
||||
return {
|
||||
"num_hours": num_hours,
|
||||
"num_days": num_days,
|
||||
}
|
||||
|
||||
|
||||
return_msg = "Employee not found with email address " + email
|
||||
return {"error": return_msg}
|
||||
return {"error": return_msg}
|
||||
|
||||
@@ -1,43 +1,59 @@
|
||||
import json
|
||||
import pandas
|
||||
from pathlib import Path
|
||||
from datetime import date, datetime
|
||||
from pathlib import Path
|
||||
|
||||
import pandas
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
|
||||
def future_pto_calc(args: dict) -> dict:
|
||||
|
||||
file_path = Path(__file__).resolve().parent.parent / "data" / "employee_pto_data.json"
|
||||
file_path = (
|
||||
Path(__file__).resolve().parent.parent / "data" / "employee_pto_data.json"
|
||||
)
|
||||
if not file_path.exists():
|
||||
return {"error": "Data file not found."}
|
||||
|
||||
|
||||
start_date = datetime.strptime(args.get("start_date"), "%Y-%m-%d").date()
|
||||
end_date = datetime.strptime(args.get("end_date"), "%Y-%m-%d").date()
|
||||
email = args.get("email")
|
||||
|
||||
#Next, set up the ability to calculate how much PTO will be added to the user's total by the start of the PTO request
|
||||
# Next, set up the ability to calculate how much PTO will be added to the user's total by the start of the PTO request
|
||||
today = date.today()
|
||||
|
||||
if today > start_date:
|
||||
return_msg = "PTO start date " + args.get("start_date") + "cannot be in the past"
|
||||
return_msg = (
|
||||
"PTO start date " + args.get("start_date") + "cannot be in the past"
|
||||
)
|
||||
return {"error": return_msg}
|
||||
|
||||
|
||||
if end_date < start_date:
|
||||
return_msg = "PTO end date " + args.get("end_date") + " must be after PTO start date " + args.get("start_date")
|
||||
return_msg = (
|
||||
"PTO end date "
|
||||
+ args.get("end_date")
|
||||
+ " must be after PTO start date "
|
||||
+ args.get("start_date")
|
||||
)
|
||||
return {"error": return_msg}
|
||||
|
||||
#Get the number of business days, and then business hours (assume 8 hr biz day), included in the PTO request
|
||||
biz_days_of_request = len(pandas.bdate_range(start=start_date, end=end_date, inclusive="both"))
|
||||
|
||||
# Get the number of business days, and then business hours (assume 8 hr biz day), included in the PTO request
|
||||
biz_days_of_request = len(
|
||||
pandas.bdate_range(start=start_date, end=end_date, inclusive="both")
|
||||
)
|
||||
if biz_days_of_request == 0:
|
||||
return_msg = "There are no business days between " + args.get("start_date") + " and " + args.get("end_date")
|
||||
return_msg = (
|
||||
"There are no business days between "
|
||||
+ args.get("start_date")
|
||||
+ " and "
|
||||
+ args.get("end_date")
|
||||
)
|
||||
return {"error": return_msg}
|
||||
biz_hours_of_request = biz_days_of_request * 8
|
||||
|
||||
#Assume PTO is added on the first of every month - month math compares rolling dates, so compare the PTO request with the first day of the current month.
|
||||
|
||||
# Assume PTO is added on the first of every month - month math compares rolling dates, so compare the PTO request with the first day of the current month.
|
||||
today_first_of_month = date(today.year, today.month, 1)
|
||||
time_difference = relativedelta(start_date, today_first_of_month)
|
||||
months_to_accrue = time_difference.years * 12 + time_difference.months
|
||||
|
||||
|
||||
data = json.load(open(file_path))
|
||||
employee_list = data["theCompany"]["employees"]
|
||||
|
||||
@@ -47,12 +63,14 @@ def future_pto_calc(args: dict) -> dict:
|
||||
if employee["email"] == email:
|
||||
current_pto_hours = int(employee["currentPTOHrs"])
|
||||
hrs_added_per_month = int(employee["hrsAddedPerMonth"])
|
||||
pto_available_at_start = current_pto_hours + (months_to_accrue * hrs_added_per_month)
|
||||
pto_available_at_start = current_pto_hours + (
|
||||
months_to_accrue * hrs_added_per_month
|
||||
)
|
||||
pto_hrs_remaining_after = pto_available_at_start - biz_hours_of_request
|
||||
if pto_hrs_remaining_after >= 0:
|
||||
enough_pto = True
|
||||
return {
|
||||
"enough_pto": enough_pto,
|
||||
"enough_pto": enough_pto,
|
||||
"pto_hrs_remaining_after": str(pto_hrs_remaining_after),
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user