Commit a5cc28e9 by ajil.k

added

parents
FROM_DATE=2023-01-01 00:00:00.000
TO_DATE=2023-02-07 00:00:00.000
URL=http://192.168.0.220:8080/api/v1/datapoints/query
\ No newline at end of file
# Default ignored files
/shelf/
/workspace.xml
<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>
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredIdentifiers">
<list>
<option value="dict.mobile" />
<option value="dict.dob" />
<option value="dict.gender" />
<option value="dict.name" />
</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"?>
<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
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (kairosdb_task)" 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/kairosdb_task.iml" filepath="$PROJECT_DIR$/.idea/kairosdb_task.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
from script.services.app_call import start_service_on_kairosdb
start_service_on_kairosdb()
from dotenv import load_dotenv
import os
load_dotenv()
from_date = os.getenv("FROM_DATE")
to_date = os.getenv("TO_DATE")
url = os.getenv("URL")
from datetime import datetime
# Convert timestamp into epochs
def convert_timestamp(timestamp):
# Convert the timestamp string into a datetime object
timestamp_dt = datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S.%f")
# Calculate the difference between the timestamp and Unix reference time in seconds
epoch = int(((timestamp_dt - datetime(1970, 1, 1)).total_seconds())*1000)
return epoch
# Convert epochs into timestamp
def convert_epoch(epoch):
# Dividing by 1000 to ignore milliseconds
epoch /= 1000
#
timestamp = datetime.fromtimestamp(epoch).strftime('%Y-%m-%d %H:%M:%S')
return timestamp
from pymongo import MongoClient
from script.constants.app_config import mongodb_uri, project_id, site_id, site_name, line_id, equipment_id
client = MongoClient(mongodb_uri)
database = client['ilens_configuration']
collection = database['tag_hierarchy']
class SendData:
@staticmethod
def extract_data():
try:
tag_hierarchy = collection
query = {
project_id: 1,
site_id: 1,
site_name: 1,
line_id: 1,
equipment_id: 1,
"_id": 0
}
documents = tag_hierarchy.find({}, query)
for document in documents:
print(document)
except Exception as e:
print(e)
import json
import requests
from script.constants.app_config import from_date, to_date, url
from script.core.handlers.convert_time import convert_timestamp, convert_epoch
from script.core.handlers.send_data import SendData
def start_service_on_kairosdb():
try:
start_absolute = convert_timestamp(from_date)
end_absolute = convert_timestamp(to_date)
query_url = url
tags = ["site_114$line_4901$equipment_6054$tag_61534"]
query = {
"metrics": [
{
"tags": {
"c3": tags
},
"name": "ilens.live_data.raw",
"aggregators": [
{
"name": "sum",
"sampling": {
"value": "1",
"unit": "milliseconds"
},
"align_sampling": "true"
}
]
}
],
"plugins": [],
"cache_time": 0,
"time_zone": "Asia/Calcutta",
"start_absolute": start_absolute,
"end_absolute": end_absolute
}
data = json.dumps(query)
response = requests.post(query_url, data=data)
print(response.text)
data = json.dumps(response.text)
timestamp = convert_epoch(1675693206000)
print(timestamp)
except Exception as e:
print("Error -", 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