Commit 7d117a7c authored by banashree.p's avatar banashree.p

assignment-1(task1,2,3)

parent d182f2d7
# Default ignored files
/shelf/
/workspace.xml
assignment_1
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.9" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/assignment_1.iml" filepath="$PROJECT_DIR$/.idea/assignment_1.iml" />
</modules>
</component>
</project>
\ No newline at end of file
[SERVICE]
port=2747
host=0.0.0.0
version_no=1.0.0
workers=1
module_name=$APP_NAME
enable_traceback = True
secure_cookie=$SECURE_COOKIE
[MONGO_DB]
uri= "mongodb://192.168.0.220:2747/"
\ No newline at end of file
import uvicorn
from scripts.services.task1 import report_router
from fastapi import FastAPI
app = FastAPI()
app.include_router(report_router)
if __name__ == "__main__":
uvicorn.run ("main:app", host="0.0.0.0", port=2747)
\ No newline at end of file
from configparser import ConfigParser
config = ConfigParser()
config.read(f"config/application.conf")
class Configconstant:
temp = config.get("SERVICE", "port")
bana=config.get("MONGO_DB","url")
\ No newline at end of file
import pymongo
import pandas as pd
from pydantic import BaseModel, BaseModel
myclient = pymongo.MongoClient("mongodb://192.168.0.220:2747/")
mydb = myclient["bana"]
dblist = myclient.list_database_names()
if "bana" in dblist:
print("The database exists.")
mycol = mydb["assignment_1"]
mycol.find()
print(mydb.list_collection_names())
class Employee_details(BaseModel):
id: str
certificate_number: int
business_name: str
date: str
result: str
sector: str
address: dict
class Task1:
def mongo(self):
mycol = mydb["assignment_1"]
mycol.find()
temp=list(mycol.aggregate(
[
{
'$project': {
'_id': '$business_name',
'result': 'Violation Issued'
}
}, {
'$group': {
'_id': '$_id',
'highest': {
'$max': '$result'
}
}
}, {
'$sort': {
'highest': -1
}
}
]))
return temp[0] if temp else []
@staticmethod
def get_nvi():
r = mycol.find({"result": "No Violation Issued"})
lst = []
for i in r:
lst.append(i["business_name"])
return lst
def Fnd(self):
q = mycol.find({})
if q:
a = []
for i in q:
d = {'Business Name': i['business_name'], 'Date': i["date"], 'Result': i["result"]}
a.append(d)
a = pd.DataFrame(a)
return (a.to_excel("bana.xlsx", sheet_name="mySheet", index=False))
else:
return "no data"
def Insert (user):
mycol.insert_one(user.dict())
return "inserted"
\ No newline at end of file
from fastapi import APIRouter
from scripts.core.handler.task1 import Task1
report_router = APIRouter()
@report_router.get("/getData1")
def showdata():
return Task1().mongo()
@report_router.get("/getData2")
def showdata2():
return Task1().get_nvi()
@report_router.get('/getData')
def get_data():
return Task1().Fnd()
\ No newline at end of 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