How to use import_table method in localstack

Best Python code snippet using localstack_python

K1830_opt.py

Source:K1830_opt.py Github

copy

Full Screen

1import csv2from math import sqrt3import os4import random5from re import S67import shutil8import tkinter as tk9from tkinter import *10from tkinter import ttk, messagebox11from tkinter import Label12from tkinter import filedialog13from tkinter.filedialog import askopenfile14from turtle import left, width15import sys16import keyboard1718from numpy import column_stack1920import tkinter as tk2122class CreateToolTip(object):23 """24 create a tooltip for a given widget25 """26 def __init__(self, widget, text='widget info'):27 self.waittime = 500 #miliseconds28 self.wraplength = 180 #pixels29 self.widget = widget30 self.text = text31 self.widget.bind("<Enter>", self.enter)32 self.widget.bind("<Leave>", self.leave)33 self.widget.bind("<ButtonPress>", self.leave)34 self.id = None35 self.tw = None3637 def enter(self, event=None):38 self.schedule()3940 def leave(self, event=None):41 self.unschedule()42 self.hidetip()4344 def schedule(self):45 self.unschedule()46 self.id = self.widget.after(self.waittime, self.showtip)4748 def unschedule(self):49 id = self.id50 self.id = None51 if id:52 self.widget.after_cancel(id)5354 def showtip(self, event=None):55 x = y = 056 x, y, cx, cy = self.widget.bbox("insert")57 x += self.widget.winfo_rootx() + 2558 y += self.widget.winfo_rooty() + 2059 # creates a toplevel window60 self.tw = tk.Toplevel(self.widget)61 # Leaves only the label and removes the app window62 self.tw.wm_overrideredirect(True)63 self.tw.wm_geometry("+%d+%d" % (x, y))64 label = tk.Label(self.tw, text=self.text, justify='left',65 background="#ffffff", relief='solid', borderwidth=1,66 wraplength = self.wraplength)67 label.pack(ipadx=1)6869 def hidetip(self):70 tw = self.tw71 self.tw= None72 if tw:73 tw.destroy()7475""" tk_ToolTip_class101.py76gives a Tkinter widget a tooltip as the mouse is above the widget77tested with Python27 and Python34 by vegaseat 09sep201478www.daniweb.com/programming/software-development/code/484591/a-tooltip-class-for-tkinter7980Modified to include a delay time by Victor Zaccardo, 25mar1681"""8283class Redirect():84 85 def __init__(self, widget):86 self.widget = widget87 88 def write(self, text):89 self.widget.insert('end', text)90 self.widget.see('end') # autoscroll91 9293def print_t(string):94 old_stdout = sys.stdout 95 sys.stdout = Redirect(text)96 print(string)97 sys.stdout = old_stdout9899##############################################################################################################################################100# MAIN101##############################################################################################################################################102103RUNS = 10000104file_location = os.getcwd()105Footprint_Library = file_location + "/Data/Footprint_Library.csv"106Compdata = file_location + "/Data/Compdata.csv"107Feeder = file_location + "/Data/Feeder.csv"108Mark = file_location + "/Data/Mark.csv"109Nozzle = file_location + "/Data/Nozzle.csv"110Panel = file_location + "/Data/Panel.csv"111PCBdata = file_location + "/Data/PCB.csv"112113import_table = []114Footprint_Library_table = list(csv.reader(open(Footprint_Library)))115Compdata_table = list(csv.reader(open(Compdata)))116F_table = list(csv.reader(open(Feeder)))117M_table = list(csv.reader(open(Mark)))118N_table = list(csv.reader(open(Nozzle)))119P_table = list(csv.reader(open(Panel)))120PCB_table = list(csv.reader(open(PCBdata)))121122#######################################################################123# Recommends Nozzles to use. Does not change the current nozzles 124# unless a specific nozzle type is missing. 125#######################################################################126def Nozzle_Suggest(import_table,Footprint_Library_table,N_table):127 nozzle_array = ["CN030","CN040","CN065","CN100","CN140","CN220","CN400","CN750"]128129 nozzle_CN030 = 0130 nozzle_CN040 = 0131 nozzle_CN065 = 0132 nozzle_CN100 = 0133 nozzle_CN140 = 0134 nozzle_CN220 = 0135 nozzle_CN400 = 0136 nozzle_CN750 = 0137138 F_col = []139140 for i in range(len(Footprint_Library_table)):141 F_col.append(Footprint_Library_table[i][0])142143 for i in range(1,len(import_table)):144 if(import_table[i][1] not in F_col):145 print_t(import_table[i][1] + " is not in Footprint_Library.csv")146 return False147 index = F_col.index(import_table[i][1])148 if Footprint_Library_table[index][4] == "CN030":149 nozzle_CN030 += 1150 elif Footprint_Library_table[index][4] == "CN040":151 nozzle_CN040 += 1152 elif Footprint_Library_table[index][4] == "CN065":153 nozzle_CN065 += 1154 elif Footprint_Library_table[index][4] == "CN100":155 nozzle_CN100 += 1156 elif Footprint_Library_table[index][4] == "CN140":157 nozzle_CN140 += 1158 elif Footprint_Library_table[index][4] == "CN220":159 nozzle_CN220 += 1160 elif Footprint_Library_table[index][4] == "CN400":161 nozzle_CN400 += 1162 elif Footprint_Library_table[index][4] == "CN750":163 nozzle_CN750 += 1164165 nozzle_CN030round = 0166 nozzle_CN040round = 0167 nozzle_CN065round = 0168 nozzle_CN100round = 0169 nozzle_CN140round = 0170 nozzle_CN220round = 0171 nozzle_CN400round = 0172 nozzle_CN750round = 0173 total = 0174175 total_nozzles = nozzle_CN030 + nozzle_CN040 + nozzle_CN065 + nozzle_CN100 + nozzle_CN140 + nozzle_CN220 + nozzle_CN400 + nozzle_CN750176177 if (nozzle_CN030 > 0):178 nozzle_CN030round = round((nozzle_CN030 / total_nozzles) * 8)179 # If round is 0180 total += nozzle_CN030round181 if nozzle_CN030round == 0:182 nozzle_CN030round += 1183 total += nozzle_CN030round184185 if (nozzle_CN040 > 0):186 nozzle_CN040round = (round((nozzle_CN040 / total_nozzles) * 8))187 total += nozzle_CN040round188 # If round is 0189 if nozzle_CN040round == 0:190 nozzle_CN040round += 1191 total += nozzle_CN040round192193 if (nozzle_CN065 > 0):194 nozzle_CN065round = round((nozzle_CN065 / total_nozzles) * 8)195 total += nozzle_CN065round196 # If round is 0197 if nozzle_CN065round == 0:198 nozzle_CN065round += 1199 total += nozzle_CN065round200201 if (nozzle_CN100 > 0):202 nozzle_CN100round = round((nozzle_CN100 / total_nozzles) * 8)203 total += nozzle_CN100round204 #If round is 0205 if nozzle_CN100round == 0:206 nozzle_CN100round += 1207 total += nozzle_CN100round208209 if (nozzle_CN140 > 0):210 nozzle_CN140round = round((nozzle_CN140 / total_nozzles) * 8)211 # If round is 0212 total += nozzle_CN140round213 if nozzle_CN140round == 0:214 nozzle_CN140round += 1215 total += nozzle_CN140round216217 if (nozzle_CN220 > 0):218 nozzle_CN220round = round((nozzle_CN220 / total_nozzles) * 8)219 total += nozzle_CN220round220 # If round is 0221 if nozzle_CN220round == 0:222 nozzle_CN220round += 1223 total += nozzle_CN220round224225 if (nozzle_CN400 > 0):226 nozzle_CN400round = round((nozzle_CN400 / total_nozzles) * 8)227 total += nozzle_CN400round228 # If round is 0229 if nozzle_CN400round == 0 :230 nozzle_CN400round += 1231 total += nozzle_CN400round232233 if (nozzle_CN750 > 0):234 nozzle_CN750round = round((nozzle_CN750 / total_nozzles) * 8)235 total += nozzle_CN750round236 # If round is 0237 if nozzle_CN750round == 0 :238 nozzle_CN750round += 1239 total += nozzle_CN750round240241 nozzle_total_array = [nozzle_CN030round,nozzle_CN040round,nozzle_CN065round,nozzle_CN100round,nozzle_CN140round,nozzle_CN220round,nozzle_CN400round,nozzle_CN750round]242243 while total > 8:244 index_max = max(range(len(nozzle_total_array)), key=nozzle_total_array.__getitem__)245 nozzle_total_array[index_max] -= 1246 total -= 1247 nozzle_array[index_max]248 while total < 8:249 index_max = max(range(len(nozzle_total_array)), key=nozzle_total_array.__getitem__)250251 nozzle_counter_array = []252 for i in range(len(nozzle_total_array)):253 to_append = []254 to_append.append(nozzle_array[i])255 to_append.append(nozzle_total_array[i])256 nozzle_counter_array.append(to_append)257 nozzle_counter_array.sort(key=lambda x:x[1],reverse=True)258259 nozzle_suggest_array = []260 for i in range(len(nozzle_counter_array)):261 while(nozzle_counter_array[i][1] > 0):262 nozzle_suggest_array.append(nozzle_counter_array[i][0])263 nozzle_counter_array[i][1] -= 1264265 print_t("Recommended Nozzles: " + nozzle_suggest_array[0] + ", " + nozzle_suggest_array[1] + ", " + nozzle_suggest_array[2] + ", " + nozzle_suggest_array[3] + ", " + nozzle_suggest_array[4] + ", " + nozzle_suggest_array[5] + ", " + nozzle_suggest_array[6] + ", " + nozzle_suggest_array[7])266 print_t("Current Nozzles: " + N_table[1][2] + ", " + N_table[2][2] + ", " + N_table[3][2] + ", " + N_table[4][2] + ", " + N_table[5][2] + ", " + N_table[6][2] + ", " + N_table[7][2] + ", " + N_table[8][2])267 window.update()268 window.after(20)269 N_table_array = [N_table[1][2],N_table[2][2],N_table[3][2],N_table[4][2],N_table[5][2],N_table[6][2],N_table[7][2],N_table[8][2]]270 for i in range(len(nozzle_suggest_array)):271 if nozzle_suggest_array[i] not in N_table_array:272 print_t("Using Recommended Nozzles.")273 window.update()274 window.after(20)275 N_table[1][2] = nozzle_suggest_array[0]276 N_table[2][2] = nozzle_suggest_array[1]277 N_table[3][2] = nozzle_suggest_array[2]278 N_table[4][2] = nozzle_suggest_array[3]279 N_table[5][2] = nozzle_suggest_array[4]280 N_table[6][2] = nozzle_suggest_array[5]281 N_table[7][2] = nozzle_suggest_array[6]282 N_table[8][2] = nozzle_suggest_array[7]283 return N_table284 print_t("Using Current Nozzles.")285 window.update()286 window.after(20) 287 return N_table288289#######################################################################290# Checks if footprints and comments are persent in Compdata.csv291# discards component otherwise.292#######################################################################293def Check_footprints_comments(table_check,Compdata_table):294 Compdata_fp_cmnt = []295 table_check_fp_cmnt = []296 discard = []297 check = 0298 for i in range(len(Compdata_table)):299 to_append = []300 to_append.append(Compdata_table[i][0])301 to_append.append(Compdata_table[i][1])302 Compdata_fp_cmnt.append(to_append)303 for i in range(len(table_check)):304 to_append = []305 to_append.append(table_check[i][1])306 to_append.append(table_check[i][10])307 table_check_fp_cmnt.append(to_append) 308 if table_check_fp_cmnt[i] in Compdata_fp_cmnt:309 continue310 else:311 check += 1312 discard.append(i)313 print_t("Discarded "+ table_check[i][1])314 print_t("Add Component '" + table_check_fp_cmnt[i][0] + "' - '" + table_check_fp_cmnt[i][1] + "' to Data/Compdata.csv" )315 window.update()316 window.after(50) 317 for i in range(len(discard)): 318 table_check.remove(table_check[discard[i]])319 320 return table_check321322#######################################################################323# If the Import file is pre-made and only needs the nozzle/feeder324# order to be modified, then this function replaces all the Panel, 325# Mark, PCB, Nozzle data with that the datafile.326#######################################################################327def Existing_Table(table_check,Compdata_table,M_table,N_table,P_table,PCB_table):328 col1 =[]329 import_table = []330 import_table_temp = []331 Compdata_table_temp = []332 for i in range(len(table_check)):333 col1.append(table_check[i][0])334 Compdata_index = col1.index('#Feeder')335 PCB_index = col1.index('#PCB')336 P_index = col1.index('#Panel')337 N_index = col1.index('#Nozzle')338 M_index = col1.index('#Mark')339 Foot_index = col1.index('#Comp')340 Compdata_end = PCB_index - 1341 PCB_end = P_index - 1342 P_end = N_index - 1343 N_end = M_index - 1344 M_end = Foot_index - 1345 Foot_end = len(col1)346347 for i in range(Compdata_index,Compdata_end):348 Compdata_table_temp.append(table_check[i])349 for i in range(PCB_index,PCB_end):350 PCB_table.append(table_check[i])351 for i in range(P_index,P_end):352 P_table.append(table_check[i])353 for i in range(N_index,N_end):354 N_table.append(table_check[i])355 for i in range(M_index,M_end):356 M_table.append(table_check[i])357 for i in range(Foot_index,Foot_end):358 import_table_temp.append(table_check[i])359360 for i in range(len(Compdata_table_temp)):361 to_append = []362 for j in range(6,len(Compdata_table_temp[i])):363 if j != 8:364 to_append.append(Compdata_table_temp[i][j])365 Compdata_table.append(to_append)366367 import_table.append(["Designator","Footprint","Center-X(mm)","Center-Y(mm)","Ref-X(mm)","Ref-Y(mm)","Pad-X(mm)","Pad-Y(mm)","Layer","Rotation","Comment"])368 for i in range(1,len(import_table_temp)):369 to_append = []370 to_append.append(import_table_temp[i][4])371 to_append.append(import_table_temp[i][3])372 to_append.append(import_table_temp[i][6])373 to_append.append(import_table_temp[i][7])374 to_append.append(import_table_temp[i][6])375 to_append.append(import_table_temp[i][7])376 to_append.append(import_table_temp[i][6])377 to_append.append(import_table_temp[i][7])378 to_append.append("Toplayer")379 to_append.append(import_table_temp[i][8])380 to_append.append(import_table_temp[i][2])381 import_table.append(to_append)382 return import_table,Compdata_table,M_table,N_table,P_table,PCB_table383384sourcefile = ''385# Store directory folder in file_location variable386file_location = os.getcwd()387388import_folder = "/Import"389import_file_location = file_location + import_folder390391# Name of the folder where output is stored392new_folder = "/Output"393new_files = file_location + new_folder394395# Check whether the specified path exists or not396isExist = os.path.exists(new_files)397398if not isExist:399 # Create a new directory because it does not exist 400 os.makedirs(new_files)401 print("The new directory is created!")402403Footprint_Nozzle = []404to_fappend = []405for i in range(len(Footprint_Library_table)):406 to_fappend.append(Footprint_Library_table[i][0])407Footprint_Nozzle.append(to_fappend)408to_fappend = []409for i in range(len(Footprint_Library_table)):410 to_fappend.append(Footprint_Library_table[i][4])411Footprint_Nozzle.append(to_fappend)412413#######################################################################414# Measures the distance between each feeder or a feeder and the center415# start is the starting feeder and end is the ending feeder416# if start is set to 0, it is considered to be the center.417#######################################################################418def distance_calc(start,end):419 dist = 0420 t = 0421422 if start == end:423 dist = 0.1424 dist = dist*20.9425 dist = round(dist,2)426 return float(str(round(dist,2)))427428 if start == 0:429 if (end <= 17):430 t = abs(17-end)+2.5431 dist = sqrt(144+(t*t))432 dist = round(dist,2)433 elif (end <= 33):434 t = abs(33-end)+2.5435 dist = sqrt(144+(t*t))436 dist = round(dist,2)437 elif (end <= 50):438 t = abs(50-end)+2.5439 dist = sqrt(144+(t*t))440 dist = round(dist,2)441 elif (end <= 66):442 t = abs(66-end)+2.5443 dist = sqrt(144+(t*t))444 dist = round(dist,2)445 dist = dist*20.9446447 dist = round(dist,2)448 return float(str(round(dist,2)))449450 if (start <= 17):451 if (end <= 17):452 dist = abs(end - start)453 elif (end <= 33):454 dist = abs((end-start))+5455 elif (end <= 50):456 t = abs(end-(start+33))457 dist = sqrt(576+(t*t))458 dist = round(dist,2)459 elif (end <= 66):460 t = abs((end-(start+33)))+5461 dist = sqrt(576+(t*t))462 dist = round(dist,2)463 elif (start <= 33):464 if (end <= 17):465 dist = abs((end - start))+5466 elif (end <= 33):467 dist = abs(end-start)468 elif (end <= 50):469 t = abs((end-(start+33)))+5470 dist = sqrt(576+(t*t))471 dist = round(dist,2)472 elif (end <= 66):473 t = abs(end-(start+33))474 dist = sqrt(576+(t*t))475 dist = round(dist,2)476 elif (start <= 50):477 if (end <= 17):478 t = abs(end-(start-33))479 dist = sqrt(576+(t*t)) 480 dist = round(dist,2) 481 elif (end <= 33):482 t = abs((end-(start-33)))+5483 dist = sqrt(576+(t*t)) 484 dist = round(dist,2) 485 elif (end <= 50):486 dist = abs(end - start)487 elif (end <= 66):488 dist = abs((end-start))+5489 elif (start <= 66):490 if (end <= 17):491 t = abs((end-(start-33)))+5492 dist = sqrt(576+(t*t)) 493 dist = round(dist,2) 494 elif (end <= 33):495 t = abs(end-(start-33))496 dist = sqrt(576+(t*t))497 dist = round(dist,2) 498 elif (end <= 50):499 dist = abs((end-start))+5500 elif (end <= 66):501 dist = abs(end - start)502 dist = dist*20.9503 dist = round(dist,2)504 return float(str(round(dist,2)))505506def csv_to_lists(r,data):507 list = []508 for i in range(r[0],r[1]):509 a = data[i]510 list.append(a)511 return list512513#######################################################################514# Discards BGA components515#######################################################################516def discard_comp(import_table,Compdata_table):517 discard = []518 footprints = []519 for i in range(1,len(Compdata_table)):520 footprints.append(Compdata_table[i][0])521 522 for i in range(1,len(import_table)):523 if import_table[i][1] == "BGA484C80P22X22_1900X1900X190" or import_table[i][1] == "BGA96C80P16X9_1400X900X120":524 print_t("Discarded "+ import_table[i][1])525 discard.append(i)526527 for i in range(len(discard)): 528 import_table.remove(import_table[discard[i]])529 return import_table530531#######################################################################532# Creates a list (comp_freq) of unique components and how many of each533# there are in the import file.534#######################################################################535def component_frequency(import_table):536 comp_freq = []537 done = []538 temp = [0,0]539 for j in range(1,len(import_table)):540 if j not in done:541 temp[0] = import_table[j][1]542 temp[1] = import_table[j][10]543 count = 0544 to_append = []545 to_append.append(count)546 to_append.append(0)547 for i in range(j,len(import_table)):548 if ((temp[0] == import_table[i][1]) & (temp[1] == import_table[i][10])):549 count = count + 1550 to_append.append(i)551 done.append(i)552 to_append[0] = count553 comp_freq.append(to_append)554 comp_freq.sort(key=lambda x:x[0],reverse=True)555 return comp_freq556557#######################################################################558# Checks if the current nozzle is the correct nozzle to pick up the559# components by comparing it to data from Footprint_Library.csv.560#######################################################################561def nozzle_match(N_table,Footprint_Nozzle,nozzle,designator,import_table):562563 N_type = N_table[nozzle][2]564 footprint_current = import_table[designator][1] # footprint of the input component565 col = Footprint_Nozzle[0].index(footprint_current)566 nozzle_current = Footprint_Nozzle[1][col] # list of all compatible parts with the chosen nozzle567 if nozzle_current == N_type:568 return True569 return False570571#######################################################################572# Returns total number of components.573#######################################################################574def total_components(comp_freq):575 comp_total = 0576 for i in range(len(comp_freq)):577 comp_total = comp_total + comp_freq[i][0]578 return comp_total579580#######################################################################581# Checks is the current nozzle can reach the current feeder582#######################################################################583def nozzle_reach(f,n):584 if ((n == 1) and (((f > 26) and (f < 34)) or (f > 59))):585 return False586 elif ((n == 2) and (((f > 27) and (f < 34)) or (f > 60) or (f < 2) or ((f > 33) and (f < 35)))):587 return False588 elif ((n == 3) and (((f > 28) and (f < 34)) or (f > 61) or (f < 3) or ((f > 33) and (f < 36)))):589 return False590 elif ((n == 4) and (((f > 29) and (f < 34)) or (f > 62) or (f < 4) or ((f > 33) and (f < 37)))):591 return False592 elif ((n == 5) and (((f > 30) and (f < 34)) or (f > 63) or (f < 5) or ((f > 33) and (f < 38)))):593 return False594 elif ((n == 6) and (((f > 31) and (f < 34)) or (f > 64) or (f < 6) or ((f > 33) and (f < 39)))):595 return False596 elif ((n == 7) and (((f > 32) and (f < 34)) or (f > 65) or (f < 7) or ((f > 33) and (f < 40)))):597 return False598 elif ((n == 8) and ((f < 8) or ((f > 33) and (f < 41)))):599 return False600 else:601 return True602603#######################################################################604# Assigns each unique component to each feeder.605# checks if there is not feeder and nozzle mismatch and moves them606# checks for any microSD components and moves them to an empty feeder607# with no adjacent used feeders.608#######################################################################609def comp_feeder_learner(comp_freq_original,import_table,N_table,comp_total,Footprint_Nozzle):610 comp_freq = comp_freq_original611612 mapping_start = [16,15,14,17,13,12,11]613 mapping_original = [18,19,20,21,22,23,24,25,50,51,49,52,48,53,47,54,46,55,45,56,44,57,43,58,10,614 9,26,8,27,7,28,6,29,5,30,4,31,3,32,2,33,1,42,59,41,60,40,61,39,62,38,63,37,64,36,65,35,66,34]615616 mapping = []617 for i in range(len(comp_freq)):618 mapping.append(mapping_original[i])619620 feeder_used = []621 current_feeder = 10622 current_comp = 0623 current_comp_feeder = 0624 current_comp_footprint = 0625 current_comp_nozzle = 0626 counter = 0627 checker = 0628 checker2 = 0629 N_types = []630 microsd = []631 micro = 0632 CN750 = []633 bool = 1634 loop = 0635 j = 0636637 for i in range(len(mapping_start)):638 map = mapping_start[i] # pick random feeder from list639 f_index = comp_freq[i][2]640 footprint = import_table[f_index][1]641642 if(footprint != "MicroSD_-_DM3C-SF"):643 comp_freq[i][1] = map644 micro = 1645 if(comp_freq[i][1] != 0):646 feeder_used.append(comp_freq[i][1])647648 for i in range(len(mapping_start),len(comp_freq)):649650 map = random.choice(mapping) # pick random feeder from list651 mapping.remove(map) # remove picked feeder to avoid duplicates652 f_index = comp_freq[i][2]653 footprint = import_table[f_index][1]654655 if(footprint != "MicroSD_-_DM3C-SF"):656 comp_freq[i][1] = map657 micro = 1658 if(comp_freq[i][1] != 0):659 feeder_used.append(comp_freq[i][1])660661 for i in range(len(comp_freq)):662 N_types = []663 counter = 0664 checker = 0665 if comp_freq[i][1] != 0:666 current_comp = comp_freq[i][2]667 current_comp_feeder = comp_freq[i][1]668 current_comp_footprint = import_table[current_comp][1]669 index = Footprint_Nozzle[0].index(current_comp_footprint)670 current_comp_nozzle = Footprint_Nozzle[1][index]671 for j in range(len(N_table)):672 if N_table[j][2] == current_comp_nozzle:673 N_types.append(N_table[j][1])674 for j in range(len(N_types)):675 if (nozzle_reach(current_comp_feeder,int(N_types[j])) is True):676 checker = 1677 break 678 while ((checker == 0) and (checker2 == 0)):679 current_comp_feeder = (current_comp_feeder % 66) + 1680 counter += 1681 if (current_comp_feeder not in feeder_used):682 for l in range(len(N_types)):683 if (nozzle_reach(current_feeder,int(N_types[l])) is True): 684 comp_freq[i][1] = current_comp_feeder685 checker2 = 1686 if(counter > 67):687 print_t("Too many components. Results may be Inaccurate.")688 break689690 if micro == 1:691 for i in range(len(N_table)):692 if N_table[i][2] == "CN750":693 CN750.append(N_table[i][1])694 for i in range(len(comp_freq)):695 while comp_freq[i][1] == 0:696 loop += 1697 if (current_feeder not in feeder_used) and ((current_feeder-1) not in feeder_used) and ((current_feeder+1) not in feeder_used):698 for j in range(len(CN750)):699 if (nozzle_reach(current_feeder,int(CN750[j])) is not True):700 current_feeder += 1701 bool = 0702 if bool == 1:703 comp_freq[i][1] = current_feeder704 current_feeder = 1705 bool = 1706 else:707 if(current_feeder >= 66):708 current_feeder = 1709 elif(current_feeder < 66):710 current_feeder += 1711712 if loop == 1000:713 comp_freq.remove(comp_freq[i])714 print_t("Discarded MicroSD_-_DM3C-SF")715 comp_total = comp_total - 1716 return comp_freq,comp_total717 718 return comp_freq,comp_total719720# def comp_feeder_designation(comp_freq_original,import_table,N_table):721# comp_freq = comp_freq_original722# mapping = [17,18,16,19,15,20,14,21,13,22,12,23,11,24,10,25,50,51,49,52,48,53,47,54,46,55,45,56,44,57,43,58,723# 9,26,8,27,7,28,6,29,5,30,4,31,3,32,2,33,1,42,59,41,60,40,61,39,62,38,63,37,64,36,65,35,66,34]724# feeder_used = []725# current_feeder = 9726# microsd = []727# micro = 0728# CN750 = []729# bool = 1730# j = 0731732# for i in range(len(comp_freq)):733734# map = mapping[i]735# f_index = comp_freq[i][2]736# footprint = import_table[f_index][1]737# if(footprint != "MicroSD_-_DM3C-SF"):738# comp_freq[i][1] = map739# micro = 1740# if(comp_freq[i][1] != 0):741# feeder_used.append(comp_freq[i][1])742743# if micro == 1:744# for i in range(len(N_table)):745# if N_table[i][2] == "CN750":746# CN750.append(N_table[i][1])747# for i in range(len(comp_freq)):748# while comp_freq[i][1] == 0:749# if (current_feeder not in feeder_used) and ((current_feeder-1) not in feeder_used) and ((current_feeder+1) not in feeder_used):750# for j in range(len(CN750)):751# if (nozzle_reach(current_feeder,int(CN750[j])) is not True):752# current_feeder += 1753# bool = 0754# if bool == 1:755# comp_freq[i][1] = current_feeder756# current_feeder = 1757# bool = 1758 759# else:760# if(current_feeder >= 66):761# current_feeder += 1762# else:763# exit("Nozzle and Feeder Mismatch!")764 765# return comp_freq 766767#######################################################################768# Assigns the picking order of nozzles for each feeder769#######################################################################770def comp_nozzle_designation(comp_total,new_comp,import_table):771 nozzle_amount = 8772 current_nozzle = 1773 left_bottom = 17774 right_bottom = 18775 left_top = 50776 right_top = 51777 comp_total_temp = comp_total778 prev_feeder = 0779 current_feeder = (left_bottom - nozzle_amount) + 1780 new_feeders = []781 nozzle_designation = []782 feeder_loop = 0783 stuck_loop = 0784785 for i in range(len(new_comp)):786 new_feeders.append(new_comp[i][1])787 788 while comp_total > 0:789 790 temp_list = []791 if current_feeder in new_feeders:792 index = new_feeders.index(current_feeder)793 794 if int(new_comp[index][0]) > 0:795 designator = int(new_comp[index][2])796 if ((nozzle_reach(current_feeder,current_nozzle) is not True) or (nozzle_match(N_table,Footprint_Nozzle,current_nozzle,designator,import_table) is not True)):797 pass798 else:799 stuck_loop = 0800 feeder_loop = 0801 new_comp[index][0] = int(new_comp[index][0]) - 1802 temp_list = [new_comp[index][1],new_comp[index][2],current_nozzle]803804 if len(new_comp[index]) > 2:805 del new_comp[index][2]806807 nozzle_designation.append(temp_list)808809 comp_total = comp_total - 1 810811 prev_feeder = current_feeder812 if current_nozzle < nozzle_amount:813 current_nozzle = current_nozzle + 1814 elif current_nozzle == nozzle_amount:815 current_nozzle = 1816 current_feeder = 10817 continue818 819 if current_feeder == 9:820 current_feeder = 34821 elif current_feeder == 25:822 current_feeder = 43823 elif current_feeder == 58:824 current_feeder = 1825 elif current_feeder == 42:826 current_feeder = 26827 elif current_feeder == 33:828 current_feeder = 59829 elif current_feeder == 66:830 current_feeder = 10831 else:832 current_feeder = current_feeder + 1833 if feeder_loop > 66:834 if current_nozzle < nozzle_amount:835 current_nozzle = current_nozzle + 1836 elif current_nozzle == nozzle_amount:837 current_nozzle = 1838 feeder_loop = 0839 feeder_loop = feeder_loop + 1840 stuck_loop = stuck_loop + 1841842 if stuck_loop > 5000:843 # print("s")844 return nozzle_designation845 846 return nozzle_designation847848#######################################################################849# update the starting feeder for measuring distance850#######################################################################851def update_distance_starting_position(nid,fid_prev,nid_prev):852 if fid_prev > 0:853 if nid > nid_prev:854 fid_prev = fid_prev + (abs(nid-nid_prev))855 elif nid < nid_prev:856 fid_prev = fid_prev - (abs(nid-nid_prev))857 elif nid == nid_prev:858 pass859 return fid_prev860861#######################################################################862# Runs distance calculations across all the assigned feeders and nozzles863#######################################################################864def total_distance_calc(nozzle_designation):865 filled_nozzle = []866 distance = 0867 fid_prev = 0868 nid_prev = 0869 for i in range(len(nozzle_designation)):870 nid = nozzle_designation[i][2]871 filled_nozzle.append(nid)872 cid = nozzle_designation[i][1]873 fid = nozzle_designation[i][0]874 # Check if we need to move back to the center875 if i > 0:876 if nid < nid_prev:877 fid_prev = 0878 distance = distance + distance_calc(fid_prev,fid)879880 # Moving to next feeder881 fid_prev = update_distance_starting_position(nid,fid_prev,nid_prev)882 distance = distance + distance_calc(fid_prev,fid)883 nid_prev = nid884 fid_prev = fid885886 # last loop to move nozzles back to the center887 distance = distance + distance_calc(fid_prev,fid)888 return distance889890#######################################################################891# Returns feeder data in the required format892#######################################################################893def feeder_output(comp_freq,F_table,Compdata_table,import_table):894 feeder_store = []895 896 for i in range(len(comp_freq)):897 f_index = comp_freq[i][1]898 c = comp_freq[i][2]899 for j in range(1,len(Compdata_table)):900 if ((Compdata_table[j][0] == import_table[c][1]) and (Compdata_table[j][1] == import_table[c][10])):901 c_index = j902 to_append = []903 for j in range(6):904 to_append.append(F_table[f_index][j])905 to_append.append(Compdata_table[c_index][0])906 to_append.append(Compdata_table[c_index][1])907 to_append.append(F_table[f_index][6])908 for j in range(2,len(Compdata_table[c_index])):909 to_append.append(Compdata_table[c_index][j])910 feeder_store.append(to_append)911912 feeder_store.sort(key=lambda x:x[1],reverse=False)913 914 return feeder_store915916#######################################################################917# Returns component data in the required format918#######################################################################919def comp_output(import_table,nozzle_designation):920 header = ['#Comp','Feeder ID','Comment','Footprint','Designatior','NozzleNumber','Pos X','Pos Y','Angle','Skip','Position']921 comp_header = []922 comp_header.append(header)923 for i in range(0,len(nozzle_designation)):924 n = nozzle_designation[i]925 append_list = []926 append_list.append('Comp')927 append_list.append(n[0])928 append_list.append(import_table[n[1]][10])929 append_list.append(import_table[n[1]][1])930 append_list.append(import_table[n[1]][0])931 append_list.append(n[2])932 append_list.append(import_table[n[1]][2])933 append_list.append(import_table[n[1]][3])934 append_list.append(import_table[n[1]][9])935 append_list.append('No')936 append_list.append('Align') 937 comp_header.append(append_list)938 return comp_header939940#######################################################################941# Creates the output csv file942#######################################################################943def full_output(feeder_store,PCB_table,P_table,N_table,M_table,comp_store,sourcefile,sourcefile_import):944 header = ['#Feeder','Feeder ID','Skip','Pos X','Pos Y','Angle','Footprint','Comment','Nozzle','Pick Height','Pick Delay','Move Speed','Place Height','Place Delay','Place Speed','Accuracy',945 'Width','Length','Thickness','Size Analyze','Tray X','Tray Y','Columns','Rows','Right Top X','Right Top Y','Vision Model','Brightness','Vision Error','Vision Flash','Feeder Type','NoisyPoint']946 pre, ext = os.path.splitext(sourcefile_import)947 output = new_files +"/" + pre + "_out" + ext948 outp = pre + "_out" + ext949 with open(output, 'w') as f:950 converted_list = [str(element) for element in header]951 joined_list = ",".join(converted_list)952 f.write(joined_list)953 f.write('\n') 954 for line in feeder_store:955 converted_list = [str(element) for element in line]956 joined_list = ",".join(converted_list)957 f.write(joined_list)958 f.write('\n') 959 f.write('\n') 960 for line in PCB_table:961 converted_list = [str(element) for element in line]962 joined_list = ",".join(converted_list)963 f.write(joined_list)964 f.write('\n') 965 f.write('\n') 966 for line in P_table:967 converted_list = [str(element) for element in line]968 joined_list = ",".join(converted_list)969 f.write(joined_list)970 f.write('\n') 971 f.write('\n') 972 for line in N_table:973 converted_list = [str(element) for element in line]974 joined_list = ",".join(converted_list)975 f.write(joined_list)976 f.write('\n') 977 f.write('\n') 978 for line in M_table:979 converted_list = [str(element) for element in line]980 joined_list = ",".join(converted_list)981 f.write(joined_list)982 f.write('\n') 983 f.write('\n') 984 for line in comp_store:985 converted_list = [str(element) for element in line]986 joined_list = ",".join(converted_list)987 f.write(joined_list)988 f.write('\n') 989 return outp 990991#######################################################################992# Runs the above functions 10000 times and picks the output with993# the shortest distance traveled.994#######################################################################995def shortest_distance(import_table,sourcefile,sourcefile_import,Compdata_table,M_table,N_table,P_table,PCB_table):996 sort_comparison_list = []997 new_comp_store = []998 total_distance = 100000999 prev_total_distance = total_distance1000 loops = 01001 i = 01002 while i < RUNS:1003 import_table = discard_comp(import_table,Compdata_table)1004 comp_freq = component_frequency(import_table)1005 new_comp_store.append(comp_freq)1006 comp_total = total_components(comp_freq)1007 new_comp,comp_total = comp_feeder_learner(comp_freq,import_table,N_table,comp_total,Footprint_Nozzle)10081009 temp_comp = new_comp1010 feeder_store = feeder_output(new_comp,F_table,Compdata_table,import_table)10111012 nozzle_designation = comp_nozzle_designation(comp_total,new_comp,import_table)1013 1014 total_distance = total_distance_calc(nozzle_designation)1015 if int(total_distance) < int(prev_total_distance):1016 prev_total_distance = total_distance10171018 sort_comp = []1019 sort_comp.append(temp_comp)1020 sort_comp.append(total_distance)1021 sort_comp.append(nozzle_designation)1022 sort_comparison_list.append(sort_comp)1023 i = i+11024 1025 loops = loops+110261027 sort_comparison_list.sort(key=lambda x:x[1],reverse=False)10281029 comp_store = comp_output(import_table,sort_comparison_list[0][2])1030 output = full_output(feeder_store,PCB_table,P_table,N_table,M_table,comp_store,sourcefile,sourcefile_import)1031 1032 return sort_comparison_list[0][2],output10331034#######################################################################1035# Same as shortest_distance() but modified for pre-made import files1036#######################################################################1037def shortest_distance_pre(import_table,sourcefile,sourcefile_import,Compdata_table,M_table,N_table,P_table,PCB_table):1038 sort_comparison_list = []1039 new_comp_store = []1040 total_distance = 1000001041 prev_total_distance = total_distance1042 loops = 01043 i = 01044 while i < RUNS:1045 import_table = discard_comp(import_table,Compdata_table)1046 comp_freq = component_frequency(import_table)1047 new_comp_store.append(comp_freq)1048 comp_total = total_components(comp_freq)1049 new_comp,comp_total = comp_feeder_learner(comp_freq,import_table,N_table,comp_total,Footprint_Nozzle)10501051 temp_comp = new_comp1052 feeder_store = feeder_output(new_comp,F_table,Compdata_table,import_table)10531054 nozzle_designation = comp_nozzle_designation(comp_total,new_comp,import_table)1055 1056 total_distance = total_distance_calc(nozzle_designation)1057 if int(total_distance) < int(prev_total_distance):1058 prev_total_distance = total_distance10591060 sort_comp = []1061 sort_comp.append(temp_comp)1062 sort_comp.append(total_distance)1063 sort_comp.append(nozzle_designation)1064 sort_comparison_list.append(sort_comp)1065 i = i+11066 1067 loops = loops+110681069 sort_comparison_list.sort(key=lambda x:x[1],reverse=False)10701071 comp_store = comp_output(import_table,sort_comparison_list[0][2])1072 output = full_output(feeder_store,PCB_table,P_table,N_table,M_table,comp_store,sourcefile,sourcefile_import)1073 1074 return sort_comparison_list[0][2],output107510761077##############################################################################################################################################1078# SIMULATION1079##############################################################################################################################################1080outline = "#000"1081fill = "#ffe"10821083#######################################################################1084# Update the feeder nozzle and component counters. components 1085# uses the footprint from import_table1086#######################################################################1087def update_counters(import_table,canvas,fid,nid,cid,canvas_counters,reset):1088 if reset:1089 canvas.itemconfig(canvas_counters[1], text="0")1090 canvas.itemconfig(canvas_counters[2], text="0")1091 canvas.itemconfig(canvas_counters[3], text="none") 1092 return1093 cid_footprint = import_table[cid][1]1094 canvas.itemconfig(canvas_counters[1], text=str(fid))1095 canvas.itemconfig(canvas_counters[2], text=str(nid))1096 canvas.itemconfig(canvas_counters[3], text=str(cid_footprint))10971098def update_distance(canvas,distance,canvas_counters):1099 d = distance1100 d = round(d,2)1101 canvas.itemconfig(canvas_counters[0], text=str(d)+" mm")11021103def update_remaining_feeders(canvas,fid,remaining_feeders,feeder_canvas):1104 if int(fid) in remaining_feeders:1105 canvas.itemconfig(feeder_canvas[fid], fill='yellow')1106 elif int(fid) not in remaining_feeders:1107 canvas.itemconfig(feeder_canvas[fid], fill=fill)11081109def update_distance_starting_position(nid,fid_prev,nid_prev):1110 if fid_prev > 0:1111 if nid > nid_prev:1112 fid_prev = fid_prev + (abs(nid-nid_prev))1113 elif nid < nid_prev:1114 fid_prev = fid_prev - (abs(nid-nid_prev))1115 elif nid == nid_prev:1116 pass1117 return fid_prev1118 11191120#######################################################################1121# Moves all 8 nozzles to (x_move,y_move). id is the number of nozzle1122# picking up.1123#######################################################################1124def animate_moveto(canvas,nozzle_canvas,id,n_c,x_move, y_move):1125 x = x_move1126 y = y_move1127 for i in range(id,len(n_c)):1128 canvas.moveto(n_c[i],x,y)1129 x = x + 231130 x = x_move1131 for i in range(id-1,0,-1):1132 x = x - 231133 canvas.moveto(nozzle_canvas[i],x,y)113411351136#######################################################################1137# Module to animate the nozzles picking up up the components for the1138# feeders based on their nozzle_designation1139#######################################################################1140def nozzle_animation(nozzle_designation,import_table):11411142 # Creating tkinter canvas and drawing all objects (feeder, nozzle, pcb, counters)1143 ws = tk.Tk()1144 ws.title('K1830 Simulation')1145 ws.geometry('1000x600')1146 ws.config(bg='#345')11471148 canvas = Canvas(1149 ws,1150 height=600,1151 width=1000,1152 bg="#ddd"1153 )11541155 canvas.pack()11561157 feeder_canvas = [0]1158 nozzle_canvas = [0]1159 x0 = 501160 x1 = x0 + 181161 y0 = 5001162 y1 = y0 - 6011631164 def draw_nozzles(start,end,x0, y0, x1, y1, nozzle_canvas):1165 for i in range(start,end):1166 n = canvas.create_oval(x0, y0, x1, y1, outline=outline, fill=fill)1167 data = [n,x0,y0,x1,y1]1168 nozzle_canvas.append(n)1169 x0 = x0 + 231170 x1 = x0 + 181171 return nozzle_canvas11721173 def draw_feeders(start,end,x0, y0, x1, y1, feeder_canvas):1174 st_x0 = x01175 st_x1 = x11176 for i in range(start,end):1177 f = canvas.create_rectangle(x0, y0, x1, y1, outline=outline, fill=fill)1178 data = [f,x0,y0,x1,y1]1179 feeder_canvas.append(f)1180 x0 = x0 + 231181 x1 = x0 + 181182 return x0, y0, x1, y1, feeder_canvas11831184 def draw_feeders_label(start,end,x0, y0, x1, y1):1185 for i in range(start,end):1186 if i >= 34:1187 canvas.create_text((x0+9, y0-10), text=str(i))1188 else:1189 canvas.create_text((x0+9, y0-50), text=str(i))1190 x0 = x0 + 231191 x1 = x0 + 181192 return x0, y0, x1, y111931194 def pause_sim(pause_keyboard,RUN_or_PAUSE):1195 canvas.itemconfig(RUN_or_PAUSE, text="Press 'r' to RUN")1196 canvas.update()1197 canvas.after(50)1198 while pause_keyboard == True:1199 if keyboard.is_pressed('r'):1200 pause_keyboard = False1201 canvas.itemconfig(RUN_or_PAUSE, text="Press 'p' to PAUSE") 1202 return pause_keyboard12031204 x0, y0, x1, y1, feeder_canvas = draw_feeders(1,18,x0, y0, x1, y1, feeder_canvas)12051206 x0 = x0 + 1501207 x1 = x0 + 181208 x0, y0, x1, y1, feeder_canvas = draw_feeders(18,34,x0, y0, x1, y1, feeder_canvas)12091210 x0 = 501211 x1 = x0 + 181212 y0 = 1501213 y1 = y0 - 601214 x0, y0, x1, y1, feeder_canvas = draw_feeders(34,51,x0, y0, x1, y1, feeder_canvas)12151216 x0 = x0 + 1501217 x1 = x0 + 181218 x0, y0, x1, y1, feeder_canvas = draw_feeders(51,67,x0, y0, x1, y1, feeder_canvas)12191220 x0 = 501221 x1 = x0 + 181222 y0 = 5001223 y1 = y0 - 601224 x0, y0, x1, y1 = draw_feeders_label(1,18,x0, y0, x1, y1)12251226 x0 = x0 + 1501227 x1 = x0 + 181228 x0, y0, x1, y1 = draw_feeders_label(18,34,x0, y0, x1, y1)12291230 x0 = 501231 x1 = x0 + 181232 y0 = 1501233 y1 = y0 - 601234 x0, y0, x1, y1 = draw_feeders_label(34,51,x0, y0, x1, y1)12351236 x0 = x0 + 1501237 x1 = x0 + 181238 x0, y0, x1, y1 = draw_feeders_label(51,67,x0, y0, x1, y1)12391240 x0 = 4251241 x1 = x0 + 181242 y0 = 2801243 y1 = y0 + 181244 nozzle_canvas = draw_nozzles(1,9,x0, y0, x1, y1, nozzle_canvas)12451246 x0 = 1801247 y0_text = 5501248 canvas.create_text(x0,y0_text,fill="black",font="Arial 12 bold",1249 text="Total Distance:")1250 counter_d = canvas.create_text(x0+65,y0_text,fill="black",font="Arial 12 bold",anchor="w",1251 text="0.00 mm")12521253 x0 = x0 + 3401254 canvas.create_text(x0,y0_text,fill="black",font="Arial 12 bold",1255 text="Feeder: ")1256 counter_f = canvas.create_text(x0+35,y0_text,fill="black",font="Arial 12 bold",anchor="w",1257 text="0")12581259 x0 = x0 + 1201260 canvas.create_text(x0,y0_text,fill="black",font="Arial 12 bold",1261 text="Nozzle: ")1262 counter_n = canvas.create_text(x0+35,y0_text,fill="black",font="Arial 12 bold",anchor="w",1263 text="0")12641265 x0 = x0 + 1201266 canvas.create_text(x0,y0_text,fill="black",font="Arial 12 bold",1267 text="Comp: ")1268 counter_c = canvas.create_text(x0+35,y0_text,fill="black",font="Arial 12 bold",anchor="w",1269 text="none")12701271 canvas_counters = [counter_d,counter_f,counter_n,counter_c]12721273 RUN_or_PAUSE = canvas.create_text(835,30,fill="black",font="Arial 12 bold",text="Press 'p' to PAUSE")12741275 remaining_feeders = []1276 for i in range(len(nozzle_designation)):1277 remaining_feeders.append(nozzle_designation[i][0])1278 canvas.itemconfig(feeder_canvas[nozzle_designation[i][0]], fill='yellow')1279 filled_nozzle = []1280 distance = 01281 fid_prev = 01282 nid_prev = 01283 pause_keyboard = False1284 canvas.update()1285 canvas.after(2000)1286 for i in range(len(nozzle_designation)):1287 if keyboard.is_pressed('p'):1288 pause_keyboard = True 1289 canvas.update()1290 canvas.after(30)1291 nid = nozzle_designation[i][2]1292 filled_nozzle.append(nid)1293 cid = nozzle_designation[i][1]1294 fid = nozzle_designation[i][0]1295 # Check if we need to move back to the center1296 if i > 0:1297 if nid < nid_prev:1298 fid_prev = 01299 if keyboard.is_pressed('p'):1300 pause_keyboard = True 1301 canvas.update()1302 canvas.after(30) 1303 distance = distance + distance_calc(fid_prev,fid)1304 update_distance(canvas,distance,canvas_counters)1305 for j in range(len(filled_nozzle)):1306 fnid = filled_nozzle[j]1307 canvas.itemconfig(nozzle_canvas[fnid], fill='green')1308 x0,y0 = 425,2801309 animate_moveto(canvas,nozzle_canvas,1,nozzle_canvas,x0, y0)1310 canvas.update()1311 canvas.after(300) 1312 for j in range(len(filled_nozzle)-1):1313 fnid = filled_nozzle[j]1314 canvas.itemconfig(nozzle_canvas[fnid], fill=fill)1315 filled_nozzle = [nid]13161317 # Moving to next feeder1318 x0,y0,x1,y1 = canvas.coords(feeder_canvas[fid])1319 if fid >= 34:1320 y0 = y1 + 51321 else:1322 y0 = y0 - 251323 fid_prev = update_distance_starting_position(nid,fid_prev,nid_prev)1324 update_counters(import_table,canvas,fid,nid,cid,canvas_counters,0)1325 distance = distance + distance_calc(fid_prev,fid)1326 update_distance(canvas,distance,canvas_counters)1327 canvas.itemconfig(nozzle_canvas[nid], fill='green')1328 canvas.itemconfig(feeder_canvas[fid], fill='green')1329 animate_moveto(canvas,nozzle_canvas,nid,nozzle_canvas,x0, y0)1330 if pause_keyboard == True:1331 pause_keyboard = pause_sim(pause_keyboard,RUN_or_PAUSE)1332 canvas.update()1333 canvas.after(300)1334 canvas.itemconfig(nozzle_canvas[nid], fill=fill)1335 remaining_feeders.pop(0)1336 update_remaining_feeders(canvas,fid,remaining_feeders,feeder_canvas)13371338 # canvas.itemconfig(feeder_canvas[fid], fill=fill)1339 nid_prev = nid1340 fid_prev = fid134113421343 # last loop to move nozzles back to the center1344 for j in range(len(filled_nozzle)):1345 fnid = filled_nozzle[j]1346 canvas.itemconfig(nozzle_canvas[fnid], fill='green')1347 x0,y0 = 425,2801348 animate_moveto(canvas,nozzle_canvas,1,nozzle_canvas,x0, y0)1349 canvas.update()1350 canvas.after(700) 1351 for j in range(len(filled_nozzle)):1352 fnid = filled_nozzle[j]1353 canvas.itemconfig(nozzle_canvas[fnid], fill=fill)1354 filled_nozzle = [] 1355 update_counters(import_table,canvas,fid,nid,cid,canvas_counters,1)1356 distance = distance + distance_calc(fid_prev,fid)1357 update_distance(canvas,distance,canvas_counters)1358 print_t("Simulation Complete")1359 ws.mainloop()136013611362##############################################################################################################################################1363# USER INTERFACE1364##############################################################################################################################################1365window = tk.Tk()13661367text = tk.Text(window)1368text.pack()1369text.place(x=30,y=325,height=210,width=615)13701371# Basic setup of window1372window.title("K1830 Pick and Place")1373window.geometry("680x550")1374window.resizable(False, False)13751376# Text in the window1377label1 = Label(window,1378 text="Choose a File",1379 font=("Arial bold", 22),1380 )1381label1.place(x=30,y=30)13821383# Showing files in the folder1384file_view = tk.Listbox(window,width=42,height= 9,font=(11))1385file_view.place(x=30,y=80)13861387for items in os.listdir(import_file_location):1388 if items.endswith(".csv"): # Only shows csv files1389 file_view.insert(0, items)13901391# Function to run the optimization from pre-existing import file1392def run_program_pre(sourcefile,sourcefile_import,import_table,Compdata_table,M_table,N_table,P_table,PCB_table):1393 nozzle_designation,output = shortest_distance_pre(import_table,sourcefile,sourcefile_import,Compdata_table,M_table,N_table,P_table,PCB_table)1394 return nozzle_designation, import_table, output13951396# Function to run the optimization from import file1397def run_program(sourcefile,sourcefile_import,import_table,Compdata_table,M_table,N_table,P_table,PCB_table):1398 import_table = list(csv.reader(open(sourcefile)))1399 import_table = Check_footprints_comments(import_table,Compdata_table)1400 nozzle_designation,output = shortest_distance(import_table,sourcefile,sourcefile_import,Compdata_table,M_table,N_table,P_table,PCB_table)1401 return nozzle_designation, import_table, output14021403# Function for storing the selected listbox value and then runs run_program1404def selected_item(Compdata_table,M_table,N_table,P_table,PCB_table):1405 sourcefile = ''1406 for i in file_view.curselection():1407 sourcefile = "Import/" + file_view.get(i)1408 sourcefile_import = file_view.get(i)1409 if sourcefile == '':1410 print_t("Please Select a CSV file.")1411 return1412 table_check = list(csv.reader(open(sourcefile)))1413 if table_check[0][0] == "#Feeder":1414 Compdata_table,M_table,N_table,P_table,PCB_table = [],[],[],[],[]1415 import_table,Compdata_table,M_table,N_table,P_table,PCB_table = Existing_Table(table_check,Compdata_table,M_table,N_table,P_table,PCB_table)1416 print_t("Running optimization on '" + sourcefile_import + "'")1417 window.update()1418 window.after(20) 1419 x,y,output = run_program_pre(sourcefile,sourcefile_import,import_table,Compdata_table,M_table,N_table,P_table,PCB_table)1420 print_t("Done. Result '" + output + "' stored in Output folder")14211422 elif table_check[0][0] != "Designator":1423 print_t(sourcefile_import + " is not in the correct format.")1424 return1425 else:1426 print_t("Running optimization on '" + sourcefile_import + "'")1427 window.update()1428 window.after(20) 1429 N_table = Nozzle_Suggest(table_check,Footprint_Library_table,N_table)1430 x,y,output = run_program(sourcefile,sourcefile_import,table_check,Compdata_table,M_table,N_table,P_table,PCB_table)1431 print_t("Done. Result '" + output + "' stored in Output folder")14321433# Function for storing the selected listbox value and then runs run_simulation1434def selected_item_sim(Compdata_table,M_table,N_table,P_table,PCB_table):1435 sourcefile = ''1436 for i in file_view.curselection():1437 sourcefile = "Import/" + file_view.get(i)1438 sourcefile_import = file_view.get(i)1439 if sourcefile == '':1440 print_t("Please Select a CSV file.")1441 return1442 table_check = list(csv.reader(open(sourcefile)))1443 if table_check[0][0] == "#Feeder":1444 Compdata_table,M_table,N_table,P_table,PCB_table = [],[],[],[],[]1445 import_table,Compdata_table,M_table,N_table,P_table,PCB_table = Existing_Table(table_check,Compdata_table,M_table,N_table,P_table,PCB_table)1446 print_t("Running Simulation on '" + sourcefile_import + "'")1447 window.update()1448 window.after(20) 1449 nozzle_designation,import_table,x = run_program_pre(sourcefile,sourcefile_import,import_table,Compdata_table,M_table,N_table,P_table,PCB_table)1450 elif table_check[0][0] != "Designator":1451 print_t(sourcefile_import + " is not in the correct format.")1452 return1453 else:1454 print_t("Running Simulation on '" + sourcefile_import + "'")1455 window.update()1456 window.after(20) 1457 N_table = Nozzle_Suggest(table_check,Footprint_Library_table,N_table)1458 nozzle_designation,import_table,x = run_program(sourcefile,sourcefile_import,table_check,Compdata_table,M_table,N_table,P_table,PCB_table)14591460 nozzle_animation(nozzle_designation,import_table)1461 14621463# Exits the program1464def Exit():1465 sys.exit("Done")14661467img_run = PhotoImage(file = file_location + '/Images/Run.png')1468img_run = img_run.zoom(10)1469img_run = img_run.subsample(64)1470button1 = tk.Button(window, text='Run Program',image = img_run,command=lambda: selected_item(Compdata_table,M_table,N_table,P_table,PCB_table))1471button1.place(x=542,y=20)1472button1_ttp = CreateToolTip(button1, \1473 "Run Optimization")147414751476img_sim = PhotoImage(file = file_location + '/Images/Sim.png')1477img_sim = img_sim.zoom(10)1478img_sim = img_sim.subsample(64)1479button2 = tk.Button(window, text='Run Simulation',image = img_sim,command=lambda: selected_item_sim(Compdata_table,M_table,N_table,P_table,PCB_table))1480button2.place(x=542,y=135)1481button2_ttp = CreateToolTip(button2, \1482 "Run Simulation")14831484img_exit = PhotoImage(file = file_location + '/images/Exit.png')1485img_exit = img_exit.zoom(6)1486img_exit = img_exit.subsample(64)1487button3 = tk.Button(window, text='Exit',image = img_exit,command=lambda: Exit(),anchor=E)1488button3.grid(row = 2, column = 6,sticky="ne",rowspan=4)1489button3.place(x=580,y=250)1490button3_ttp = CreateToolTip(button3, \1491 "Exit")14921493# Defining infinite loop ...

Full Screen

Full Screen

cartodb.py

Source:cartodb.py Github

copy

Full Screen

...35 sql_url,36 CDB_USER,37 CDB_KEY))38@task39def import_table(relpath, tablename):40 '''import a table to cartodb'''41 with lcd(cwd):42 execute(run_query, drop_sql(tablename))43 with hide('running'):44 local('%s/import_csv_cartodb.sh %s/%s/%s.csv %s %s'45 % (scripts_path,46 data_path,47 relpath,48 tablename,49 CDB_USER,50 CDB_KEY))51@task52@runs_once53def import_common():...

Full Screen

Full Screen

import.py

Source:import.py Github

copy

Full Screen

...65 # '9ace7c8c-55b4-4c5d-9aa8-e573a5dde9ad')66 #67 # time3 = datetime.now()68 # print(str(time3 - time2))69 # importer.import_table('enum_area_type_values')70 # importer.import_table('area')71 # importer.import_table('enum_artist_alias_type_values')72 # importer.import_table('enum_artist_type_values')73 # importer.import_table('enum_release_group_type_values')74 # importer.import_table('enum_release_status_values')75 # importer.import_table('enum_language_values')76 # importer.import_table('enum_gender_values')77 # importer.import_table('enum_medium_format_values')78 # importer.import_table('enum_work_type_values')79 # importer.import_table('enum_place_type_values')80 # importer.import_table('enum_series_type_values')81 # importer.import_table('enum_label_type_values')82 # importer.import_table('artist', artists)83 # importer.import_table('artist')84 # importer.import_table('artist_credit')85 # importer.import_table('release_group')86 # importer.import_table('release')87 # importer.import_table('medium')88 # importer.import_table('recording')89 # importer.import_table('track')90 # importer.import_table('work')91def main():92 main_parser = argparse.ArgumentParser(93 description='Import data from MusicBrainz DB dumps',94 formatter_class=argparse.RawTextHelpFormatter)95 sps = main_parser.add_subparsers(96 dest='command', metavar='command',97 help='''The following commands are available: update-dump, import''')98 parser = sps.add_parser('update-dump',99 description='Download the latest '100 'MusicBrainz DB dump')101 parser.add_argument('--verbose', dest='verbose', action='store_true',102 help='Be verbose')103 parser = sps.add_parser('import',104 description='Import data from the MB DB dump')...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful