Skip to content

Commit

Permalink
Merge pull request #98 from David2261/math
Browse files Browse the repository at this point in the history
Add logging to db json
  • Loading branch information
David2261 authored Oct 30, 2023
2 parents 69b8ee3 + a5e9c15 commit d40eb59
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 26 deletions.
26 changes: 25 additions & 1 deletion RFTCS/api.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
#include "api.h"


// Api of flight trajectory
// API of flight trajectory
static PyObject * ext_double_angle_sine(PyObject *self, PyObject *args)
{
float das = 0;
if (!PyArg_ParseTuple(args, "f", &das)) return NULL;
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}
};

Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion RFTCS/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions RFTCS/bind.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
66 changes: 49 additions & 17 deletions RFTCS/dbms/databaseJSON.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 7 additions & 5 deletions RFTCS/rocket_flight_trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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:
Expand All @@ -59,9 +60,10 @@ def _double_angle_sine(self):
def flight_range(self):
""" Дальность полета, км """
try:
G = ACCELERATION_FREE_FALL
sine = self._double_angle_sine()
res = ((self.speed**2) * sine) / (2 * G)
# 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'")
except TypeError as te:
logger.error(invalid_type(te))
Expand Down
3 changes: 2 additions & 1 deletion RFTCS/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]),
]
)
Binary file modified calculationDB.db
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@


## Pytest - параметры для терминала
- `--cokkect-only` - показывает какие тесты будут выполняться с заданными параметрами
- `--collect-only` - показывает какие тесты будут выполняться с заданными параметрами
- `-k` - позволяет испытать выражения для определения функций тестирования
- `-m` - маркеры, самый лучший способ пометить подмножество функций для совместного запуска
```python
Expand Down

0 comments on commit d40eb59

Please sign in to comment.