Skip to content

Commit 2068358

Browse files
committed
Add time range conversion
1 parent e35e40f commit 2068358

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

quotientai/resources/tracing.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import gzip
21
import json
3-
from typing import List, Optional, Dict, Any
2+
import re
3+
44
from dataclasses import dataclass
5-
from datetime import datetime
5+
from datetime import datetime, timedelta
6+
from typing import Any, Dict, List, Optional
67

78
from quotientai.exceptions import logger
89

@@ -98,7 +99,7 @@ def list(
9899
List traces with optional filtering parameters.
99100
100101
Args:
101-
time_range: Optional time range filter (e.g., "1 DAY", "30 MINUTES")
102+
time_range: Optional time range filter (e.g., "1d", "1h", "1m")
102103
app_name: Optional app name filter
103104
environments: Optional list of environments to filter by
104105
compress: Whether to request compressed response
@@ -110,6 +111,11 @@ def list(
110111
params = {}
111112
if time_range:
112113
params["time_range"] = time_range
114+
# convert time range from 1d / 1h / 1m to 1 DAY / 1 HOUR / 1 MINUTE, months to MONTHS
115+
params["time_range"] = params["time_range"].replace("d", " DAY").replace("h", " HOUR").replace("m", " MINUTE").replace("M", " MONTHS")
116+
# add a space between the number and the unit
117+
params["time_range"] = re.sub(r'(\d+)([a-zA-Z]+)', r'\1 \2', params["time_range"])
118+
113119
if app_name:
114120
params["app_name"] = app_name
115121
if environments:

0 commit comments

Comments
 (0)