Skip to content

Commit

Permalink
Add the other calculation and K8s configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeiP committed Nov 20, 2023
1 parent aaf991a commit c3d7a46
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 3 deletions.
7 changes: 7 additions & 0 deletions app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ class MixtureForm(FlaskForm):
o2_fill_percentage = DecimalField(u'O2 täyttö-%', validators=[DataRequired()])
used_po2 = DecimalField(u'Käytetty PO2', validators=[DataRequired()])

class Co2Form(FlaskForm):
pressure = DecimalField(u'Paine pullossa bar', validators=[DataRequired()])
o2_bottle_percentage = DecimalField(u'O2-% pullossa', validators=[DataRequired()])
fill_amount = DecimalField(u'Täytettävä määrä bar', validators=[DataRequired()])
o2_target = DecimalField(u'O2-% haluttu', validators=[DataRequired()])
used_po2 = DecimalField(u'Käytetty PO2', validators=[DataRequired()])

class FeedbackForm(FlaskForm):
name = StringField(u'Nimi')
email = StringField(u'Sähköpostiosoite')
Expand Down
7 changes: 4 additions & 3 deletions app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
</head>
<body>
<div style="position: absolute; right: 0; top: 0;">
<a href="https://github.com/ZeiP/viiteaineistomuunnin"><img width="149" height="149" src="https://github.blog/wp-content/uploads/2008/12/forkme_right_green_007200.png?resize=149%2C149" class="attachment-full size-full" alt="Fork me on GitHub" data-recalc-dims="1"></a>
<a href="https://github.com/Ardcoras/miksalotti"><img width="149" height="149" src="https://github.blog/wp-content/uploads/2008/12/forkme_right_green_007200.png?resize=149%2C149" class="attachment-full size-full" alt="Fork me on GitHub" data-recalc-dims="1"></a>
</div>
<div class="container">
<nav class="navbar navbar-expand-lg">
<ul class="navbar-nav">
<li role="presentation" class="nav-item"><a class="nav-link" href="/">Työkalu</a></li>
<li role="presentation" class="nav-item"><a class="nav-link" href="/feedback">Palaute</a></li>
<li role="presentation" class="nav-item"><a class="nav-link" href="/">Seoksen laskeminen</a></li>
<li role="presentation" class="nav-item"><a class="nav-link" href="/co2">Happipitoisuuden laskeminen</a></li>
<!-- <li role="presentation" class="nav-item"><a class="nav-link" href="/feedback">Palaute</a></li> -->
</ul>
</nav>
{% block body %}
Expand Down
20 changes: 20 additions & 0 deletions app/templates/co2_result.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% extends "base.html" %}
{% block title %}Tulos{% endblock %}
{% block body %}
<table class="table">
<thead>
<tr>
<th scope="col">Täytön jälkeen BAR</th>
<th scope="col">O2 täyttö-% (max. 40 %)</th>
<th scope="col">MOD(m)</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ pressure_after }}</th>
<td>{{ o2_percentage }}</td>
<td>{{ mod }}</td>
</tr>
</tbody>
</table>
{% endblock %}
13 changes: 13 additions & 0 deletions app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ def mixture():

return render_template('form.html', form=form)

@app.route('/co2', methods=['GET', 'POST'])
def o2view():
form = Co2Form()
if form.validate_on_submit():
# print(form.file.data.filename, file=sys.stderr)

pressure_after = form.pressure.data + form.fill_amount.data
o2_percentage = ((pressure_after * form.o2_target.data) - (form.pressure.data * form.o2_bottle_percentage.data)) / form.fill_amount.data
mod = (form.used_po2.data - (form.o2_target.data / 100)) / (form.o2_target.data / 1000)

return render_template('co2_result.html', pressure_after=pressure_after, o2_percentage=o2_percentage, mod=mod)

return render_template('form.html', form=form)
@app.route('/feedback', methods=['GET', 'POST'])
def feedback():
form = FeedbackForm()
Expand Down
102 changes: 102 additions & 0 deletions kubernetes/flask.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
apiVersion: v1
kind: Namespace
metadata:
name: miksalotti
---
apiVersion: v1
kind: Service
metadata:
name: flask
namespace: miksalotti
labels:
app: flask
spec:
type: NodePort
ports:
- port: 80
nodePort: 30781
selector:
app: flask
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: flask-set
namespace: miksalotti
spec:
selector:
matchLabels:
app: flask
serviceName: flask
replicas: 1
updateStrategy:
type: RollingUpdate
# rollingUpdate:
# maxUnavailable: 0
# maxSurge: 1
template:
metadata:
namespace: miksalotti
labels:
app: flask
spec:
imagePullSecrets:
- name: regcred
containers:
- image: ghcr.io/ardcoras/miksalotti:master
name: flask
imagePullPolicy: Always
ports:
- containerPort: 30781
name: flask
env:
# - name: SMTP_HOST
# value: 'mail.ardcoras.fi'
# - name: SMTP_USER
# valueFrom:
# secretKeyRef:
# name: smtp
# key: user
# - name: SMTP_PASSWORD
# valueFrom:
# secretKeyRef:
# name: smtp
# key: password
- name: SECRET_KEY
value: ''
# valueFrom:
# secretKeyRef:
# name: hash-salt
# key: hash_salt
readinessProbe:
initialDelaySeconds: 1
periodSeconds: 15
timeoutSeconds: 5
successThreshold: 2
failureThreshold: 2
httpGet:
host:
scheme: HTTP
path: /
httpHeaders:
- name: Host
value: miksalotti.ardcoras.fi
port: 80
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: flask-route
namespace: miksalotti
spec:
entryPoints:
- websecure
- web
routes:
- match: Host(`miksalotti.ardcoras.fi`)
kind: Rule
middlewares:
- name: headers-default@file
services:
- name: flask
port: 80

0 comments on commit c3d7a46

Please sign in to comment.