Commit b7b60f96 authored by madhu.tr's avatar madhu.tr

addd

parent 7866f744
......@@ -10,7 +10,7 @@ Datetime,RH,,,Time,Date
3/11/20042:00:00,59.7,,,2:00:00,3/11/2004
3/11/20043:00:00,60.2,,,3:00:00,3/11/2004
3/11/20044:00:00,60.5,,,4:00:00,3/11/2004
3/11/20045:00:00,56.2,,,5:00:00,3/11/2004
3/11/20045:00:00,56.2,,,5:00:00,3/11/20041
3/11/20046:00:00,58.1,,,6:00:00,3/11/2004
3/11/20047:00:00,59.6,,,7:00:00,3/11/2004
3/11/20048:00:00,57.4,,,8:00:00,3/11/2004
......
......@@ -10,3 +10,7 @@ secure_cookie=$SECURE_COOKIE
[MONGO_DB]
uri= "mongodb://192.168.0.220:2747/"
[kairoddb]
kairosdb_server = "http://192.168.0.220:8080"
url='http://192.168.0.220:8080/api/v1/datapoints/query'
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)
import pymongo
import pandas as pd
from pydantic import BaseModel
myclient = pymongo.MongoClient("mongodb://192.168.0.220:2747/")
mydb = myclient["factory"]
mycol = mydb["status"]
mycol.find()
class Employee_details(BaseModel):
id: str
certificate_number: int
business_name: str
date: str
result: str
sector: str
address: dict
# #
dblist = myclient.list_database_names()
if "factory" in dblist:
print("The database exists.")
class Task1:
def read_violation(self):
agg = list(mycol.aggregate(
[
{
'$project': {
'_id': '$business_name',
'result': 'Violation Issued'
}
}, {
'$group': {
'_id': '$_id',
'heghest': {
'$max': '$result'
}
}
}, {
'$sort': {
'highest': -1
}
}
]))
return (agg[0])
def read_noviolation(self):
r = mycol.find({"result": "No Violation Issued"})
lst = []
for i in r:
lst.append(i["business_name"])
return lst
# class Employee_details(BaseModel):
# )
# id: str
# certificate_number: int
# business_name: str
# date: str
# result: str
# sector: str
# address: dict
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("incpection.xlsx", sheet_name="mySheet", index=False))
else:
return "no data"
def Insert(user):
mycol.insert_one(user.dict())
return "Inserted"
def check_result(business_name, record_type):
x = business_name
y = record_type
cnt = mycol.count_documents({'$and':[{'business_name':x},{'result':y}]})
return str(cnt) +" " +str( y)
\ No newline at end of file
import pandas as pd
import requests
import json
import gzip
import pandas as pd
from datetime import datetime
epoch = datetime.strptime('2004-12-31 1:00:00', '%Y-%m-%d %H:%M:%S').timestamp()
print(epoch)
pd.options.display.max_rows = 99999
df = pd.read_csv("airrrr1-AirQualityUCI-_1_ - Worksheet.csv")
print(df.head(10))
print(df.Datetime)
print(df["Datetime"].values.tolist())
seconds = []
for j in df['Datetime'].values:
seconds.append(int(datetime.strptime(j, "%m/%d/%Y%H:%M:%S").timestamp()) * 1000)
print(seconds)
df['Datetime'] = seconds
print(df['Datetime'])
import openpyxl
kairosdb_server = "http://192.168.0.220:8080"
url='http://192.168.0.220:8080/api/v1/datapoints/query'
# Simple test [without compression]
data = [
{
"name": "Madhu",
"datapoints": df[['Datetime', 'RH']].values.tolist(),
"tags": {"project": "table"}
}
]
response = requests.post(kairosdb_server + "/api/v1/datapoints", json.dumps(data))
print("Simple test [without compression]: \t %d (status code)" % response.status_code)
def minm(query):
if query=="months":
payload = json.dumps({
"metrics": [
{
"tags": {},
"name": "Madhu",
"aggregators": [
{
"name": "min",
"sampling": {
"value": "1",
"unit": "months"
}
}
]
}
],
"plugins": [],
"cache_time": 0,
"start_absolute":1094668200000,
"end_absolute":1126204200000
})
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
return response.json()
def maxm(query):
if query=="months":
payload = json.dumps({
"metrics": [
{
"tags": {},
"name": "Madhu",
"aggregators": [
{
"name": "max",
"sampling": {
"value": "1",
"unit": "months"
}
}
]
}
],
"plugins": [],
"cache_time": 0,
"start_absolute":1094668200000,
"end_absolute":1126204200000
})
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
return response.json()
def avgm(query):
if query=="months":
payload = json.dumps({
"metrics": [
{
"tags": {},
"name": "Madhu",
"aggregators": [
{
"name": "avg",
"sampling": {
"value": "1",
"unit": "months"
}
}
]
}
],
"plugins": [],
"cache_time": 0,
"start_absolute":1094668200000,
"end_absolute":1126204200000
})
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
return response.json()
def monthlyhumiditydata():
hum2= maxm("months")['queries'][0]['results'][0]['values']
hum1= minm("months")['queries'][0]['results'][0]['values']
hum=avgm("months")['queries'][0]['results'][0]['values']
df1=pd.DataFrame(hum2,columns=["Updated_Date","maxm"])
df2=pd.DataFrame(hum1, columns=["Updated_Date", "minm"])
df3=pd.DataFrame(hum, columns=["Updated_Date", "avgm"])
a=pd.merge(df1,df2,on="Updated_Date")
b=pd.merge(a,df3,on="Updated_Date")
b.to_excel("scripts/Data/monthreport.xlsx")
fpath = 'scripts/Data/'
fname = 'monthreport.xlsx'
filepath = fpath + fname
return filepath, fname
\ No newline at end of file
from servicee import monthlyhumiditydata
from fastapi import FastAPI
app = FastAPI()
@app.get("/getData1")
def monthlyhumiditydata1():
fpath,fname =monthlyhumiditydata()
return FileResponse(fpath,media_type='application/octet-stream',filename=fname)
\ No newline at end of file
from scripts.core.handler.task2 import monthlyhumiditydata
from fastapi import FastAPI
app = FastAPI()
from fastapi import APIRouter
from scripts.core.handler import task2
report_router= APIRouter()
@report_router.get("/getdata1")
def monthlyhum():
return task2().monthlyhumiditydata()
@report_router.get("/weektemp_report")
def minimumm():
fpath, fname = monthlyhumiditydata()
return FileResponse(fpath, media_type='application/octet-stream', filename=fname)
@report_router.get("/weektemp_report")
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GitToolBoxProjectSettings">
<option name="commitMessageIssueKeyValidationOverride">
<BoolValueOverride>
<option name="enabled" value="true" />
</BoolValueOverride>
</option>
<option name="commitMessageValidationEnabledOverride">
<BoolValueOverride>
<option name="enabled" value="true" />
</BoolValueOverride>
</option>
</component>
</project>
\ 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.6 (22)" 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/22.iml" filepath="$PROJECT_DIR$/.idea/22.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
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="a25e93a7-5a95-4848-9194-11f5189602bb" name="Changes" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Python Script" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="27VwTxHxJOnIcPzdNVfw433LKEZ" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
</component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="C:\Users\madhu.tr\PycharmProjects\pythonProject\22" />
</key>
</component>
<component name="RunManager" selected="Python.apii">
<configuration name="apii" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="22" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/apii.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="main" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<module name="22" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/main.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="servicee" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="22" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/servicee.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<recent_temporary>
<list>
<item itemvalue="Python.apii" />
<item itemvalue="Python.servicee" />
</list>
</recent_temporary>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="a25e93a7-5a95-4848-9194-11f5189602bb" name="Changes" comment="" />
<created>1649418572998</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1649418572998</updated>
</task>
<task id="LOCAL-00001" summary="task 2">
<created>1649424748160</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1649424748160</updated>
</task>
<option name="localTasksCounter" value="2" />
<servers />
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="task 2" />
<option name="LAST_COMMIT_MESSAGE" value="task 2" />
</component>
</project>
\ No newline at end of file
from starlette.responses import FileResponse
from servicee import monthlyhumiditydata
from fastapi import FastAPI
app = FastAPI()
@app.get("/getData1")
def monthlyhumiditydata1():
fpath,fname =monthlyhumiditydata()
return FileResponse(fpath,media_type='application/octet-stream',filename=fname)
\ No newline at end of file
#main
import pandas as pd
from datetime import datetime
epoch = datetime.strptime('2004-12-31 1:00:00', '%Y-%m-%d %H:%M:%S').timestamp()
print(epoch)
pd.options.display.max_rows = 99999
df = pd.read_csv("airrrr1-AirQualityUCI-_1_ - Worksheet.csv")
print(df.head(10))
print(df.Datetime)
print(df["Datetime"].values.tolist())
seconds = []
for j in df['Datetime'].values:
seconds.append(int(datetime.strptime(j, "%m/%d/%Y%H:%M:%S").timestamp()) * 1000)
print(seconds)
df['Datetime'] = seconds
print(df['Datetime'])
Binary files a/task 2/requirement.txt and /dev/null differ
import pandas as pd
import requests
import json
import gzip
from main import df
import openpyxl
kairosdb_server = "http://192.168.0.220:8080"
url='http://192.168.0.220:8080/api/v1/datapoints/query'
# Simple test [without compression]
data = [
{
"name": "Madhu",
"datapoints": df[['Datetime', 'RH']].values.tolist(),
"tags": {"project": "table"}
}
]
response = requests.post(kairosdb_server + "/api/v1/datapoints", json.dumps(data))
print("Simple test [without compression]: \t %d (status code)" % response.status_code)
def minm(query):
if query=="months":
payload = json.dumps({
"metrics": [
{
"tags": {},
"name": "Madhu",
"aggregators": [
{
"name": "min",
"sampling": {
"value": "1",
"unit": "months"
}
}
]
}
],
"plugins": [],
"cache_time": 0,
"start_absolute":1094668200000,
"end_absolute":1126204200000
})
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
return response.json()
def maxm(query):
if query=="months":
payload = json.dumps({
"metrics": [
{
"tags": {},
"name": "Madhu",
"aggregators": [
{
"name": "max",
"sampling": {
"value": "1",
"unit": "months"
}
}
]
}
],
"plugins": [],
"cache_time": 0,
"start_absolute":1094668200000,
"end_absolute":1126204200000
})
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
return response.json()
def avgm(query):
if query=="months":
payload = json.dumps({
"metrics": [
{
"tags": {},
"name": "Madhu",
"aggregators": [
{
"name": "avg",
"sampling": {
"value": "1",
"unit": "months"
}
}
]
}
],
"plugins": [],
"cache_time": 0,
"start_absolute":1094668200000,
"end_absolute":1126204200000
})
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
return response.json()
def monthlyhumiditydata():
hum2= maxm("months")['queries'][0]['results'][0]['values']
hum1= minm("months")['queries'][0]['results'][0]['values']
hum=avgm("months")['queries'][0]['results'][0]['values']
df1=pd.DataFrame(hum2,columns=["Updated_Date","maxm"])
df2=pd.DataFrame(hum1, columns=["Updated_Date", "minm"])
df3=pd.DataFrame(hum, columns=["Updated_Date", "avgm"])
a=pd.merge(df1,df2,on="Updated_Date")
b=pd.merge(a,df3,on="Updated_Date")
b.to_excel("scripts/Data/monthreport.xlsx")
fpath = 'scripts/Data/'
fname = 'monthreport.xlsx'
filepath = fpath + fname
return filepath, fname
\ 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