From 172b28baaac7bcf08ee55b7c1fc7b1e368f3e17c Mon Sep 17 00:00:00 2001 From: David2261 Date: Wed, 26 Jul 2023 19:12:24 +0300 Subject: [PATCH 1/3] Update docs about test --- docs/test.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/test.md b/docs/test.md index d84e43c..12e9c08 100755 --- a/docs/test.md +++ b/docs/test.md @@ -43,7 +43,7 @@ ## Pytest - параметры для терминала -- `--cokkect-only` - показывает какие тесты будут выполняться с заданными параметрами +- `--collect-only` - показывает какие тесты будут выполняться с заданными параметрами - `-k` - позволяет испытать выражения для определения функций тестирования - `-m` - маркеры, самый лучший способ пометить подмножество функций для совместного запуска ```python From a915866b5eb42308e476310a42f91707beea3111 Mon Sep 17 00:00:00 2001 From: David2261 Date: Mon, 7 Aug 2023 19:38:09 +0300 Subject: [PATCH 2/3] Added new API for flight range but with bug --- RFTCS/api.c | 26 +++++++++++++++++++++++++- RFTCS/api.h | 2 +- RFTCS/bind.c | 23 +++++++++++++++++++++++ RFTCS/rocket_flight_trajectory.py | 8 +++++--- RFTCS/setup.py | 3 ++- calculationDB.db | Bin 12288 -> 16384 bytes 6 files changed, 56 insertions(+), 6 deletions(-) diff --git a/RFTCS/api.c b/RFTCS/api.c index 423970c..b6c1e8b 100755 --- a/RFTCS/api.c +++ b/RFTCS/api.c @@ -1,7 +1,7 @@ #include "api.h" -// Api of flight trajectory +// API of flight trajectory static PyObject * ext_double_angle_sine(PyObject *self, PyObject *args) { float das = 0; @@ -9,8 +9,27 @@ static PyObject * ext_double_angle_sine(PyObject *self, PyObject *args) return PyLong_FromLong(api_double_angle_sine(das)); }; + +static PyObject * ext_flight_range(PyObject *self, PyObject *args) +{ + float sine = 0, speed = 0; + if (!PyArg_ParseTuple(args, "ff", &sine, &speed)) return NULL; + return PyLong_FromLong(api_flight_range(sine, speed)); +}; + + +// static struct PyModuleDef module = { +// PyModuleDef_HEAD_INIT, +// "API_FR", +// "API for flight range", +// -1, +// methods +// }; + + static PyMethodDef methods[] = { {"ext_double_angle_sine", ext_double_angle_sine, METH_VARARGS, "ext_double_angle_sine"}, + {"ext_flight_range", ext_flight_range, METH_VARARGS, "ext_flight_range"}, {NULL, NULL, 0, NULL} }; @@ -26,3 +45,8 @@ PyMODINIT_FUNC PyInit_ext_double_angle_sine(void) { return PyModule_Create(&module); } + +PyMODINIT_FUNC +PyInit_ext_flight_range(void) { + return PyModule_Create(&module); +} diff --git a/RFTCS/api.h b/RFTCS/api.h index 4390ef5..1786fcc 100755 --- a/RFTCS/api.h +++ b/RFTCS/api.h @@ -13,7 +13,7 @@ // Extentions static PyObject * ext_double_angle_sine(PyObject *, PyObject *); -// static PyObject * ext_flight_range(PyObject *, PyObject *); +static PyObject * ext_flight_range(PyObject *, PyObject *); // static PyObject * ext_flight_time(PyObject *, PyObject *); #endif diff --git a/RFTCS/bind.c b/RFTCS/bind.c index cb584b5..f4c1dcb 100755 --- a/RFTCS/bind.c +++ b/RFTCS/bind.c @@ -31,6 +31,29 @@ static PyModuleDef core_mod = { core_funcs }; +PyMODINIT_FUNC PyInit_core_api(void) { + return PyModule_Create(&core_mod); +} + + +static PyMethodDef core_funcs[] = { + { + "flight_range", + (PyCFunction)ext_flight_range, + METH_VARARGS, + "flight_range" + }, + {NULL, NULL, 0, NULL}, +}; + +static PyModuleDef core_mod = { + PyModuleDef_HEAD_INIT, + "core_api", + "Core Api", + -1, + core_funcs +}; + PyMODINIT_FUNC PyInit_core_api(void) { return PyModule_Create(&core_mod); } \ No newline at end of file diff --git a/RFTCS/rocket_flight_trajectory.py b/RFTCS/rocket_flight_trajectory.py index ec35feb..624acbb 100755 --- a/RFTCS/rocket_flight_trajectory.py +++ b/RFTCS/rocket_flight_trajectory.py @@ -27,7 +27,8 @@ try: from .setup.constant import ACCELERATION_FREE_FALL from .setup.settings import FPV - # import core_api as CA # CPython API + import API_das as CA # CPython API + import API_FR as FR # CPython API except ImportError as e: logger.error(invalid_import(e)) raise ImportError(invalid_import(e)) @@ -48,7 +49,7 @@ def __init__(self, speed): def _double_angle_sine(self): """ Синус двойного угла, градусов """ try: - # res = CA.double_angle_sine() + res = CA.ext_double_angle_sine(self.speed) res = 2 * np.sin(self.speed) * np.cos(self.speed) log_info.info("Запуск функции '_double_angle_sine'") except TypeError as te: @@ -61,7 +62,8 @@ def flight_range(self): try: G = ACCELERATION_FREE_FALL sine = self._double_angle_sine() - res = ((self.speed**2) * sine) / (2 * G) + res = FR.ext_flight_range(self.sine, self.speed) + # res = ((self.speed**2) * sine) / (2 * G) log_info.info("Запуск функции 'flight_range'") except TypeError as te: logger.error(invalid_type(te)) diff --git a/RFTCS/setup.py b/RFTCS/setup.py index ebb8f6e..a48c4f0 100755 --- a/RFTCS/setup.py +++ b/RFTCS/setup.py @@ -7,6 +7,7 @@ description="Extend core on the C code", author="Bulat", ext_modules=[ - Extension("API_das", ["api.c"]) + Extension("API_das", ["api.c"]), + Extension("API_FR", ["api.c"]), ] ) diff --git a/calculationDB.db b/calculationDB.db index 1f6d59221e5b219c80465a4b54ff401685d1aa28..aefc6fc9d8176ec77bd8a38ed61f12551cb0fa04 100644 GIT binary patch delta 279 zcmZojXlP)ZAT7wsz`(!)#4x}#QO8)Al|j#YA}>&gnNN~|-<9t(pXA2E<-B%{;mqvf z%F2vQr6q|;IjO$+DXBSbIhpAhB}hyb=O9 Date: Mon, 30 Oct 2023 22:49:31 +0300 Subject: [PATCH 3/3] Add logging to db json --- RFTCS/dbms/databaseJSON.py | 66 +++++++++++++++++++++++-------- RFTCS/rocket_flight_trajectory.py | 8 ++-- 2 files changed, 53 insertions(+), 21 deletions(-) diff --git a/RFTCS/dbms/databaseJSON.py b/RFTCS/dbms/databaseJSON.py index cfe6ba5..0b3afec 100755 --- a/RFTCS/dbms/databaseJSON.py +++ b/RFTCS/dbms/databaseJSON.py @@ -1,7 +1,26 @@ import json from datetime import datetime import random -from numpyencoder import NumpyEncoder + +import logging +import logging.config + +from RFTCS.setup.logging_conf import LOGGING_CONF + +logging.config.dictConfig(LOGGING_CONF) +logger = logging.getLogger("dev") +log_info = logging.getLogger("root") + +try: + from numpyencoder import NumpyEncoder +except Exception as ex: + logger.error(f"Ошибка с импортированием функкций исключений... {ex}") + print("You may not have connected the numpy library") + +try: + from RFTCS.exceptions.exception import invalid_general +except Exception as ex: + logger.error(f"Ошибка с импортированием функкций исключений... {ex}") class JsonLoad: @@ -63,27 +82,40 @@ def generate_data(self): return json_data def json_entire(self): - with open('record.json', 'r', encoding='utf-8', errors='ignore') as f: - data_file = json.loads(f.read()) + try: + with open( + 'record.json', + 'r', + encoding='utf-8', + errors='ignore') as f: + data_file = json.loads(f.read()) + except Exception as ex: + logger.error(invalid_general(ex)) json_data = self.generate_data() data_file.append(json_data) - with open('record.json', 'w', encoding='utf-8') as file: - json.dump( - data_file, - file, - indent=2, - separators=(', ', ': '), - cls=NumpyEncoder) + try: + with open('record.json', 'w', encoding='utf-8') as file: + json.dump( + data_file, + file, + indent=2, + separators=(', ', ': '), + cls=NumpyEncoder) + except Exception as ex: + logger.error(invalid_general(ex)) def json_generate(self): json_data = self.generate_data() - with open('record.json', 'w', encoding='utf-8') as file: - json.dump( - json_data, - file, - indent=2, - separators=(', ', ': '), - cls=NumpyEncoder) + try: + with open('record.json', 'w', encoding='utf-8') as file: + json.dump( + json_data, + file, + indent=2, + separators=(', ', ': '), + cls=NumpyEncoder) + except Exception as ex: + logger.error(invalid_general(ex)) def json_main(self): try: diff --git a/RFTCS/rocket_flight_trajectory.py b/RFTCS/rocket_flight_trajectory.py index 624acbb..6ab2d1a 100755 --- a/RFTCS/rocket_flight_trajectory.py +++ b/RFTCS/rocket_flight_trajectory.py @@ -27,8 +27,8 @@ try: from .setup.constant import ACCELERATION_FREE_FALL from .setup.settings import FPV - import API_das as CA # CPython API - import API_FR as FR # CPython API + import API_das as CA # CPython API + import API_FR as FR # CPython API except ImportError as e: logger.error(invalid_import(e)) raise ImportError(invalid_import(e)) @@ -60,8 +60,8 @@ def _double_angle_sine(self): def flight_range(self): """ Дальность полета, км """ try: - G = ACCELERATION_FREE_FALL - sine = self._double_angle_sine() + # G = ACCELERATION_FREE_FALL + # sine = self._double_angle_sine() res = FR.ext_flight_range(self.sine, self.speed) # res = ((self.speed**2) * sine) / (2 * G) log_info.info("Запуск функции 'flight_range'")