本文整理汇总了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))
示例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