Implement cable_details call
This commit is contained in:
parent
6d6c2030a9
commit
ad216f21fa
@ -301,7 +301,7 @@ def parse(filename, output_dir, partnum, dstype):
|
|||||||
output_table["id"] = id
|
output_table["id"] = id
|
||||||
#output_table["position"] = id
|
#output_table["position"] = id
|
||||||
#output_table["brand"] = brand
|
#output_table["brand"] = brand
|
||||||
output_table["fullspecs"] = tables
|
output_table["fullspecs"] = {"partnum": partnum, "id": id, **tables}
|
||||||
output_table["searchspecs"] = {"partnum": partnum, **flatten(tables)}
|
output_table["searchspecs"] = {"partnum": partnum, **flatten(tables)}
|
||||||
|
|
||||||
output_table["searchspecs"]["id"] = id
|
output_table["searchspecs"]["id"] = id
|
||||||
|
186
run.py
186
run.py
@ -90,7 +90,15 @@ def wait_for(val, name):
|
|||||||
while val is False:
|
while val is False:
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
|
|
||||||
|
def send_data(type, call, data, client_id="*"):
|
||||||
|
out = dict()
|
||||||
|
out["type"] = type
|
||||||
|
out["call"] = call
|
||||||
|
out["data"] = data
|
||||||
|
to_server_queue.put((client_id, json.dumps(out)))
|
||||||
|
|
||||||
def start_server_socket():
|
def start_server_socket():
|
||||||
|
global jbs
|
||||||
"""app = Flask(__name__)
|
"""app = Flask(__name__)
|
||||||
|
|
||||||
@app.route('/report_ip', methods=['POST'])
|
@app.route('/report_ip', methods=['POST'])
|
||||||
@ -122,92 +130,99 @@ def start_server_socket():
|
|||||||
# Message handler
|
# Message handler
|
||||||
try:
|
try:
|
||||||
decoded = json.loads(message)
|
decoded = json.loads(message)
|
||||||
if "type" not in decoded:
|
|
||||||
fprint("Missing \"type\" field.")
|
|
||||||
continue
|
|
||||||
if "call" not in decoded:
|
|
||||||
fprint("Missing \"call\" field.")
|
|
||||||
continue
|
|
||||||
if "data" not in decoded:
|
|
||||||
fprint("Missing \"data\" field.")
|
|
||||||
continue
|
|
||||||
|
|
||||||
# if we get here, we have a "valid" data packet
|
|
||||||
data = decoded["data"]
|
|
||||||
call = decoded["call"]
|
|
||||||
match decoded["type"]:
|
|
||||||
case "log":
|
|
||||||
fprint("log message")
|
|
||||||
if call == "send":
|
|
||||||
fprint("webapp: " + str(data), sendqueue=to_server_queue)
|
|
||||||
elif call == "request":
|
|
||||||
fprint("")
|
|
||||||
|
|
||||||
case "cable_map":
|
|
||||||
fprint("cable_map message")
|
|
||||||
if call == "send":
|
|
||||||
fprint("")
|
|
||||||
elif call == "request":
|
|
||||||
fprint("")
|
|
||||||
|
|
||||||
|
|
||||||
case "ping":
|
|
||||||
fprint("Pong!!!")
|
|
||||||
|
|
||||||
# Lucas' notes
|
|
||||||
# Add a ping pong :) response/handler
|
|
||||||
# Add a get cable response/handler
|
|
||||||
# this will tell the robot arm to move
|
|
||||||
# Call for turning off everything
|
|
||||||
|
|
||||||
# TODO Helper for converting Python Dictionaries to JSON
|
|
||||||
# make function: pythonData --> { { "type": "...", "call": "...", "data": pythonData } }
|
|
||||||
|
|
||||||
# to send: to_server_queue.put(("*", "JSON STRING HERE")) # replace * with UUID of client to send to one specific location
|
|
||||||
|
|
||||||
case "cable_details":
|
|
||||||
fprint("cable_details message")
|
|
||||||
if call == "send":
|
|
||||||
fprint("")
|
|
||||||
elif call == "request":
|
|
||||||
fprint("")
|
|
||||||
|
|
||||||
case "cable_search":
|
|
||||||
fprint("cable_search message")
|
|
||||||
if call == "send":
|
|
||||||
fprint("")
|
|
||||||
elif call == "request":
|
|
||||||
fprint("")
|
|
||||||
|
|
||||||
case "keyboard":
|
|
||||||
fprint("keyboard message")
|
|
||||||
if call == "send":
|
|
||||||
fprint("")
|
|
||||||
elif call == "request":
|
|
||||||
fprint("")
|
|
||||||
if data["enabled"] == True:
|
|
||||||
# todo : send this to client
|
|
||||||
p = Process(target=run_cmd, args=("./keyboard-up.ps1",))
|
|
||||||
p.start()
|
|
||||||
elif data["enabled"] == False:
|
|
||||||
p = Process(target=run_cmd, args=("./keyboard-down.ps1",))
|
|
||||||
p.start()
|
|
||||||
|
|
||||||
case "machine_settings":
|
|
||||||
fprint("machine_settings message")
|
|
||||||
if call == "send":
|
|
||||||
fprint("")
|
|
||||||
elif call == "request":
|
|
||||||
fprint("")
|
|
||||||
|
|
||||||
case _:
|
|
||||||
fprint("Unknown/unimplemented data type: " + decoded["type"])
|
|
||||||
|
|
||||||
|
|
||||||
except:
|
except:
|
||||||
fprint("Non-JSON message recieved")
|
fprint("Non-JSON message recieved")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if "type" not in decoded:
|
||||||
|
fprint("Missing \"type\" field.")
|
||||||
|
continue
|
||||||
|
if "call" not in decoded:
|
||||||
|
fprint("Missing \"call\" field.")
|
||||||
|
continue
|
||||||
|
if "data" not in decoded:
|
||||||
|
fprint("Missing \"data\" field.")
|
||||||
|
continue
|
||||||
|
# if we get here, we have a "valid" data packet
|
||||||
|
data = decoded["data"]
|
||||||
|
call = decoded["call"]
|
||||||
|
match decoded["type"]:
|
||||||
|
case "log":
|
||||||
|
fprint("log message")
|
||||||
|
if call == "send":
|
||||||
|
fprint("webapp: " + str(data), sendqueue=to_server_queue)
|
||||||
|
elif call == "request":
|
||||||
|
fprint("")
|
||||||
|
case "cable_map":
|
||||||
|
fprint("cable_map message")
|
||||||
|
if call == "send":
|
||||||
|
fprint("")
|
||||||
|
elif call == "request":
|
||||||
|
fprint("")
|
||||||
|
case "ping":
|
||||||
|
fprint("Pong!!!")
|
||||||
|
# Lucas' notes
|
||||||
|
# Add a ping pong :) response/handler
|
||||||
|
# Add a get cable response/handler
|
||||||
|
# this will tell the robot arm to move
|
||||||
|
# Call for turning off everything
|
||||||
|
# TODO Helper for converting Python Dictionaries to JSON
|
||||||
|
# make function: pythonData --> { { "type": "...", "call": "...", "data": pythonData } }
|
||||||
|
|
||||||
|
# to send: to_server_queue.put(("*", "JSON STRING HERE")) # replace * with UUID of client to send to one specific location
|
||||||
|
|
||||||
|
case "cable_details":
|
||||||
|
fprint("cable_details message")
|
||||||
|
if call == "send":
|
||||||
|
fprint("")
|
||||||
|
elif call == "request":
|
||||||
|
fprint("")
|
||||||
|
dataout = dict()
|
||||||
|
dataout["cables"] = list()
|
||||||
|
print(data)
|
||||||
|
if "part_number" in data:
|
||||||
|
for part in data["part_number"]:
|
||||||
|
print(part)
|
||||||
|
print(jbs.get_partnum(part))
|
||||||
|
dataout["cables"].append(jbs.get_partnum(part)["fullspecs"])
|
||||||
|
if "position" in data:
|
||||||
|
for pos in data["position"]:
|
||||||
|
print(pos)
|
||||||
|
print(jbs.get_position(str(pos)))
|
||||||
|
dataout["cables"].append(jbs.get_position(str(pos))["fullspecs"])
|
||||||
|
send_data(decoded["type"], "send", dataout, client_id)
|
||||||
|
|
||||||
|
case "cable_search":
|
||||||
|
fprint("cable_search message")
|
||||||
|
if call == "send":
|
||||||
|
fprint("")
|
||||||
|
elif call == "request":
|
||||||
|
fprint("")
|
||||||
|
case "keyboard":
|
||||||
|
fprint("keyboard message")
|
||||||
|
if call == "send":
|
||||||
|
fprint("")
|
||||||
|
elif call == "request":
|
||||||
|
fprint("")
|
||||||
|
if data["enabled"] == True:
|
||||||
|
# todo : send this to client
|
||||||
|
p = Process(target=run_cmd, args=("./keyboard-up.ps1",))
|
||||||
|
p.start()
|
||||||
|
elif data["enabled"] == False:
|
||||||
|
p = Process(target=run_cmd, args=("./keyboard-down.ps1",))
|
||||||
|
p.start()
|
||||||
|
case "machine_settings":
|
||||||
|
fprint("machine_settings message")
|
||||||
|
if call == "send":
|
||||||
|
fprint("")
|
||||||
|
elif call == "request":
|
||||||
|
fprint("")
|
||||||
|
case _:
|
||||||
|
fprint("Unknown/unimplemented data type: " + decoded["type"])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
sleep(0.001) # Sleep to prevent tight loop
|
sleep(0.001) # Sleep to prevent tight loop
|
||||||
|
|
||||||
@ -262,6 +277,7 @@ def setup_server(pool):
|
|||||||
ledsys = LEDSystem()
|
ledsys = LEDSystem()
|
||||||
pool.apply_async(ledsys.init, callback=led_start_callback)
|
pool.apply_async(ledsys.init, callback=led_start_callback)
|
||||||
#pool.apply_async(sensor_control.init, callback=sensor_start_callback)
|
#pool.apply_async(sensor_control.init, callback=sensor_start_callback)
|
||||||
|
jbs = JukeboxSearch()
|
||||||
serverproc = Process(target=start_server_socket)
|
serverproc = Process(target=start_server_socket)
|
||||||
serverproc.start()
|
serverproc.start()
|
||||||
|
|
||||||
@ -293,7 +309,7 @@ def setup_server(pool):
|
|||||||
fprint("Arm initialized.", sendqueue=to_server_queue)
|
fprint("Arm initialized.", sendqueue=to_server_queue)
|
||||||
|
|
||||||
|
|
||||||
jbs = JukeboxSearch()
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@ -391,7 +407,7 @@ def mainloop_server(pool):
|
|||||||
"BLRA500P"
|
"BLRA500P"
|
||||||
]
|
]
|
||||||
cable_list = tmp
|
cable_list = tmp
|
||||||
pool.apply_async(get_specs.get_multi, (tmp, 0.5), callback=cable_search_callback)
|
pool.apply_async(get_specs.get_multi, (tmp, 0.3), callback=cable_search_callback)
|
||||||
mode = "Parsing"
|
mode = "Parsing"
|
||||||
fprint("All cables scanned. Finding & parsing datasheets...")
|
fprint("All cables scanned. Finding & parsing datasheets...")
|
||||||
if mode == "Parsing":
|
if mode == "Parsing":
|
||||||
@ -423,6 +439,8 @@ def mainloop_server(pool):
|
|||||||
specs = json.load(f)
|
specs = json.load(f)
|
||||||
searchdata["fullspecs"] = specs
|
searchdata["fullspecs"] = specs
|
||||||
jbs.add_document(searchdata)
|
jbs.add_document(searchdata)
|
||||||
|
#sleep(0.5)
|
||||||
|
#print(jbs.get_position("1"))
|
||||||
|
|
||||||
fprint("All cables added to database.")
|
fprint("All cables added to database.")
|
||||||
mode = "Idle"
|
mode = "Idle"
|
||||||
|
11
search.py
11
search.py
@ -70,11 +70,10 @@ class JukeboxSearch:
|
|||||||
|
|
||||||
:param filterables: List of all filterable attributes"""
|
:param filterables: List of all filterable attributes"""
|
||||||
|
|
||||||
existing_filterables = self.idxref.get_filterable_attributes()
|
#existing_filterables = self.idxref.get_filterable_attributes()
|
||||||
if len(set(existing_filterables).difference(set(filterables))) > 0:
|
#if len(set(existing_filterables).difference(set(filterables))) > 0:
|
||||||
taskref = self.idxref.update_filterable_attributes(filterables)
|
taskref = self.idxref.update_filterable_attributes(filterables)
|
||||||
|
#self.client.wait_for_task(taskref.index_uid)
|
||||||
self.client.wait_for_task(taskref.index_uid)
|
|
||||||
|
|
||||||
def search(self, query: str, filters: str = None):
|
def search(self, query: str, filters: str = None):
|
||||||
"""Execute a search query on the Meilisearch index.
|
"""Execute a search query on the Meilisearch index.
|
||||||
@ -95,7 +94,7 @@ class JukeboxSearch:
|
|||||||
:returns: A dict containing the results; If no results found, an empty dict."""
|
:returns: A dict containing the results; If no results found, an empty dict."""
|
||||||
q = self.search("", filter)
|
q = self.search("", filter)
|
||||||
if q["estimatedTotalHits"] != 0:
|
if q["estimatedTotalHits"] != 0:
|
||||||
return ["hits"][0]
|
return q["hits"][0]
|
||||||
else:
|
else:
|
||||||
return dict()
|
return dict()
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@
|
|||||||
socket.send(message);
|
socket.send(message);
|
||||||
console.log('Message sent', message);
|
console.log('Message sent', message);
|
||||||
}
|
}
|
||||||
setInterval(ping, 1500);
|
//setInterval(ping, 1500);
|
||||||
|
|
||||||
// setInterval(() => {
|
// setInterval(() => {
|
||||||
// updateServiceStatus('serviceA', 'down');
|
// updateServiceStatus('serviceA', 'down');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user