Skip to content

Commit

Permalink
sample layout for fax-checker added and implemented for fez checker. …
Browse files Browse the repository at this point in the history
…In checker type selection download for sample added
  • Loading branch information
seiferta committed Apr 23, 2016
1 parent d190215 commit 26bfde6
Show file tree
Hide file tree
Showing 7 changed files with 574 additions and 306 deletions.
4 changes: 4 additions & 0 deletions emonitor/modules/alarms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ def __init__(self, app):
# static folders
@app.route('/alarms/inc/<path:filename>')
def alarms_static(filename):
if filename.startswith('sample_'): # deliver sample checker file
clsname = filename.split('_')[1]
return Response(AlarmType.getAlarmTypes(clsname).interpreterclass().getSampleLayout(), mimetype="image/jpeg")

return send_from_directory("{}/emonitor/modules/alarms/inc/".format(app.config.get('PROJECT_ROOT')), filename)

@app.route('/alarms/export/<path:filename>') # filename = [id]-[style].pdf
Expand Down
25 changes: 24 additions & 1 deletion emonitor/modules/alarms/alarmutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import logging
import datetime, time
import requests
import json
from StringIO import StringIO
from PIL import Image, ImageDraw, ImageFont
from collections import OrderedDict
from sqlalchemy import inspect
from flask import current_app
Expand Down Expand Up @@ -251,6 +252,28 @@ def buildAlarmFromText(self, alarmtype, rawtext):
"""
return dict()

def getSampleLayout(self):
"""
create sample layout file and return file
:return: sample as jpeg image
"""
img_sample = Image.new('RGB', (2480, 3508), (255, 255, 255)) # DIN-A4 72 dpi
font = ImageFont.truetype("times.ttf", 60)

draw = ImageDraw.Draw(img_sample)
lines = [u'Sample not set']
t = 10
for line in lines:
size = font.getsize(line)
l = (2480 - size[0]) / 2
t += size[1] + 20
draw.text((l, t), line, (0, 0, 0), font=font)

draw.line((40, t + 100, 2400, t + 100), fill=256, width=3)
output = StringIO()
img_sample.save(output, format="JPEG", dpi=(300, 300))
return output.getvalue()


def getAlarmRoute(alarm):
"""
Expand Down
61 changes: 58 additions & 3 deletions emonitor/modules/alarms/inc/faxchecker_fez.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from collections import OrderedDict
import re
import difflib
from StringIO import StringIO
from emonitor.modules.alarms.alarmutils import AlarmFaxChecker
from emonitor.modules.streets.street import Street
from emonitor.modules.streets.city import City
from emonitor.modules.cars.car import Car
from emonitor.modules.settings.department import Department
from emonitor.modules.alarmkeys.alarmkey import Alarmkey
from emonitor.modules.alarmobjects.alarmobject import AlarmObject
from PIL import Image, ImageDraw, ImageFont

__all__ = ['FezAlarmFaxChecker']

Expand All @@ -17,7 +19,7 @@ class FezAlarmFaxChecker(AlarmFaxChecker):
fax checker implementation for Feuerwehreinsatzzentrale Muenchen Land (FEZ) with special layout
"""
__name__ = "FEZ"
__version__ = '0.2'
__version__ = '0.3'

fields = {}
sections = OrderedDict()
Expand Down Expand Up @@ -405,7 +407,6 @@ def buildAlarmFromText(self, alarmtype, rawtext):

curr_field = ""

#for l in rawtext.decode('utf-8').split(u"\n"):
for l in rawtext.split(u"\n"):
field = difflib.get_close_matches(re.split(u':|=|i ', l)[0], sectionnames.keys(), 1) # test line ->:|=
if len(field) == 0 and u" " in l:
Expand All @@ -423,7 +424,6 @@ def buildAlarmFromText(self, alarmtype, rawtext):
curr_field = field[0]
elif curr_field != '':
if sectionnames[curr_field] != u'':
#FezAlarmFaxChecker().fields[sectionnames[curr_field]] = (FezAlarmFaxChecker().fields[sectionnames[curr_field]][0] + u'\n' + value, FezAlarmFaxChecker().fields[sectionnames[curr_field]][1])
if value[0] == u' ':
FezAlarmFaxChecker().fields[sectionnames[curr_field]] = (u"\n".join((FezAlarmFaxChecker().fields[sectionnames[curr_field]][0], value)), FezAlarmFaxChecker().fields[sectionnames[curr_field]][1])
else:
Expand Down Expand Up @@ -454,3 +454,58 @@ def buildAlarmFromText(self, alarmtype, rawtext):
except:
values[k] = (FezAlarmFaxChecker().fields[k][0], FezAlarmFaxChecker().fields[k][1])
return values

def getSampleLayout(self):
"""
create sample layout file and return file
:return: sample as jpeg image
"""
img_sample = Image.new('RGB', (2480, 3508), (255, 255, 255)) # DIN-A4 72 dpi
font = ImageFont.truetype("times.ttf", 60)

draw = ImageDraw.Draw(img_sample)
lines = [u'Alarmschreiben',
u'Feuerwehreinsatzzentrale Landkreis M\xfcnchen Land',
u'Telefon: +49 (89) 1234-56789 Telefax: +49 (89) 4444-123456']
t = 10
for line in lines:
size = font.getsize(line)
l = (2480 - size[0]) / 2
t += size[1] + 20
draw.text((l, t), line, (0, 0, 0), font=font)

draw.line((40, t + 100, 2400, t + 100), fill=256, width=3)
draw.text((40, t + 120), u'Einsatznr:' + u' ' * 20 + u'B 1.4.2 160101 000 ' + u' ' * 20 + u'Alarm: 01.01.2016 00:01', (0, 0, 0), font=font)
draw.line((40, t + 200, 2400, t + 200), fill=256, width=3)

draw.text((40, t + 300), u'Mitteiler:' + u' ' * 30 + u'Person ABC', (0, 0, 0), font=font)
draw.text((40, t + 400), u'Einsatzort:', (0, 0, 0), font=font)
draw.text((40, t + 460), u'Stra\xdfe:' + u' ' * 34 + u'Musterstra\xdfe 1 3a', (0, 0, 0), font=font)
draw.text((40, t + 520), u'Abschnitt:', (0, 0, 0), font=font)
draw.text((40, t + 660), u'Kreuzung:', (0, 0, 0), font=font)
draw.text((40, t + 780), u'Ortsteil/Ort:' + u' ' * 26 + u'Musterstadt in 80000 Musterstadt, Kr M\xfcnchen', (0, 0, 0), font=font)

draw.text((40, t + 900), u'Objekt:', (0, 0, 0), font=font)
draw.text((40, t + 1000), u'Einsatzplan:', (0, 0, 0), font=font)

draw.line((40, t + 1100, 2400, t + 1100), fill=256, width=3)
draw.text((40, t + 1140), u'Meldebild:' + u' ' * 28 + u'Wasserschaden', (0, 0, 0), font=font)
draw.line((40, t + 1240, 2400, t + 1240), fill=256, width=3)

draw.text((40, t + 1300), u'Hinweis:' + u' ' * 30 + u'Achtung nass!', (0, 0, 0), font=font)
draw.line((40, t + 1440, 2400, t + 1440), fill=256, width=3)
draw.line((40, t + 1500, 2400, t + 1500), fill=256, width=3)

draw.text((40, t + 1520), u'Geforderte Einsatzmittel bzw. Ausr\xfcstung:', (0, 0, 0), font=font)

draw.text((70, t + 1600), u'1.4.2 M-L FF Musterstadt', (0, 0, 0), font=font)
draw.text((70, t + 1680), u'1.4.2 M-L FF Musterstadt 40/1', (0, 0, 0), font=font)
draw.text((70, t + 1760), u'1.4.2 M-L FF Musterstadt 65/1', (0, 0, 0), font=font)

draw.text((40, t + 1900), u'(Alarmschreiben Ende)', (0, 0, 0), font=font)
draw.line((40, t + 2000, 2400, t + 2000), fill=256, width=3)

draw.text((40, t + 2060), u'Auch bei Erhalt des Alarmschreiben den EINSATZORT \xfcber Funk best\xe4tigen!!', (0, 0, 0), font=font)
output = StringIO()
img_sample.save(output, format="JPEG", dpi=(300, 300))
return output.getvalue()
3 changes: 2 additions & 1 deletion emonitor/modules/alarms/templates/admin.alarms.type.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ <h2>{{ _('alarms.type.header.overview') }}</h2>
{% for alarmtype in alarmtypes %}
<div class="row">
<a href="#" class="morelink" title="{{ _('alarms.type.detailtitle') }}" onclick="return details({{ alarmtype.id }}, this)"> </a>
<div style="margin-right:60px;margin-left:15px;">
<div style="margin-right:90px;margin-left:15px;">
<div class="rowcell" style="width:20%;">{{ alarmtype.name }}</div>
<div class="rowcell" style="width:80%;overflow:hidden">{{ alarmtype.keywords.replace('\r\n', ', ') }}</div>
</div>
<button type="submit" name="action" value="deletetype_{{ alarmtype.id }}" title="{{ _('alarms.type.deletetitle') }}" onclick="return questionDel()"><i class="fa fa-trash-o fa-lg"></i></button>
<button type="submit" name="action" value="editalarmtype_{{ alarmtype.id }}" title="{{ _('alarms.type.edittitle') }}"><i class="fa fa-pencil fa-lg"></i></button>
<button type="button" name="action" title="{{ _('alarms.type.getsample') }}" onclick="window.open('/alarms/inc/sample_{{ alarmtype.id }}', 'sample', 'toolbar=0,status=0')"><i class="fa fa-file-image-o"></i></button>
</div>

<div class="details" style="display:none" id="details_{{ alarmtype.id }}">
Expand Down
Binary file modified emonitor/modules/translations/de/LC_MESSAGES/modules.mo
Binary file not shown.
Loading

0 comments on commit 26bfde6

Please sign in to comment.