Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Mongo-Aggregations
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
arjun.b
Mongo-Aggregations
Commits
7774619a
Commit
7774619a
authored
Feb 02, 2023
by
arjun.b
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MongoDB task based on Aggregation
file upload api added
parent
db1764cc
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
29 deletions
+28
-29
.idea/sonarlint/issuestore/index.pb
+12
-0
scripts/services/main.py
+16
-29
temp/excel_data.xlsx
+0
-0
No files found.
.idea/sonarlint/issuestore/index.pb
View file @
7774619a
No preview for this file type
scripts/services/main.py
View file @
7774619a
import
csv
import
json
import
json
from
fastapi
import
FastAPI
,
UploadFile
from
fastapi
import
FastAPI
,
UploadFile
...
@@ -19,25 +20,12 @@ async def root():
...
@@ -19,25 +20,12 @@ async def root():
return
{
"data"
:
"Mongo aggregation task"
}
return
{
"data"
:
"Mongo aggregation task"
}
# # upload file from user directory
@app.post
(
"/upload"
,
tags
=
[
"upload file"
])
# @app.post("/upload", tags=["file upload"])
async
def
upload_file
(
file
:
UploadFile
):
# async def file_upload(file: UploadFile):
file_content
=
file
.
file
.
read
()
# dataset = file.file.read()
data
=
json
.
loads
(
file_content
.
decode
(
"utf-8"
))
# file_data = dataset.decode()
inspection
.
insert_many
(
data
)
# # print(file_data)
return
{
"data"
:
"CSV data uploaded successfully"
}
# return {"file": file}
# insert json data into database
@app.post
(
"/insert_json"
,
tags
=
[
"insert JSON"
])
async
def
insert_data
():
try
:
with
open
(
file_path
)
as
data
:
file_data
=
json
.
load
(
data
)
inspection
.
insert_many
(
file_data
)
return
{
"data"
:
"JSON data successfully inserted"
}
except
Exception
as
e
:
print
(
str
(
e
))
@app.get
(
"/business_name with max violation issued"
,
tags
=
[
"tasks"
])
@app.get
(
"/business_name with max violation issued"
,
tags
=
[
"tasks"
])
...
@@ -45,25 +33,24 @@ async def max_violation():
...
@@ -45,25 +33,24 @@ async def max_violation():
try
:
try
:
pipeline
=
[
pipeline
=
[
{
{
'$match'
:
{
'result'
:
'Violation issued'
}
},
{
'$group'
:
{
'$group'
:
{
'_id'
:
'$business_name'
,
'_id'
:
'$business_name'
,
'count'
:
{
'count'
:
{
'$sum'
:
1
'$sum'
:
1
}
}
}
}
},
},
{
{
'$sort'
:
{
'$sort'
:
{
'count'
:
-
1
'count'
:
-
1
}
}
},
},
{
{
'$limit'
:
1
'$limit'
:
1
},
},
{
{
'$project'
:
{
'$project'
:
{
'business_name'
:
'$_id'
,
'business_name'
:
'$_id'
,
'_id'
:
0
'_id'
:
0
}
}
...
...
temp/excel_data.xlsx
View file @
7774619a
No preview for this file type
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