Skip to content

Commit

Permalink
removed unused code, fixed docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
Max McKelvey authored and Max McKelvey committed Aug 4, 2023
1 parent 245c171 commit 8c62e63
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 134 deletions.
3 changes: 0 additions & 3 deletions api/gl_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,12 @@ def push_label_result(api_key: str, endpoint: str, query_id: str, label: str):
def run_process(idx: int, logger, detector: dict, api_key: str, endpoint: str,
notify_queue: multiprocessing.Queue,
photo_queue: multiprocessing.Queue,
# websocket_img_queue: multiprocessing.Queue,
websocket_metadata_queue: multiprocessing.Queue,
websocket_cancel_queue: multiprocessing.Queue,
websocket_response_queue: multiprocessing.Queue):
# print("Starting process...")

trigger_type = detector["config"]["trigger_type"]

# delay = lambda: time.sleep(30)
poll_delay = 0.5
delay = lambda: time.sleep(poll_delay)
cycle_time = 30
Expand Down
50 changes: 5 additions & 45 deletions api/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,32 @@

def send_notifications(det_name: str, query: str, label: str, options: dict, image, logger):
if "condition" not in options:
# print("No condition provided")
logger.error("No condition provided")
return
condition = options["condition"].upper() # "PASS", "FAIL"
condition = options["condition"].upper() # "PASS" or "FAIL"
if label == "YES":
label = "PASS"
elif label == "NO":
label = "FAIL"

if "stacklight" in options:
# print("Sending stacklight")
logger.error("Sending stacklight")
logger.error("Sending to stacklight")
stacklight_options = options["stacklight"]
post_to_stacklight(det_name, query, label, stacklight_options)

if not ((condition == "PASS" and label == "PASS") or (condition == "FAIL" and label == "FAIL")):
# print("Condition not met")
logger.error("Condition not met")
return

if "email" in options:
# print("Sending email")
logger.error("Sending email")
email_options = options["email"]
send_email(det_name, query, image, label, email_options)
if "twilio" in options:
# print("Sending sms")
logger.error("Sending sms")
twilio_options = options["twilio"]
send_sms(det_name, query, label, twilio_options)
if "slack" in options:
# print("Sending slack")
logger.error("Sending slack")
slack_options = options["slack"]
send_slack(det_name, query, label, slack_options)
Expand Down Expand Up @@ -109,46 +103,12 @@ def send_slack(det_name: str, query: str, label: str, options: dict):
channel=options["channel_id"],
text=f"Your detector [{det_name}] returned a \"{label}\" result to the query [{query}]."
)
# assert response["message"]["text"] == f"Your detector [{det_name}] returned a \"{label}\" result."

def post_to_stacklight(det_name: str, query: str, label: str, options: dict):
if "ip" not in options:
return # TODO: Fix this (probably add usb stuff)

if "ip" not in options:
id = options["id"]
ap_name = "GL_STACKLIGHT_" + id
ap_password = "gl_stacklight_password_" + id
if "ssid" not in options or "password" not in options:
print("No ssid or password provided")
return
ssid = options["ssid"]
password = options["password"]
try:
wifi_networks = os.popen("nmcli -t -f ssid dev wifi list").read()
if ap_name not in wifi_networks:
return
os.popen(f"nmcli dev wifi connect {ap_name} password {ap_password}")

# push ssid and password to stacklight
res = requests.post(f"http://192.168.4.1:8080", json={"ssid": ssid, "password": password})
if res.status_code != 200:
print("Could not connect to stacklight")
return
res = requests.get(f"http://192.168.4.1:8080/ip")
if res.status_code != 200:
print("Could not connect to stacklight")
return
ip = res.text
except:
try:
os.popen(f"nmcli dev wifi connect {options['ssid']} password {options['password']}")
except:
print("Could not connect to wifi network")
return

else:
ip: str = options["ip"]
return

ip: str = options["ip"]

port = "8080"

Expand Down
60 changes: 0 additions & 60 deletions app/detectors/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ export default function Home() {

const changeDetectorEnabled = (det_idx: number, enabled: boolean) => {
// change detector enabled
// const det_idx = detectors.findIndex((det) => det == detector);
// if (det_idx === -1) return;
let detectors_copy = [...detectors];
detectors_copy[det_idx].config.enabled = enabled;
setDetectors(detectors_copy);
Expand Down Expand Up @@ -183,22 +181,6 @@ export default function Home() {
cycle_time: 30,
}
}));
// let detectors_copy = [...detectors, {
// name: "New Detector",
// query: "New Query?",
// id: "",
// config: {
// enabled: false,
// imgsrc_idx: 0,
// vid_config: detectors[0]?.config?.vid_config ? detectors[0].config.vid_config : {
// name: "",
// },
// image: detectors[0]?.config?.image ? detectors[0].config.image : "",
// trigger_type: "time",
// cycle_time: 30,
// }
// }];
// setDetectors(detectors_copy);
}}>
New Detector
<div className="p-1"></div>
Expand All @@ -208,21 +190,6 @@ export default function Home() {
<Dropdown options={availableDetectors.map(d => d.name)} selected="Add Existing Detector" setSelected={(e, idx) => {
setLastButtonWasAdd(true);
setEditOverlayIndex(detectors.length);
// let detectors_copy = [...detectors, {
// name: availableDetectors[idx].name,
// query: availableDetectors[idx].query,
// id: availableDetectors[idx].id,
// config: {
// enabled: false,
// imgsrc_idx: 0,
// vid_config: detectors[0]?.config?.vid_config ? detectors[0].config.vid_config : {
// name: "webcam",
// },
// image: detectors[0]?.config?.image ? detectors[0].config.image : "",
// trigger_type: "time",
// cycle_time: 30,
// }
// }];
let detectors_copy = detectors.concat({
name: availableDetectors[idx].name,
query: availableDetectors[idx].query,
Expand Down Expand Up @@ -274,14 +241,6 @@ export default function Home() {
:
<div className="w-full rounded-lg bg-red-400 h-32" />
}
{/* <button>
<Cog6ToothIcon className="absolute top-0 right-0 w-8 h-8 rounded-md backdrop-blur-xl backdrop-brightness-150" onClick={() => {
const index = detectorIndiciesByGroup[indexA][indexB];
setEditOverlayIndex(index);
setShowEditOverlay(true);
setLastButtonWasAdd(false);
}} />
</button> */}
<button className="bg-blue-500 hover:bg-blue-700ab absolute top-0 left-0 rounded-md px-2 py-1 text-white font-bold" onClick={() => {
refreshDetectorImg(detector.config.imgsrc_idx, detector);
}}>
Expand All @@ -299,7 +258,6 @@ export default function Home() {
}} />
</div>
<div className="flex flex-col place-items-center justify-center">
{/* <div className="font-bold place-self-center">Enabled?</div> */}
<div className="font-bold place-self-center text-center mb-2">Condition Running?</div>
<ReactSwitch checked={detector.config.enabled} onChange={(checked) => {
const index = detectorIndiciesByGroup[indexA][indexB];
Expand All @@ -318,8 +276,6 @@ export default function Home() {
<div className={` ${detector.config.trigger_type != "time" && "hidden"}`}>{detector.config.cycle_time + "s"}</div>
</div>
</div>
{/* <div className="flex place-items-center">
</div> */}
<div className="w-full h-full flex flex-col place-items-center justify-center gap-4">
<button className="flex place-items-center rounded-md backdrop-blur-xl backdrop-brightness-150 text-lg px-4 py-2 border-2 border-gray-300 bg-gray-200 hover:bg-gray-300 text-gray-600" onClick={() => {
const index = detectorIndiciesByGroup[indexA][indexB];
Expand Down Expand Up @@ -359,22 +315,6 @@ export default function Home() {
cycle_time: 30,
}
}));
// let detectors_copy = [...detectors, {
// name: group[0]?.name ? group[0].name : "New Detector",
// query: group[0]?.query ? group[0].query : "New Query?",
// id: group[0]?.id ? group[0].id : "",
// config: {
// enabled: false,
// imgsrc_idx: 0,
// vid_config: detectors[0]?.config?.vid_config ? detectors[0].config.vid_config : {
// name: "webcam",
// },
// image: detectors[0]?.config?.image ? detectors[0].config.image : "",
// trigger_type: "time",
// cycle_time: 30,
// }
// }];
// setDetectors(detectors_copy);
}}>
<PlusIcon className="w-16" />
</button>
Expand Down
18 changes: 0 additions & 18 deletions app/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,6 @@ export default function Page() {
Save
</button>
</div>
{/* <div className="p-10"></div>
<div className="text-2xl" >
Notification Settings:
</div>
<div className="p-2"></div>
<div className="text-xl" >
Enter your wifi credentials to enable Stacklight:
</div>
<div className="p-2"></div>
<div className="flex gap-2 mx-4">
<input className="border-2 border-gray-300 rounded-md p-2" type="text" placeholder="WiFi SSID" />
<input className="border-2 border-gray-300 rounded-md p-2" type="text" placeholder="WiFi Password" />
<button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" onClick={() => {
// save email
}}>
Save WiFi Config
</button>
</div> */}
<div className="p-10"></div>
<div className="text-2xl" >
Additional Settings:
Expand Down
5 changes: 1 addition & 4 deletions components/EditNotificationsOverlay.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useEffect, useState } from "react";
import { Dropdown } from "./Dropdown";
import { useState } from "react";
import { ArrowLeftIcon } from "@heroicons/react/24/outline";
import ReactSwitch from "react-switch";
import { PushStacklightConfigButton } from "./PushStacklightConfigButton";
Expand Down Expand Up @@ -33,8 +32,6 @@ export const EditNotificationsOverlay = ({ detector, index, onSave, onBack }:
const slackValid = !(slackNotification && (slackNotification.token === "" || slackNotification.channel_id === ""));
const twilioValid = !(twilioNotification && (twilioNotification.account_sid === "" || twilioNotification.auth_token === "" || twilioNotification.from_number === "" || twilioNotification.to_number === ""));
const emailValid = !(emailNotification && (emailNotification.from_email === "" || emailNotification.to_email === "" || emailNotification.email_password === ""));
// const stacklightValid = !(stacklightNotification && ((stacklightNotification.ip === "") && (stacklightNotification.id === "" || stacklightNotification.ssid === "" || stacklightNotification.password === "")));
// const stacklightValid = !(stacklightNotification && (stacklightNotification.id === "" && stacklightNotification.ip === ""));
const stacklightValid = !(stacklightNotification && stacklightNotification.ip === "");
const isDetectorValid = slackValid && twilioValid && emailValid && stacklightValid;

Expand Down
2 changes: 0 additions & 2 deletions components/PushStacklightConfigButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ export const PushStacklightConfigButton = ({ valid, ssid, password, callback }:
try {
const port = await Serial.requestPort({ filters: filters });
await port.open({ baudRate: 115200 });
// await port.open({ baudRate: 9600 });
// console.log(port.getInfo())
return port;
} catch (e) {
console.error(e);
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
services:
frontend:
image: docker.io/maxatgroundlight/detector-builder-frontend:latest
image: docker.io/groundlight/notification-server-example-frontend:latest
ports:
- "3000:3000"
depends_on:
- backend
backend:
image: docker.io/maxatgroundlight/detector-builder-backend:latest
image: docker.io/groundlight/notification-server-example-backend:latest
ports:
- "8000:8000"
devices:
Expand Down

0 comments on commit 8c62e63

Please sign in to comment.