Commit 4d8a31aa authored by arjun.b's avatar arjun.b

topic updated

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 (MQTT-redis)" 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/MQTT-redis.iml" filepath="$PROJECT_DIR$/.idea/MQTT-redis.iml" />
</modules>
</component>
</project>
\ No newline at end of file
~ python:S1192Ç"`Define a constant instead of duplicating this literal 'failed to receive on socket: %s' 4 times.(³ ªÇüÿÿÿÿ
g python:S1192Ì "ODefine a constant instead of duplicating this literal 'Invalid topic.' 7 times.(¨ÿÀw
q python:S1192Ô "SDefine a constant instead of duplicating this literal 'Invalid QoS level.' 5 times.(œÖ³Àùÿÿÿÿ
M python:S1066Ë "/Merge this if statement with the enclosing one.(™‹“Žùÿÿÿÿ
H python:S1066 "/Merge this if statement with the enclosing one.(–žåä
H python:S1066Î"/Merge this if statement with the enclosing one.(ŽÕêå
H python:S1066½"/Merge this if statement with the enclosing one.(ŽÕêå
m python:S3776½"TRefactor this function to reduce its Cognitive Complexity from 18 to the 15 allowed.(î€Ãê
A python:S108è")Either remove or fill this block of code.(ã‘Û¾
A python:S108û")Either remove or fill this block of code.(ã‘Û¾
o python:S116—"RRename this field "_sockpairW" to match the regular expression ^[_a-z][_a-z0-9]*$.(Èˬ˜ùÿÿÿÿ
o python:S116—"RRename this field "_sockpairR" to match the regular expression ^[_a-z][_a-z0-9]*$.(Èˬ˜ùÿÿÿÿ
m python:S3776í"TRefactor this function to reduce its Cognitive Complexity from 18 to the 15 allowed.(÷¹çÄ
m python:S3776ß"TRefactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.(Ú¹òó
j python:S1134²"LTake the required action to fix the issue indicated by this "FIXME" comment.(ãÕóçùÿÿÿÿ
Q python:S1172Â"3Remove the unused function parameter "max_packets".(ƒþ‡ýÿÿÿÿ
r python:S3776â"TRefactor this function to reduce its Cognitive Complexity from 22 to the 15 allowed.(Õ«¨¢üÿÿÿÿ
r python:S3776£ "TRefactor this function to reduce its Cognitive Complexity from 31 to the 15 allowed.(ðž§óÿÿÿÿÿ
r python:S3776Ð
"TRefactor this function to reduce its Cognitive Complexity from 58 to the 15 allowed.(€¢þÿÿÿÿÿ
q python:S1226‚ "SIntroduce a new variable or use its initial value before reassigning 'max_packets'.(ø–è«ûÿÿÿÿ
Q python:S1172› "3Remove the unused function parameter "max_packets".(Ðø´Åüÿÿÿÿ
Q python:S1172³ "3Remove the unused function parameter "max_packets".(‡‹áøÿÿÿÿ
r python:S3776³ "TRefactor this function to reduce its Cognitive Complexity from 33 to the 15 allowed.(‡‹áøÿÿÿÿ
F python:S1172‰"-Remove the unused function parameter "force".(Ä‚ýÎ
m python:S3776²"TRefactor this function to reduce its Cognitive Complexity from 41 to the 15 allowed.(Þ¿Ëö
m python:S3776˜"TRefactor this function to reduce its Cognitive Complexity from 43 to the 15 allowed.(™Úà
m python:S3776ã"TRefactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.(ÆÍ’¬
e python:S1134»"LTake the required action to fix the issue indicated by this "FIXME" comment.(Ô»¹Ë
r python:S3776Ä"TRefactor this function to reduce its Cognitive Complexity from 17 to the 15 allowed.(…ï×£þÿÿÿÿ
m python:S3776ž"TRefactor this function to reduce its Cognitive Complexity from 31 to the 15 allowed.(†œû—
| python:S1871«"dEither merge this branch with the identical one on line "2729" or change one of the implementations.(г¢
m python:S3776…"TRefactor this function to reduce its Cognitive Complexity from 18 to the 15 allowed.(ÇÒäå
< python:S125ä"Remove this commented out code.(–×Óýÿÿÿÿ
m python:S3776"TRefactor this function to reduce its Cognitive Complexity from 36 to the 15 allowed.(˜Ô—Ê
< python:S125Š"Remove this commented out code.(÷Ö½’øÿÿÿÿ
< python:S125"Remove this commented out code.(÷Ö½’øÿÿÿÿ
r python:S3776û"TRefactor this function to reduce its Cognitive Complexity from 74 to the 15 allowed.(ÆÛ·­üÿÿÿÿ
x python:S117‘"[Rename this local variable "reasonCode" to match the regular expression ^[_a-z][a-z0-9_]*$.(ûˆá¨úÿÿÿÿ
m python:S3776¢"TRefactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.(úߪ¡
e python:S1134¤"LTake the required action to fix the issue indicated by this "FIXME" comment.(©àå©
m python:S3776¬"TRefactor this function to reduce its Cognitive Complexity from 17 to the 15 allowed.(Ýÿ÷
x python:S117Ï"[Rename this local variable "reasonCode" to match the regular expression ^[_a-z][a-z0-9_]*$.(²ÆÉÚøÿÿÿÿ
r python:S3776à"TRefactor this function to reduce its Cognitive Complexity from 21 to the 15 allowed.(õáØ þÿÿÿÿ
s python:S117¾"[Rename this local variable "reasonCode" to match the regular expression ^[_a-z][a-z0-9_]*$.(ƒáÿ
I python:S1481Ï"+Remove the unused local variable "matched".( ùšÊùÿÿÿÿ
r python:S3776Î"TRefactor this function to reduce its Cognitive Complexity from 18 to the 15 allowed.(‡—ƒÃüÿÿÿÿ
m python:S3776ˆ"TRefactor this function to reduce its Cognitive Complexity from 32 to the 15 allowed.(€Õã“
r python:S3776"TRefactor this function to reduce its Cognitive Complexity from 21 to the 15 allowed.(¨¤×Áøÿÿÿÿ
\ No newline at end of file
‹ python:S1192¶"mDefine a constant instead of duplicating this literal "``start`` and ``num`` must both be specified" 5 times.(‹«‹Óýÿÿÿÿ
H python:S1066Î"/Merge this if statement with the enclosing one.(ÃúÚ
; python:S125"Remove this commented out code.(¶þäÂýÿÿÿÿ
m python:S107·"PMethod "acl_setuser" has 15 parameters, which is greater than the 13 authorized.( Ðàþüÿÿÿÿ
r python:S3776¶"TRefactor this function to reduce its Cognitive Complexity from 64 to the 15 allowed.(å ¨¿úÿÿÿÿ
r python:S3776‹"TRefactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.(Þ¾«™ýÿÿÿÿ
m python:S3776«"TRefactor this function to reduce its Cognitive Complexity from 22 to the 15 allowed.(ʹå
r python:S3776"TRefactor this function to reduce its Cognitive Complexity from 22 to the 15 allowed.(¨ªý©øÿÿÿÿ
r python:S3776ô"TRefactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.(€¬Óàýÿÿÿÿ
r python:S3776Ü"TRefactor this function to reduce its Cognitive Complexity from 19 to the 15 allowed.(¾çôüÿÿÿÿ
r python:S3776¬"TRefactor this function to reduce its Cognitive Complexity from 17 to the 15 allowed.(Ü´·¬ùÿÿÿÿ
- python:S1700û&"Rename field "script"(žÀª'
m python:S3776Ö*"TRefactor this function to reduce its Cognitive Complexity from 21 to the 15 allowed.(™àæ´
k python:S107…+"NMethod "geosearch" has 14 parameters, which is greater than the 13 authorized.( Ðàþüÿÿÿÿ
m python:S3776û+"TRefactor this function to reduce its Cognitive Complexity from 34 to the 15 allowed.(ÔìŒ
- python:S1700Œ-"Rename field "script"(žÀª'
\ No newline at end of file
]
-venv/Lib/site-packages/redis/commands/core.py,b\2\b204d4ef36aacc8a61785673cf411a6f8cea4c84
Z
*venv/Lib/site-packages/paho/mqtt/client.py,4\8\48884692210df18efbccf5a8ef04328b95bf40af
\ 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 as uvicorn
from scripts.config.application_config import server_path, port_no
if __name__ == "__main__":
try:
uvicorn.run(server_path, port=int(port_no), reload=True)
except Exception as e:
print(str(e))
[server]
server_path=scripts.services.publisher:app
port_no=8000
[MQTT_connect]
host=192.168.0.220
port=1883
topic=hospital/patients
[redis_connect]
host=127.0.0.1
port=6379
[logging]
file_name=scripts/external/logging_log
\ No newline at end of file
import configparser
try:
config = configparser.ConfigParser()
config.read(r'E:\MQTT-redis\conf\application.conf')
# server details
server_path = config.get("server", "server_path")
port_no = config.get("server", "port_no")
# mqtt
hostname = config.get("MQTT_connect", "host")
port_num = config.get("MQTT_connect", "port")
topic_name = config.get("MQTT_connect", "topic")
# redis
redis_host = config.get("redis_connect", "host")
redis_port = config.get("redis_connect", "port")
file_name = config.get("logging", "file_name")
except configparser.NoOptionError:
print("could not ")
import redis
from scripts.config.application_config import redis_host, redis_port
from scripts.logging.logging import logger
try:
# Connect to Redis
r = redis.Redis(host=redis_host, port=int(redis_port), db=1)
except Exception as e:
logger.error(f'cant connect to redis {e}')
print(str(e))
class EndPoints:
root = "/"
publish = "/publish"
import json
from paho.mqtt import client as mqtt_client
from scripts.config.application_config import hostname, port_num
from scripts.config.redis_connection import r
from scripts.core.handlers.get_next_doctor import get_next_doctor
from scripts.logging.logging import logger
broker = hostname
port = int(port_num)
client = mqtt_client.Client()
client.connect(broker, port, 60)
def assign_patient(patient, doctors):
try:
# Get the next doctor for the patient
next_doctor = get_next_doctor(doctors)
# Check if the patient has an assigned doctor
if r.hexists(patient['patient_id'], 'doctor'):
# Get the assigned doctor for the patient
assigned_doctor = r.hget(patient['patient_id'], 'doctor').decode('utf-8')
# Check if the assigned doctor is still on duty
if assigned_doctor in doctors:
# Assign the patient to the same doctor
next_doctor = assigned_doctor
# Assign the patient to the next doctor
patient.update({"doctor": next_doctor})
r.hset(patient['patient_id'], 'doctor', next_doctor)
topic = f"hospital/{next_doctor}"
client.publish(topic, json.dumps(patient))
except Exception as e:
logger.error(f"could not assign patient: {e}")
from scripts.config.redis_connection import r
from scripts.logging.logging import logger
def get_next_doctor(doctors):
try:
# Get the current doctor index from Redis
current_doctor = int(r.get('current_doctor') or 0)
# Update the current doctor index in Redis
r.set('current_doctor', (current_doctor + 1) % len(doctors))
# Return the next doctor
return doctors[current_doctor]
except Exception as e:
logger.error(f'cant find next doctor:{e}')
from scripts.core.handlers.assign_patient import assign_patient
from scripts.logging.logging import logger
class PublishHandler:
@staticmethod
def main_handler(details):
try:
doctors = ['Dr. Smith', 'Dr. Johnson', 'Dr. Brown', "Dr. Arjun B"]
patient_details = {
"patient_id": details.id,
"description": details.description,
"age": details.age,
"name": details.name
}
assign_patient(patient_details, doctors)
except Exception as e:
logger.error(f"cant get patients details :{e}")
import logging
import os
from logging.handlers import RotatingFileHandler
from scripts.config.application_config import file_name
def get_logger():
"""
Creates a rotating log
"""
__logger__ = logging.getLogger('')
__logger__.setLevel("ERROR")
log_formatter = '%(asctime)s - %(levelname)-6s - [%(threadName)5s:%(funcName)5s():%(lineno)s] - %(message)s'
time_format = "%Y-%m-%d %H:%M:%S"
formatter = logging.Formatter(log_formatter, time_format)
log_file = os.path.join(f"{file_name}_ERROR.log")
temp_handler = RotatingFileHandler(log_file,
maxBytes=100000000,
backupCount=5)
temp_handler.setFormatter(formatter)
__logger__.addHandler(temp_handler)
return __logger__
logger = get_logger()
from pydantic import BaseModel
class patients(BaseModel):
id: int
description: str
age: int
name: str
from fastapi import FastAPI
from scripts.core.handlers.publisher_handler import PublishHandler
from scripts.logging.logging import logger
from scripts.model.patients import patients
from scripts.constants.end_points import EndPoints
app = FastAPI()
@app.get(EndPoints.root, tags=["root"])
def root():
return {"data": "mqtt-redis publish"}
@app.post(EndPoints.publish, tags=["assign doctor and publish"])
def publish_data(details: patients):
try:
PublishHandler.main_handler(details)
except Exception as e:
logger.error(f'assign a doctor and publishing the details failed: {e}')
return {"data": "data published"}
[
{
"patient_id": "101",
"description": "fever",
"age": 23,
"name": "Raju"
},
{
"patient_id": "102",
"description": "headache",
"age": 32,
"name": "John"
},
{
"patient_id": "103",
"description": "back pain",
"age": 45,
"name": "Jane"
},
{
"patient_id": "104",
"description": "allergies",
"age": 26,
"name": "Emma"
},
{
"patient_id": "105",
"description": "stomach ache",
"age": 18,
"name": "Sam"
}
]
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