示例#1
0
    def __init__(self, calib, dt=0.01):
        super(INS, self).__init__()

        # self.imuCalibration = ImuCalibration('/home/xaedes/bags/mit_kamera/magcalib/2014-08-20-17-33-13.bag')
        self.imuCalibration = calib

        self.states = ['speed', 'orientation', 'yaw_rate', 'pos_x', 'pos_y']
        self.states = dict(map((lambda x: (x, 0)), self.states))

        self.dt = dt

        self.gyro_integrated = Integrator()
        self.accel_integrated = Integrator()

        self.orientation_error = WienerKalman(
            self.dt, self.imuCalibration.gyro_z_variance,
            self.imuCalibration.mag_theta_variance)
        self.velocity_error = WienerKalman(
            self.dt, self.imuCalibration.accel_x_variance,
            self.imuCalibration.odometer_variance)

        self.vx_integrated = Integrator()
        self.vy_integrated = Integrator()

        self.mag_offset = None
        self.o_error_last = None

        self.velocity_carthesian_history = RingBuffer(100, 2)
示例#2
0
 def __init__(self, file, logLimit, exchange=''):
     self.jsonOutputFile = file
     self.jsonOutput = {}
     self.clearStatusValues()
     self.jsonOutputLog = RingBuffer(logLimit)
     self.jsonOutput['exchange'] = exchange
     self.jsonOutput['label'] = Config.get("BOT", "label", "Lending Bot")
    def run(self):
        # Queue
        if self.name == 'pack_data_user1':
            queue_packets = hold_data.queuePacketsUser1
        elif self.name == 'pack_data_user2':
            queue_packets = hold_data.queuePacketsUser2
        else:
            queue_packets = []
            logging.error('(Thread) BlockPackData (name : ' + self.name +
                          '): problem selecting queue, queue_packets is empty')

        # Objects
        if self.name == 'pack_data_user1':
            ring_buffer = RingBuffer(hold_data.bufferBinFilesDataUser1)
        elif self.name == 'pack_data_user2':
            ring_buffer = RingBuffer(hold_data.bufferBinFilesDataUser2)
        else:
            ring_buffer = []
            logging.error(
                '(Thread) BlockPackData (name : ' + self.name +
                '): problem selecting ring_buffer, ring_buffer is empty')

        while True:

            # checks if the queue is full
            # size of queue is defined in the HoldData files
            if not queue_packets.full():
                # --------------------------- Get payload --------------------------
                # Get a payload that need to be packed
                payload = ring_buffer.get_payload_from_buffer()
                # ---------------------------- Add Packet --------------------------
                # Make the packet
                packet = util.create_packet(payload)
                # Add the packet in the queue
                queue_packets.put(packet)

                # ----------------------------- logger -----------------------------
                # Shows who is getting or setting data to or from the buffer/queue
                # and shows the size of the queue
                # logging.debug('Add data: ' + str(packet)
                #               + ' : ' + str(queue_packets.qsize()) + ' items in queue')

        return
示例#4
0
    def __init__(self, source):
        ##
        self.source = source
        self.mAppSink = None
        self.mBus = None
        self.mPipeline = None
        self.isStreaming = False

        self.mBufferRGB = RingBuffer()
        self.mWaitEvent = Event()

        print("INFO -- Creating Gst Source")
        self.start()
        print("INFO -- Created Gst Source")
def main():
#    e0 = Element(0)
#    e1 = Element(1)
#    e2 = Element(2)
#    e3 = Element(3)
    rb = RingBuffer(4)
    rb.append(0)
    rb.append(1)
    rb.append(2)
    rb.append(3)
    rb.append(4)
    rb.append(5)
    print(rb.delete())
    print(rb.delete())
    print(rb.get_data())
示例#6
0
    def run(self):
        rb = RingBuffer(56)

        while self.measure:
            rb.append(self.ser.read(1)[0])
            if rb[0] == ord("B") and rb[1] == ord("E") and rb[54] == ord(
                    "E") and rb[55] == ord("N"):
                timestamp = int.from_bytes(bytes(rb[2:6]), byteorder="little")
                timestamp = timestamp & 0xffffffff
                data = np.fromstring(bytes(rb[6:54]), dtype="<f")
                if self.start_time is None:
                    self.start_time = timestamp
                self.newData.emit([timestamp - self.start_time, data])

        self.ser.close()
示例#7
0
 def __init__(self, process_config_obj=None):
     if process_config_obj != None and type(process_config_obj) == type(
             ProcessConfig()):
         self.name = process_config_obj.name
         self.startcmds = process_config_obj.startcmds
         self.wdir = process_config_obj.wdir
         self.outlines = process_config_obj.outlines
         self.outbuffer = RingBuffer(self.outlines)
         self.stdin_pipe = process_config_obj.stdin_pipe
         self.envdict = process_config_obj.envdict
         self.startuplvl = process_config_obj.startuplvl
         ###
     self.retcode = None
     self.subproc = None
     self.started = False
     self.tmpfpath = None
     self.stdout_queue = None
     self.stdout_thread = None
示例#8
0
    def run(self):
        """
        This function is the main loop of the Process and is where driver
        data is received. The camera driver is created here as  the
        __init__() function is not run in this Process. This loop waits for
        data from the camera driver and either compute or pass frames to the
        shared buffer to be used by another process.
        """
        if(self.openni_version==True):
        	device = OpenNi2Driver(fps_window=self.driver_fps_window)
        	print('OpenNi2Driver')
        else:
        	device = OpenNiDriver(fps_window=self.driver_fps_window)   
        	print('OpenNiDriver') 	
        self.height = device.height
        self.width = device.width
        self.ring_buffer = RingBuffer(self.height, self.width,
                                      self.buffer_size)
        frame_number = 0
        chacha = device.wait_and_get_depth_frame()
        background_frame = ones_like(chacha) * 65535    ####### 65535 is maximum of uint16
        replace_value = int((summ(chacha) / summ(chacha) != 0)) *66   ######### TO BE CHECKED!
        print("[Driver] Replacing bad values with {}".format(replace_value))

        print("[Driver] Estimating background from {} " \
              "frames".format(self.nb_background_frame))
        mean = zeros(chacha.shape)
        stdev = zeros(chacha.shape)

        try:
            while not self.cancel.value:
                # We wait for the consumer thread to handle the frame before
                # writing a new one
                while self.frame_available.is_set():
                    pass
                else:
                    frame = device.wait_and_get_depth_frame()
                   # self.ring_buffer.extend(frame)   #################################  ONLY NECESSARY IF RECORDING (1)

                if self.background_ready:
                    # Synchronized write access to shared array
                    # with self.shared_array.get_lock():
                    arr = frombuffer(self.shared_array.get_obj(),
                                        dtype='I').reshape(self.height,
                                                           self.width)
                    arr[:] = frame
                    self.frame_available.set()

                else:
                    frame_number = frame_number + 1
         #           print(frame_number)

                    if frame_number <= self.nb_background_frame:
                        mean = mean + frame
                        for j in range(frame.shape[0]):
                            for k in range(frame.shape[1]):
                                if frame[j][k] < background_frame[j][k] and \
                                    frame[j][k] != 0:
                                    background_frame[j][k] = frame[j][k]
                                elif frame[j][k] == 0:
                                    background_frame[j][k] = replace_value
                        if (frame_number == self.nb_background_frame):
                            self.background = background_frame
                            mean = mean / self.nb_background_frame

                    if (frame_number >= self.nb_background_frame) and (frame_number-1 < (self.nb_background_frame*2)):
                        # Compute standard deviation frame
                        stdev += (frame - mean) ** 2
                        if (frame_number == (self.nb_background_frame*2)):
                            stdev = stdev / self.nb_background_frame
                            stdev = roundd(sqrtt(stdev), 0)
                            # Extract values for parameters estimation
                            self.middle_pixel_value = mean[int(self.height / 2)][
                                int(self.width / 2)]


                            self.percentile_stdev = percentile(stdev, 97)      





                            self.compute_parameters()
                            arr = frombuffer(self.shared_array.get_obj(),
                                                dtype='I').reshape(self.height,
                                                                   self.width)
                            arr[:] = self.background
                            self.background_ready = True
                            print("[Driver] Background ready")
                            self.frame_available.set()
#                        del frame_list  ####################### adicionado por mi

           #     if self.recording_trigger.is_set():  #################################  ONLY NECESSARY IF RECORDING (4)
#                    self.async_buffer_save()    #################################  ONLY NECESSARY IF RECORDING (2)
#                    self.recording_trigger.clear()    #################################  ONLY NECESSARY IF RECORDING (3)
            print("[Driver] Process closing")
            device.shutdown()

        except Exception:
            print("[Driver] Exception in process")
            device.shutdown()
            raise
示例#9
0
    def run(self):
        """
        This function is the main loop of the Process and is where driver
        data is received. The camera driver is created here as  the
        __init__() function is not run in this Process. This loop waits for
        data from the camera driver and either compute or pass frames to the
        shared buffer to be used by another process.
        """
        if (self.openni_version == True):
            device = OpenNi2Driver(fps_window=self.driver_fps_window)
            print('')
            print('')
            print('')
            print('OpenNi2Driver')
            print('')
            print('')
            print('')
        else:
            device = OpenNiDriver(fps_window=self.driver_fps_window)
            print('')
            print('')
            print('')
            print('OpenNiDriver')
            print('')
            print('')
            print('')
        self.height = device.height
        self.width = device.width
        self.ring_buffer = RingBuffer(self.height, self.width,
                                      self.buffer_size)
        frame_list = []

        try:
            while not self.cancel.value:
                # We wait for the consumer thread to handle the frame before
                # writing a new one
                while self.frame_available.is_set():
                    pass
                else:
                    frame = device.wait_and_get_depth_frame()
                    self.ring_buffer.extend(frame)

                if self.background_ready:
                    # Synchronized write access to shared array
                    # with self.shared_array.get_lock():
                    arr = np.frombuffer(self.shared_array.get_obj(),
                                        dtype='I').reshape(
                                            self.height, self.width)
                    arr[:] = frame
                    self.frame_available.set()

                else:
                    frame_list.append(frame)

                    if len(frame_list) >= self.nb_background_frame:
                        # Estimate background
                        print("[Driver] Estimating background from {} " \
                              "frames".format(self.nb_background_frame))
                        arr = np.frombuffer(self.shared_array.get_obj(),
                                            dtype='I').reshape(
                                                self.height, self.width)
                        self.background = self.background_estimation(
                            frame_list)
                        self.compute_std_dev(frame_list)
                        self.compute_parameters()
                        arr[:] = self.background
                        self.background_ready = True
                        print("[Driver] Background ready")
                        self.frame_available.set()
#                        del frame_list  ####################### adicionado por mi

                if self.recording_trigger.is_set():
                    self.async_buffer_save()
                    self.recording_trigger.clear()
            print("[Driver] Process closing")
            device.shutdown()

        except Exception:
            print("[Driver] Exception in process")
            device.shutdown()
            raise
示例#10
0
 def __init__(self, file, logLimit):
     self.jsonOutputFile = file
     self.jsonOutput = {}
     self.clearStatusValues()
     self.jsonOutputLog = RingBuffer(logLimit)
示例#11
0
 def __init__(self, file, logLimit, exchange=''):
     self.jsonOutputFile = file
     self.jsonOutput = {}
     self.clearStatusValues()
     self.jsonOutputLog = RingBuffer(logLimit)
     self.jsonOutput['exchange'] = exchange
示例#12
0
 def __init__(self, nodeid, buffersize=10):
     self.nodeid = nodeid
     self.buffersize = buffersize
     self.buffer = RingBuffer(buffersize)
示例#13
0
 def setUp(self):
     # self._log = logging.getLogger("RingBuffer.Tests")
     self.sample_data = np.arange(10.0)
     self.ring_buffer = RingBuffer(10)
'''
https://blog.francoismaillet.com/epic-celebration/
'''
import pyaudio
import librosa
import numpy as np
import requests
from RingBuffer import RingBuffer
import sounddevice as sd
from time import sleep
import time
import serial
# ring buffer will keep the last 2 seconds worth of audio
ringBuffer = RingBuffer(5 * 22050)
arduinodata=serial.Serial('com4',9600,timeout=(1))
tempo=0
def callback(in_data, frame_count, time_info, flag):
    audio_data = np.frombuffer(in_data, dtype=np.float32)
    
    # we trained on audio with a sample rate of 22050 so we need to convert it
    audio_data = librosa.resample(audio_data, 44100, 22050)
    ringBuffer.extend(audio_data)
    # analysis beat
    #print(audio_data)
    onset_env = librosa.onset.onset_strength(ringBuffer.get(), sr=22050, aggregate=np.median)
    tempo, beat_times = librosa.beat.beat_track(onset_envelope=onset_env, sr=22050)
    #tempo = librosa.beat.tempo(ringBuffer.get(), sr=22050, start_bpm=60)
    print("tempo: ", tempo)
    arduinodata.reset_input_buffer()
    arduinodata.reset_output_buffer()
    if tempo<90:
示例#15
0
 def __init__(self, file, logLimit):
     self.jsonOutputFile = file
     self.jsonOutput = {}
     self.jsonOutputCoins = {}
     self.jsonOutput["raw_data"] = self.jsonOutputCoins
     self.jsonOutputLog = RingBuffer(logLimit)
示例#16
0
 def setUp(self):
     self.ringbuffer = RingBuffer(2)
示例#17
0
    def process_subtitles(self, srtpath):
        '''
        Process ``scenario.txt``,
        translate «date-based» subtitles to time-bases SRT-subtitles.
        '''
        lf = open(self.scenariopath, "r")
        subtitles = lf.read().decode("utf-8")
        lf.close()

        subtitles = re.sub(r"(?m)^#[^\n]*\n?", "", subtitles)
        scenario = []
        for line in subtitles.splitlines():
            if len(line.split(" ", 1)) > 1:
                datas, text = line.split(" ", 1)
                vcstime = None
                datas = datas.replace(u'\ufeff', '')
                for format in ["%d.%m.%Y", "%Y-%m-%d"]:
                    try:
                        vcstime = time.strptime(datas.encode("latin-1"),
                                                format)
                        break
                    except ValueError:
                        pass
                if not vcstime:
                    print "Warning: can not understand date <%s>" % datas

                subtitletimestart = (time.mktime(vcstime) - time.mktime(
                    self.startdate)) * self.movielength / self.historylength
                if -1 < subtitletimestart < 0:
                    subtitletimestart = 0
                if subtitletimestart < 0:
                    print "Date <%s> before start of work history" % datas
                else:
                    scenario.append((subtitletimestart, text))

        if len(scenario) == 0:
            return

        scenario.sort()

        messages = RingBuffer(3)

        class SRTText:
            """
              Subtitles in SRT format
            """
            def __init__(self):
                self.srt = ""
                self.index = 0
                self.stime = float(max([scenario[0][0] - 1, 0]))
                self.etime = 0.0

            def append(self, messages):
                """
                Append subtitle from list of messages
                """
                ml = messages.get()
                msg = " * ".join(ml)
                subtitletimestart_str = time.strftime("%H:%M:%S",
                                                      time.gmtime(self.stime))
                subtitletimeend_str = time.strftime("%H:%M:%S",
                                                    time.gmtime(self.etime))
                self.srt += """
%d
%s,000 --> %s,000
%s
                """ % (self.index, subtitletimestart_str, subtitletimeend_str,
                       msg)
                self.stime = self.etime
                self.index += 1

        default_subtitle_time = 3
        srt_text = SRTText()
        for s in scenario:
            newtime = float(s[0])
            if newtime > srt_text.stime + default_subtitle_time:
                srt_text.etime = srt_text.stime + default_subtitle_time
                srt_text.append(messages)
                messages = RingBuffer(3)
                srt_text.stime = newtime
            else:
                srt_text.etime = newtime
                srt_text.append(messages)
            messages.append(s[1])
        srt_text.etime = min(srt_text.etime + 3, self.movielength)
        srt_text.append(messages)

        lf = open(srtpath, "w")
        lf.write(srt_text.srt.encode("utf-8"))
        lf.close()
示例#18
0
    def __init__(self, logger):
        """
        Connects to LoRaWAN using OTAA and sets up a ring buffer for storing messages.
        :param logger: status logger
        :type logger: LoggerFactory object
        """

        self.logger = logger
        self.message_limit = int(
            float(config.get_config("fair_access")) /
            (float(config.get_config("air_time")) / 1000))
        self.transmission_date = config.get_config(
            "transmission_date")  # last date when lora was transmitting
        today = time.gmtime()
        date = str(today[0]) + str(today[1]) + str(today[2])
        if self.transmission_date == date:  # if device was last transmitting today
            self.message_count = config.get_config(
                "message_count")  # get number of messages sent today
        else:
            self.message_count = 0  # if device was last transmitting a day or more ago, reset message_count for the day
            self.transmission_date = date
            config.save_config({
                "message_count": self.message_count,
                "transmission_date": date
            })

        regions = {
            "Europe": LoRa.EU868,
            "Asia": LoRa.AS923,
            "Australia": LoRa.AU915,
            "United States": LoRa.US915
        }
        region = regions[config.get_config("region")]

        self.lora = LoRa(mode=LoRa.LORAWAN, region=region, adr=True)

        # create an OTAA authentication parameters
        app_eui = ubinascii.unhexlify(config.get_config("application_eui"))
        app_key = ubinascii.unhexlify(config.get_config("app_key"))

        # join a network using OTAA (Over the Air Activation)
        self.lora.join(activation=LoRa.OTAA,
                       auth=(app_eui, app_key),
                       timeout=0)

        # create a LoRa socket
        self.lora_socket = socket.socket(socket.AF_LORA, socket.SOCK_RAW)

        # request acknowledgment of data sent
        # self.lora_socket.setsockopt(socket.SOL_LORA, socket.SO_CONFIRMED, True)

        # do not request acknowledgment of data sent
        self.lora_socket.setsockopt(socket.SOL_LORA, socket.SO_CONFIRMED,
                                    False)

        # sets timeout for sending data
        self.lora_socket.settimeout(
            int(config.get_config("lora_timeout")) * 1000)

        # set up callback for receiving downlink messages
        self.lora.callback(trigger=LoRa.RX_PACKET_EVENT,
                           handler=self.lora_recv)

        # initialises circular lora stack to back up data up to about 22.5 days depending on the length of the month
        self.lora_buffer = RingBuffer(self.logger, s.processing_path,
                                      s.lora_file_name,
                                      31 * self.message_limit, 100)

        try:  # this fails if the buffer is empty
            self.check_date()  # remove messages that are over a month old
        except Exception as e:
            pass
示例#19
0
 def __init__(self, file, logLimit):
     self.jsonOutputFile = file
     self.jsonOutput = {}
     self.jsonOutputLog = RingBuffer(logLimit)
示例#20
0
 def __init__(self, api_key, secret):
     self.APIKey = api_key
     self.Secret = secret
     self.req_per_sec = 6
     self.req_time_log = RingBuffer(self.req_per_sec)
     self.lock = threading.RLock()
示例#21
0
    def __init__(self):
        super(App, self).__init__()
        # load background
        self.background = Background(filename="background.png")

        # get array copy of background image
        self.background.arr = pygame.surfarray.array3d(self.background.img)

        # create bw from image
        _, self.background.arr_bw = cv2.threshold(self.background.arr[:, :, 0],
                                                  128, 1, cv2.THRESH_BINARY)

        # print self.background.arr_bw.shape, self.background.arr_bw.dtype
        # self.background.arr_dist = cv2.distanceTransform(self.background.arr_bw, cv.CV_DIST_L1, 3)

        # get nearest (zero) pixel labels with corresponding distances
        self.background.arr_dist, self.labels = cv2.distanceTransformWithLabels(
            self.background.arr_bw,
            cv.CV_DIST_L1,
            3,
            labelType=cv2.DIST_LABEL_PIXEL)
        self.distances = self.background.arr_dist

        ### get x,y coordinates for each label
        # get positions of zero points
        zero_points = Utils.zero_points(self.background.arr_bw)
        # get labels for zero points
        zero_labels = self.labels[zero_points[:, 0], zero_points[:, 1]]
        # create dictionary mapping labels to zero point positions
        self.label_positions = dict(
            zip(zero_labels, zip(zero_points[:, 0], zero_points[:, 1])))

        # create hilbert curve lookup table
        self.hilbert = Hilbert.hilbert_lookup(*self.background.arr.shape[:2])

        # provide a rgb variant of dist for display
        self.background.arr_dist_rgb = self.background.arr.copy()
        self.background.arr_dist_rgb[:, :, 0] = self.background.arr_dist
        self.background.arr_dist_rgb[:, :, 1] = self.background.arr_dist
        self.background.arr_dist_rgb[:, :, 2] = self.background.arr_dist
        # print a.shape

        self.setup_pygame()

        self.events = Events()

        self.lane = Lane(self.events)
        self.lane.load("parkour.sv")
        # self.lane.add_support_point(100,100)
        # self.lane.add_support_point(200,100)
        # self.lane.add_support_point(200,200)
        # self.lane.add_support_point(100,200)

        self.optimize = Optimize(self.lane)

        self.cars = []
        # for k in range(1):
        # self.cars.append(Car(x=150+k*5,y=100,theta=np.random.randint(0,360),speed=np.random.randint(45,180)))
        self.cars.append(Car(x=50, y=250, theta=90, speed=1 * 1.5 * 90))
        self.cars.append(Car(x=50, y=250, theta=90, speed=1 * 90))  # [1] human
        self.cars.append(Car(x=50, y=250, theta=90,
                             speed=1 * 90))  # [2] ghost of ins estimating [0]

        self.action = None
        self.human = HumanController()
        self.heuristic = Heuristic(self.lane)
        Node.heuristic = self.heuristic

        self.onestep = OneStepLookaheadController(self.cars, self.lane,
                                                  self.heuristic)
        self.nstep = NStepLookaheadController(self.cars, self.lane,
                                              self.heuristic, 2)
        self.bestfirst = BestFirstController(self.cars, self.lane,
                                             self.heuristic)
        self.controller = self.bestfirst

        self.cars[0].camview = CamView(self.cars[0], self.background.arr)
        self.cars[0].camview.register_events(self.events)

        self.cars[0].controller = self.controller
        self.cars[0].collision = False
        self.cars[0].imu = IMU(self.cars[0])
        self.cars[0].ins = INS(self.cars[0].imu.calibration_noise)
        self.cars[0].ins.update_pose(self.cars[0].x,
                                     self.cars[0].y,
                                     self.cars[0].theta / Utils.d2r,
                                     gain=1)
        self.insghost = INSGhostController(self.cars[0].ins)
        self.cars[1].controller = self.human
        self.cars[2].controller = self.insghost
        self.cars[2].collision = False
        self.cars[2].size *= 1.25
        self.cars[2].camview = CamView(self.cars[2],
                                       self.background.arr_dist_rgb,
                                       width=275,
                                       height=275,
                                       offset=(0, 75),
                                       angle_offset=-25)
        self.cars[2].camview.register_events(self.events)

        self.cars[0].name = "actual"
        self.cars[1].name = "human"
        self.cars[2].name = "estimate"

        # this causes the controller of cars[0] to use the information from cars[0].ghost but act on cars[0]
        # self.cars[0].ghost = self.cars[2]

        # self.window = Window(self.screen, self.events, 300, 200, "caption")

        self.grid = Grid(50, 50, *self.size)
        self.last_distance_grid_update = time() - 10
        self.update_distance_grid()

        self.done = False

        for car in self.cars:
            # save original speed
            if not hasattr(car, "speed_on"):
                car.speed_on = car.speed
            # toggle speed
            car.speed = car.speed_on - car.speed

            # car.pause = not car.pause

        self.plot_window_size = 100
        self.xyt_corr_ring_buffer = RingBuffer(self.plot_window_size,
                                               channels=3)
        self.xyt_corr_plot = RingBufferPlot(self.xyt_corr_ring_buffer)
        # self.normal_test_p_value_plot = RingBufferPlot(RingBuffer(self.plot_window_size,channels=self.xyt_corr_ring_buffer.channels))
        self.std_plot = RingBufferPlot(
            RingBuffer(self.plot_window_size,
                       channels=self.xyt_corr_ring_buffer.channels))
        self.velocity_carthesian_history_plot = RingBufferPlot(
            self.cars[0].ins.velocity_carthesian_history)

        # self.hist_plot = HistogramPlot(10)

        self.register_events()
        self.spin()
示例#22
0
 def __init__(self):
     self.__frame_id = 0
     self.__id_of_last_anim_end = 0  # id of the last frame of the saved animation
     self.__frame_cache = RingBuffer(self.max_gif_length_f)
     self.__frame_thumbs_cache = RingBuffer(self.max_gif_length_f)
     self.__stats = {'frames_saved_as_anim': 0, 'frames_dist': []}
示例#23
0
import json
from RingBuffer import RingBuffer
import logging
from pprint import pformat
import csv
from datetime import datetime, timedelta
from customLogging import info, writeToCsv, setChannelName
from trafficDataImport import getMetaData

initialPacketsize = 100
packetsize = 10
centroidinp = [[], []]
means = False
clusterResult = []
#Here only the features are stored which are taken into account while clustering
clusterDataStore = RingBuffer(50000)
#Here metadata is stored. Basically everything which is important for later analysis but should not taken into
# account while clustering (e.g. location, timestamp) . It must be ensured that this buffer is consistent with the
# buffer above (i.e. index links the data)
# TODO: Once able to retrieve individual values through CKAN API fill this with values
metaDataStore = RingBuffer(50000)


#save the chosen k
k = 0

datetimeFormat = '%Y-%m-%dT%H:%M:%S'
#Timestamps to know when initial centroid computation and the recalculations take place
startdate = datetime.strptime('2014-02-13T12:25:00', datetimeFormat)
datesincerecalculation = datetime.strptime('2014-02-13T12:25:00', datetimeFormat)
recalculationtime = 0