Skip to content

Commit

Permalink
set local timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
PacificDou committed Nov 26, 2024
1 parent 214009b commit 3eee5b3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
14 changes: 12 additions & 2 deletions roboflow/adapters/deploymentapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,25 @@ def list_deployment(api_key):


def get_workspace_usage(api_key, from_timestamp, to_timestamp):
url = f"{DEDICATED_DEPLOYMENT_URL}/usage_workspace?api_key={api_key}&from_timestamp={from_timestamp.isoformat()}&to_timestamp={to_timestamp.isoformat()}"
params = {"api_key": api_key}
if from_timestamp is not None:
params["from_timestamp"] = from_timestamp.isoformat() # may contain + sign
if to_timestamp is not None:
params["to_timestamp"] = to_timestamp.isoformat() # may contain + sign
url = f"{DEDICATED_DEPLOYMENT_URL}/usage_workspace?{urllib.parse.urlencode(params)}"
response = requests.get(url)
if response.status_code != 200:
return response.status_code, response.text
return response.status_code, response.json()


def get_deployment_usage(api_key, deployment_name, from_timestamp, to_timestamp):
url = f"{DEDICATED_DEPLOYMENT_URL}/usage_deployment?api_key={api_key}&deployment_name={deployment_name}&from_timestamp={from_timestamp.isoformat()}&to_timestamp={to_timestamp.isoformat()}"
params = {"api_key": api_key, "deployment_name": deployment_name}
if from_timestamp is not None:
params["from_timestamp"] = from_timestamp.isoformat() # may contain + sign
if to_timestamp is not None:
params["to_timestamp"] = to_timestamp.isoformat() # may contain + sign
url = f"{DEDICATED_DEPLOYMENT_URL}/usage_deployment?{urllib.parse.urlencode(params)}"
response = requests.get(url)
if response.status_code != 200:
return response.status_code, response.text
Expand Down
10 changes: 5 additions & 5 deletions roboflow/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ def check_from_to_timestamp(from_timestamp, to_timestamp, default_timedelta):
print("Please provide a valid to_timestamp in ISO8601 format")
exit(1)

time_now = datetime.now().replace(tzinfo=None)
time_now = datetime.now().astimezone() # local timezone
if from_timestamp is None and to_timestamp is None:
from_timestamp = time_now - default_timedelta
to_timestamp = time_now
elif from_timestamp is not None and to_timestamp is None:
from_timestamp = datetime.fromisoformat(from_timestamp).replace(tzinfo=None)
from_timestamp = datetime.fromisoformat(from_timestamp).astimezone()
to_timestamp = from_timestamp + default_timedelta
elif from_timestamp is None and to_timestamp is not None:
to_timestamp = datetime.fromisoformat(to_timestamp).replace(tzinfo=None)
to_timestamp = datetime.fromisoformat(to_timestamp).astimezone()
from_timestamp = to_timestamp - default_timedelta
else:
from_timestamp = datetime.fromisoformat(from_timestamp).replace(tzinfo=None)
to_timestamp = datetime.fromisoformat(to_timestamp).replace(tzinfo=None)
from_timestamp = datetime.fromisoformat(from_timestamp).astimezone()
to_timestamp = datetime.fromisoformat(to_timestamp).astimezone()
if from_timestamp >= to_timestamp:
print("from_timestamp should be earlier than to_timestamp")
exit(1)
Expand Down

0 comments on commit 3eee5b3

Please sign in to comment.