def save(self): if (self.ID == -1): pass if (self.erro == 1): pass else: control = 0 if (self.label_severely_injured_value != str(self.severely_old)): self.severely_old = int(self.severely_number) control = 1 if (self.label_casualties_value != str(self.casualties_old)): self.casualties_old = int(self.casualty_number) control = 1 if (control == 0): pass else: get_query_result("UPDATE Acidentes SET Mortos = " + str(self.casualties_old) + ", FeridosGraves = " + str(self.severely_old) + " WHERE IdAcidente = " + self.ID + "; COMMIT;") process = Popen(['python3', 'hospital_successful.py'], stdout=PIPE, stderr=PIPE) self.id_search()
def __init__(self, testes, **kwargs): super().__init__(**kwargs) # get the data from the "concelho" given data = get_query_result( "SELECT * FROM acidentes WHERE IdVia IN (SELECT IdVia FROM vias WHERE IdConcelho = (SELECT IdConcelho FROM concelhos WHERE Nome = '" + sys.argv[1] + "'))") testes = [] for i in range(len(data)): testes.append([]) # date and time year = str(data[i][1]).split(" ")[0].split("-")[0] month = str(data[1][1]).split(" ")[0].split("-")[1] day = str(data[1][1]).split(" ")[0].split("-")[2] date = day + "/" + month + "/" + year + " " # Time hour = str(data[1][1]).split(" ")[1].split(":")[0] minutes = str(data[1][1]).split(" ")[1].split(":")[1] time = hour + ":" + minutes date = day + "/" + month + "/" + year + " " + hour + ":" + minutes testes[i].append("ID: " + str(data[i][0]) + " | " + date + " | IdVia: " + str(data[i][2]) + " | \"" + data[i][3] + "\" | KM: " + str(data[i][4]) + " | M.: " + str(data[i][5]) + " | FG.: " + str(data[i][6])) for teste in testes: self.ids.box.add_widget( Label(text=teste[0], font_size=17, size_hint_y=None, height=50, width=300, color=(0.0, 0.0, 0.4, 1.0)))
def concelho_search(self): if (self.text_concelho_search.text == ""): process = Popen(['python3', 'entity_input_warning.py'], stdout=PIPE, stderr=PIPE) else: results = get_query_result( "SELECT * FROM concelhos WHERE Nome = '" + self.text_concelho_search.text + "';") print(results) if (len(results) == 0): process = Popen(['python3', 'entity_input_warning.py'], stdout=PIPE, stderr=PIPE) else: process = Popen([ 'python3', 'entity_concelhos.py', self.text_concelho_search.text ], stdout=PIPE, stderr=PIPE)
def id_search(self): if (self.text_id_search.text == ""): process = Popen(['python3', 'entity_input_warning.py'], stdout=PIPE, stderr=PIPE) else: self.ID = self.text_id_search.text # retireve our results results_list = get_query_result( "SELECT * FROM acidentes WHERE IdAcidente=" + self.ID + ";" ) # format = [(IdAcidente, DataHora, IdVia, Natureza, Km, Mortos, FeridosGraves)] # Description # --------------------------------------------------------------------------------------------------------------------- self.label_accident_description_value.text = results_list[0][3] # --------------------------------------------------------------------------------------------------------------------- # Location # --------------------------------------------------------------------------------------------------------------------- location = get_query_result( "SELECT IdVia, Nome FROM Vias Where IdVia = (SELECT IdVia FROM Acidentes Where IdAcidente = " + self.ID + ");") self.label_accident_location_value.text = location[0][1] # --------------------------------------------------------------------------------------------------------------------- # KM # --------------------------------------------------------------------------------------------------------------------- self.label_accident_km_value.text = str(results_list[0][4]) # --------------------------------------------------------------------------------------------------------------------- # Date and Time # ----------------------------------------------------------- # Date year = str(results_list[0][1]).split(" ")[0].split("-")[0] month = str(results_list[0][1]).split(" ")[0].split("-")[1] day = str(results_list[0][1]).split(" ")[0].split("-")[2] date = day + "/" + month + "/" + year + " " # Time hour = str(results_list[0][1]).split(" ")[1].split(":")[0] minutes = str(results_list[0][1]).split(" ")[1].split(":")[1] time = hour + ":" + minutes self.label_accident_timestamp_value.text = date + time # ----------------------------------------------------------- # Casualties # ----------------------------------------------------- self.label_casualties_value.text = str(results_list[0][5]) self.casualties_old = int(results_list[0][5]) # ----------------------------------------------------- # Severely Injured # ----------------------------------------------------------- self.label_severely_injured_value.text = str(results_list[0][6]) self.severely_old = int(results_list[0][6])
def save(self): if (self.ID == -1): pass if (self.erro == 1): pass else: control = 0 if (len(self.text_accident_timestamp_value.text) < 16): process = Popen(['python3', 'police_input_warning.py'], stdout=PIPE, stderr=PIPE) if (self.text_accident_description_value.text != "" and self.text_accident_description_value.text != self.description_old): self.description_old = self.text_accident_description_value.text control = 1 if (self.text_accident_km_value.text != "" and self.text_accident_km_value.text != self.km_old): self.km_old = self.text_accident_km_value.text control = 1 if (self.text_accident_location_value.text != "" and self.text_accident_location_value.text != self.location_text_old): control = 1 # new road ID location_id_new = get_query_result( "SELECT IdVia FROM Vias Where Nome = '" + self.text_accident_location_value.text + "';") # "concelho" and "tipo" of the currently stored road data location_concelho = get_query_result( "SELECT IdConcelho FROM Vias Where IdVia = '" + str(self.location_id_old) + "';")[0][0] location_tipo = get_query_result( "SELECT Tipo FROM Vias Where IdVia = '" + str(self.location_id_old) + "';")[0][0] if (len(location_id_new) == 0): # it's a new road max_id = get_query_result( "SELECT MAX(IdVia) FROM Vias;")[0][0] get_query_result( "INSERT INTO Vias (IdVia, Nome, IdConcelho, Tipo) Values (" + str(max_id + 1) + ", '" + self.text_accident_location_value.text + "', " + str(location_concelho) + ", '" + location_tipo + "'); COMMIT;") self.location_id_old = max_id + 1 else: # it's an already stored road self.location_id_old = location_id_new[0][0] if (len(self.text_accident_timestamp_value.text) == 16 and self.text_accident_timestamp_value.text != self.timestamp_old): self.timestamp_old = self.text_accident_timestamp_value.text control = 1 # invert the timestamp year = str(self.timestamp_old).split(" ")[0].split("/")[2] month = str(self.timestamp_old).split(" ")[0].split("/")[1] day = str(self.timestamp_old).split(" ")[0].split("/")[0] date = year + "/" + month + "/" + day + " " # Time hour = str(self.timestamp_old).split(" ")[1].split(":")[0] minutes = str(self.timestamp_old).split(" ")[1].split(":")[1] time = hour + ":" + minutes self.timestamp_old = date + time if (self.severely_number != str(self.severely_old)): self.severely_old = int(self.severely_number) control = 1 if (self.casualty_number != str(self.casualties_old)): self.casualties_old = int(self.casualty_number) control = 1 if (control == 0): pass else: get_query_result("UPDATE Acidentes SET Natureza = '" + self.description_old + "', IdVia = " + str(self.location_id_old) + ", Km = " + str(self.km_old) + ", DataHora = '" + self.timestamp_old + "', Mortos = " + str(self.casualties_old) + ", FeridosGraves = " + str(self.severely_old) + " WHERE IdAcidente = " + self.ID + "; COMMIT;") process = Popen(['python3', 'police_successful.py'], stdout=PIPE, stderr=PIPE) self.id_search()
def save_accident(self): if(self.text_accident_description_value.text==""): process = Popen(['python3', 'police_input_warning.py'], stdout=PIPE, stderr=PIPE) elif(self.text_accident_location_value.text==""): process = Popen(['python3', 'police_input_warning.py'], stdout=PIPE, stderr=PIPE) elif(self.text_accident_km_value.text==""): process = Popen(['python3', 'police_input_warning.py'], stdout=PIPE, stderr=PIPE) elif(self.text_accident_concelho_value.text==""): process = Popen(['python3', 'police_input_warning.py'], stdout=PIPE, stderr=PIPE) elif(len(self.text_accident_timestamp_value.text)<16): process = Popen(['python3', 'police_input_warning.py'], stdout=PIPE, stderr=PIPE) else: new_id = get_query_result("SELECT MAX(IdAcidente) FROM Acidentes;")[0][0] + 1 new_road_id = get_query_result("SELECT IdVia FROM Vias Where Nome = '" + self.text_accident_location_value.text + "';") new_concelho_name = get_query_result("SELECT IdConcelho FROM Concelhos Where Nome = '" + self.text_accident_concelho_value.text + "';") if(len(new_concelho_name)==0): new_concelho_id = get_query_result("SELECT MAX(IdConcelho) FROM Concelhos;")[0][0] + 1 get_query_result("INSERT INTO Concelhos(IdConcelho, Nome, IdDistrito) VALUES (" + str(new_concelho_id) + ", '" + self.text_accident_concelho_value.text + "',1); COMMIT;") else: new_concelho_id = new_concelho_name[0][0] if(len(new_road_id)==0): # it's a new road new_new_road_id = get_query_result("SELECT MAX(IdVia) FROM Vias;")[0][0] + 1 get_query_result("INSERT INTO Vias(IdVia, Nome, IdConcelho, Tipo) VALUES (" + str(new_new_road_id) + ", '" + self.text_accident_location_value.text + "'," + str(new_concelho_id) + ", 'None'); COMMIT;") get_query_result("INSERT INTO Acidentes(IdAcidente, DataHora, IdVia, Natureza, Km, Mortos, FeridosGraves) VALUES (" + str(new_id) + ", '" + self.text_accident_timestamp_value.text + "', " + str(new_new_road_id) + ", '" + self.text_accident_description_value.text + "', " + self.text_accident_km_value.text + ", " + self.casualty_number + ", " + self.severely_number + "); COMMIT;") else: get_query_result("INSERT INTO Vias(IdVia, Nome, IdConcelho, Tipo) VALUES (" + str(new_road_id[0][0]) + ", '" + self.text_accident_location_value.text + "'," + str(new_concelho_id) + ", 'None'); COMMIT;") get_query_result("INSERT INTO Acidentes(IdAcidente, DataHora, IdVia, Natureza, Km, Mortos, FeridosGraves) VALUES (" + str(new_id) + ", '" + self.text_accident_timestamp_value.text + "', " + str(new_road_id[0][0]) + ", '" + self.text_accident_description_value.text + "', " + self.text_accident_km_value.text + ", " + self.casualty_number + ", " + self.severely_number + "); COMMIT;") process = Popen(['python3', 'police_successful.py'], stdout=PIPE, stderr=PIPE)