def parse(self):
     
     __sheetnames = [u'Q1 GeneralData', 
           u'Q2 EnergyConsumption', 
           u'Q3_ Processes', 
           u'Q3A', 
           u'Q4H_HeatGeneration', 
           u'Q4C_ColdGeneration', 
           u'Q5_Distribution', 
           u'Q6_HeatRecovery', 
           u'Q7_ Renewables', 
           u'Q8 Buildings', 
           u'Q9 Economics']
     
     dlg = DialogGauge(None,"OpenOffice Calc Parsing","reading document")
     self.__md = self.__connectToDB()
     xmlString = self.readOOContent(self.__filepath)
     dlg.update(10)
     parsedDom = xml.dom.minidom.parseString(xmlString)
     dlg.update(53)
     
     __handle, lists = self.__getLists(parsedDom, dlg, __sheetnames)
     DButil = Utils(self.__md, __sheetnames)
     __handle = DButil.writeToDB(lists)
     dlg.update(100)
     dlg.Destroy()
     return __handle
Example #2
0
    def replaceData(self):
        #
        # Scan the sheet names list and change values on each
        # sheet on the list
        #
        dlg = DialogGauge(None,"Report generation","writing report")
        nSheets = len(self.sheetnames.keys())
        i = 0.0

        for sheetname in self.sheetnames.keys():
            #
            # get the list of names,changes for this sheet
            # each element of the list has the structure:
            # [name,[col,row]] for cells
            # [name,[left_col, upper_row,  right_col,lower_row]] for ranges
            #
            changesList = self.sheetnames[sheetname]
            nChanges = len(changesList)
            if nChanges == 0: i += 1
            for cl in changesList:
                thename = cl[0]
                if not Interfaces.GData.has_key(thename):
#                    print "PanelReport: no data available for key %s"%thename
                    continue
                # found a name on this sheet
#                print "PanelReport (replaceData): Key = ",thename
                data = Interfaces.GData[thename]
                thelist = cl[1]
                ncol = thelist[0]
                nrow = thelist[1]
#                print "panelReport: data block found. sheet:%s name:%s row %s col %s" %\
#                      (sheetname,thename,nrow,ncol)
                try:
                    (datarows,datacols) = data.shape
                except:
                    logDebug("PanelReport (replaceData): no data shape found for key %s"%thename)
                    continue
#                print "panelReport: datacols %s datarows %s data %s" % (datacols,datarows,repr(data))
                self._findCellRange(sheetname,nrow,datarows,ncol,datacols,data)
                i += 1.0/nChanges
                dlg.update(100.0 * i / nSheets)

            dlg.update(100.0 * i / nSheets)
        dlg.Destroy()
Example #3
0
    def createNamesTable(self):

        dlg = DialogGauge(None,"Report generation","screening master")

        self.names = {}
        self.sheetnames = {}

        namelements = self.document.getElementsByTagName("table:named-range")

        nElements = len(namelements)
        i = 0
        for namelement in namelements:
            name = namelement.getAttribute('table:name')
            if not name.startswith(PREFIX):
                continue
            name = name[len(PREFIX):]
            range = namelement.getAttribute('table:cell-range-address')
            m = self.getNameComponents(range)
            if m is not None:
                (sheetname,itemlist) = m

#                print "createNamesTable %r %r - %r"%(name,sheetname,itemlist)
                
                self.names[name] = [sheetname,itemlist]
                sheetlist = []
                if self.sheetnames.has_key(sheetname):
                    sheetlist = self.sheetnames[sheetname]
                sheetlist.append([name,itemlist])
                self.sheetnames[sheetname] = sheetlist
        #for s in self.names.keys():
        #    print 'self.names. key',s,'value',self.names[s]
        #for s in self.sheetnames.keys():
        #    print 'self.sheetnames. key',s,'value',self.sheetnames[s]
            dlg.update(100.0 * i / nElements)
            i += 1
        dlg.Destroy()
Example #4
0
 def parseold(self):
     dlg = DialogGauge(None,"OpenOffice Calc Parsing","reading document")
     self.__md = self.__connectToDB()
     xmlString = self.readOOContent(self.__filepath)
     dlg.update(10)
     self.__parsedDom = xml.dom.minidom.parseString(xmlString)
     dlg.update(53)
     __handle, lists = self.__getLists(dlg, self.sheetnames)
     if len(lists)==0:
         return __handle
     DButil = Utils(self.__md, self.sheetnames)
     __handle = DButil.writeToDB(lists)
     dlg.update(100)
     dlg.Destroy()
     return __handle
 def parse(self):
     dlg = DialogGauge(None,"Excel Parsing","reading document")
     Q1 = Q2 = QProduct = QFuel = Q3 = QRenewables = QSurf = QProfiles = QIntervals = Q9Questionnaire = []
     try:
         self.__xlApp, self.__xlWb = self.__openExcelDispatch(self.__filepath)
         __sheets = self.__xlWb.Sheets
         self.__sheetnames = []
         for i in xrange(0,__sheets.count):
             if __sheets[i].Name[0] == 'Q':
                 self.__sheetnames.append(__sheets[i].Name)
         self.__md = self.__connectToDB()
         
     except:
         self.__closeExcelDispatch(self.__xlWb, self.__xlApp)
         return Utils.parseError("Consistency")
     dlg.update(5)
     try:
         __handle, lists = self.__getExcelLists(self.__sheetnames, self.__xlWb,dlg)
     except:
         try:
             time.sleep(3)
             self.__xlApp, self.__xlWb = openExcelDispatch()
             __handle, lists = self.__getExcelLists(self.__sheetnames, self.__xlWb,dlg)
         except:
             try:
                 time.sleep(3)
                 self.__xlApp, self.__xlWb = openExcelDispatch()
                 __handle, lists = self.__getExcelLists(self.__sheetnames, self.__xlWb, dlg)
             except:
                 self.__closeExcelDispatch(self.__xlWb, self.__xlApp)
                 return Utils.parseError("Consistency")
             
     
     DButil = Utils(self.__md, self.__sheetnames)
     dlg.update(75)
     __handle = DButil.writeToDB(lists)
     dlg.update(100)
     dlg.Destroy()
     self.__closeExcelDispatch(self.__xlWb, self.__xlApp)
     return __handle
Example #6
0
def prepareDataForReport():
    # ------------------------------------------------------------------------------
    #   calls the functions necessary for writing the report
    # ------------------------------------------------------------------------------

    dlg = DialogGauge(Status.main, "Report generation", "preparing data")

    # Title page
    (projectData, generalData) = Status.prj.getProjectData()
    reportTitle = unicode(projectData.Name, "utf-8")
    if projectData.City is not None:
        reportTitle += u", " + unicode(projectData.City, "utf-8")
    if projectData.Country is not None:
        reportTitle += u", " + unicode(projectData.Country, "utf-8")
    Status.int.setGraphicsData("TITLE", array([[reportTitle]]))
    print "Control (prepareDataForReport): Title = %s" % (reportTitle.encode("utf-8"))
    print "Type: ", type(reportTitle)
    print Status.int.GData["TITLE"]

    Status.prj.setActiveAlternative(0)  # select present state

    Status.mod.moduleEA.update()

    dlg.update(10)

    # Cap. 2.1 - 2.3
    modEA1 = ModuleEA1(["EA1"])
    modEA1.initModule()

    modEA2 = ModuleEA2(["EA2"])
    modEA2.initPanel()

    modEA3 = ModuleEA3(["EA3_FET", "EA3_USH"])
    modEA3.initModule()

    dlg.update(15)

    modEA4 = ModuleEA4(["EA4a_Table", "EA4a_Plot"])
    modEA4.updatePanel()
    modEA4 = ModuleEA4(["EA4b_Table", "EA4b_Plot"])
    modEA4.updatePanel()
    modEA4 = ModuleEA4(["EA4c_Table", "EA4c_Plot"])
    modEA4.updatePanel()

    modEA5 = ModuleEA5(["EA5_EI", "EA5_SEC"])
    modEA5.initModule()

    dlg.update(20)

    # Cap. 2.4
    Status.mod.moduleBM.initPanel(["BM1"])

    dlg.update(30)

    products = Status.mod.moduleBM.products
    if len(products) > 0:
        Status.mod.moduleBM.product = products[0]
    Status.mod.moduleBM.initPanel(["BM2"])

    dlg.update(40)

    processes = Status.mod.moduleBM.processes
    if len(processes) > 0:
        Status.mod.moduleBM.process = processes[0]
    Status.mod.moduleBM.initPanel(["BM3"])

    dlg.update(50)

    # Cap. 3
    Status.mod.moduleA.updatePanel()

    for ANo in range(1, (Status.NoOfAlternatives + 1)):
        Status.prj.setActiveAlternative(ANo)

        Status.mod.moduleEA.update()  # calculate for update of CS plots

        Status.mod.moduleHR.initPanel()
        Status.mod.moduleHC.updatePanel()

        dlg.update(50 + 20.0 * ANo / Status.NoOfAlternatives)
    dlg.update(70)

    # Cap. 4
    modCS = ModuleCS(["CS1_Plot"])
    modCS.updatePanel()

    modCS = ModuleCS(["CS2_Plot"])
    modCS.updatePanel()

    modCS = ModuleCS(["CS3_Plot"])
    modCS.updatePanel()

    modCS = ModuleCS(["CS4_Plot"])
    modCS.updatePanel()

    modCS = ModuleCS(["CS5_Plot"])
    modCS.updatePanel()

    modCS = ModuleCS(["CS6_Plot"])
    modCS.updatePanel()

    modCS = ModuleCS(["CS7_Plot"])
    modCS.updatePanel()

    dlg.update(80)

    # Cap. 5 and 6

    if Status.FinalAlternative is not None:
        Status.prj.setActiveAlternative(Status.FinalAlternative)
    else:
        Status.prj.setActiveAlternative(0)

    Status.mod.moduleEA.update()

    # Chap. 5

    try:
        Status.mod.moduleTCA.runTCAModule()
    except:
        logTrack("prepareDataForReport: error in TCA module")

    # Chap. 6.1 - 6.3
    modEA1 = ModuleEA1(["EA1"])
    modEA1.initModule()

    modEA2 = ModuleEA2(["EA2"])
    modEA2.initPanel()

    modEA3 = ModuleEA3(["EA3_FET", "EA3_USH"])
    modEA3.initModule()

    modEA4 = ModuleEA4(["EA4a_Table", "EA4a_Plot"])
    modEA4.updatePanel()
    modEA4 = ModuleEA4(["EA4b_Table", "EA4b_Plot"])
    modEA4.updatePanel()
    modEA4 = ModuleEA4(["EA4c_Table", "EA4c_Plot"])
    modEA4.updatePanel()

    modEA5 = ModuleEA5(["EA5_EI", "EA5_SEC"])
    modEA5.initModule()

    dlg.update(90)

    # Cap. 6.4
    Status.mod.moduleBM.initPanel(["BM1"])

    dlg.update(93)

    products = Status.mod.moduleBM.products
    if len(products) > 0:
        Status.mod.moduleBM.product = products[0]
    Status.mod.moduleBM.initPanel(["BM2"])

    dlg.update(96)

    processes = Status.mod.moduleBM.processes
    if len(processes) > 0:
        Status.mod.moduleBM.process = processes[0]
    Status.mod.moduleBM.initPanel(["BM3"])

    dlg.update(99)

    # Summary

    modCS = ModuleCS(["Summary"])
    modCS.updatePanel()

    dlg.update(100)
    dlg.Destroy()