Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit e9aeb6f

Browse files
authored
Merge pull request #30 from mcV3rs/devel
MiASI v.1.2.0
2 parents 51689ed + cb2d649 commit e9aeb6f

File tree

5 files changed

+34
-10
lines changed

5 files changed

+34
-10
lines changed

miasi/ext/admin.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ def index(self):
117117
class FormAdmin(ModelView):
118118
"""Panel administracyjny dla tabeli Form."""
119119
column_list = ("name", "name_human_readable", "description")
120-
form_columns = ("name", "name_human_readable", "input_type", "description", "select_options", "select_values")
120+
form_columns = (
121+
"name", "name_human_readable", "input_type", "description", "unit", "select_options", "select_values")
121122

122123
# Mapowanie nazw kolumn
123124
column_labels = {
@@ -232,7 +233,11 @@ def on_form_prefill(self, form, id):
232233
class EquationAdmin(sqla.ModelView):
233234
"""Panel administracyjny dla tabeli Equation."""
234235
column_list = ("name_human_readable", 'formula', "sex")
235-
form_columns = ['name', 'name_human_readable', 'formula', 'system', 'sex']
236+
form_columns = ['name', 'name_human_readable', 'formula', 'system', 'sex', 'is_internal']
237+
238+
column_formatters = {
239+
'sex': lambda v, c, m, p: '-' if m.sex == 'None' else ('Female' if m.sex == 0 else 'Male')
240+
}
236241

237242
form_extra_fields = {
238243
'system': QuerySelectField(
@@ -248,7 +253,15 @@ class EquationAdmin(sqla.ModelView):
248253
(1, 'Male'),
249254
(0, 'Female')
250255
]
251-
)
256+
),
257+
}
258+
259+
# Konfiguracja pól formularza
260+
form_args = {
261+
'is_internal': {
262+
'label': 'Internal Equation', # Ustawienie etykiety
263+
'description': 'Check, if equation is internal, it won\'t be displayed in user side' # Ustawienie opisu
264+
}
252265
}
253266

254267
def __init__(self, model, session, **kwargs):

miasi/ext/restapi/resources.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,13 @@ def calculate_results(filtered_equations, processed_data):
9999
for equation in filtered_equations:
100100
try:
101101
result = eval(equation.formula, {}, processed_data)
102-
results.append({
103-
"equation_name": equation.name_human_readable,
104-
"result": round(result, 2)
105-
})
102+
103+
if not equation.is_internal:
104+
results.append({
105+
"equation_name": equation.name_human_readable,
106+
"result": round(result, 2)
107+
})
108+
106109
processed_data[equation.name] = round(result, 2)
107110
except Exception as e:
108111
abort(500, f"Error calculating equation {equation.name_human_readable}: {str(e)}")

miasi/ext/webui/templates/system.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h2>{{ system.name_human_readable }}</h2>
1111
{% for form in forms %}
1212
<div class="form-group">
1313
<label for="{{ form.name }}">
14-
{{ form.name_human_readable }}
14+
{{ form.name_human_readable }} {% if form.unit != None %} [{{ form.unit }}] {% endif %}
1515
<span style="color: red;">*</span>
1616
</label>
1717
{% if form.input_type == 'text' %}

miasi/ext/webui/views.py

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def system(system_id):
2323

2424
# Sprawdzenie, czy którykolwiek z pól formularza jest typu select
2525
for form in forms:
26+
print(form.name)
2627
if form.input_type == "select":
2728
form.select_options = form.select_options.split(",")
2829
form.select_values = form.select_values.split(',')

miasi/models.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ class Form(db.Model, SerializerMixin):
7676
description = db.Column(db.Text) # Opis pola formularza
7777
select_options = db.Column(db.Text, nullable=True) # Opcje wyboru dla pól typu "select"
7878
select_values = db.Column(db.Text, nullable=True) # Wartości wyboru dla pól typu "select"
79+
unit = db.Column(db.String(50), nullable=True) # Jednostka miary
7980

8081
system_forms = db.relationship('SystemForm', back_populates='form',
8182
cascade='all, delete-orphan') # Relacja wiele-do-wielu
8283

8384
def __init__(self, name: str, name_human_readable: str, input_type: str, description: str,
84-
select_options: str = None, select_values: str = None):
85+
select_options: str = None, select_values: str = None, unit: str = None):
8586
"""
8687
Konstruktor klasy Form
8788
:param name: Nazwa pola formularza używana w kodzie
@@ -90,13 +91,15 @@ def __init__(self, name: str, name_human_readable: str, input_type: str, descrip
9091
:param description: Opis pola formularza
9192
:param select_options: Opcje wyboru dla pól typu "select"
9293
:param select_values: Wartości wyboru dla pól typu "select"
94+
:param unit: Jednostka miary
9395
"""
9496
self.name = name
9597
self.name_human_readable = name_human_readable
9698
self.input_type = input_type
9799
self.description = description
98100
self.select_options = select_options
99101
self.select_values = select_values
102+
self.unit = unit
100103

101104

102105
class SystemForm(db.Model, SerializerMixin):
@@ -145,24 +148,28 @@ class Equation(db.Model, SerializerMixin):
145148
name_human_readable = db.Column(db.String(512)) # Nazwa równania, używana w interfejsie użytkownika
146149
formula = db.Column(db.Text) # Wyrażenie matematyczne jako string (np. "weight / (height ** 2)")
147150
sex = db.Column(db.Integer, nullable=True) # None - both, 1 - Male, 0 - Female
151+
is_internal = db.Column(db.Boolean, default=False) # Czy równanie jest wewnętrzne
148152

149153
system = db.relationship('System', backref='equations') # Powiązanie z tabelą System
150154

151-
def __init__(self, id_system: int, name: str, name_human_readable: str, formula: str, sex: int = None):
155+
def __init__(self, id_system: int, name: str, name_human_readable: str, formula: str, sex: int = None,
156+
is_internal: bool = False):
152157
"""
153158
Konstruktor klasy Equation
154159
:param id_system: ID systemu
155160
:param name: Nazwa równania, używana w kodzie
156161
:param name_human_readable: Nazwa równania, używana w interfejsie użytkownika
157162
:param formula: Wyrażenie matematyczne jako string (np. "weight / (height ** 2)")
158163
:param sex: Płeć, dla której równanie jest obliczane (None - oba, 1 - mężczyzna, 0 - kobieta)
164+
:param is_internal: Czy równanie jest wewnętrzne
159165
"""
160166

161167
self.id_system = id_system
162168
self.name = name
163169
self.name_human_readable = name_human_readable
164170
self.formula = formula
165171
self.sex = sex
172+
self.is_internal = is_internal
166173

167174

168175
class Knowledge(db.Model, SerializerMixin):

0 commit comments

Comments
 (0)