Config auf Module angewand
*die readConf wurde verbessert *Standartwerte wurden hinterlegt *In den Modulen wird das Configfile verwendet
This commit is contained in:
parent
b205714658
commit
e70ef4de38
4 changed files with 67 additions and 30 deletions
|
|
@ -12,7 +12,8 @@ from datetime import datetime
|
|||
from time import sleep
|
||||
from threading import Thread
|
||||
from Queue import Queue
|
||||
#from MySQLdb import connect
|
||||
from MySQLdb import connect
|
||||
from config import readConf
|
||||
|
||||
debug = False
|
||||
|
||||
|
|
@ -20,6 +21,14 @@ class CANFilter(Thread):
|
|||
|
||||
battery_current, battery_voltage, battery_capacity, battery_timestamp, test = [], [], [], [], [] #create tmp lists
|
||||
|
||||
conf = readConf()
|
||||
|
||||
connection = connect(host = conf['mySQL_server'],
|
||||
user = conf['mySQL_user'],
|
||||
passwd = conf['mySQL_pass'],
|
||||
db = conf['mySQL_database'])
|
||||
cursor = connection.cursor()
|
||||
|
||||
def __init__(self):
|
||||
Thread.__init__(self)
|
||||
|
||||
|
|
@ -64,11 +73,6 @@ class CANFilter(Thread):
|
|||
self.pcan.Messages['dc_charging'].addSignal( current )
|
||||
self.pcan.Messages['dc_charging'].addSignal( voltage )
|
||||
|
||||
return self.queue
|
||||
|
||||
#connection = MySQLdb.connect("url", "user", "passwort", "datenbankname")
|
||||
#cursor = connection.cursor()
|
||||
|
||||
def mean(self, l):
|
||||
return float(sum(l))/len(l) if len(l) > 0 else 0
|
||||
|
||||
|
|
@ -89,15 +93,17 @@ class CANFilter(Thread):
|
|||
print 'SoC: ', self.mean(self.battery_capacity)
|
||||
print 'time: ', self.mean(self.battery_timestamp)
|
||||
|
||||
tabelle = 'EMS-TEST'
|
||||
daten = [(tabelle, str(self.battery_timestamp[i]), str(self.battery_current[i]), str(self.battery_voltage[i]), str(self.battery_capacity[i])) for i in range(100)]
|
||||
sql = 'INSERT INTO %s VALUES(%s, %s, %s, %s)'
|
||||
tabelle = 'battery'
|
||||
# daten = [(tabelle, str(self.battery_timestamp[i]), str(self.battery_current[i]), str(self.battery_voltage[i]), str(self.battery_capacity[i])) for i in range(100)]
|
||||
daten = (tabelle, str(self.battery_timestamp[50]), str(self.mean(self.battery_current)), str(self.mean(self.battery_voltage)), str(self.mean(self.battery_capacity)))
|
||||
sql = "INSERT INTO %s VALUES (%s,%s,%s,%s)"
|
||||
|
||||
self.queue.put(daten[0])
|
||||
|
||||
# for i in daten:
|
||||
# print sql % i
|
||||
# cursor.executemany(sql, daten)
|
||||
# print sql % daten
|
||||
self.cursor.execute("INSERT INTO %s VALUES (\'%s\',%s,%s,%s)" % daten)
|
||||
#self.cursor.executemany(sql, daten)
|
||||
|
||||
del self.battery_current[:], self.battery_voltage[:], self.battery_capacity[:], self.battery_timestamp[:] #clear tmp lists
|
||||
sleep(0.01)
|
||||
Loading…
Add table
Add a link
Reference in a new issue