source: sasview/sansview/perspectives/fitting/console.py @ 1350c87

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 1350c87 was e54d2c32, checked in by Gervaise Alina <gervyh@…>, 15 years ago

working on status bar display for fit

  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[e54d2c32]1
2
3
4from sans.guicomm.events import StatusEvent
5import time
6import wx
7import park
8from park.fitresult import FitHandler
9
10class ConsoleUpdate(FitHandler):
11    """
12    Print progress to the console.
13    """
14    isbetter = False
15    """Record whether results improved since last update"""
16    progress_delta =  60
17    """Number of seconds between progress updates"""
18    improvement_delta = 5
19    """Number of seconds between improvement updates"""
20    def __init__(self,parent, quiet=False,progress_delta=60,improvement_delta=5):
21        """
22        If quiet is true, only print out final summary, not progress and
23        improvements.
24        """
25        self.parent= parent
26        self.progress_time = time.time()
27        self.progress_percent = 0
28        self.improvement_time = self.progress_time
29        self.isbetter = False
30        self.quiet = quiet
31        self.progress_delta = progress_delta
32        self.improvement_delta = improvement_delta
33        self.elapsed_time = self.progress_time
34       
35    def progress(self, k, n):
36        """
37        Report on progress.
38        """
39        if self.quiet: return
40
41        t = time.time()
42        p = int((100*k)//n)
43       
44        # Show improvements if there are any
45        dt = t - self.improvement_time
46        if self.isbetter and dt > self.improvement_delta:
47            self.result.print_summary()
48            self.isbetter = False
49            self.improvement_time = t
50           
51            wx.PostEvent(self.parent, StatusEvent(status=\
52             "%d%% complete ..."%(p),type="progress"))
53       
54        # Update percent complete
55        dp = p-self.progress_percent
56        if dp < 1: return
57        dt = t - self.progress_time
58        if dt > self.progress_delta:
59            if 1 <= dp <= 2:
60                self.progress_percent = p
61                self.progress_time = t
62                wx.PostEvent(self.parent, StatusEvent(status=\
63                                                      "%d%% complete ..."%(p),
64                                                      type="progress"))
65       
66            elif 2 < dp <= 5:
67                if p//5 != self.progress_percent//5:
68                    wx.PostEvent(self.parent, StatusEvent(status=\
69                       "%d%% complete ..."%(5*(p//5)),type="progress"))
70                    self.progress_percent = p
71                    self.progress_time = t
72            else:
73                if p//10 != self.progress_percent//10:
74                    self.progress_percent = p
75                    self.progress_time = t
76                    wx.PostEvent(self.parent, StatusEvent(status=\
77                   "%d%% complete ..."%(10*(p//10)),type="progress"))
78       
79    def improvement(self):
80        """
81        Called when a result is observed which is better than previous
82        results from the fit.
83        """
84        self.isbetter = True
85   
86    def error(self, msg):
87        """
88        Model had an error; print traceback
89        """
90        if self.isbetter:
91            self.result.print_summary()
92        message = "fit Error"
93        message = str(msg)+ " \n %s"%self.result.__str__()
94        wx.PostEvent(self.parent, StatusEvent(status=message,
95                                              info="error", type="stop"))
96           
97    def finalize(self):
98        if self.isbetter:
99            self.result.print_summary()
100
101    def abort(self):
102        if self.isbetter:
103            self.result.print_summary()
104           
105    def update_fit(self, msg=""):
106        self.elapsed_time = time.time() - self.elapsed_time
107        msg = " Updating fit ...\n result:\n %s \n"%self.result.__str__()
108        wx.PostEvent(self.parent, StatusEvent(status=msg, info="info",
109                                              type="progress"))
110       
111    def starting_fit(self):
112        wx.PostEvent(self.parent, StatusEvent(status="Starting the Fit...",
113                                        info="info",type="progress"))
114       
115    def set_result(self, result):
116        self.result = result
117       
118   
Note: See TracBrowser for help on using the repository browser.