Exemplo n.º 1
0
class AutomaticTest(unittest.TestCase):
    def setUp(self):
        self.qToEe = Queue()
        self.qFromEe = Queue()
        self.ee = ExecutionEngine(1, self.qToEe, self.qFromEe, Lock())
        self.ee.start()
        self.transceive('{} {}'.format('setRecipe', './recipes/test.csv'))

    def tearDown(self):
        self.transceive('quit')
        self.ee.join()

    def test_flow(self):
        self.assertEqual(self.transceive('start'), 'timed out')
        self.assertAlmostEqual(self.transceive('getPv'), 26, delta=1)
        self.assertEqual(self.transceive('getSv'), 30)
        self.assertAlmostEqual(self.transceive('getTotalRemainingTime'),
                               32,
                               delta=1)
        time.sleep(6)
        self.assertAlmostEqual(self.transceive('getRemainingStepTime'),
                               4.5,
                               delta=1)

    def transceive(self, commandname):
        self.qToEe.put(commandname)
        try:
            return float(self.qFromEe.get(block=True, timeout=1))
        except Empty:
            return 'timed out'
        except TypeError:
            pass
Exemplo n.º 2
0
 def __init__(self, brewView, tempControllerAddress, interfaceLock):
     self.brewView = brewView
     self.tempControllerAddress = tempControllerAddress
     self.qToEe = Queue()
     self.qFromEe = Queue()
     self.ee = ExecutionEngine(self.tempControllerAddress,
                               self.qToEe,
                               self.qFromEe,
                               interfaceLock)
     self.ee.start()
     self.setupLogger()
Exemplo n.º 3
0
def manualTest():
    qToEe = Queue()
    qFromEe = Queue()
    ee = ExecutionEngine(1, qToEe, qFromEe, Lock())
    ee.setRecipe('./recipes/test.csv')
    ee.start()
    printAvailableCommands()
    while True:
        command = input('command: ')
        if command == 'q':
            break
        if not command in commands.keys():
            continue
        qToEe.put(command)
        try:
            print('respone: {}'.format(qFromEe.get(block=True, timeout=1)))
        except Empty:
            print('timed out')
    qToEe.put('quit')
    ee.join()
Exemplo n.º 4
0
 def setUp(self):
     self.qToEe = Queue()
     self.qFromEe = Queue()
     self.ee = ExecutionEngine(1, self.qToEe, self.qFromEe, Lock())
     self.ee.start()
     self.transceive('{} {}'.format('setRecipe', './recipes/test.csv'))
# -*- coding: utf-8 -*-
"""
Created on Tue Jul 14 15:28:43 2015

@author: 
"""

from pprint import pprint
from datetime import datetime
from analytics import Analytics
from execution_engine import ExecutionEngine
from analytics_utils import plot

a = Analytics()
e = ExecutionEngine()

dimensions = {'X': {'range': (147.968, 148.032)}, 'Y': {'range': (-36.032, -35.968)}, 'T': {'range': (1262304000.0, 1325375999.999999)}, }
arrays = a.createArray('LS5TM', ['B40', 'B30'], dimensions, 'get_data')
ndvi = a.applyBandMath(arrays, '((array1 - array2) / (array1 + array2))', 'ndvi')
arrays2 = a.createArray('LS5TM', ['B40', 'B30'], dimensions, 'get_data2')
ndvi2 = a.applyBandMath(arrays2, '((array1 - 2.0*array2) / (array2))', 'ndvi2')
average = a.applyBandMath([ndvi, ndvi2], '((array1 + array2) / 2)', 'average')
pq_data = a.createArray('LS5TMPQ', ['PQ'], dimensions, 'pq_data')
mask = a.applyCloudMask(average, pq_data, 'mask')
median_t = a.applyGenericReduction(mask, ['T'], 'median(array1)', 'medianT')
result = e.executePlan(a.plan)

plot(e.cache['medianT'])
# -*- coding: utf-8 -*-
"""
Created on Tue Jul 14 15:03:49 2015

@author: 
"""

from pprint import pprint
from datetime import datetime
from analytics import Analytics
from execution_engine import ExecutionEngine
from analytics_utils import plot

a = Analytics()
e = ExecutionEngine()

dimensions = {'X': {'range': (147.0, 148.0)}, 'Y': {'range': (-37.0, -36.0)}, 'T': {'range': (1262304000.0, 1325375999.999999)}, }
arrays = a.createArray('LS5TM', ['B40',], dimensions, 'get_data')
#ndvi = a.applyBandMath(arrays, '((array1 - array2) / (array1 + array2))', 'ndvi')

e.executePlan(a.plan)

plot(e.cache['get_data'])

Exemplo n.º 7
0
class StateMachine():
    def __init__(self, brewView, tempControllerAddress, interfaceLock):
        self.brewView = brewView
        self.tempControllerAddress = tempControllerAddress
        self.qToEe = Queue()
        self.qFromEe = Queue()
        self.ee = ExecutionEngine(self.tempControllerAddress,
                                  self.qToEe,
                                  self.qFromEe,
                                  interfaceLock)
        self.ee.start()
        self.setupLogger()

    def setupLogger(self):
        self.logger = logging.getLogger('{}_{}'.format(
            __name__, self.tempControllerAddress))
        self.logger.setLevel(logging.INFO)
        fh = logging.handlers.RotatingFileHandler('statemachine.log',
                                                  maxBytes=20000,
                                                  backupCount=5)
        fh.setLevel(logging.DEBUG)
        formatter = logging.Formatter(
            '%(asctime)s - %(name)s - %(process)d - %(levelname)s - %(message)s')
        fh.setFormatter(formatter)
        self.logger.addHandler(fh)

    def start(self):
        self.logger.info('start')
        self.logger.info('selected recipe: {}'.format(self.brewView.getRecipe()))
        self.qToEe.put('{} {}'.format('setRecipe', self.brewView.getRecipe()))
        self.qToEe.put('start')

    def stop(self):
        self.logger.info('stop')
        self.qToEe.put('stop')

    def quit(self):
        self.logger.info('quit')
        self.qToEe.put('quit')
        self.ee.join()

    def updateViews(self):
        self.logger.debug('update views')
        self.clearQFromEe()
        self.updateSv()
        self.updatePv()
        self.updateRemainingStepTime()
        self.updateTotalRemainingTime()

    def clearQFromEe(self):
        for i in range(self.qFromEe.qsize()):
            self.qFromEe.get()

    def updateSv(self):
        self.qToEe.put('getSv')
        sv = self.qFromEe.get()
        if not sv == None:
            self.brewView.setSetValue(sv)

    def updatePv(self):
        self.qToEe.put('getPv')
        pv = self.qFromEe.get()
        if not pv == None:
            self.brewView.setProcessValue(pv)

    def updateRemainingStepTime(self):
        self.qToEe.put('getRemainingStepTime')
        rst = self.qFromEe.get()
        if not rst == None:
            self.brewView.setStepTimeLeft(rst)

    def updateTotalRemainingTime(self):
        self.qToEe.put('getTotalRemainingTime')
        trt = self.qFromEe.get()
        if not trt == None:
            self.brewView.setTotalTimeLeft(trt)