Skip to content

Commit

Permalink
Enable handling of more items
Browse files Browse the repository at this point in the history
  • Loading branch information
benflexcompute committed Jan 14, 2025
1 parent 1ea562a commit c2155d0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
30 changes: 24 additions & 6 deletions flow360/component/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,34 @@ class Project(pd.BaseModel):
_root_simulation_json: Optional[dict] = pd.PrivateAttr(None)

@classmethod
def show_remote(cls, project_naming_pattern: Union[None, str] = None):
def show_remote(cls, search_keyword: Union[None, str] = None, max_item_count: int = 1000):
"""
Shows all projects on the cloud. Use naming pattern filter if provided by user.
Shows all projects on the cloud.
Parameters
----------
search_keyword : str, optional
"""
_api = RestApi(ProjectInterface.endpoint, id=None)
resp = _api.get()
resp = _api.get(
params={
"page": "0",
"size": max_item_count,
"filterKeywords": search_keyword,
"sortFields": ["createdAt"],
"sortDirections": ["asc"],
}
)
if resp["total"] > max_item_count:
log.warning(
f"Total number of projects matching the keyword on the cloud is {resp['total']}, "
f"but only the latest {max_item_count} will be displayed. "
"If you want to see all, set larger value for `max_item_count`"
)
log.info("Total number of matching projects on the cloud: %d", resp["total"])
all_projects = ProjectRecords.model_validate({"records": resp["records"]})
if project_naming_pattern:
all_projects.filter_by_project_name_pattern(project_naming_pattern)
log.info(str(all_projects))
log.info("%s", str(all_projects))

@property
def id(self) -> str:
Expand Down
12 changes: 3 additions & 9 deletions flow360/component/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,9 @@ class ProjectInfo(pd.BaseModel):
tags: list[str] = pd.Field()
description: str = pd.Field()
statistics: ProjectStatistics = pd.Field()
solver_version: str = pd.Field(alias="solverVersion")
solver_version: Optional[str] = pd.Field(
None, alias="solverVersion", description="If None then the project is from old database"
)
created_at: str = pd.Field(alias="createdAt")
root_item_type: Literal["Geometry", "SurfaceMesh", "VolumeMesh"] = pd.Field(
alias="rootItemType"
Expand Down Expand Up @@ -808,11 +810,3 @@ def __str__(self):

output_str += "\n"
return output_str

def filter_by_project_name_pattern(self, naming_pattern: str):
"""Filter the projects by the naming pattern and sort by the time."""
regex = _naming_pattern_handler(pattern=naming_pattern)
self.records = [project for project in self.records if regex.match(project.name)]
self.records = sorted(
self.records, key=lambda x: x.local_time_zone_created_time, reverse=True
)

0 comments on commit c2155d0

Please # to comment.