makerplane / FIX-Gateway

Flight Information eXchange Gateway
GNU General Public License v2.0
9 stars 20 forks source link

gw persistence #94

Closed qubolino closed 2 years ago

qubolino commented 2 years ago

is there a plugin for persistence of all db fields over time?

birkelbach commented 2 years ago

Do you mean something like a historical logging plugin, for recording flight data? If so then it would be easy enough to code. There are some decisions to make. Most important would be what file format (CSV, custom binary, SQLlite, ...) Another question would be how much data to store, and/or how to handle filling up the media. I agree this would be an important plugin but it just has not been done yet.

qubolino commented 2 years ago

essentially, yes. the more i dig into makerplane the more i agree it'd be fairly easy. in terms of file format, anything easily readable by pandas would do imho.

qubolino commented 2 years ago

could anyone point me to a snippet where a plugin subscribes to fields changes please? i'll write a short draft

birkelbach commented 2 years ago

The PluginBase class has a function for adding callback functions to the database. Anytime the data changes the assigned function would be called. The function definition is...

db_callback_add(self, key, function, udata=None):

The function that you pass should take three arguments. The database key, the new value and whatever udata (userdata) you assigned...

def myFunc(key, value, udata):
    do some stuff()
    do some more stuff()

...

self.db_callback_add(self, "OILP1", myFunc, None)

Hope this helps. Admittedly the documentation could use some love.

qubolino commented 2 years ago

ok, so: mixing demo.py and your explanation, something like

def persist(key, value, udata=None):
    print(key, value). # TODO persist in file or like

class MainThread(threading.Thread):
    def __init__(self, parent):
        super(MainThread, self).__init__()
        self.getout = False   # indicator for when to stop
        self.parent = parent  # parent plugin object
        self.log = parent.log  # simplifies logging
        self.keylist = {"ROLL":3, "PITCH":0, "IAS":113, "ALT":4220,
                        "TACH1":2450, "MAP1":24.2, "FUELP1":28.5, "OILP1":56.4,
                        "OILT1":95, "FUELQ1":11.2, "FUELQ2":19.8, "OAT": 32,
                        "CHT11":201,"CHT12":202,"CHT13":199,"CHT14":200,
                        "EGT11":710,"EGT12":700,"EGT13":704,"EGT14":702,
                        "FUELF1":8.7,"VOLT":13.7,"CURRNT":45.6
                        }

        for key in self.keylist.keys():
            self.parent.db_callback_add(key, persist)

    def run(self):
        while not self.getout:
            time.sleep(1.0)
        self.running = False

    def stop(self):
        self.getout = True

[...]
qubolino commented 2 years ago

ok. i have something. how do i make a pull request?

birkelbach commented 2 years ago

First create a fork of the repo on GitHub. Then add that new fork as a remote on your local repo. Push to your GitHub fork and then create a pull request on GitHub.

qubolino commented 2 years ago

created PR https://github.com/makerplane/FIX-Gateway/pull/95