Skip to content

Commit

Permalink
[fix] Resolve timezone issues for activity map (aimhubio#1870)
Browse files Browse the repository at this point in the history
  • Loading branch information
mihran113 committed Jun 14, 2022
1 parent 86b94f4 commit 4a7c469
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
- Change the font of the runs navigation popover (VkoHov)
- Keep color persistence state after page reload (VkoHov)
- Resolve content blinking issue after search in the run page (arsengit)
- Fix timezone issues for activity map (mihran113)

## 3.10.3 May 31, 2022

Expand Down
18 changes: 4 additions & 14 deletions aim/web/api/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
from typing import Optional, Tuple

from collections import Counter
from fastapi import Depends, HTTPException, Request, Query
from fastapi import Depends, HTTPException, Query
from aim.web.api.utils import APIRouter # wrapper for fastapi.APIRouter
from urllib import parse

from aim.web.configs import AIM_UI_TELEMETRY_KEY
from aim.web.api.projects.project import Project
Expand Down Expand Up @@ -36,26 +35,17 @@ async def project_api():


@projects_router.get('/activity/', response_model=ProjectActivityApiOut)
async def project_activity_api(request: Request, factory=Depends(object_factory)):
async def project_activity_api(factory=Depends(object_factory)):
project = Project()

if not project.exists():
raise HTTPException(status_code=404)

try:
timezone = request.cookies.get('__AIMDE__:TIMEZONE')
if timezone:
timezone = pytz.timezone(parse.unquote(timezone))
except Exception:
timezone = None
if not timezone:
timezone = pytz.timezone('gmt')

num_runs = 0
activity_counter = Counter()
for run in factory.runs():
creation_time = run.created_at.replace(tzinfo=pytz.utc).astimezone(timezone)
activity_counter[creation_time.strftime('%Y-%m-%d')] += 1
creation_time = run.created_at.replace(tzinfo=pytz.utc)
activity_counter[creation_time.strftime('%Y-%m-%dT%H:00:00')] += 1
num_runs += 1

return {
Expand Down
2 changes: 1 addition & 1 deletion tests/api/test_project_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_project_activity_api(self):
response = client.get('/api/projects/activity')
self.assertEqual(200, response.status_code)
data = response.json()
today_gmt = datetime.datetime.now().astimezone(pytz.timezone('gmt')).date().isoformat()
today_gmt = datetime.datetime.now().astimezone(pytz.timezone('gmt')).strftime('%Y-%m-%dT%H:00:00')
self.assertEqual(10, data['num_runs'])
self.assertEqual(10, data['activity_map'][today_gmt])
self.assertEqual(2, data['num_experiments']) # count 'default' experiment
Expand Down

0 comments on commit 4a7c469

Please sign in to comment.