agent: |
WkqQtVr10BRb4bZcm0zgParse the period string
Parse the period string
There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.
inputs
outputs
import re
import math
import datetime
period = period_str
max_data_points = 1430
tt = re.search("(\d+)\s*d|(\d+)\s*day|(\d+)\s*days", period_str, re.IGNORECASE)
if tt:
days = tt.group(1)
period = int(days) * 3600 *24
tt = re.search("(\d+)\s*h|(\d+)\s*hr|(\d+)\s*hrs|(\d+)\s*hour|(\d+)\s*hours", period_str, re.IGNORECASE)
if tt:
hours = tt.group(1)
period = int(hours) * 3600
tt = re.search("(\d+)\s*m|(\d+)\s*min|(\d+)\s*mins|(\d+)\s*minute|(\d+)\s*minutes", period_str, re.IGNORECASE)
if tt:
minutes = tt.group(1)
period = int(minutes) * 60
interval = 1
if math.ceil(period) <= 1440:
interval = 1
elif math.ceil(period/5) <= 1440:
interval = 5
elif math.ceil(period/10) <= 1440:
interval = 10
elif math.ceil(period/30) <= 1440:
interval = 30
else:
interval = math.ceil(period/max_data_points)
interval = 60*math.ceil(interval/60)
interval = str(interval)
now = datetime.datetime.now().timestamp()
end_time = datetime.datetime.now().isoformat()
then = now - period
start_time = datetime.datetime.fromtimestamp(then).isoformat()
print("Start time: ", start_time)
print("End time: ", end_time)
print("Interval: ", interval)
copied