Skip to content

Commit

Permalink
Add logging to db json
Browse files Browse the repository at this point in the history
  • Loading branch information
David2261 committed Oct 30, 2023
1 parent a915866 commit a5e9c15
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 21 deletions.
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
8 changes: 4 additions & 4 deletions RFTCS/rocket_flight_trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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'")
Expand Down

0 comments on commit a5e9c15

Please sign in to comment.