This repository has been archived by the owner on Jan 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add print console #37
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -52,5 +52,6 @@ | |
"asynchronous": true, | ||
"detail": true, | ||
"detail_log": false, | ||
"print_console": true, | ||
"log_level": "INFO" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,54 +27,49 @@ def __eq__(self, other: Any): | |
return self.plate == other.plate | ||
return False | ||
|
||
def __str__(self): | ||
# TODO: Handle show details later when main updates that option | ||
def __str__(self) -> str: | ||
def create_violation_str(violation: ViolationDetail, index: int) -> str: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. create str method in violation model instead in this big class |
||
violation_str: str = ( | ||
f"Lỗi vi phạm thứ {index}:" | ||
+ (f"\nMàu biển: {violation.color}" if violation.color else "") | ||
+ (f"\nThời điểm vi phạm: {violation.date}" if violation.date else "") | ||
+ ( | ||
f"\nVị trí vi phạm: {violation.location}" | ||
if violation.location | ||
else "" | ||
) | ||
+ ( | ||
f"\nHành vi vi phạm: {violation.violation}" | ||
if violation.violation | ||
else "" | ||
) | ||
+ ( | ||
f"\nTrạng thái: {'Chưa xử phạt' if not violation.status else 'Đã xử phạt'}" | ||
if violation.status is not None | ||
else "" | ||
) | ||
+ ( | ||
f"\nĐơn vị phát hiện vi phạm: {violation.enforcement_unit}" | ||
if violation.enforcement_unit | ||
else "" | ||
) | ||
) | ||
resolution_offices: str | None = ( | ||
f""" | ||
Nơi giải quyết vụ việc: | ||
{ | ||
"\n".join( | ||
resolution_office_detail | ||
for resolution_office_detail in violation.resolution_offices_details | ||
) | ||
} | ||
""" | ||
"\n" | ||
+ "Nơi giải quyết vụ việc:" | ||
+ "\n" | ||
+ "\n".join( | ||
resolution_office_detail.strip() | ||
for resolution_office_detail in violation.resolution_offices_details | ||
) | ||
if violation.resolution_offices_details | ||
else None | ||
) | ||
# TODO: Keep going on | ||
violation_str: str = ( | ||
f"Lỗi vi phạm thứ {index}:" + f"\nMàu biển: {violation.color}" | ||
if violation.color | ||
else "" | ||
) | ||
# violation_str = "\n".join( | ||
# line | ||
# for line in f""" | ||
# Lỗi vi phạm thứ {index}: | ||
# Màu biển: {violation.color if violation.color else " "} | ||
# Thời điểm vi phạm: {violation.date if violation.date else " "} | ||
# Vị trí vi phạm: {violation.location if violation.location else " "} | ||
# Hành vi vi phạm: {violation.violation if violation.violation else " "} | ||
# Trạng thái: {"Đã xử phạt" if violation.status else ("Chưa xử phạt" if not violation.status else " ")} | ||
# Đơn vị phát hiện vi phạm: {violation.enforcement_unit if violation.enforcement_unit else " "} | ||
# """.splitlines() | ||
# if line.strip() | ||
# ) | ||
return ( | ||
"\n".join([violation_str, resolution_offices]) | ||
if resolution_offices | ||
else violation_str | ||
) | ||
return violation_str + (resolution_offices if resolution_offices else "") | ||
|
||
# TODO: Ye going on hehehe | ||
plate_detail: str = "\n".join( | ||
line | ||
for line in f""" | ||
Biển số: {self.plate} | ||
Chủ sở hữu: {self.owner if self.owner else " "} | ||
""".splitlines() | ||
if line.strip() | ||
plate_detail: str = f"Biển số: {self.plate}" + ( | ||
f"\nChủ sở hữu: {self.owner}" if self.owner else "" | ||
) | ||
|
||
if self.violations: | ||
|
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,3 @@ | ||
from .print_console import PrintConsole | ||
|
||
__all__ = ["PrintConsole"] |
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,20 @@ | ||
from logging import getLogger | ||
|
||
from check_phat_nguoi.config.config_reader import config | ||
from check_phat_nguoi.context import PlateDetail, plates_context | ||
|
||
logger = getLogger(__name__) | ||
|
||
|
||
class PrintConsole: | ||
def __init__(self): | ||
self.plate_details: tuple[PlateDetail, ...] = plates_context.plates | ||
|
||
def print_console(self) -> None: | ||
if not config.print_console: | ||
return | ||
if not self.plate_details: | ||
logger.info("No plate details. Skip printing") | ||
return | ||
for plate_detail in self.plate_details: | ||
print(plate_detail) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle show details later when main updates that option