Exemplo n.º 1
0
  def _wavelet_from_json(self, json, pending_ops):
    """Construct a wavelet from the passed json.

    The json should either contain a wavelet and a blips record that
    define those respective object. The returned wavelet
    will be constructed using the passed pending_ops
    OperationQueue.
    Alternatively the json can be the result of a previous
    wavelet.serialize() call. In that case the blips will
    be contaned in the wavelet record.
    """
    if isinstance(json, basestring):
      json = simplejson.loads(json)

    # Create blips dict so we can pass into BlipThread objects
    blips = {}

    # Setup threads first, as the Blips and Wavelet need to know about them
    threads = {}
    # In case of blind_wavelet or new_wave, we may not have threads indo
    threads_data = json.get('threads', {})
    # Create remaining thread objects
    for thread_id, raw_thread_data in threads_data.items():
      threads[thread_id] = wavelet.BlipThread(thread_id,
          raw_thread_data.get('location'), raw_thread_data.get('blipIds', []),
          blips, pending_ops)

    # If being called from blind_wavelet, wavelet is top level info
    if 'wavelet' in json:
      raw_wavelet_data = json['wavelet']
    elif 'waveletData' in json:
      raw_wavelet_data = json['waveletData']
    else:
      raw_wavelet_data = json
    root_thread_data = raw_wavelet_data.get('rootThread')
    root_thread = wavelet.BlipThread('',
                             root_thread_data.get('location'),
                             root_thread_data.get('blipIds', []),
                             blips,
                             pending_ops)
    threads[''] = root_thread

    # Setup the blips, pass  in reply threads
    for blip_id, raw_blip_data in json['blips'].items():
      reply_threads = [threads[id] for id in raw_blip_data.get('replyThreadIds',
                                                               [])]
      thread = threads.get(raw_blip_data.get('threadId'))
      blips[blip_id] = blip.Blip(raw_blip_data, blips, pending_ops,
                                 thread=thread, reply_threads=reply_threads)

    result = wavelet.Wavelet(raw_wavelet_data, blips, root_thread, pending_ops,
                             raw_deltas=json.get('rawDeltas'))

    robot_address = json.get('robotAddress')
    if robot_address:
      result.robot_address = robot_address

    return result
Exemplo n.º 2
0
 def setUp(self):
     self.operation_queue = ops.OperationQueue()
     self.all_blips = {}
     self.blip = blip.Blip(TEST_BLIP_DATA, self.all_blips,
                           self.operation_queue)
     self.all_blips[self.blip.blip_id] = self.blip
     self.wavelet = wavelet.Wavelet(TEST_WAVELET_DATA, self.all_blips, None,
                                    self.operation_queue)
     self.wavelet.robot_address = ROBOT_NAME
Exemplo n.º 3
0
    def _wavelet_from_json(self, json, pending_ops):
        """Construct a wavelet from the passed json.

    The json should either contain a wavelet and a blips record that
    define those respective object. The returned wavelet
    will be constructed using the passed pending_ops
    OperationQueue.
    Alternatively the json can be the result of a previous
    wavelet.serialize() call. In that case the blips will
    be contaned in the wavelet record.
    """
        if isinstance(json, basestring):
            json = simplejson.loads(json)

        # Create blips dict so we can pass into BlipThread objects
        blips = {}

        # Setup threads first, as the Blips and Wavelet need to know about them
        threads = {}
        threads_data = json.get('threads', {})
        # Create remaining thread objects
        for thread_id, raw_thread_data in threads_data.items():
            threads[thread_id] = wavelet.BlipThread(
                thread_id, raw_thread_data.get('location'),
                raw_thread_data.get('blipIds', []), blips, pending_ops)

        # Setup the blips, pass  in reply threads
        for blip_id, raw_blip_data in json['blips'].items():
            reply_threads = []
            reply_thread_ids = raw_blip_data.get('replyThreadIds', [])
            for reply_thread_id in reply_thread_ids:
                reply_threads.append(threads[reply_thread_id])
            blips[blip_id] = blip.Blip(raw_blip_data,
                                       blips,
                                       pending_ops,
                                       reply_threads=reply_threads)

        if 'wavelet' in json:
            raw_wavelet_data = json['wavelet']
        elif 'waveletData' in json:
            raw_wavelet_data = json['waveletData']
        else:
            raw_wavelet_data = json
        wavelet_blips = {}
        wavelet_id = raw_wavelet_data['waveletId']
        wave_id = raw_wavelet_data['waveId']
        for blip_id, instance in blips.items():
            if instance.wavelet_id == wavelet_id and instance.wave_id == wave_id:
                wavelet_blips[blip_id] = instance
        result = wavelet.Wavelet(raw_wavelet_data, wavelet_blips, pending_ops)

        robot_address = json.get('robotAddress')
        if robot_address:
            result.robot_address = robot_address

        return result
Exemplo n.º 4
0
    def setUp(self):
        self.operation_queue = ops.OperationQueue()
        self.all_blips = {}
        self.blip = blip.Blip(TEST_BLIP_DATA, self.all_blips,
                              self.operation_queue)
        self.all_blips[self.blip.blip_id] = self.blip
        root_thread_data = TEST_WAVELET_DATA.get('rootThread')
        root_thread = wavelet.BlipThread('', root_thread_data.get('location'),
                                         root_thread_data.get('blipIds', []),
                                         self.all_blips, self.operation_queue)

        self.wavelet = wavelet.Wavelet(TEST_WAVELET_DATA, self.all_blips,
                                       root_thread, self.operation_queue)
        self.wavelet.robot_address = ROBOT_NAME
Exemplo n.º 5
0
    def _wavelet_from_json(self, json, pending_ops):
        """Construct a wavelet from the passed json.

    The json should either contain a wavelet and a blips record that
    define those respective object. The returned wavelet
    will be constructed using the passed pending_ops
    OperationQueue.
    Alternatively the json can be the result of a previous
    wavelet.serialize() call. In that case the blips will
    be contaned in the wavelet record.
    """
        if isinstance(json, basestring):
            json = simplejson.loads(json)

        blips = {}
        for blip_id, raw_blip_data in json['blips'].items():
            blips[blip_id] = blip.Blip(raw_blip_data, blips, pending_ops)

        if 'wavelet' in json:
            raw_wavelet_data = json['wavelet']
        elif 'waveletData' in json:
            raw_wavelet_data = json['waveletData']
        else:
            raw_wavelet_data = json
        wavelet_blips = {}
        wavelet_id = raw_wavelet_data['waveletId']
        wave_id = raw_wavelet_data['waveId']
        for blip_id, instance in blips.items():
            if instance.wavelet_id == wavelet_id and instance.wave_id == wave_id:
                wavelet_blips[blip_id] = instance
        result = wavelet.Wavelet(raw_wavelet_data, wavelet_blips, self,
                                 pending_ops)
        robot_address = json.get('robotAddress')
        if robot_address:
            result.robot_address = robot_address
        return result
Exemplo n.º 6
0
import matplotlib.pyplot as plt
from PIL import Image
import numpy as np
import wfdb
import utilise
import record as rd
import wavelet
wav = wavelet.Wavelet()
wavelet_level = 4
use = 'wavelet'
import time
import logging
mitdb_fs = 360
_5_mins = mitdb_fs * 300
"""
For classify the SVEB(Superventricular Premature Beat) and VEB(Ventricular Ectopic Beat)
Total 48 ECG recordings, 23(from 100 to 214) and 25 (from 200 to 234, which are rare but clinically important).
    exclusive recordings of 102, 104, 107 and 217 which mainly exists paced beats.

N = "N", 'NORMAL', 'Normal beat'
    "L", 'LBBB', 'Left bundle branch block beat'
    "R", 'RBBB', 'Right bundle branch block beat'
    "j", 'NESC', 'Nodal (junctional) escape beat'

S = "a", 'ABERR', 'Aberrated atrial premature beat'
    "J", 'NPC', 'Nodal (junctional) premature beat'
    "S", 'SVPB', 'Premature or ectopic supraventricular beat'

V = "V", 'PVC', 'Premature ventricular contraction'
    "E", 'VESC', 'Ventricular escape beat'
Exemplo n.º 7
0
  def new_wave(self, domain, participants=None, message='', proxy_for_id=None,
               submit=False):
    """Create a new wave with the initial participants on it.

    A new wave is returned with its own operation queue. It the
    responsibility of the caller to make sure this wave gets
    submitted to the server, either by calling robot.submit() or
    by calling .submit_with() on the returned wave.

    Args:
      domain: the domain to create the wavelet on. This should
          in general correspond to the domain of the incoming
          wavelet. (wavelet.domain). Exceptions are situations
          where the robot is calling new_wave outside of an
          event or when the server is handling multiple domains.

      participants: initial participants on the wave. The robot
          as the creator of the wave is always added.

      message: a string that will be passed back to the robot
          when the WAVELET_CREATOR event is fired. This is a
          lightweight way to pass around state.

      submit: if true, use the active gateway to make a round
          trip to the server. This will return immediately an
          actual waveid/waveletid and blipId for the root blip.

    """
    util.check_is_valid_proxy_for_id(proxy_for_id)
    operation_queue = ops.OperationQueue(proxy_for_id)
    if not isinstance(message, basestring):
      message = simplejson.dumps(message)

    # Create temporary wavelet data
    blip_data, wavelet_data = operation_queue.robot_create_wavelet(
        domain=domain,
        participants=participants,
        message=message)

    # Create temporary blips dictionary
    blips = {}
    root_blip = blip.Blip(blip_data, blips, operation_queue)
    blips[root_blip.blip_id] = root_blip

    if submit:
      # Submit operation to server and return actual wave/blip IDs
      temp_wavelet = wavelet.Wavelet(wavelet_data,
                                blips=blips,
                                root_thread=None,
                                operation_queue=operation_queue)
      result = self._first_rpc_result(self.submit(temp_wavelet))
      if isinstance(result, list):
        result = result[0]
      if 'blipId' in result:
        blip_data['blipId'] = result['blipId']
        wavelet_data['rootBlipId'] = result['blipId']
      for field in 'waveId', 'waveletId':
        if field in result:
          wavelet_data[field] = result[field]
          blip_data[field] = result[field]
      blips = {}
      root_blip = blip.Blip(blip_data, blips, operation_queue)
      blips[root_blip.blip_id] = root_blip

    root_thread = wavelet.BlipThread('',
                             -1,
                             [root_blip.blip_id],
                             blips,
                             operation_queue)
    new_wavelet = wavelet.Wavelet(wavelet_data,
                              blips=blips,
                              root_thread=root_thread,
                              operation_queue=operation_queue)
    return new_wavelet
Exemplo n.º 8
0
    def new_wave(self,
                 domain,
                 participants=None,
                 message='',
                 proxy_for_id=None,
                 submit=False):
        """Create a new wave with the initial participants on it.

    A new wave is returned with its own operation queue. It the
    responsibility of the caller to make sure this wave gets
    submitted to the server, either by calling robot.submit() or
    by calling .submit_with() on the returned wave.

    Args:
      domain: the domain to create the wavelet on. This should
          in general correspond to the domain of the incoming
          wavelet. (wavelet.domain). Exceptions are situations
          where the robot is calling new_wave outside of an
          event or when the server is handling multiple domains.

      participants: initial participants on the wave. The robot
          as the creator of the wave is always added.

      message: a string that will be passed back to the robot
          when the WAVELET_CREATOR event is fired. This is a
          lightweight way to pass around state.

      submit: if true, use the active gateway to make a round
          trip to the server. This will return immediately an
          actual waveid/waveletid and blipId for the root blip.

    """
        operation_queue = ops.OperationQueue(proxy_for_id)
        if not isinstance(message, basestring):
            message = simplejson.dumps(message)

        blip_data, wavelet_data = operation_queue.robot_create_wavelet(
            domain=domain, participants=participants, message=message)

        blips = {}
        root_blip = blip.Blip(blip_data, blips, operation_queue)
        blips[root_blip.blip_id] = root_blip
        created = wavelet.Wavelet(wavelet_data,
                                  blips=blips,
                                  robot=self,
                                  operation_queue=operation_queue)
        if submit:
            result = self._first_rpc_result(self.submit(created))
            if type(result) == list:
                result = result[0]
            # Currently, data is sometimes wrapped in an outer 'data'
            # Remove these 2 lines when that is no longer an issue.
            if 'data' in result and len(result) == 2:
                result = result['data']
            if 'blipId' in result:
                blip_data['blipId'] = result['blipId']
                wavelet_data['rootBlipId'] = result['blipId']
            for field in 'waveId', 'waveletId':
                if field in result:
                    wavelet_data[field] = result[field]
                    blip_data[field] = result[field]
            blips = {}
            root_blip = blip.Blip(blip_data, blips, operation_queue)
            blips[root_blip.blip_id] = root_blip
            created = wavelet.Wavelet(wavelet_data,
                                      blips=blips,
                                      robot=self,
                                      operation_queue=operation_queue)

        return created