wizata-dsapi 2.2.0.dev10__py3-none-any.whl → 2.2.0.dev11__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
wizata_dsapi/__init__.py CHANGED
@@ -66,7 +66,8 @@ from .connection import Connection, ConnectionMapping, ConnectionDirection, Tran
66
66
  from .connection_types import ConnectionType, CONNECTION_TYPES, TRANSFORM_SCHEMAS, get_connection_type, \
67
67
  list_connection_types
68
68
  from .product import ProductKind, Product, ProductComponent, BUILTIN_PRODUCT_KINDS, is_valid_product_key
69
- from .inventory import (InventoryBalance, InventoryStorage, InventoryStorageDatapoint, inventory_mode, INVENTORY_OPTION, INVENTORY_MODES,
69
+ from .inventory import (InventoryBalance, InventoryStorage, InventoryStorageDatapoint, inventory_mode,
70
+ InventoryStock, InventoryStockProduct, InventoryStockLine, InventoryStockCount, INVENTORY_OPTION, INVENTORY_MODES,
70
71
  INVENTORY_MOVEMENTS, INVENTORY_BALANCES, INVENTORY_STOCK,
71
72
  PRODUCT_TAG, PRODUCT_MESSAGE_KEY)
72
73
  from .dashboard import Dashboard, DashboardType
wizata_dsapi/inventory.py CHANGED
@@ -204,3 +204,110 @@ class InventoryStorage:
204
204
 
205
205
  def __repr__(self) -> str:
206
206
  return f"InventoryStorage({self.twin_hardware_id!r}, {[d.hardware_id for d in self.datapoints]})"
207
+
208
+
209
+ class InventoryStockCount:
210
+ """The last count behind a stock line: the balance it starts from (DEV-6088)."""
211
+
212
+ def __init__(self, balance_id=None, count=None, timestamp=None, quantity: float = None, by: str = None):
213
+ self.id: Optional[str] = _uuid_str(balance_id)
214
+ self.count: Optional[str] = _uuid_str(count)
215
+ self.timestamp: Optional[datetime] = _ts_in(timestamp)
216
+ self.quantity: Optional[float] = quantity
217
+ self.by: Optional[str] = by
218
+
219
+ def to_dict(self) -> dict:
220
+ return {"id": self.id, "count": self.count,
221
+ "timestamp": _ts_out(self.timestamp) if isinstance(self.timestamp, datetime) else self.timestamp,
222
+ "quantity": self.quantity, "by": self.by}
223
+
224
+ @classmethod
225
+ def from_dict(cls, data: dict) -> "InventoryStockCount":
226
+ return cls(balance_id=data.get("id"), count=data.get("count"), timestamp=data.get("timestamp"),
227
+ quantity=data.get("quantity"), by=data.get("by"))
228
+
229
+
230
+ class InventoryStockLine:
231
+ """
232
+ One product on one storage datapoint at a moment: ``quantity`` in the datapoint's unit,
233
+ ``last_count`` (None when never counted) and ``moved_since`` it (DEV-6088).
234
+ """
235
+
236
+ def __init__(self, twin_id=None, twin_hardware_id: str = None, twin_name: str = None, datapoint: str = None,
237
+ unit=None, unit_symbol: str = None, quantity: float = None, moved_since: float = None,
238
+ last_count: InventoryStockCount = None):
239
+ self.twin_id: Optional[str] = _uuid_str(twin_id)
240
+ self.twin_hardware_id: Optional[str] = twin_hardware_id
241
+ self.twin_name: Optional[str] = twin_name
242
+ self.datapoint: Optional[str] = datapoint
243
+ self.unit: Optional[str] = _uuid_str(unit)
244
+ self.unit_symbol: Optional[str] = unit_symbol
245
+ self.quantity: Optional[float] = quantity
246
+ self.moved_since: Optional[float] = moved_since
247
+ self.last_count: Optional[InventoryStockCount] = last_count
248
+
249
+ def to_dict(self) -> dict:
250
+ return {"twin": {"id": self.twin_id, "hardwareId": self.twin_hardware_id, "name": self.twin_name},
251
+ "datapoint": self.datapoint, "unit": self.unit, "unitSymbol": self.unit_symbol,
252
+ "quantity": self.quantity, "movedSince": self.moved_since,
253
+ "lastCount": self.last_count.to_dict() if self.last_count is not None else None}
254
+
255
+ @classmethod
256
+ def from_dict(cls, data: dict) -> "InventoryStockLine":
257
+ twin = data.get("twin") or {}
258
+ last = data.get("lastCount")
259
+ return cls(twin_id=twin.get("id"), twin_hardware_id=twin.get("hardwareId"), twin_name=twin.get("name"),
260
+ datapoint=data.get("datapoint"), unit=data.get("unit"), unit_symbol=data.get("unitSymbol"),
261
+ quantity=data.get("quantity"), moved_since=data.get("movedSince"),
262
+ last_count=InventoryStockCount.from_dict(last) if last else None)
263
+
264
+
265
+ class InventoryStockProduct:
266
+ """
267
+ A product's stock at a moment: one line per storage holding it, and a ``total`` in
268
+ ``total_unit``: the product's default unit, else the unit most of its storages use
269
+ (DEV-6088). ``total`` is None when a line's unit cannot be converted.
270
+ """
271
+
272
+ def __init__(self, key: str = None, name: str = None, kind: str = None, category=None, unit=None,
273
+ unit_symbol: str = None, total: float = None, total_unit=None, total_unit_symbol: str = None,
274
+ storages: list = None):
275
+ self.key: Optional[str] = key
276
+ self.name: Optional[str] = name
277
+ self.kind: Optional[str] = kind
278
+ self.category: Optional[str] = _uuid_str(category)
279
+ self.unit: Optional[str] = _uuid_str(unit)
280
+ self.unit_symbol: Optional[str] = unit_symbol
281
+ self.total: Optional[float] = total
282
+ self.total_unit: Optional[str] = _uuid_str(total_unit)
283
+ self.total_unit_symbol: Optional[str] = total_unit_symbol
284
+ self.storages: list = list(storages or [])
285
+
286
+ def to_dict(self) -> dict:
287
+ return {"key": self.key, "name": self.name, "kind": self.kind, "category": self.category,
288
+ "unit": self.unit, "unitSymbol": self.unit_symbol, "total": self.total,
289
+ "totalUnit": self.total_unit, "totalUnitSymbol": self.total_unit_symbol,
290
+ "storages": [s.to_dict() for s in self.storages]}
291
+
292
+ @classmethod
293
+ def from_dict(cls, data: dict) -> "InventoryStockProduct":
294
+ return cls(key=data.get("key"), name=data.get("name"), kind=data.get("kind"), category=data.get("category"),
295
+ unit=data.get("unit"), unit_symbol=data.get("unitSymbol"), total=data.get("total"),
296
+ total_unit=data.get("totalUnit"), total_unit_symbol=data.get("totalUnitSymbol"),
297
+ storages=[InventoryStockLine.from_dict(s) for s in data.get("storages") or []])
298
+
299
+
300
+ class InventoryStock:
301
+ """Stock of every product × storage at ``as_of`` (``POST /dsapi/planner/inventory/stock``, DEV-6088)."""
302
+
303
+ def __init__(self, as_of=None, products: list = None):
304
+ self.as_of: Optional[datetime] = _ts_in(as_of)
305
+ self.products: list = list(products or [])
306
+
307
+ def to_dict(self) -> dict:
308
+ return {"asOf": _ts_out(self.as_of) if isinstance(self.as_of, datetime) else self.as_of,
309
+ "products": [p.to_dict() for p in self.products]}
310
+
311
+ @classmethod
312
+ def from_dict(cls, data: dict) -> "InventoryStock":
313
+ return cls(as_of=data.get("asOf"), products=[InventoryStockProduct.from_dict(p) for p in data.get("products") or []])
wizata_dsapi/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "2.2.0.dev10"
1
+ __version__ = "2.2.0.dev11"
@@ -55,7 +55,7 @@ from .version import __version__
55
55
  import ast
56
56
  from .deployment import Deployment, DeploymentStatus
57
57
  from .product import ProductKind, Product, ProductComponent
58
- from .inventory import InventoryBalance, InventoryStorage
58
+ from .inventory import InventoryBalance, InventoryStorage, InventoryStock
59
59
  from .api_config import _registry
60
60
 
61
61
  from .streamlit_utils import get_streamlit_token, get_streamlit_domain
@@ -2909,6 +2909,31 @@ class WizataDSAPIClient(ApiInterface, ApiDtoInterface):
2909
2909
  body=search_query.to_dict())
2910
2910
  return PagedQueryResult.from_dict(response.json(), dto_class=InventoryBalance)
2911
2911
 
2912
+ def get_inventory_stock(self, as_of=None, twins: list = None, products: list = None,
2913
+ kinds: list = None) -> InventoryStock:
2914
+ """
2915
+ Stock of every product × storage at a moment (DEV-6088): per storage datapoint the
2916
+ quantity in its unit, the last count and what moved since; per product a total in
2917
+ its default unit (else the unit most of its storages use).
2918
+
2919
+ :param as_of: datetime or ISO string; default now. Events at that moment count.
2920
+ :param twins: storage twins (hardware ids or ids) to keep.
2921
+ :param products: product keys to keep.
2922
+ :param kinds: product kind keys to keep.
2923
+ """
2924
+ body = {}
2925
+ if as_of is not None:
2926
+ if isinstance(as_of, datetime.datetime):
2927
+ if as_of.tzinfo is None:
2928
+ as_of = as_of.replace(tzinfo=datetime.timezone.utc)
2929
+ as_of = as_of.isoformat()
2930
+ body["asOf"] = as_of
2931
+ for name, value in (("twins", twins), ("products", products), ("kinds", kinds)):
2932
+ if value is not None:
2933
+ body[name] = list(value)
2934
+ response = self._planner_request("POST", "planner/inventory/stock", body=body)
2935
+ return InventoryStock.from_dict(response.json())
2936
+
2912
2937
  def search_inventory_storages(self, search_query=None) -> PagedQueryResult:
2913
2938
  """
2914
2939
  The storage places: Twins holding an inventoryMovement DataPoint, each with those
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wizata_dsapi
3
- Version: 2.2.0.dev10
3
+ Version: 2.2.0.dev11
4
4
  Summary: Wizata Data Science Toolkit
5
5
  Author: Wizata S.A.
6
6
  Author-email: info@wizata.com
@@ -1,4 +1,4 @@
1
- wizata_dsapi/__init__.py,sha256=OhSN2Zzt61B5nkcG5Brb8Spgg9QxBeQ-28JJka41RsU,3757
1
+ wizata_dsapi/__init__.py,sha256=516snAD8O2UzisjESLEDEqYAPnIA-4sMMdHiTkxOI40,3861
2
2
  wizata_dsapi/api_config.py,sha256=zOgvpkB3FE2ny_2vAui7B1hcAMFCLvfb2ep3m-b7dIw,8270
3
3
  wizata_dsapi/api_dto.py,sha256=F9HjNa_vqYhdEMZwwk8E3SmCxuMBcxFnMp1eE9dxLvg,2910
4
4
  wizata_dsapi/api_interface.py,sha256=mCq0-rlwWL4GKB2QnxSPuyTecYOXXknmPOlQe_SEf2I,14670
@@ -25,7 +25,7 @@ wizata_dsapi/graylog_log.py,sha256=KaHzv9HSqzmg8Cjr1vrsqeggd3tvrDkSN1TXaxCwsPs,4
25
25
  wizata_dsapi/group_system.py,sha256=6rUKe0_J3YWACysyBlzuw_TEpKNXgLOMxhpWsNxOzwY,1708
26
26
  wizata_dsapi/ilogger.py,sha256=YKBTRp7pHYtBlnzroGRPT91_bMVJT93Pft3fUGcFSIM,488
27
27
  wizata_dsapi/insight.py,sha256=ABFZ04DqYxxzqAEfU1tzlTZqqrigM-zN-8Lbetko3g0,6468
28
- wizata_dsapi/inventory.py,sha256=vS840qrFYeaQRUN9trPPSlJtZPFURqqPlwy27lMwLsc,8827
28
+ wizata_dsapi/inventory.py,sha256=BhyrpZJOmiGwBgrrrGVauiwnsEKb1ewLpC68k5XWlPc,14386
29
29
  wizata_dsapi/mlmodel.py,sha256=ezgln6vyNGqEw7mD4P2YQZxHm5rXGqM9YW40eS09A8Q,26595
30
30
  wizata_dsapi/mobile_asset.py,sha256=FBEvrOaXkT8YaLv1coemqNFJaoY-NVUcgNKPFgUzfP4,7631
31
31
  wizata_dsapi/model_toolkit.py,sha256=UNyw5CFSgZeXydQFsiDIRTjoMeqIsdyIIuiwumLW5bA,1574
@@ -46,10 +46,10 @@ wizata_dsapi/trigger.py,sha256=waOX2AhrLvFzNFRQ535j6iemgg_QJP2QsWGL2ipljFg,8848
46
46
  wizata_dsapi/twin.py,sha256=8AnrxSaL7dMrILXJ3-GGmmUz078j3qqwzDTe6i86xqA,12672
47
47
  wizata_dsapi/twinregistration.py,sha256=iXt55AVGAQNl0jmxa3ZVynPqlSsIunFf4sLfp-MWTw0,13244
48
48
  wizata_dsapi/user.py,sha256=-hchKAMZULu9P00RUHDqu_5AT4NI5BYOJd8XCBrt3eQ,1950
49
- wizata_dsapi/version.py,sha256=acHEfh-uFKEAwnmeHaJQ1omUYJ9PBgHKOaq0o40T5KM,28
49
+ wizata_dsapi/version.py,sha256=TCQ6EuxkZkSAF9z2OreOaoGUIml8M_cNTiATBZV2h_U,28
50
50
  wizata_dsapi/wizard_function.py,sha256=RbM7W7Gf-6Rhp_1dU9DBYkHaciknGAGvuAndhAS_vyo,942
51
51
  wizata_dsapi/wizard_request.py,sha256=v6BaqKLKvTWmUSo0_gda9FabAQz5x_-GOH1Av50GzFo,3762
52
- wizata_dsapi/wizata_dsapi_client.py,sha256=FEb7dTBzxmbW0XA2LJW7He58u0Uq6uu5AWKySNm_f40,123726
52
+ wizata_dsapi/wizata_dsapi_client.py,sha256=RH3EOCzWgwi9-gWrcsB7_hlLb0ZnpGE7Fl3nms50KI4,125021
53
53
  wizata_dsapi/words.py,sha256=tV8CqzCqODZCV7PgBxBF5exBxeF_ya9t5DiUy-cg6Sg,1535
54
54
  wizata_dsapi/models/__init__.py,sha256=O3Tusyhl8hFb-5QaEBY7DJISRB8Gf_Xbxxr-aFDR1_U,380
55
55
  wizata_dsapi/models/common.py,sha256=5BC3Dc6kMvqPGxHgoCuGVOynu_F1MWh7EJSzXIICSSg,27196
@@ -58,8 +58,8 @@ wizata_dsapi/plots/common.py,sha256=7F4WMBaddubnCpdSafgaI9U9Sz0Sngg0VREP_vnIMno,
58
58
  wizata_dsapi/plots/theme.py,sha256=D4sSgEwabXVxF3z1GV8DivXJbbY61KgxXAWfjUbNDAc,3594
59
59
  wizata_dsapi/scripts/__init__.py,sha256=9fRdTMuuXcqMkIsUPf5dwFsTWwBzKteQdAMVkyy2acQ,212
60
60
  wizata_dsapi/scripts/common.py,sha256=T2cP8aGPg8OgIvBWuQBNonVtph_dHlNFubByuYrLb0o,15675
61
- wizata_dsapi-2.2.0.dev10.dist-info/licenses/LICENSE.txt,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
62
- wizata_dsapi-2.2.0.dev10.dist-info/METADATA,sha256=Pfb3gCqCdiCQFfNYsAm6nA5L1rfXtU659UMWEh5S6yY,14038
63
- wizata_dsapi-2.2.0.dev10.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
64
- wizata_dsapi-2.2.0.dev10.dist-info/top_level.txt,sha256=-OeTJbEnh5DuWyTOHtvw0Dw3LRg3G27TNS6W4ZtfwPs,13
65
- wizata_dsapi-2.2.0.dev10.dist-info/RECORD,,
61
+ wizata_dsapi-2.2.0.dev11.dist-info/licenses/LICENSE.txt,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
62
+ wizata_dsapi-2.2.0.dev11.dist-info/METADATA,sha256=W23IzCqA60_BsqAK8nIUiuFYtMNfoQts9-RjpZx4GtM,14038
63
+ wizata_dsapi-2.2.0.dev11.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
64
+ wizata_dsapi-2.2.0.dev11.dist-info/top_level.txt,sha256=-OeTJbEnh5DuWyTOHtvw0Dw3LRg3G27TNS6W4ZtfwPs,13
65
+ wizata_dsapi-2.2.0.dev11.dist-info/RECORD,,