Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visualizations #22

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
22 changes: 22 additions & 0 deletions backend/app/app/api/api_v1/endpoints/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,25 @@ def read_leaderboard(
if isinstance(top_users, json.decoder.JSONDecodeError):
raise HTTPException(status_code=556, detail="Scheduler malfunction")
return top_users


@router.get("/visualizations", response_model=List[schemas.Visualization])
def read_visualization(
*,
db: Session = Depends(deps.get_db),
deck_id: int = None,
date_start: datetime = None,
date_end: datetime = None,
current_user: models.User = Depends(deps.get_current_active_user),
) -> Any:
"""
Retrieves leaderboard of users since the specified start time, or all time otherwise
"""

top_users = interface.statistics.get_user_visualizations(db=db, user=current_user, date_start=date_start,
date_end=date_end, deck_id=deck_id)
if isinstance(top_users, requests.exceptions.RequestException):
raise HTTPException(status_code=555, detail="Connection to scheduler is down")
if isinstance(top_users, json.decoder.JSONDecodeError):
raise HTTPException(status_code=556, detail="Scheduler malfunction")
return top_users
28 changes: 28 additions & 0 deletions backend/app/app/interface/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,34 @@ def get_leaderboard(db: Session, rank_type: schemas.RankType, user: models.user,
return e


def get_user_visualizations(db: Session, user: models.user, *, date_start: datetime = None, date_end: datetime = None,
deck_id: int = None) -> Union[
List[schemas.Visualization], requests.exceptions.RequestException, json.decoder.JSONDecodeError]:
parameters = {'user_id': user.id, 'env': settings.ENVIRONMENT}
# if date_start:
# parameters['date_start'] = date_start
# if date_end:
# parameters['date_end'] = date_end
# if deck_id:
# parameters['deck_id'] = deck_id
try:
request = requests.get(f"{settings.INTERFACE}api/karl/get_user_charts", params=parameters)
logger.info(request.url)
visualization_dict = request.json()

visualizations = []
for visualization in visualization_dict:
logger.info(visualization["specs"])
visualizations.append(schemas.Visualization(**visualization))
return visualizations
except requests.exceptions.RequestException as e:
capture_exception(e)
return e
except json.decoder.JSONDecodeError as e:
capture_exception(e)
return e


def create_name(db: Session, date_start: datetime = None, date_end: datetime = None, deck_id: int = None):
name = ""

Expand Down
1 change: 1 addition & 0 deletions backend/app/app/schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
from .file_props import FileProps
from .rank_type import RankType
from .leaderboard import LeaderboardUser, Leaderboard, DataTypeHeader
from .visualization import Visualization

6 changes: 6 additions & 0 deletions backend/app/app/schemas/visualization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from pydantic import BaseModel, Json


class Visualization(BaseModel):
name: str
specs: str
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ services:
# You also have to change the flower command

flower:
image: mher/flower
image: mher/flower:0.9.5
networks:
- ${TRAEFIK_PUBLIC_NETWORK?Variable not set}
- default
Expand Down
Loading