forked from ITISFoundation/osparc-simcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎨Image pulling progress: pass current/total size (Part 3) (ITISFounda…
- Loading branch information
Showing
26 changed files
with
550 additions
and
228 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
packages/models-library/src/models_library/progress_bar.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from typing import Any, ClassVar, Literal, TypeAlias | ||
|
||
from pydantic import BaseModel | ||
|
||
# NOTE: keep a list of possible unit, and please use correct official unit names | ||
ProgressUnit: TypeAlias = Literal["Byte"] | ||
|
||
|
||
class ProgressReport(BaseModel): | ||
actual_value: float | ||
total: float | ||
unit: ProgressUnit | None = None | ||
|
||
@property | ||
def percent_value(self) -> float: | ||
if self.total != 0: | ||
return max(min(self.actual_value / self.total, 1.0), 0.0) | ||
return 0 | ||
|
||
class Config: | ||
frozen = True | ||
schema_extra: ClassVar[dict[str, Any]] = { | ||
"examples": [ | ||
# typical percent progress (no units) | ||
{ | ||
"actual_value": 0.3, | ||
"total": 1.0, | ||
}, | ||
# typical byte progress | ||
{ | ||
"actual_value": 128.5, | ||
"total": 1024.0, | ||
"unit": "Byte", | ||
}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.