Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mongo_aggregation_function
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rakesh.pv
mongo_aggregation_function
Commits
4a6a476e
Commit
4a6a476e
authored
Feb 16, 2023
by
rakesh.pv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
completed
parent
c26c5270
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
94 additions
and
77 deletions
+94
-77
app.py
+1
-1
scripts/core/pipelines/all_piplines.py
+88
-0
scripts/routes/routes.py
+5
-76
No files found.
app.py
View file @
4a6a476e
import
uvicorn
try
:
uvicorn
.
run
(
"scripts.services.main:app"
,
reload
=
True
)
uvicorn
.
run
(
"scripts.services.main:app"
)
except
Exception
as
e
:
print
(
str
(
e
))
scripts/core/pipelines/all_piplines.py
0 → 100644
View file @
4a6a476e
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
scripts/routes/routes.py
View file @
4a6a476e
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment