From 5a7dd8ab10ecbe5802820df7f5edae9b143b4b9a Mon Sep 17 00:00:00 2001 From: "michel.sialer-cruz.1@ens.etsmtl.ca" Date: Fri, 9 Jun 2023 09:30:20 -0400 Subject: [PATCH 01/11] github templates --- .github/ISSUE_TEMPLATE/bug_report.md | 38 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/config.yml | 1 + .github/ISSUE_TEMPLATE/doc.md | 10 ++++++ .github/ISSUE_TEMPLATE/feature_request.md | 20 ++++++++++++ .github/pull_request_template.md | 38 +++++++++++++++++++++++ 5 files changed, 107 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/doc.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/pull_request_template.md 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..4223b840 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/doc.md @@ -0,0 +1,10 @@ +--- +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 From dfa6d79e7a3239575f3befd0e31d0320d1e50f9e Mon Sep 17 00:00:00 2001 From: "michel.sialer-cruz.1@ens.etsmtl.ca" Date: Fri, 9 Jun 2023 10:37:18 -0400 Subject: [PATCH 02/11] run oxygen-cs in docker --- Dockerfile | 12 +++++++++++- README.md | 8 ++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e77045d1..9f463e7c 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 + +CMD [ "pipenv", "run", "start" ] \ No newline at end of file diff --git a/README.md b/README.md index acf62cf9..54d19a41 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 +``` \ No newline at end of file From e775d7b31be789b8880af93a32dd83cbea972171 Mon Sep 17 00:00:00 2001 From: "michel.sialer-cruz.1@ens.etsmtl.ca" Date: Fri, 9 Jun 2023 10:49:04 -0400 Subject: [PATCH 03/11] minimize size of image with .dockerignore --- .dockerignore | 7 +++++++ src/main.py | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..7ff8cf74 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +# Ignore everything +** + +# ... except for dependencies and source +!Pipfile +!Pipfile.lock +!src/ \ No newline at end of file diff --git a/src/main.py b/src/main.py index e2b8af16..a12e9ea5 100644 --- a/src/main.py +++ b/src/main.py @@ -82,5 +82,9 @@ def send_event_to_database(self, timestamp, event): if __name__ == "__main__": - main = Main() - main.start() + # main = Main() + # main.start() + + while True: + print("test") + time.sleep(1) \ No newline at end of file From 43165f3c42319d0f870fc7d2bbdffe9c87e4fcd1 Mon Sep 17 00:00:00 2001 From: "michel.sialer-cruz.1@ens.etsmtl.ca" Date: Thu, 29 Jun 2023 08:44:32 -0400 Subject: [PATCH 04/11] removing while --- src/main.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main.py b/src/main.py index a12e9ea5..e8c3fb6a 100644 --- a/src/main.py +++ b/src/main.py @@ -82,9 +82,5 @@ def send_event_to_database(self, timestamp, event): if __name__ == "__main__": - # main = Main() - # main.start() - - while True: - print("test") - time.sleep(1) \ No newline at end of file + main = Main() + main.start() \ No newline at end of file From 248cf4b992fb8ace775d6a6d2d5eb2c9a4cfd1af Mon Sep 17 00:00:00 2001 From: "michel.sialer-cruz.1@ens.etsmtl.ca" Date: Thu, 29 Jun 2023 09:48:57 -0400 Subject: [PATCH 05/11] add docker compose --- docker-compose.yml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..39b7028d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +version: '3.7' +services: + app: + build: . + ports: + - "8000:8000" + volumes: + - ".:/usr/src/app" \ No newline at end of file From 7da3937807c754764f5a704447216f7de1ea2301 Mon Sep 17 00:00:00 2001 From: Sam Kryszto Date: Mon, 3 Jul 2023 18:28:05 -0400 Subject: [PATCH 06/11] local pre commit and corrections to main --- .dockerignore | 2 +- .github/ISSUE_TEMPLATE/doc.md | 2 -- .gitignore | 2 +- .pre-commit-config.yaml | 18 +++++++++++++++++- .pylintrc | 2 ++ Dockerfile | 4 ++-- Pipfile | 5 +++-- README.md | 2 +- docker-compose.yml | 2 +- src/main.py | 18 +++++++++++------- 10 files changed, 39 insertions(+), 18 deletions(-) create mode 100644 .pylintrc diff --git a/.dockerignore b/.dockerignore index 7ff8cf74..5a7eaa69 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,4 +4,4 @@ # ... except for dependencies and source !Pipfile !Pipfile.lock -!src/ \ No newline at end of file +!src/ diff --git a/.github/ISSUE_TEMPLATE/doc.md b/.github/ISSUE_TEMPLATE/doc.md index 4223b840..26865ae0 100644 --- a/.github/ISSUE_TEMPLATE/doc.md +++ b/.github/ISSUE_TEMPLATE/doc.md @@ -6,5 +6,3 @@ labels: '' assignees: '' --- - - 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..ae9adf76 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1 +1,17 @@ -## 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 diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 00000000..a08cdb4b --- /dev/null +++ b/.pylintrc @@ -0,0 +1,2 @@ +[MASTER] +disable=missing-docstring,invalid-name,import-error,broad-except,unused-argument,unused-variable diff --git a/Dockerfile b/Dockerfile index 9f463e7c..05cf90de 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,6 @@ WORKDIR /usr/src/app COPY . . -RUN pipenv install +RUN pipenv install --dev -CMD [ "pipenv", "run", "start" ] \ No newline at end of file +CMD [ "pipenv", "run", "start" ] diff --git a/Pipfile b/Pipfile index 9ff3d2c5..1fb5d5d3 100644 --- a/Pipfile +++ b/Pipfile @@ -8,11 +8,12 @@ requests = "*" signalrcore = "*" [dev-packages] +pylint = "*" +black = "*" +pre-commit = "*" [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 54d19a41..7d07541b 100644 --- a/README.md +++ b/README.md @@ -69,4 +69,4 @@ For more information, please feel free to contact the repository owner. docker pull python:3.8 docker build -t oxygen-cs . docker run -it --rm --name oxygen-cs oxygen-cs -``` \ No newline at end of file +``` diff --git a/docker-compose.yml b/docker-compose.yml index 39b7028d..8614cce7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,4 +5,4 @@ services: ports: - "8000:8000" volumes: - - ".:/usr/src/app" \ No newline at end of file + - ".:/usr/src/app" diff --git a/src/main.py b/src/main.py index e8c3fb6a..097519e4 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) @@ -82,5 +84,7 @@ def send_event_to_database(self, timestamp, event): if __name__ == "__main__": - main = Main() - main.start() \ No newline at end of file + # main = Main() + # main.start() + while True: + print("s") From 23a0c987c43143d30873458286764a86943d9380 Mon Sep 17 00:00:00 2001 From: Sam Kryszto Date: Mon, 3 Jul 2023 19:44:41 -0400 Subject: [PATCH 07/11] unit tests included to pre hooks --- .pre-commit-config.yaml | 9 +++++++++ .pylintrc | 2 +- Dockerfile.tests | 11 +++++++++++ Pipfile | 1 + docker-compose.yml | 2 +- test/test.py | 32 +++++++++++++++++++++++++++++++- 6 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 Dockerfile.tests diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ae9adf76..c3f60f4c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,3 +15,12 @@ repos: 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 index a08cdb4b..f68e19d9 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,2 +1,2 @@ [MASTER] -disable=missing-docstring,invalid-name,import-error,broad-except,unused-argument,unused-variable +disable=missing-docstring,invalid-name,import-error,broad-except,unused-argument,unused-variable,too-few-public-methods 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 1fb5d5d3..5ccee965 100644 --- a/Pipfile +++ b/Pipfile @@ -11,6 +11,7 @@ signalrcore = "*" pylint = "*" black = "*" pre-commit = "*" +pytest = "*" [requires] python_version = "3.8" diff --git a/docker-compose.yml b/docker-compose.yml index 8614cce7..f9e00bdf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3.7' +version: '3.8' services: app: build: . 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() From 58e14b5338f8a2df790023c9ed4e7c30fcb79b94 Mon Sep 17 00:00:00 2001 From: "michel.sialer-cruz.1@ens.etsmtl.ca" Date: Tue, 4 Jul 2023 08:16:22 -0400 Subject: [PATCH 08/11] using postgres network --- docker-compose.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 39b7028d..c82ad629 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,4 +5,11 @@ services: ports: - "8000:8000" volumes: - - ".:/usr/src/app" \ No newline at end of file + - ".:/usr/src/app" + networks: + - app + +networks: + app: + name: postgres_network + external: true \ No newline at end of file From c413dc81050358cd718affbe535996e7505f5d8a Mon Sep 17 00:00:00 2001 From: "michel.sialer-cruz.1@ens.etsmtl.ca" Date: Tue, 4 Jul 2023 16:56:52 -0400 Subject: [PATCH 09/11] changing name of external network --- docker-compose.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index c82ad629..77ad3cc8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,9 +7,11 @@ services: volumes: - ".:/usr/src/app" networks: - - app + - network + environment: + - PYTHONUNBUFFERED=1 networks: - app: + network: name: postgres_network - external: true \ No newline at end of file + external: true From 1151091dc91d8031833b24998574bcf9fa4e6be0 Mon Sep 17 00:00:00 2001 From: "michel.sialer-cruz.1@ens.etsmtl.ca" Date: Wed, 5 Jul 2023 14:21:36 -0400 Subject: [PATCH 10/11] reducing size container with .dockerignore --- .dockerignore | 5 +++-- docker-compose.yml | 2 -- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.dockerignore b/.dockerignore index 7ff8cf74..fb75a1e4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,7 +1,8 @@ # Ignore everything -** +# ** # ... except for dependencies and source !Pipfile !Pipfile.lock -!src/ \ No newline at end of file +!src/ +!.env diff --git a/docker-compose.yml b/docker-compose.yml index 77ad3cc8..04833674 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,8 +4,6 @@ services: build: . ports: - "8000:8000" - volumes: - - ".:/usr/src/app" networks: - network environment: From e155c0acfb7e9907eda45635ed58c5c950b2b857 Mon Sep 17 00:00:00 2001 From: "michel.sialer-cruz.1@ens.etsmtl.ca" Date: Wed, 5 Jul 2023 14:49:58 -0400 Subject: [PATCH 11/11] ignore all except in .dockerignore --- .dockerignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index fb75a1e4..081a964c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,5 @@ # Ignore everything -# ** +** # ... except for dependencies and source !Pipfile