diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..081a964c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +# Ignore everything +** + +# ... except for dependencies and source +!Pipfile +!Pipfile.lock +!src/ +!.env diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..dd84ea78 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 00000000..3ba13e0c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1 @@ +blank_issues_enabled: false diff --git a/.github/ISSUE_TEMPLATE/doc.md b/.github/ISSUE_TEMPLATE/doc.md new file mode 100644 index 00000000..26865ae0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/doc.md @@ -0,0 +1,8 @@ +--- +name: Doc +about: Documentation needs +title: Documentation +labels: '' +assignees: '' + +--- diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..bbcbbe7d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000..0720d9ee --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,38 @@ +# Description + +Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. + +Fixes # (issue) + +## Type of change + +Please delete options that are not relevant. + +- [ ] Bug fix (non-breaking change which fixes an issue) +- [ ] New feature (non-breaking change which adds functionality) +- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) +- [ ] This change requires a documentation update + +# How Has This Been Tested? + +Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration + +- [ ] Test A +- [ ] Test B + +**Test Configuration**: +* Firmware version: +* Hardware: +* Toolchain: +* SDK: + +# Checklist: + +- [ ] My code follows the style guidelines of this project +- [ ] I have performed a self-review of my own code +- [ ] I have commented my code, particularly in hard-to-understand areas +- [ ] I have made corresponding changes to the documentation +- [ ] My changes generate no new warnings +- [ ] I have added tests that prove my fix is effective or that my feature works +- [ ] New and existing unit tests pass locally with my changes +- [ ] Any dependent changes have been merged and published in downstream modules diff --git a/.gitignore b/.gitignore index 2a06dded..f4563aca 100644 --- a/.gitignore +++ b/.gitignore @@ -136,4 +136,4 @@ deploy_rsa deploy_rsa.pub # Kubernetes config -kubeconfig.yaml \ No newline at end of file +kubeconfig.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9e054b3f..c3f60f4c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1 +1,26 @@ -## To implement +repos: +- repo: https://github.com/PyCQA/pylint + rev: v3.0.0a6 + hooks: + - id: pylint + args: [--rcfile=.pylintrc] + +- repo: https://github.com/psf/black + rev: 23.3.0 + hooks: + - id: black + +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + +- repo: local + hooks: + - id: run-unit-tests + name: Run Unit Tests + entry: "docker buildx build -t oxygen-tests -f Dockerfile.tests . --output type=docker --rm" + language: system + pass_filenames: false + types: [python] diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 00000000..f68e19d9 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,2 @@ +[MASTER] +disable=missing-docstring,invalid-name,import-error,broad-except,unused-argument,unused-variable,too-few-public-methods diff --git a/Dockerfile b/Dockerfile index e77045d1..05cf90de 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1 +1,11 @@ -## To implement \ No newline at end of file +FROM python:3.8 + +RUN pip install pipenv + +WORKDIR /usr/src/app + +COPY . . + +RUN pipenv install --dev + +CMD [ "pipenv", "run", "start" ] diff --git a/Dockerfile.tests b/Dockerfile.tests new file mode 100644 index 00000000..dddfab6a --- /dev/null +++ b/Dockerfile.tests @@ -0,0 +1,11 @@ +FROM python:3.8 AS development + +RUN pip install pipenv + +WORKDIR /usr/src/app + +COPY . . + +RUN pipenv install --dev + +CMD ["pytest", "test.py"] diff --git a/Pipfile b/Pipfile index 9ff3d2c5..5ccee965 100644 --- a/Pipfile +++ b/Pipfile @@ -8,11 +8,13 @@ requests = "*" signalrcore = "*" [dev-packages] +pylint = "*" +black = "*" +pre-commit = "*" +pytest = "*" [requires] python_version = "3.8" [scripts] start = "python src/main.py" -test = "# To implement" -lint = "# To implement" diff --git a/README.md b/README.md index acf62cf9..7d07541b 100644 --- a/README.md +++ b/README.md @@ -62,3 +62,11 @@ MIT ## Contact For more information, please feel free to contact the repository owner. + +## Docker + +``` +docker pull python:3.8 +docker build -t oxygen-cs . +docker run -it --rm --name oxygen-cs oxygen-cs +``` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..c6f0b502 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +version: '3.8' +services: + app: + build: . + ports: + - "8000:8000" + networks: + - network + environment: + - PYTHONUNBUFFERED=1 + +networks: + network: + name: postgres_network + external: true diff --git a/src/main.py b/src/main.py index e2b8af16..f1d1eadc 100644 --- a/src/main.py +++ b/src/main.py @@ -1,8 +1,8 @@ -from signalrcore.hub_connection_builder import HubConnectionBuilder import logging -import requests import json import time +from signalrcore.hub_connection_builder import HubConnectionBuilder +import requests class Main: @@ -16,7 +16,7 @@ def __init__(self): self.DATABASE = None # Setup your database here def __del__(self): - if self._hub_connection != None: + if self._hub_connection is not None: self._hub_connection.stop() def setup(self): @@ -49,14 +49,16 @@ def setSensorHub(self): self._hub_connection.on("ReceiveSensorData", self.onSensorDataReceived) self._hub_connection.on_open(lambda: print("||| Connection opened.")) self._hub_connection.on_close(lambda: print("||| Connection closed.")) - self._hub_connection.on_error(lambda data: print(f"||| An exception was thrown closed: {data.error}")) + self._hub_connection.on_error( + lambda data: print(f"||| An exception was thrown closed: {data.error}") + ) def onSensorDataReceived(self, data): try: print(data[0]["date"] + " --> " + data[0]["data"]) date = data[0]["date"] dp = float(data[0]["data"]) - self.send_temperature_to_fastapi(date, dp) + # DNE self.send_temperature_to_fastapi(date, dp) self.analyzeDatapoint(date, dp) except Exception as err: print(err) diff --git a/test/test.py b/test/test.py index 5e05d010..171ecec4 100644 --- a/test/test.py +++ b/test/test.py @@ -1 +1,31 @@ -## To Implement +import unittest +from unittest.mock import MagicMock + + +# The class we want to test +class Calculator: + def add(self, x, y): + return x + y + + +# The unit test class +class TestCalculator(unittest.TestCase): + def test_add(self): + # Create an instance of the Calculator class + calculator = Calculator() + + # Create a mock object for the add method + calculator.add = MagicMock(return_value=10) + + # Call the add method with some values + result = calculator.add(2, 3) + + # Verify that the add method was called with the correct arguments + calculator.add.assert_called_once_with(2, 3) + + # Verify that the result is as expected + self.assertEqual(result, 10) + + +if __name__ == "__main__": + unittest.main()