Repository for M.A.I.L system's recording client.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import tkinter
  2. import json
  3. import paramiko
  4. import time
  5. from datetime import datetime
  6. from tkinter import messagebox
  7. import os
  8. import git
  9. from paramiko import file
  10. import pymssql
  11. window = tkinter.Tk()
  12. settings =[]
  13. customer_code = ''
  14. surgery_date = str(time.strftime('%Y%m%d', time.localtime(time.time())))
  15. cnxn = pymssql.connect('52.231.39.219' , 'mc365', 'tkadbrdhmc1!', 'tsfmc_data')
  16. cursor = cnxn.cursor()
  17. with open('./settings.json', encoding='utf-8')as json_file:
  18. json_data = json.load(json_file)
  19. settings.append(json_data['window_name'])
  20. settings.append(json_data['window_position'])
  21. settings.append(json_data['branch_location'])
  22. settings.append(json_data['surgery_room_number'])
  23. settings.append(json_data['ddns'])
  24. settings.append(json_data['account']) #settings[5]
  25. settings.append(json_data['password']) #settings[6]
  26. window.title(settings[0])
  27. window.geometry(settings[1])
  28. window.resizable(False,False)
  29. def sshConnect(cs, sd):
  30. cs = cs
  31. sd = sd
  32. filepath = './log.txt'
  33. ssh = paramiko.SSHClient()
  34. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  35. ssh.connect(settings[4],port= settings[3], username=settings[5], password=settings[6])
  36. data_root_dir = './data/'+cs+sd
  37. stdin, stdout, stderr = ssh.exec_command('mkdir ' + data_root_dir)
  38. #TODO: 여기에 도커 명령어 및 동시 녹화 코드 입력
  39. cmd = 'docker run --rm --name mail_recorder --gpus 1 --privileged -v /dev:/dev -v /home/mc365/sources:/sources -v /home/mc365/data/'+cs+sd+':/data/'+cs+sd+' stereolabs/zed:3.5-gl-devel-cuda11.1-ubuntu18.04 python3 /sources/rec_ubuntu.py'
  40. print(cmd)
  41. stdin, stdout, stderr = ssh.exec_command(cmd)
  42. f = open(filepath, 'w')
  43. r_time = time.ctime(time.time())
  44. f.write('record succesfully started at ' + str(r_time) + '\n')
  45. f.close()
  46. def sshQuit(cs, sd):
  47. cs = cs
  48. sd = sd
  49. filepath = './log.txt'
  50. data_root_dir = './data/'+cs+sd
  51. f = open(filepath, 'a')
  52. r_time = time.ctime(time.time())
  53. f.write('record succesfully stopped at ' + str(r_time)+ '\n')
  54. f.close()
  55. transport = paramiko.Transport((settings[4], settings[3]))
  56. transport.connect(username=settings[5], password=settings[6])
  57. sftp = paramiko.SFTPClient.from_transport(transport)
  58. sftp.put(filepath, data_root_dir + filepath[1:])
  59. sftp.close()
  60. transport.close()
  61. os.remove(filepath)
  62. ssh = paramiko.SSHClient()
  63. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  64. ssh.connect(settings[4],port= settings[3], username=settings[5], password=settings[6])
  65. t = ssh.get_transport()
  66. c = t.open_session()
  67. c.exec_command('docker stop mail_recorder && mv ' + data_root_dir + ' /hdd/')
  68. label_branch = tkinter.Label(window, text = '지점 위치: ' + settings[2] + ' / 수술방 번호: ' + str(settings[3]))
  69. label_customer_code = tkinter.Label(window, text="고객번호(지점 번호 포함 9자리)")
  70. def dummyexit():
  71. pass
  72. def askInformation(customer_code,surgery_date, customer_name):
  73. cs = customer_code
  74. sd = surgery_date
  75. global pk
  76. pk = cs + sd
  77. if len(cs) != 9:
  78. err_box = messagebox.showerror("고객 번호 오류", '지점 번호를 포함한 9자리를 입력해주세요.')
  79. else:
  80. msg_box = messagebox.askquestion("입력 정보 확인", "\n고객 이름 : " + customer_name + "\n\n고객 번호 : " + customer_code + '\n\n맞으면 Yes를 눌러 기록시작을,\n 틀리면 No를 눌러 수정해주세요.')
  81. #TODO: try: 형태로 고칠 것. Err 메세지도 종류 정할 것
  82. if msg_box == 'yes':
  83. global start_time
  84. start_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  85. err_status = True
  86. if err_status == False:
  87. label_recording = tkinter.Label(window, text='분석 PC에 문제가 발생하였습니다.\nHOBIT LAB으로 연락 부탁드립니다.\n내선번호: 1103 \n에러 코드: REQUEST TIME OUT')
  88. label_recording.pack()
  89. else:
  90. #TODO: paramiko로 ssh 접속 후 도커 명령어 보낼 것
  91. sshConnect(cs, sd)
  92. button_confirm['text'] = '기록 종료'
  93. window.protocol('WM_DELETE_WINDOW', dummyexit)
  94. label_recording = tkinter.Label(window, text='MAIL system에 수술을 기록 중입니다.\n기록 중단을 원할 시 \n기록 종료 버튼을 눌러주세요.')
  95. label_recording.pack()
  96. def askQuit(cn, sd):
  97. customer_number = cn
  98. surgery_date = sd
  99. msg_box = messagebox.askquestion("기록 중지 확인", '기록을 중지하시겠습니까?')
  100. if msg_box == 'yes':
  101. end_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  102. # print(str(end_time))
  103. data = [(pk, json_data['branch_location'], json_data['surgery_room_number'], str(start_time), str(end_time))]
  104. cursor.executemany("INSERT into tsfmc_mailsystem.dbo.MAIL_SURGERYCOUNT values ( %s, %s, %d, %s, %s)", data)
  105. cnxn.commit()
  106. #TODO: docker 중지 명령어 보내기
  107. sshQuit(customer_number, surgery_date)
  108. window.destroy()
  109. def buttonAction(event):
  110. customer_code = str(entry_customer_code.get())
  111. cursor.execute("SELECT PSNAME FROM ADM010T WHERE PSENTRY='{}';".format(customer_code) )
  112. customer_name = cursor.fetchone()[0]
  113. if button_confirm['text'] == '입력완료':
  114. askInformation(customer_code, surgery_date, customer_name)
  115. else:
  116. askQuit(customer_code,surgery_date)
  117. # def fillSurgeryDate():
  118. entry_customer_code = tkinter.Entry(window)
  119. entry_surgery_date = tkinter.Entry(window)
  120. button_confirm = tkinter.Button(window, text="입력완료", width=20, height=2)
  121. button_confirm.bind("<Button-1>", buttonAction)
  122. label_branch.pack()
  123. label_customer_code.pack()
  124. entry_customer_code.pack()
  125. button_confirm.pack()
  126. if __name__ == "__main__":
  127. lastmod = int(os.path.getmtime('./main.py'))
  128. #NOTE: UPDATE PROGRESSING....
  129. print(lastmod)
  130. os.system('git merge origin/alpha')
  131. if lastmod != int(os.path.getmtime('./main.py')):
  132. pass
  133. else:
  134. window.mainloop()