-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCmdAnalysis.py
109 lines (88 loc) · 2.75 KB
/
CmdAnalysis.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
import multiprocessing
from multiprocessing import Process
import time
import threading
import os
import NN_Train
import EmailTool
import Global
def nn(params,nameparams):
train, test = NN_Train.GetDate()
print(params)
print(nameparams)
msg = ('%s\n') % str(params)
msg += ('%s\n') % str(nameparams)
msg += NN_Train.NN_Train(
NN_Train.GetNN(),
train_data=train,
test_data=test,
params = params,
nameparams = nameparams)
EmailTool.SentEmail(msg, 'TrainResult',os.path.join(nameparams['dir'],nameparams['png']))
def run():
p = Process(target=nn,args=(Global.params,Global.nameparams,))
print('TrainStrart')
Global.running = True
p.start()
p.join()
Global.running = False
class BaseCmd:
def __init__(self, cmd):
self.Next = None
self.cmd = cmd
def SetNext(self, n):
self.Next = n
def DoAnalysis(self, cmd, params):
if cmd == self.cmd:
self.Work(params)
elif self.Next is not None:
self.Next.DoAnalysis(cmd, params)
def Work(self, params):
pass
class TrainCmd(BaseCmd):
def __init__(self, cmd):
BaseCmd.__init__(self, cmd)
def Work(self, msg):
print('train')
if Global.running == False:
xx = msg.split('\r\n')
for k in xx:
ks = k.split(' ')
if len(ks) > 1:
Global.params[ks[0]] = float(ks[1])
t = threading.Thread(target=run)
t.start()
else:
message = ('Training is underway\n%s\n%s') % (str(Global.params),str(Global.nameparams))
EmailTool.SentEmail(message,
'Training is underway',
None)
class ExitCmd(BaseCmd):
def __init__(self, cmd):
BaseCmd.__init__(self, cmd)
def Work(self, params):
print('exit')
os._exit(0)
class SetNameParamsCmd(BaseCmd):
def __init__(self,cmd):
BaseCmd.__init__(self,cmd)
def Work(self,msg):
xx = msg.split('\r\n')
for k in xx:
ks = k.split(' ')
if len(ks) > 1:
Global.nameparams[ks[0]] = ks[1]
print(Global.nameparams)
EmailTool.SentEmail(str(Global.nameparams),'NameParams',None)
class CmdAnaly:
def __init__(self):
self.CmdList = []
self.Add(ExitCmd('exit'))
self.Add(TrainCmd('train'))
self.Add(SetNameParamsCmd('setname'))
def Add(self, cmd):
self.CmdList.append(cmd)
if len(self.CmdList) > 1:
self.CmdList[len(self.CmdList) - 2].SetNext(self.CmdList[len(self.CmdList) - 1])
def Analy(self, cmd, params):
self.CmdList[0].DoAnalysis(cmd, params)