├── Main ├── body.csv ├── file.csv ├── sensor_module.py └── server_module.py ├── README.md └── Test ├── test_pipeline_leakage_detection.py └── test_server_module.py /Main/body.csv: -------------------------------------------------------------------------------- 1 | "Dear Sir,",It has come to attention to our monitoring system that a leakage has been detected at system present ,The type of leakage has been found to be ,Kindly bring your attention.,Thanks & Regards 2 | "Dear Sir,",It has come to attention to our monitoring system that an obstacle has been detected at system present ,Kindly bring your attention.,Thanks & Regards 3 | -------------------------------------------------------------------------------- /Main/file.csv: -------------------------------------------------------------------------------- 1 | 1,0 2 | 0,560 3 | -------------------------------------------------------------------------------- /Main/sensor_module.py: -------------------------------------------------------------------------------- 1 | import csv 2 | import os 3 | import threading 4 | import time 5 | import asyncio 6 | 7 | MidLevel=500 8 | NormalDelay=30 9 | ReducedDelay=5 10 | path = os.getcwd() + "/file.csv" 11 | Mailpath = os.getcwd() + "/body.csv" 12 | 13 | MailBody = [['Dear Sir,','It has come to attention to our monitoring system that a leakage has been detected at system present ','The type of leakage has been found to be ','Kindly bring your attention.','Thanks & Regards'], 14 | ['Dear Sir,','It has come to attention to our monitoring system that an obstacle has been detected at system present ','Kindly bring your attention.','Thanks & Regards'] 15 | ] 16 | 17 | class setup_manager: 18 | def pin_mode(self, water_sensor_pin, ir_sensor_pin): 19 | self.water_sensor_pin = water_sensor_pin 20 | self.ir_sensor_pin = ir_sensor_pin 21 | print("Pins Callibrated Successfully !!") 22 | 23 | def get_delay(self, flag, delay): 24 | self.delay = delay 25 | if(delay == 30): 26 | self.flag = True 27 | else: 28 | self.flag = False 29 | 30 | print("Default delay set to ", self.delay, " seconds !!") 31 | 32 | class Connection: 33 | def __init__(self,list_of_list,path): 34 | self.list_of_list = list_of_list 35 | self.path = path 36 | 37 | def writing_data_to_csv_file(self): 38 | with open(self.path,"w") as f: 39 | writer = csv.writer(f) 40 | writer.writerows(self.list_of_list) 41 | f.close() 42 | 43 | def read_csv_file(self,path): 44 | self.list_of_list = [] 45 | with open(path,newline='') as f: 46 | csvreader = csv.reader(f) 47 | for row in csvreader: 48 | self.list_of_list.append(row) 49 | temp = self.list_of_list[-1] 50 | if(len(temp)==0): 51 | self.list_of_list.pop() 52 | 53 | 54 | 55 | 56 | class water_sensor_data_collection: 57 | def __init__(self,water_data,ida): 58 | self.water_data=water_data 59 | self.delay = NormalDelay 60 | self.ida = ida 61 | 62 | def get_water_sensor_data(self): 63 | return self.water_data 64 | 65 | def get_delay(self): 66 | if(self.water_data > MidLevel): 67 | self.delay = ReducedDelay 68 | else : 69 | self.delay = NormalDelay 70 | 71 | return self.delay 72 | 73 | def get_id(self): 74 | return self.ida 75 | 76 | class ir_sensor_data_collection: 77 | 78 | def __init__(self,ir_data,ida): 79 | self.ir_data=ir_data 80 | self.ida = ida 81 | 82 | def get_ir_sensor_data(self): 83 | return self.ir_data 84 | 85 | def get_id(self): 86 | return self.ida 87 | 88 | class wifi_manager(): 89 | def __init__(self,sensor_id): 90 | self.sensor_id=sensor_id 91 | 92 | def get_water_sensor_data(self,water_data): 93 | self.water_sensor_data=water_data 94 | def get_ir_sensor_data(self,ir_data): 95 | self.ir_sensor_data=ir_data 96 | 97 | setup_manager=setup_manager() 98 | 99 | def delay(interval): 100 | time.sleep(interval) 101 | 102 | def ir_sensor(id_sensor): 103 | sensor_id = id_sensor 104 | f=0 105 | while f!=1: 106 | sensor_data=int(input("Enter IR Sensor data : ")) 107 | if sensor_data==0 or sensor_data==1: 108 | f=1 109 | else: 110 | print("Invalid data") 111 | Data[sensor_id-1][0] = sensor_data 112 | ir_sensor_1=ir_sensor_data_collection(sensor_data,sensor_id) 113 | wifi_manager_1=wifi_manager(sensor_id) 114 | wifi_manager_1.get_ir_sensor_data(ir_sensor_1.ir_data) 115 | print("data recieved in wifi_module is ",wifi_manager_1.ir_sensor_data) 116 | newConnection = Connection(Data,path) 117 | newConnection.writing_data_to_csv_file() 118 | return sensor_data 119 | 120 | 121 | def water_sensor(id_sensor): 122 | sensor_id = id_sensor 123 | f=0 124 | while f!=1: 125 | sensor_data=int(input("Enter Water Sensor data : ")) 126 | if sensor_data>=0 and sensor_data<=1024: 127 | f=1 128 | else: 129 | print("Invalid data") 130 | Data[sensor_id-1][1] = sensor_data 131 | water_sensor_1=water_sensor_data_collection(sensor_data,sensor_id) 132 | print("delay is ",water_sensor_1.get_delay()," minutes") 133 | wifi_manager_1=wifi_manager(1) 134 | wifi_manager_1.get_water_sensor_data(water_sensor_1.water_data) 135 | print("data recieved in wifi_module is ",wifi_manager_1.water_sensor_data) 136 | newConnection = Connection(Data,path) 137 | newConnection.writing_data_to_csv_file() 138 | return sensor_data 139 | 140 | 141 | def sensor(sensor_id,f): 142 | ir_data=ir_sensor(sensor_id) 143 | f=0 144 | water_data=water_sensor(sensor_id) 145 | if water_data>500: 146 | for i in range(0,5): 147 | f=1 148 | time.sleep(5) 149 | water_data=water_sensor(sensor_id) 150 | if water_data<500: 151 | f=0 152 | break 153 | return f 154 | 155 | 156 | 157 | 158 | 159 | flag = 0 160 | id_sensor = int(input("Enter Sensor Id : ")) 161 | while True : 162 | 163 | if(os.path.exists(path)): 164 | temp=[] 165 | newConnection = Connection(temp, path) 166 | newConnection.read_csv_file(path) 167 | Data = newConnection.list_of_list 168 | else: 169 | Data = [[0,0],[0,0],[0,0]] 170 | newConnection2 = Connection(Data,path) 171 | newConnection2.writing_data_to_csv_file() 172 | newConnection3 = Connection(MailBody,Mailpath) 173 | newConnection3.writing_data_to_csv_file() 174 | 175 | 176 | f=0 177 | f=sensor(id_sensor,f) 178 | if f==0: 179 | time.sleep(30) 180 | else: 181 | f=1 182 | 183 | 184 | 185 | -------------------------------------------------------------------------------- /Main/server_module.py: -------------------------------------------------------------------------------- 1 | import smtplib 2 | import csv 3 | import os 4 | import time 5 | 6 | path = os.getcwd() + "/file.csv" 7 | Mailpath = os.getcwd() + "/body.csv" 8 | Dry = "Dry" 9 | Partial = "Partially Submerged." 10 | Full = "Fully Submerged." 11 | Obstacle = "Obstacles Present" 12 | NoObstacle = "No Obstacles Present" 13 | MidLevel = 500 14 | ServerEmail = "perceptronfordesignlab@gmail.com" 15 | ServerPassword = "Perceptron@1234" 16 | MailSent = "Email Sent Successfully" 17 | ReceiverMail = "hitmanabhishek089@gmail.com" 18 | HeaderSubject = "Pipeline Leakage Detection" 19 | Sensor_ids=[1,2,3] 20 | Delay=30 21 | 22 | class Connection: 23 | def __init__(self,path): 24 | self.path = path 25 | self.list_of_list = [] 26 | def read_csv_file(self,path): 27 | with open(path,newline='') as f: 28 | csvreader = csv.reader(f) 29 | for row in csvreader: 30 | self.list_of_list.append(row) 31 | temp = self.list_of_list[-1] 32 | if(len(temp)==0): 33 | self.list_of_list.pop() 34 | 35 | class cloud_manager(): 36 | def __init__(self): 37 | self.sensor_id=None 38 | def create_lookup_table(self): 39 | self.lookup_table={} 40 | self.lookup_table[0]="at GODREJ WATERSIDE." 41 | self.lookup_table[1]="in front of COLLEGE MORE." 42 | self.lookup_table[2]="near WIPRO MORE." 43 | self.lookup_table[3]="near KARUNAMOYEE." 44 | self.lookup_table[4]="at CITY CENTRE 1." 45 | def get_water_sensor_data(self,water_data,sensor_id): 46 | self.water_sensor_data=water_data 47 | self.sensor_id=sensor_id 48 | def get_ir_sensor_data(self,ir_data,sensor_id): 49 | self.ir_sensor_data=ir_data 50 | self.sensor_id=sensor_id 51 | def process_water_sensor_data(self): 52 | if self.water_sensor_data==0: 53 | return Dry 54 | elif self.water_sensor_data < MidLevel: 55 | emailManager = Email_Manager() 56 | msg = MailBody[0][0] +'\n' + MailBody[0][1] + str(self.lookup_table[self.sensor_id - 1])+'.' +'\n' +MailBody[0][2] + Partial +'\n'+ MailBody[0][3]+'\n'+MailBody[0][4] 57 | message = 'Subject: {}\n\n{}'.format(HeaderSubject, msg) 58 | emailManager.send_email(ReceiverMail, message) 59 | return Partial 60 | else: 61 | emailManager = Email_Manager() 62 | msg = MailBody[0][0] +'\n' + MailBody[0][1] + str(self.lookup_table[self.sensor_id - 1])+'.' +'\n' +MailBody[0][2] + Full +'\n'+ MailBody[0][3]+'\n'+MailBody[0][4] 63 | message = 'Subject: {}\n\n{}'.format(HeaderSubject, msg) 64 | emailManager.send_email(ReceiverMail, message) 65 | Delay=5 66 | return Full 67 | 68 | 69 | def process_ir_sensor_data(self): 70 | if self.ir_sensor_data==1: 71 | emailManager = Email_Manager() 72 | msg = MailBody[1][0] + '\n' + MailBody[1][1] + str(self.lookup_table[self.sensor_id - 1]) + '\n' + MailBody[1][2] + '\n' + MailBody[1][3] 73 | message = 'Subject: {}\n\n{}'.format(HeaderSubject, msg) 74 | emailManager.send_email(ReceiverMail, message) 75 | return Obstacle 76 | else: 77 | return NoObstacle 78 | 79 | class Email_Manager(): 80 | def __init__(self): 81 | self.email_id = ServerEmail 82 | self.password = ServerPassword 83 | 84 | def send_email(self,recievers_email, message): 85 | server = smtplib.SMTP('smtp.gmail.com', 587) 86 | server.starttls() 87 | server.login(self.email_id, self.password) 88 | server.sendmail(self.email_id, recievers_email,message) 89 | server.quit() 90 | print(MailSent) 91 | 92 | cloud_manager_1=cloud_manager() 93 | cloud_manager_1.create_lookup_table() 94 | def process_ir_sensor(): 95 | for sensor_id in Sensor_ids: 96 | sensor_data=int(Data[sensor_id-1][0]) 97 | cloud_manager_1.get_ir_sensor_data(sensor_data,sensor_id) 98 | print(cloud_manager_1.process_ir_sensor_data()," at ir sensor",sensor_id) 99 | 100 | def process_water_sensor(): 101 | for sensor_id in Sensor_ids: 102 | sensor_data=int(Data[sensor_id-1][1]) 103 | cloud_manager_1.get_water_sensor_data(sensor_data,sensor_id) 104 | print("sensor",sensor_id,"is",cloud_manager_1.process_water_sensor_data()) 105 | 106 | 107 | 108 | while True : 109 | if(os.path.exists(path) and os.path.exists(Mailpath)): 110 | break 111 | 112 | 113 | 114 | 115 | while True : 116 | Data = [[0,0],[0,0],[0,0]] 117 | MailBody =[["x","y"]] 118 | newConnection = Connection(path) 119 | newConnection.read_csv_file(path) 120 | Data = newConnection.list_of_list 121 | print(Data) 122 | newConnection1 = Connection(Mailpath) 123 | newConnection1.read_csv_file(Mailpath) 124 | MailBody = newConnection1.list_of_list 125 | process_ir_sensor() 126 | process_water_sensor() 127 | time.sleep(Delay) 128 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pipeline-Leakage-Detection 2 | The application aims to simulate real life pipeline conditions and detect leaking in pipeline system whether it is underground or general pipeline system 3 | -------------------------------------------------------------------------------- /Test/test_pipeline_leakage_detection.py: -------------------------------------------------------------------------------- 1 | from pipeline_leakage_detection import * 2 | import unittest 3 | class test_water_sensor_data_collection(unittest.TestCase): 4 | 5 | def test_get_water_sensor_data(self): 6 | water_sensor=water_sensor_data_collection(0,1) 7 | expt_ans=0 8 | self.assertEqual(water_sensor.get_water_sensor_data(),expt_ans) 9 | 10 | water_sensor=water_sensor_data_collection(1024,1) 11 | expt_ans=1024 12 | self.assertEqual(water_sensor.get_water_sensor_data(),expt_ans) 13 | def test_get_delay(self): 14 | water_sensor=water_sensor_data_collection(0,1) 15 | expt_ans=30 16 | self.assertEqual(water_sensor.get_delay(),expt_ans) 17 | 18 | water_sensor=water_sensor_data_collection(550,1) 19 | expt_ans=5 20 | self.assertEqual(water_sensor.get_delay(),expt_ans) 21 | 22 | class test_ir_sensor_data_collection(unittest.TestCase): 23 | 24 | def test_get_ir_sensor_data(self): 25 | ir_sensor=ir_sensor_data_collection(0,1) 26 | expt_ans=0 27 | self.assertEqual(ir_sensor.get_ir_sensor_data(),expt_ans) 28 | 29 | ir_sensor=ir_sensor_data_collection(1,1) 30 | expt_ans=1 31 | self.assertEqual(ir_sensor.get_ir_sensor_data(),expt_ans) 32 | 33 | class test_wifi_manager(unittest.TestCase): 34 | def test_get_water_sensor_data(self): 35 | wifi_module=wifi_manager(1) 36 | wifi_module.get_water_sensor_data(1024) 37 | expt_ans=1024 38 | self.assertEqual(wifi_module.water_sensor_data,expt_ans) 39 | 40 | def test_get_ir_sensor_data(self): 41 | wifi_module=wifi_manager(1) 42 | wifi_module.get_ir_sensor_data(1) 43 | expt_ans=1 44 | self.assertEqual(wifi_module.ir_sensor_data,expt_ans) 45 | 46 | if __name__ == '__main__': 47 | unittest.main() 48 | -------------------------------------------------------------------------------- /Test/test_server_module.py: -------------------------------------------------------------------------------- 1 | from server_module import cloud_manager 2 | import unittest 3 | 4 | class test_cloud_manager(unittest.TestCase) : 5 | def test_process_water_sensor_data(self) : 6 | cloud_manager_1=cloud_manager() 7 | cloud_manager_1.create_lookup_table() 8 | cloud_manager_1.get_water_sensor_data(560,1) 9 | self.assertEqual(cloud_manager_1.process_water_sensor_data(),"Fully Submerged.") 10 | 11 | def test_process_ir_sensor_data(self) : 12 | cloud_manager_1=cloud_manager() 13 | cloud_manager_1.create_lookup_table() 14 | cloud_manager_1.get_ir_sensor_data(1,1) 15 | self.assertEqual(cloud_manager_1.process_ir_sensor_data(),"Obstacles Present") 16 | 17 | if __name__ == '__main__': 18 | unittest.main() 19 | --------------------------------------------------------------------------------