當前位置: 首頁>>代碼示例>>Python>>正文


Python WRCCUtils.find_id_and_name方法代碼示例

本文整理匯總了Python中WRCCUtils.find_id_and_name方法的典型用法代碼示例。如果您正苦於以下問題:Python WRCCUtils.find_id_and_name方法的具體用法?Python WRCCUtils.find_id_and_name怎麽用?Python WRCCUtils.find_id_and_name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在WRCCUtils的用法示例。


在下文中一共展示了WRCCUtils.find_id_and_name方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: set_min_max_dates

# 需要導入模塊: import WRCCUtils [as 別名]
# 或者: from WRCCUtils import find_id_and_name [as 別名]
def set_min_max_dates(initial):
    sd = '9999-99-99';ed = '9999-99-99'
    sd_fut = sd; ed_fut = ed
    if 'station_id' in initial.keys():
        stn_json = settings.MEDIA_DIR + '/json/US_station_id.json'
        stn_id, stn_name = WRCCUtils.find_id_and_name(initial['station_id'],stn_json)
        els = []
        if 'element' in initial.keys():
            els = [initial['element']]
            if initial['element'] in ['dtr','pet']:els = ['maxt','mint']
        if 'elements' in initial.keys():
            els = initial['elements']
            if 'dtr' in els and 'maxt' not in els:
                els.append('maxt')
            if 'dtr' in els and 'mint' not in els:
                els.append('mint')
            if 'dtr' in els and 'maxt' not in els:
                els.append('maxt')
            if 'dtr' in els and 'mint' not in els:
                els.append('mint')

        vd = WRCCUtils.find_valid_daterange(stn_id,el_list=els,max_or_min='min')
        if vd and len(vd) >=1:sd = vd[0]
        if vd and len(vd) >1:ed = vd[1]
        sd_fut =  sd;ed_fut = ed
    if 'location' in initial.keys() or initial['app_name'] == 'monthly_spatial_summary':
        sd = WRCCData.GRID_CHOICES[str(initial['grid'])][3][0][0]
        ed = WRCCData.GRID_CHOICES[str(initial['grid'])][3][0][1]
        sd_fut =  sd;ed_fut = ed
        if len(WRCCData.GRID_CHOICES[initial['grid']][3]) == 2:
            sd_fut = WRCCData.GRID_CHOICES[initial['grid']][3][1][0]
            ed_fut = WRCCData.GRID_CHOICES[initial['grid']][3][1][1]
    return sd, ed, sd_fut, ed_fut
開發者ID:,項目名稱:,代碼行數:35,代碼來源:

示例2: set_min_max_dates

# 需要導入模塊: import WRCCUtils [as 別名]
# 或者: from WRCCUtils import find_id_and_name [as 別名]
def set_min_max_dates(initial):
    sd = '9999-99-99';ed = '9999-99-99'
    sd_fut = sd; ed_fut = ed
    data_type = 'station'
    if 'location' in initial.keys():
        data_type = 'grid'
    if initial['app_name'] in ['monthly_spatial_summary', 'temporal_summary']:
        data_type = 'grid'
    if 'data_type' in initial.keys() and initial['data_type'] == 'grid':
        data_type = 'grid'
    if 'station_id' in initial.keys():
        stn_json = settings.MEDIA_DIR + '/json/US_station_id.json'
        stn_id, stn_name = WRCCUtils.find_id_and_name(initial['station_id'],stn_json)
        els = []
        if 'variable' in initial.keys():
            els = [initial['variable']]
        if 'variables' in initial.keys():
            els = initial['variables']
        vd, no_vd_els = WRCCUtils.find_valid_daterange(stn_id,el_list=els,max_or_min='min')
        sd = vd[0];ed = vd[1]
        #sd_fut =  sd;ed_fut = ed
    elif data_type == 'grid':
        sd = WRCCData.GRID_CHOICES[str(initial['grid'])][3][0][0]
        #ed = WRCCUtils.advance_date(sd,10*365,'forward')
        ed = WRCCData.GRID_CHOICES[str(initial['grid'])][3][0][1]
        #sd_fut =  sd;ed_fut = ed
        if len(WRCCData.GRID_CHOICES[initial['grid']][3]) == 2:
            sd_fut = WRCCData.GRID_CHOICES[initial['grid']][3][1][0]
            #ed_fut = WRCCUtils.advance_date(sd,10*365,'forward')
            ed_fut = WRCCData.GRID_CHOICES[initial['grid']][3][1][1]
    else:
        if 'data_type' in initial.keys() and initial['data_type'] == 'station':
            sd = '1850-01-01'
            ed = today
    return sd, ed, sd_fut, ed_fut
開發者ID:bdaudert,項目名稱:my-python-lib,代碼行數:37,代碼來源:DJANGOUtils.py

示例3: test_find_id_and_name

# 需要導入模塊: import WRCCUtils [as 別名]
# 或者: from WRCCUtils import find_id_and_name [as 別名]
 def test_find_id_and_name(self):
     for area_type, area_val in self.test_areas.iteritems():
         if area_type in ['station_id','basin','county','county_warning_area','climate_division']:
             json_file_path = '/www/apps/csc/dj-projects/my_acis/media/json/US_' + area_type + '.json'
             ID, name = WRCCUtils.find_id_and_name(area_val, json_file_path)
             try:
                 self.assertNotEqual('ID','')
             except AssertionError as err:
                 logger.error('AssertionError' + str(err))
開發者ID:bdaudert,項目名稱:my-python-lib,代碼行數:11,代碼來源:UnitTestSCENIC.py

示例4: test_find_area

# 需要導入模塊: import WRCCUtils [as 別名]
# 或者: from WRCCUtils import find_id_and_name [as 別名]
 def test_find_area(self):
     msg = 'Testing Area finder for Multi Lister'
     logger.info(msg)
     for area_type, area in self.area_dict.iteritems():
         if area_type in ['station_id','station_ids','shape','location','state']:
             continue
         msg = 'Area: ' + area_type
         logger.info(msg)
         station_json = '/www/apps/csc/dj-projects/my_acis/media/json/US_'+area_type+'.json'
         ID, name = WRCCUtils.find_id_and_name(area,station_json)
         try:
             self.assertIsInstance(name, str)
         except AssertionError as err:
             logger.error('AssertionError' + str(err))
         try:
             self.assertIsInstance(ID, str)
         except AssertionError as err:
             logger.error('AssertionError' + str(err))
         try:
             self.assertNotEqual(ID,'')
         except AssertionError as err:
             logger.error('AssertionError' + str(err))
開發者ID:bdaudert,項目名稱:my-python-lib,代碼行數:24,代碼來源:UnitTestSCENIC.py

示例5: set_initial

# 需要導入模塊: import WRCCUtils [as 別名]
# 或者: from WRCCUtils import find_id_and_name [as 別名]
def set_initial(request,app_name):
    '''
    Set html form
    Args:
        request: django request object
        app_name: application, one of
            single_lister, multi_lister, station_finder
            map_overlay,
            sf_download
            spatial_summary, temporal_summary
            monthly_summary, climatology
            data_comparison, liklihood,
            data_download
    Returns:
        two dictionaries
        initial: form input
    '''
    initial = {}
    initial['app_name'] = app_name
    Get = set_GET(request)
    Getlist = set_GET_list(request)
    #Set area type: station_id(s), location, basin,...
    area_type = None
    if app_name in ['single_lister','climatology','monthly_summary', 'seasonal_summary','intraannual']:
        initial['area_type'] = Get('area_type','station_id')
    elif app_name in ['data_comparison']:
        initial['area_type'] = 'location'
    else:
        initial['area_type'] = Get('area_type','state')
    #Set todays date parameters
    initial['today_year'] = today_year
    initial['today_month'] = today_month
    initial['today_day'] = today_day
    #Set area depending on area_type
    if app_name == 'data_comparison':
        location = Get('location',None)
        station_id = Get('station_id',None)
        if location is None and station_id is not None:
            #Link from station finder,
            #set location to station lon, lat if we are
            stn_id, stn_name = WRCCUtils.find_id_and_name(station_id,settings.MEDIA_DIR + '/json/US_station_id.json')
            meta = AcisWS.StnMeta({'sids':stn_id,'meta':'ll'})
            ll = None
            ll = str(meta['meta'][0]['ll'][0]) + ',' + str(meta['meta'][0]['ll'][1])
            initial['location'] = ll
        else:
            initial[str(initial['area_type'])] = Get(str(initial['area_type']), WRCCData.AREA_DEFAULTS[str(initial['area_type'])])
    else:
        initial[str(initial['area_type'])] = Get(str(initial['area_type']), WRCCData.AREA_DEFAULTS[str(initial['area_type'])])
    initial['area_type_label'] = WRCCData.DISPLAY_PARAMS[initial['area_type']]
    initial['area_type_value'] = initial[str(initial['area_type'])]

    #Set data type and map parameters
    if initial['area_type'] in ['station_id','station_ids']:
        initial['autofill_list'] = 'US_' + initial['area_type']
        initial['data_type'] = 'station'
    elif initial['area_type'] in ['location','locations']:
        initial['data_type'] = 'grid'
    elif initial['area_type'] in ['basin','county_warning_area','county','climate_division','state','shape']:
        initial['autofill_list'] = 'US_' + initial['area_type']
        initial['data_type'] = Get('data_type','station')
    if app_name in  ['temporal_summary','monthly_spatial_summary']:
        initial['data_type'] = 'grid'
    if app_name in ['station_finder','sf_download']:
        initial['data_type'] = 'station'
    #Grid
    if app_name not in ['station_finder', 'sf_download']:
        initial['grid'] = Get('grid','1')
    #Set up map parameters
    initial['overlay_state'] = Get('overlay_state','nv').lower()
    initial['host'] = settings.HOST
    #Create kml files for oerlay state
    for at in ['basin', 'county', 'county_warning_area', 'climate_division']:
        kml_file_path = create_kml_file(at, initial['overlay_state'])
        if initial['area_type'] == at:
            initial['kml_file_path'] = kml_file_path
    #If station_finder download, we need to set the station_ids
    #and override the original area type fields
    if app_name == 'sf_download':
        #delete old are type
        del initial[str(initial['area_type'])]
        #set new area params
        initial['station_ids'] = str(Get('station_ids_string',''))
        initial['station_ids_string'] = initial['station_ids']
        initial['area_type'] = 'station_ids'
        initial['area_type_label'] = 'Station IDs'
        initial['area_type_value'] = initial['station_ids']
        initial['station_json'] = Get('station_json','')

    #If station finder set hidden var station_ids_string for results
    if app_name == 'station_finder':
        initial['station_ids_string'] = str(Get('station_ids_string',''))
    #Set element(s)--> always as list if multiple
    if app_name == 'map_overlay':
        initial['elements'] = Get('elements','maxt,mint,pcpn').split(',')
        initial['elements_str'] = ','.join(initial['elements'])
    elif app_name in ['monthly_spatial_summary','monthly_summary','data_comparison', 'seasonal_summary','intraannual']:
            initial['element'] = Get('element',None)
            if initial['element'] is not None and len(initial['element'].split(',')) > 1:
                initial['element'] =  str(initial['element'].split(',')[0])
#.........這裏部分代碼省略.........
開發者ID:,項目名稱:,代碼行數:103,代碼來源:

示例6: set_form

# 需要導入模塊: import WRCCUtils [as 別名]
# 或者: from WRCCUtils import find_id_and_name [as 別名]

#.........這裏部分代碼省略.........
        del form['csrfmiddlewaretoken']
    if 'formData' in form.keys():
        del form['formData']
    if 'form_options' in form.keys():
        del form['form_options']

    if not clean:
        return form
    #Clean up form for submission
    #Clean Dates and windows
    vd = None
    for key in ['start_date', 'end_date', 'start_year', 'end_year','start_window','end_window']:
        if key not in form.keys():
            continue
        if form[key].lower() == 'por':
            if str(key) in ['start_date']:
                k=key; idx = 0;sd = 'por'; ed = form['end_date']
            if str(key) in ['end_date']:
                k=key; idx = 1;ed = 'por'; sd = form['start_date']
            if str(key) in ['start_year']:
                k='start_date'; idx = 0;sd = 'por'
                if form['end_year'].lower() == 'por':ed = 'por'
                else:ed = str(int(form['end_year']) -1) + '-12-31'
            if str(key) in ['end_year']:
                k='end_date'; idx = 1;ed = 'por'
                if form['start_year'].lower() == 'por':sd = 'por'
                else:sd = form['start_year'] + '-01-01'
            if 'element' in form.keys() and not 'elements' in form.keys():
                if form['element'] in ['dtr']:
                    el_list = ['maxt','mint']
                if form['element'] in ['pet']:
                    el_list = ['maxt','mint','pcpn']
            if 'elements' in form.keys() and not 'element' in form.keys():
                if isinstance(form['elements'],basestring):
                    el_list = form['elements'].replace(' ','').split(',')
                else:
                    el_list = form['elements']
            else:
                el_list = None

            if 'station_id' in form.keys():
                if vd is None:
                    stn_id, stn_name = WRCCUtils.find_id_and_name(str(form['station_id']),settings.MEDIA_DIR +'json/US_station_id.json')
                    vd = WRCCUtils.find_valid_daterange(stn_id, start_date=sd, end_date=ed, el_list=el_list, max_or_min='max')
                form[k] = vd[idx]
                if key == 'start_year' and form['start_year'].lower() == 'por':
                    form['start_year'] = vd[0][0:4]
                if key == 'end_year' and form['end_year'].lower() == 'por':
                    form['end_year'] = vd[1][0:4]
            else:
                form[str(key)] = str(form[key]).replace('-','').replace(':','').replace('/','').replace(' ','')
        else:
            form[str(key)] = str(form[key]).replace('-','').replace(':','').replace('/','').replace(' ','')

    #Convert user input of area names to ids
    for key in ['station_id','county', 'basin', 'county_warning_area', 'climate_division']:
        if not key in form.keys():
            continue
        ID,name = WRCCUtils.find_id_and_name(form[key],settings.MEDIA_DIR +'json/US_' + key + '.json')
        form[key] = ID
        form['user_area_id'] = str(name) + ', ' + str(ID)
    if not 'user_area_id' in form.keys():
        try:
            form['user_area_id'] = form[form['area_type']]
        except:
            try:
                form['user_area_id'] =  form[form['data_type']]
            except:
                pass
    #station_ids is special case
    if 'station_ids' in form.keys():
        stn_ids = ''
        stn_list = form['station_ids'].rstrip(',').split(',')
        #Remove leading spaces from list items
        stn_list = [v.lstrip(' ').rstrip(' ') for v in stn_list]
        stn_ids, stn_names = WRCCUtils.find_ids_and_names(stn_list,settings.MEDIA_DIR +'json/US_' + 'station_id' + '.json')
        form['station_ids'] = stn_ids
        uai = ''
        stn_names_list = stn_names.split(',')
        for idx, stn_id in enumerate(stn_ids.split(',')):
            uai+=str(stn_names[idx]) + ', ' + str(stn_id) + ';'
        form['user_area_id'] = uai
    #set data summary if needed
    if 'data_summary' not in form.keys():
        if 'temporal_summary' in form.keys():
            form['data_summary'] = 'temporal_summary'
        if 'spatial_summary' in form.keys():
            form['data_summary'] = 'spatial_summary'
    #Combine elements
    if 'add_degree_days' in form.keys() and form['add_degree_days'] == 'T':
        for dd in form['degree_days'].replace(' ','').split(','):
            '''
            if form['units'] == 'metric':
                el_strip, base_temp = WRCCUtils.get_el_and_base_temp(dd)
                form['elements'].append(el_strip + str(WRCCUtils.convert_to_english('base_temp',base_temp)))
            else:
                form['elements'].append(dd)
            '''
            form['elements'].append(dd)
    return form
開發者ID:,項目名稱:,代碼行數:104,代碼來源:


注:本文中的WRCCUtils.find_id_and_name方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。