#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ISPForum internet quality measurement daemon
# Marek Wajdzik 29.10.2017 <wajdzik.m@gmail.com>

import logging
import time
import os 
import sys

class SampleData(object):
    def __init__(self, size=32768):
        #Logger
        self.logger = logging.getLogger("sampledata")
        self.size = size
        self.logger.info("Sampledata initialized")
        self.data = []
    
    def fast_random(self):
        tbl = bytes.maketrans(bytearray(range(256)),
                bytearray([ord(b'a') + b % 26 for b in range(256)]))
        return os.urandom(64).translate(tbl)

    def pop_data(self):
        # return data only when we have some random values
        while True:
            if len(self.data)>1:
                return self.data.pop()
    
    def main_loop(self):
        while True:
            if not len(self.data) > 500:
                # Buffer random to make measurements more accurate
                self.data.append(
                    self.fast_random()
                )
            time.sleep(0.0001)