def startProcessing(self): self.N = int(self.numcells.get()) self.ImgProcessing = processing.Processing(self.master, self.imagestate, self.file, self.N, self.colorrange.get()) ImgProcessing = self.ImgProcessing self.image1 = ImgProcessing.image self.image2 = ImageTk.PhotoImage(self.image1) self.outimage1 = ImgProcessing.outimage self.outimage2 = (ImgProcessing.outimage) self.outimage2 = ImageTk.PhotoImage(self.outimage2) self.c.delete("all") self.c.image = self.c.create_image(0, 0, image=self.outimage2, anchor="nw") self.showcolored = Button(self.c, text="Show colored result", relief=RIDGE, bg="white", command=self.showColored) self.showcolored.place(x=2, y=2, height=30) self.paint.config(state=NORMAL) self.download.config(state=NORMAL) self.download2.config(state=NORMAL) self.palette = ImgProcessing.palette self.pCanvas = Canvas(self.master) self.pCanvas.place(x=2, y=425, width=110, height=180) self.createPalette() self.download3 = Button(self.master, text="Save palette", font=("Verdana", 10), command=self.downloadPalette) self.download3.place(x=2, y=390, width=110, height=30) tt8 = CreateToolTip( self.download3, "Download the color palette for the processed image")
def on_click_apply(self): step_val = float(self.lineEdit_step.text().strip()) n_val = int(self.lineEdit_n.text().strip()) l_val = float(self.lineEdit_width.text().strip()) self.new_process = processing.Processing(step_val, n_val, l_val, self.cvImage, self) self.new_process.radon() self.new_process.reverse_radon() if self.filter: self.new_process.filtering() self.new_process.rmse() else: self.new_process.rmse() if self.iterative: self.label_statistic.setText("Błąd średniokwadratowy: " + str(self.new_process.rmse)) else: self.sinogram = toimage(self.new_process.sinogram) qsinogram = ImageQt(self.sinogram) self.output_image = toimage(self.new_process.newImage) qoutput = ImageQt(self.output_image) pixmap1 = QPixmap.fromImage(qsinogram) pixmap2 = QPixmap.fromImage(qoutput) pixmap1 = pixmap1.scaled(self.label_img_sin.size(), Qt.KeepAspectRatio) pixmap2 = pixmap2.scaled(self.label_img_out.size(), Qt.KeepAspectRatio) self.label_img_sin.setPixmap(pixmap1) self.label_img_out.setPixmap(pixmap2) self.label_statistic.setText("Błąd średniokwadratowy: " + str(self.new_process.rmse))
def add_single_csv(self, csv_file_path): table_name = 'reddit_comments' #processor = processing.Processing(**self.config_processing) processor = processing.Processing(delete_punctuation_marks=True, delete_numeral=True, delete_single_words=True, initial_form=True, stop_words=None) conn = sqlite3.connect(self.db_file) c = conn.cursor() c.execute("PRAGMA foreign_keys = ON") csvfile = open(csv_file_path) readCSV = csv.reader(csvfile, delimiter=',') # to_db = [( # datetime.datetime.fromtimestamp(int(row[0])).strftime('%Y-%m-%d %H:%M:%S'), # row[1].replace("'", "''"), # row[2].replace("'", "''"), # row[3].replace("'", "''") # ) for row in readCSV] # c.executemany("INSERT INTO " + table_name + " (time, username, comment, tag) VALUES (?, ?, ?, ?)", to_db) for row in readCSV: time_ = datetime.datetime.fromtimestamp(int( row[0])).strftime('%Y-%m-%d %H:%M:%S') username_ = row[1].replace("'", "''") comment_ = row[2].replace("'", "''") tag_ = row[3].replace( "'", "''") # assume there are 4 fields in every line comment_id = None tag_id = None username_id = None try: c.execute("INSERT INTO tags (tag) VALUES ('" + tag_ + "')") tag_id = c.lastrowid except sqlite3.IntegrityError as err: c.execute("SELECT tag_id FROM tags WHERE tag='" + tag_ + "'") found = [r for r in c] if len(found) > 0: tag_id = found[0][0] else: tag_id = None try: c.execute("INSERT INTO usernames (username) VALUES ('" + username_ + "')") username_id = c.lastrowid except sqlite3.IntegrityError as err: c.execute( "SELECT username_id FROM usernames WHERE username='******'") found = [r for r in c] if len(found) > 0: username_id = found[0][0] else: username_id = None try: c.execute("INSERT INTO " + table_name + " (time, comment, username_id, tag_id) VALUES ('" + time_ + "', '" + comment_ + "', '" + str(username_id) + "', '" + str(tag_id) + "')") comment_id = c.lastrowid except sqlite3.IntegrityError as err: print("Error adding comment issued at " + time_ + ": " + str(err)) comment_id = None # to process text and insert result #document, words = processor(comment_) # print(words) # for w in words: # # c.execute("IF EXISTS (SELECT * FROM global_dict WHERE word='" + w[0] + "' AND type='" + w[1] + "') " + # # "UPDATE global_dict SET global_occuerrences=global_occuerrences+" + str(w[2]) + # # " WHERE word='" + w[0] + "' AND type='" + w[1] + "' " + # # "ELSE INSERT INTO global_dict (word, type, global_occuerrences) VALUES ('" + w[0] + "', '" + w[1] + "', " + str(w[2]) + ")") # # # added to global dictionatyor updated number of occurrences # try: # c.execute("INSERT INTO global_dict (word, type, global_occurrences) VALUES ('" + w[0] + "', '" + # w[1] + "', " + str(w[2]) + ")") # # print("- inserted " + w[0]) # # except sqlite3.IntegrityError as err1: # # UNIQUE constraint prevents from adding, trying updating # try: # c.execute("UPDATE global_dict SET global_occurrences=global_occurrences+" + str(w[2]) + # " WHERE word='" + w[0] + "' AND type='" + w[1] + "' ") # # print("- updated " + w[0]) # except sqlite3.IntegrityError as err2: # print("!! failed both to insert and update word.\n - error message on INSERT: " + str(err1) # + "\n - error message on UPDATE: " + str(err2)) # c.execute("SELECT * FROM global_dict WHERE word='" + w[0] + "' AND type='" + w[1] + "'") # word_id = None # try: # word_id = c.fetchone()[0] # except: # print("!! failed to select the word " + w[0] + ", " + w[1] + " in 'global_dict' table") # if word_id: # try: # c.execute( # "INSERT INTO occurrences (word_id, comment_id, occurrences) VALUES ('" + str( # word_id) + "', '" + # str(comment_id) + "', " + str(w[2]) + ")") # except sqlite3.IntegrityError as err: # print("!! failed to insert record into 'occurrences' table.\n - error message: " + str(err)) conn.commit() conn.close()
def image_stop(self): print("stop") process = processing.Processing() processing.run()
"-input_framerate": stream1.framerate } output_params2 = {"-input_framerate": stream2.framerate} writer1 = WriteGear(output_filename="blank.mkv", **output_params1) #Define writer writer2 = WriteGear(output_filename="blank.mkv", **output_params2) #Define writer # Closing extra streams stream1.stop() stream2.stop() fileNameList = [] compute = processing.Processing() startTime = 0 endTime = 0 ##################################### END SETUP ####################################### ##################################### CHANGE LED ###################################### # This function calls led.py to change the color with given requirements def change_LED(r, g, b): os.system('sudo python3 led.py -r' + str(r) + ' -g' + str(g) + ' -b' + str(b)) ################################## END CHANGE LED #####################################
import processing from commons import logging import project_config if __name__ == '__main__': logging.init_logging(project_config.PROJECT_SYMBOL) processor = processing.Processing() processor.run()
def setUp(self): params = {"X_train":[], "X_test":[], "y_train":[], "y_test":[]} self.p = processing.Processing(params)
def __init__( self, Facility_Name, facility_type, Distance_per_lift, Distance_to_TransferStation, Total_tonnes_collected, Number_bin_per_hhold, number_hhold, Transfer_Station, Processing_Facility, Transfer_Distance, ): self.Facility_Name = Facility_Name self.facility_type = facility_type self.Distance_per_lift = Distance_per_lift self.Distance_to_TransferStation = Distance_to_TransferStation self.Total_tonnes_collected = Total_tonnes_collected self.Number_bin_per_hhold = Number_bin_per_hhold self.number_hhold = number_hhold self.Transfer_Station = Transfer_Station self.Processing_Facility = Processing_Facility self.Transfer_Distance = Transfer_Distance ########################################################################################################### #processing facility #grab composition self.waste_composition_class = Co.Waste_Composition() #grab mat diversion per facility self.Material_Diversion_class = WF.Facility_Type() self.WP = Prcss.Processing(self.Facility_Name, self.waste_composition_class, self.Material_Diversion_class) self.WP.Material_Recovery(facility_type) self.total_landfill_in_t = self.WP.total_for_landfill self.total_processed = self.WP.total_processed print("total landfill in t = ", self.WP.total_for_landfill, " total processed = ", self.WP.total_processed) ########################################################################################################### #waste stream self.WasteCompo = self.waste_composition_class.Waste_Composition self.WS = wststream.WasteStream(self.WasteCompo) #self.WS.verification() for compo in self.WS.Waste_Composition: self.WS.landfill_emissions_per_t(compo) print(compo, " total emissions per t = ", self.WS.total_emission_per_t) ########################################################################################################### #trip from households to transfer station self.Trucks = TR.trucks() for collection_truck in self.Trucks.collection_trucks: self.TRP = Trp.Trip(collection_truck, self.Distance_per_lift, self.Distance_to_TransferStation, self.Total_tonnes_collected, self.Number_bin_per_hhold, self.number_hhold) self.TRP.total_emissions() self.TRP.costs() print("Collection truck = ", collection_truck, " total emissions in t CO2 = ", self.TRP.tCO2, " total liftcost = ", self.TRP.lift_costs) ########################################################################################################### #transfert from transfert station to processing facility for transfer_truck in self.Trucks.transfer_trucks: self.TRANS = Trf.Transfer(transfer_truck, self.Transfer_Station, self.Processing_Facility, self.Transfer_Distance, self.Total_tonnes_collected) self.TRANS.total_emissions() self.TRANS.costs() print("transfer truck = ", transfer_truck, " total emissions in t CO2 = ", self.TRANS.tCO2, " total transfercost = ", self.TRANS.transfer_costs) return
ratio = np.array([zero_count[i] / (i + 1) for i in range(length)]) self.ratio_array.append(ratio) # print(self.ratio_array) print('finished') class Analysis(object): def __init__(self, classifier, test_data): self.classifier = classifier self.test_data = test_data if __name__ == '__main__': da = pd.read_csv('train.csv') da = pr.Processing(da) da.data_processing() di = pr.Divide(da.get_data()) ''' c = 10 times = 5 for k in range(10): acc = 0 for i in range(times): cv = di.cross_validation(c) for data in cv: train = data[0] test = data[1] knn = KNN(train, k) acc += knn.accuracy(test) / c / times print(k, acc)