Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
task8-aggregate
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
mohammed.shibili
task8-aggregate
Commits
f0fedd5e
Commit
f0fedd5e
authored
Feb 09, 2023
by
mohammed.shibili
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
loggers added
parent
9d66ddc5
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
22 additions
and
22 deletions
+22
-22
scripts/core/handlers/api_function.py
+1
-0
scripts/database/mongo_db/aggregation.py
+15
-12
scripts/logging/exceptions
+0
-0
scripts/logging/logging.py
+1
-1
scripts/service/ApiCalls.py
+5
-8
temp/data.xlsx
+0
-0
util/mongo_util.py
+0
-1
No files found.
scripts/core/handlers/api_function.py
View file @
f0fedd5e
...
...
@@ -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
):
...
...
scripts/database/mongo_db/aggregation.py
View file @
f0fedd5e
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
...
...
scripts/logging/exceptions
deleted
100644 → 0
View file @
9d66ddc5
scripts/logging/logging.py
View file @
f0fedd5e
...
...
@@ -10,7 +10,7 @@ def get_logger():
file_path
=
"scripts/logging/"
formatter
=
logging
.
Formatter
(
'
%(asctime)
s -
%(levelname)-6
s -
%(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
=
1
000
,
backupCount
=
10
)
temp_handler
.
setFormatter
(
formatter
)
__logger__
.
addHandler
(
temp_handler
)
...
...
scripts/service/ApiCalls.py
View file @
f0fedd5e
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"
temp/data.xlsx
View file @
f0fedd5e
No preview for this file type
util/mongo_util.py
View file @
f0fedd5e
...
...
@@ -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
)
...
...
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