Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 12 additions & 1 deletion containers/init_script/init_script.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
###### TODO REFACTOR : use the init scripts which are in the test_update_pi directory
#  TODO REFACTOR : use the init scripts which are in the test_update_pi directory

#!/usr/bin/env python

Expand Down Expand Up @@ -72,6 +72,7 @@ def write_json_file(file_path, data):
organizations = pd.read_csv(f"data/csv/API_DATA{sub_path} - organizations.csv")
cameras = pd.read_csv(f"data/csv/API_DATA{sub_path} - cameras.csv")
cameras = cameras.fillna("")
poses = pd.read_csv(f"data/csv/API_DATA{sub_path} - poses.csv")

for orga in organizations.itertuples(index=False):
logging.info(f"saving orga : {orga.name}")
Expand Down Expand Up @@ -131,6 +132,16 @@ def write_json_file(file_path, data):
write_json_file(credentials_path, data)
write_json_file(credentials_path_etl, data_wildfire)

logging.info("creating poses")
for pose in poses.itertuples(index=False):
payload = {
"camera_id": pose.camera_id,
"azimuth": pose.azimuth,
"patrol_id": pose.patrol_id,
}
api_request("post", f"{api_url}/poses/", superuser_auth, payload)


# Load environment variables from .env file
# load_dotenv()

Expand Down
28 changes: 18 additions & 10 deletions containers/notebooks/app/send_real_alerts.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@
"metadata": {},
"outputs": [],
"source": [
"send_alert_from_cam_ids = [2, 4, 5, 14] # select cameras\n",
"\n",
"sequances_folders = glob.glob(f\"{SAMPLE_PATH}/*\")\n",
"\n",
"for camera_id in send_alert_from_cam_ids:\n",
Expand All @@ -151,17 +153,20 @@
" imgs.sort()\n",
" preds = glob.glob(f\"{sequances_folder}/labels_predictions/*\")\n",
" preds.sort()\n",
" \n",
" cam_center_azimuth = random.randint(0,360)\n",
" print(f\"Sending alerts from camera {camera_id} at azimuth {cam_center_azimuth}\")\n",
"\n",
" cam_poses = camera_client.get_current_poses().json()\n",
" # pick a random pose id\n",
" pose_id = random.choice(cam_poses)['id']\n",
"\n",
" print(f\"Sending alerts from camera {camera_id} at (pose_id={pose_id})\")\n",
" for img_file, pred_file in zip(imgs, preds):\n",
" \n",
" stream = io.BytesIO()\n",
" im = Image.open(img_file)\n",
" im.save(stream, format=\"JPEG\", quality=80)\n",
"\n",
" bboxes = read_pred_file(pred_file)\n",
" response = camera_client.create_detection(stream.getvalue(), cam_center_azimuth, bboxes)\n",
" response = camera_client.create_detection(stream.getvalue(), bboxes, pose_id=pose_id)\n",
" # Force a KeyError if the request failed\n",
" \n",
" response.json()[\"id\"]"
Expand Down Expand Up @@ -193,7 +198,7 @@
"source": [
"SEQUENCES_DIR_PATH = \"../data/alert_samples/single_sequences/*\"\n",
"sequences_directories = glob.glob(SEQUENCES_DIR_PATH)\n",
"CAM_MAPPING = {22:13, 42:7, 59:5, 14:11, 43:8, 79:14, 13:10, 11:15, 59:1, 60:2, 15:12, 12:9, 10:16, 41:2, 65:8}\n",
"CAM_MAPPING = {22: 13, 42: 7, 59: 5, 14: 11, 43: 8, 79: 14, 13: 10, 11: 15, 60: 2, 15: 12, 12: 9, 10: 16, 41: 2, 65: 8}\n",
"\n",
"for seq_path in sequences_directories:\n",
" \n",
Expand All @@ -211,9 +216,12 @@
" preds = glob.glob(f\"{seq_path}/labels_predictions/*\")\n",
" preds.sort()\n",
"\n",
" cam_center_azimuth = random.randint(0,360)\n",
" cam_poses = camera_client.get_current_poses().json()\n",
" # pick a random pose id\n",
" pose_id = random.choice(cam_poses)['id']\n",
"\n",
" \n",
" print(f\"Sending alerts from camera {camera_id} at azimuth {cam_center_azimuth}\")\n",
" print(f\"Sending alerts from camera {camera_id} at (pose_id={pose_id})\")\n",
" for img_file, pred_file in zip(imgs, preds):\n",
" \n",
" stream = io.BytesIO()\n",
Expand All @@ -223,9 +231,9 @@
" #bboxes = read_pred_file(pred_file)\n",
" with open(pred_file, 'r', encoding='utf-8') as file:\n",
" bboxes = ast.literal_eval(file.read())\n",
" \n",
" #bboxes = np.loadtxt(pred_file, ndmin=2)\n",
" response = camera_client.create_detection(stream.getvalue(), cam_center_azimuth, bboxes)\n",
" response = camera_client.create_detection(stream.getvalue(), bboxes, pose_id=pose_id)\n",
"\n",
" # Force a KeyError if the request failed\n",
" time.sleep(0.5)\n",
" response.json()[\"id\"]"
Expand Down Expand Up @@ -352,7 +360,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.7"
"version": "3.11.14"
}
},
"nbformat": 4,
Expand Down
Loading