master > master: code py - models + config implementiert

This commit is contained in:
RD
2022-06-10 11:50:59 +02:00
parent 67f6caf2d5
commit 0523c68100
21 changed files with 538 additions and 94 deletions

View File

@@ -0,0 +1,51 @@
# Models #
- In this folder the configuration files for the models of data classes (as `*.yaml`-files) are stored.
- These are interpreted by `openapi` to generate the classes for the source code during the `build` phase of the programme.
- Once the models are generated, the app configurations are read at run time and interpreted as these models.
- Generating instead of manually encoding the classes is safer/more stable as it allows for validation.
## Folder structure ##
As per the 3rd point, the `yaml`-file/s for the models (schemata)
and the `yaml`-file/s for actual configuration values for the app
are to be kept separately.
All models are to be stored in [./models](../models/),
whereas configuration files are to be stored in [./assets](../assets/).
Note that the generated python files are not stored in the repository.
When deployed on a server, these are generated as part of the `build`-process.
## Developer notes ##
### Prerequisites ###
For the python source code, we currently use:
- Python: `v3.10.*`
- Modules:
- `datamodel-code-generator==0.12.0`
(This is all taken care of during the `build` process.)
### Building the models ###
To build the models before run time, use the following command + options:
```bash
datamodel-codegen
--input-file-type openapi
--encoding "UTF-8"
--disable-timestamp
--use-schema-description
--snake-case-field
--strict-nullable
--input <path/to/file.yml>
--output <path/to/file.py>
```
(cf. https://pydantic-docs.helpmanual.io/datamodel_code_generator/).
Alternatively, call:
```
just build
```

View File

@@ -0,0 +1,140 @@
openapi: 3.0.3
info:
version: 0.1.0
title: Schemata for command instructions
servers: []
paths: {}
components:
schemas:
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Commands
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Commands:
description: |-
List of commands to test algorithms/datastructures.
type: array
items:
$ref: "#/components/schemas/Command"
default: []
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Command
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Command:
description: |-
Instructions for command to call
required:
- name
properties: &ref_command_properties
name:
$ref: '#/components/schemas/EnumAlgorithmNames'
additionalProperties: true
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Command - Algorithm: Tarjan
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CommandTarjan:
description: |-
Instructions for execution of Tarjan-Algorithm
type: object
required:
- name
properties:
<<: *ref_command_properties
# required:
# properties:
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Command - Algorithm: TSP
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CommandTsp:
description: |-
Instructions for execution of TSP-Algorithm
type: object
required:
- name
- optimise
- dist
properties:
<<: *ref_command_properties
dist:
type: array
items:
type: array
items:
type: number
optimise:
$ref: '#/components/schemas/EnumTSPOptimise'
verbose:
type: boolean
default: false
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Command - Algorithm: Hirschberg
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CommandHirschberg:
description: |-
Instructions for execution of Hirschberg-Algorithm
type: object
required:
- name
- horizontal
- vertical
properties:
<<: *ref_command_properties
word1:
description: Word that gets placed vertically in algorithm.
type: string
word2:
description: Word that gets placed horizontally in algorithm
type: string
once:
type: boolean
default: false
verbose:
type: array
items:
$ref: '#/components/schemas/EnumHirschbergVerbosity'
default: []
show:
type: array
items:
$ref: '#/components/schemas/EnumHirschbergShow'
default: []
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Enum Algorithm Names
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
EnumAlgorithmNames:
description: |-
Enumeration of possible algorithm options.
type: string
enum:
- TARJAN
- TSP
- HIRSCHBERG
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Enum TSP - Optimise Mode
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
EnumTSPOptimise:
description: |-
Enumeration of optimisation options for TSP
type: string
enum:
- MIN
- MAX
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Enum Hirschberg - Verbosity options
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
EnumHirschbergVerbosity:
description: |-
Enumeration of verbosity options for Hirschberg
type: string
enum:
- COSTS
- MOVES
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Enum Hirschberg - display options
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
EnumHirschbergShow:
description: |-
Enumeration of verbosity options for Hirschberg
type: string
enum:
- TREE
- ATOMS

View File

@@ -0,0 +1,49 @@
openapi: 3.0.3
info:
version: 0.1.0
title: Schemata for config models
servers: []
paths: {}
components:
schemas:
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Config
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Config:
descripton: |-
Data model for all parts of the configuration.
type: object
required:
- info
- options
- calls
properties:
info:
$ref: "#/components/schemas/Info"
options:
$ref: "#/components/schemas/AppOptions"
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Info
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Info:
description: |-
Contains meta data about project.
type: object
required:
- title
- description
- author
properties:
title:
type: string
description:
type: string
author:
type: string
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# App Options
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
AppOptions:
description: |-
Options pertaining to the rudimentary setup of the app.
type: object