[vz-users] Middleware mit negativen Werten nach Update

Andreas Goetz cpuidle at gmail.com
Thu Dec 26 12:24:38 CET 2013


Hallo Sebastian,

verstehe ich Dich richtig, dass Du die Datenbank direkt manipulierst? Wenn
Du das machst bist Du natürlich auch dafür verantwortlich dass die gesamte
Datenbank stimmt.

Einfachste Lösung: aggregation ausschalten (klappts dann?)

Zweiteinfachste Lösung: aggregation NICHT für Deinen selbst geschriebenen
Kanal nutzen.

Schwieriger: überlegen was passiert.
Das aggregate Skript schiebt die historischen Daten (=vor der aktuellen
Periode) in eine Extratabelle. Das Problem ist wenn Du jetzt nochmal Daten
in die Originaltabelle schreibst. Wenn das einen Zeitraum betrifft der in
der Aggregationstabelle bereits enthalten ist werden die Änderungen
schlicht ignoriert, unabhängig davon ob Du es über Middleware oder
Datenbank machst.
Für Middleware liesse sich das mit ein wenig Logik noch beheben, für
Datenbank bist Du auf Dich gestellt.

vg
Andreas



On Thu, Dec 26, 2013 at 11:42 AM, Sebastian Michel
<Sebastian_Michel at gmx.de>wrote:

> Es ist in python geschrieben. Hier ein Auszug:
>
> class VzDb(object):
>
>     def __init__(self, host, port, user, passwd, name):
>         self.Host = host
>         self.Port = port
>         self.User = user
>         self.Pass = passwd
>         self.Name = name
>
>     def connect(self):
>         self.Handle = MySQLdb.connect(host=self.Host, port=self.Port,
> user=self.User, passwd=self.Pass, db=self.Name)
>
>     def save(self, uuid, value):
>
>         cursor = self.Handle.cursor()
>         query = """SELECT e.id, p.value FROM entities e
>                    LEFT JOIN properties p
>                    ON (e.id = p.entity_id)
>                    WHERE e.uuid = '%s' AND p.pkey = 'title'""" % (uuid)
>         resp = cursor.execute(query)
>         if resp != 1:
>             raise Exception("Multiple channels in database with uuid: %s"
> % uuid)
>
>          # get channel id and channel title
>         (channel_id,title,) = cursor.fetchone()
>
>         timestamp = int( time.time()*1000 )
>         query = "INSERT INTO data(channel_id, timestamp, value) VALUES
> (%d, %d, %f)" % (channel_id, timestamp, value)
>         resp = cursor.execute(query)
> #        print query
>         if resp == 1:
>             syslog.syslog(syslog.LOG_INFO, "Added value (%.2f) to database
> channel: '%s'" % (value, title))
>         else:
>             raise Exception("Error adding value to database channel:" %
> title)
>
>         cursor.close()
>
>     def close(self):
>         self.Handle.commit()
>         self.Handle.close()
>
>
>
> Viele Grüße
> Sebastian
>
>
> Am 2013-12-26 11:34, schrieb Daniel Lauckner:
>
>  Mahlzeit,
>>
>> Am Donnerstag, 26. Dezember 2013 um 11:11 schrieb Sebastian Michel:
>>
>>> Hallo,
>>>
>>
>>  ich hab folgendes Problem:
>>>
>>
>> [...]
>>
>>  Kann mir jmd weiterhelfen?
>>>
>>
>>
>> Script vergessen?!
>>
>>
>>
>>
>> mfg Daniel
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://demo.volkszaehler.org/pipermail/volkszaehler-users/attachments/20131226/20b74652/attachment.html>


More information about the volkszaehler-users mailing list