Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions optics_framework/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,10 @@ def parse_text_only_prefix(element: str) -> Tuple[str, bool]:

def get_timestamp():
try:
current_utc_time = datetime.now(timezone.utc)
desired_timezone = timezone(timedelta(hours=5, minutes=30))
current_time_in_desired_timezone = current_utc_time.astimezone(desired_timezone)
formatted_time = current_time_in_desired_timezone.strftime("%Y-%m-%dT%H:%M:%S.%f%z")
return formatted_time[:-2] + ":" + formatted_time[-2:]
ist = timezone(timedelta(hours=5, minutes=30))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not hardcode timezones

now_ist = datetime.now(ist)
return now_ist.strftime("%Y-%m-%dT%H-%M-%S-%f")

except Exception as e:
internal_logger.error('Unable to get current time', exc_info=e)
return None
Expand Down Expand Up @@ -273,19 +272,23 @@ def save_screenshot(img, name, output_dir, time_stamp=None):
return
name = re.sub(r'[^a-zA-Z0-9\s_]', '', name)
if time_stamp is None:
time_stamp = str(datetime.now().astimezone().strftime('%Y-%m-%dT%H-%M-%S-%f'))
time_stamp = datetime.now().astimezone().strftime('%Y-%m-%dT%H-%M-%S-%f%z')
screenshot_file_path = os.path.join(output_dir, f"{time_stamp}-{name}.jpg")
try:
cv2.imwrite(screenshot_file_path, img)
internal_logger.debug(f'Screenshot saved as : {time_stamp}-{name}.jpg')
internal_logger.debug(f"Screenshot saved to :{screenshot_file_path}")
success = cv2.imwrite(screenshot_file_path, img)

if success:
internal_logger.debug(f"Screenshot saved as : {time_stamp}-{name}.jpg")
internal_logger.debug(f"Screenshot saved to :{screenshot_file_path}")
else:
internal_logger.error(f"cv2 returned FALSE. FAILED to save screenshot to : {screenshot_file_path}")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this error will not give context to a developer new to this repo, we can improve it

except Exception as e:
internal_logger.debug(f"Error writing screenshot to file : {e}")


def annotate(screenshot, bboxes):
# Iterate over each bounding box and annotate it on the image
internal_logger.debug(f"Bounding boxes {bboxes} to be annotated.")
for bbox in bboxes:
if bbox is None or len(bbox) != 2:
internal_logger.debug(f"Invalid bounding box: {bbox}")
Expand Down
Loading