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

v0.8.2 : add data source logic and link it to variable, remove CalculatedVariable #109

Merged
merged 9 commits into from
Jan 29, 2024

Conversation

clavay
Copy link
Collaborator

@clavay clavay commented Jan 25, 2024

Minor changes:

  • add operations and aggregation protocols
  • fix migration WidgetCotent update for Charts
  • plugin can add apps to INSTALLED_APPS in settings.py
  • fix for get_objects_for_html

Major changes:

  • add DataSourceModel (define how a data source appears in the admin), Datasource (base for all datasource) and DjangoDatabase (allows to define data sources as django models like RecordedData or RecordedDataOld)
  • create VariableManager (replacing the RecordedDataValueManager to support data sources)
  • delete CalculatedVariable : moved to the PyScada-Operations plugin (aggregation protocol)

a plugin can specify additional apps to add to INSTALLED_APPS

in the __init__.py file of the plugin (in pyscada/pluginName) :
add a list named :
additional_installed_app = ["pyscada.otherAppX", "pyscada.otherAppY"]

exemple in the pyscada-operations plugin.
DataSourceModel :
Used to define a data source type.
The data source base model have a foreign key to this model to specify
the configuration :
- the name,
- can add, modify on select in the admin panel,
- the model name of the inline having the specific config (fields,
functions, manager).

DataSource :
The base model for all the data sources.
A data source needs to inherit from this class, and should have the
basic functions :
- last_value,
- read_multiple,
- write_multiple,
- get_first_element_timestamp,
- get_last_element_timestamp.

DjangoDatabase :
Specify a table to store the values. The table model should have a
manager similar to the RecordedDataManager (functions).

The default data source added is the RecordedData table.

To add new data source, look at the example in pyscada-operations.
To switch to the data source architecture, use the VariableManager
function in order to :
- filter Variable list by datasource (_get_variables_by_datasource)
- read values from datasources (read_multiple)
- write values to datasources (write_multiple)
- get first timestamp recorded for a variable list
(get_first_element_timestamp)
- get last one (get_last_element_timestamp)

Plugins and handlers should not use directly the RecordedDataManager but
the VariableManager in order to talk to differents data sources.

Look at the new way to save read data from GenericDevice and
GenericDeviceHandler in pyscada/device.py and in the pyscada.operations
plugin.
in order to not loose your calculated variables you should install
pyscada.operations plugin before running the pyscada migration 108.
@clavay clavay requested a review from trombastic January 25, 2024 13:59
Copy link
Collaborator

@trombastic trombastic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do the changes of this commit allow to keep existing data in the "old" RecordedData Database?

pyscada/apps.py Outdated
},
)

except ProgrammingError:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should at least be logged

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProgrammingError and OperationalError appears when migrations are not yet applied.
Do you think we should add log for this case ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes i think so, otherwise it is not visible for the user/admin what happend

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do it on Monday.

pyscada/apps.py Outdated
except ProgrammingError:
pass
except OperationalError:
pass
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should at least be logged

@@ -19,6 +19,8 @@ Device Protocol IDs
- 15: `MeterBus (MBus) <https://github.com/pyscada/PyScada-MeterBus>`_
- 16: Generic dummy device
- 17: `EMS <https://github.com/pyscada/PyScada-EMS>`_
- 18: `Operations <https://github.com/pyscada/PyScada-Operations>`_
- 19: `Aggregation <https://github.com/pyscada/PyScada-Operations>`_
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the URL seems to be wrong

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is in my account, so the pyscada organization can fork it to make to link exist.
what do you think ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, fork is done

both apps have the same Repo so the URL is okay

@clavay
Copy link
Collaborator Author

clavay commented Jan 26, 2024

do the changes of this commit allow to keep existing data in the "old" RecordedData Database?

Are you talking about the RecordedDataOld table ?
The changes does not touch the RecordedDataOld.
But we need to specify the manager to use for this model, for this we can adapt the RecordedDataManager to never use date_saved.
What do you think ?

@trombastic
Copy link
Collaborator

if i have a working pyscada installation with data in the RecordedData table, will this data be preserved and accessible after the update?

@clavay
Copy link
Collaborator Author

clavay commented Jan 26, 2024

Yes, default (here) is for each variable to use the first (id=1, here) data source, which is the DataSource linked to the RecordedData table.

A plugin can add datasource using the DjangoDatabase model and define another table to use (as here for the RecordedDataOld table).

A plugin can also, as the PyScada-Operations plugin, add another DataSourceModel, create a DataSource and create a model with a OneToOne relation to the DataSource model, specifying additional fields and the functions needed (read, write, last element... as described in the commit 7110864 message), as done by the OperationsDataSource

I will publish a simple plugin creating random data in the read function and logging values in the write function as an example.
I will also add some documentation later.

@clavay
Copy link
Collaborator Author

clavay commented Jan 29, 2024

I add the logs for ProgrammingError and OperationalError while populating models

Is it ok for merging ?

@trombastic trombastic merged commit ff99126 into pyscada:main Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants