Skip to content

Commit e9daa16

Browse files
Merge pull request #7 from SonySemiconductorSolutions/release/v1/1.1.0
Squashed merge
2 parents 1455738 + 3d056d3 commit e9daa16

File tree

5 files changed

+64
-38
lines changed

5 files changed

+64
-38
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,17 @@ This repository provides sample code for a [Flask](https://flask.palletsprojects
7575

7676
### Restrictions
7777

78-
None
78+
- Only images and inference results up to 10 hours after the inference start time can be acquired.
7979

8080
## Get support
8181

82-
- [Contact us](https://developer.aitrios.sony-semicon.com/en/edge-ai-sensing/contact-us/)
82+
- [Contact us](https://support.aitrios.sony-semicon.com/hc/en-us/requests/new/)
8383

8484
## See also
8585

8686
- [Get Started](https://developer.aitrios.sony-semicon.com/en/edge-ai-sensing/guides/)
87-
- [aitrios-sdk-console-access-lib-python](https://github.com/SonySemiconductorSolutions/aitrios-sdk-console-access-lib-python)
88-
- [aitrios-sdk-cloud-app-sample-python](https://github.com/SonySemiconductorSolutions/aitrios-sdk-cloud-app-sample-python)
87+
- [aitrios-sdk-console-access-lib-python](https://github.com/SonySemiconductorSolutions/aitrios-sdk-console-access-lib-python/tree/v1/main)
88+
- [aitrios-sdk-cloud-app-sample-python](https://github.com/SonySemiconductorSolutions/aitrios-sdk-cloud-app-sample-python/tree/v1/main)
8989

9090
## Trademark
9191

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from setuptools import find_packages, setup
2020

2121
PACKAGE_NAME = "checkdata-python"
22-
PACKAGE_VERSION = "0.1.0"
22+
PACKAGE_VERSION = "1.1.0"
2323
PACKAGE_DESCRIPTION = "checkdata-python"
2424
AUTHOR_NAME = "Sony Semiconductor Solutions Corporation"
2525
AUTHOR_EMAIL = ""

src/app.py

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,9 @@ def get_devices():
3535
try:
3636
devices_data = get_console_data.get_devices()
3737
return jsonify(devices_data), 200
38-
38+
3939
except Exception as error:
40-
error_message = {
41-
"result": "ERROR",
42-
"message": str(error)
43-
}
40+
error_message = {"result": "ERROR", "message": str(error)}
4441
return jsonify(error_message), 400
4542

4643

@@ -51,35 +48,34 @@ def get_image_directories():
5148
if device_id == "":
5249
error_response = {
5350
"result": "ERROR",
54-
"message": "Device ID is not specified."
51+
"message": "Device ID is not specified.",
5552
}
5653
return jsonify(error_response), 400
57-
54+
5855
directories_data = get_console_data.get_image_directories(device_id)
5956
return jsonify(directories_data), 200
60-
57+
6158
except Exception as error:
62-
error_message = {
63-
"result": "ERROR",
64-
"message": str(error)
65-
}
59+
error_message = {"result": "ERROR", "message": str(error)}
6660
return jsonify(error_message), 400
6761

6862

6963
@app.route("/api/getImagesAndInferences", methods=["GET"])
7064
def get_images_and_inferences():
7165
try:
7266
device_id = request.args.get("deviceId")
73-
sub_directory = request.args.get("imagePath")
67+
sub_directory_name = request.args.get("imagePath")
7468
number_of_images = request.args.get("numberOfImages")
75-
if device_id == "" or sub_directory == "" or number_of_images == "":
69+
if device_id == "" or sub_directory_name == "" or number_of_images == "":
7670
error_response = {
7771
"result": "ERROR",
78-
"message": "Device ID is not specified."
72+
"message": "Required parameter is not specified.",
7973
}
8074
return jsonify(error_response), 400
81-
82-
images_list = get_console_data.get_images(device_id, sub_directory, int(number_of_images))
75+
76+
images_list = get_console_data.get_images(
77+
device_id, sub_directory_name, int(number_of_images)
78+
)
8379
output_list = []
8480
for image in images_list:
8581
image_timestamp = image["name"].replace(".jpg", "")
@@ -98,19 +94,13 @@ def get_images_and_inferences():
9894
}
9995
output_list.append(output)
10096
except Exception as error:
101-
error_message = {
102-
"result": "ERROR",
103-
"message": str(error)
104-
}
97+
error_message = {"result": "ERROR", "message": str(error)}
10598
return jsonify(error_message), 400
106-
99+
107100
return jsonify(output_list), 200
108-
101+
109102
except Exception as error:
110-
error_message = {
111-
"result": "ERROR",
112-
"message": str(error)
113-
}
103+
error_message = {"result": "ERROR", "message": str(error)}
114104
return jsonify(error_message), 500
115105

116106

src/data_loader/get_console_data.py

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
limitations under the License.
1515
"""
1616

17+
from datetime import datetime, timezone, timedelta
1718
from data_loader.common.get_client import get_console_client
1819

1920

@@ -40,11 +41,32 @@ def get_image_directories(device_id):
4041
raise Exception(str(error))
4142

4243

43-
def get_images(device_id, device_directory_name, number_of_images):
44+
def get_images(device_id, sub_directory_name, number_of_images):
4445
try:
4546
client_obj = get_console_client()
47+
48+
start_datetime = convert_timestamp_to_datetime(sub_directory_name)
49+
start_time = start_datetime.strftime("%Y%m%d%H%M")
50+
51+
# Retrieve images for 10 hours from the specified time.
52+
# If 10 hours later exceeds the current time, use the current time.
53+
tenhours_later_datetime = start_datetime + timedelta(hours=10)
54+
current_datetime = datetime.now(timezone.utc)
55+
end_datetime = (
56+
tenhours_later_datetime
57+
if tenhours_later_datetime < current_datetime
58+
else current_datetime
59+
)
60+
end_time = end_datetime.strftime("%Y%m%d%H%M")
61+
4662
response = client_obj.insight.get_images(
47-
device_id=device_id, sub_directory_name=device_directory_name, number_of_images=number_of_images
63+
device_id=device_id,
64+
sub_directory_name=sub_directory_name,
65+
number_of_images=number_of_images,
66+
order_by="DESC",
67+
skip=0,
68+
from_datetime=start_time,
69+
to_datetime=end_time,
4870
)
4971
if len(response["images"]) == 0:
5072
raise Exception("Cannot get images.")
@@ -62,10 +84,24 @@ def get_inference_result(device_id, image_timestamp):
6284
raw=1,
6385
time=image_timestamp,
6486
)
65-
if len(response[0]["inferences"]) == 0:
87+
if len(response[0]["inference_result"]["Inferences"]) == 0:
6688
print("Cannot get inference results.")
6789
raise Exception("Cannot get inference results.")
68-
return response[0]["inferences"]
90+
return response[0]["inference_result"]["Inferences"]
6991
except Exception as error:
7092
raise Exception(str(error))
71-
93+
94+
95+
def convert_timestamp_to_datetime(timestamp):
96+
converted_datetime = datetime(
97+
year=int(timestamp[:4]),
98+
month=int(timestamp[4:6]),
99+
day=int(timestamp[6:8]),
100+
hour=int(timestamp[8:10]),
101+
minute=int(timestamp[10:12]),
102+
second=int(timestamp[12:14]),
103+
microsecond=int(timestamp[14:] + "000"),
104+
tzinfo=timezone.utc,
105+
)
106+
107+
return converted_datetime

0 commit comments

Comments
 (0)