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


Python WRCCUtils.find_ids_and_names方法代碼示例

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


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

示例1: test_find_ids_and_names

# 需要導入模塊: import WRCCUtils [as 別名]
# 或者: from WRCCUtils import find_ids_and_names [as 別名]
 def test_find_ids_and_names(self):
     area_type = 'station_ids'
     area_val = self.test_areas[area_type]
     json_file_path = '/www/apps/csc/dj-projects/my_acis/media/json/US_station_id.json'
     IDs, names = WRCCUtils.find_ids_and_names(area_val, json_file_path)
     try:
         self.assertIsInstance(IDs, str)
     except AssertionError as err:
         logger.error('AssertionError' + str(err))
     try:
         self.assertNotEqual(IDs.split(','),[])
     except AssertionError as err:
         logger.error('AssertionError' + str(err))
開發者ID:bdaudert,項目名稱:my-python-lib,代碼行數:15,代碼來源:UnitTestSCENIC.py

示例2: set_form

# 需要導入模塊: import WRCCUtils [as 別名]
# 或者: from WRCCUtils import find_ids_and_names [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_ids_and_names方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。