Changeset 2315 for TI07-MOLES


Ignore:
Timestamp:
23/03/07 12:42:12 (12 years ago)
Author:
lawrence
Message:

Improved parameter handling, and better test cases.

Location:
TI07-MOLES/trunk/PythonCode/wsgi
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • TI07-MOLES/trunk/PythonCode/wsgi/DIF.py

    r2295 r2315  
    7373        self.parameters=[] 
    7474        for parameter in helper.findall(self.tree,'Parameters'): 
    75             name=parameter.text 
    76             if name is not None:  
    77                 #self.parameters.append(name.replace('>','/')) 
    78                 while len(name.split('>'))<5:name+='>' 
    79                 self.parameters.append(name) 
    80             else: 
    81                 name='' 
    82                 for level in ['Category','Topic','Term','Variable','Detailed_Variable']: 
     75            name='' 
     76            for level in ['Category','Topic','Term','Variable','Detailed_Variable']: 
    8377                    name+=helper.getText(parameter,level)+'>' 
    84                 self.parameters.append(name.rstrip('>')) 
     78            name=name.rstrip('>') 
     79            #print '[%s]\n%s'%(name,ET.tostring(parameter)) 
     80            if name=='': 
     81                name=parameter.text 
     82                if name is not None:  
     83                    #self.parameters.append(name.replace('>','/')) 
     84                    while len(name.split('>'))<5:name+='>' 
     85            self.parameters.append(name) 
     86             
    8587 
    8688        #load up information about spatial bounding box  
     
    155157    inputFile = 'examples/neodc.eg1.dif' 
    156158    inputFile2= 'examples/bodc.eg2.edmed.dif' 
     159    inputFile2= 'examples/bodc.eg3.difChange.dif' 
    157160    configFile='examples/example.config' 
    158161     
  • TI07-MOLES/trunk/PythonCode/wsgi/ndgRetrieve.py

    r2274 r2315  
    150150         
    151151        if outputType!='xml':  
    152             try: 
    153                 r=self.shower.get(r,format,otype=outputType,ndgObject=self.uri) 
     152            #r=self.shower.get(r,format,otype=outputType,ndgObject=self.uri) 
     153            try: 
     154                r=self.shower.get(r,format,otype=outputType,ndgObject=self.uri) 
    154155            except Exception,e: 
    155                 r='<p> Unable to show document, reason was [%s]<p>'%e 
     156                r='<p> Unable to show document, reason was [%s]<p>'%e 
    156157        else: 
    157158            ctype='text/xml' 
     
    178179     
    179180import unittest 
    180 testURI='noc.soton.ac.uk__DIF__NOCSDAT193' 
     181#testURI='noc.soton.ac.uk__DIF__NOCSDAT193' 
     182#testURI='ndg.noc.soton.ac.uk__NDG-B0__NOCSDAT274' 
     183testURI='grid.bodc.nerc.ac.uk__DIF__EDMED1048034.xml' 
    181184retriever=ndgRetrieve('./') 
    182185class TestCase(unittest.TestCase): 
     
    209212         
    210213         
     214         
    211215if __name__=="__main__": 
    212216    unittest.main() 
  • TI07-MOLES/trunk/PythonCode/wsgi/ndgSearch.py

    r2260 r2315  
    110110            result=searchResult.Documents.Document[0] 
    111111        else: 
    112             result=searchResult._statusMessage 
     112            raise ValueError('Error retrieving [%s] was [%s]'%(document,searchResult._statusMessage)) 
     113            #result=searchResult._statusMessage 
    113114        return result 
    114115                    
     
    182183        j=len(responses) 
    183184        if i!=j: 
     185            print filenames 
    184186            raise ValueError,'Internal inconsistency in search return [hits:%s!=responses:%s]'%(i,j) 
    185187        indices=range(i) 
     
    224226        ''' Test obtaining a specific document which had better exist ''' 
    225227        doc='noc.soton.ac.uk__DIF__NOCSDAT100.xml' 
     228        #doc='ndg.noc.soton.ac.uk__DIF__NOCSDAT274.xml' 
    226229        s=ndgSearch() 
    227230        r=s.getDoc(doc) 
  • TI07-MOLES/trunk/PythonCode/wsgi/renderEntity.py

    r2295 r2315  
    177177        #and use the vocabulary server 
    178178        print title,len(keywords[0].split('>')) 
    179         if (title=='Parameter' and len(keywords[0].split('>'))==5): 
     179        if (title=='Parameter'):# and len(keywords[0].split('>'))==5): 
    180180            html+=renderParameters(keywords) 
    181         else: 
    182             html+=keywords[0] 
    183             for item in keywords[1:]: 
    184                 i=item.replace(' ','&nbsp;') 
    185                 html+=',&nbsp;&nbsp; %s'%i 
     181        #else: 
     182        #    html+=keywords[0] 
     183        #    for item in keywords[1:]: 
     184        #        i=item.replace(' ','&nbsp;') 
     185        #        html+=',&nbsp;&nbsp; %s'%i 
    186186        html+='</td></tr>' 
    187187    return html 
  • TI07-MOLES/trunk/PythonCode/wsgi/renderParameters.py

    r2295 r2315  
    33    to the BODC vocabulary service ''' 
    44    #well the vocab bit is still to do :-) 
    5     k=collapse(keywords) 
    6     return htmlList(k) 
     5    k=collapse2(keywords) 
     6    return htmlCollapse2(k) 
    77 
    88def htmlList(keywords): 
     
    2424                line=[] 
    2525    return result 
     26                 
     27def collapse2(keywords): 
     28    ''' Take the last element of a DIF parameter tree entry, and put them in a dictionary 
     29    under the DIF category ''' 
     30    d={} 
     31    for item in keywords: 
     32        line=item.split('>') 
     33        category=line[0] 
     34        if category not in d: d[category]=[] 
     35        while line<>[]: 
     36            c=line.pop() 
     37            if c<>'':  
     38                if c<>category: 
     39                    d[category].append(c) 
     40                line=[] 
     41    return d 
     42def htmlCollapse2(d): 
     43    ''' format the collapse2 responses ''' 
     44    html='<table>' 
     45    def r(x): 
     46        return '<tr><td>%s</td></tr>'%x 
     47    for item in d: 
     48        html+=r(item) 
     49        html+=r(htmlList(d[item])) 
     50    html+='</table>' 
     51    return html 
     52 
     53 
    2654 
    2755def reorder(keywords): 
     
    6492import unittest 
    6593 
    66 dummy=['EARTH SCIENCE / Oceans / Ocean Temperature  / Water Temperature  / Temperature of the water column', 'EARTH SCIENCE / Oceans / Salinity/Density  / Salinity  / Salinity of the water column', 'EARTH SCIENCE / Oceans / Ocean Chemistry  / Pigments  / Chlorophyll pigment concentrations in the water column', 'EARTH SCIENCE / Oceans / Ocean Chemistry  / Carbon Dioxide  / Partial pressure (pCO2) and fugacity (fCO2) of carbon dioxide in the water column', 'EARTH SCIENCE / Oceans / Ocean Chemistry  / Inorganic Carbon  / Total dissolved inorganic carbon (TCO2) concentration in the water column', 'EARTH SCIENCE / Oceans / Ocean Chemistry  / Alkalinity  / Alkalinity, acidity and pH of the water column', 'EARTH SCIENCE / Oceans / Ocean Chemistry  / Oxygen  / Dissolved oxygen parameters in the water column', "EARTH SCIENCE / Oceans / Ocean Chemistry  / 'Other'/ halocarbon concentrations in the water column", "EARTH SCIENCE / Oceans / Ocean Chemistry  / Concentration of 'other' / hydrocarbons in the water column", 'EARTH SCIENCE / Oceans / Marine Biology  / Marine Invertebrates  / Acoustic backscatter in the water column', 'EARTH SCIENCE / Biosphere / Ecological Dynamics  / Primary Production  / Primary production in the water column', 'EARTH SCIENCE / Oceans / Ocean Chemistry  / Ammonia  / Regenerated production in the water column', 'EARTH SCIENCE / Oceans / Ocean Optics  / Attenuation/Transmission  / Transmittance and attenuance of the water column', 'EARTH SCIENCE / Oceans / Bathymetry/Seafloor Topography  / Water Depth  / Bathymetry and Elevation', 'EARTH SCIENCE / Oceans / Ocean Optics  / Photosynthetically Active Radiation  / Visible waveband radiance and irradiance measurements in the water column', 'EARTH SCIENCE / Atmosphere / Atmospheric Radiation  / Solar Radiation  / Solar Radiation', 'EARTH SCIENCE / Atmosphere / Atmospheric Temperature  / Air Temperature  / Air temperature', 'EARTH SCIENCE / Atmosphere / Atmospheric Pressure  / Surface Pressure  / Air pressure', 'EARTH SCIENCE / Oceans / Ocean Chemistry  / Organic Carbon  / Particulate total and organic carbon concentrations in the water column', 'EARTH SCIENCE / Oceans / Ocean Chemistry  / Organic Matter  / Particulate total and organic nitrogen concentrations in the water column', "EARTH SCIENCE / Oceans / Ocean Chemistry  / Nutrients  / Uptake of 'other' nutrients in the water column", 'EARTH SCIENCE / Oceans / Marine Biology  / Marine Plants  / Phytoplankton taxonomy-related abundance per unit volume of the water column', 'EARTH SCIENCE / Biosphere / Ecological Dynamics  / Herbivory  / Zooplankton feeding'] 
     94dummy=['EARTH SCIENCE > Oceans > Ocean Temperature  > Water Temperature  > Temperature of the water column', 'EARTH SCIENCE > Oceans > Salinity>Density  > Salinity  > Salinity of the water column', 'EARTH SCIENCE > Oceans > Ocean Chemistry  > Pigments  > Chlorophyll pigment concentrations in the water column', 'EARTH SCIENCE > Oceans > Ocean Chemistry  > Carbon Dioxide  > Partial pressure (pCO2) and fugacity (fCO2) of carbon dioxide in the water column', 'EARTH SCIENCE > Oceans > Ocean Chemistry  > Inorganic Carbon  > Total dissolved inorganic carbon (TCO2) concentration in the water column', 'EARTH SCIENCE > Oceans > Ocean Chemistry  > Alkalinity  > Alkalinity, acidity and pH of the water column', 'EARTH SCIENCE > Oceans > Ocean Chemistry  > Oxygen  > Dissolved oxygen parameters in the water column', "EARTH SCIENCE > Oceans > Ocean Chemistry  > 'Other'> halocarbon concentrations in the water column", "EARTH SCIENCE > Oceans > Ocean Chemistry  > Concentration of 'other' > hydrocarbons in the water column", 'EARTH SCIENCE > Oceans > Marine Biology  > Marine Invertebrates  > Acoustic backscatter in the water column', 'EARTH SCIENCE > Biosphere > Ecological Dynamics  > Primary Production  > Primary production in the water column', 'EARTH SCIENCE > Oceans > Ocean Chemistry  > Ammonia  > Regenerated production in the water column', 'EARTH SCIENCE > Oceans > Ocean Optics  > Attenuation>Transmission  > Transmittance and attenuance of the water column', 'EARTH SCIENCE > Oceans > Bathymetry>Seafloor Topography  > Water Depth  > Bathymetry and Elevation', 'EARTH SCIENCE > Oceans > Ocean Optics  > Photosynthetically Active Radiation  > Visible waveband radiance and irradiance measurements in the water column', 'EARTH SCIENCE > Atmosphere > Atmospheric Radiation  > Solar Radiation  > Solar Radiation', 'EARTH SCIENCE > Atmosphere > Atmospheric Temperature  > Air Temperature  > Air temperature', 'EARTH SCIENCE > Atmosphere > Atmospheric Pressure  > Surface Pressure  > Air pressure', 'EARTH SCIENCE > Oceans > Ocean Chemistry  > Organic Carbon  > Particulate total and organic carbon concentrations in the water column', 'EARTH SCIENCE > Oceans > Ocean Chemistry  > Organic Matter  > Particulate total and organic nitrogen concentrations in the water column', "EARTH SCIENCE > Oceans > Ocean Chemistry  > Nutrients  > Uptake of 'other' nutrients in the water column", 'EARTH SCIENCE > Oceans > Marine Biology  > Marine Plants  > Phytoplankton taxonomy-related abundance per unit volume of the water column', 'EARTH SCIENCE > Biosphere > Ecological Dynamics  > Herbivory  > Zooplankton feeding'] 
    6795 
    6896class TestCase(unittest.TestCase): 
     
    76104        ''' test the renderParameters routine which is the only one that really matters ''' 
    77105        o=renderParameters(dummy) 
     106        print o 
    78107         
    79108 
  • TI07-MOLES/trunk/PythonCode/wsgi/xmlHandler.py

    r1925 r2315  
    1313        except ImportError: 
    1414            from leonardo.thirdParty import ElementTree as ET 
    15  
     15from xml.parsers.expat import ExpatError 
    1616import StringIO 
    1717 
     
    6666        start=1 
    6767         
    68         for event,elem in ET.iterparse(f,events=('start','end','start-ns')): 
    69             if start and event=='start': 
    70                 self.__parse(event,elem,self.__extra()) 
    71                 start=0 
    72             else:  
    73                 self.__parse(event,elem) 
     68        try: 
     69            for event,elem in ET.iterparse(f,events=('start','end','start-ns')): 
     70                if start and event=='start': 
     71                    self.__parse(event,elem,self.__extra()) 
     72                    start=0 
     73                else:  
     74                    self.__parse(event,elem) 
     75        except ExpatError,e: 
     76            #.seek(0) 
     77            #rint 'Failed to parse:\n%s\n!!!!'%f.read() 
     78            raise ValueError('XML Parsing error in xmlHandler:%s'%e) 
    7479        self.tree=elem 
    7580        self.tree.nsMap=self.nsMap 
     
    177182    """ 
    178183 
    179     inputFile = 'instance0.xml' 
     184    inputFile = 'examples/neodc.eg1.dif' 
    180185     
    181186    def setUp(self): 
Note: See TracChangeset for help on using the changeset viewer.