Commit f0fedd5e by mohammed.shibili

loggers added

parent 9d66ddc5
......@@ -26,6 +26,7 @@ class OperationsOnApi:
violation = next(self.collection_name.aggregate(self.data_violation))
return violation
except Exception as e:
logger.exception(e)
return "error while getting no:of violations", e
def no_violation(self):
......
class Aggregation:
# aggregation for violation issued
@staticmethod
def data_violation():
def __init__(self):
self.project = '$project'
self.business_name = '$business_name'
def data_violation(self):
resul_violation = [
{
'$match': {
......@@ -9,7 +12,7 @@ class Aggregation:
}
}, {
'$group': {
'_id': '$business_name',
'_id': self.business_name,
'count': {
'$sum': 1
}
......@@ -21,7 +24,7 @@ class Aggregation:
}, {
'$limit': 1
}, {
'$project': {
self.project: {
'business_name': '$_id',
'_id': 0
}
......@@ -30,8 +33,8 @@ class Aggregation:
return resul_violation
# aggregation for no violation issued
@staticmethod
def resul_no_violation():
def resul_no_violation(self):
data_no_violation = [
{
'$match': {
......@@ -39,10 +42,10 @@ class Aggregation:
}
}, {
'$group': {
'_id': '$business_name'
'_id': self.business_name
}
}, {
'$project': {
self.project: {
'business_name': '$_id',
'_id': 0
}
......@@ -51,12 +54,12 @@ class Aggregation:
return data_no_violation
# aggregation for convert to exel
@staticmethod
def exel_conversion():
def exel_conversion(self):
data_to_exel = [
{
'$project': {
'business_name': '$business_name',
self.project: {
'business_name': self.business_name,
'date': '$date',
'result': '$result',
'_id': 0
......
......@@ -10,7 +10,7 @@ def get_logger():
file_path = "scripts/logging/"
formatter = logging.Formatter('%(asctime)s - %(levelname)-6s - %(message)s', "%Y-%m-%d %H:%M:%S")
log_file = os.path.join(f"{file_path}exceptions.log")
temp_handler = RotatingFileHandler(log_file, maxBytes=1, backupCount=10)
temp_handler = RotatingFileHandler(log_file, maxBytes=1000, backupCount=10)
temp_handler.setFormatter(formatter)
__logger__.addHandler(temp_handler)
......
from fastapi import APIRouter, UploadFile, Response
from scripts.core.handlers.api_function import OperationsOnApi
from fastapi import APIRouter, UploadFile
from scripts.constants.const import Endpoints
from scripts.core.handlers.api_function import OperationsOnApi
files = APIRouter()
extract = APIRouter()
......@@ -9,15 +9,13 @@ extract = APIRouter()
# for insert datas in file
@files.post(Endpoints().post_insert, tags=['Aggregation'])
async def post_all(file: UploadFile):
OperationsOnApi().data_insert(await file.read())
return "data inserted"
return OperationsOnApi().data_insert(await file.read())
# to get business name with maximum violation issued
@extract.get(Endpoints().get_violation, tags=['Aggregation'])
async def get_violation():
print(OperationsOnApi().violation_issued())
return "data extracted"
return {"Maximum violation": OperationsOnApi().violation_issued()}
# to get business names with no violations
......@@ -31,5 +29,4 @@ async def get_no_violation():
@files.get(Endpoints().get_to_exel, tags=['Aggregation'])
async def convert_exel():
print(OperationsOnApi().create_exel_file())
return Response(content=open(Endpoints().folder + Endpoints().exel_file, "rb").read(),
media_type="application/msexcel")
return "converted to exel"
No preview for this file type
......@@ -10,7 +10,6 @@ def mongo_connection():
client = MongoClient(server_name)
database = client[DbDetails().db_name]
collection = database[DbDetails().collection_name]
print("connection success")
return collection
except Exception as e:
logger.exception(e)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment