Skip to content

Commit

Permalink
stash changes
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoKle committed Sep 30, 2024
1 parent faf5058 commit a436f78
Show file tree
Hide file tree
Showing 22 changed files with 312 additions and 42 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/data-consolidation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# name: databuilder

# on:
# push:
# branches:
# - main

# jobs:
# run-workflow-script:
# runs-on: ubuntu-latest

# steps:
# - name: Checkout main branch
# uses: actions/checkout@v2
# with:
# ref: main

# - name: Set up Python
# uses: actions/setup-python@v2
# with:
# python-version: "3.11.4"

# # - name: Install dependencies # not needed atm as we are not using any requirements apart from default libs
# # run: |
# # python -m pip install --upgrade pip
# # pip install -r requirements.txt

# - name: Run Python script
# run: python src/combine_data.py

# - name: Archive generated files as artifact
# uses: actions/upload-artifact@v4
# with:
# name: generated-files
# path: ./api

# - name: Checkout production branch
# uses: actions/checkout@v2
# with:
# ref: production

# - name: Download generated files artifact
# uses: actions/download-artifact@v4
# with:
# name: generated-files
# path: ./api

# - name: Apply changes to production branch
# run: |
# git config --local user.email "[email protected]"
# git config --local user.name "GitHub Action"
# git add .
# git diff-index --quiet HEAD || (git commit -a -m "Add generated files from main branch" --allow-empty && git push origin production)
24 changes: 24 additions & 0 deletions .github/workflows/data-sorting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# name: data sorter
# run-name: Sorting data on branch ${{github.ref_name}}
# on:
# push:
# branches:
# - "!main"
# - "!production"
# - "*"

# permissions: write-all
# jobs:
# sort-data:
# runs-on: ubuntu-latest
# steps:
# - name: checkout repo content
# uses: actions/checkout@v2

# - name: setup python
# uses: actions/setup-python@v4
# with:
# python-version: "3.11"

# - name: sort data
# run: python src/sort_data.py
24 changes: 24 additions & 0 deletions .github/workflows/data-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# name: data validator
# run-name: Validating data on branch ${{github.ref_name}}
# on:
# push:
# branches:
# - "!main"
# - "!production"
# - "*"

# permissions: write-all
# jobs:
# sort-data:
# runs-on: ubuntu-latest
# steps:
# - name: checkout repo content
# uses: actions/checkout@v2

# - name: setup python
# uses: actions/setup-python@v4
# with:
# python-version: "3.11"

# - name: sort data
# run: python src/validate_data.py
84 changes: 42 additions & 42 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
name: data-sorter
run-name: Push by ${{ github.actor }} is sorting station mappings.json
on:
push:
branches:
- "*"
- "*/**"
- "!main" # Exclude the main branch
permissions: write-all
jobs:
consolidate-and-sort-data:
runs-on: ubuntu-latest
steps:
- name: checkout repo content
uses: actions/checkout@v2 # checkout the repository content
# name: data-sorter
# run-name: Push by ${{ github.actor }} is sorting station mappings.json
# on:
# push:
# branches:
# - "*"
# - "*/**"
# - "!main" # Exclude the main branch
# permissions: write-all
# jobs:
# consolidate-and-sort-data:
# runs-on: ubuntu-latest
# steps:
# - name: checkout repo content
# uses: actions/checkout@v2 # checkout the repository content

- name: setup python
uses: actions/setup-python@v4
with:
python-version: "3.11" # install the python version needed
# - name: setup python
# uses: actions/setup-python@v4
# with:
# python-version: "3.11" # install the python version needed

- name: Check, sort and consolidate data
id: consolidate
working-directory: .
run: python .github/workflows/main.py
# - name: Check, sort and consolidate data
# id: consolidate
# working-directory: .
# run: python .github/workflows/main.py

- name: Check script outcome
run: |
if [ ${{ steps.consolidate.outcome }} != 'success' ]; then
echo "Sorting and consolidation of data failed, data invalid"
exit 1
fi
# - name: Check script outcome
# run: |
# if [ ${{ steps.consolidate.outcome }} != 'success' ]; then
# echo "Sorting and consolidation of data failed, data invalid"
# exit 1
# fi

- if: ${{ steps.consolidate.outcome == 'success' }}
name: commit files
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add -A
git diff-index --quiet HEAD || (git commit -a -m "Consolidated and formatted data" --allow-empty)
# - if: ${{ steps.consolidate.outcome == 'success' }}
# name: commit files
# run: |
# git config --local user.email "[email protected]"
# git config --local user.name "GitHub Action"
# git add -A
# git diff-index --quiet HEAD || (git commit -a -m "Consolidated and formatted data" --allow-empty)

- if: ${{ steps.consolidate.outcome == 'success' }}
name: push changes
uses: ad-m/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
# - if: ${{ steps.consolidate.outcome == 'success' }}
# name: push changes
# uses: ad-m/[email protected]
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# branch: ${{ github.ref }}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"python.analysis.extraPaths": [
"./src"
]
}
13 changes: 13 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run tests",
"type": "shell",
"command": "python3",
"args": [
"src/test_runner.py"
]
}
]
}
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- read data and overwrite data later on, to automatically enforce upper case for all ICAO for ex. or convert str frequencies to float
Empty file added src/__init__.py
Empty file.
1 change: 1 addition & 0 deletions src/sort_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Test sort workflow")
31 changes: 31 additions & 0 deletions src/test_runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import unittest
import os
import sys


def run_tests():
"""
This function runs all unit tests inside of the tests/ directory and its subdirectories.
"""

# Get the absolute path of the directory containing this script
script_dir = os.path.dirname(os.path.abspath(__file__))

# Construct the path to the tests/ directory next to this script
tests_dir = os.path.join(script_dir, "tests")

# Discover and run tests in the tests/ directory and its subdirectories
test_loader = unittest.TestLoader()
test_suite = test_loader.discover(
start_dir=tests_dir, pattern="test_*.py", top_level_dir=script_dir
)
test_runner = unittest.TextTestRunner()
result = test_runner.run(test_suite)

# Explicitly exit with status code based on test result
if not result.wasSuccessful():
sys.exit(1) # Exit with non-zero status code if tests failed


if __name__ == "__main__":
run_tests()
Empty file added src/tests/__init__.py
Empty file.
Empty file.
24 changes: 24 additions & 0 deletions src/tests/validators/test_logon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from unittest import TestCase

from validators.logon import logon_validator


class TestLogonValidator(TestCase):
def test_normal(self):

logon = "EDMM_FUL_CTR"
self.assertEqual(logon.upper(), logon_validator(logon))

logon = "edmm_ful_ctr"
self.assertEqual(logon.upper(), logon_validator(logon))

logon = "EDDL_TWR"
self.assertEqual(logon.upper(), logon_validator(logon))

logon = "eddb_twr"
self.assertEqual(logon.upper(), logon_validator(logon))

def test_exceptions(self):
with self.assertRaises(ValueError):
logon = "EDMM_INVALIDSUFFIX"
logon_validator(logon)
Empty file added src/tests/views/__init__.py
Empty file.
29 changes: 29 additions & 0 deletions src/tests/views/test_icao.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from unittest import TestCase

from pydantic import ValidationError
from views.icao import ICAOModel


class TestICAOType(TestCase):
def test_normal(self):
ICAOModel(icao="EDDB")
ICAOModel(icao="EDDL")
ICAOModel(icao="EDDF")

def test_lowercase(self):
test = ICAOModel(icao="eddl")

self.assertEqual(test.icao, "EDDL")

def test_expections(self):
# ValidationError due to numbers in ICAO
with self.assertRaises(ValidationError):
ICAOModel(icao="1ADW")

# ValidationError due to <4 letters
with self.assertRaises(ValidationError):
ICAOModel(icao="EDD")

# ValidationError due to >4 letters
with self.assertRaises(ValidationError):
ICAOModel(icao="EDDTT")
1 change: 1 addition & 0 deletions src/validate_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Test validate workflow")
Empty file added src/validators/frequency.py
Empty file.
24 changes: 24 additions & 0 deletions src/validators/logon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
LOGON_SUFFIXES = [
"DEL",
"RMP",
"GND",
"TWR",
"DEP",
"APP",
"CTR",
"FSS",
"RDO",
"TMV",
"FMP",
]


def logon_validator(value: str) -> str:
value = value.strip().upper()

parts = value.split("_")

if len(parts) >= 2 and not parts[-1] in LOGON_SUFFIXES:
raise ValueError(f"Suffix {parts[-1]} is not allowed.")

return value
Empty file added src/views/__init__.py
Empty file.
14 changes: 14 additions & 0 deletions src/views/icao.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pydantic import BaseModel, Field, field_validator


class ICAOModel(BaseModel):
icao: str = Field(
...,
pattern=r"^[A-Za-z]{4}$",
description="Must be a string of exactly 4 letters.",
)

@field_validator("icao")
@classmethod
def validate_icao(cls, value: str) -> str:
return value.strip().upper()
4 changes: 4 additions & 0 deletions src/views/schedules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from typing import Literal


ScheduleType = Literal["EDGG", "EDMM", "EDWW"]
22 changes: 22 additions & 0 deletions src/views/station.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from typing import List, Literal, Optional
from pydantic import BaseModel, field_validator

from validators.logon import logon_validator
from views.schedules import ScheduleType


class Station(BaseModel):
logon: str
frequency: float
abbreviation: str
description: Optional[str]
schedule_show_always: Optional[ScheduleType]
schedule_show_booked: Optional[ScheduleType]
relevant_airports: List[str]
gcap_status: Optional[Literal["AFIS", "1", "2"]]
s1_twr: Optional[bool]

@field_validator("logon")
@classmethod
def validate_logon(cls, value: str) -> str:
return logon_validator(value)

0 comments on commit a436f78

Please sign in to comment.