Commit a8c202de by mohammed.shibili

final commit

parents
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="N801" />
</list>
</option>
</inspection_tool>
</profile>
</component>
\ 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 (advanced_mongo)" 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/advanced_mongo.iml" filepath="$PROJECT_DIR$/.idea/advanced_mongo.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
import uvicorn
if __name__ == "__main__":
uvicorn.run("scripts.service.main:app", port=8000, reload=True)
\ No newline at end of file
[mongo]
server=mongodb://localhost:27017
database =aggregation
collection =my_table
\ No newline at end of file
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
import pandas as pd
import tkinter as tk
from tkinter import filedialog
# reading csv
def data_upload():
# section for file upload
try:
print("upload json file")
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename()
dataset = pd.read_json(file_path)
dict_dataset = dataset.to_dict(orient='records')
return dict_dataset
except Exception as e:
print("reading error", e)
from fastapi import FastAPI
import pandas as pd
from scripts.core.handlers.file_upload import data_upload
from util.mongo_util import mongo_connection
app = FastAPI()
@app.post("/insert_data", tags=['FIRST'])
async def post_all():
try:
collection_name.insert_many(dict_from_file)
return "data inserted"
except Exception as e:
print("data insertion error", e)
@app.get("/get_violation", tags=['FIRST'])
async def get_violation():
try:
data = [
{
'$match': {
'result': 'Violation Issued'
}
}, {
'$group': {
'_id': '$business_name',
'count': {
'$sum': 1
}
}
}, {
'$sort': {
'count': -1
}
}, {
'$limit': 1
}, {
'$project': {
'business_name': '$_id',
'_id': 0
}
}
]
violation = next(collection_name.aggregate(data))
print(violation)
return violation
except Exception as e:
print("error while getting no:of violations", e)
@app.get("/no_violation")
async def get_no_violation():
try:
data = [
{
'$match': {
'result': 'No Violation Issued'
}
}, {
'$group': {
'_id': '$business_name'
}
}, {
'$project': {
'business_name': '$_id',
'_id': 0
}
}
]
no_violation = list(collection_name.aggregate(data))
print(no_violation)
return no_violation
except Exception as e:
print("error in fetching no violation", e)
@app.get("/to_exel", tags=['FIRST'])
async def convert_exel():
data = [
{
'$project': {
'business_name': '$business_name',
'date': '$date',
'result': '$result',
'_id': 0
}
}
]
values = collection_name.aggregate(data)
list_data = []
for data in values:
list_data.append(data)
dataframe = pd.DataFrame(list_data)
dataframe.to_excel("temp/data.xlsx")
collection_name = mongo_connection()
dict_from_file = data_upload()
File added
from pymongo import MongoClient
from scripts.config.appconf import db_name, collection_name, server_name
def mongo_connection():
try:
client = MongoClient(server_name)
database = client[db_name]
collection = database[collection_name]
print("connection success")
return collection
except Exception as e:
print("db connection failed", e)
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