Changeset 78312f7 in sasview for src/sas/sasgui/perspectives/fitting/pagestate.py
- Timestamp:
- Jun 19, 2017 8:10:07 PM (7 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 2a0f33f
- Parents:
- bc04647
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/pagestate.py
r959eb01 r78312f7 15 15 import os 16 16 import sys 17 import wx18 17 import copy 19 18 import logging … … 519 518 rep = "\nState name: %s\n" % self.file 520 519 t = time.localtime(self.timestamp) 521 time_str = time.strftime("%b %d %Y %H ;%M;%S ", t)520 time_str = time.strftime("%b %d %Y %H:%M:%S ", t) 522 521 523 522 rep += "State created: %s\n" % time_str … … 596 595 return rep 597 596 598 def set_report_string(self):597 def _get_report_string(self): 599 598 """ 600 599 Get the values (strings) from __str__ for report … … 611 610 q_range = "" 612 611 strings = self.__repr__() 612 fixed_parameter = False 613 613 lines = strings.split('\n') 614 615 614 # get all string values from __str__() 616 615 for line in lines: 617 value = ""618 content = line.split(":")619 name = content[0]620 try:621 value = content[1]622 except Exception:623 msg = "Report string expected 'name: value' but got %r" % line 624 logger.error(msg)625 if name .count("State created"):626 repo_time = "" +value627 if name.count("parameter name"):616 # Skip lines which are not key: value pairs, which includes 617 # blank lines and freeform notes in SASNotes fields. 618 if not ':' in line: 619 #msg = "Report string expected 'name: value' but got %r" % line 620 #logger.error(msg) 621 continue 622 623 name, value = [s.strip() for s in line.split(":", 1)] 624 if name == "State created": 625 repo_time = value 626 elif name == "parameter name": 628 627 val_name = value.split(".") 629 628 if len(val_name) > 1: … … 634 633 else: 635 634 param_string += value + ',' 636 if name == "value":635 elif name == "value": 637 636 param_string += value + ',' 638 fixed_parameter = False 639 if name == "selected": 640 if value == u' False': 641 fixed_parameter = True 642 if name == "error value": 637 elif name == "selected": 638 # remember if it is fixed when reporting error value 639 fixed_parameter = (value == u'False') 640 elif name == "error value": 643 641 if fixed_parameter: 644 642 param_string += '(fixed),' 645 643 else: 646 644 param_string += value + ',' 647 if name == "parameter unit":645 elif name == "parameter unit": 648 646 param_string += value + ':' 649 if name == "Value of Chisqr":647 elif name == "Value of Chisqr": 650 648 chi2 = ("Chi2/Npts = " + value) 651 649 chi2_string = CENTRE % chi2 652 if name == "Title":650 elif name == "Title": 653 651 if len(value.strip()) == 0: 654 652 continue 655 653 title = value + " [" + repo_time + "]" 656 654 title_name = HEADER % title 657 if name == "data":655 elif name == "data": 658 656 try: 659 file_value = ("File name:" + content[2]) 657 # parsing "data : File: filename [mmm dd hh:mm]" 658 name = value.split(':', 1)[1].strip() 659 file_value = "File name:" + name 660 660 file_name = CENTRE % file_value 661 661 if len(title) == 0: 662 title = content[2]+ " [" + repo_time + "]"662 title = name + " [" + repo_time + "]" 663 663 title_name = HEADER % title 664 664 except Exception: 665 665 msg = "While parsing 'data: ...'\n" 666 666 logger.error(msg + traceback.format_exc()) 667 if name == "model name":667 elif name == "model name": 668 668 try: 669 modelname = "Model name:" + content[1]670 except :669 modelname = "Model name:" + value 670 except Exception: 671 671 modelname = "Model name:" + " NAN" 672 672 model_name = CENTRE % modelname 673 673 674 if name == "Plotting Range":674 elif name == "Plotting Range": 675 675 try: 676 q_range = content[1] + " = " + content[2] \ 677 + " = " + content[3].split(",")[0] 676 parts = value.split(':') 677 q_range = parts[0] + " = " + parts[1] \ 678 + " = " + parts[2].split(",")[0] 678 679 q_name = ("Q Range: " + q_range) 679 680 q_range = CENTRE % q_name … … 681 682 msg = "While parsing 'Plotting Range: ...'\n" 682 683 logger.error(msg + traceback.format_exc()) 684 683 685 paramval = "" 684 686 for lines in param_string.split(":"): … … 709 711 "\n" + paramval_string + \ 710 712 "\n" + ELINE + \ 711 "\n" + FEET_1 % title + \ 712 "\n" + FEET_2 713 "\n" + FEET_1 % title 713 714 714 715 return html_string, text_string, title … … 723 724 return name 724 725 725 def report(self, fig s=None, canvases=None):726 def report(self, fig_urls): 726 727 """ 727 728 Invoke report dialog panel … … 729 730 : param figs: list of pylab figures [list] 730 731 """ 731 from sas.sasgui.perspectives.fitting.report_dialog import ReportDialog732 732 # get the strings for report 733 html_str, text_str, title = self. set_report_string()733 html_str, text_str, title = self._get_report_string() 734 734 # Allow 2 figures to append 735 if len(figs) == 1: 736 add_str = FEET_3 737 elif len(figs) == 2: 738 add_str = ELINE 739 add_str += FEET_2 % ("%s") 740 add_str += ELINE 741 add_str += FEET_3 742 elif len(figs) > 2: 743 add_str = ELINE 744 add_str += FEET_2 % ("%s") 745 add_str += ELINE 746 add_str += FEET_2 % ("%s") 747 add_str += ELINE 748 add_str += FEET_3 749 else: 750 add_str = "" 735 image_links = [FEET_2%fig for fig in fig_urls] 751 736 752 737 # final report html strings 753 report_str = html_str % ("%s") + add_str 754 755 # make plot image 756 images = self.set_plot_state(figs, canvases) 757 report_list = [report_str, text_str, images] 758 dialog = ReportDialog(report_list, None, wx.ID_ANY, "") 759 dialog.Show() 738 report_str = html_str + ELINE.join(image_links) 739 740 return report_str, text_str 760 741 761 742 def _to_xml_helper(self, thelist, element, newdoc): … … 805 786 try: 806 787 top_element = newdoc.createElement(FITTING_NODE_NAME) 807 except :788 except Exception: 808 789 string = etree.tostring(doc, pretty_print=True) 809 790 newdoc = parseString(string) … … 814 795 try: 815 796 entry_node.appendChild(top_element) 816 except :797 except Exception: 817 798 node_name = entry_node.tag 818 799 node_list = newdoc.getElementsByTagName(node_name) … … 1036 1017 try: 1037 1018 self.timestamp = float(entry.get('epoch')) 1038 except :1019 except Exception: 1039 1020 msg = "PageState.fromXML: Could not" 1040 1021 msg += " read timestamp\n %s" % sys.exc_value … … 1104 1085 dic[name] = np.array(value_list) 1105 1086 setattr(self, varname, dic) 1106 1107 def set_plot_state(self, figs, canvases):1108 """1109 Build image state that wx.html understand1110 by plotting, putting it into wx.FileSystem image object1111 1112 """1113 images = []1114 1115 # Reset memory1116 self.imgRAM = None1117 wx.MemoryFSHandler()1118 1119 # For no figures in the list, prepare empty plot1120 if figs is None or len(figs) == 0:1121 figs = [None]1122 1123 # Loop over the list of figures1124 # use wx.MemoryFSHandler1125 self.imgRAM = wx.MemoryFSHandler()1126 for fig in figs:1127 if fig is not None:1128 ind = figs.index(fig)1129 canvas = canvases[ind]1130 1131 # store the image in wx.FileSystem Object1132 wx.FileSystem.AddHandler(wx.MemoryFSHandler())1133 1134 # index of the fig1135 ind = figs.index(fig)1136 1137 # AddFile, image can be retrieved with 'memory:filename'1138 self.imgRAM.AddFile('img_fit%s.png' % ind,1139 canvas.bitmap, wx.BITMAP_TYPE_PNG)1140 1141 # append figs1142 images.append(fig)1143 1144 return images1145 1087 1146 1088 … … 1410 1352 return doc 1411 1353 1412 # Simple html report templ et1354 # Simple html report template 1413 1355 HEADER = "<html>\n" 1414 1356 HEADER += "<head>\n" … … 1438 1380 """ 1439 1381 FEET_2 = \ 1440 """ 1441 <img src="%s" > 1442 </img> 1382 """<img src="%s" ></img> 1443 1383 """ 1444 1384 FEET_3 = \ 1445 """ 1446 </center> 1385 """</center> 1447 1386 </div> 1448 1387 </body> 1449 1388 </html> 1450 1389 """ 1451 ELINE = "<p class=MsoNormal> </p>" 1390 ELINE = """<p class=MsoNormal> </p> 1391 """
Note: See TracChangeset
for help on using the changeset viewer.