1
0

gui.py 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204
  1. import os
  2. import webbrowser
  3. import tkinter
  4. from newtkinter import askopenfilename, asksaveasfilename
  5. import tkinter.messagebox
  6. from tkinter.scrolledtext import ScrolledText
  7. import chardet
  8. import datascience.controller
  9. from system import exception_catch, QueueController
  10. queue_controller = QueueController()
  11. render_dict = {} # 保存了画图的List
  12. learn_dict = {} # 保存数据处理
  13. PATH = os.getcwd()
  14. sheet_list = []
  15. machine_controller = datascience.controller.MachineLearner()
  16. SCREEN = tkinter.Tk()
  17. bg_color = "#FFFAFA" # 主颜色
  18. buttom_bg_color = "#FFFAFA" # 按钮颜色
  19. word_color = "#000000" # 文字颜色
  20. SCREEN["bg"] = bg_color
  21. FONT = ("黑体", 11) # 设置字体
  22. FONT1 = ("黑体", 13)
  23. SCREEN.title("CoTan数据处理")
  24. SCREEN.resizable(width=False, height=False)
  25. SCREEN.geometry("+10+10") # 设置所在位置
  26. gui_width = 13 # 标准宽度
  27. gui_height = 2
  28. row = 0
  29. column = 0
  30. stored_list = []
  31. clean_list = []
  32. # 层叠多图
  33. base_image = None
  34. top_image = None
  35. # 数据清洗
  36. clean_default_script = """#输入你的数据清洗执行代码
  37. Done_Row=[] #输入操作的行号
  38. Done_Column=[] #输入操作的列号
  39. axis=True #True-操作行,False-操作列
  40. name='' #方法代号
  41. def check(data, row, column, get, R, C): #检查方法
  42. return True
  43. def done(data, row, column, get, R, C): #应用修正方法
  44. return DEL
  45. """
  46. clean_help = """
  47. 使用Python代码进行数据清洗
  48. 1)代码结构
  49. Done_Row=[] 代码用来检测的数据的列号
  50. Done_Column=[] 代码用来检测的数据的行号
  51. 不在以上指定范围内的数据将不会被检测,若为空则整个表格检测
  52. axis 执行删除方法时删除行或者列
  53. name 方法代号
  54. check 检查方法
  55. 输入:当前的值(输入的是一个值而不是一行(列)或整个列表)
  56. 输入:row和column当前值来自的行号(row)和列号(column)
  57. 输入:get当前检查的所有数据:类型是表格
  58. 输入:R和C当前值所来自的行和列的所有数据:类型是一维表格
  59. 输出:输出布尔为True代表该值可以使用,输出布尔为假表示该值不可使用
  60. done 不可使用的数值改造方法
  61. 输入:内容同上
  62. 输出:改造值或者DEL
  63. DEL:代表删除改值所在的行(axis=True)或列(axis=False)
  64. 2)扩展
  65. 默认:pd-pandas,re-re[正则表达式],Sheet-包含所有表格,用Sheet['name']访问名字为name的表格(注意引号别漏了)
  66. 支持:可以使用import导入语句,支持python语法
  67. """
  68. drawing_parameters = """
  69. 输入python变量赋值代码:渲染设置
  70. title #设置标题:str
  71. vice_title #设置副标题:str
  72. show_Legend #是否显示图例:bool
  73. show_Visual_mapping #是否使用视觉映射:bool
  74. is_color_Visual_mapping #是否为颜色视觉映射:bool[否则为大小视觉映射]
  75. min_Visual_mapping #映射的最小值
  76. max_Visual_mapping #映射的最大值
  77. ......(我太懒了, 设置太多不想写了)
  78. """
  79. class UIAPI:
  80. @staticmethod
  81. @exception_catch()
  82. def add_from_python_gui():
  83. file_dir = askopenfilename(
  84. title="选择载入的py", filetypes=[("Python", ".py"), ("Txt", ".txt")]
  85. )
  86. name = sheet_name.get().replace(" ", "")
  87. if name == "":
  88. name = os.path.splitext(os.path.split(file_dir)[1])[0]
  89. with open(file_dir, "r") as f:
  90. code = f.read()
  91. return code, name
  92. @staticmethod
  93. @exception_catch()
  94. def get_sheet_name_gui(): # 获得名字统一接口
  95. global sheet_list
  96. try:
  97. return sheet_list[sheet_box.curselection()[0]]
  98. except IndexError:
  99. try:
  100. return sheet_list[0]
  101. except IndexError:
  102. return None
  103. @staticmethod
  104. @exception_catch()
  105. def update_sheet_box_gui():
  106. global SCREEN, sheet_box, sheet_list
  107. sheet_list = machine_controller.get_sheet_list()
  108. sheet_box.delete(0, tkinter.END)
  109. sheet_box.insert(tkinter.END, *sheet_list)
  110. @staticmethod
  111. @exception_catch()
  112. def update_combo_box_gui():
  113. overlap_box.delete(0, tkinter.END)
  114. if base_image is not None:
  115. overlap_box.insert(tkinter.END, f"底图: {base_image}")
  116. if top_image is not None:
  117. overlap_box.insert(tkinter.END, f"顶图: {top_image}")
  118. @staticmethod
  119. @exception_catch()
  120. def add_csv_gui():
  121. file_dir = askopenfilename(title="选择载入的CSV", filetypes=[("CSV", ".csv")])
  122. csv_sep = sep.get()
  123. csv_encoding = encoding.get()
  124. str_ = bool(str_must.get())
  125. index = bool(index_must.get())
  126. name = sheet_name.get().replace(" ", "")
  127. if name == "":
  128. name = os.path.splitext(os.path.split(file_dir)[1])[0]
  129. if csv_encoding == "":
  130. with open(file_dir, "rb") as f:
  131. csv_encoding = chardet.detect(f.read())["encoding"]
  132. if csv_sep == "":
  133. csv_sep = ","
  134. return csv_encoding, csv_sep, file_dir, index, name, str_
  135. @staticmethod
  136. @exception_catch()
  137. def to_csv_gui():
  138. save_dir = asksaveasfilename(title="选择保存的CSV", filetypes=[("CSV", ".csv")])
  139. csv_sep = sep.get()
  140. return csv_sep, save_dir
  141. @staticmethod
  142. @exception_catch()
  143. def update_index_box_gui(index):
  144. global SCREEN, index_box
  145. index_box.delete(0, tkinter.END)
  146. index_box.insert(tkinter.END, *index)
  147. @staticmethod
  148. @exception_catch()
  149. def vitables_gui(data, name):
  150. global bg_color, FONT1
  151. new_top = tkinter.Toplevel(bg=bg_color)
  152. new_top.title(name)
  153. new_top.geometry("+10+10") # 设置所在位置
  154. text = ScrolledText(new_top, font=FONT1, height=50)
  155. text.pack(fill=tkinter.BOTH)
  156. text.insert("0.0", data)
  157. text.config(state=tkinter.DISABLED)
  158. new_top.resizable(width=False, height=False)
  159. @staticmethod
  160. @exception_catch()
  161. def get_des_bool_gui():
  162. return bool(des_bool.get())
  163. @staticmethod
  164. @exception_catch()
  165. def sort_by_column_gui():
  166. ascending = not bool(ascending_type.get())
  167. new = bool(ascending_new.get())
  168. return new, ascending
  169. @staticmethod
  170. @exception_catch()
  171. def add_baseline_gui(ascending_type_, sort_by_):
  172. ascending = not bool(ascending_type_.get())
  173. value = int(sort_by_.get())
  174. return ascending, value
  175. @staticmethod
  176. @exception_catch()
  177. def update_sort_box_gui():
  178. global stored_list, stored_box
  179. re = []
  180. d = {True: "正序", False: "倒叙"}
  181. for i in stored_list:
  182. re.append(f"列号:{i[0]}, 排序方式{d[i[1]]}")
  183. stored_box.delete(0, tkinter.END)
  184. stored_box.insert(tkinter.END, *re)
  185. @staticmethod
  186. @exception_catch()
  187. def get_stored_box_index_gui():
  188. return stored_box.curselection()[0]
  189. @staticmethod
  190. @exception_catch()
  191. def get_ascending_new_gui():
  192. new = bool(ascending_new.get())
  193. return new
  194. @staticmethod
  195. @exception_catch()
  196. def slice_data_gui():
  197. def split_slice_core(slice_list, func_type):
  198. a = []
  199. for i in slice_list:
  200. b = i.get().replace(" ", "")
  201. if b == "":
  202. a.append(None)
  203. else:
  204. try:
  205. a.append(func_type(b))
  206. except ValueError:
  207. a.append(None)
  208. if a[0] is not None and a[1] is None:
  209. a[1] = a[0] + 1
  210. a[2] = None
  211. return a
  212. the_column_type = column_type.get()
  213. is_iloc = True
  214. if the_column_type == 0: # 输入的列号
  215. column_ = slice(*split_slice_core(column_clist, int))
  216. elif the_column_type == 1:
  217. is_iloc = False
  218. column_ = slice(*split_slice_core(column_clist, str))
  219. else:
  220. get = column_clist[0].get().replace(" ", "").split(",")
  221. column_ = []
  222. for i in get:
  223. try:
  224. column_.append(int(i))
  225. except ValueError:
  226. pass
  227. the_row_type = row_type.get()
  228. if the_row_type == 0: # 输入的列号
  229. row_ = slice(*split_slice_core(row_clist, int))
  230. elif the_row_type == 1:
  231. row_ = slice(*split_slice_core(row_clist, str))
  232. else:
  233. get = row_clist[0].get().replace(" ", "").split(",")
  234. row_ = []
  235. for i in get:
  236. try:
  237. row_.append(int(i))
  238. except ValueError:
  239. pass
  240. new = bool(slice_new.get())
  241. return column_, is_iloc, new, row_
  242. @staticmethod
  243. @exception_catch()
  244. def del_data_gui():
  245. column_ = column_clist[0].get().replace(" ", "").split(",")
  246. row_ = row_clist[0].get().replace(" ", "").split(",")
  247. new = bool(slice_new.get())
  248. return column_, new, row_
  249. @staticmethod
  250. @exception_catch()
  251. def get_clean_code_gui():
  252. exp = clean_code.get("0.0", tkinter.END)
  253. return exp
  254. @staticmethod
  255. @exception_catch()
  256. def view_cleaning_script_gui():
  257. name = clean_list[API.get_clean_func_box_index_gui()]
  258. API.update_clean_code(machine_controller.get_clean_code(name))
  259. @staticmethod
  260. @exception_catch()
  261. def get_clean_func_box_index_gui():
  262. return clean_func_box.curselection()[0]
  263. @staticmethod
  264. @exception_catch()
  265. def show_dictionary_gui():
  266. tkinter.messagebox.showinfo("帮助字典", clean_help)
  267. @staticmethod
  268. @exception_catch()
  269. def open_python_for_clean_gui():
  270. global clean_code
  271. file_dir = askopenfilename(
  272. title="打开Python脚本", filetypes=[("Python", ".py"), ("TXT", ".txt")]
  273. )
  274. with open(file_dir) as f:
  275. get = f.read()
  276. clean_code.delete("0.0", tkinter.END)
  277. clean_code.insert("0.0", get)
  278. @staticmethod
  279. @exception_catch()
  280. def reset_clean_code_gui():
  281. global clean_code, clean_default_script
  282. API.update_clean_code(clean_default_script)
  283. @staticmethod
  284. @exception_catch()
  285. def update_render_box_gui():
  286. global render_dict, render_box, machine_controller
  287. render_dict = machine_controller.get_all_render()
  288. render_box.delete(0, tkinter.END)
  289. render_box.insert(tkinter.END, *render_dict.keys())
  290. @staticmethod
  291. @exception_catch()
  292. def get_draw_as_well_gui():
  293. return bool(draw_as_well.get())
  294. @staticmethod
  295. @exception_catch()
  296. def render_box_index_gui():
  297. return render_box.curselection()[0]
  298. @staticmethod
  299. @exception_catch()
  300. def rendering_one_gui():
  301. render_dir = asksaveasfilename(title="选择渲染保存地址", filetypes=[("HTML", ".html")])
  302. try:
  303. assert render_dir.startswith(".html")
  304. except AssertionError:
  305. render_dir += ".html"
  306. return render_dir
  307. @staticmethod
  308. @exception_catch()
  309. def rendering_gui():
  310. render_dir = asksaveasfilename(title="选择渲染保存地址", filetypes=[("HTML", ".html")])
  311. try:
  312. assert render_dir.startswith(".html")
  313. except AssertionError:
  314. render_dir += ".html"
  315. return render_dir
  316. @staticmethod
  317. @exception_catch()
  318. def set_dtype_gui():
  319. type_ = bool(dtype_func.get())
  320. name = API.get_sheet_name_gui()
  321. column_list = dtype_column.get().split(",")
  322. if column_list == [""]:
  323. column_list = []
  324. dtype = dtype_input.get()
  325. wrong = dtype_wrong.get()
  326. return column_list, dtype, name, type_, wrong
  327. @staticmethod
  328. @exception_catch()
  329. def datetime_index_gui():
  330. is_column = bool(replace_index.get()) # 操作行名-False,操作列名-True
  331. save = bool(replace_type[0].get())
  332. k = ["start", "end", "freq"]
  333. init = {}
  334. for i in range(len(date_input)):
  335. data = date_input[i].get()
  336. if data == "":
  337. continue
  338. init[k[i]] = data
  339. if len(init) == 3:
  340. if bool(date_type.get()): # 使用间隔
  341. del init["end"]
  342. else:
  343. del init["freq"]
  344. return init, is_column, save
  345. @staticmethod
  346. @exception_catch()
  347. def num_with_name_gui():
  348. is_column = bool(replace_index.get()) # 操作行名-False,操作列名-True
  349. save = bool(replace_type[0].get())
  350. return is_column, save
  351. @staticmethod
  352. @exception_catch()
  353. def num_to_name_gui():
  354. is_column = bool(replace_index.get()) # 操作行名-False,操作列名-True
  355. save = bool(replace_type[0].get())
  356. return is_column, save
  357. @staticmethod
  358. @exception_catch()
  359. def change_index_gui():
  360. is_column = bool(replace_index.get()) # 操作行名-False,操作列名-True
  361. iloc = int(replace_iloc.get()) # 替换的列号(行号)
  362. save = bool(replace_type[0].get())
  363. drop = not bool(replace_type[1].get())
  364. return drop, iloc, is_column, save
  365. @staticmethod
  366. @exception_catch()
  367. def replace_index_func_gui():
  368. the_replace_dict = eval(replace_dict.get())
  369. is_column = bool(replace_index.get()) # 操作行-False,操作列-True
  370. save = bool(replace_type[0].get())
  371. return is_column, save, the_replace_dict
  372. @staticmethod
  373. @exception_catch()
  374. def update_leaner_box_gui():
  375. global learn_dict, learner_box
  376. learn_dict = machine_controller.return_learner()
  377. learner_box.delete(0, tkinter.END)
  378. learner_box.insert(tkinter.END, *learn_dict.keys())
  379. @staticmethod
  380. @exception_catch()
  381. def get_data_split_gui():
  382. try:
  383. split = float(data_split.get())
  384. assert not split < 0 or 1 < split
  385. except (AssertionError, ValueError):
  386. split = 0.3
  387. return split
  388. @staticmethod
  389. @exception_catch()
  390. def set_learner_gui():
  391. global chose_learner
  392. chose_learner.set(API.get_learner_name_gui(True))
  393. @staticmethod
  394. @exception_catch()
  395. def get_learner_name_gui(learner_type=False):
  396. global learn_dict, learner_box, chose_learner
  397. if learner_type:
  398. try:
  399. return list(learn_dict.keys())[learner_box.curselection()[0]]
  400. except IndexError:
  401. try:
  402. return list(learn_dict.keys)[0]
  403. except IndexError:
  404. return None
  405. else:
  406. return chose_learner.get()
  407. @staticmethod
  408. @exception_catch()
  409. def askokcancel_gui(messgae):
  410. return tkinter.messagebox.askokcancel("提示", messgae)
  411. @staticmethod
  412. @exception_catch()
  413. def show_tips_gui():
  414. tkinter.messagebox.showinfo("使用提示", drawing_parameters)
  415. @staticmethod
  416. @exception_catch()
  417. def show_sorry_gui():
  418. tkinter.messagebox.showinfo("非常抱歉", "高级别的机器学习请到机器学习板块深入研究...")
  419. class API(UIAPI):
  420. @staticmethod
  421. @exception_catch()
  422. def clear_rendering():
  423. machine_controller.clean_render()
  424. API.update_render_box_gui()
  425. @staticmethod
  426. @exception_catch()
  427. def del_form():
  428. name = API.get_sheet_name_gui()
  429. machine_controller.del_sheet(name)
  430. API.update_sheet_box_gui()
  431. @staticmethod
  432. @exception_catch()
  433. def del_learner():
  434. learner = API.get_learner_name_gui(True)
  435. set_learne = API.get_learner_name_gui(False) # 获取学习器Learner
  436. if set_learne != learner:
  437. machine_controller.del_leaner(learner)
  438. API.update_leaner_box_gui()
  439. @staticmethod
  440. @exception_catch()
  441. def visual_learner():
  442. learner = API.get_learner_name_gui(True)
  443. data = machine_controller.visual_learner(
  444. learner, API.askokcancel_gui(f"是否将数据生成表格。\n(可绘制成散点图对比数据)")
  445. )
  446. API.vitables_gui(
  447. f"对象:{learner}\n\n{data[0]}\n\n\n{data[1]}", f"CoTan数据处理 查看数据:{learner}"
  448. )
  449. API.update_sheet_box_gui()
  450. @staticmethod
  451. @exception_catch()
  452. def get_learner_config():
  453. return learner_parameters.get("0.0", tkinter.END)
  454. @staticmethod
  455. @exception_catch()
  456. def test_learner():
  457. name = API.get_sheet_name_gui() # 表格数据
  458. learner = API.get_learner_name_gui()
  459. try:
  460. split = float(data_split.get())
  461. assert not split < 0 or 1 < split
  462. except (AssertionError, ValueError):
  463. split = 0.3
  464. socore = machine_controller.training_machine(
  465. name, learner, Score_Only=True, split=split
  466. )[1]
  467. tkinter.messagebox.showinfo("测试完成", f"针对测试数据评分结果为:{socore}")
  468. @staticmethod
  469. @exception_catch()
  470. def predict_learner():
  471. name = API.get_sheet_name_gui() # 表格数据
  472. learner = API.get_learner_name_gui()
  473. data = machine_controller.predict(name, learner)
  474. title = f"CoTan数据处理 表格:{name} 学习器:{learner}"
  475. API.vitables_gui(data, title)
  476. API.update_sheet_box_gui()
  477. @staticmethod
  478. @exception_catch()
  479. def fit_learner():
  480. name = API.get_sheet_name_gui() # 表格数据
  481. learner = API.get_learner_name_gui()
  482. split = API.get_data_split_gui()
  483. socore = machine_controller.training_machine(
  484. name, learner, parameters=API.get_learner_config(), split=split
  485. )
  486. tkinter.messagebox.showinfo(
  487. "训练完成",
  488. f"针对训练数据({(1 - split) * 100}%)评分结果为:{socore[0]}\n"
  489. f"针对测试数据评分({split * 100}%)结果为:{socore[1]}",
  490. )
  491. @staticmethod
  492. @exception_catch()
  493. def add_knn_class():
  494. API.add_learner_core("Knn_class")
  495. @staticmethod
  496. @exception_catch()
  497. def add_logistic_regression():
  498. API.add_learner_core("LogisticRegression")
  499. @staticmethod
  500. @exception_catch()
  501. def add_lasso():
  502. API.add_learner_core("Lasso")
  503. @staticmethod
  504. @exception_catch()
  505. def add_knn_regression():
  506. API.add_learner_core("Knn")
  507. @staticmethod
  508. @exception_catch()
  509. def add_ridge():
  510. API.add_learner_core("Ridge")
  511. @staticmethod
  512. @exception_catch()
  513. def add_generalized_linear():
  514. API.add_learner_core("Line")
  515. @staticmethod
  516. @exception_catch()
  517. def add_learner_core(learner_type): # 添加Lenear的核心
  518. machine_controller.add_learner(learner_type, parameters=API.get_learner_config())
  519. API.update_leaner_box_gui()
  520. @staticmethod
  521. @exception_catch()
  522. def feature_extraction():
  523. name = API.get_sheet_name_gui()
  524. machine_controller.decision_tree_classifier(name)
  525. API.update_sheet_box_gui()
  526. @staticmethod
  527. @exception_catch()
  528. def replace_index_func():
  529. name = API.get_sheet_name_gui()
  530. is_column, save, the_replace_dict = API.replace_index_func_gui()
  531. machine_controller.replace_index(name, is_column, the_replace_dict, save)
  532. API.update_sheet_box_gui()
  533. @staticmethod
  534. @exception_catch()
  535. def change_index():
  536. name = API.get_sheet_name_gui() # 名字
  537. drop, iloc, is_column, save = API.change_index_gui()
  538. machine_controller.change_index(name, is_column, iloc, save, drop)
  539. API.update_sheet_box_gui()
  540. @staticmethod
  541. @exception_catch()
  542. def num_to_name():
  543. name = API.get_sheet_name_gui() # 名字
  544. is_column, save = API.num_to_name_gui()
  545. machine_controller.number_naming(name, is_column, save)
  546. API.update_sheet_box_gui()
  547. @staticmethod
  548. @exception_catch()
  549. def num_with_name():
  550. name = API.get_sheet_name_gui() # 名字
  551. is_column, save = API.num_with_name_gui()
  552. machine_controller.name_with_number(name, is_column, save)
  553. API.update_sheet_box_gui()
  554. @staticmethod
  555. @exception_catch()
  556. def datetime_index(is_date=True):
  557. name = API.get_sheet_name_gui() # 名字
  558. init, is_column, save = API.datetime_index_gui()
  559. if is_date:
  560. machine_controller.date_index(name, is_column, save, **init)
  561. else:
  562. machine_controller.time_naming(name, is_column, save, **init)
  563. API.update_sheet_box_gui()
  564. @staticmethod
  565. @exception_catch()
  566. def date_index():
  567. API.datetime_index(True)
  568. @staticmethod
  569. @exception_catch()
  570. def time_index():
  571. API.datetime_index(False)
  572. @staticmethod
  573. @exception_catch()
  574. def set_dtype():
  575. column_list, dtype, name, type_, wrong = API.set_dtype_gui()
  576. if type_: # 软转换
  577. if wrong != "ignore":
  578. wrong = "coerce"
  579. machine_controller.set_dtype(name, column_list, dtype, wrong)
  580. else:
  581. machine_controller.as_dtype(name, column_list, dtype, "ignore")
  582. API.update_sheet_box_gui()
  583. @staticmethod
  584. @exception_catch()
  585. def python_render(): # 导入绘制方法
  586. file_dir = askopenfilename(
  587. title="打开Python脚本", filetypes=[("Python", ".py"), ("TXT", ".txt")]
  588. )
  589. with open(file_dir) as f:
  590. code = f.read()
  591. API.new_render(machine_controller.custom_graph(code), "自定义图")
  592. @staticmethod
  593. @exception_catch()
  594. def get_rendering_parameters(): # 获取画图的args
  595. return rendering_parameters.get("0.0", tkinter.END)
  596. @staticmethod
  597. @exception_catch()
  598. def rendering():
  599. render_dir = API.rendering_gui()
  600. webbrowser.open(
  601. machine_controller.render_all(API.get_rendering_parameters(), render_dir)
  602. )
  603. API.update_render_box_gui()
  604. @staticmethod
  605. @exception_catch()
  606. def rendering_one():
  607. render_dir = API.rendering_one_gui()
  608. list(render_dict.values())[API.render_box_index_gui()].render(render_dir)
  609. webbrowser.open(render_dir)
  610. API.update_render_box_gui()
  611. @staticmethod
  612. @exception_catch()
  613. def make_overlap():
  614. global top_image, base_image
  615. if base_image is not None and top_image is not None:
  616. try:
  617. API.new_render(machine_controller.overlap(base_image, top_image), f"合成图")
  618. except BaseException:
  619. raise
  620. base_image = None
  621. top_image = None
  622. API.update_combo_box_gui()
  623. @staticmethod
  624. @exception_catch()
  625. def add_basemap():
  626. global base_image
  627. base_image = list(render_dict.keys())[API.render_box_index_gui()]
  628. API.update_combo_box_gui()
  629. @staticmethod
  630. @exception_catch()
  631. def add_top_image():
  632. global top_image
  633. top_image = list(render_dict.keys())[API.render_box_index_gui()]
  634. API.update_combo_box_gui()
  635. @staticmethod
  636. @exception_catch()
  637. def del_rendering():
  638. key = list(render_dict.keys())[API.render_box_index_gui()]
  639. machine_controller.del_render(key)
  640. API.update_render_box_gui()
  641. @staticmethod
  642. @exception_catch()
  643. def new_render(c, name):
  644. if API.get_draw_as_well_gui():
  645. c.render(fr"{PATH}{os.sep}{name}.html")
  646. API.update_render_box_gui()
  647. @staticmethod
  648. @exception_catch()
  649. def to_geo():
  650. name = API.get_sheet_name_gui()
  651. API.new_render(machine_controller.to_geo(name, API.get_rendering_parameters()), "Geo地图")
  652. @staticmethod
  653. @exception_catch()
  654. def to_map():
  655. name = API.get_sheet_name_gui()
  656. API.new_render(machine_controller.to_map(name, API.get_rendering_parameters()), "Map地图")
  657. @staticmethod
  658. @exception_catch()
  659. def to_scattergeo():
  660. name = API.get_sheet_name_gui()
  661. API.new_render(
  662. machine_controller.to_scattergeo(name, API.get_rendering_parameters()), "Geo点地图"
  663. )
  664. @staticmethod
  665. @exception_catch()
  666. def to_treemap():
  667. name = API.get_sheet_name_gui()
  668. API.new_render(machine_controller.to_tree_map(name, API.get_rendering_parameters()), "矩形树图")
  669. @staticmethod
  670. @exception_catch()
  671. def to_tree():
  672. name = API.get_sheet_name_gui()
  673. API.new_render(machine_controller.to_tree(name, API.get_rendering_parameters()), "树状图")
  674. @staticmethod
  675. @exception_catch()
  676. def to_sankey():
  677. name = API.get_sheet_name_gui()
  678. API.new_render(machine_controller.to_sankey(name, API.get_rendering_parameters()), "桑基图")
  679. @staticmethod
  680. @exception_catch()
  681. def to_sunburst():
  682. name = API.get_sheet_name_gui()
  683. API.new_render(machine_controller.to_sunburst(name, API.get_rendering_parameters()), "旭日图")
  684. @staticmethod
  685. @exception_catch()
  686. def to_theme_river():
  687. name = API.get_sheet_name_gui()
  688. API.new_render(
  689. machine_controller.to_theme_river(name, API.get_rendering_parameters()), "河流图"
  690. )
  691. @staticmethod
  692. @exception_catch()
  693. def to_calendar():
  694. name = API.get_sheet_name_gui()
  695. API.new_render(machine_controller.to_calendar(name, API.get_rendering_parameters()), "日历图")
  696. @staticmethod
  697. @exception_catch()
  698. def to_gauge():
  699. name = API.get_sheet_name_gui()
  700. API.new_render(machine_controller.to_gauge(name, API.get_rendering_parameters()), "仪表图")
  701. @staticmethod
  702. @exception_catch()
  703. def to_liquid():
  704. name = API.get_sheet_name_gui()
  705. API.new_render(machine_controller.to_liquid(name, API.get_rendering_parameters()), "水球图")
  706. @staticmethod
  707. @exception_catch()
  708. def to_line3d():
  709. name = API.get_sheet_name_gui()
  710. API.new_render(machine_controller.to_line3d(name, API.get_rendering_parameters()), "3D折线图")
  711. @staticmethod
  712. @exception_catch()
  713. def to_scatter3d():
  714. name = API.get_sheet_name_gui()
  715. API.new_render(
  716. machine_controller.to_scatter3d(name, API.get_rendering_parameters()), "3D散点图"
  717. )
  718. @staticmethod
  719. @exception_catch()
  720. def to_bar3d():
  721. name = API.get_sheet_name_gui()
  722. API.new_render(machine_controller.to_bar3d(name, API.get_rendering_parameters()), "3D柱状图")
  723. @staticmethod
  724. @exception_catch()
  725. def to_word_cloud():
  726. name = API.get_sheet_name_gui()
  727. API.new_render(
  728. machine_controller.to_word_cloud(name, API.get_rendering_parameters()), "词云图"
  729. )
  730. @staticmethod
  731. @exception_catch()
  732. def to_radar():
  733. name = API.get_sheet_name_gui()
  734. API.new_render(machine_controller.to_radar(name, API.get_rendering_parameters()), "雷达图")
  735. @staticmethod
  736. @exception_catch()
  737. def to_polar():
  738. name = API.get_sheet_name_gui()
  739. API.new_render(machine_controller.to_polar(name, API.get_rendering_parameters()), "极坐标图")
  740. @staticmethod
  741. @exception_catch()
  742. def to_pie():
  743. name = API.get_sheet_name_gui()
  744. API.new_render(machine_controller.to_pie(name, API.get_rendering_parameters()), "饼图")
  745. @staticmethod
  746. @exception_catch()
  747. def to_parallel():
  748. name = API.get_sheet_name_gui()
  749. API.new_render(machine_controller.to_parallel(name, API.get_rendering_parameters()), "多轴图")
  750. @staticmethod
  751. @exception_catch()
  752. def to_graph():
  753. name = API.get_sheet_name_gui()
  754. API.new_render(machine_controller.to_graph(name, API.get_rendering_parameters()), "关系图")
  755. @staticmethod
  756. @exception_catch()
  757. def to_format_graph():
  758. name = API.get_sheet_name_gui()
  759. API.new_render(
  760. machine_controller.to_format_graph(name, API.get_rendering_parameters()), "关系图"
  761. )
  762. @staticmethod
  763. @exception_catch()
  764. def to_funnel():
  765. name = API.get_sheet_name_gui()
  766. API.new_render(machine_controller.to_funnel(name, API.get_rendering_parameters()), "漏斗图")
  767. @staticmethod
  768. @exception_catch()
  769. def to_heat_map():
  770. name = API.get_sheet_name_gui()
  771. API.new_render(machine_controller.to_heatmap(name, API.get_rendering_parameters()), "热力图")
  772. @staticmethod
  773. @exception_catch()
  774. def to_boxpolt():
  775. name = API.get_sheet_name_gui()
  776. API.new_render(machine_controller.to_boxpolt(name, API.get_rendering_parameters()), "箱形图")
  777. @staticmethod
  778. @exception_catch()
  779. def to_pictorialbar():
  780. name = API.get_sheet_name_gui()
  781. API.new_render(
  782. machine_controller.to_pictorialbar(name, API.get_rendering_parameters()), "象形柱状图"
  783. )
  784. @staticmethod
  785. @exception_catch()
  786. def to_scatter():
  787. name = API.get_sheet_name_gui()
  788. API.new_render(machine_controller.to_scatter(name, API.get_rendering_parameters()), "散点图")
  789. @staticmethod
  790. @exception_catch()
  791. def to_line():
  792. name = API.get_sheet_name_gui()
  793. API.new_render(machine_controller.to_line(name, API.get_rendering_parameters()), "折线图")
  794. @staticmethod
  795. @exception_catch()
  796. def to_bar():
  797. name = API.get_sheet_name_gui()
  798. API.new_render(machine_controller.to_bar(name, API.get_rendering_parameters()), "柱状图")
  799. @staticmethod
  800. @exception_catch()
  801. def update_clean_code(clean_default_script_):
  802. clean_code.delete("0.0", tkinter.END)
  803. clean_code.insert("0.0", clean_default_script_)
  804. @staticmethod
  805. @exception_catch()
  806. def empty_cleaning_script():
  807. machine_controller.del_all_clean_func()
  808. API.update_sheet_box_gui()
  809. @staticmethod
  810. @exception_catch()
  811. def execute_cleaning_script():
  812. name = API.get_sheet_name_gui()
  813. data = machine_controller.data_clean(name)
  814. title = f"CoTan数据处理 表格:{name}.数据清洗"
  815. API.vitables_gui(data, title)
  816. API.update_sheet_box_gui()
  817. @staticmethod
  818. @exception_catch()
  819. def del_cleaning_script():
  820. name = clean_list[API.get_clean_func_box_index_gui()]
  821. machine_controller.del_clean_func(name)
  822. API.update_cleaning_script_box()
  823. @staticmethod
  824. @exception_catch()
  825. def update_cleaning_script_box():
  826. clean_list_ = machine_controller.get_clean_func()
  827. clean_func_box.delete(0, tkinter.END)
  828. clean_func_box.insert(tkinter.END, *clean_list_)
  829. @staticmethod
  830. @exception_catch()
  831. def add_cleaning_script():
  832. exp = API.get_clean_code_gui()
  833. machine_controller.add_clean_func(exp)
  834. API.update_cleaning_script_box()
  835. @staticmethod
  836. @exception_catch()
  837. def clean_nan_row():
  838. name = API.get_sheet_name_gui()
  839. data = machine_controller.del_nan(name, True)
  840. title = f"CoTan数据处理 表格:{name}.NaN"
  841. API.vitables_gui(data, title)
  842. API.update_sheet_box_gui()
  843. @staticmethod
  844. @exception_catch()
  845. def is_nan():
  846. name = API.get_sheet_name_gui()
  847. data = machine_controller.is_nan(name)
  848. title = f"CoTan数据处理 表格:{name}.NaN"
  849. API.vitables_gui(data, title)
  850. API.update_sheet_box_gui()
  851. @staticmethod
  852. @exception_catch()
  853. def to_bool():
  854. the_bool_exp = bool_exp.get()
  855. name = API.get_sheet_name_gui()
  856. data = machine_controller.to_bool(name, the_bool_exp, True)
  857. title = f"CoTan数据处理 表格:{name} 布尔化"
  858. API.vitables_gui(data, title)
  859. API.update_sheet_box_gui()
  860. @staticmethod
  861. @exception_catch()
  862. def del_data():
  863. name = API.get_sheet_name_gui()
  864. column_, new, row_ = API.del_data_gui()
  865. data = "None 你的操作不被允许"
  866. try:
  867. data = machine_controller.del_slice(name, column_, row_, new)
  868. except BaseException:
  869. raise
  870. finally:
  871. title = f"CoTan数据处理 表格:{name}"
  872. API.vitables_gui(data, title)
  873. API.update_sheet_box_gui()
  874. @staticmethod
  875. @exception_catch()
  876. def slice_data():
  877. column_, is_iloc, new, row_ = API.slice_data_gui()
  878. name = API.get_sheet_name_gui()
  879. data = "None 你的操作不被允许"
  880. try:
  881. data = machine_controller.get_slice(name, column_, row_, is_iloc, new)
  882. except BaseException:
  883. raise
  884. finally:
  885. title = f"CoTan数据处理 表格:{name}"
  886. API.vitables_gui(data, title)
  887. API.update_sheet_box_gui()
  888. @staticmethod
  889. @exception_catch()
  890. def sample_data():
  891. name = API.get_sheet_name_gui()
  892. new = API.get_ascending_new_gui()
  893. data = machine_controller.sample(name, new)
  894. title = f"CoTan数据处理 打乱表格:{name}"
  895. API.vitables_gui(data, title)
  896. API.update_sheet_box_gui()
  897. @staticmethod
  898. @exception_catch()
  899. def stored_value():
  900. name = API.get_sheet_name_gui()
  901. new = API.get_ascending_new_gui()
  902. data = machine_controller.stored_value(name, stored_list, new)
  903. title = f"CoTan数据处理 表格:{name}.Stored"
  904. API.vitables_gui(data, title)
  905. API.update_sheet_box_gui()
  906. @staticmethod
  907. @exception_catch()
  908. def del_baseline():
  909. global stored_list, stored_box
  910. del stored_list[API.get_stored_box_index_gui()]
  911. API.update_sort_box_gui()
  912. @staticmethod
  913. @exception_catch()
  914. def add_baseline(): # 按基准列排行
  915. ascending, value = API.add_baseline_gui(ascending_type, sort_by)
  916. stored_list.append((value, ascending))
  917. API.update_sort_box_gui()
  918. @staticmethod
  919. @exception_catch()
  920. def sort_by_column(): # 行
  921. name = API.get_sheet_name_gui()
  922. new, ascending = API.sort_by_column_gui()
  923. data = machine_controller.sorted_index(name, False, new, ascending)
  924. title = f"CoTan数据处理 表格:{name}.Stored by Column"
  925. API.vitables_gui(data, title)
  926. API.update_sheet_box_gui()
  927. @staticmethod
  928. @exception_catch()
  929. def sort_by_tow(): # 行
  930. name = API.get_sheet_name_gui()
  931. new, ascending = API.sort_by_column_gui()
  932. data = machine_controller.sorted_index(name, True, new, ascending)
  933. title = f"CoTan数据处理 表格:{name}.Stored by Row"
  934. API.vitables_gui(data, title)
  935. API.update_sheet_box_gui()
  936. @staticmethod
  937. @exception_catch()
  938. def transpose():
  939. name = API.get_sheet_name_gui()
  940. new = API.get_ascending_new_gui()
  941. data = machine_controller.transpose(name, new)
  942. title = f"CoTan数据处理 表格:{name}.T"
  943. API.vitables_gui(data, title)
  944. API.update_sheet_box_gui()
  945. @staticmethod
  946. @exception_catch()
  947. def show_report():
  948. assert not API.askokcancel_gui(f"是否统计数据,大量的数据需要耗费一定的时间(确定后,系统会在后台统计)")
  949. report_dir = f"{PATH}{os.sep}$Show_Des_Sheet.html"
  950. name = API.get_sheet_name_gui()
  951. assert not name is None
  952. machine_controller.to_report(name, report_dir)
  953. webbrowser.open(report_dir)
  954. @staticmethod
  955. @exception_catch()
  956. def show_describe():
  957. describe = API.get_des_bool_gui()
  958. name = API.get_sheet_name_gui()
  959. title = f"CoTan数据处理 表格:{name}_describe"
  960. data = str(machine_controller.describe(name, describe))
  961. API.vitables_gui(data, title)
  962. API.update_sheet_box_gui()
  963. @staticmethod
  964. @exception_catch()
  965. def show_sheet():
  966. name = API.get_sheet_name_gui()
  967. title = f"CoTan数据处理 表格:{name}"
  968. data = str(machine_controller.get_sheet(name))
  969. API.vitables_gui(data, title)
  970. @staticmethod
  971. @exception_catch()
  972. def get_column(): # 列名(横行竖列,列名是上面的)
  973. name = API.get_sheet_name_gui()
  974. API.update_index_box_gui(machine_controller.get_column(name))
  975. @staticmethod
  976. @exception_catch()
  977. def get_row(): # 行名(横行竖列,行名左)
  978. name = API.get_sheet_name_gui()
  979. API.update_index_box_gui(machine_controller.get_index(name))
  980. @staticmethod
  981. @exception_catch()
  982. def show_one_sheet_html():
  983. global PATH, to_html_type
  984. html_dir = f"{PATH}{os.sep}$Show_Sheet.html"
  985. name = API.get_sheet_name_gui()
  986. assert not name is None
  987. machine_controller.render_html_one(name, html_dir)
  988. webbrowser.open(html_dir)
  989. @staticmethod
  990. @exception_catch()
  991. def show_sheet_html():
  992. global PATH, to_html_type
  993. html_dir = f"{PATH}{os.sep}$Show_Sheet.html"
  994. name = API.get_sheet_name_gui()
  995. assert not name is None
  996. machine_controller.render_html_all(name, html_dir, to_html_type.get())
  997. webbrowser.open(html_dir)
  998. @staticmethod
  999. @exception_catch()
  1000. def to_csv():
  1001. global SCREEN, sep, encoding, str_must, index_must
  1002. csv_sep, save_dir = API.to_csv_gui()
  1003. name = API.get_sheet_name_gui()
  1004. machine_controller.to_csv(name, save_dir, csv_sep)
  1005. API.update_sheet_box_gui()
  1006. @staticmethod
  1007. @exception_catch()
  1008. def add_csv():
  1009. global SCREEN, sep, encoding, str_must, index_must, sheet_name
  1010. csv_encoding, csv_sep, file_dir, index, name, str_ = API.add_csv_gui()
  1011. machine_controller.add_csv(file_dir, name, csv_sep, csv_encoding, str_, index)
  1012. API.update_sheet_box_gui()
  1013. @staticmethod
  1014. @exception_catch()
  1015. def add_from_python():
  1016. global SCREEN, sep, encoding, str_must, index_must
  1017. code, name = API.add_from_python_gui()
  1018. machine_controller.add_python(code, name)
  1019. API.update_sheet_box_gui()
  1020. def machine_learning(in_queue, out_queue):
  1021. global SCREEN
  1022. queue_controller.set_queue(in_queue, out_queue)
  1023. queue_controller()
  1024. SCREEN.mainloop()
  1025. queue_controller.stop_process()
  1026. tkinter.Button(
  1027. SCREEN,
  1028. bg=buttom_bg_color,
  1029. fg=word_color,
  1030. text="导入CSV",
  1031. command=API.add_csv,
  1032. font=FONT,
  1033. width=gui_width,
  1034. height=gui_height,
  1035. ).grid(
  1036. column=column,
  1037. row=row,
  1038. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1039. )
  1040. tkinter.Button(
  1041. SCREEN,
  1042. bg=buttom_bg_color,
  1043. fg=word_color,
  1044. text="导入Py",
  1045. command=API.add_from_python,
  1046. font=FONT,
  1047. width=gui_width,
  1048. height=gui_height,
  1049. ).grid(
  1050. column=column + 1,
  1051. row=row,
  1052. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1053. )
  1054. tkinter.Button(
  1055. SCREEN,
  1056. bg=buttom_bg_color,
  1057. fg=word_color,
  1058. text="导出CSV",
  1059. command=API.to_csv,
  1060. font=FONT,
  1061. width=gui_width,
  1062. height=gui_height,
  1063. ).grid(
  1064. column=column + 2,
  1065. row=row,
  1066. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1067. )
  1068. row += 1
  1069. tkinter.Label(
  1070. SCREEN,
  1071. text="表格名称:",
  1072. bg=bg_color,
  1073. fg=word_color,
  1074. font=FONT,
  1075. width=gui_width,
  1076. height=gui_height,
  1077. ).grid(
  1078. column=column, row=row
  1079. ) # 设置说明
  1080. sheet_name = tkinter.Entry(SCREEN, width=gui_width)
  1081. sheet_name.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  1082. row += 1
  1083. tkinter.Button(
  1084. SCREEN,
  1085. bg=buttom_bg_color,
  1086. fg=word_color,
  1087. text="删除表格",
  1088. command=API.del_form,
  1089. font=FONT,
  1090. width=gui_width,
  1091. height=gui_height,
  1092. ).grid(
  1093. column=column,
  1094. row=row,
  1095. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1096. )
  1097. tkinter.Button(
  1098. SCREEN,
  1099. bg=buttom_bg_color,
  1100. fg=word_color,
  1101. text="查看表格",
  1102. command=API.show_sheet_html,
  1103. font=FONT,
  1104. width=gui_width,
  1105. height=gui_height,
  1106. ).grid(
  1107. column=column + 1,
  1108. row=row,
  1109. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1110. )
  1111. tkinter.Button(
  1112. SCREEN,
  1113. bg=buttom_bg_color,
  1114. fg=word_color,
  1115. text="查看单一表格",
  1116. command=API.show_one_sheet_html,
  1117. font=FONT,
  1118. width=gui_width,
  1119. height=gui_height,
  1120. ).grid(
  1121. column=column + 2,
  1122. row=row,
  1123. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1124. )
  1125. row += 1
  1126. to_html_type = tkinter.IntVar() # 正,负,0
  1127. lable = ["选项卡型", "可移动型", "自适应型"] # 复选框
  1128. for i in range(3):
  1129. tkinter.Radiobutton(
  1130. SCREEN,
  1131. bg=bg_color,
  1132. fg=word_color,
  1133. activebackground=bg_color,
  1134. activeforeground=word_color,
  1135. selectcolor=bg_color,
  1136. text=lable[i],
  1137. variable=to_html_type,
  1138. value=i,
  1139. ).grid(column=column + i, row=row, sticky=tkinter.W)
  1140. str_must = tkinter.IntVar()
  1141. index_must = tkinter.IntVar()
  1142. row += 1
  1143. tkinter.Label(
  1144. SCREEN,
  1145. text="编码方式:",
  1146. bg=bg_color,
  1147. fg=word_color,
  1148. font=FONT,
  1149. width=gui_width,
  1150. height=gui_height,
  1151. ).grid(
  1152. column=column, row=row
  1153. ) # 设置说明
  1154. encoding = tkinter.Entry(SCREEN, width=gui_width)
  1155. encoding.grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
  1156. buttom = tkinter.Checkbutton(
  1157. SCREEN,
  1158. bg=bg_color,
  1159. fg=word_color,
  1160. activebackground=bg_color,
  1161. activeforeground=word_color,
  1162. selectcolor=bg_color,
  1163. text="字符串类型",
  1164. variable=str_must,
  1165. )
  1166. buttom.grid(column=column + 2, row=row, sticky=tkinter.W)
  1167. row += 1
  1168. tkinter.Label(
  1169. SCREEN,
  1170. text="CSV分隔符:",
  1171. bg=bg_color,
  1172. fg=word_color,
  1173. font=FONT,
  1174. width=gui_width,
  1175. height=gui_height,
  1176. ).grid(
  1177. column=column, row=row
  1178. ) # 设置说明
  1179. sep = tkinter.Entry(SCREEN, width=gui_width)
  1180. sep.grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
  1181. tkinter.Checkbutton(
  1182. SCREEN,
  1183. bg=bg_color,
  1184. fg=word_color,
  1185. activebackground=bg_color,
  1186. activeforeground=word_color,
  1187. selectcolor=bg_color,
  1188. text="重置列名",
  1189. variable=index_must,
  1190. ).grid(column=column + 2, row=row, sticky=tkinter.W)
  1191. row += 1
  1192. sheet_box = tkinter.Listbox(SCREEN, width=gui_width * 3, height=gui_height * 5) # 显示符号
  1193. sheet_box.grid(
  1194. column=column,
  1195. row=row,
  1196. columnspan=3,
  1197. rowspan=5,
  1198. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
  1199. )
  1200. row += 5
  1201. tkinter.Button(
  1202. SCREEN,
  1203. bg=buttom_bg_color,
  1204. fg=word_color,
  1205. text="查看行名",
  1206. command=API.get_row,
  1207. font=FONT,
  1208. width=gui_width,
  1209. height=gui_height,
  1210. ).grid(
  1211. column=column,
  1212. row=row,
  1213. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1214. )
  1215. tkinter.Button(
  1216. SCREEN,
  1217. bg=buttom_bg_color,
  1218. fg=word_color,
  1219. text="查看列名",
  1220. command=API.get_column,
  1221. font=FONT,
  1222. width=gui_width,
  1223. height=gui_height,
  1224. ).grid(
  1225. column=column + 1,
  1226. row=row,
  1227. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1228. )
  1229. tkinter.Button(
  1230. SCREEN,
  1231. bg=buttom_bg_color,
  1232. fg=word_color,
  1233. text="显示表格",
  1234. command=API.show_sheet,
  1235. font=FONT,
  1236. width=gui_width,
  1237. height=gui_height,
  1238. ).grid(
  1239. column=column + 2,
  1240. row=row,
  1241. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1242. )
  1243. row += 1
  1244. tkinter.Label(
  1245. SCREEN,
  1246. text="最大显示行数:",
  1247. bg=bg_color,
  1248. fg=word_color,
  1249. font=FONT,
  1250. width=gui_width,
  1251. height=gui_height,
  1252. ).grid(
  1253. column=column, row=row
  1254. ) # 设置说明
  1255. max_row = tkinter.Entry(SCREEN, width=gui_width * 2)
  1256. max_row.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  1257. row += 1
  1258. tkinter.Label(
  1259. SCREEN,
  1260. text="最大显示列数:",
  1261. bg=bg_color,
  1262. fg=word_color,
  1263. font=FONT,
  1264. width=gui_width,
  1265. height=gui_height,
  1266. ).grid(
  1267. column=column, row=row
  1268. ) # 设置说明
  1269. max_column = tkinter.Entry(SCREEN, width=gui_width * 2)
  1270. max_column.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  1271. # Row与Column Row是横行,tkinter布局中Row变大,表示所在行数变大,向下移动如:
  1272. # 1,2,3,4,5,6
  1273. # 7,8,9,a,b,c
  1274. # 其中数字1-6是第一行,1-c是第二行,第二行在第一行下面,row变大向下移动(Row是横向行而不是横向移动) to 搞不清楚横行竖列的人
  1275. row += 1
  1276. index_box = tkinter.Listbox(SCREEN, width=gui_width * 3, height=gui_height * 10) # 显示符号
  1277. index_box.grid(
  1278. column=column,
  1279. row=row,
  1280. columnspan=3,
  1281. rowspan=10,
  1282. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
  1283. )
  1284. row += 10
  1285. tkinter.Button(
  1286. SCREEN,
  1287. bg=buttom_bg_color,
  1288. fg=word_color,
  1289. text="查看数据分析",
  1290. command=API.show_report,
  1291. font=FONT,
  1292. width=gui_width,
  1293. height=gui_height,
  1294. ).grid(
  1295. column=column,
  1296. row=row,
  1297. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1298. )
  1299. tkinter.Button(
  1300. SCREEN,
  1301. bg=buttom_bg_color,
  1302. fg=word_color,
  1303. text="简单数据统计",
  1304. command=API.show_describe,
  1305. font=FONT,
  1306. width=gui_width,
  1307. height=gui_height,
  1308. ).grid(
  1309. column=column + 1,
  1310. row=row,
  1311. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1312. )
  1313. des_bool = tkinter.IntVar() # 是否启用
  1314. tkinter.Checkbutton(
  1315. SCREEN,
  1316. bg=bg_color,
  1317. fg=word_color,
  1318. activebackground=bg_color,
  1319. activeforeground=word_color,
  1320. selectcolor=bg_color,
  1321. text="生成统计表格",
  1322. variable=des_bool,
  1323. ).grid(column=column + 2, row=row, sticky=tkinter.W)
  1324. column += 3
  1325. tkinter.Label(SCREEN, text="", bg=bg_color, fg=word_color, font=FONT, width=1).grid(
  1326. column=column, row=row
  1327. ) # 设置说明
  1328. column += 1
  1329. row = 0
  1330. tkinter.Label(
  1331. SCREEN,
  1332. text="【数据清洗】",
  1333. bg=bg_color,
  1334. fg=word_color,
  1335. font=FONT,
  1336. width=gui_width * 3,
  1337. height=gui_height,
  1338. ).grid(
  1339. column=column,
  1340. columnspan=3,
  1341. row=row,
  1342. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1343. ) # 设置说明
  1344. column_clist = []
  1345. row_clist = []
  1346. label = ["启始(列号):", "终止(列):", "间隔(列):"]
  1347. for i in range(3):
  1348. row += 1
  1349. tkinter.Label(
  1350. SCREEN,
  1351. text=label[i],
  1352. bg=bg_color,
  1353. fg=word_color,
  1354. font=FONT,
  1355. width=gui_width,
  1356. height=gui_height,
  1357. ).grid(
  1358. column=column, row=row
  1359. ) # 设置说明
  1360. column_clist.append(tkinter.Entry(SCREEN, width=gui_width * 2))
  1361. column_clist[-1].grid(
  1362. column=column + 1, row=row, columnspan=2, sticky=tkinter.W + tkinter.E
  1363. )
  1364. label = ["启始(行号):", "终止(行):", "间隔(行):"]
  1365. for i in range(3):
  1366. row += 1
  1367. tkinter.Label(
  1368. SCREEN,
  1369. text=label[i],
  1370. bg=bg_color,
  1371. fg=word_color,
  1372. font=FONT,
  1373. width=gui_width,
  1374. height=gui_height,
  1375. ).grid(
  1376. column=column, row=row
  1377. ) # 设置说明
  1378. row_clist.append(tkinter.Entry(SCREEN, width=gui_width * 2))
  1379. row_clist[-1].grid(
  1380. column=column + 1, row=row, columnspan=2, sticky=tkinter.W + tkinter.E
  1381. )
  1382. row += 1
  1383. column_type = tkinter.IntVar()
  1384. lable = ["根据列号", "根据列名", "输入列号"] # 复选框
  1385. for i in range(3):
  1386. tkinter.Radiobutton(
  1387. SCREEN,
  1388. bg=bg_color,
  1389. fg=word_color,
  1390. activebackground=bg_color,
  1391. activeforeground=word_color,
  1392. selectcolor=bg_color,
  1393. text=lable[i],
  1394. variable=column_type,
  1395. value=i,
  1396. ).grid(column=column + i, row=row, sticky=tkinter.W)
  1397. row += 1
  1398. row_type = tkinter.IntVar()
  1399. lable = ["根据行号", "根据行名", "输入行号"] # 复选框
  1400. for i in range(3):
  1401. tkinter.Radiobutton(
  1402. SCREEN,
  1403. bg=bg_color,
  1404. fg=word_color,
  1405. activebackground=bg_color,
  1406. activeforeground=word_color,
  1407. selectcolor=bg_color,
  1408. text=lable[i],
  1409. variable=row_type,
  1410. value=i,
  1411. ).grid(column=column + i, row=row, sticky=tkinter.W)
  1412. row += 1
  1413. slice_new = tkinter.IntVar()
  1414. tkinter.Button(
  1415. SCREEN,
  1416. bg=buttom_bg_color,
  1417. fg=word_color,
  1418. text="切片选定",
  1419. command=API.slice_data,
  1420. font=FONT,
  1421. width=gui_width,
  1422. height=gui_height,
  1423. ).grid(
  1424. column=column,
  1425. row=row,
  1426. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1427. )
  1428. tkinter.Button(
  1429. SCREEN,
  1430. bg=buttom_bg_color,
  1431. fg=word_color,
  1432. text="删除选定",
  1433. command=API.del_data,
  1434. font=FONT,
  1435. width=gui_width,
  1436. height=gui_height,
  1437. ).grid(
  1438. column=column + 1,
  1439. row=row,
  1440. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1441. )
  1442. tkinter.Checkbutton(
  1443. SCREEN,
  1444. bg=bg_color,
  1445. fg=word_color,
  1446. activebackground=bg_color,
  1447. activeforeground=word_color,
  1448. selectcolor=bg_color,
  1449. text="生成新表格",
  1450. variable=slice_new,
  1451. ).grid(column=column + 2, row=row, sticky=tkinter.W)
  1452. row += 1
  1453. tkinter.Label(
  1454. SCREEN,
  1455. text="布尔逻辑:",
  1456. bg=bg_color,
  1457. fg=word_color,
  1458. font=FONT,
  1459. width=gui_width,
  1460. height=gui_height,
  1461. ).grid(
  1462. column=column,
  1463. row=row,
  1464. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1465. ) # 设置说明
  1466. bool_exp = tkinter.Entry(SCREEN, width=gui_width * 2)
  1467. bool_exp.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.W + tkinter.E)
  1468. row += 1
  1469. tkinter.Label(
  1470. SCREEN,
  1471. text="操作的列号:",
  1472. bg=bg_color,
  1473. fg=word_color,
  1474. font=FONT,
  1475. width=gui_width,
  1476. height=gui_height,
  1477. ).grid(
  1478. column=column,
  1479. row=row,
  1480. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1481. ) # 设置说明
  1482. drop_column = tkinter.Entry(SCREEN, width=gui_width * 2)
  1483. drop_column.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.W + tkinter.E)
  1484. row += 1
  1485. tkinter.Button(
  1486. SCREEN,
  1487. bg=buttom_bg_color,
  1488. fg=word_color,
  1489. text="生成布尔表格",
  1490. command=API.to_bool,
  1491. font=FONT,
  1492. width=gui_width,
  1493. height=gui_height,
  1494. ).grid(
  1495. column=column,
  1496. row=row,
  1497. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1498. )
  1499. tkinter.Button(
  1500. SCREEN,
  1501. bg=buttom_bg_color,
  1502. fg=word_color,
  1503. text="查看空值",
  1504. command=API.is_nan,
  1505. font=FONT,
  1506. width=gui_width,
  1507. height=gui_height,
  1508. ).grid(
  1509. column=column + 1,
  1510. row=row,
  1511. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1512. )
  1513. tkinter.Button(
  1514. SCREEN,
  1515. bg=buttom_bg_color,
  1516. fg=word_color,
  1517. text="清洗空值(按行)",
  1518. command=API.clean_nan_row,
  1519. font=FONT,
  1520. width=gui_width,
  1521. height=gui_height,
  1522. ).grid(
  1523. column=column + 2,
  1524. row=row,
  1525. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1526. )
  1527. row += 1
  1528. tkinter.Button(
  1529. SCREEN,
  1530. bg=buttom_bg_color,
  1531. fg=word_color,
  1532. text="添加执行方法",
  1533. command=API.add_cleaning_script,
  1534. font=FONT,
  1535. width=gui_width,
  1536. height=gui_height,
  1537. ).grid(
  1538. column=column,
  1539. row=row,
  1540. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1541. )
  1542. tkinter.Button(
  1543. SCREEN,
  1544. bg=buttom_bg_color,
  1545. fg=word_color,
  1546. text="删除执行方法",
  1547. command=API.del_cleaning_script,
  1548. font=FONT,
  1549. width=gui_width,
  1550. height=gui_height,
  1551. ).grid(
  1552. column=column + 1,
  1553. row=row,
  1554. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1555. )
  1556. tkinter.Button(
  1557. SCREEN,
  1558. bg=buttom_bg_color,
  1559. fg=word_color,
  1560. text="数据特征提取",
  1561. command=API.feature_extraction,
  1562. font=FONT,
  1563. width=gui_width,
  1564. height=gui_height,
  1565. ).grid(
  1566. column=column + 2,
  1567. row=row,
  1568. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1569. )
  1570. row += 1
  1571. clean_func_box = tkinter.Listbox(SCREEN, width=gui_width * 3, height=gui_height * 2)
  1572. clean_func_box.grid(
  1573. column=column,
  1574. row=row,
  1575. columnspan=3,
  1576. rowspan=2,
  1577. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
  1578. )
  1579. row += 2
  1580. tkinter.Button(
  1581. SCREEN,
  1582. bg=buttom_bg_color,
  1583. fg=word_color,
  1584. text="查看词典",
  1585. command=API.show_dictionary_gui,
  1586. font=FONT,
  1587. width=gui_width,
  1588. height=gui_height,
  1589. ).grid(
  1590. column=column,
  1591. row=row,
  1592. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1593. )
  1594. tkinter.Button(
  1595. SCREEN,
  1596. bg=buttom_bg_color,
  1597. fg=word_color,
  1598. text="恢复显示",
  1599. command=API.reset_clean_code_gui,
  1600. font=FONT,
  1601. width=gui_width,
  1602. height=gui_height,
  1603. ).grid(
  1604. column=column + 1,
  1605. row=row,
  1606. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1607. )
  1608. tkinter.Button(
  1609. SCREEN,
  1610. bg=buttom_bg_color,
  1611. fg=word_color,
  1612. text="执行数据清洗",
  1613. command=API.execute_cleaning_script,
  1614. font=FONT,
  1615. width=gui_width,
  1616. height=gui_height,
  1617. ).grid(
  1618. column=column + 2,
  1619. row=row,
  1620. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1621. )
  1622. row += 1
  1623. clean_code = tkinter.Text(SCREEN, width=gui_width * 3, height=gui_height * 7)
  1624. clean_code.grid(
  1625. column=column,
  1626. row=row,
  1627. columnspan=3,
  1628. rowspan=7,
  1629. sticky=tkinter.E + tkinter.W + tkinter.N + tkinter.S,
  1630. )
  1631. clean_code.insert("0.0", clean_default_script)
  1632. row += 7
  1633. tkinter.Button(
  1634. SCREEN,
  1635. bg=buttom_bg_color,
  1636. fg=word_color,
  1637. text="清空执行方法",
  1638. command=API.empty_cleaning_script,
  1639. font=FONT,
  1640. width=gui_width,
  1641. height=gui_height,
  1642. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  1643. tkinter.Button(
  1644. SCREEN,
  1645. bg=buttom_bg_color,
  1646. fg=word_color,
  1647. text="查看执行方法",
  1648. command=API.view_cleaning_script_gui,
  1649. font=FONT,
  1650. width=gui_width,
  1651. height=gui_height,
  1652. ).grid(
  1653. column=column + 1,
  1654. row=row,
  1655. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1656. )
  1657. tkinter.Button(
  1658. SCREEN,
  1659. bg=buttom_bg_color,
  1660. fg=word_color,
  1661. text="导入执行方法",
  1662. command=API.open_python_for_clean_gui,
  1663. font=FONT,
  1664. width=gui_width,
  1665. height=gui_height,
  1666. ).grid(
  1667. column=column + 2,
  1668. row=row,
  1669. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1670. )
  1671. column += 3
  1672. tkinter.Label(SCREEN, text="", bg=bg_color, fg=word_color, font=FONT, width=1).grid(
  1673. column=column, row=row
  1674. ) # 设置说明
  1675. column += 1
  1676. row = 0
  1677. tkinter.Label(
  1678. SCREEN,
  1679. text="【数据可视化】",
  1680. bg=bg_color,
  1681. fg=word_color,
  1682. font=FONT,
  1683. width=gui_width * 3,
  1684. height=gui_height,
  1685. ).grid(
  1686. column=column,
  1687. columnspan=3,
  1688. row=row,
  1689. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1690. ) # 设置说明
  1691. row += 1
  1692. tkinter.Button(
  1693. SCREEN,
  1694. bg=buttom_bg_color,
  1695. fg=word_color,
  1696. text="生成柱状图",
  1697. command=API.to_bar,
  1698. font=FONT,
  1699. width=gui_width,
  1700. height=gui_height,
  1701. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  1702. tkinter.Button(
  1703. SCREEN,
  1704. bg=buttom_bg_color,
  1705. fg=word_color,
  1706. text="生成3D柱状图",
  1707. command=API.to_bar3d,
  1708. font=FONT,
  1709. width=gui_width,
  1710. height=gui_height,
  1711. ).grid(
  1712. column=column + 1,
  1713. row=row,
  1714. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1715. )
  1716. tkinter.Button(
  1717. SCREEN,
  1718. bg=buttom_bg_color,
  1719. fg=word_color,
  1720. text="生成折线图",
  1721. command=API.to_line,
  1722. font=FONT,
  1723. width=gui_width,
  1724. height=gui_height,
  1725. ).grid(
  1726. column=column + 2,
  1727. row=row,
  1728. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1729. )
  1730. row += 1
  1731. tkinter.Button(
  1732. SCREEN,
  1733. bg=buttom_bg_color,
  1734. fg=word_color,
  1735. text="生成3D折线图",
  1736. command=API.to_line3d,
  1737. font=FONT,
  1738. width=gui_width,
  1739. height=gui_height,
  1740. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  1741. tkinter.Button(
  1742. SCREEN,
  1743. bg=buttom_bg_color,
  1744. fg=word_color,
  1745. text="生成象形柱状图",
  1746. command=API.to_pictorialbar,
  1747. font=FONT,
  1748. width=gui_width,
  1749. height=gui_height,
  1750. ).grid(
  1751. column=column + 1,
  1752. row=row,
  1753. columnspan=2,
  1754. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
  1755. )
  1756. row += 1
  1757. tkinter.Button(
  1758. SCREEN,
  1759. bg=buttom_bg_color,
  1760. fg=word_color,
  1761. text="生成散点图",
  1762. command=API.to_scatter,
  1763. font=FONT,
  1764. width=gui_width,
  1765. height=gui_height,
  1766. ).grid(
  1767. column=column,
  1768. row=row,
  1769. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1770. )
  1771. tkinter.Button(
  1772. SCREEN,
  1773. bg=buttom_bg_color,
  1774. fg=word_color,
  1775. text="生成3D散点图",
  1776. command=API.to_scatter3d,
  1777. font=FONT,
  1778. width=gui_width,
  1779. height=gui_height,
  1780. ).grid(
  1781. column=column + 1,
  1782. row=row,
  1783. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1784. )
  1785. tkinter.Button(
  1786. SCREEN,
  1787. bg=buttom_bg_color,
  1788. fg=word_color,
  1789. text="生成箱形图",
  1790. command=API.to_boxpolt,
  1791. font=FONT,
  1792. width=gui_width,
  1793. height=gui_height,
  1794. ).grid(
  1795. column=column + 2,
  1796. row=row,
  1797. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1798. )
  1799. row += 1
  1800. tkinter.Button(
  1801. SCREEN,
  1802. bg=buttom_bg_color,
  1803. fg=word_color,
  1804. text="生成漏斗图",
  1805. command=API.to_funnel,
  1806. font=FONT,
  1807. width=gui_width,
  1808. height=gui_height,
  1809. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  1810. tkinter.Button(
  1811. SCREEN,
  1812. bg=buttom_bg_color,
  1813. fg=word_color,
  1814. text="生成热力图",
  1815. command=API.to_heat_map,
  1816. font=FONT,
  1817. width=gui_width,
  1818. height=gui_height,
  1819. ).grid(
  1820. column=column + 1,
  1821. row=row,
  1822. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1823. )
  1824. tkinter.Button(
  1825. SCREEN,
  1826. bg=buttom_bg_color,
  1827. fg=word_color,
  1828. text="生成饼图",
  1829. command=API.to_pie,
  1830. font=FONT,
  1831. width=gui_width,
  1832. height=gui_height,
  1833. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  1834. row += 1
  1835. tkinter.Button(
  1836. SCREEN,
  1837. bg=buttom_bg_color,
  1838. fg=word_color,
  1839. text="生成多轴图",
  1840. command=API.to_parallel,
  1841. font=FONT,
  1842. width=gui_width,
  1843. height=gui_height,
  1844. ).grid(
  1845. column=column,
  1846. row=row,
  1847. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1848. )
  1849. tkinter.Button(
  1850. SCREEN,
  1851. bg=buttom_bg_color,
  1852. fg=word_color,
  1853. text="生成极坐标图",
  1854. command=API.to_polar,
  1855. font=FONT,
  1856. width=gui_width,
  1857. height=gui_height,
  1858. ).grid(
  1859. column=column + 1,
  1860. row=row,
  1861. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1862. )
  1863. tkinter.Button(
  1864. SCREEN,
  1865. bg=buttom_bg_color,
  1866. fg=word_color,
  1867. text="生成雷达图",
  1868. command=API.to_radar,
  1869. font=FONT,
  1870. width=gui_width,
  1871. height=gui_height,
  1872. ).grid(
  1873. column=column + 2,
  1874. row=row,
  1875. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1876. )
  1877. row += 1
  1878. tkinter.Button(
  1879. SCREEN,
  1880. bg=buttom_bg_color,
  1881. fg=word_color,
  1882. text="生成词云",
  1883. command=API.to_word_cloud,
  1884. font=FONT,
  1885. width=gui_width,
  1886. height=gui_height,
  1887. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N)
  1888. tkinter.Button(
  1889. SCREEN,
  1890. bg=buttom_bg_color,
  1891. fg=word_color,
  1892. text="生成关系图",
  1893. command=API.to_format_graph,
  1894. font=FONT,
  1895. width=gui_width,
  1896. height=gui_height,
  1897. ).grid(
  1898. column=column + 1,
  1899. row=row,
  1900. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1901. )
  1902. tkinter.Button(
  1903. SCREEN,
  1904. bg=buttom_bg_color,
  1905. fg=word_color,
  1906. text="生成XY关系图",
  1907. command=API.to_graph,
  1908. font=FONT,
  1909. width=gui_width,
  1910. height=gui_height,
  1911. ).grid(
  1912. column=column + 2,
  1913. row=row,
  1914. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1915. )
  1916. row += 1
  1917. tkinter.Button(
  1918. SCREEN,
  1919. bg=buttom_bg_color,
  1920. fg=word_color,
  1921. text="生成水球图",
  1922. command=API.to_liquid,
  1923. font=FONT,
  1924. width=gui_width,
  1925. height=gui_height,
  1926. ).grid(
  1927. column=column,
  1928. row=row,
  1929. columnspan=2,
  1930. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
  1931. )
  1932. tkinter.Button(
  1933. SCREEN,
  1934. bg=buttom_bg_color,
  1935. fg=word_color,
  1936. text="生成仪表图",
  1937. command=API.to_gauge,
  1938. font=FONT,
  1939. width=gui_width,
  1940. height=gui_height,
  1941. ).grid(
  1942. column=column + 2,
  1943. row=row,
  1944. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1945. )
  1946. row += 1
  1947. tkinter.Button(
  1948. SCREEN,
  1949. bg=buttom_bg_color,
  1950. fg=word_color,
  1951. text="生成日历图",
  1952. command=API.to_calendar,
  1953. font=FONT,
  1954. width=gui_width,
  1955. height=gui_height,
  1956. ).grid(
  1957. column=column,
  1958. row=row,
  1959. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1960. )
  1961. tkinter.Button(
  1962. SCREEN,
  1963. bg=buttom_bg_color,
  1964. fg=word_color,
  1965. text="生成河流图",
  1966. command=API.to_theme_river,
  1967. font=FONT,
  1968. width=gui_width,
  1969. height=gui_height,
  1970. ).grid(
  1971. column=column + 1,
  1972. row=row,
  1973. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1974. )
  1975. tkinter.Button(
  1976. SCREEN,
  1977. bg=buttom_bg_color,
  1978. fg=word_color,
  1979. text="生成旭日图",
  1980. command=API.to_sunburst,
  1981. font=FONT,
  1982. width=gui_width,
  1983. height=gui_height,
  1984. ).grid(
  1985. column=column + 2,
  1986. row=row,
  1987. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  1988. )
  1989. row += 1
  1990. tkinter.Button(
  1991. SCREEN,
  1992. bg=buttom_bg_color,
  1993. fg=word_color,
  1994. text="生成桑基图",
  1995. command=API.to_sankey,
  1996. font=FONT,
  1997. width=gui_width,
  1998. height=gui_height,
  1999. ).grid(
  2000. column=column,
  2001. row=row,
  2002. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2003. )
  2004. tkinter.Button(
  2005. SCREEN,
  2006. bg=buttom_bg_color,
  2007. fg=word_color,
  2008. text="生成树状图",
  2009. command=API.to_tree,
  2010. font=FONT,
  2011. width=gui_width,
  2012. height=gui_height,
  2013. ).grid(
  2014. column=column + 1,
  2015. row=row,
  2016. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2017. )
  2018. tkinter.Button(
  2019. SCREEN,
  2020. bg=buttom_bg_color,
  2021. fg=word_color,
  2022. text="生成矩形树图",
  2023. command=API.to_treemap,
  2024. font=FONT,
  2025. width=gui_width,
  2026. height=gui_height,
  2027. ).grid(
  2028. column=column + 2,
  2029. row=row,
  2030. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2031. )
  2032. row += 1
  2033. tkinter.Button(
  2034. SCREEN,
  2035. bg=buttom_bg_color,
  2036. fg=word_color,
  2037. text="生成Map地图",
  2038. command=API.to_map,
  2039. font=FONT,
  2040. width=gui_width,
  2041. height=gui_height,
  2042. ).grid(
  2043. column=column,
  2044. row=row,
  2045. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2046. )
  2047. tkinter.Button(
  2048. SCREEN,
  2049. bg=buttom_bg_color,
  2050. fg=word_color,
  2051. text="生成Geo点地图",
  2052. command=API.to_scattergeo,
  2053. font=FONT,
  2054. width=gui_width,
  2055. height=gui_height,
  2056. ).grid(
  2057. column=column + 1,
  2058. row=row,
  2059. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2060. )
  2061. tkinter.Button(
  2062. SCREEN,
  2063. bg=buttom_bg_color,
  2064. fg=word_color,
  2065. text="生成Geo地图",
  2066. command=API.to_geo,
  2067. font=FONT,
  2068. width=gui_width,
  2069. height=gui_height,
  2070. ).grid(
  2071. column=column + 2,
  2072. row=row,
  2073. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2074. )
  2075. row += 1
  2076. tkinter.Button(
  2077. SCREEN,
  2078. bg=buttom_bg_color,
  2079. fg=word_color,
  2080. text="选择底图",
  2081. command=API.add_basemap,
  2082. font=FONT,
  2083. width=gui_width,
  2084. height=gui_height,
  2085. ).grid(
  2086. column=column,
  2087. row=row,
  2088. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2089. )
  2090. tkinter.Button(
  2091. SCREEN,
  2092. bg=buttom_bg_color,
  2093. fg=word_color,
  2094. text="选择顶图",
  2095. command=API.add_top_image,
  2096. font=FONT,
  2097. width=gui_width,
  2098. height=gui_height,
  2099. ).grid(
  2100. column=column + 1,
  2101. row=row,
  2102. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2103. )
  2104. tkinter.Button(
  2105. SCREEN,
  2106. bg=buttom_bg_color,
  2107. fg=word_color,
  2108. text="生成层叠图",
  2109. command=API.make_overlap,
  2110. font=FONT,
  2111. width=gui_width,
  2112. height=gui_height,
  2113. ).grid(
  2114. column=column + 2,
  2115. row=row,
  2116. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2117. )
  2118. row += 1
  2119. overlap_box = tkinter.Listbox(SCREEN, width=gui_width * 3, height=gui_height * 2)
  2120. overlap_box.grid(
  2121. column=column,
  2122. row=row,
  2123. columnspan=3,
  2124. rowspan=2,
  2125. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
  2126. )
  2127. row += 1
  2128. tkinter.Button(
  2129. SCREEN,
  2130. bg=buttom_bg_color,
  2131. fg=word_color,
  2132. text="渲染HTML",
  2133. command=API.rendering,
  2134. font=FONT,
  2135. width=gui_width,
  2136. height=gui_height,
  2137. ).grid(
  2138. column=column,
  2139. row=row,
  2140. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2141. )
  2142. tkinter.Button(
  2143. SCREEN,
  2144. bg=buttom_bg_color,
  2145. fg=word_color,
  2146. text="单独渲染HTML",
  2147. command=API.rendering_one,
  2148. font=FONT,
  2149. width=gui_width,
  2150. height=gui_height,
  2151. ).grid(
  2152. column=column + 1,
  2153. row=row,
  2154. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2155. )
  2156. tkinter.Button(
  2157. SCREEN,
  2158. bg=buttom_bg_color,
  2159. fg=word_color,
  2160. text="删除渲染",
  2161. command=API.del_rendering,
  2162. font=FONT,
  2163. width=gui_width,
  2164. height=gui_height,
  2165. ).grid(
  2166. column=column + 2,
  2167. row=row,
  2168. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2169. )
  2170. row += 1
  2171. render_box = tkinter.Listbox(SCREEN, width=gui_width * 3, height=gui_height)
  2172. render_box.grid(
  2173. column=column,
  2174. row=row,
  2175. columnspan=3,
  2176. rowspan=2,
  2177. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
  2178. )
  2179. row += 2
  2180. draw_as_well = tkinter.IntVar()
  2181. tkinter.Button(
  2182. SCREEN,
  2183. bg=buttom_bg_color,
  2184. fg=word_color,
  2185. text="清空渲染",
  2186. command=API.clear_rendering,
  2187. font=FONT,
  2188. width=gui_width,
  2189. height=gui_height,
  2190. ).grid(
  2191. column=column,
  2192. row=row,
  2193. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2194. )
  2195. tkinter.Button(
  2196. SCREEN,
  2197. bg=buttom_bg_color,
  2198. fg=word_color,
  2199. text="导入渲染",
  2200. command=API.python_render,
  2201. font=FONT,
  2202. width=gui_width,
  2203. height=gui_height,
  2204. ).grid(
  2205. column=column + 1,
  2206. row=row,
  2207. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2208. )
  2209. tkinter.Checkbutton(
  2210. SCREEN,
  2211. bg=bg_color,
  2212. fg=word_color,
  2213. activebackground=bg_color,
  2214. activeforeground=word_color,
  2215. selectcolor=bg_color,
  2216. text="马上渲染",
  2217. variable=draw_as_well,
  2218. ).grid(column=column + 2, row=row, sticky=tkinter.W)
  2219. row += 1
  2220. rendering_parameters = tkinter.Text(SCREEN, width=gui_width * 3, height=gui_height * 7)
  2221. rendering_parameters.grid(
  2222. column=column,
  2223. row=row,
  2224. columnspan=3,
  2225. rowspan=7,
  2226. sticky=tkinter.E + tkinter.W + tkinter.N + tkinter.S,
  2227. )
  2228. row += 7
  2229. tkinter.Button(
  2230. SCREEN,
  2231. bg=buttom_bg_color,
  2232. fg=word_color,
  2233. text="查看词典",
  2234. command=API.show_dictionary_gui,
  2235. font=FONT,
  2236. width=gui_width,
  2237. height=gui_height,
  2238. ).grid(
  2239. column=column,
  2240. row=row,
  2241. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2242. )
  2243. tkinter.Button(
  2244. SCREEN,
  2245. bg=buttom_bg_color,
  2246. fg=word_color,
  2247. text="恢复显示",
  2248. command=API.show_tips_gui,
  2249. font=FONT,
  2250. width=gui_width,
  2251. height=gui_height,
  2252. ).grid(
  2253. column=column + 1,
  2254. row=row,
  2255. columnspan=2,
  2256. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2257. )
  2258. column += 3
  2259. tkinter.Label(SCREEN, text="", bg=bg_color, fg=word_color, font=FONT, width=1).grid(
  2260. column=column, row=row
  2261. ) # 设置说明
  2262. column += 1
  2263. row = 0
  2264. tkinter.Label(
  2265. SCREEN,
  2266. text="【行名与列名】",
  2267. bg=bg_color,
  2268. fg=word_color,
  2269. font=FONT,
  2270. width=gui_width * 3,
  2271. height=gui_height,
  2272. ).grid(
  2273. column=column,
  2274. columnspan=3,
  2275. row=row,
  2276. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2277. ) # 设置说明
  2278. row += 1
  2279. replace_index = tkinter.IntVar()
  2280. lable = ["(列数据)调整行名", "(行数据)调整列名"] # 复选框
  2281. for i in range(2):
  2282. tkinter.Radiobutton(
  2283. SCREEN,
  2284. bg=bg_color,
  2285. fg=word_color,
  2286. activebackground=bg_color,
  2287. activeforeground=word_color,
  2288. selectcolor=bg_color,
  2289. text=lable[i],
  2290. variable=replace_index,
  2291. value=i,
  2292. ).grid(column=column + i, row=row, sticky=tkinter.W)
  2293. tkinter.Button(
  2294. SCREEN,
  2295. bg=buttom_bg_color,
  2296. fg=word_color,
  2297. text="植入行(列)号",
  2298. command=API.num_with_name,
  2299. font=FONT,
  2300. width=gui_width,
  2301. height=gui_height,
  2302. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  2303. row += 1
  2304. replace_type = []
  2305. lable = ["保留原值", "保留新值"] # 复选框
  2306. for i in range(2):
  2307. replace_type.append(tkinter.IntVar())
  2308. tkinter.Checkbutton(
  2309. SCREEN,
  2310. bg=bg_color,
  2311. fg=word_color,
  2312. activebackground=bg_color,
  2313. activeforeground=word_color,
  2314. selectcolor=bg_color,
  2315. text=lable[i],
  2316. variable=replace_type[-1],
  2317. ).grid(column=column + i, row=row, sticky=tkinter.W)
  2318. tkinter.Button(
  2319. SCREEN,
  2320. bg=buttom_bg_color,
  2321. fg=word_color,
  2322. text="统一行(列)号",
  2323. command=API.num_to_name,
  2324. font=FONT,
  2325. width=gui_width,
  2326. height=gui_height,
  2327. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  2328. row += 1
  2329. tkinter.Label(
  2330. SCREEN,
  2331. text="替换字典:",
  2332. bg=bg_color,
  2333. fg=word_color,
  2334. font=FONT,
  2335. width=gui_width,
  2336. height=gui_height,
  2337. ).grid(
  2338. column=column, row=row
  2339. ) # 设置说明
  2340. replace_dict = tkinter.Entry(SCREEN, width=gui_width * 2)
  2341. replace_dict.grid(
  2342. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  2343. )
  2344. row += 1
  2345. tkinter.Label(
  2346. SCREEN,
  2347. text="替换列(行):",
  2348. bg=bg_color,
  2349. fg=word_color,
  2350. font=FONT,
  2351. width=gui_width,
  2352. height=gui_height,
  2353. ).grid(
  2354. column=column, row=row
  2355. ) # 设置说明
  2356. replace_iloc = tkinter.Entry(SCREEN, width=gui_width * 2)
  2357. replace_iloc.grid(
  2358. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  2359. )
  2360. row += 1
  2361. tkinter.Button(
  2362. SCREEN,
  2363. bg=buttom_bg_color,
  2364. fg=word_color,
  2365. text="执行替换已有列(行)操作",
  2366. command=API.change_index,
  2367. font=FONT,
  2368. width=gui_width * 2,
  2369. height=gui_height,
  2370. ).grid(column=column, columnspan=2, row=row, sticky=tkinter.E + tkinter.W)
  2371. tkinter.Button(
  2372. SCREEN,
  2373. bg=buttom_bg_color,
  2374. fg=word_color,
  2375. text="执行替换操作",
  2376. command=API.replace_index_func,
  2377. font=FONT,
  2378. width=gui_width,
  2379. height=gui_height,
  2380. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  2381. label = ["起点", "终点", "间隔"]
  2382. date_input = []
  2383. for i in range(3):
  2384. row += 1
  2385. tkinter.Label(
  2386. SCREEN,
  2387. text="时间序列" + label[i],
  2388. bg=bg_color,
  2389. fg=word_color,
  2390. font=FONT,
  2391. width=gui_width,
  2392. height=gui_height,
  2393. ).grid(
  2394. column=column, row=row
  2395. ) # 设置说明
  2396. date_input.append(tkinter.Entry(SCREEN, width=gui_width * 2))
  2397. date_input[-1].grid(
  2398. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  2399. )
  2400. row += 1
  2401. date_type = tkinter.IntVar()
  2402. tkinter.Button(
  2403. SCREEN,
  2404. bg=buttom_bg_color,
  2405. fg=word_color,
  2406. text="刷入Date序列",
  2407. command=API.date_index,
  2408. font=FONT,
  2409. width=gui_width,
  2410. height=gui_height,
  2411. ).grid(column=column, row=row, sticky=tkinter.E + tkinter.W)
  2412. tkinter.Button(
  2413. SCREEN,
  2414. bg=buttom_bg_color,
  2415. fg=word_color,
  2416. text="刷入Time序列",
  2417. command=API.time_index,
  2418. font=FONT,
  2419. width=gui_width,
  2420. height=gui_height,
  2421. ).grid(column=column + 1, row=row, sticky=tkinter.E + tkinter.W)
  2422. tkinter.Checkbutton(
  2423. SCREEN,
  2424. bg=bg_color,
  2425. fg=word_color,
  2426. activebackground=bg_color,
  2427. activeforeground=word_color,
  2428. selectcolor=bg_color,
  2429. text="使用间隔",
  2430. variable=date_type,
  2431. ).grid(column=column + 2, row=row, sticky=tkinter.W)
  2432. row += 1
  2433. tkinter.Label(
  2434. SCREEN,
  2435. text="【数据类型管理】",
  2436. bg=bg_color,
  2437. fg=word_color,
  2438. font=FONT,
  2439. width=gui_width * 3,
  2440. height=gui_height,
  2441. ).grid(
  2442. column=column,
  2443. columnspan=3,
  2444. row=row,
  2445. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2446. ) # 设置说明
  2447. row += 1
  2448. tkinter.Label(
  2449. SCREEN,
  2450. text="修改(列号):",
  2451. bg=bg_color,
  2452. fg=word_color,
  2453. font=FONT,
  2454. width=gui_width,
  2455. height=gui_height,
  2456. ).grid(
  2457. column=column, row=row
  2458. ) # 设置说明
  2459. dtype_column = tkinter.Entry(SCREEN, width=gui_width * 2)
  2460. dtype_column.grid(
  2461. column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W
  2462. )
  2463. row += 1
  2464. tkinter.Label(
  2465. SCREEN,
  2466. text="数据类型:",
  2467. bg=bg_color,
  2468. fg=word_color,
  2469. font=FONT,
  2470. width=gui_width,
  2471. height=gui_height,
  2472. ).grid(
  2473. column=column, row=row
  2474. ) # 设置说明
  2475. dtype_input = tkinter.Entry(SCREEN, width=gui_width * 2)
  2476. dtype_input.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  2477. row += 1
  2478. tkinter.Label(
  2479. SCREEN,
  2480. text="错误值:",
  2481. bg=bg_color,
  2482. fg=word_color,
  2483. font=FONT,
  2484. width=gui_width,
  2485. height=gui_height,
  2486. ).grid(
  2487. column=column, row=row
  2488. ) # 设置说明
  2489. dtype_wrong = tkinter.Entry(SCREEN, width=gui_width * 2)
  2490. dtype_wrong.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  2491. row += 1
  2492. tkinter.Button(
  2493. SCREEN,
  2494. bg=buttom_bg_color,
  2495. fg=word_color,
  2496. text="执行转换",
  2497. command=API.set_dtype,
  2498. font=FONT,
  2499. width=gui_width,
  2500. height=gui_height,
  2501. ).grid(
  2502. column=column,
  2503. row=row,
  2504. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2505. )
  2506. dtype_func = tkinter.IntVar() # 正,负,0
  2507. lable = ["硬转换", "软转换"] # 复选框
  2508. for i in range(2):
  2509. tkinter.Radiobutton(
  2510. SCREEN,
  2511. bg=bg_color,
  2512. fg=word_color,
  2513. activebackground=bg_color,
  2514. activeforeground=word_color,
  2515. selectcolor=bg_color,
  2516. text=lable[i],
  2517. variable=dtype_func,
  2518. value=i,
  2519. ).grid(column=column + 1 + i, row=row, sticky=tkinter.W)
  2520. row += 1
  2521. tkinter.Label(
  2522. SCREEN,
  2523. text="【排序操作】",
  2524. bg=bg_color,
  2525. fg=word_color,
  2526. font=FONT,
  2527. width=gui_width * 3,
  2528. height=gui_height,
  2529. ).grid(
  2530. column=column, columnspan=3, row=row
  2531. ) # 设置说明
  2532. row += 1
  2533. tkinter.Button(
  2534. SCREEN,
  2535. bg=buttom_bg_color,
  2536. fg=word_color,
  2537. text=".T",
  2538. command=API.transpose,
  2539. font=FONT,
  2540. width=gui_width,
  2541. height=gui_height,
  2542. ).grid(
  2543. column=column,
  2544. row=row,
  2545. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2546. )
  2547. tkinter.Button(
  2548. SCREEN,
  2549. bg=buttom_bg_color,
  2550. fg=word_color,
  2551. text="按行名排序",
  2552. command=API.sort_by_tow,
  2553. font=FONT,
  2554. width=gui_width,
  2555. height=gui_height,
  2556. ).grid(
  2557. column=column + 1,
  2558. row=row,
  2559. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2560. )
  2561. tkinter.Button(
  2562. SCREEN,
  2563. bg=buttom_bg_color,
  2564. fg=word_color,
  2565. text="按列名排序",
  2566. command=API.sort_by_column,
  2567. font=FONT,
  2568. width=gui_width,
  2569. height=gui_height,
  2570. ).grid(
  2571. column=column + 2,
  2572. row=row,
  2573. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2574. )
  2575. row += 1
  2576. tkinter.Label(
  2577. SCREEN,
  2578. text="基准列(列号):",
  2579. bg=bg_color,
  2580. fg=word_color,
  2581. font=FONT,
  2582. width=gui_width,
  2583. height=gui_height,
  2584. ).grid(
  2585. column=column, row=row
  2586. ) # 设置说明
  2587. sort_by = tkinter.Entry(SCREEN, width=gui_width + 2)
  2588. sort_by.grid(column=column + 1, row=row, sticky=tkinter.W)
  2589. tkinter.Button(
  2590. SCREEN,
  2591. bg=buttom_bg_color,
  2592. fg=word_color,
  2593. text="按数据排序",
  2594. command=API.stored_value,
  2595. font=FONT,
  2596. width=gui_width,
  2597. height=gui_height,
  2598. ).grid(
  2599. column=column + 2,
  2600. row=row,
  2601. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2602. )
  2603. row += 1
  2604. ascending_type = tkinter.IntVar()
  2605. ascending_new = tkinter.IntVar()
  2606. lable = ["正序排列", "倒序排列"] # 复选框
  2607. for i in range(2):
  2608. tkinter.Radiobutton(
  2609. SCREEN,
  2610. bg=bg_color,
  2611. fg=word_color,
  2612. activebackground=bg_color,
  2613. activeforeground=word_color,
  2614. selectcolor=bg_color,
  2615. text=lable[i],
  2616. variable=ascending_type,
  2617. value=i,
  2618. ).grid(column=column + i, row=row, sticky=tkinter.W)
  2619. tkinter.Checkbutton(
  2620. SCREEN,
  2621. bg=bg_color,
  2622. fg=word_color,
  2623. activebackground=bg_color,
  2624. activeforeground=word_color,
  2625. selectcolor=bg_color,
  2626. text="生成新表格",
  2627. variable=ascending_new,
  2628. ).grid(column=column + 2, row=row, sticky=tkinter.W)
  2629. row += 1
  2630. stored_box = tkinter.Listbox(SCREEN, width=gui_width * 3, height=gui_height * 4) # 显示符号
  2631. stored_box.grid(
  2632. column=column,
  2633. row=row,
  2634. columnspan=3,
  2635. rowspan=5,
  2636. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
  2637. )
  2638. row += 5
  2639. tkinter.Button(
  2640. SCREEN,
  2641. bg=buttom_bg_color,
  2642. fg=word_color,
  2643. text="添加基准",
  2644. command=API.add_baseline,
  2645. font=FONT,
  2646. width=gui_width,
  2647. height=gui_height,
  2648. ).grid(
  2649. column=column,
  2650. row=row,
  2651. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2652. )
  2653. tkinter.Button(
  2654. SCREEN,
  2655. bg=buttom_bg_color,
  2656. fg=word_color,
  2657. text="删除基准",
  2658. command=API.del_baseline,
  2659. font=FONT,
  2660. width=gui_width,
  2661. height=gui_height,
  2662. ).grid(
  2663. column=column + 1,
  2664. row=row,
  2665. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2666. )
  2667. tkinter.Button(
  2668. SCREEN,
  2669. bg=buttom_bg_color,
  2670. fg=word_color,
  2671. text="打乱表格",
  2672. command=API.sample_data,
  2673. font=FONT,
  2674. width=gui_width,
  2675. height=gui_height,
  2676. ).grid(
  2677. column=column + 2,
  2678. row=row,
  2679. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2680. )
  2681. column += 3
  2682. tkinter.Label(SCREEN, text="", bg=bg_color, fg=word_color, font=FONT, width=1).grid(
  2683. column=column, row=row
  2684. ) # 设置说明
  2685. column += 1
  2686. row = 0
  2687. tkinter.Label(
  2688. SCREEN,
  2689. text="【机器学习】",
  2690. bg=bg_color,
  2691. fg=word_color,
  2692. font=FONT,
  2693. width=gui_width * 3,
  2694. height=gui_height,
  2695. ).grid(
  2696. column=column,
  2697. columnspan=3,
  2698. row=row,
  2699. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2700. ) # 设置说明
  2701. row += 1
  2702. chose_learner = tkinter.StringVar()
  2703. put = tkinter.Entry(SCREEN, width=gui_width * 2, textvariable=chose_learner)
  2704. put.grid(column=column, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  2705. put["state"] = "readonly"
  2706. tkinter.Button(
  2707. SCREEN,
  2708. bg=buttom_bg_color,
  2709. fg=word_color,
  2710. text="选用学习器",
  2711. command=API.set_learner_gui,
  2712. font=FONT,
  2713. width=gui_width,
  2714. height=gui_height,
  2715. ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
  2716. row += 1
  2717. tkinter.Label(
  2718. SCREEN,
  2719. text="测试数据分割:",
  2720. bg=bg_color,
  2721. fg=word_color,
  2722. font=FONT,
  2723. width=gui_width,
  2724. height=gui_height,
  2725. ).grid(column=column, row=row)
  2726. data_split = tkinter.Entry(SCREEN, width=gui_width * 2)
  2727. data_split.grid(column=column + 1, row=row, columnspan=2, sticky=tkinter.E + tkinter.W)
  2728. row += 1
  2729. learner_box = tkinter.Listbox(SCREEN, width=gui_width * 3, height=gui_height * 5)
  2730. learner_box.grid(
  2731. column=column,
  2732. row=row,
  2733. columnspan=3,
  2734. rowspan=5,
  2735. sticky=tkinter.E + tkinter.W + tkinter.S + tkinter.N,
  2736. )
  2737. row += 5
  2738. tkinter.Button(
  2739. SCREEN,
  2740. bg=buttom_bg_color,
  2741. fg=word_color,
  2742. text="导入学习器",
  2743. command=API.rendering,
  2744. font=FONT,
  2745. width=gui_width,
  2746. height=gui_height,
  2747. ).grid(
  2748. column=column,
  2749. row=row,
  2750. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2751. )
  2752. tkinter.Button(
  2753. SCREEN,
  2754. bg=buttom_bg_color,
  2755. fg=word_color,
  2756. text="查看数据",
  2757. command=API.visual_learner,
  2758. font=FONT,
  2759. width=gui_width,
  2760. height=gui_height,
  2761. ).grid(
  2762. column=column + 1,
  2763. row=row,
  2764. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2765. )
  2766. tkinter.Button(
  2767. SCREEN,
  2768. bg=buttom_bg_color,
  2769. fg=word_color,
  2770. text="删除学习器",
  2771. command=API.del_learner,
  2772. font=FONT,
  2773. width=gui_width,
  2774. height=gui_height,
  2775. ).grid(
  2776. column=column + 2,
  2777. row=row,
  2778. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2779. )
  2780. row += 1
  2781. tkinter.Button(
  2782. SCREEN,
  2783. bg=buttom_bg_color,
  2784. fg=word_color,
  2785. text="训练机器",
  2786. command=API.fit_learner,
  2787. font=FONT,
  2788. width=gui_width,
  2789. height=gui_height,
  2790. ).grid(
  2791. column=column,
  2792. row=row,
  2793. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2794. )
  2795. tkinter.Button(
  2796. SCREEN,
  2797. bg=buttom_bg_color,
  2798. fg=word_color,
  2799. text="测试机器",
  2800. command=API.test_learner,
  2801. font=FONT,
  2802. width=gui_width,
  2803. height=gui_height,
  2804. ).grid(
  2805. column=column + 1,
  2806. row=row,
  2807. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2808. )
  2809. tkinter.Button(
  2810. SCREEN,
  2811. bg=buttom_bg_color,
  2812. fg=word_color,
  2813. text="数据预测",
  2814. command=API.predict_learner,
  2815. font=FONT,
  2816. width=gui_width,
  2817. height=gui_height,
  2818. ).grid(
  2819. column=column + 2,
  2820. row=row,
  2821. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2822. )
  2823. row += 1
  2824. tkinter.Label(
  2825. SCREEN,
  2826. text="【学习器选择和配置】",
  2827. bg=bg_color,
  2828. fg=word_color,
  2829. font=FONT,
  2830. width=gui_width * 3,
  2831. height=gui_height,
  2832. ).grid(
  2833. column=column,
  2834. columnspan=3,
  2835. row=row,
  2836. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2837. ) # 设置说明
  2838. row += 1
  2839. tkinter.Button(
  2840. SCREEN,
  2841. bg=buttom_bg_color,
  2842. fg=word_color,
  2843. text="线性回归",
  2844. command=API.add_generalized_linear,
  2845. font=FONT,
  2846. width=gui_width,
  2847. height=gui_height,
  2848. ).grid(
  2849. column=column,
  2850. row=row,
  2851. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2852. )
  2853. tkinter.Button(
  2854. SCREEN,
  2855. bg=buttom_bg_color,
  2856. fg=word_color,
  2857. text="岭回归",
  2858. command=API.add_ridge,
  2859. font=FONT,
  2860. width=gui_width,
  2861. height=gui_height,
  2862. ).grid(
  2863. column=column + 1,
  2864. row=row,
  2865. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2866. )
  2867. tkinter.Button(
  2868. SCREEN,
  2869. bg=buttom_bg_color,
  2870. fg=word_color,
  2871. text="Lasso",
  2872. command=API.add_lasso,
  2873. font=FONT,
  2874. width=gui_width,
  2875. height=gui_height,
  2876. ).grid(
  2877. column=column + 2,
  2878. row=row,
  2879. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2880. )
  2881. row += 1
  2882. tkinter.Button(
  2883. SCREEN,
  2884. bg=buttom_bg_color,
  2885. fg=word_color,
  2886. text="逻辑回归",
  2887. command=API.add_logistic_regression,
  2888. font=FONT,
  2889. width=gui_width,
  2890. height=gui_height,
  2891. ).grid(
  2892. column=column,
  2893. row=row,
  2894. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2895. )
  2896. tkinter.Button(
  2897. SCREEN,
  2898. bg=buttom_bg_color,
  2899. fg=word_color,
  2900. text="决策树",
  2901. command=API.show_sorry_gui,
  2902. font=FONT,
  2903. width=gui_width,
  2904. height=gui_height,
  2905. ).grid(
  2906. column=column + 1,
  2907. row=row,
  2908. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2909. )
  2910. tkinter.Button(
  2911. SCREEN,
  2912. bg=buttom_bg_color,
  2913. fg=word_color,
  2914. text="SVM",
  2915. command=API.show_sorry_gui,
  2916. font=FONT,
  2917. width=gui_width,
  2918. height=gui_height,
  2919. ).grid(
  2920. column=column + 2,
  2921. row=row,
  2922. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2923. )
  2924. row += 1
  2925. tkinter.Button(
  2926. SCREEN,
  2927. bg=buttom_bg_color,
  2928. fg=word_color,
  2929. text="朴素贝叶斯",
  2930. command=API.show_sorry_gui,
  2931. font=FONT,
  2932. width=gui_width,
  2933. height=gui_height,
  2934. ).grid(
  2935. column=column,
  2936. row=row,
  2937. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2938. )
  2939. tkinter.Button(
  2940. SCREEN,
  2941. bg=buttom_bg_color,
  2942. fg=word_color,
  2943. text="K邻近分类",
  2944. command=API.add_knn_regression,
  2945. font=FONT,
  2946. width=gui_width,
  2947. height=gui_height,
  2948. ).grid(
  2949. column=column + 1,
  2950. row=row,
  2951. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2952. )
  2953. tkinter.Button(
  2954. SCREEN,
  2955. bg=buttom_bg_color,
  2956. fg=word_color,
  2957. text="K邻近预测",
  2958. command=API.add_knn_class,
  2959. font=FONT,
  2960. width=gui_width,
  2961. height=gui_height,
  2962. ).grid(
  2963. column=column + 2,
  2964. row=row,
  2965. sticky=tkinter.E + tkinter.W + tkinter.W + tkinter.S + tkinter.N,
  2966. )
  2967. row += 1
  2968. learner_parameters = tkinter.Text(SCREEN, width=gui_width * 3, height=gui_height * 11)
  2969. learner_parameters.grid(
  2970. column=column,
  2971. row=row,
  2972. columnspan=3,
  2973. rowspan=11,
  2974. sticky=tkinter.E + tkinter.W + tkinter.N + tkinter.S,
  2975. )