diff --git a/app.py b/app.py index 5a557d7..e0ba360 100644 --- a/app.py +++ b/app.py @@ -6,6 +6,14 @@ import io app = Flask(__name__) +SHOOTOFF_DISTANCE = 1200 +SHOOTOFF_GAP = 100 +IPSC_DISTANCE = 914 +IPSC_GAP = 92 +IPSC_TARGET_WIDTH = 46 +IPSC_TARGET_HEIGHT = 58 +IPSC_STAGE_WIDTH = 322 + VALUES = { "five_to_go": { "t1": {"len_a": 3100, "len_h": 9100, 'width': 250, 'height': 250, 'elevation': 0, 'stop_plate': False, @@ -109,6 +117,135 @@ VALUES = { } } +@app.route('/') +def index(): + return render_template('sc.html', current_url=request.path) + +@app.route('/shootoff') +def shootoff(): + return render_template('shootoff.html', current_url=request.path) + +@app.route('/ipsc') +def ipsc(): + return render_template('ipsc.html', current_url=request.path) + +@app.route('/generate-pdf', methods=['POST']) +def generate_pdf(): + distance = int(request.form.get('distance', 1) or 1) + distance_in_mm = distance * 10 + stage = request.form.get('stage') + size = request.form.get('size') + distance_type = request.form.get('distance_type') + if distance_type == 'wall': + distance_in_mm = calculate_distance(distance_in_mm, stage, size) + + targets = [f't{i}' for i in range(1, 6)] + target_info = [_target_info(distance_in_mm, stage, size, target) for target in targets] + wall_extra_space_for_paper = 297 if size == 'a3' else 210 + wall_length = target_info[-1]['position'] + wall_extra_space_for_paper + preview_size = 267 if size == 'a3' else 190 + preview_scale = preview_size / target_info[-1]['position'] + preview_distance = distance_in_mm * preview_scale + preview_target_info = [_target_info(preview_distance, stage, size, target) for target in targets] + box_position = int(target_info[0]['sim_a_len']) / 10 + + rendered_html = render_template( + 'pdf_template.html', + distance=distance_in_mm/10, + size=size, + stage=stage, + target_info=target_info, + preview_target_info=preview_target_info, + wall_length=wall_length, + box_position=box_position, + ) + #return rendered_html + + pdf_file = io.BytesIO() + HTML(string=rendered_html).write_pdf(pdf_file) + pdf_file.seek(0) + filename = 'Paper Challenge - ' + stage.replace('_', ' ') + ' - ' + str(distance) + 'cm-' + size + '.pdf' + + return send_file(pdf_file, download_name=filename, as_attachment=False) + + +@app.route('/generate-pdf-shootoff', methods=['POST']) +def generate_pdf_shootoff(): + distance = int(request.form.get('distance', 1) or 1) + size = request.form.get('size') + distance_type = request.form.get('distance_type') + target_count = 6 + if distance_type == 'wall': + desired_wall_length = distance + distance = calculate_distance_shootoff(desired_wall_length, size, target_count) + target_line = (target_count - 1) * SHOOTOFF_GAP + scale = distance / SHOOTOFF_DISTANCE + wall_extra_space_for_paper = 29.7 if size == 'a3' else 21.0 + wall_length = target_line * scale + wall_extra_space_for_paper + preview_size = 25.7 if size == 'a3' else 18 + preview_scale = preview_size /target_line + box_position = wall_length / 2 + + + + rendered_html = render_template( + 'pdf_template_shootoff.html', + distance=distance, + size=size, + wall_length=wall_length, + gap=SHOOTOFF_GAP*scale, + target_count=target_count, + scale=scale, + preview_scale=preview_scale, + box_position=box_position + ) + #return rendered_html + + pdf_file = io.BytesIO() + HTML(string=rendered_html).write_pdf(pdf_file) + pdf_file.seek(0) + filename = 'Paper Challenge - Shootoff - ' + str(distance) + 'cm-' + size + '.pdf' + + return send_file(pdf_file, download_name=filename, as_attachment=False) + +@app.route('/generate-pdf-ipsc', methods=['POST']) +def generate_pdf_ipsc(): + distance = int(request.form.get('distance', 1) or 1) + size = request.form.get('size') + distance_type = request.form.get('distance_type') + scale = distance / IPSC_DISTANCE + wall_extra_space_for_paper = 29.7 if size == 'a3' else 21.0 + if distance_type == 'wall': + scale = (distance - wall_extra_space_for_paper) / IPSC_STAGE_WIDTH + distance = scale * IPSC_DISTANCE + target_line = scale * IPSC_STAGE_WIDTH + wall_extra_space_for_paper + preview_size = 15 if size == 'a3' else 10 + preview_scale = preview_size /target_line + box_position = target_line / 2 + + rendered_html = render_template( + 'pdf_template_ipsc.html', + distance=distance, + size=size, + wall_length=target_line, + target_height=scale * IPSC_TARGET_HEIGHT, + target_width=scale * IPSC_TARGET_WIDTH, + gap=scale * IPSC_GAP + scale * IPSC_TARGET_WIDTH, + preview_margin=(wall_extra_space_for_paper - preview_size) / 2, + scale=scale, + preview_scale=preview_scale, + box_position=box_position + ) +# return rendered_html + + pdf_file = io.BytesIO() + HTML(string=rendered_html).write_pdf(pdf_file) + pdf_file.seek(0) + filename = 'Paper Challenge - IPSC - EL Presidente - ' + str(distance) + 'cm-' + size + '.pdf' + + return send_file(pdf_file, download_name=filename, as_attachment=False) + + def calculate_distance(desired_wall_length, stage, size): wall_extra_space_for_paper = 297 if size == 'a3' else 210 @@ -175,50 +312,30 @@ def _target_info(distance, stage, size, target): } -@app.route('/') -def index(): - return render_template('index.html') -@app.route('/generate-pdf', methods=['POST']) -def generate_pdf(): - distance = int(request.form.get('distance', 1) or 1) - distance_in_mm = distance * 10 - stage = request.form.get('stage') - size = request.form.get('size') - distance_type = request.form.get('distance_type') - if distance_type == 'wall': - distance_in_mm = calculate_distance(distance_in_mm, stage, size) - targets = [f't{i}' for i in range(1, 6)] - target_info = [_target_info(distance_in_mm, stage, size, target) for target in targets] - wall_extra_space_for_paper = 297 if size == 'a3' else 210 - wall_length = target_info[-1]['position'] + wall_extra_space_for_paper - preview_size = 267 if size == 'a3' else 190 - preview_scale = preview_size / target_info[-1]['position'] - preview_distance = distance_in_mm * preview_scale - preview_target_info = [_target_info(preview_distance, stage, size, target) for target in targets] - box_position = int(target_info[0]['sim_a_len']) / 10 +def calculate_distance_shootoff(desired_wall_length, size, target_count): + wall_extra_space_for_paper = 29.7 if size == 'a3' else 21.0 + distance = 1 + step = 100 - rendered_html = render_template( - 'pdf_template.html', - distance=distance_in_mm/10, - size=size, - stage=stage, - target_info=target_info, - preview_target_info=preview_target_info, - wall_length=wall_length, - box_position=box_position, - ) - #return rendered_html - - pdf_file = io.BytesIO() - HTML(string=rendered_html).write_pdf(pdf_file) - pdf_file.seek(0) - filename = 'Paper Challenge - ' + stage.replace('_', ' ') + ' - ' + str(distance) + 'cm-' + size + '.pdf' - - return send_file(pdf_file, download_name=filename, as_attachment=False) + while True: + target_line = (target_count - 1) * SHOOTOFF_GAP + scale = distance / SHOOTOFF_DISTANCE + wall_length = target_line * scale + wall_extra_space_for_paper + print(distance, wall_length, desired_wall_length) + if abs(wall_length - desired_wall_length) <= 0.5: + break + if wall_length > desired_wall_length: + distance -= step + step = step / 10 + continue + distance += step; + if distance > 700: + break + return distance if __name__ == '__main__': app.run(debug=True) diff --git a/static/images/ipsc.png b/static/images/ipsc.png new file mode 100644 index 0000000..a6aa04b Binary files /dev/null and b/static/images/ipsc.png differ diff --git a/static/images/ipsc.svg b/static/images/ipsc.svg new file mode 100644 index 0000000..baf564b --- /dev/null +++ b/static/images/ipsc.svg @@ -0,0 +1,9 @@ + + ipsc-svg + + + + + + \ No newline at end of file diff --git a/static/images/ipsc_preview.png b/static/images/ipsc_preview.png new file mode 100644 index 0000000..f189547 Binary files /dev/null and b/static/images/ipsc_preview.png differ diff --git a/static/images/shootoff.png b/static/images/shootoff.png new file mode 100644 index 0000000..fb43625 Binary files /dev/null and b/static/images/shootoff.png differ diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..6b98b5d --- /dev/null +++ b/templates/base.html @@ -0,0 +1,49 @@ + + + + + + Paper Challenge + + + + +
+

Paper Challenge

+

Wygeneruj tor {% block title %}{% endblock %}

+
+ + Steel Challenge + + + Shootoff + + + IPSC - El Presidente + +
+ {% block content %}{% endblock %} +
+ + diff --git a/templates/index.html b/templates/index.html deleted file mode 100644 index 74b6668..0000000 --- a/templates/index.html +++ /dev/null @@ -1,186 +0,0 @@ - - - - - - Paper Challenge - - - - -
-

Paper Challenge

- - -
-

Projekt powstał na potrzeby treningu Steel Challenge w domowym zaciszu

-

Ostrzeżenie: Od ponad 11 lat pracuję z PHP, więc mogą być widoczne naleciałości!
Ten projekt - to moje pierwsze... no może drugie kroki w Pythonie.

-

Kopiowanie, rozpowszechnianie, modyfikowanie i udostępnianie na potrzeby własne, klubowe lub dla - kolegi, stanowczo zalecane

-
-

Wygeneruj tor

-
-
-

Wybierz rodzaj kalkulacji ze względu na ograniczoną długość ściany lub ograniczoną odległość stanowiska od ściany

-
- - - - -
-
-

dystans [cm]

- -
-
-
-

Format druku

-
- - -
-
- -
-

Tor

-
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
- -
- -
-
-
- - diff --git a/templates/ipsc.html b/templates/ipsc.html new file mode 100644 index 0000000..4aeac3f --- /dev/null +++ b/templates/ipsc.html @@ -0,0 +1,20 @@ +{% extends "base.html" %} +{% block title %}IPSC - El Presidente{% endblock %} +{% block content %} +
+ {% include 'setup.html' %} +
+

IPSC - El Presidente

+ +
+ IPSC - El Presidente +
+
+
+ +
+
+{% endblock %} diff --git a/templates/ipsc_target.html b/templates/ipsc_target.html new file mode 100644 index 0000000..2a05060 --- /dev/null +++ b/templates/ipsc_target.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/templates/pdf_template.html b/templates/pdf_template.html index 3ae5eaa..b5140d4 100644 --- a/templates/pdf_template.html +++ b/templates/pdf_template.html @@ -83,11 +83,11 @@

Wymagana długość ściany: {{ wall_length/10 }}cm

-

Odległość od ściany: {{ distance }}cm

+

Odległość od ściany: {{ distance|round(1,'ceil') }}cm

Przygotowanie toru: