Commit 4a6a476e by rakesh.pv

completed

parent c26c5270
import uvicorn
try:
uvicorn.run("scripts.services.main:app", reload=True)
uvicorn.run("scripts.services.main:app")
except Exception as e:
print(str(e))
from scripts.services.main import coll
def maximum():
try:
pipeline = [
{
'$group': {
'_id': '$business_name',
'count': {
'$sum': 1
}
}
},
{
'$sort':
{
'count': -1
}
},
{
'$limit': 1
},
{
'$project':
{
'business_name': '$_id',
'_id': 0
}
}
]
result = list(coll.aggregate(pipeline))
print(result)
return {"data": result}
except Exception as e:
print(str(e))
def no_vilation():
try:
pipeline = [
{
'$match': {
'result': 'No violation issued'
}
}, {
'$group': {
'_id': '$business_name'
}
}, {
'$project': {
'business_name': '$_id',
'_id': 0
}
}
]
result = list(coll.aggregate(pipeline))
print(result)
return {"data": result}
except Exception as e:
print(str(e))
def have_violation():
try:
pipeline = [
{
'$match': {
'result': 'Violation issued'
}
}, {
'$group': {
'_id': '$business_name'
}
}, {
'$project': {
'business_name': '$_id',
'_id': 0
}
}
]
result = list(coll.aggregate(pipeline))
print(result)
return {"data": result}
except Exception as e:
print(str(e))
\ No newline at end of file
......@@ -4,6 +4,7 @@ from fastapi import APIRouter
from scripts.config.configurations import path_file
from scripts.core.handlers.json_to_excel import create_excel_file
from scripts.core.pipelines.all_piplines import maximum, no_vilation, have_violation
from scripts.services.main import coll
router=APIRouter()
......@@ -22,90 +23,18 @@ async def insert_data():
@router.get("/max_violation_issued")
async def max_violation():
try:
pipeline = [
{
'$group': {
'_id': '$business_name',
'count': {
'$sum': 1
}
}
},
{
'$sort':
{
'count': -1
}
},
{
'$limit': 1
},
{
'$project':
{
'business_name': '$_id',
'_id': 0
}
}
]
result = list(coll.aggregate(pipeline))
print(result)
return {"data": result}
except Exception as e:
print(str(e))
maximum()
@router.get("/no_violations")
async def no_violation():
try:
pipeline = [
{
'$match': {
'result': 'No violation issued'
}
}, {
'$group': {
'_id': '$business_name'
}
}, {
'$project': {
'business_name': '$_id',
'_id': 0
}
}
]
result = list(coll.aggregate(pipeline))
print(result)
return {"data": result}
except Exception as e:
print(str(e))
no_vilation()
@router.get("/with_violations")
async def with_violation():
try:
pipeline = [
{
'$match': {
'result': 'Violation issued'
}
}, {
'$group': {
'_id': '$business_name'
}
}, {
'$project': {
'business_name': '$_id',
'_id': 0
}
}
]
result = list(coll.aggregate(pipeline))
print(result)
return {"data": result}
except Exception as e:
print(str(e))
have_violation()
# create Excel file
......
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