Skip to content

Commit

Permalink
fix: (part) cloud status of project command
Browse files Browse the repository at this point in the history
  • Loading branch information
Romazes committed Jul 9, 2024
1 parent 9b37e01 commit 9819290
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lean/commands/cloud/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def status(project: str) -> None:
cloud_project_manager = container.cloud_project_manager
cloud_project = cloud_project_manager.get_cloud_project(project, False)

live_algorithm = next((d for d in api_client.live.get_all() if d.projectId == cloud_project.projectId), None)
live_algorithm = api_client.live.get_project_by_id(cloud_project.projectId)

logger.info(f"Project id: {cloud_project.projectId}")
logger.info(f"Project name: {cloud_project.name}")
Expand Down
29 changes: 14 additions & 15 deletions lean/components/api/live_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,28 @@ def __init__(self, api_client: 'APIClient') -> None:
"""
self._api = api_client

def get_all(self,
status: Optional[QCLiveAlgorithmStatus] = None,
# Values less than 86400 cause errors on Windows: https://bugs.python.org/issue37527
start: datetime = datetime.fromtimestamp(86400),
end: datetime = datetime.now()) -> List[QCFullLiveAlgorithm]:
def get_project_by_id(self,
project_id: str,
status: Optional[QCLiveAlgorithmStatus] = None) -> QCFullLiveAlgorithm:
"""Retrieves all live algorithms.
:param status: the status to filter by or None if no status filter should be applied
:param start: the earliest launch time the returned algorithms should have
:param end: the latest launch time the returned algorithms should have
:return: a list of live algorithms which match the given filters
:param project_id: the project id
:return: a live algorithm which match the given filters
"""
from math import floor
parameters = {
"start": floor(start.timestamp()),
"end": floor(end.timestamp())
}
from lean.container import container

parameters = {"projectId": project_id}

if status is not None:
parameters["status"] = status.value

data = self._api.get("live/read", parameters)
return [QCFullLiveAlgorithm(**algorithm) for algorithm in data["live"]]
response = self._api.get("live/read", parameters)

if response:
return QCFullLiveAlgorithm(data=response)

return None

def start(self,
project_id: int,
Expand Down
9 changes: 5 additions & 4 deletions lean/components/util/live_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ def _get_last_portfolio(api_client: APIClient, project_id: str, project_name: Pa
from datetime import datetime
from lean.container import container

cloud_deployment_list = api_client.get("live/read", { "projectId": project_id })
container.logger.info(f'----- After cloud_deployment_list: {cloud_deployment_list}')

if "live" not in cloud_deployment_list:
if not project_id:
# Project is not initialized in the cloud, hence project_id is None
return None

cloud_deployment_list = api_client.get("live/read", {"projectId": project_id})
container.logger.info(f'----- After cloud_deployment_list: {cloud_deployment_list}')

cloud_deployment_time = [datetime.strptime(instance["launched"], "%Y-%m-%d %H:%M:%S").astimezone(UTC) for instance in cloud_deployment_list["live"]
if instance["projectId"] == project_id]
cloud_last_time = sorted(cloud_deployment_time, reverse = True)[0] if cloud_deployment_time else utc.localize(datetime.min)
Expand Down
2 changes: 1 addition & 1 deletion lean/models/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class QCMinimalLiveAlgorithm(WrappedBaseModel):
def get_url(self) -> str:
"""Returns the url of the live deployment in the cloud.
:return: a url which when visited opens an Algorithm Lab tab containing the live deployment
:return: an url which when visited opens an Algorithm Lab tab containing the live deployment
"""
return f"https://www.quantconnect.com/project/{self.projectId}/live"

Expand Down

0 comments on commit 9819290

Please sign in to comment.