Add AI insights feature
This commit is contained in:
@@ -174,42 +174,81 @@ def resolve_time_marker(
|
||||
# Just "BASE_TS" - return session_created_at
|
||||
return session_created_at
|
||||
|
||||
# Parse operator and value
|
||||
operator = offset_part[0]
|
||||
value_part = offset_part[1:].strip()
|
||||
# Handle complex multi-operation markers like "- 30d 6h + 4h 5m"
|
||||
# Split by operators to handle multiple operations
|
||||
import re
|
||||
|
||||
if operator not in ['+', '-']:
|
||||
raise ValueError(f"Invalid operator in time marker: {time_marker}")
|
||||
# Parse all operations in the format: [operator][value]
|
||||
# Pattern matches: optional whitespace, operator (+/-), number with optional decimal, unit (d/h/m)
|
||||
pattern = r'\s*([+-])\s*(\d+\.?\d*)\s*([dhm])'
|
||||
operations = []
|
||||
|
||||
# Parse time components (supports decimals like 0.5d, 1.25h)
|
||||
days = 0.0
|
||||
hours = 0.0
|
||||
minutes = 0.0
|
||||
|
||||
if 'd' in value_part:
|
||||
# Handle days (supports decimals like 0.5d = 12 hours)
|
||||
day_part, rest = value_part.split('d', 1)
|
||||
days = float(day_part)
|
||||
value_part = rest
|
||||
|
||||
if 'h' in value_part:
|
||||
# Handle hours (supports decimals like 1.5h = 1h30m)
|
||||
hour_part, rest = value_part.split('h', 1)
|
||||
hours = float(hour_part)
|
||||
value_part = rest
|
||||
|
||||
if 'm' in value_part:
|
||||
# Handle minutes (supports decimals like 30.5m)
|
||||
minute_part = value_part.split('m', 1)[0]
|
||||
minutes = float(minute_part)
|
||||
|
||||
# Calculate offset using float values
|
||||
offset = timedelta(days=days, hours=hours, minutes=minutes)
|
||||
# Find all operations in the string
|
||||
for match in re.finditer(pattern, offset_part):
|
||||
operator = match.group(1)
|
||||
value = float(match.group(2))
|
||||
unit = match.group(3)
|
||||
operations.append((operator, value, unit))
|
||||
|
||||
if operator == '+':
|
||||
return session_created_at + offset
|
||||
else:
|
||||
return session_created_at - offset
|
||||
if not operations:
|
||||
# Fallback to old simple parsing for backwards compatibility
|
||||
operator = offset_part[0]
|
||||
value_part = offset_part[1:].strip()
|
||||
|
||||
if operator not in ['+', '-']:
|
||||
raise ValueError(f"Invalid operator in time marker: {time_marker}")
|
||||
|
||||
# Parse time components (supports decimals like 0.5d, 1.25h)
|
||||
days = 0.0
|
||||
hours = 0.0
|
||||
minutes = 0.0
|
||||
|
||||
if 'd' in value_part:
|
||||
# Handle days (supports decimals like 0.5d = 12 hours)
|
||||
day_part, rest = value_part.split('d', 1)
|
||||
days = float(day_part)
|
||||
value_part = rest
|
||||
|
||||
if 'h' in value_part:
|
||||
# Handle hours (supports decimals like 1.5h = 1h30m)
|
||||
hour_part, rest = value_part.split('h', 1)
|
||||
hours = float(hour_part)
|
||||
value_part = rest
|
||||
|
||||
if 'm' in value_part:
|
||||
# Handle minutes (supports decimals like 30.5m)
|
||||
minute_part = value_part.split('m', 1)[0]
|
||||
minutes = float(minute_part)
|
||||
|
||||
# Calculate offset using float values
|
||||
offset = timedelta(days=days, hours=hours, minutes=minutes)
|
||||
|
||||
if operator == '+':
|
||||
return session_created_at + offset
|
||||
else:
|
||||
return session_created_at - offset
|
||||
|
||||
# Process multiple operations
|
||||
result_time = session_created_at
|
||||
|
||||
for operator, value, unit in operations:
|
||||
if unit == 'd':
|
||||
offset = timedelta(days=value)
|
||||
elif unit == 'h':
|
||||
offset = timedelta(hours=value)
|
||||
elif unit == 'm':
|
||||
offset = timedelta(minutes=value)
|
||||
else:
|
||||
raise ValueError(f"Invalid time unit '{unit}' in time marker: {time_marker}")
|
||||
|
||||
if operator == '+':
|
||||
result_time = result_time + offset
|
||||
elif operator == '-':
|
||||
result_time = result_time - offset
|
||||
else:
|
||||
raise ValueError(f"Invalid operator '{operator}' in time marker: {time_marker}")
|
||||
|
||||
return result_time
|
||||
|
||||
|
||||
def shift_to_session_time(
|
||||
|
||||
Reference in New Issue
Block a user