2017-02-06 18:50:10 +01:00
|
|
|
from __future__ import absolute_import, unicode_literals
|
2017-03-09 20:08:35 +01:00
|
|
|
|
|
|
|
import logging
|
2017-02-06 18:50:10 +01:00
|
|
|
|
2018-02-11 10:56:44 +01:00
|
|
|
import billard.utils as utils
|
2018-02-19 10:33:09 +01:00
|
|
|
from billard.models import LocationData, Client, Accounting, ClientData
|
2017-03-09 20:08:35 +01:00
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
2017-02-06 18:50:10 +01:00
|
|
|
|
2017-08-04 17:49:33 +02:00
|
|
|
|
2018-02-19 10:33:09 +01:00
|
|
|
def process_client_data():
|
2018-02-19 10:56:56 +01:00
|
|
|
data = ClientData.objects.all().order_by('last_seen')
|
2018-02-19 10:33:09 +01:00
|
|
|
for cd in data:
|
|
|
|
client = Client.objects.get(uuid=cd.uuid)
|
|
|
|
client.last_seen = cd.last_seen
|
|
|
|
client.save()
|
|
|
|
cd.delete()
|
|
|
|
|
|
|
|
|
2017-03-09 20:08:35 +01:00
|
|
|
def process_location_data():
|
2017-08-01 07:48:41 +02:00
|
|
|
data = LocationData.objects.filter(processed=False).order_by('tst')
|
2017-03-09 20:08:35 +01:00
|
|
|
for ld in data:
|
2017-08-04 19:31:46 +02:00
|
|
|
try:
|
|
|
|
cli = Client.objects.filter(uuid=ld.client_id, desks__desk_no=ld.desk_no)
|
|
|
|
if cli.count() < 1:
|
2017-03-09 20:08:35 +01:00
|
|
|
ld.processed = True
|
2017-08-04 19:31:46 +02:00
|
|
|
ld.error_msg = 'No client object found. Stopp processing! {}, {}'.format(ld.client_id, ld.desk_no)
|
2017-03-09 20:08:35 +01:00
|
|
|
ld.save()
|
|
|
|
log.error(ld.error_msg)
|
|
|
|
else:
|
2017-08-04 19:31:46 +02:00
|
|
|
cli = cli[0]
|
|
|
|
desk = cli.desks.filter(desk_no=ld.desk_no, enabled=True)
|
|
|
|
if desk.count() != 1:
|
2017-03-09 20:08:35 +01:00
|
|
|
ld.processed = True
|
2017-08-04 19:31:46 +02:00
|
|
|
ld.error_msg = 'No desk object found. Stopp processing! {}, {}'.format(ld.client_id, ld.desk_no)
|
2017-03-09 20:08:35 +01:00
|
|
|
ld.save()
|
|
|
|
log.error(ld.error_msg)
|
2017-08-04 19:31:46 +02:00
|
|
|
desk = desk[0]
|
|
|
|
ac = desk.accounting_set.order_by('time_from').reverse()
|
|
|
|
if ld.on_off:
|
|
|
|
acc = None
|
|
|
|
if ac.count() > 0 and ac[0].time_to is None:
|
|
|
|
log.error('Vorheriges Accounting nicht abgeschlossen: Desk_id {}, Accounting_id {}'
|
|
|
|
.format(desk.id, ac[0].id))
|
|
|
|
acc = ac[0]
|
|
|
|
if acc is None:
|
|
|
|
acc = Accounting(
|
|
|
|
desk=desk,
|
|
|
|
time_from=ld.tst,
|
|
|
|
)
|
|
|
|
acc.save()
|
|
|
|
ld.delete()
|
|
|
|
else:
|
|
|
|
if len(ac) > 0:
|
|
|
|
acc = ac[0]
|
|
|
|
acc.time_to = ld.tst
|
|
|
|
acc.prize, acc.prize_normal, acc.prize_hh = utils.get_prize_for(
|
|
|
|
start=acc.time_from,
|
|
|
|
end=ld.tst,
|
|
|
|
pph=desk.prize,
|
|
|
|
hh_start=cli.location.happy_hour_start,
|
|
|
|
hh_end=cli.location.happy_hour_end,
|
|
|
|
pphh=desk.prize_hh,
|
|
|
|
)
|
|
|
|
acc.reporter_uuid = cli.uuid
|
|
|
|
acc.save()
|
|
|
|
ld.delete()
|
|
|
|
else:
|
|
|
|
ld.processed = True
|
2018-02-11 10:56:44 +01:00
|
|
|
ld.error_msg = 'No existing accountings found. Stopp processing! {}, {}'.format(ld.client_id,
|
|
|
|
ld.desk_no)
|
2017-08-04 19:31:46 +02:00
|
|
|
ld.save()
|
|
|
|
log.error(ld.error_msg)
|
|
|
|
except:
|
|
|
|
log.exception('', exc_info=True)
|