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

Improved parameter handling, and better test cases.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 
Note: See TracChangeset for help on using the changeset viewer.