dynamic machines

main
alex 2023-09-09 19:51:01 +02:00
parent d78ef57ac2
commit 2e2cfb69a3
7 changed files with 97 additions and 48 deletions

View File

@ -1,16 +1,46 @@
{
"category": "Janex",
"name": "Janex Device Acryl schneiden",
"globalInputs": [
{
"parameterName": "irgendwas",
"type": "text",
"displayName": "Irgendwas tolles"
},
{
"parameterName": "kiste",
"type": "number",
"displayName": "Nummer der Kiste"
}
]
"category": "Janex",
"name": "Janex Device Acryl schneiden",
"globalInputs": [
{
"parameterName": "irgendwas",
"type": "text",
"displayName": "Irgendwas tolles"
},
{
"parameterName": "kiste",
"type": "number",
"displayName": "Nummer der Kiste"
},
{
"parameterName": "3d_printer_machine_selection3",
"type": "select_machine",
"displayName": "3D Drucker3",
"options": {
"location": 5,
"whitelistParts": [1, 2],
"blacklistParts": [0, 5]
}
},
{
"parameterName": "3d_printer_machine_selection2",
"type": "select_machine",
"displayName": "3D Drucker2",
"options": {
"location": 5,
"whitelistParts": [1, 2],
"blacklistParts": [0, 5]
}
}
],
"tasks": [
{
"name": "Label drucken",
"onFinish": "next",
"undoPossible": false,
"repeatPossible": false,
"scriptPath": "test2.py",
"parameters": []
}
]
}

View File

@ -20,11 +20,11 @@
{
"parameterName": "3d_printer_machine_selection",
"type": "select_machine",
"displayName": "3D Drucker auswählen",
"displayName": "3D Drucker",
"options": {
"location": 1,
"whitelist": [1, 2],
"blacklist": [0, 5]
"location": 5,
"whitelistParts": [],
"blacklistParts": []
}
}
],
@ -53,6 +53,16 @@
"type": "textarea",
"displayName": "Nummer der zweiten Kiste lul",
"global": true
},
{
"parameterName": "print_machine_selection",
"type": "select_machine",
"displayName": "Drucker",
"options": {
"location": 5,
"whitelistParts": [],
"blacklistParts": []
}
}
]
},

View File

@ -4,12 +4,17 @@ import time
import sys
import numpy as np
from stl import mesh
import json
time.sleep(3)
labelformat = sys.argv[1]
kiste = sys.argv[2]
# arg format is like this: args ['test1.py', '{"kiste":{"value":"321"},"labelformat":{"value":"123123"},"print_machine_selection":{"data":{"displayName":"Brother Workplace","ip":"127.0.0.1"},"value":"Brother Workplace"}}', '--undo'] undo is optional
json_object = json.loads(sys.argv[1])
labelformat = json_object["labelformat"]
kiste = json_object["kiste"]
print("args", sys.argv)
if len(sys.argv) >= 5:
undo = sys.argv[4]

View File

@ -503,15 +503,7 @@ func RunGroupTask(args RunGroupTaskArgs) {
})
return
} else if len(args.TaskInputs) > 0 {
var taskParameterInputs []InputParameters
if err := json.Unmarshal([]byte(args.TaskInputs), &taskParameterInputs); err != nil {
log.Error().Msgf("err unmarshalling task parameter inputs %s", err.Error())
}
for _, taskParameterInput := range taskParameterInputs {
commandArgs = append(commandArgs, taskParameterInput.Value)
}
commandArgs = append(commandArgs, args.TaskInputs)
// append undo as last arg to script
if args.StartType == RunGroupTaskStartTypeUndo {

View File

@ -1,9 +1,9 @@
package structs
type MachinesBody struct {
Location int
Whitelist []int
Blacklist []int
Location int
WhitelistParts []int
BlacklistParts []int
}
/*

View File

@ -5,25 +5,17 @@ import (
"jannex/admin-dashboard-backend/modules/requestclient"
"jannex/admin-dashboard-backend/modules/structs"
"jannex/admin-dashboard-backend/modules/utils"
"strconv"
"github.com/gofiber/fiber/v2"
"github.com/rs/zerolog/log"
)
// POST /v1/machines/
/*
{
location: 2,
whitelist: [],
blacklist: []
}
*/
type InvexApiStockListResponse struct {
Results []struct {
Notes string
Status int
Part int
PartDetail struct {
Name string
Thumbnail string
@ -40,7 +32,7 @@ func GetMachines(c *fiber.Ctx) error {
log.Info().Msgf("body %v", body)
statusCode, reqBody, err := requestclient.InvexApiRequestClient(fiber.MethodGet, requestclient.ApiBase+"/stock/?search=&offset=0&limit=25&location=5&part_detail=true")
statusCode, reqBody, err := requestclient.InvexApiRequestClient(fiber.MethodGet, requestclient.ApiBase+"/stock/?search=&offset=0&limit=50&location="+strconv.Itoa(body.Location)+"&part_detail=true&in_stock=0")
log.Info().Msgf("statuscode %v", statusCode)
@ -57,11 +49,29 @@ func GetMachines(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusInternalServerError)
}
for locationItem, i := range data.Results {
log.Info().Msgf("lI %v %v", locationItem, i)
var finalData InvexApiStockListResponse
for _, item := range data.Results {
if !contains(body.BlacklistParts, item.Part) {
if len(body.WhitelistParts) == 0 || contains(body.WhitelistParts, item.Part) {
finalData.Results = append(finalData.Results, item)
}
}
}
//log.Info().Msgf("body %s", data)
// send empty array if no results
if len(finalData.Results) == 0 {
return c.JSON([]string{})
}
return c.JSON(data.Results)
return c.JSON(finalData.Results)
}
func contains(slice []int, item int) bool {
for _, s := range slice {
if s == item {
return true
}
}
return false
}

View File

@ -90,6 +90,8 @@ func RunHub() {
globalInputsJsonString := utils.MarshalJson(receivedMessage.Body["globalInputs"])
log.Debug().Msgf("globalInputsJsonString %v", globalInputsJsonString)
grouptasks.StartGroupTask(data.Conn.Locals("userId").(string),
structs.GroupTasks{
Category: category,