コード例 #1
0
 def setUp(self):
     
     self.fTest=StringIO()
     self.sContentTest="""[Test]\n
     key1 = 2\n
     key2 = 1\n"""
     
     self.fTest.write(self.sContentTest)
     self.fTest.seek(0)
     self.configReader=ConfigReader(self.fTest,'Test')
コード例 #2
0
	def dbConnect(self):
		configReader = ConfigReader()
		config = configReader.readConfig()
		
		host = config.get('Database', "database.host")
		username = config.get('Database', "database.user")
		password = config.get('Database', "database.password")
		dbname = config.get('Database', "database.dbname")
		
		conn = MySQLdb.connect(host,username,password,dbname)
		return conn
コード例 #3
0
	def pointError(self,value,i,rowNum):
		
		configReader = ConfigReader()
		config = configReader.readConfig()
		
		#Reading parameters from the config file
		topOffset = config.get('Csv','csv.topOffset')
		leftOffset = config.get('Csv','csv.leftOffset')
		
		print "Column number : %d" %(i+1+int(leftOffset))
		print "Row number : %d" %(rowNum+1+int(topOffset))
		print "value: %s" % (value)
コード例 #4
0
	def readHeader(self):
		configReader = ConfigReader()
		config = configReader.readConfig()
		file = config.get('Csv', 'csv.file')
		topOffset = config.get('Csv','csv.topOffset')
		
		with open(file, "rb") as csvfile:
			file = csv.reader(csvfile, delimiter=',', quotechar='"')
			data = []
			for lines in file:
				data.append(lines)
			columns = data[int(topOffset)]		
		
		return columns
コード例 #5
0
    def __init__(self, configDir):
        Thread.__init__(self)

        self.deviceConfigReader = ConfigReader(configDir, "Device")
        self.sh = sense_hat.SenseHat()
        self.currentSensorData = SensorData("Temperature")
        #SensorEmulator simulates temperature range from 25 degree to 15 degree
        #temperature is changed after a random period of time in range 10 sec to 1 sec
        self.tempSensorEmulator = SensorEmulator(30, 15, 10, 1)
        self.tempSensorEmulator.daemon = True
        self.tempSensorEmulator.start()

        if self.deviceConfigReader.getProperty("enableEmulator") == "True":
            self.enableTempEmulator = True
            self.tempSensorEmulator.enableTempEmulator = True
コード例 #6
0
    def _getConfigReader(self):
        fBufferConfig = None
        if os.path.isfile(self._path):
            fBufferConfig = open(self._path, 'r+')
        else:
            fBufferConfig = self._genConfigFile()

        return ConfigReader(fBufferConfig, self._sSection)
コード例 #7
0
    def __init__(self, configDir):

        Thread.__init__(self)

        #Set all the custom variables from configuration file
        self.confiReader = ConfigReader(configDir, "Device")
        self.pollCycleSecs = int(self.confiReader.getProperty("pollCycleSecs"))
        self.confiReader = ConfigReader(configDir, "mqtt.gateway")
        self.mqttGatewayHost = self.confiReader.getProperty("host")
        self.mqttGatewayPort = int(self.confiReader.getProperty("port"))

        #Start temperature Sensor Adaptor
        self.tempSensorAdaptor = TempSensorAdaptor(configDir)
        self.tempSensorAdaptor.daemon = True
        self.tempSensorAdaptor.start()

        #Initialize Temperature Actuator Emulator and AirConditioner Actuator Emulator
        self.tempActuatorEmulator = TempActuatorEmulator()
        self.airConActuatorEmulator = AirConActuatorEmulator()

        #Initialize a mqttClient_TempSensor with custom call back methods and start listening on Temperature ActuatorData from gateway broker
        self.mqttClient_TempSensor = mqttClientConnector.MqttClientConnector(
            self.mqttGatewayHost, self.mqttGatewayPort, self.on_connect,
            self.on_message_TempActuator, self.on_publish_TempSensorData,
            self.on_subscribe_TempActuator)
        self.mqttClient_TempSensor.connect()
        self.mqttClient_TempSensor.subscribeTopic(
            "iot/actuatorData/temperature", 1)

        #Initialize a mqttClient_AirCon with custom call back methods and start listening on AirConditioner ActuatorData from gateway broker
        self.mqttClient_AirCon = mqttClientConnector.MqttClientConnector(
            self.mqttGatewayHost, self.mqttGatewayPort, self.on_connect,
            self.on_message_AirConActuator, self.on_publish_AirConStatus,
            self.on_subscribe_AirConActuator)
        self.mqttClient_AirCon.connect()
        self.mqttClient_AirCon.subscribeTopic(
            "iot/actuatorData/airConditioner", 1)
コード例 #8
0
    def __init__(self, fileName):
        configReader = ConfigReader()
        config = configReader.readConfig()

        # reading the parameters from the config file
        # file = config.get('Csv', 'csv.file')
        file = fileName
        self.topOffset = config.get("Csv", "csv.topOffset")
        self.leftOffset = config.get("Csv", "csv.leftOffset")

        # opening and reading from the file
        with open(file, "rb") as csvfile:

            try:
                # for removing the byte order mark (BOM ), read the file, decoded the file , and encodeg again without the BOM
                file = csv.reader(
                    f.read().decode("utf-8-sig").encode("utf-8").splitlines(), delimiter="\t", quotechar='"'
                )
            except:
                file = csv.reader(csvfile, delimiter=",", quotechar='"')

            self.data = []
            for lines in file:
                self.data.append(lines)  # storing each lines of file in array
コード例 #9
0
class TempSensorAdaptor(Thread):

    deviceConfigReader = None
    tempSensorEmulator = None
    enableTempEmulator = False
    currentTemp = 0
    currentSensorData = None
    sh = None

    def __init__(self, configDir):
        Thread.__init__(self)

        self.deviceConfigReader = ConfigReader(configDir, "Device")
        self.sh = sense_hat.SenseHat()
        self.currentSensorData = SensorData("Temperature")
        #SensorEmulator simulates temperature range from 25 degree to 15 degree
        #temperature is changed after a random period of time in range 10 sec to 1 sec
        self.tempSensorEmulator = SensorEmulator(30, 15, 10, 1)
        self.tempSensorEmulator.daemon = True
        self.tempSensorEmulator.start()

        if self.deviceConfigReader.getProperty("enableEmulator") == "True":
            self.enableTempEmulator = True
            self.tempSensorEmulator.enableTempEmulator = True

    def getCurrentTemp(self):
        return self.currentTemp

    def getCurrentSensorData(self):
        self.currentSensorData.addNewValue(
            self.currentTemp)  # refresh SensorData only when it is called.
        return self.currentSensorData

    def run(self):
        while True:
            if self.enableTempEmulator:  #If enableTempEmulator is false then using sense_hat to get current temperature!
                self.currentTemp = self.tempSensorEmulator.getCurrValue()
            else:
                self.currentTemp = self.sh.get_temperature()

    def setflagEnableTempEmulator(self, enableTempEmulator):
        self.enableTempEmulator = enableTempEmulator
        self.tempSensorEmulator.enableTempEmulator = enableTempEmulator
コード例 #10
0
from boxGraphicView import BoxGraphicView
from configReader import ConfigReader
import numpy as np
import matplotlib.pyplot as plt
import time
import os
import sys

ACTION = sys.argv[1]
mode = "default"
if ACTION == "left" or ACTION == "right":
    mode = "horizontal"
else:
    mode = "vertical"

CONF = ConfigReader("hyperParameters.ini", mode)
RESHAPE = (-1, 8, 60)
FFT_MAX_HZ = CONF.frequency_slot
HM_SECONDS = 10
TOTAL_ITERS = HM_SECONDS * 25
CHANNELS_NUM = CONF.channels_num
ACTIONS = ["left", "right", "up", "down", "none"]

# last_print = time.time()
# fps_counter = deque(maxlen=150)

# 接收推流数据
print("looking for an EEG stream...")
streams = resolve_stream('type', 'EEG')
# 创建inlet读取数据
inlet = StreamInlet(streams[0])
コード例 #11
0
"""
contains code to initiate the process
"""
import sys
sys.path.append('../../')

from api_base.api_framework import APIFramework
from configReader import ConfigReader
#TODO: Fix the import statements, APIFramework is not being imported

CONFIG_PATH = 'configs/config.yaml'

api_framework = APIFramework()
cfg_reader = ConfigReader(CONFIG_PATH)

cfg = cfg_reader.getConfig()
print(cfg)
コード例 #12
0
class SensorManagementApp(Thread):

    tempSensorAdaptor = None
    tempSensorData = None

    tempActuatorEmulator = None
    airConActuatorEmulator = None

    mqttClient_TempSensor = None
    mqttClient_AirCon = None

    confiReader = None
    pollCycleSecs = None
    mqttGatewayHost = None
    mqttGatewayPort = None

    def __init__(self, configDir):

        Thread.__init__(self)

        #Set all the custom variables from configuration file
        self.confiReader = ConfigReader(configDir, "Device")
        self.pollCycleSecs = int(self.confiReader.getProperty("pollCycleSecs"))
        self.confiReader = ConfigReader(configDir, "mqtt.gateway")
        self.mqttGatewayHost = self.confiReader.getProperty("host")
        self.mqttGatewayPort = int(self.confiReader.getProperty("port"))

        #Start temperature Sensor Adaptor
        self.tempSensorAdaptor = TempSensorAdaptor(configDir)
        self.tempSensorAdaptor.daemon = True
        self.tempSensorAdaptor.start()

        #Initialize Temperature Actuator Emulator and AirConditioner Actuator Emulator
        self.tempActuatorEmulator = TempActuatorEmulator()
        self.airConActuatorEmulator = AirConActuatorEmulator()

        #Initialize a mqttClient_TempSensor with custom call back methods and start listening on Temperature ActuatorData from gateway broker
        self.mqttClient_TempSensor = mqttClientConnector.MqttClientConnector(
            self.mqttGatewayHost, self.mqttGatewayPort, self.on_connect,
            self.on_message_TempActuator, self.on_publish_TempSensorData,
            self.on_subscribe_TempActuator)
        self.mqttClient_TempSensor.connect()
        self.mqttClient_TempSensor.subscribeTopic(
            "iot/actuatorData/temperature", 1)

        #Initialize a mqttClient_AirCon with custom call back methods and start listening on AirConditioner ActuatorData from gateway broker
        self.mqttClient_AirCon = mqttClientConnector.MqttClientConnector(
            self.mqttGatewayHost, self.mqttGatewayPort, self.on_connect,
            self.on_message_AirConActuator, self.on_publish_AirConStatus,
            self.on_subscribe_AirConActuator)
        self.mqttClient_AirCon.connect()
        self.mqttClient_AirCon.subscribeTopic(
            "iot/actuatorData/airConditioner", 1)

    # custom callback when connect to Gateway broker
    def on_connect(self, mqttc, obj, flags, rc):
        print("Successfully Connect to GatewayBroker!! rc: " + str(rc))

    #custom callback when subscribed actuatorData arrive, then tiger temperature ActuatorEmulator
    def on_message_TempActuator(self, mqttc, obj, msg):
        print("TempActuatorData arrived from topic:" + msg.topic + " QoS:" +
              str(msg.qos) + " Message:" + str(msg.payload.decode("utf-8")))
        self.tempActuatorEmulator.process_message(str(msg.payload))

    #custom callback when Temperature SensorData publish success
    def on_publish_TempSensorData(self, mqttc, obj, mid):
        print(
            "Successfully published SensorData to topic iot/sensorData/temperature !! mid: "
            + str(mid))

    #custom callback when successfully subscribe to Temperature Actuator
    def on_subscribe_TempActuator(self, mqttc, obj, mid, granted_qos):
        print(
            "Successfully Subscribed to topic: iot/actuatorData/temperature !! "
            + str(mid) + " Granted_QoS:" + str(granted_qos))

    #custom callback method when subscribed AirConditionerActuatorData arrive, then tiger air Conditioner ActuatorEmulater
    def on_message_AirConActuator(self, mqttc, obj, msg):
        print("AirConditionerActuatorData arrived from topic:" + msg.topic +
              " QoS:" + str(msg.qos) + " Message:" +
              str(msg.payload.decode("utf-8")))
        self.airConActuatorEmulator.process_message(str(msg.payload))

    #custom callback when air conditioner status publish success
    def on_publish_AirConStatus(self, mqttc, obj, mid):
        print(
            "Successfully published AirConditionerStatus to topic iot/status/AirConditioner !! mid: "
            + str(mid))

    #custom callback when air Conditioner actuatorData subscribe success
    def on_subscribe_AirConActuator(self, mqttc, obj, mid, granted_qos):
        print(
            "Successfully Subscribed to topic: iot/actuatorData/airConditioner !! "
            + str(mid) + " Granted_QoS:" + str(granted_qos))

    def run(self):
        while True:
            #Read new temperature sensorData and publish to gateway broker
            self.tempSensorData = self.tempSensorAdaptor.getCurrentSensorData()

            self.mqttClient_TempSensor.publishMessage(
                "iot/sensorData/temperature",
                str(self.tempSensorData.toDict()), 2)

            sleep(self.pollCycleSecs)  #wait for next poll
コード例 #13
0
ファイル: deploy.py プロジェクト: Beyyes/Titan
 def __init__(self):
     configReader = ConfigReader()
     self.hosts = configReader.parse()
     self.remoteTool = RemoteTool()
     self.script_folder = "init_k8s_scrpts"
     self.join_cmd = ""
コード例 #14
0
ファイル: client.py プロジェクト: ollien/screenshot-uploader
#!/usr/bin/env python3

from configReader import ConfigReader
import sys
import os, os.path
from time import time
from math import floor
import hashlib
import random
import requests

configReader = ConfigReader(name = "clientConfig.txt")
path = sys.argv[1]
keys = configReader.getKeys()
endpoint = keys['endpoint']
username = keys['username']
password = keys['password']
finalLocation = keys['finalLocation']

print("Uploading to %s" % (endpoint))
r = requests.post(endpoint, 
    auth = (username, password), 
    files = {'file': open(path, 'rb')})

print(r.status_code)

if r.status_code == 200:
    urlPath = os.path.join(finalLocation, r.text)
    print(urlPath)
    os.system("echo '%s'|pbcopy" % urlPath)
else:
コード例 #15
0
import os
from configReader import ConfigReader

CONF = ConfigReader()

for j in range(2):
    if j == 0:
        mode = "vertical"
    elif j == 1:
        mode = "horizontal"
    CONF.setMode(mode)
    for i in range(5):
        if i == 0:
            c_str = "0,1,2,3,4,5,6,7"
        elif i == 1:
            c_str = "2,3,4,5,6,7"
        elif i == 2:
            c_str = "0,1,4,5,6,7"
        elif i == 3:
            c_str = "0,1,2,3,6,7"
        elif i == 4:
            c_str = "0,1,2,3,4,5"
        else:
            c_str = ""
    # c_str = "0,1,2,3,4,5,6,7"
        CONF.setChannels(c_str)
        os.system("python train_model.py")
コード例 #16
0
    correct = 0
    output = model.predict(data)
    box = BoxGraphicView()
    for i in range(total):
        act = actions[np.argmax(output[i])]
        print(act, output[i])
        box.move(act, step=1)
        sleep(0.03)
        if act == tag:
            correct += 1
    acc = correct / total
    return acc


if __name__ == "__main__":
    CONF = ConfigReader()
    actions = CONF.actions

    model_name = CONF.test_model
    model_dir = os.path.join(CONF.models_dir, model_name)
    model = tf.keras.models.load_model(model_dir)

    tag = "left"
    act = os.path.join("horizontal_data", tag)
    file_name = "1618882899.npy"
    data_dir = os.path.join(act, file_name)
    data = np.load(data_dir)
    data = dataLoading.cutData(data, stride=1)

    print("accuracy:", test(data, tag, actions, model))
    print("data:", tag, file_name)
コード例 #17
0
class Test_ConfigReader(unittest.TestCase):


    def setUp(self):
        
        self.fTest=StringIO()
        self.sContentTest="""[Test]\n
        key1 = 2\n
        key2 = 1\n"""
        
        self.fTest.write(self.sContentTest)
        self.fTest.seek(0)
        self.configReader=ConfigReader(self.fTest,'Test')

    def tearDown(self):
        self.configReader.close()

    def testSections(self):
        listSections=['Test']
        self.assertEqual(self.configReader.getSections(),listSections,'Las secciones no son iguales')
        
    def testValues(self):
        dictValues={'key1':'2','key2':'1'}
        dictConfigReader=self.configReader.getAllValues()
        self.assertTrue(dictValues==dictConfigReader, 'Los valores no son iguales, correcto: '+dictValues.__str__()+\
                        '\n configReader: '+dictConfigReader.__str__())
    
    def testRemoveValue(self):
        self.assertTrue(self.configReader.removeValue('key1'))
        self.assertEqual(self.configReader.getValue('key1'), None, 'El elemento no ha sido borrado') 
        self.configReader.setValue('key1', '2')
        
        
    def testInsertValue(self):
        self.configReader.setValue('key3', '3')
        self.assertEqual(self.configReader.getValue('key3'), '3', 'El valor devuelto no es el mismo al introducido')
        
        self.configReader.removeValue('key3')
        
    def testModifyValue(self):
        self.configReader.setValue('key1', '10')
        self.assertEqual(self.configReader.getValue('key1'), '10', 'El valor devuelto no es el mismo al introducido')
        
        self.configReader.setValue('key1', '2')
        

    def testWriteTest(self):
        self.configReader.writeConfigFile()
        self.fTest.seek(0)
        
        sContentFile=self.fTest.read()
        
        self.assertEquals(sContentFile,self.sContentTest, 'El contenido del buffer que el original')
コード例 #18
0
ファイル: train_model.py プロジェクト: Masquerade51256/IMABOT
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten
from tensorflow.keras.layers import Conv2D
from tensorflow.keras.layers import MaxPooling2D, BatchNormalization
import time
import dataLoading
import gc
from configReader import ConfigReader

CONF = ConfigReader("hyperParameters.ini")
ACTIONS = dataLoading.ACTIONS
TIME_SLOT = CONF.time_slot
FREQUENCY_SLOT = CONF.frequency_slot
CHANNELS_NUM = len(CONF.selected_channels)
RESHAPE = (-1, TIME_SLOT, FREQUENCY_SLOT, CHANNELS_NUM)
HIDDEN_LAYERS = int(CONF.getAttr("default", "hidden_layers"))
# 用于后续规格化,(NTFC)
# 由于后续keras中卷积层默认通道数在最后一个维度上,即channels_last,故此处需要将8放在最后
# cpu版本的tf不支持channels_first,只支持NHWC模式,即channels_last
OUT_SIZE = len(ACTIONS)  #输出规格,与分类数有关

# ========================== data create =======================
print("Loading data...")
train_data, test_data, validate_data = dataLoading.load("new_data")
print("Done.")

train_X, train_y = dataLoading.tag_divide(train_data)
test_X, test_y = dataLoading.tag_divide(test_data)
val_X, val_y = dataLoading.tag_divide(validate_data)
コード例 #19
0
from configReader import ConfigReader
import numpy as np
import tensorflow as tf
import time
import os
import sys
import dataLoading

ACTION = sys.argv[1]
mode = "default"
if ACTION == "left" or ACTION == "right":
    mode = "horizontal"
else:
    mode = "vertical"

CONF = ConfigReader("hyperParameters.ini", mode)
RESHAPE = (-1, 8, 60)
FFT_MAX_HZ = CONF.frequency_slot
HM_SECONDS = 10
TOTAL_ITERS = HM_SECONDS * 25
CHANNELS_NUM = CONF.channels_num
TIME_SLOT = CONF.time_slot
ACTIONS = CONF.actions
CONF.addActions(ACTION)
model = tf.keras.models.load_model(
    os.path.join(CONF.models_dir, CONF.test_model))

last_print = time.time()
fps_counter = deque(maxlen=150)

# 接收推流数据
コード例 #20
0
ファイル: main.py プロジェクト: ollien/purple-america
	def GET(self,**kwargs):
		configReader = ConfigReader()
		configReader.readKeys()
		keys = configReader.getKeys()
		region = 'USA-county'
		year = '2012'
		if 'region' in kwargs:
			if self.validRegion(kwargs['region']):
				region = kwargs['region']
		elif 'region' in keys:
			if self.validRegion(keys['region']):
				region=keys['region']
		if 'year' in kwargs:
			if self.validYear(int(kwargs['year'])):
				year = kwargs['year']
		elif 'year' in keys:
			if self.validYear(int(keys['year'])):
				year = keys['year']
		areas = {}
		#Read election data
		if 'county' in region:
			files = glob(staticPath+'purple/*'+year+'.txt')
			for fileName in files:
				f = open(fileName,'r')
				areas.update(self.readReigion(f))
				f.close()
		else:
			f = open(staticPath+'purple/'+region+'2012.txt')
			areas.update(self.readReigion(f))
		f = open(staticPath+'purple/'+region+'.txt')
		coords = [{'name':'','color':None,'coords':[]}]
		reading = False
		#Read the region file
		for line in f:
			if not reading:
				#A fix for some file inconsitencies in LA
				line = line.rstrip().lower().replace(' parish','')
				if line in areas:
					coords[-1]['name']=line
					l = areas[line]
					# Baisc Red Green Blue Map
					# if (max(l)==l[0]):
					# 	coords[-1]['color']='blue'
					# elif (max(l)==l[1]):
					# 	coords[-1]['color']='red'
					# elif (max(l)==l[2]):
					# 	coords[-1]['color']='green'
					r = float(l[0])/sum(l)*255
					g = float(l[2])/sum(l)*255
					b = float(l[1])/sum(l)*255
					
					coords[-1]['color'] = '#%02X%02X%02X' % (r,g,b)					
					reading = True
			else:
				if line[0]!='\n':
					coords[-1]['coords'].append([float(item) for item in line.split() if len(line.split())==2])
				else:
					reading = False
					coords.append({'name':'','color':None,'coords':[]})
		f.close()
		#Fix there being elements that are len == 0. String parsing can be a pain.
		c = []
		for dictionary in coords:
			l = []
			for item in dictionary['coords']:
				if len(item)==2:
					l.append(item)
			if len(l)!=0:
				dictionary['coords']=l
				c.append(dictionary)
		coords = list(c)
		lowest = min([item for dictionary in coords for c in dictionary['coords'] for item in c])*-1
		#Convert them to values above 0, round them, and multiply to make it bigger
		for dictionary in coords:
			dictionary['coords'] = [[(item+lowest)*20 for item in c]for c in dictionary['coords']]
		#get the highest y coordinate
		highestY = min([c[1] for dictionary in coords for c in dictionary['coords']])
		#We need to reflect it, since we're drawing in quadrant IV
		for dictionary in coords:
			dictionary['coords'] = [[c[0], highestY-(c[1]-highestY)] for c in dictionary['coords']]
		
		#Now we're gonna move it up so you can actually see it
		#Find the newest highest y coordinate
		highestY = min([c[1] for dictionary in coords for c in dictionary['coords']])
		for dictionary in coords:
			dictionary['coords'] = [[c[0],c[1]-highestY]for c in dictionary['coords']]
		print 'sending to client'
		return json.dumps({'coords':coords})
コード例 #21
0
ファイル: real_test.py プロジェクト: Masquerade51256/IMABOT
from pylsl import StreamInlet, resolve_stream
import tensorflow as tf
import numpy as np
import time
from collections import deque
import os
from boxGraphicView import BoxGraphicView
from configReader import ConfigReader
import dataLoading

CONF = ConfigReader("hyperParameters.ini")
RESHAPE = (-1, 8, 60)
FFT_MAX_HZ = CONF.frequency_slot
HM_SECONDS = 10
TOTAL_ITERS = HM_SECONDS * 25
ACTIONS_H = CONF.getAttr("horizontal", "actions").split(',')
ACTIONS_V = CONF.getAttr("vertical", "actions").split(',')
CHANNELS_NUM = CONF.channels_num
TIME_SLOT = CONF.time_slot

model_h = tf.keras.models.load_model(
    os.path.join(CONF.getAttr("horizontal", "models_dir"),
                 CONF.getAttr("horizontal", "test_model")))
model_v = tf.keras.models.load_model(
    os.path.join(CONF.getAttr("vertical", "models_dir"),
                 CONF.getAttr("vertical", "test_model")))
# model_h.predict(np.zeros((32,60,60,8)))

last_print = time.time()
fps_counter = deque(maxlen=150)