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

@ -11,6 +11,36 @@
"parameterName": "kiste", "parameterName": "kiste",
"type": "number", "type": "number",
"displayName": "Nummer der Kiste" "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", "parameterName": "3d_printer_machine_selection",
"type": "select_machine", "type": "select_machine",
"displayName": "3D Drucker auswählen", "displayName": "3D Drucker",
"options": { "options": {
"location": 1, "location": 5,
"whitelist": [1, 2], "whitelistParts": [],
"blacklist": [0, 5] "blacklistParts": []
} }
} }
], ],
@ -53,6 +53,16 @@
"type": "textarea", "type": "textarea",
"displayName": "Nummer der zweiten Kiste lul", "displayName": "Nummer der zweiten Kiste lul",
"global": true "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 sys
import numpy as np import numpy as np
from stl import mesh from stl import mesh
import json
time.sleep(3) time.sleep(3)
labelformat = sys.argv[1] # 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
kiste = sys.argv[2] json_object = json.loads(sys.argv[1])
labelformat = json_object["labelformat"]
kiste = json_object["kiste"]
print("args", sys.argv)
if len(sys.argv) >= 5: if len(sys.argv) >= 5:
undo = sys.argv[4] undo = sys.argv[4]

View File

@ -503,15 +503,7 @@ func RunGroupTask(args RunGroupTaskArgs) {
}) })
return return
} else if len(args.TaskInputs) > 0 { } else if len(args.TaskInputs) > 0 {
var taskParameterInputs []InputParameters commandArgs = append(commandArgs, args.TaskInputs)
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)
}
// append undo as last arg to script // append undo as last arg to script
if args.StartType == RunGroupTaskStartTypeUndo { if args.StartType == RunGroupTaskStartTypeUndo {

View File

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

View File

@ -5,25 +5,17 @@ import (
"jannex/admin-dashboard-backend/modules/requestclient" "jannex/admin-dashboard-backend/modules/requestclient"
"jannex/admin-dashboard-backend/modules/structs" "jannex/admin-dashboard-backend/modules/structs"
"jannex/admin-dashboard-backend/modules/utils" "jannex/admin-dashboard-backend/modules/utils"
"strconv"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
// POST /v1/machines/
/*
{
location: 2,
whitelist: [],
blacklist: []
}
*/
type InvexApiStockListResponse struct { type InvexApiStockListResponse struct {
Results []struct { Results []struct {
Notes string Notes string
Status int Status int
Part int
PartDetail struct { PartDetail struct {
Name string Name string
Thumbnail string Thumbnail string
@ -40,7 +32,7 @@ func GetMachines(c *fiber.Ctx) error {
log.Info().Msgf("body %v", body) 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) log.Info().Msgf("statuscode %v", statusCode)
@ -57,11 +49,29 @@ func GetMachines(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusInternalServerError) return c.SendStatus(fiber.StatusInternalServerError)
} }
for locationItem, i := range data.Results { var finalData InvexApiStockListResponse
log.Info().Msgf("lI %v %v", locationItem, i)
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"]) globalInputsJsonString := utils.MarshalJson(receivedMessage.Body["globalInputs"])
log.Debug().Msgf("globalInputsJsonString %v", globalInputsJsonString)
grouptasks.StartGroupTask(data.Conn.Locals("userId").(string), grouptasks.StartGroupTask(data.Conn.Locals("userId").(string),
structs.GroupTasks{ structs.GroupTasks{
Category: category, Category: category,