-
Notifications
You must be signed in to change notification settings - Fork 0
/
processterminal.py
112 lines (87 loc) · 2.74 KB
/
processterminal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env python
# test if barcode in correct production run and passed testing
# tell with how many boards found total and by user
import os
import sys
import traceback
import string
import subprocess
import psycopg2
from colorama import init
from termcolor import colored, cprint
import winsound
import datetime
# terminal init for windows
init()
goodfrequency = 2500
goodduration = 1000
print ("Log process step for board")
directory = os.path.split(os.path.realpath(__file__))[0]
print ("Connecting to database...")
dbfile = open(directory+'/postgres_info.txt', 'r')
postgresInfo = dbfile.read()
dbfile.close()
try:
testStorage = psycopg2.connect(postgresInfo)
print ("Connect success.")
except:
print ("Could not connect!")
sys.exit(0)
state = "logging"
runId = '-1'
user = '-1'
process = 'Wave Solder'
process_step = 'Seho'
# get user name from terminal
while user == '-1':
print ("\nEnter User ID : ")
user = input()
if user == 'exit':
sys.exit(0)
# get runId number from terminal
while runId == '-1':
print ("\nEnter Run ID : ")
runId = input()
if runId == 'exit':
sys.exit(0)
while (state == 'logging'):
#setup database
conn = psycopg2.connect(postgresInfo)
cur = conn.cursor()
# get serial number from terminal
print ("\nCurrent Run ID " + runId)
print ("Current Operator : " + user)
print ("Current Process " + process)
print ("Current Process Step " + process_step)
print ("Type exit to exit")
print ("\nEnter serial number : ")
serialNumber = input()
if serialNumber == 'exit':
sys.exit(0)
try:
# write board serial number to process log
insertquery = """INSERT INTO process_log (serial, operator, runid, process, process_step) VALUES (%s,%s,%s,%s,%s)"""
# print (insertquery)
# print (serialNumber + " " + user + " " + runId + " " + process + " " + process_step)
cur.execute(insertquery,(serialNumber,user,runId,process,process_step))
conn.commit()
print (colored("Logged "+ serialNumber,'white','on_green'))
winsound.Beep(3000, 800)
mytoday = str(datetime.date.today())
mytomorrow = str(datetime.date.today() + datetime.timedelta(days=1))
cur.execute("""SELECT date_part('day', time) AS day, process_step, COUNT (DISTINCT serial) AS boards
FROM process_log WHERE time >= %s AND time < %s
GROUP BY day, process_step ORDER BY boards DESC""", (mytoday, mytomorrow ))
rows = cur.fetchall()
for row in rows:
print(str(row))
conn.commit()
cur.close()
except (Exception, psycopg2.DatabaseError) as error :
print ("Error in transction Reverting all other operations of a transction ", error)
conn.rollback()
finally:
#closing database connection.
if(conn):
cur.close()
conn.close()