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
a0eedd26
Commit
a0eedd26
authored
Feb 03, 2023
by
mohammed.shibili
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
corrections done
parent
5f14357e
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
56 additions
and
57 deletions
+56
-57
.idea/sonarlint/issuestore/2/5/2511a7590eb091d560dac1615e6bcef0ceeaffb6
+0
-0
.idea/sonarlint/issuestore/6/e/6e9644ddf83ab52f39902ecdbfdf4118285ac40c
+0
-0
.idea/sonarlint/issuestore/index.pb
+5
-0
app.py
+2
-3
conf/datas.conf
+3
-12
main.py
+11
-0
scripts/config/appconf.py
+1
-3
scripts/config/end_points.py
+0
-11
scripts/constants/const.py
+7
-3
scripts/core/handlers/api_function.py
+8
-8
scripts/database/mongo_db/aggregation.py
+1
-1
scripts/service/ApiCalls.py
+13
-12
temp/data.xlsx
+0
-0
util/mongo_util.py
+5
-4
No files found.
.idea/sonarlint/issuestore/2/5/2511a7590eb091d560dac1615e6bcef0ceeaffb6
0 → 100644
View file @
a0eedd26
.idea/sonarlint/issuestore/6/e/6e9644ddf83ab52f39902ecdbfdf4118285ac40c
0 → 100644
View file @
a0eedd26
.idea/sonarlint/issuestore/index.pb
View file @
a0eedd26
No preview for this file type
app.py
View file @
a0eedd26
import
uvicorn
from
scripts.config.appconf
import
api_port
if
__name__
==
"__main__"
:
uvicorn
.
run
(
"scripts.service.ApiCalls:app"
,
port
=
8000
,
reload
=
True
)
\ No newline at end of file
uvicorn
.
run
(
"main:app"
,
port
=
api_port
)
conf/datas.conf
View file @
a0eedd26
[
mongo
]
server
=
mongodb
://
localhost
:
27017
database
=
aggregation
collection
=
my_table
[
end_points
]
post_insert
=/
insert_data
get_violation
=/
get_violation
get_noViolation
=/
no_violation
get_to_exel
=/
to_exel
exel_file
=/
data
.
xlsx
[
folder_path
]
folder
=
temp
\ No newline at end of file
[
api
]
api_port
=
8000
\ No newline at end of file
main.py
0 → 100644
View file @
a0eedd26
import
uvicorn
from
fastapi
import
FastAPI
from
scripts.config.appconf
import
api_port
from
scripts.service.ApiCalls
import
files
,
extract
app
=
FastAPI
()
app
.
include_router
(
files
)
app
.
include_router
(
extract
)
if
__name__
==
"__main__"
:
uvicorn
.
run
(
app
,
port
=
api_port
)
\ No newline at end of file
scripts/config/appconf.py
View file @
a0eedd26
...
...
@@ -2,5 +2,4 @@ import configparser
config
=
configparser
.
RawConfigParser
()
config
.
read
(
"conf/datas.conf"
)
server_name
=
config
.
get
(
"mongo"
,
"server"
)
db_name
=
config
.
get
(
"mongo"
,
"database"
)
collection_name
=
config
.
get
(
"mongo"
,
"collection"
)
\ No newline at end of file
api_port
=
int
(
config
.
get
(
"api"
,
"api_port"
))
scripts/config/end_points.py
deleted
100644 → 0
View file @
5f14357e
import
configparser
config
=
configparser
.
RawConfigParser
()
config
.
read
(
"conf/datas.conf"
)
post_insert
=
config
.
get
(
"end_points"
,
"post_insert"
)
get_violation
=
config
.
get
(
"end_points"
,
"get_violation"
)
get_noViolation
=
config
.
get
(
"end_points"
,
"get_noViolation"
)
get_to_exel
=
config
.
get
(
"end_points"
,
"get_to_exel"
)
exel_path
=
config
.
get
(
"end_points"
,
"exel_file"
)
# folder
folder_name
=
config
.
get
(
"folder_path"
,
"folder"
)
scripts/constants/const.py
View file @
a0eedd26
class
endpoints
:
@staticmethod
def
api_end
():
class
Endpoints
:
post_insert
=
"/insert_data"
get_violation
=
"/get_violation"
get_noViolation
=
"/no_violation"
get_to_exel
=
"/to_exel"
exel_file
=
"/data.xlsx"
folder
=
"temp"
class
DbDetails
:
db_name
=
"aggregation"
collection_name
=
"my_table"
scripts/core/handlers/api_function.py
View file @
a0eedd26
import
json
import
pandas
as
pd
from
scripts.con
fig.end_points
import
folder_name
,
exel_path
from
scripts.database.mongo_db.aggregation
import
a
ggregation
from
scripts.con
stants.const
import
Endpoints
from
scripts.database.mongo_db.aggregation
import
A
ggregation
from
util.mongo_util
import
mongo_connection
class
operations_on_a
pi
:
class
OperationsOnA
pi
:
def
__init__
(
self
):
self
.
collection_name
=
mongo_connection
()
self
.
data_violation
=
a
ggregation
()
.
data_violation
()
self
.
data_no_violation
=
a
ggregation
()
.
resul_no_violation
()
self
.
data_to_exel
=
a
ggregation
()
.
exel_conversion
()
self
.
data_violation
=
A
ggregation
()
.
data_violation
()
self
.
data_no_violation
=
A
ggregation
()
.
resul_no_violation
()
self
.
data_to_exel
=
A
ggregation
()
.
exel_conversion
()
def
data_insert
(
self
,
file
):
try
:
...
...
@@ -37,7 +37,7 @@ class operations_on_api:
try
:
values
=
list
(
self
.
collection_name
.
aggregate
(
self
.
data_to_exel
))
dataframe
=
pd
.
DataFrame
(
values
)
dataframe
.
to_excel
(
folder_name
+
exel_path
)
return
f
'data inserted to path {
folder_name}{exel_path
}'
dataframe
.
to_excel
(
Endpoints
()
.
folder
+
Endpoints
()
.
exel_file
)
return
f
'data inserted to path {
Endpoints().folder}{Endpoints().exel_file
}'
except
Exception
as
e
:
return
"exel conversion failed"
,
e
scripts/database/mongo_db/aggregation.py
View file @
a0eedd26
class
a
ggregation
:
class
A
ggregation
:
# aggregation for violation issued
@staticmethod
def
data_violation
():
...
...
scripts/service/ApiCalls.py
View file @
a0eedd26
from
fastapi
import
FastAPI
,
UploadFile
from
scripts.co
nfig.end_points
import
post_insert
,
get_violation
,
get_noViolation
,
get_to_exel
from
scripts.co
re.handlers.api_function
import
operations_on_api
from
fastapi
import
APIRouter
,
UploadFile
from
scripts.co
re.handlers.api_function
import
OperationsOnApi
from
scripts.co
nstants.const
import
Endpoints
app
=
FastAPI
()
files
=
APIRouter
()
extract
=
APIRouter
()
# for insert datas in file
@
app.post
(
post_insert
,
tags
=
[
'Aggregation'
])
@
files.post
(
Endpoints
()
.
post_insert
,
tags
=
[
'Aggregation'
])
async
def
post_all
(
file
:
UploadFile
):
operations_on_a
pi
()
.
data_insert
(
await
file
.
read
())
OperationsOnA
pi
()
.
data_insert
(
await
file
.
read
())
return
"data inserted"
# to get business name with maximum violation issued
@
app.get
(
get_violation
,
tags
=
[
'Aggregation'
])
@
extract.get
(
Endpoints
()
.
get_violation
,
tags
=
[
'Aggregation'
])
async
def
get_violation
():
print
(
operations_on_a
pi
()
.
violation_issued
())
print
(
OperationsOnA
pi
()
.
violation_issued
())
return
"data extracted"
# to get business names with no violations
@
app.get
(
get_noViolation
,
tags
=
[
'Aggregation'
])
@
extract.get
(
Endpoints
()
.
get_noViolation
,
tags
=
[
'Aggregation'
])
async
def
get_no_violation
():
print
(
operations_on_a
pi
()
.
no_violation
())
print
(
OperationsOnA
pi
()
.
no_violation
())
return
"values extracted"
# convert to exel file
@
app.get
(
get_to_exel
,
tags
=
[
'Aggregation'
])
@
files.get
(
Endpoints
()
.
get_to_exel
,
tags
=
[
'Aggregation'
])
async
def
convert_exel
():
print
(
operations_on_a
pi
()
.
create_exel_file
())
print
(
OperationsOnA
pi
()
.
create_exel_file
())
return
"exel file created"
temp/data.xlsx
View file @
a0eedd26
No preview for this file type
util/mongo_util.py
View file @
a0eedd26
from
pymongo
import
MongoClient
from
scripts.con
fig.appconf
import
db_name
,
collection_name
,
server_name
from
scripts.config.appconf
import
server_name
from
scripts.con
stants.const
import
DbDetails
# creating mongo connection
def
mongo_connection
():
try
:
client
=
MongoClient
(
server_name
)
database
=
client
[
db_name
]
collection
=
database
[
collection_name
]
database
=
client
[
DbDetails
()
.
db_name
]
collection
=
database
[
DbDetails
()
.
collection_name
]
print
(
"connection success"
)
return
collection
except
Exception
as
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