Minor fixes
This commit is contained in:
54
Taurus.py
54
Taurus.py
@@ -36,9 +36,12 @@ entities ['201863'] = [
|
||||
(9, 'MAN', '00900085', 'Tieruntersuchung', 'N', 1, 0, '', 0),
|
||||
(10, 'MAN', '00900059', 'Datum Tieruntersuchung', 'N', 8, 0, 'CCYYMMDD', 0),
|
||||
(11, 'MAN', '00900058', 'Laktationsnummer', 'N', 2, 0, '', 0),
|
||||
(13, 'OPT', '00900080', 'Ohrnummer', 'N', 15, 0, '', 0)
|
||||
(13, 'OPT', '00900080', 'Ohrnummer', 'AN', 15, 0, '', 0),
|
||||
(14, 'OPT', '00200112', 'unbekannt', 'AN', 2, 0, '', 0),
|
||||
(15, 'OPT', '00200050', 'unbekannt', 'AN', 8, 0, '', 0),
|
||||
(16, 'OPT', '00201592', 'unbekannt', 'AN', 6, 0, '', 0)
|
||||
]
|
||||
|
||||
#Fixme Ohrnummer numerisch
|
||||
"""
|
||||
Entity 201865
|
||||
Futterdaten
|
||||
@@ -59,7 +62,7 @@ Melkverbot
|
||||
#NR, ART, ITEM, NAME, TYPE, LEN, RESOLUTION, UNIT, CODE
|
||||
entities ['201867'] = [
|
||||
(1, 'KEY', '00201896', 'Stallnummer', 'N', 6, 0, '', 0),
|
||||
(2, 'OPT', '00900080', 'Ohrnummer', 'N', 15, 0, '', 0),
|
||||
(2, 'OPT', '00900080', 'Ohrnummer', 'AN', 15, 0, '', 0),
|
||||
(3, 'MAN', '00004401', 'Start Melkverbot', 'N', 8, 0, 'CCYYMMDD', 0),
|
||||
(4, 'MAN', '00004402', 'Ende Melkverbot', 'N', 8, 0, 'CCYYMMDD', 0)
|
||||
]
|
||||
@@ -134,6 +137,7 @@ class TAURUS:
|
||||
self.log ("Request Normaldaten", 9)
|
||||
reqentity, reqd = self.parsed (linedata)
|
||||
self.log ("Request Normaldaten entity %s" % reqentity, 9)
|
||||
self.log ("Request Normaldaten daten %s" % reqd, 9)
|
||||
request.append ((reqentity, reqd))
|
||||
elif linetype == 'V':
|
||||
#Values
|
||||
@@ -148,6 +152,7 @@ class TAURUS:
|
||||
self.log ("Normaldaten", 9)
|
||||
if currententity == '201863':
|
||||
self.log ("Tierdaten updaten", 6)
|
||||
self.log ("Ohrmakre '%s'" % values ['00900080'], 6)
|
||||
animaldata = {'animalnr' : values ['00201896'],
|
||||
'earmark' : values ['00900080'],
|
||||
'rfid' : values ['00201812'],
|
||||
@@ -181,9 +186,17 @@ class TAURUS:
|
||||
file.close ()
|
||||
# Handle Requests
|
||||
if request:
|
||||
self.log ("Path %s" % path)
|
||||
file = open (path + self.writefilename, 'w')
|
||||
for reqentity, reqd in request:
|
||||
self.log ("Request %s ausfuehren" % reqentity)
|
||||
if reqentity == '201863':
|
||||
wline = self.generated (reqentity, reqd)
|
||||
file.write (wline + '\n')
|
||||
for animalinfo in self.db.getanimals ():
|
||||
wline = self.createanimaldataset (animalinfo, reqd)
|
||||
if wline:
|
||||
file.write (wline + '\n')
|
||||
if reqentity == '201865':
|
||||
wline = self.generated (reqentity, reqd)
|
||||
file.write (wline + '\n')
|
||||
@@ -249,7 +262,30 @@ class TAURUS:
|
||||
return values
|
||||
|
||||
|
||||
def createmilkdataset (self, animalinfo, ddef, nr):
|
||||
def createanimaldataset (self, animalinfo, ddef):
|
||||
"""
|
||||
Tierdatensatz
|
||||
"""
|
||||
animalnr, earmark, rfid, tsforbidstart, tsforbidend = animalinfo
|
||||
|
||||
data = {'00201896': animalnr}
|
||||
data ['00900080'] = earmark
|
||||
data ['00201812'] = rfid
|
||||
ds = "VN201863"
|
||||
for nr, art, item, name, datatype, length, resolution, unit, code in ddef:
|
||||
if item in data:
|
||||
if datatype == 'AN':
|
||||
ds += str (data[item]).rjust (int (length))
|
||||
elif datatype == 'N':
|
||||
_v = "%d" % (int (data[item] * (10**int (resolution))))
|
||||
ds += _v.rjust (int (length))
|
||||
else:
|
||||
ds += '?' * length
|
||||
self.log (ds, 9)
|
||||
return ds
|
||||
|
||||
|
||||
def createmilkdataset (self, animalinfo, ddef, milkings):
|
||||
"""
|
||||
Creating entity for 880022
|
||||
"""
|
||||
@@ -267,7 +303,7 @@ class TAURUS:
|
||||
milkforbid = 1
|
||||
|
||||
retval = ''
|
||||
mds = self.db.getlastmilkdatabyanimal (animalnr, nr)
|
||||
mds = self.db.getlastmilkdatabyanimal (animalnr, milkings)
|
||||
for md in mds:
|
||||
ts, animalnr, ammount, time, milkplace = md
|
||||
dt = datetime.strptime (ts, '%Y-%m-%d %H:%M:%S')
|
||||
@@ -284,7 +320,7 @@ class TAURUS:
|
||||
for nr, art, item, name, datatype, length, resolution, unit, code in ddef:
|
||||
if item in data:
|
||||
if datatype == 'AN':
|
||||
ds += data[item].rjust (int (length + 1))
|
||||
ds += data[item].rjust (int (length))
|
||||
elif datatype == 'N':
|
||||
_v = "%d" % (int (data[item] * (10**int (resolution))))
|
||||
ds += _v.rjust (int (length))
|
||||
@@ -300,6 +336,12 @@ class TAURUS:
|
||||
|
||||
if __name__ == "__main__":
|
||||
taurus = TAURUS (DB ('/opt/data/animaldb.sqlite', '/tmp/talog.sql', logtest, errlogtest), loglevel = 9, writefilename = 'rep.taur')
|
||||
print ("UPDATE")
|
||||
taurus.parsefile ('sampledata/', 'Update.taur')
|
||||
print ("REQUEST")
|
||||
taurus.parsefile ('sampledata/', 'TAU_REQ_20180116.2')
|
||||
sys.exit (0)
|
||||
print ("MELKverbot")
|
||||
taurus.parsefile ('sampledata/', 'Melkverbot.taur')
|
||||
print ("REQUEST")
|
||||
taurus.parsefile ('sampledata/', 'Request.taur')
|
||||
|
||||
3
startlactor.sh
Normal file → Executable file
3
startlactor.sh
Normal file → Executable file
@@ -1,9 +1,10 @@
|
||||
#! /bin/bash
|
||||
while true; do
|
||||
cd /opt/lactor
|
||||
echo "Starting Lactor in `pwd` at `date`" >> /var/log/lactor/startstop.log
|
||||
#echo "BDE restarted" | mail -s "BDE Restart" admin@apc910.finoba.by
|
||||
python3 ./lactor.py `pwd` 2>&1 >> log_`date -Idate`.txt
|
||||
echo "Lactor stopped in `pwd` at `date`" >> /var/log/bde/startstop.log
|
||||
echo "Lactor stopped in `pwd` at `date`" >> /var/log/lactor/startstop.log
|
||||
sleep 2
|
||||
done
|
||||
|
||||
|
||||
Reference in New Issue
Block a user