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

Offline mode / SQLite problems #94

Closed
ChristianTremblay opened this issue Aug 30, 2018 · 3 comments
Closed

Offline mode / SQLite problems #94

ChristianTremblay opened this issue Aug 30, 2018 · 3 comments

Comments

@ChristianTremblay
Copy link
Owner

[bug received by email]

I successfully managed to set up the connection, connect to the devices
I am interested to, send commands, see points, plot historical values,
etc., and also to save devices' data to a database with the command
dev_S10_AS01.save(), as explained in section 4.7 of the documentation
(dev_S10_AS01 is the name I gave to one of the controllers): the files
S10'AS01.db and S10'AS01.bin are correctly created (S10'AS01 is the
"actual" name of the controller in our system).

Then, I try to retrieve off-line the data I saved with the following
steps (in Spyder):

In [1]: import BAC0

In [2]: bacnet=BAC0.connect(ip='172.16.1.220')
Starting BAC0 version 0.99.921 (Complete)
Registered as Simple BACnet/IP App
Server started : http://172.16.1.220:8111
Bokeh server already running There is no current event loop in thread 
'Thread-7'.
Flask server already running not writable

In [3]: dev_S10_AS01=BAC0.device('172.16.1.201',2107393,bacnet)
2018-08-29 11:43:09,386 - WARNING | Offline: provide database name to 
load stored data.
WARNING:BAC0:Offline: provide database name to load stored data.
2018-08-29 11:43:09,389 - WARNING | Ex. controller.connect(db = 'backup')
WARNING:BAC0:Ex. controller.connect(db = 'backup')

In [4]: cd test_seb_2018_08_24
C:\Users\Administrator\test_seb_2018_08_24

In [5]: dev_S10_AS01.connect(db="S10'AS01")
Device restored from db

Till now, everything works just fine; but now, if I try to see the 
history of a point (a temperature sensor), just as I would do when on-line:

In [6]: dev_S10_AS01["HC'HC06'Sen'TRt"].history
Traceback (most recent call last):

   File "<ipython-input-6-5f5e1e19bfc2>", line 1, in <module>
     dev_S10_AS01["HC'HC06'Sen'TRt"].history

   File 
"C:\ProgramData\Anaconda3\lib\site-packages\BAC0\core\devices\Device.py", 
line 410, in __getitem__
     return self._findPoint(point_name)

   File 
"C:\ProgramData\Anaconda3\lib\site-packages\BAC0\core\devices\Device.py", 
line 505, in _findPoint
     point.value

   File 
"C:\ProgramData\Anaconda3\lib\site-packages\BAC0\core\devices\Points.py", 
line 645, in value
     value = self.lastValue

   File 
"C:\ProgramData\Anaconda3\lib\site-packages\BAC0\core\devices\Points.py", 
line 131, in lastValue
     return self.history.dropna().iloc[-1]

   File 
"C:\ProgramData\Anaconda3\lib\site-packages\BAC0\core\devices\Points.py", 
line 635, in history
     'history', self.properties.device.db))

TypeError: read_sql() missing 1 required positional argument: 'con'

The problem seems to lie in lines 634-635 of Points.py (here I copy from 
631 to 637):

class NumericPointOffline(NumericPoint):
     @property
     def history(self):
         his = sql.read_sql('select * from "{}"'.format(
             'history', self.properties.device.db))
         his.index = his['index'].apply(Timestamp)
         return his.set_index('index')[self.properties.name]

If I got it correctly, read_sql(sql,con) needs at least two arguments:
the query (sql) and the connectable database (con), but it seems that
the lines:

his = sql.read_sql('select * from "{}"'.format(
             'history', self.properties.device.db))

are not "interpreted" that way.
What am I missing? Unfortunately, my knowledge of python is very limited
and I am not able to see it.

ChristianTremblay added a commit that referenced this issue Sep 5, 2018
Signed-off-by: Christian Tremblay <christian.tremblay@servisys.com>
@ChristianTremblay
Copy link
Owner Author

Documentation needs to be updated

@ChristianTremblay ChristianTremblay added the Documentation needed Need to document this label Sep 28, 2018
@ChristianTremblay
Copy link
Owner Author

I broke something in 0.99.942
Will work on it and make a test

@ChristianTremblay
Copy link
Owner Author

Work have been done on SQL, I'll close and reopen if required...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant