Skip to content

Commit

Permalink
Rename Appliance to Machine (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
denizs authored Jan 29, 2024
1 parent caa69aa commit c5c191f
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 130 deletions.
2 changes: 1 addition & 1 deletion docs/api_clients/production_runs/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Models
:exclude-members: model_config, model_fields
:show-inheritance:

.. autoclass:: Appliance()
.. autoclass:: Machine()
:members:
:undoc-members:
:exclude-members: model_config, model_fields
Expand Down
2 changes: 1 addition & 1 deletion docs/api_clients/timeseries/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Models
:exclude-members: model_config, model_fields
:show-inheritance:

.. autoclass:: Appliance()
.. autoclass:: Machine()
:members:
:undoc-members:
:exclude-members: model_config, model_fields
Expand Down
32 changes: 16 additions & 16 deletions docs/concepts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ The concept of a *site* refers to a physical production site. Depending on its s
your organization might have one or many of them. In the ENLYZE platform, each site has
a name and an address, which makes it easy to identify for humans.

.. _appliance:
.. _machine:

Appliance
Machine
---------

An *appliance* refers to a machine that your organization uses to produce goods. For
A *machine* refers to a machine that your organization uses to produce goods. For
example, a CNC-milling center, a blown film extrusion line or an injection molding
machine all represent an appliance in the ENLYZE platform. Just as a physical machine is
located at one production site, an appliance in the ENLYZE platform is associated with
machine all represent a machine in the ENLYZE platform. Just as a physical machine is
located at one production site, a machine in the ENLYZE platform is associated with
exactly one :ref:`site <site>`.

.. _variable:

Variable
--------

A *variable* represents a process measure of one :ref:`appliance <appliance>` of which
timeseries data is captured and stored in the ENLYZE platform. One appliance may have
many variables, whereas one variable is only associated with one appliance.
A *variable* represents a process measure of one :ref:`machine <machine>` of which
timeseries data is captured and stored in the ENLYZE platform. One machine may have
many variables, whereas one variable is only associated with one machine.

.. _production_order:

Expand All @@ -45,7 +45,7 @@ MES and then synchronized into the ENLYZE platform. They are referenced by an id
which oftentimes is a short combination of numbers and/or characters, like FA23000123.

In the ENLYZE platform, a production order always encompasses the production of one
single :ref:`product <product>` on one single :ref:`appliance <appliance>` within one
single :ref:`product <product>` on one single :ref:`machine <machine>` within one
or more :ref:`production runs <production_run>`.

.. _production_run:
Expand All @@ -54,15 +54,15 @@ Production Run
--------------

A *production run* is a time frame within which a machine was producing a :ref:`product
<product>` on an :ref:`appliance <appliance>` in order to complete a :ref:`production
<product>` on a :ref:`machine <machine>` in order to complete a :ref:`production
order <production_order>`. A production run always has a beginning and, if it's not
still running, it also has an end.

Usually, the operator of the appliance uses an interface to log the time when a certain
production order has been worked on. For instance, this could be the appliance's HMI or
Usually, the operator of the machine uses an interface to log the time when a certain
production order has been worked on. For instance, this could be the machine's HMI or
a tablet computer next to it. In German, this is often referred to as *Betriebsdatenerfassung* (BDE).
It is common, that a production order is not completed in one go, but is interrupted
several times for very different reasons, like a breakdown of the appliance or a
several times for very different reasons, like a breakdown of the machine or a
public holiday. These interruptions lead to the creation of multiple production runs
for a single production order.

Expand All @@ -71,9 +71,9 @@ for a single production order.
Product
-------

A *product* is the output of the production process which is executed by an
:ref:`appliance <appliance>`, driven by a :ref:`production order <production_order>`. In
the real world, an appliance might have some additional outputs, but only the main
A *product* is the output of the production process which is executed by a
:ref:`machine <machine>`, driven by a :ref:`production order <production_order>`. In
the real world, a machine might have some additional outputs, but only the main
output (the product) is modeled in the ENLYZE platform. Similarly to the production order,
a product is referenced by an identifier originating from a customer's system, that gets
synchronized into the ENLYZE platform.
Expand Down
2 changes: 1 addition & 1 deletion docs/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Data models
.. autoclass:: Site()
:members:

.. autoclass:: Appliance()
.. autoclass:: Machine()
:members:

.. autoclass:: Variable()
Expand Down
4 changes: 2 additions & 2 deletions src/enlyze/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from .client import EnlyzeClient
from .errors import EnlyzeError, InvalidTokenError
from .models import Appliance, ResamplingMethod, Site, Variable
from .models import Machine, ResamplingMethod, Site, Variable

__all__ = [
"Appliance",
"Machine",
"EnlyzeClient",
"EnlyzeError",
"InvalidTokenError",
Expand Down
8 changes: 4 additions & 4 deletions src/enlyze/api_clients/production_runs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ def to_user_model(self) -> user_models.Quantity:
)


class Appliance(ApiBaseModel):
class Machine(ApiBaseModel):
name: str
uuid: UUID


class ProductionRun(ProductionRunsApiModel):
uuid: UUID
appliance: Appliance
machine: Machine
average_throughput: Optional[float]
production_order: str
product: Product
Expand All @@ -81,7 +81,7 @@ class ProductionRun(ProductionRunsApiModel):
productivity: Optional[OEEComponent]

def to_user_model(
self, appliances_by_uuid: dict[UUID, user_models.Appliance]
self, machines_by_uuid: dict[UUID, user_models.Machine]
) -> user_models.ProductionRun:
"""Convert into a :ref:`user model <user_models>`"""

Expand All @@ -101,7 +101,7 @@ def to_user_model(

return user_models.ProductionRun(
uuid=self.uuid,
appliance=appliances_by_uuid[self.appliance.uuid],
machine=machines_by_uuid[self.machine.uuid],
average_throughput=self.average_throughput,
production_order=self.production_order,
product=self.product.to_user_model(),
Expand Down
10 changes: 5 additions & 5 deletions src/enlyze/api_clients/timeseries/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ def to_user_model(self) -> user_models.Site:
)


class Appliance(TimeseriesApiModel):
class Machine(TimeseriesApiModel):
uuid: UUID
name: str
genesis_date: date
site: int

def to_user_model(self, site: user_models.Site) -> user_models.Appliance:
def to_user_model(self, site: user_models.Site) -> user_models.Machine:
"""Convert into a :ref:`user model <user_models>`"""

return user_models.Appliance(
return user_models.Machine(
uuid=self.uuid,
display_name=self.name,
genesis_date=self.genesis_date,
Expand All @@ -55,15 +55,15 @@ class Variable(TimeseriesApiModel):
unit: Optional[str]
data_type: user_models.VariableDataType

def to_user_model(self, appliance: user_models.Appliance) -> user_models.Variable:
def to_user_model(self, machine: user_models.Machine) -> user_models.Variable:
"""Convert into a :ref:`user model <user_models>`."""

return user_models.Variable(
uuid=self.uuid,
display_name=self.display_name,
unit=self.unit,
data_type=self.data_type,
appliance=appliance,
machine=machine,
)


Expand Down
74 changes: 36 additions & 38 deletions src/enlyze/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,27 @@ def get_sites(self) -> list[user_models.Site]:
"""
return [site.to_user_model() for site in self._get_sites()]

def _get_appliances(self) -> Iterator[timeseries_api_models.Appliance]:
"""Get all appliances from the API"""
def _get_machines(self) -> Iterator[timeseries_api_models.Machine]:
"""Get all machines from the API"""
return self._timeseries_api_client.get_paginated(
"appliances", timeseries_api_models.Appliance
"appliances", timeseries_api_models.Machine
)

@cache
def get_appliances(
def get_machines(
self, site: Optional[user_models.Site] = None
) -> list[user_models.Appliance]:
"""Retrieve all :ref:`appliances <appliance>`, optionally filtered by site.
) -> list[user_models.Machine]:
"""Retrieve all :ref:`machines <machine>`, optionally filtered by site.
:param site: Only get appliances of this site. Gets all appliances of the
:param site: Only get machines of this site. Gets all machines of the
organization if None.
:raises: |token-error|
:raises: |generic-error|
:returns: Appliances
:rtype: list[:class:`~enlyze.models.Appliance`]
:returns: Machines
:rtype: list[:class:`~enlyze.models.Machine`]
"""

Expand All @@ -111,43 +111,43 @@ def get_appliances(
else:
sites_by_id = {site._id: site for site in self.get_sites()}

appliances = []
for appliance_api in self._get_appliances():
site_ = sites_by_id.get(appliance_api.site)
machines = []
for machine_api in self._get_machines():
site_ = sites_by_id.get(machine_api.site)
if not site_:
continue

appliances.append(appliance_api.to_user_model(site_))
machines.append(machine_api.to_user_model(site_))

return appliances
return machines

def _get_variables(
self, appliance_uuid: UUID
self, machine_uuid: UUID
) -> Iterator[timeseries_api_models.Variable]:
"""Get variables for an appliance from the API."""
"""Get variables for a machine from the API."""
return self._timeseries_api_client.get_paginated(
"variables",
timeseries_api_models.Variable,
params={"appliance": str(appliance_uuid)},
params={"appliance": str(machine_uuid)},
)

def get_variables(
self, appliance: user_models.Appliance
self, machine: user_models.Machine
) -> Sequence[user_models.Variable]:
"""Retrieve all variables of an :ref:`appliance <appliance>`.
"""Retrieve all variables of a :ref:`machine <machine>`.
:param appliance: The appliance for which to get all variables.
:param machine: The machine for which to get all variables.
:raises: |token-error|
:raises: |generic-error|
:returns: Variables of ``appliance``
:returns: Variables of ``machine``
"""
return [
variable.to_user_model(appliance)
for variable in self._get_variables(appliance.uuid)
variable.to_user_model(machine)
for variable in self._get_variables(machine.uuid)
]

def get_timeseries(
Expand All @@ -159,7 +159,7 @@ def get_timeseries(
"""Get timeseries data of :ref:`variables <variable>` for a given time frame.
Timeseries data for multiple variables can be requested at once. However, all
variables must belong to the same appliance.
variables must belong to the same machine.
You should always pass :ref:`timezone-aware datetime
<python:datetime-naive-aware>` objects to this method! If you don't, naive
Expand All @@ -180,15 +180,13 @@ def get_timeseries(
"""

start, end, appliance_uuid = validate_timeseries_arguments(
start, end, variables
)
start, end, machine_uuid = validate_timeseries_arguments(start, end, variables)

pages = self._timeseries_api_client.get_paginated(
"timeseries",
timeseries_api_models.TimeseriesData,
params={
"appliance": appliance_uuid,
"appliance": machine_uuid,
"start_datetime": start.isoformat(),
"end_datetime": end.isoformat(),
"variables": ",".join(str(v.uuid) for v in variables),
Expand All @@ -215,7 +213,7 @@ def get_timeseries_with_resampling(
"""Get resampled timeseries data of :ref:`variables <variable>` for a given time frame.
Timeseries data for multiple variables can be requested at once. However, all
variables must belong to the same appliance.
variables must belong to the same machine.
You should always pass :ref:`timezone-aware datetime
<python:datetime-naive-aware>` objects to this method! If you don't, naive
Expand Down Expand Up @@ -257,7 +255,7 @@ def get_timeseries_with_resampling(
resampling_method, variable.data_type
)

start, end, appliance_uuid = validate_timeseries_arguments(
start, end, machine_uuid = validate_timeseries_arguments(
start,
end,
variables_sequence,
Expand All @@ -268,7 +266,7 @@ def get_timeseries_with_resampling(
"timeseries",
timeseries_api_models.TimeseriesData,
params={
"appliance": appliance_uuid,
"appliance": machine_uuid,
"start_datetime": start.isoformat(),
"end_datetime": end.isoformat(),
"variables": ",".join(variables_query_parameter_list),
Expand All @@ -291,7 +289,7 @@ def _get_production_runs(
*,
production_order: Optional[str] = None,
product: Optional[str] = None,
appliance: Optional[UUID] = None,
machine: Optional[UUID] = None,
start: Optional[datetime] = None,
end: Optional[datetime] = None,
) -> Iterator[ProductionRun]:
Expand All @@ -300,7 +298,7 @@ def _get_production_runs(
filters = {
"production_order": production_order,
"product": product,
"appliance": appliance,
"appliance": machine,
"start": start.isoformat() if start else None,
"end": end.isoformat() if end else None,
}
Expand All @@ -314,13 +312,13 @@ def get_production_runs(
*,
production_order: Optional[str] = None,
product: Optional[user_models.Product | str] = None,
appliance: Optional[user_models.Appliance] = None,
machine: Optional[user_models.Machine] = None,
start: Optional[datetime] = None,
end: Optional[datetime] = None,
) -> user_models.ProductionRuns:
"""Retrieve optionally filtered list of :ref:`production runs <production_run>`.
:param appliance: The appliance for which to get all production runs.
:param machine: The machine for which to get all production runs.
:param product: Filter production runs by product.
:param production_order: Filter production runs by production order.
Expand All @@ -342,12 +340,12 @@ def get_production_runs(
product_filter = (
product.code if isinstance(product, user_models.Product) else product
)
appliances_by_uuid = {a.uuid: a for a in self.get_appliances()}
machines_by_uuid = {a.uuid: a for a in self.get_machines()}
return user_models.ProductionRuns(
[
production_run.to_user_model(appliances_by_uuid)
production_run.to_user_model(machines_by_uuid)
for production_run in self._get_production_runs(
appliance=appliance.uuid if appliance else None,
machine=machine.uuid if machine else None,
production_order=production_order,
product=product_filter,
start=start,
Expand Down
Loading

0 comments on commit c5c191f

Please sign in to comment.