Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poetry, period specific mappings, and OO refactor #71

Merged
merged 28 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @ONSdigital/DFTS
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.6.5
1.0.0
9 changes: 7 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
FROM europe-west2-docker.pkg.dev/ons-sdx-ci/sdx-apps/sdx-gcp:1.4.4
FROM europe-west2-docker.pkg.dev/ons-sdx-ci/sdx-apps/sdx-gcp:1.4.5

COPY . /app
WORKDIR /app

# Export dependencies to requirements.txt and install them
RUN poetry export -f requirements.txt --output requirements.txt
RUN pip install -r requirements.txt

EXPOSE 5000
CMD ["python", "./run.py"]
CMD ["python", "./run.py"]
10 changes: 3 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ SHELL := bash

.PHONY: test
test:
. venv/bin/activate \
&& python3 --version \
&& python3 -m pip install --upgrade pip \
&& pip install -r requirements.txt \
&& pip install -r test-requirements.txt \
&& flake8 . --count --statistics \
&& pytest -v --cov-report term-missing --disable-warnings --cov=app tests/
poetry install \
&& poetry run flake8 . --count --statistics \
&& poetry run pytest -v --cov-report term-missing --disable-warnings --cov=app tests/
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,43 @@
# SDX-Transformer

The sdx-transformer service provides data transformation functionality for SDX. It is used to transform both survey submission data into pck files on the journey downstream, and for transforming the data headed upstream for pre-population.
The sdx-transformer service provides data transformation functionality for SDX.
It is used to transform both survey submission data into pck files on the journey downstream, and for transforming the data headed upstream for pre-population.

## Getting Started

### 1. Install Poetry:
- This project uses Poetry for dependency management. Ensure Poetry is installed on your system.
- If you have poetry installed, you can skip this step.
- If Poetry is not installed, you can install it using:
```bash
brew install poetry
```
or
```bash
brew install pipx
pipx install poetry
```
- Use the official Poetry installation guide for other installation methods: https://python-poetry.org/docs/#installation
- Verify the installation by using the following command:
```bash
poetry --version
```

### 2. Install Dependencies:
- Install the project dependencies using Poetry by running the following command at the project root:
```bash
poetry install
```
This will create a new virtual environment if one does not already exist and install the dependencies into it.

### 3. Run the tests:
- To run all the tests, use the following command or use the Makefile:
```bash
poetry run pytest -v --cov-report term-missing --disable-warnings --cov=app tests/
```

### 4. Run the transformer:
- To run the transformer, use the following command:
```bash
poetry run python run.py
```
210 changes: 210 additions & 0 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
openapi: 3.0.3
info:
title: SDX Transformer API
version: 1.0.0
description: API for processing PCK and Prepop requests
paths:
/pck:
post:
summary: Process PCK request
description: "Convert a survey response into a PCK file"
operationId: processPck
requestBody:
required: true
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/ListCollector'
- $ref: '#/components/schemas/Data'
parameters:
- name: survey_id
description: "The id of the survey"
example: "009"
in: query
required: true
schema:
type: string
- name: period_id
description: "The period of the collection exercise"
example: "202501"
in: query
required: true
schema:
type: string
- name: ru_ref
description: "The reference of the respondent"
example: "12345678901A"
in: query
required: true
schema:
type: string
- name: form_type
description: "The form type"
example: "0001"
in: query
required: true
schema:
type: string
- name: period_start_date
description: "The start date of the period in iso 8601 format (YYY-MM-DD)"
example: "2025-01-01"
in: query
required: true
schema:
type: string
- name: period_end_date
description: "The end date of the period in iso 8601 format (YYY-MM-DD)"
example: "2025-01-31"
in: query
required: true
schema:
type: string
- name: data_version
description: The version of schema of the data.
example: "0.0.3"
in: query
required: false
schema:
type: string
default: "0.0.1"
responses:
'200':
description: Successful response
content:
text/plain:
schema:
oneOf:
- type: string
- $ref: '#/components/schemas/SPP'
'400':
description: Bad request
'500':
description: Internal server error
/prepop:
post:
summary: Process Prepop request
description: "Convert prepopulated data into a supplementary data file"
operationId: processPrepop
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/PrepopData'
parameters:
- name: survey_id
description: "The id of the survey"
example: "071"
in: query
required: true
schema:
type: string
responses:
'200':
description: Successful response
content:
application/json:
schema:
type: object
'400':
description: Bad request
'500':
description: Internal server error
components:
schemas:
Data:
type: object
PrepopData:
type: object
additionalProperties:
type: array
items:
type: object
additionalProperties:
type: string
Answer:
type: object
properties:
answer_id:
type: string
value:
oneOf:
- type: object
- type: array
- type: string
list_item_id:
type: string
nullable: true
SupplementaryDataMapping:
type: object
properties:
identifier:
type: string
list_item_id:
type: string
Group:
type: object
properties:
items:
type: array
items:
type: string
name:
type: string
supplementary_data_mappings:
type: array
items:
$ref: '#/components/schemas/SupplementaryDataMapping'
nullable: true
AnswerCode:
type: object
properties:
answer_id:
type: string
code:
type: string
answer_value:
type: string
nullable: true
ListCollector:
type: object
properties:
answer_codes:
type: array
items:
$ref: '#/components/schemas/AnswerCode'
answers:
type: array
items:
$ref: '#/components/schemas/Answer'
lists:
type: array
items:
$ref: '#/components/schemas/Group'
PCK:
type: string
SPPResponse:
type: object
properties:
questioncode:
type: string
response:
type: string
instance:
type: integer
SPP:
type: object
properties:
formtype:
type: string
reference:
type: string
period:
type: string
survey:
type: string
responses:
type: array
items:
$ref: '#/components/schemas/SPPResponse'
69 changes: 0 additions & 69 deletions app/build_spec.py

This file was deleted.

Loading
Loading