Part
Model
- class pytm4srv.models.Part
Represents one produced part.
If a program produces multiple parts per cycle, multiple instances are created.
- editor_id: Mapped[int | None]
ID of the user who last edited this part.
- finished: Mapped[datetime]
The date and time this part was produced.
- id: MappedColumn object at 0x7907c2991c60>]]
Unique (across all machines), numeric ID of this part in OnTakt.
- notes: Mapped[str]
User-specified notes about this part.
- program_id: Mapped[int]
The ID of the program that was loaded when this part was reported.
- reworked: Mapped[bool]
Whether the part was reworked by the user.
- scrapped: Mapped[bool]
Whether the part was scrapped by the user.
- suspect: Mapped[bool]
Whether the part has been flagged for review.
- tmac_monitored: Mapped[int]
Percentage of the production time TMAC was monitoring.
- tool_life: Mapped[Dict[str, int]]
Record of the number of parts that have been produced by each tool at the time this part was produced.
Maps tool ID to number of parts.
- tools_seen: Mapped[List[int]]
Tool locations that the machine reported using while producing this part.
- variables: Mapped[Dict[str, int | float]]
Variable values saved with the part in the following format:
{ "Serial number": 150, "Material heat": 14 }
- work_order: Mapped[str]
User-specified work order name.
Endpoints
- GET /api/parts/
Get parts matching certain criteria.
Example response:
{ "45349": { "finished": 1595426416.769725, "id": 45349, "machine_id": 9, "notes": "", "program_name": "TM4_DEMO_PROG.MIN", "scrapped": false, "tmac_monitored": 0, "variables": { "SERIAL": "1" } }, "45351": { "finished": 1595430017.126168, "id": 45351, "machine_id": 9, "notes": "", "program_name": "TM4_DEMO_PROG.MIN", "scrapped": false, "tmac_monitored": 0, "variables": { "SERIAL": "2" } }, "45353": { "finished": 1595433617.552167, "id": 45353, "machine_id": 9, "notes": "", "program_name": "TM4_DEMO_PROG.MIN", "scrapped": false, "tmac_monitored": 0, "variables": { "SERIAL": "3" } } }
- Query Parameters:
scrapped (boolean) – if specified as 0 or 1, only parts that are (1) or aren’t (0) scrapped will be returned.
machine_id (int) – if specified by ID, only parts produced by that machine will be returned. Can be specified multiple times to include parts from multiple machines. This parameter used to be named
machine
, and either name will work.start (float) – only get parts finished on or after this UNIX timestamp (UTC)
end (float) – only get parts finished on or before this UNIX timestamp (UTC)
variable (string) – include parts only if they have a value for this variable. Can be used multiple times to include parts with ANY of the specified variables.
work_order (string) – include parts only if they have the specified work order. Make sure this parameter is not present at all in the query string when it is not being used as setting it to an empty string will return parts with a work order of
""
(the default work order).var[NAME] –
include parts only if they have a variable named NAME, and if a value is passed, only if the part’s value for the variable is equal to the passed value. NAME can be any string and is case-sensitive. Specifying multiple variables will return parts having ALL the specified variables (and, optionally, values).
For example,
?var[Part in bar]
will only return parts that have a non-empty value forPart in bar
, while?var[SERIAL]=500
will only return parts that have a SERIAL value of 500. Combining the two (?var[Part in bar]&var[SERIAL]=500
) will only return parts that have a non-empty value forPart in bar
AND aSERIAL
value of 500.Depending on your HTTP interface, you may need to url-encode special characters such as (but not limited to)
?
,&
, and#
(as%3F
,%26
, and%23
, respectively) where they appear in variable names.Repeating this parameter with the same NAME and different values will return no parts because a part can only have one value for a given variable.
- Returns:
a JSON object of all matching parts, keyed by part ID
- GET /api/parts/workOrders
Get a list of all the work orders present on any of the parts matching the specified criteria.
- Query Parameters:
scrapped (boolean) – if specified as 0 or 1, only parts that are (1) or aren’t (0) scrapped will be returned.
machine_id (int) – if specified by ID, only parts produced by that machine will be returned. Can be specified multiple times to include parts from multiple machines. This parameter used to be named
machine
, and either name will work.start (float) – only get parts finished on or after this UNIX timestamp (UTC)
end (float) – only get parts finished on or before this UNIX timestamp (UTC)
variable (string) – include parts only if they have a value for this variable. Can be used multiple times to include parts with ANY of the specified variables.
work_order (string) – include parts only if they have the specified work order. Make sure this parameter is not present at all in the query string when it is not being used as setting it to an empty string will return parts with a work order of
""
(the default work order).var[NAME] –
include parts only if they have a variable named NAME, and if a value is passed, only if the part’s value for the variable is equal to the passed value. NAME can be any string and is case-sensitive. Specifying multiple variables will return parts having ALL the specified variables (and, optionally, values).
For example,
?var[Part in bar]
will only return parts that have a non-empty value forPart in bar
, while?var[SERIAL]=500
will only return parts that have a SERIAL value of 500. Combining the two (?var[Part in bar]&var[SERIAL]=500
) will only return parts that have a non-empty value forPart in bar
AND aSERIAL
value of 500.Depending on your HTTP interface, you may need to url-encode special characters such as (but not limited to)
?
,&
, and#
(as%3F
,%26
, and%23
, respectively) where they appear in variable names.Repeating this parameter with the same NAME and different values will return no parts because a part can only have one value for a given variable.
- Returns:
an array of work order strings. The default work order (empty string) will not be present.
- GET /api/parts/(int: part_id)
Get a single part.
- Parameters:
part_id – the ID of the part to get
- Status Codes:
404 Not Found – if the part does not exist
- DELETE /api/parts/(int: part_id)
Delete a part from the database.
- Parameters:
part_id – The numeric ID of the part to delete.
- Status Codes:
204 No Content – on success
404 Not Found – if the part does not exist
- PATCH /api/parts/(int: part_id)
Modify a produced part.
- Reqjson:
a (partial) Part object. Omitted fields will not be changed.
- Parameters:
part_id – the ID of the part to edit
- Returns:
the modified part object
- Status Codes:
400 Bad Request – if any part variables are invalid
404 Not Found – if the part doesn’t exist
- POST /api/parts/flag
Update flags on many parts at once.
- Query Parameters:
scrapped (int) – set to 1 to mark parts as scrapped, 0 to mark parts as not scrapped, or omit for no change to the
scrapped
fieldreworked (int) – set to 1 to mark parts as reworked, 0 to mark parts as not reworked, or omit for no change to the
reworked
fieldsuspect (int) – set to 1 to flag parts for review, 0 to remove the flag, or omit for no change to the
suspect
field
- Request JSON Array of Objects:
parts (int) – list of part IDs to flag
- Request JSON Object:
notes (string) – text to append to the
notes
field of each part
- Status Codes:
204 No Content – on success
400 Bad Request – if the part list is invalid
- POST /api/parts/delete
Delete many parts from the database.
The list of parts to delete should be provided as a JSON array of part IDs in the request body.
- Status Codes:
204 No Content – on success
400 Bad Request – if the part list is invalid
- POST /api/parts/create
Create many parts at once manually to account for missing production data.
- Request JSON Object:
machine_id (int) – the machine to create parts on (required)
num_parts (int) – the number of parts to create (required and must be at least 1)
program_id (int) – the ID of the program to create parts from. Optional (defaults to the program currently running on the machine).
use_tools (boolean) – whether to count these parts against the life of tools assigned to the program. Optional (defaults to false). Only tools that have not been replaced since the timestamp will be affected.
timestamp (int) – UNIX timestamp to assign as the parts’ creation time. Defaults to now.
- Returns:
a JSON object of created parts
- Status Codes:
400 Bad Request – if a required parameter is missing or invalid
201 Created – on success
- POST /api/parts/setWorkOrder
Set the work order field of many parts at once.
- Request JSON Array of Objects:
parts – list of part IDs to modify
- Request JSON Object:
work_order – new value for the work order field
- Status Codes:
400 Bad Request – if the parts or work_order fields are missing from the request body or invalid
204 No Content – on success
- GET /api/parts/variables
Get the names of all metadata fields that have ever been recorded on a part.
- Query Parameters:
machine (int) – set to the ID of a machine to limit the search to parts produced by this machine.
start (float) – return only variables that appear on parts produced after this time (UNIX timestamp)
end (float) – return only variables that appear on parts produced before this time (UNIX timestamp)
- Resjsonarr:
list of metadata field names
- Status Codes:
404 Not Found – if the machine does not exist