From af66990323fa247205debb0416891bafc7dbdb00 Mon Sep 17 00:00:00 2001 From: Lionel Date: Fri, 24 Oct 2014 15:23:55 +0200 Subject: [PATCH] Simplify SQL table : remove Cost column --- cm160Server.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cm160Server.py b/cm160Server.py index c255dbe..05a3d76 100755 --- a/cm160Server.py +++ b/cm160Server.py @@ -142,7 +142,7 @@ class CM160Data: except ValueError: return None - def __init__(self, min, hour, day, month, year, cost, amps): + def __init__(self, min, hour, day, month, year, amps): self.__sec = 0 #The CM160 does not return seconds in it's data #stream. self.__min = min @@ -153,7 +153,7 @@ class CM160Data: # to 0x49. Not sure why but I'll mask them out # so that we don't get invalid month errors. self.__year = year - self.__costPerKWH = cost +# self.__costPerKWH = cost self.__amps = amps self.__realTime = False #Changes to True when realtime data is being read @@ -178,8 +178,8 @@ class CM160Data: def getSecond(self): return self.__sec - def getCostPerKWH(self): - return self.__costPerKWH +# def getCostPerKWH(self): +# return self.__costPerKWH def getAmps(self): return self.__amps @@ -222,7 +222,7 @@ class CM160Data: def __str__(self): """Return the object as a string""" - s="%s %f %f" % (self.getDateStr(), self.__amps, self.__costPerKWH) + s="%s %f " % (self.getDateStr(), self.__amps) if self.__month >= 1 and self.__month <= 12: return s #The CM160 sometime returns a month greater than 12. As I don't know how to @@ -246,7 +246,7 @@ class CM160Data: if len(elems) == 4: try: self.__amps = float(elems[2]) - self.__costPerKWH = float(elems[3]) +# self.__costPerKWH = float(elems[3]) t = elems[0] d = elems[1] dateElems = d.split("/") @@ -510,9 +510,9 @@ class CM160: day = frame[3] hour = frame[4] _min = frame[5] - costPerKWH = (frame[6]+(frame[7]<<8))/100.0 #Cost in pence per kWh +# costPerKWH = (frame[6]+(frame[7]<<8))/100.0 #Cost in pence per kWh amps = (frame[8]+(frame[9]<<8))* 0.07 #Conversion factor to Amps - cm160Data = CM160Data(_min, hour, day, month, year, costPerKWH, amps) + cm160Data = CM160Data(_min, hour, day, month, year, amps) #Set flag to indicate if this CM160Data was read in realtime or during a data download cm160Data.setRealTime(realTimeData) heappush(self.__queue, cm160Data) # read data from the queue by, cm160Data = heappop(self.__queue) @@ -768,7 +768,7 @@ class MySQLDataStore(object): """ conn, cursor = self.__connect() try: - cursor.execute("CREATE TABLE cm160data(ts timestamp, current float, tariff float, UNIQUE (ts))") + cursor.execute("CREATE TABLE cm160data(ts timestamp, current float, UNIQUE (ts))") # Attempt to create table in case this is first time to run # the server; but thereafter we expect an exception because the # create will fail... @@ -792,7 +792,7 @@ class MySQLDataStore(object): stored=False try: - self.__StoreCursor.execute("""INSERT INTO cm160data VALUES (%s,%s,%s)""", (cm160Data.getDatetime(),cm160Data.getAmps(),cm160Data.getCostPerKWH(),)) + self.__StoreCursor.execute("""INSERT INTO cm160data VALUES (%s,%s)""", (cm160Data.getDatetime(),cm160Data.getAmps(),)) stored=True except MySQLdb.Error as e: -- 2.39.2