Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/add-analyses-class/SDKPY-117 #39

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions docs/source/Resources/Analysis/Analysis_Type.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
**Analysis Type**
=================


.. _ScriptFile:

ScriptFile
----------

**Attributes:**

| name: str

| content: :ref:`Base64`

| language: "node" or "python"



.. _AnalysisCreateInfo:

AnalysisCreateInfo
------------------

**Attributes:**

| name: str

| description: Optional[str]

| interval: Optional[str]

| run_on: Optional["tago" or "external"]

| file_name: Optional[str]

| runtime: Optional["node" or "python"]

| active: Optional[bool]

| profile: Optional[:ref:`GenericID`]

| variables: Optional[List[Dict[str, Union[str, int, bool]]]]

| tags: Optional[List[:ref:`TagsObj`]]



.. _AnalysisInfo:

AnalysisInfo(:ref:`AnalysisCreateInfo`)
------------

**Attributes:**

| id: :ref:`GenericID`

| token: str

| last_run: :ref:`ExpireTimeOption``

| created_at: datetime

| updated_at: datetime

| locked_at: Any

| console: Optional[List[str]]


.. _AnalysisQuery:

AnalysisQuery(:ref:`Query`)
-------------

**Attributes:**

| fields: Optional[List["name" or "active" or "run_on" or "last_run" or "created_at" or "updated_at"]]


.. _AnalysisListItem:

AnalysisListItem
----------------

**Attributes:**

| id: Optional[:ref:`GenericID`]

| name: Optional[str]

| active: Optional[bool]

| run_on: Optional["tago" or "external"]

| last_run: Optional[:ref:`ExpireTimeOption`]

| created_at: Optional[datetime]

| updated_at: Optional[datetime]

| locked_at: Optional[datetime]

| console: Optional[List[str]]
251 changes: 251 additions & 0 deletions docs/source/Resources/Analysis/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
**Analysis**
========

Manage analysis in account.

=======
list
=======

Retrieves a list with all analyses from the account

**Parameters:**

| *Optional* **queryObj**: :ref:`AnalysisQuery`
| Query parameters to filter the results.

.. code-block::
:caption: **Default queryObj:**

queryObj: {
"page": 1,
"fields": ["id", "name"],
"filter": {},
"amount": 20,
"orderBy": "name,asc",
}

**Returns:**

| list[:ref:`AnalysisListItem`]

.. code-block::
:caption: **Example:**

from tagoio_sdk import Resources

resources = Resources()
resources.analysis.list()


=======
create
=======

Create a new analysis

**Parameters:**

| **analysisInfo**: :ref:`AnalysisCreateInfo`
| Analysis information

**Returns:**

| Dict[str, GenericID | GenericToken]

.. code-block::
:caption: **Example:**

from tagoio_sdk import Resources

resources = Resources()
resources.analysis.create({
"name": "My Analysis",
"runtime": "python",
"active": True,
})


=======
edit
=======

Modify any property of the analyze

**Parameters:**

| **analysisID**: GenericID: str
| Analysis ID

| **analysisInfo**: :ref:`AnalysisCreateInfo`
| Analysis information

**Returns:**

| string

.. code-block::
:caption: **Example:**

from tagoio_sdk import Resources

resources = Resources()
resources.analysis.edit("analysisID", { "name": "My Analysis Edited" })


=======
delete
=======

Deletes an analysis from the account

**Parameters:**

| **analysisID**: GenericID: str
| Analysis ID

**Returns:**

| string

.. code-block::
:caption: **Example:**

from tagoio_sdk import Resources

resources = Resources()
resources.analysis.delete("analysisID")


=======
info
=======

Gets information about an analysis

**Parameters:**

| **analysisID**: GenericID: str
| Analysis ID

**Returns:**

| :ref:`AnalysisInfo`

.. code-block::
:caption: **Example:**

from tagoio_sdk import Resources

resources = Resources()
resources.analysis.info("analysisID")


=======
run
=======

Run an analysis

**Parameters:**

| **analysisID**: GenericID: str
| Analysis ID

**Returns:**

| Dict[str, GenericToken]

.. code-block::
:caption: **Example:**

from tagoio_sdk import Resources

resources = Resources()
resources.analysis.run("analysisID")


=======
tokenGenerate
=======

Generate a new token for the analysis

**Parameters:**

| **analysisID**: GenericID: str
| Analysis ID

**Returns:**

| Dict[str, str]

.. code-block::
:caption: **Example:**

from tagoio_sdk import Resources

resources = Resources()
resources.analysis.tokenGenerate("analysisID")


=======
uploadScript
=======

Upload a file (base64) to Analysis. Automatically erase the old one

**Parameters:**

| **analysisID**: GenericID: str
| Analysis ID

| **file**: :ref:`ScriptFile`
| File information

**Returns:**

| string

.. code-block::
:caption: **Example:**

from tagoio_sdk import Resources
import base64

data = "print(Hello, World!)"
encoded_bytes = base64.b64encode(data.encode('utf-8')).decode('utf-8')

resources = Resources()
resources.analysis.uploadScript("analysisID", {
"name": "My Script",
"content": encoded_bytes,
"language": "python",
})


=======
downloadScript
=======

Get a url to download the analysis. If `version` is specified in `options`, downloads a specific version.

**Parameters:**

| **analysisID**: GenericID: str
| Analysis ID

| *Optional* **options**: Dict["version", int]
| Options

**Returns:**

| Dict[str, Any]

.. code-block::
:caption: **Example:**

from tagoio_sdk import Resources

resources = Resources()
resources.analysis.downloadScript("analysisID")
1 change: 1 addition & 0 deletions docs/source/Resources/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Instance
.. toctree::

Account/index
Analysis/index
Billing/index
Buckets/index
Dashboards/index
Expand Down
2 changes: 1 addition & 1 deletion src/tagoio_sdk/common/Common_Type.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
GenericToken = str
"""Token used on TagoIO, string with 36 characters"""

ExpireTimeOption = "never" or datetime
ExpireTimeOption = Union[Literal["never"], datetime]

PermissionOption = Literal["write", "read", "full", "deny"]

Expand Down
3 changes: 3 additions & 0 deletions src/tagoio_sdk/modules/Resources/AccountDeprecated.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from tagoio_sdk.common.tagoio_module import GenericModuleParams

from .Account import Account
from .Analyses import Analyses
from .Billing import Billing
from .Buckets import Buckets
from .Dashboards import Dashboards
Expand All @@ -19,6 +20,8 @@ class AccountDeprecated(Account):
"""

def __init__(self, params: GenericModuleParams):
self.analysis = Analyses(params)
"""@deprecated moved to Resources().analysis"""
self.buckets = Buckets(params)
"""@deprecated moved to Resources().buckets"""
self.dashboards = Dashboards(params)
Expand Down
Loading
Loading