Py-Engineering documentation

Welcome to the Py-Engineering documentation. If you're new to these docs, we recommend you to check what Py-Engineering is all about. Watch the introduction movie "How it works" and checkout some examples.
If you think anything is missing or unclear, let us know. Ready to start, but no Py-Engineering account yet? Request a demo!

Content


Calculation


Calculation steps

A calculation will try to run main_function with the provided input in a dictionnary called input_dict. Optionnaly, a validation script can be ran prior to executing the main script. If the script ran succesfully, a pdf document can be created using a LaTeX script.

Step Optional states
Form validation
Before trying to execute any script, a simple form validation checks if all the required fields are filled. For integer and float fields, the min- and max values will alse be checked.
If the validation fails, the user is informed by styling the form. No calculation is started yet and results of this step will not be logged.
If the form validation is passed, the next step will start.
If multiple calculations run at the same time, it is possible that a calculation is queued. The next step will start when other calcualtions are done. Queued
Python validation script (optional)
A more complex valiation can be done with a custom python script.
If the python validation script did not return anything and printed nothing, the next step will start.
Busy validating
Error in python validation script
Failed validation
Python script
If the python validation script did not return anything and printed nothing, the next step will start.
Busy calculating
Error in python script
LaTeX script (optional)
A PDF-file can be created using the results of the python script.
Error in LaTeX script
Finally, if all steps are completed without errors. Done

Input


A calculation comes with a form where the user can provide input according to the input settings. This will result in a python dictionnary that can be used in the python scripts.

Input Types

The type of input defines the form-element that is used and in which type object the input is stored and passed to the python script. Some input types require predefined input. A dropdown for example needs to have a set of option from wich the user can choose.

Input type Form element Python object Required attributes
Integer input (restricted to [-][numbers]) int
Integer (slider) range (step=1) int Min value; Max value
Float input (restricted to [-][numbers][dot or comma][numbers]) float
Float (slider) range (step=0.01) float Min value; Max value
Text input (type: text) str
Radio input (type: radio) [Autodiscover] Predefined input
Boolean input (type: checkbox) bool
Check multiple input (type: checkbox) list Predefined input
Select multiple select (multiple) [Autodiscover] Predefined input
Select (1rst level) select [Autodiscover] Predefined input
Select (2nd level) select [Autodiscover] Predefined input; Select (1rst level)
Select (3rd level) select [Autodiscover] Predefined input; Select (1rst level); Select (2nd level)
Predefined input

For some input types, a selection of options need to be predefined. This is done with a JSON script. The JSON script needs to contain a list of choices. Every choice should have an id, name and optionally another list of choices. The id is passed to the python dictionary if that name is selected. The deepest level does not contain choices, but only id and name. For translation, name_XX can be used with XX being the language code.

Example: JSON object for 1 level predefined input
{
  "choices": [
    {
      "id": "a",
      "name": "Option A"
    },
    {
      "id": "b",
      "name": "Option B"
    },
    {
      "id": "c",
      "name": "Option C"
    },
    {
      "id": "d",
      "name": "Option D"
    }
  ]
}
Example: JSON object for 3 level predefined input and translation
{
  "choices": [
    {
      "id": "a",
      "name": "Main: A",
      "name_nl": "Hoofd: A",
      "choices": [
        {
          "id": "a_1",
          "name": "Second: A1",
          "name_nl": "Tweede: A1",
          "choices": [
            {
              "id": "a_11",
              "name": "Third: A1.1",
              "name_nl": "Derde: A1.1"
            },
            {
              "id": "a_12",
              "name": "Third: A1.2",
              "name_nl": "Derde: A1.2"
            }
          ]
        },
        {
          "id": "a_2",
          "name": "Second: A2",
          "name_nl": "Tweede: A2",
          "choices": [
            {
              "id": "a_21",
              "name": "Third: A2.2",
              "name_nl": "Derde: A2.2"
            },
            {
              "id": "a_22",
              "name": "Third: A2.2",
              "name_nl": "Derde: A2.2"
            }
          ]
        }
      ]
    },
    {
      "id": "b",
      "name": "Main: B",
      "name_nl": "Hoofd: B",
      "choices": [
        {
          "id": "b_1",
          "name": "Second: B1",
          "name_nl": "Tweede: B1",
          "choices": [
            {
              "id": "b_11",
              "name": "Third: B1.1",
              "name_nl": "Derde: B1.1"
            },
            {
              "id": "b_22",
              "name": "Third: B1.2",
              "name_nl": "Derde: B1.2"
            }
          ]
        },
        {
          "id": "b_2",
          "name": "Second: B2",
          "name_nl": "Tweede: B2",
          "choices": [
            {
              "id": "b_21",
              "name": "Third: B2.1",
              "name_nl": "Derde: B2.1"
            },
            {
              "id": "b_22",
              "name": "Third: B2.2",
              "name_nl": "Derde: B2.2"
            }
          ]
        }
      ]
    }
  ]
}
Mathematical operators

Mathematical operators can be assigend to an input field to create an extra dropdown where the user can choose if the value needs to be interpreted as a minimal or maximal value for example. An extra key and value will be added to the dictionnary. The key in this dictionary is the CID of the parameter appended with _operator

Mathematical operator Symbol Value
Less than < lt
Less than or equal le
Equal = equals
Greater than or equal ge
Greater than > gt
Validation

If validation is set in the input settings, the user will be notified if the input is not correct before the calculation will run.

  • Required
  • Minimum value
  • Maximum value

Input Rules

Validation


Input validation

Validtion script

External files


External files can be uploaded in the admin console Caclulator > Upload files. Select your platform and calculation(s) that are aloud to use this file.

Once external files are uploaded, you can add them to your calculation under USE EXTERNAL FILES

In your Python code, the file can be opened like it would be in the same directory as the python script itself. For example:

Example: Python script for reading CSV file
import csv


with open('example_file.csv') as csv_file:
    csv_reader = csv.reader(csv_file, delimiter=',')
    line_count = 0

    for row in csv_reader:
        print(row)
        line_count += 1

Output


All statements printed while executing the python script are treated as output. There are some special tags that you could use to format the output text. Characters as & <, >, " and ' are escaped when formatting the output as HTML. The newline character is not escaped, so to start a new line: print \n. To escape the newline character, print \\n.

Start- and end-tags

There are some tags that translate to specific HTML. Start- and end tags can be used to format text in between te tags. If only a start-tag is used, all the following text will be formatted according to the tag. Likewise, if only an end-tag is used, all the previous output is formatted. Start- and end-tags are written in lowercase within an underscore and an open or close bracket like _tag[

Start tag End tag HTML substitution LaTeX substitution Example
_bold[ or _b[ _bold] or _b] <b> ... </b> \textbf{ ... } _bold[Bold_b]
Bold
_italic[ or _i[ _italic] or _i] <i> ... </i> \textit{ ... } _italic[Italic_i]
Italic
_underline[ or _u[ _underline] or _u] <u> ... </u> \underline{ ... } _underline[Underline_u]
Underline
_superscript[ or _sup[ _superscript] or _sup] <sup> ... </sup> $^{ ... }$ x_sup[2_sup]
x2
_subscript[ or _sub[ _subscript] or _sub] <sub> ... </sub> $_{ ... }$ y_sub[z_sub]
yz
_code_inline[ or _ci[ _code_inline] or _ci] <code> ... </code> \begin{verbatim} ... \end{verbatim} _code_inline[code_inline_ci]
code_inline
_code_block[ or _cb[ _code_block] or _cb] <pre> ... </pre> \begin{verbatim} ... \end{verbatim} _code_block[multiple lines\nof code_cb]
multiple lines
of code
_html_inline[ or _hi[ _html_inline] or _hi] <code> ... </code> ... _html_inline[html_inline_hi]
html_inline

Single line tags

Single line tags are written in lowercase within an underscore and a space like _single_line_tag .... The following line up to a newline character is formatted according to the tag. You can use start- and end-tags within each other and within aa single line tag.

Single line tag HTML substitution Example
_info <p class="text-info my-1"><span class="fa fa-fw fa-info-circle"></span> ...</p> _info Info

Info

_warning <p class="text-warning my-1"><span class="fa fa-fw fa-exlamation-circle"></span> ...</p> _warning Info

Warning

_danger <p class="text-danger my-1"><span class="fa fa-fw fa-times-circle"></span> ...</p> _danger Info

Danger

_success <p class="text-success my-1"><span class="fa fa-fw fa-check-circle"></span> ...</p> _success Info

Success

_header <h6>...</h6> _header Header
Header
_small <small><...</small> _small Small
Small

Show file or image

If your python script creates a file, you can show a download link as ouptut or show a responsive image if the file is an image.

Tag HTML substitution
_img[...] <img src="..." class="img-fluid"><br>
_file_link[...] <a href="...">...</a>

Generate PDF with LaTeX


If a LaTeX script is provided, a PDF will be created after the python function is finished. The PDF can be downloaded or sent by mail.

Tex file from template

You can specify a tex-file as a template in each available language in the admin console. This template can be modified with print statements from your python script. Print statements with _latex tags will be inserted in the .tex file before the PDF is compiled. Use the tag _latex_line or _latex_line99 where 99 is a positive integer.

By using no positive integer, the line will be inserted 1 line above the \begin{document} statement.
Single line tag Example
_latex_line print('_latex_line15', 'Custom text inserted before the \begin{document} statement')
_latex_line print('_latex_line15', 'Custom text inserted in row $15$')
Tex file generated by python script

If your python script generates a .tex file, you can set the name of the file in the admin console and the .tex file will be compiled aftere executing the python code.