# Spectropy server Fast-Api 8000

### Start container build
```
$env:APP_VERSION = (Get-Content -Raw VERSION).Trim()
docker compose up --build -d
```

Stop:
```
docker compose down
```

## Structure:

- start server - `run_py.py`
- decoder - `ESSSST.py`
- main functional - `main.py`
- tests - `test.py` with testing .csv and .json files

## Docs:
### Data:
`/export-raw-data/` - post req, return raw data without filters or decimation or demodulator
```json
{
  "status": "raw signal",
  "data": signal,
  "path": session_id
}
```

`/export-filter-data/` - post req, return filtered data without decimation

```json
{
  "status": "filtered signal",
  "signal_real": np.array(ch1_complex).real.tolist(), 
  "signal_imag": np.array(ch1_complex).imag.tolist(),
  "time_data_signal":dt.tolist(), 
  "path": session_id
}
```
`/export-decdem-data/` - post req, return decimated and demodulated data

```json
{
  "status": "dec and dem signal",
  "signal_real": np.array(decimated).real.tolist(),
  "signal_imag": np.array(decimated).imag.tolist(),        
  "path": session_id
}
```
### FWHM:

`/export-position-freq/` - found position in decimated signal

```json
{
  "status": "peak position",
  "peak max amplitude in freq": peak_frequency,
  "path": session_id
}
```

`/export-FWHM/` - found width at half height in decimated signal

```json
{
  "status": "FWHM",
  "width at half height": FWHM_normalized,
  "path": session_id
}
```
`/export-max-amplitude-freq/` - found max amplitude frequency in decimated data
```json
{
  "status": "max amplitude freq",
  "max amplitude": max_amplitude,
  "path": session_id
}
```
## Build

in cmd u open directory where file `run_py.py`, make .spec file:

```spec
# -*- mode: python ; coding: utf-8 -*-

a = Analysis(
    ['run_py.py'],
    pathex=[],
    binaries=[],
    datas=[
    ('main.py', '.'),  
    ('state.py', '.')
    ],
    hiddenimports=[
        'fastapi',
        'uvicorn',
        'starlette',
        'pydantic',
        'typing_extensions',
        'anyio',
        'httpx',
        'h11',
        'idna',
        'certifi',
        'urllib3',
        'pandas',
        'scipy',
        'numpy',
        'io',
        'uuid',
        'math',
        'matplotlib',
        'scipy.signal',
        'fastapi.responses',
        'scipy.fft',
        
    ],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    noarchive=False,
    optimize=0,
)

pyz = PYZ(a.pure)

exe = EXE(
    pyz,
    a.scripts,
    a.binaries,
    a.datas,
    [],
    name='run_py',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    upx_exclude=[],
    runtime_tmpdir=None,
    console=True,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
)
```

and write in terminal:

`pyinstaller NAME_SPEC_FILE.spec`
