I'm trying to use MySQL to save some time-series boolean data, and then make a decision according to the saved data.
I am required to save the last 144 samples, and then check if more than X% are non-zero.
I try to use a Numeric field with a scale of 44. At some point the data is truncated to 9999999999.
That's how I created the column:
op.add_column('object', sa.Column('data_history', sa.Numeric(scale=44), nullable=False, default=0)) Here's my code that handles the calculation:
happens_now = data < DATA_THRESHOLD mask = 0 for i in xrange(144): mask <<= 1 mask |= 1 safe_logging.info('History: {} LongHistory: {}'.format(my_object.data_history, long(my_object.data_history))) my_object.data_history *= 2 safe_logging.info('History: {} LongHistory: {}'.format(my_object.data_history, long(my_object.data_history))) my_object.data_history += happens_now safe_logging.info('History: {} LongHistory: {}'.format(my_object.data_history, long(my_object.data_history))) history_to_consider = long(my_object.data_history) & mask safe_logging.info('Mask: {} Data: {} Happens now: {} History: {}'.format(mask, data, happens_now, history_to_consider)) pop_count = self._PopCount(history_to_consider) if (not my_object.is_total) and pop_count/144 > PERCENTAGE_THERSHOLD: my_object.is_total = True Here's my log output for two consecutive data insertions:
INFO: History: 8589934591 LongHistory: 8589934591 INFO: History: 17179869182 LongHistory: 17179869182 INFO: History: 17179869183 LongHistory: 17179869183 INFO: Mask: 22300745198530623141535718272648361505980415 Data: 10 Happens now: True History: 17179869183 INFO: History: 9999999999 LongHistory: 9999999999 INFO: History: 19999999998 LongHistory: 19999999998 INFO: History: 19999999999 LongHistory: 19999999999 INFO: Mask: 22300745198530623141535718272648361505980415 Data: 10 Happens now: True History: 19999999999 I tried to find a limitation in MySQL docs and couldn't. Python seems to handle well long numbers (see mask).
Is it a SQLAlchemy limitation? Some MySQL limitation I missed?