Skip to content

Commit 6bb34a0

Browse files
committed
Tests and docs
1 parent c9c539b commit 6bb34a0

4 files changed

Lines changed: 78 additions & 3 deletions

File tree

docs/entities/kpis.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,42 @@ In order to make use of the data viz function you'll need the name of the KPI yo
3636
### Get KPI Data Viz
3737
Once you have the name of the KPI you wish to access and a logged in client you can make a call to the data viz api with the following SDK function call:
3838
```
39-
cli.get_kpi_data_viz(**data_viz_query)
39+
cli.get_kpi_data_viz(machine_source, kpis, i_vars, time_selection, **optional_data_viz_query)
4040
```
4141

42-
The d_vars section of your data_viz_query should include an d_var with the name of the KPI you wish to query. For more information on [data_viz_queries](/docs/commonly_used_data_types/data_viz_query.md) click on the previous link. After some time the SDK should return a list that looks something like this:
42+
After some time the SDK should return a list that looks something like this:
4343
```
4444
[{'i_vals': {'endtime': {'i_pos': 0, 'bin_no': 0, 'bin_min': '2022-10-20T00:00:00-07:00', 'bin_max': '2022-10-20T00:00:00-07:00', 'bin_avg': '2022-10-20T00:00:00-07:00'}}, 'd_vals': {'quality': {'avg': 95.18072289156626}}, '_count': 418, 'kpi_dependencies': {'quality': {'Output': 395.0, 'ScrapQuantity': 20.0}}},...]
45+
```
46+
47+
There's two ways to call this function you can use a data_viz_query,For more information on [data_viz_queries](/docs/commonly_used_data_types/data_viz_query.md) click on the previous link, or have the function fill out the query for you by passing in a few variable we will now go over one at a time.
48+
49+
#### machine_source
50+
This is a string and is the name of machine you wish to run a query on.
51+
52+
#### kpis
53+
This is a list of the names of all the kpis you wish to run this query on.
54+
55+
#### i_vars
56+
This is a list, this is the same as the i_vars object in the data_viz_query and is the axis you are querying the kpis against it will look like the following:
57+
```
58+
[
59+
{
60+
"name": "endtime",
61+
"time_resolution": "day",
62+
"query_tz": "America/Los_Angeles",
63+
"output_tz": "America/Los_Angeles"
64+
}
65+
]
66+
```
67+
68+
#### time_selection
69+
This is an object, this is the same as the [time_selection](/docs/commonly_used_data_types/data_viz_query.md#time_selection) object in the data_viz_query and more info can be found at that link. The most common form is the relative time selection and looks like this:
70+
```
71+
{
72+
"time_type": "relative",
73+
"relative_start": 7,
74+
"relative_unit": "day",
75+
"ctime_tz": "America/Los_Angeles"
76+
}
4577
```

docs/entities/machine.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Machines
2+
Machines are just that, machines in factories. The machine object is how the Sight Machine software replesents and is the key to accessing data that we collect from them
3+
4+
## Functions
5+
6+
### get_type_from_machine
7+
The get_type_from_machine function allows you to get the type of any machine from it's name and is called this way:
8+
```
9+
cli.get_type_from_machine(machine_name)
10+
```
11+
12+
And will return something like the following:
13+
```
14+
'Lasercut'
15+
```

tests/kpi/test_kpi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def json():
2828
assert len(kpis) == 5
2929

3030
assert kpis[0]["name"] == 'Scrap_Rate'
31+
3132
def test_get_kpi_for_asset(monkeypatch):
3233
# Setup
3334
def mockapi(self, session, endpoint):
@@ -77,4 +78,4 @@ def json():
7778
dt = Client("demo")
7879
data = dt.get_kpi_data_viz()
7980
assert len(data) == 3
80-
assert data[0]['d_vals']['quality']['avg'] == 95.18072289156626
81+
assert data[0]['d_vals']['quality']['avg'] == 95.18072289156626

tests/machine/test_machine.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
from unittest.mock import MagicMock
2+
from mock import patch
13
import pandas as pd
24
from requests.sessions import Session
5+
from smsdk.client import Client
36
from tests.machine.machine_data import JSON_MACHINE
47
from smsdk.smsdk_entities.machine.machine import Machine
58

@@ -32,3 +35,27 @@ def mockapi(self, session, endpoint):
3235
]
3336

3437
assert cols == df.columns.sort_values().tolist()
38+
39+
40+
@patch("smsdk.ma_session.Session")
41+
def test_get_type(mocked):
42+
class ResponseGet:
43+
ok = True
44+
text = "Success"
45+
status_code=200
46+
47+
@staticmethod
48+
def json():
49+
return {'results':[{"machine":[{"name":"test", "type":'test_type'}]}]}
50+
51+
mocked.return_value = MagicMock(
52+
get=MagicMock(return_value=ResponseGet())
53+
)
54+
55+
dt = Client("demo")
56+
57+
# Run
58+
type = dt.get_type_from_machine('test')
59+
60+
# Verify
61+
assert type == 'test_type'

0 commit comments

Comments
 (0)