1
2 """
3 Interface to the PARK fitting service.
4
5 *** WARNING *** This is a design sketch and is not presently used.
6
7 TODO: user and url need to be retrieved from a config file with defaults
8 """
9
11 """
12 Client-side view of the fitting service.
13 """
19
20
21 - def notify(self,email=None,rate=None):
22 """Set the email address and update frequency for user notification"""
23 if email is not None:
24 self.server.setemail(self.context, email)
25 if rate is not None:
26 self.server.setrate(self.context, rate)
27
28
34 - def stop(self, jobid):
41 """Retrieve job"""
42 text = self.server.retrieve(self.context, jobid)
43 return encode(text)
47
48
54
55 - def listen(self, callback=on_message):
56 """
57 Listen to the message queue for information about running jobs.
58
59 The listener runs in a separate thread, allowing the listen
60 call to return immediately. The callback is called each time
61 there is a new message on the queue. If no callback is
62 supplied, then a simple print is used.
63 """
64 thread.start_new_thread(self._listener,(callback,))
65
66
67
69 """
70 Coordinate the fit.
71 """
72 update = on_fit_update
73 complete = on_fit_complete
74 - def __init__(self, models = [],
75 optimizer = None,
76 service = None,
77 update = None,
78 complete = None):
79 """
80 Set up the fit.
81
82 models []
83 List of models which make up the assembly.
84 optimizer
85 Optimizer to use for the fit
86 """
87 self.assembly = assembly.Assembly(models)
88 self.optimizer = optimizer
89 self.complete = complete
90 self.update = update
91 self.isrunning = False
92 self._stopping = False
93
95 """
96 Interrupt a running fit.
97 """
98 self._stopping = True
99 self.service.stop()
100
106
110
114
116 """
117 Wait for a fit to complete.
118 """
119 while self.isrunning: time.sleep(0.1)
120
122 """
123 Start the fit and wait for the result.
124 Returns the result.
125 """
126 self.start()
127 self.wait()
128 return self.result
129