switch kann nun auch mit warteschalngen initialisiert werden, pCharger überarbeitet
This commit is contained in:
parent
cee95b4b63
commit
4512f2b3dc
2 changed files with 139 additions and 117 deletions
|
|
@ -12,6 +12,7 @@ from Config.parser import config
|
||||||
#import Module
|
#import Module
|
||||||
import database
|
import database
|
||||||
import modbus
|
import modbus
|
||||||
|
from test import query
|
||||||
|
|
||||||
MYSQL = 0
|
MYSQL = 0
|
||||||
MODBUS = 1
|
MODBUS = 1
|
||||||
|
|
@ -30,10 +31,10 @@ class Switch(Thread):
|
||||||
Thread.__init__(self)
|
Thread.__init__(self)
|
||||||
self.source = source
|
self.source = source
|
||||||
|
|
||||||
def initialisiere(self):
|
def initialisiere(self, query = None, queue = None):
|
||||||
'''
|
'''
|
||||||
initialize the swich with the given source and creates a queue and a query
|
initialize the swich with the given source and creates a queue and a query
|
||||||
it calls the setup method from the source module
|
it calls the setup method from the submodule of the source
|
||||||
|
|
||||||
@return: queue and query
|
@return: queue and query
|
||||||
'''
|
'''
|
||||||
|
|
@ -41,14 +42,16 @@ class Switch(Thread):
|
||||||
self.cursor = database.setup(conf)
|
self.cursor = database.setup(conf)
|
||||||
elif self.source == MODBUS:
|
elif self.source == MODBUS:
|
||||||
self.cursor = modbus.setup(conf)
|
self.cursor = modbus.setup(conf)
|
||||||
|
else:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
### init Query ###
|
### init Query ###
|
||||||
self.query = Queue()
|
self.query = Queue() if query is None else query
|
||||||
if conf['config_debug']:
|
if conf['config_debug']:
|
||||||
print '\tSWITCH-QUERY:\t', self.query
|
print '\tSWITCH-QUERY:\t', self.query
|
||||||
|
|
||||||
### init Queue ###
|
### init Queue ###
|
||||||
self.queue = Queue()
|
self.queue = Queue() if queue is None else queue
|
||||||
if conf['config_debug']:
|
if conf['config_debug']:
|
||||||
print '\tSWITCH-QUEUE:\t', self.queue
|
print '\tSWITCH-QUEUE:\t', self.queue
|
||||||
|
|
||||||
|
|
@ -56,7 +59,7 @@ class Switch(Thread):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
'''
|
'''
|
||||||
The loop method of the source module is called with a parameter from the query.
|
The loop method from the submodule is called with a parameter from the query.
|
||||||
Its output is written to the queue.
|
Its output is written to the queue.
|
||||||
'''
|
'''
|
||||||
while True:
|
while True:
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,12 @@ import numpy
|
||||||
|
|
||||||
number = 1
|
number = 1
|
||||||
|
|
||||||
sqlerr = "INSERT INTO %s (DateTime,Type,error) VALUES (\'%s\',%s,%s);"
|
#sqlerr = "INSERT INTO %s (DateTime,Type,error) VALUES (\'%s\',%s,%s);"
|
||||||
sqlnor = "INSERT INTO %s (DateTime,Type,cardnumber,customernumber,plug,meterreading) VALUES (\'%s\',%s,%s,%s,%s,%s);"
|
#sqlnor = "INSERT INTO %s (DateTime,Type,cardnumber,customernumber,plug,meterreading) VALUES (\'%s\',%s,%s,%s,%s,%s);"
|
||||||
folder = 'I:\Rauch\pCharger0%s'
|
folder = 'I:\Rauch\pCharger0%s'
|
||||||
|
|
||||||
|
columns = ('DateTime', 'Type', 'cardnumber', 'customernumber', 'plug', 'meterreading', 'error')
|
||||||
|
|
||||||
def clean(li):
|
def clean(li):
|
||||||
'''
|
'''
|
||||||
Cleans every strings in a list with the strip() Method
|
Cleans every strings in a list with the strip() Method
|
||||||
|
|
@ -55,7 +57,6 @@ def genData(folder):
|
||||||
@param folder: path to the folder containing pCarger csv files
|
@param folder: path to the folder containing pCarger csv files
|
||||||
'''
|
'''
|
||||||
ordner = os.listdir(folder)
|
ordner = os.listdir(folder)
|
||||||
columns = ('DateTime', 'Type','cardnumber', 'customernumber', 'plug', 'meterreading', 'error')
|
|
||||||
res_data = DataFrame(columns = ['DateTime', 'Type', 'cardnumber', 'customernumber', 'plug', 'meterreading', 'error'])
|
res_data = DataFrame(columns = ['DateTime', 'Type', 'cardnumber', 'customernumber', 'plug', 'meterreading', 'error'])
|
||||||
for datei in ordner:
|
for datei in ordner:
|
||||||
path = "%s/%s" % (folder, datei)
|
path = "%s/%s" % (folder, datei)
|
||||||
|
|
@ -88,7 +89,7 @@ def genData(folder):
|
||||||
#res_data = res_data.set_index('DateTime', verify_integrity = True)
|
#res_data = res_data.set_index('DateTime', verify_integrity = True)
|
||||||
res_data = res_data.replace('', numpy.nan)
|
res_data = res_data.replace('', numpy.nan)
|
||||||
res_data = res_data.where(DataFrame.notnull(res_data), 0)
|
res_data = res_data.where(DataFrame.notnull(res_data), 0)
|
||||||
res_data[['cardnumber', 'customernumber', 'plug', 'meterreading', 'error']] = res_data[['cardnumber', 'customernumber', 'plug', 'meterreading', 'error']].astype(numpy.int64)
|
res_data[['cardnumber', 'customernumber', 'plug', 'meterreading', 'error']] = res_data[[ 'cardnumber', 'customernumber', 'plug', 'meterreading', 'error']].astype(numpy.int64)
|
||||||
return res_data
|
return res_data
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -102,11 +103,29 @@ db.loadDatabase(strHost = conf['mySQL_server'],
|
||||||
strPasswd = conf['mySQL_pass'],
|
strPasswd = conf['mySQL_pass'],
|
||||||
strDatabase = 'ems_testdb', #conf['mySQL_database'],
|
strDatabase = 'ems_testdb', #conf['mySQL_database'],
|
||||||
strTable = None)
|
strTable = None)
|
||||||
|
big_data = DataFrame(columns = ['DateTime', 'pillarID', 'Type', 'cardnumber', 'customernumber', 'plug', 'meterreading', 'error'])
|
||||||
for i in range(1,8):
|
for i in range(1,8):
|
||||||
number = i
|
number = i
|
||||||
#print genData('I:\Rauch\pCharger%s' % '0{0}'.format(number))
|
#print genData('I:\Rauch\pCharger%s' % '0{0}'.format(number))
|
||||||
if i == 5:
|
if i == 5:
|
||||||
continue
|
continue
|
||||||
db.writeDatabase('pCharger%s' % '0{0}'.format(number), genData('I:\Rauch\pCharger%s' % '0{0}'.format(number)), bClear = False)
|
tmp = genData('I:\Rauch\pCharger%s' % '0{0}'.format(number))
|
||||||
|
tmp['pillarID'] = i
|
||||||
|
big_data = big_data.append(tmp, ignore_index = True)
|
||||||
|
#db.writeDatabase('pCharger%s' % '0{0}'.format(number), big_data, bClear = False)
|
||||||
print 'wrote pCharger%s' % '0{0}'.format(number)
|
print 'wrote pCharger%s' % '0{0}'.format(number)
|
||||||
|
|
||||||
|
tmp = big_data.sort('DateTime')
|
||||||
|
tmp = tmp.reset_index(drop = True)
|
||||||
|
gr = tmp.groupby(['pillarID', 'plug'])
|
||||||
|
cur = gr.agg('min')['meterreading']
|
||||||
|
tmp['global'] = sum(list(cur))
|
||||||
|
gl = cur
|
||||||
|
|
||||||
|
for i in range(tmp.index[-1]+1):
|
||||||
|
x = tmp.ix[i]
|
||||||
|
if cur[x['pillarID']][x['plug']] < x['meterreading']:
|
||||||
|
cur[x['pillarID']][x['plug']] = x['meterreading']
|
||||||
|
tmp.loc[i, 'global'] = sum(list(cur))
|
||||||
|
|
||||||
|
db.writeDatabase('pCharger', tmp, bClear = False)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue