Esempio n. 1
0
def process_help(request, path):
    try:
        smry_type = None
        pest = None
        tech_choice = 'conventional'
        #	 	retrieve input
        newForm = {}
        for k, v in request.form.items():
            newForm[str(k)] = str(v)
        request.form = newForm
        if path is None:
            if request and request.form:
                #				print 'update form:',request.form
                try:
                    smry_type = request.form['type'].strip()
                    if request.form.has_key('pest'):
                        pest = request.form['pest']
                    if request.form.has_key('tech_choice'):
                        tech_choice = request.form['tech_choice']
                except:
                    print_exception()
                    raise program_exit('Error processing help form')
            else:
                return newaCommon_io.errmsg(
                    'Error processing help form; check input')
        elif path[0] in ['crucifer_disease']:
            try:
                smry_type = path[0]
                pest = path[1]
            except IndexError:
                raise program_exit('Error processing help form - index error')
            except:
                print_exception()
                raise program_exit('Error processing help form')
        else:
            try:
                smry_type = path[0]
                pest = path[0]
            except IndexError:
                raise program_exit('Error processing help form - index error')
            except:
                print_exception()
                raise program_exit('Error processing help form')

# 		send input to appropriate routine
        if pest:
            return Crucifer().run_crucifer_help(pest, tech_choice)
        else:
            return newaCommon_io.errmsg('Error processing help input')
    except program_exit, msg:
        print msg
        return newaCommon_io.errmsg('Error processing help input')
Esempio n. 2
0
def run_stationList(list_options='all'):
	try:
		from newaCommon.stn_info import stn_info
		station_dict = {}
		station_dict['stations'] = []
		unsortedDict = {}
		for stn in stn_info.keys():
			if (list_options == 'lwrh' and 'lwet' in stn_info[stn]['vars'] and 'rhum' in stn_info[stn]['vars']) \
				or (list_options == 'eslw' and ('lwet' in stn_info[stn]['vars'] or 'rhum' in stn_info[stn]['vars'])) \
				or list_options == 'all' or list_options in stn_info[stn]['vars']\
				or (list_options == 'goodsr' and stn_info[stn].has_key('srqual') and stn_info[stn]['srqual'] == 'ok')\
				or (list_options == 'srad' and stn_info[stn]['network'] == 'icao'):
				sdict = {}
				sdict['id'] = stn
				for item in ['lat','lon','elev','name','network','state']:
					sdict[item] = stn_info[stn][item]
				unsortedDict[stn_info[stn]['name']] = sdict
		
		unsortedKeys = unsortedDict.keys()
		unsortedKeys.sort()
		for state in ['NY','VT','MA','NH','CT','RI','NJ','PA','DE','MD','ME','DC','WI','IA','NE','MN','NC','IL','SD','MO','VA','SC','WV','AL','ID','UT','GA']:
			for usk in unsortedKeys:
				if state == unsortedDict[usk]['state']:
					station_dict['stations'].append(unsortedDict[usk])
					json_return = json.dumps(station_dict)
		return json_return
	except:
		return newaCommon_io.errmsg('Error processing request')
Esempio n. 3
0
def run_stateInactiveStationList(options):
	try:
		reqvar = options['reqvar']
		state = options['state']
		if state == '':
			state = 'ALL'
		station_dict = {}
		station_dict['stations'] = []
		unsortedDict = {}
		try:
			# only line that's different from stateStationList
			exec("from newaCommon.stn_info_" + state.lower() + "_inactive import stn_info")
		except:
			pass
		for stn in stn_info.keys():
			if (reqvar == 'lwrh' and 'lwet' in stn_info[stn]['vars'] and 'rhum' in stn_info[stn]['vars']) \
				or (reqvar == 'eslw' and ('lwet' in stn_info[stn]['vars'] or 'rhum' in stn_info[stn]['vars'])) \
				or reqvar == 'all' or reqvar in stn_info[stn]['vars']\
				or (reqvar == 'goodsr' and stn_info[stn].has_key('srqual') and stn_info[stn]['srqual'] == 'ok')\
				or (reqvar == 'srad' and stn_info[stn]['network'] == 'icao'):
				sdict = {}
				sdict['id'] = stn
				for item in ['lat','lon','elev','name','network','state']:
					sdict[item] = stn_info[stn][item]
				unsortedDict[stn_info[stn]['name']] = sdict
		
		sortedKeys = unsortedDict.keys()
		sortedKeys.sort()
		#return alphabetized list
		for usk in sortedKeys:
			station_dict['stations'].append(unsortedDict[usk])
		json_return = json.dumps(station_dict)
		return json_return
	except:
		return newaCommon_io.errmsg('Error processing request')
Esempio n. 4
0
def run_ddrange(stn, ddtype, accstr, accend):
    try:
        base = newaCommon.Base()
        cabbage = newaDisease.Cabbage()
        smry_dict = {'ddtype': ddtype.replace("dd", "")}
        now = DateTime.now()
        if not accend:
            accend = now
        end_date_dt = accend
        if not accstr:
            accstr = DateTime.DateTime(end_date_dt.year, 1, 1, 0)
        start_date_dt = accstr

        if start_date_dt > end_date_dt:
            return newaCommon_io.errmsg('Start date must be before end data.')

        if end_date_dt.year != now.year:
            smry_dict['this_year'] = False
            end_date_dt = end_date_dt + DateTime.RelativeDate(days=+6)
        else:
            smry_dict['this_year'] = True

        hourly_data, daily_data, download_time, station_name, avail_vars = base.get_hddata2(
            stn, start_date_dt, end_date_dt)
        smry_dict['last_time'] = download_time

        # add forecast data
        if smry_dict['this_year']:
            start_fcst_dt = DateTime.DateTime(
                *download_time) + DateTime.RelativeDate(hours=+1)
            end_fcst_dt = end_date_dt + DateTime.RelativeDate(days=+6)
            hourly_data = newaDisease.add_hrly_fcst(stn, hourly_data,
                                                    start_fcst_dt, end_fcst_dt)
            daily_data = newaDisease.hrly_to_dly(hourly_data)
        else:
            start_fcst_dt = end_date_dt + DateTime.RelativeDate(hours=+1)
            end_fcst_dt = end_date_dt
            end_date_dt = end_date_dt + DateTime.RelativeDate(days=-6)

        if len(daily_data) > 0:
            degday_dict = base.degday_calcs(daily_data, start_date_dt,
                                            end_fcst_dt, ddtype, "accum")

            if len(degday_dict) > 0:
                # get dates for gdd table
                smry_dict = cabbage.setup_dates(smry_dict, end_date_dt)
                # get dd for days of interest (including forecast)
                smry_dict = cabbage.add_ddays(smry_dict, degday_dict,
                                              start_date_dt, end_date_dt)
                return newaLister_io.ddrange_html(station_name, smry_dict,
                                                  degday_dict)
            else:
                return self.nodata(stn, station_name, start_date_dt,
                                   end_date_dt)
        else:
            return self.nodata(stn, station_name, start_date_dt, end_date_dt)
    except:
        print_exception()
    return
Esempio n. 5
0
def process_help (request, path):
	try:
		smry_type = None
#	 	retrieve input
		newForm = {}
		for k,v in request.form.items() :
			newForm[str(k)] = str(v)
		request.form = newForm
		if path is None:
			if request and request.form:
				try:
					smry_type = request.form['type'].strip()
				except:
					print_exception()
					raise program_exit('Error processing request')
			else:
				return newaCommon_io.errmsg('Error processing form; check input')
		elif path[0] in ['apple_et', 'apple_thin']:
			try:
				smry_type = path[0]
			except IndexError:
				raise program_exit('Error processing request - index error')
			except:
				print_exception()
				raise program_exit('Error processing request')
		else:
			return newaCommon_io.errmsg('Error processing input')

# 		send input to appropriate routine
		if smry_type == 'apple_et':
			return newaTools_io.helppage([("Model overview","/apple_et_help.html"),
										  ("Station inclusion","/apple_tool_stations.html")])
		elif smry_type == 'apple_thin':
			return newaTools_io.helppage([("Model overview","/apple_thin_help.html"),
										  ("Station inclusion","/apple_tool_stations.html")])
		else:
			return newaCommon_io.errmsg('Error processing input')
	except program_exit,msg:
		print msg
		return newaCommon_io.errmsg('Error processing input')
Esempio n. 6
0
def getForecastUrl(stn):
	forecastUrl = ""
	try:
		from newaCommon.stn_info import stn_info
		if not stn_info.has_key(stn):
			from newaCommon.stn_info_ma import stn_info
		lat = stn_info[stn]['lat']
		lon = stn_info[stn]['lon']
		forecastUrl = 'http://forecast.weather.gov/MapClick.php?textField1=%s&textField2=%s' % (lat,lon)
		return forecastUrl
	except:
		return newaCommon_io.errmsg('Error processing request')
	return forecastUrl
Esempio n. 7
0
def process_update(request, path):
    try:
        pest = None
        altref = None
        tech_choice = 'conventional'
        #	 	retrieve input
        newForm = {}
        for k, v in request.form.items():
            newForm[str(k)] = str(v)
        request.form = newForm
        if path is None:
            if request and request.form:
                try:
                    if request.form.has_key('pest'):
                        pest = request.form['pest']
                    if request.form.has_key('altref'):
                        altref = request.form['altref']
                    if request.form.has_key('tech_choice'):
                        tech_choice = request.form['tech_choice']
                except:
                    print_exception()
                    raise program_exit('Error processing request')
            else:
                return newaCommon_io.errmsg(
                    'Error processing form; check input')
        else:
            return newaCommon_io.errmsg('Error processing input')

# 		send input to appropriate routine
        if pest and altref:
            return Crucifer().run_crucifer_update(pest, altref, tech_choice)
        else:
            return newaCommon_io.errmsg('Error processing input')
    except program_exit, msg:
        print msg
        return newaCommon_io.errmsg('Error processing input')
Esempio n. 8
0
def run_stationSisterInfo(options):
	from newaCommon.sister_info import sister_info
	try:
		stn = options['station']
		network = options['network']
		sister_dict = {}
		if network == 'miwx' and stn[0:3] != 'ew_':
			stn = "ew_%s" % stn
		elif network == 'nysm' and stn[0:5] != 'nysm_':
			stn = "nysm_%s" % stn
		if sister_info.has_key(stn):
			sister = sister_info[stn]
			for var in sister.keys():
				if sister[var][0:3] == '42.' or sister[var][0:3] == '43.':
					station_id = sister[var]
					station_type  = 'ucc'
				elif sister[var][0:1] >= '1' and sister[var][0:1] <= '9' and sister[var][1:2] >= '0' and sister[var][1:2] <= '9':
					station_id = sister[var]
					station_type = 'njwx'
				elif len(sister[var]) == 4 and sister[var][0:1].upper() == 'K':
					station_id = sister[var]
					station_type = "icao"
				elif len(sister[var]) == 4:
					station_id = sister[var]
					station_type = "oardc"
				elif sister[var][0:3] == "cu_" or sister[var][0:3] == "um_" or sister[var][0:3] == "uc_" or sister[var][0:3] == "un_":
					station_id = sister[var]
					station_type = "culog"
				elif sister[var][0:3] == "ew_":
					station_id = sister[var][3:]
					station_type = 'miwx'
				elif sister[var][0:5] == "nysm_":
					station_id = sister[var][5:]
					station_type = 'nysm'
				elif len(sister[var]) == 7 and sister[var][2:3] == "_":
					station_id = sister[var]
					station_type = 'nwon'
				else:
					station_id = sister[var]
					station_type = "newa"
				sister_dict[var] = "%s %s" % (station_id, station_type)
		json_return = json.dumps(sister_dict)
		return json_return
	except:
		return newaCommon_io.errmsg('Error processing request')
Esempio n. 9
0
 def run_crucifer_help(self, pest, tech_choice):
     try:
         pest_status_management = import_info_dict(pest)
         if pest_status_management:
             key_char = pest_status_management['keychar_oc']
             if tech_choice == 'organic':
                 key_char += pest_status_management['keychar_o']
             else:
                 key_char += pest_status_management['keychar_c']
             help_links = [(key_char, "")]
             for htup in pest_status_management['help_links']:
                 help_links.append(htup)
             return newaVegModel_io.helppage(help_links)
         else:
             return newaCommon_io.errmsg(
                 'Help is not available for the disease you selected.')
     except:
         print_exception()
Esempio n. 10
0
 def run_crucifer_update(self, pest, altref, tech_choice):
     try:
         smry_dict = {}
         # determine information needed for calculations for particular disease
         pest_status_management = import_info_dict(pest)
         if not pest_status_management:
             return newaCommon_io.errmsg(
                 'A model is not available for the disease you selected.')
         if pest_status_management['messages'].has_key(altref):
             psmk = pest_status_management['messages'][altref]
             smry_dict['crop_stages'] = pest_status_management[
                 'messages'].keys()
             smry_dict = self.filldict(psmk, altref, tech_choice, smry_dict)
         else:
             smry_dict['stage'] = "Not defined"
             smry_dict['status'] = "Not defined"
             smry_dict['manage'] = "Not defined"
         return newaVegModel_io.crucifer_sm_table(smry_dict)
     except:
         print_exception()
Esempio n. 11
0
def process_gridSoilTemps(request):
	try:
#	 	retrieve input
		if request and request.form:
			try:
				if request.form.has_key('ll'):
					ll = request.form['ll'].strip()
				if request.form.has_key('sdate'):
					sdate = request.form['sdate'].strip()
				if request.form.has_key('edate'):
					edate = request.form['edate'].strip()
				if request.form.has_key('cover'):
					cover = request.form['cover'].strip()
				else:
					cover = 'bare'
				return run_gridSoilTemps(ll,cover,sdate,edate)
			except:
				raise program_exit('Error processing gridSoilTemps form')
		else:
			return program_exit('Error processing gridSoilTemps; check input')			
	except program_exit,msg:
		print msg
		return newaCommon_io.errmsg('Error processing gridSoilTemps request')
Esempio n. 12
0
def process_input(request, path):
    try:
        stn = None
        year = None
        greentip = None
        firstblossom = None
        orchard_history = None
        accend = None
        output = "tab"
        #	 	retrieve input
        if path is None:
            newForm = {}
            for k, v in request.form.items():
                newForm[str(k)] = str(v)
            request.form = newForm
            if request and request.form:
                try:
                    smry_type = request.form['type'].strip()
                    if request.form.has_key('stn'):
                        stn = request.form['stn'].strip()
                    if request.form.has_key('orchard_history'):
                        orchard_history = int(request.form['orchard_history'])
                    if request.form.has_key('year'):
                        year = int(request.form['year'])
                    if request.form.has_key('output'):
                        output = request.form['output']
                    if request.form.has_key('greentip'):
                        try:
                            mm, dd, yy = request.form['greentip'].replace(
                                "-", "/").split("/")
                            greentip = DateTime.DateTime(
                                int(yy), int(mm), int(dd), 23)
                        except:
                            greentip = None
                    if request.form.has_key('firstblossom'):
                        try:
                            mm, dd, yy = request.form['firstblossom'].replace(
                                "-", "/").split("/")
                            firstblossom = DateTime.DateTime(
                                int(yy), int(mm), int(dd), 23)
                        except:
                            firstblossom = None
                    if request.form.has_key('accend'):
                        try:
                            mm, dd, yy = request.form['accend'].replace(
                                "-", "/").split("/")
                            accend = DateTime.DateTime(int(yy), int(mm),
                                                       int(dd), 23)
                        except:
                            accend = None
                except:
                    print_exception()
                    raise program_exit('Error processing request')
            else:
                return newaCommon_io.errmsg(
                    'Error processing form; check input')
        elif path[0] in ['apple_scab_grf', 'fire_blight_grf']:
            try:
                smry_type = path[0]
                stn = path[1]
                if len(path) > 2: year = int(path[2])
                output = "standalone"
            except IndexError:
                raise program_exit('Error processing request - index error')
            except:
                print_exception()
                raise program_exit('Error processing request')
        else:
            return newaCommon_io.errmsg('Error processing input')

        if not accend:
            now = DateTime.now()
            if year and year != 9999 and year != now.year:
                accend = DateTime.DateTime(year, 6, 15, 23)

# 		send input to appropriate routine
        if stn:
            if smry_type == 'apple_scab_grf':
                return run_apple_scab_plots(stn, accend, greentip, output)
            elif smry_type == 'fire_blight_grf':
                return run_fire_blight_plots(stn, accend, firstblossom,
                                             orchard_history, output)
            else:
                return newaCommon_io.errmsg(
                    'Error processing form; check input')
        else:
            return newaCommon_io.errmsg(
                'Error processing form; select station')
    except program_exit, msg:
        print msg
        return newaCommon_io.errmsg('Error processing form; check input')
Esempio n. 13
0
                return newaCommon_io.errmsg(
                    'Error processing form; check input')
        else:
            return newaCommon_io.errmsg('Error processing input')

# 		send input to appropriate routine
        if pest and altref:
            return Crucifer().run_crucifer_update(pest, altref, tech_choice)
        else:
            return newaCommon_io.errmsg('Error processing input')
    except program_exit, msg:
        print msg
        return newaCommon_io.errmsg('Error processing input')
    except:
        print_exception()
        return newaCommon_io.errmsg('Unexpected error')


#--------------------------------------------------------------------------------------------
def process_help(request, path):
    try:
        smry_type = None
        pest = None
        tech_choice = 'conventional'
        #	 	retrieve input
        newForm = {}
        for k, v in request.form.items():
            newForm[str(k)] = str(v)
        request.form = newForm
        if path is None:
            if request and request.form:
Esempio n. 14
0
def process_input (request,path):
	try:
		stn = None
		accend = None
		greentip = None
		bloom = None
		percentflowerspurs = None
		output = "tab"
#	 	retrieve input
		newForm = {}
		for k,v in request.form.items() :
			newForm[str(k)] = str(v)
		request.form = newForm
		if path is None:
			if request and request.form:
				try:
					smry_type = request.form['type'].strip()
					if request.form.has_key('stn'):             stn = request.form['stn'].strip()
					if request.form.has_key('output'):          output = request.form['output']
					if request.form.has_key('percentflowerspurs'):  percentflowerspurs = request.form['percentflowerspurs']
					if request.form.has_key('greentip'):
						try:
							mm,dd,yy = request.form['greentip'].replace("-","/").split("/")
							greentip = DateTime.DateTime(int(yy),int(mm),int(dd),23)
						except:
							greentip = None
					if request.form.has_key('bloom'):
						try:
							mm,dd,yy = request.form['bloom'].replace("-","/").split("/")
							bloom = DateTime.DateTime(int(yy),int(mm),int(dd),23)
						except:
							bloom = None
					if request.form.has_key('accend'):
						try:
							mm,dd,yy = request.form['accend'].replace("-","/").split("/")
							accend = DateTime.DateTime(int(yy),int(mm),int(dd),23)
						except:
							accend = None
				except:
					print_exception()
					raise program_exit('Error processing request')
			else:
				return newaCommon_io.errmsg('Error processing form; check input')
		elif path[0] in ['apple_et','apple_et_specs', 'apple_thin', 'apple_thin_specs']:
			try:
				smry_type = path[0]
				if len(path) > 1: stn = path[1]
				output = "standalone"
			except IndexError:
				raise program_exit('Error processing request - index error')
			except:
				print_exception()
				raise program_exit('Error processing request')
		else:
			return newaCommon_io.errmsg('Error processing input')
			
# 		send input to appropriate routine
		if stn:
			if smry_type == 'apple_et':
				return run_apple_et(stn,accend,greentip,output)
			elif smry_type == 'apple_et_specs':
				return run_apple_et_specs(stn,accend,output)
			elif smry_type == 'apple_thin':
				return run_apple_thin(stn,accend,greentip,bloom,percentflowerspurs,output)
			elif smry_type == 'apple_thin_specs':
				return run_apple_thin_specs(stn,accend,output)
			else:
				return newaCommon_io.errmsg('Error processing form; check input')
		else:
			return newaCommon_io.errmsg('Error processing form; select station')
	except program_exit,msg:
		print msg
		return newaCommon_io.errmsg('Error processing form; check input')
Esempio n. 15
0
def process_input(request, path):
    try:
        # 		retrieve input
        if path is None:
            newForm = {}
            for k, v in request.form.items():
                newForm[str(k)] = str(v)
            request.form = newForm
            if request and request.form:
                try:
                    stn = request.form['stn'].strip()
                    smry_type = request.form['type'].strip()
                    if request.form.has_key('month'):
                        month = int(request.form['month'])
                    else:
                        month = None
                    if request.form.has_key('year'):
                        year = int(request.form['year'])
                    else:
                        year = None
                    if request.form.has_key('accend'):
                        try:
                            mm, dd, yy = request.form['accend'].split("/")
                            accend = DateTime.DateTime(int(yy), int(mm),
                                                       int(dd), 23)
                        except:
                            accend = None
                    else:
                        accend = None
                    if request.form.has_key('accstr'):
                        try:
                            mm, dd, yy = request.form['accstr'].split("/")
                            accstr = DateTime.DateTime(int(yy), int(mm),
                                                       int(dd), 0)
                        except:
                            accstr = None
                    else:
                        accstr = None
                    if request.form.has_key('ddtype'):
                        ddtype = request.form['ddtype'].strip()
                    else:
                        ddtype = None
                except:
                    print_exception()
                    raise program_exit('Error processing request')
            else:
                return newaCommon_io.errmsg(
                    'Error processing request; check input')
        elif path[0] in ('dly', 'hly', 'dly0', 'hly0') or path[0][0:2] == 'dd':
            try:
                smry_type = path[0]
                stn = path[1]
                year = int(path[2])
                month = int(path[3])
            except IndexError:
                raise program_exit('Error processing request - index error')
            except:
                print_exception()
                raise program_exit('Error processing request')
        elif path[0] == 'est_info':
            try:
                smry_type = path[0]
                stn = path[1]
                if len(path) > 2:
                    year = int(path[2])
                    month = int(path[3])
                else:
                    now = DateTime.now()
                    year = now.year
                    month = now.month
            except IndexError:
                raise program_exit('Error processing request - index error')
            except:
                print_exception()
                raise program_exit('Error processing request')
        else:
            return newaCommon_io.errmsg('Error processing input')

        if smry_type == 'ddrange':
            return run_ddrange(stn, ddtype, accstr, accend)

        if year and year == 9999:
            now = DateTime.now()
            year = now.year

        req_date_dt = DateTime.DateTime(year, month, 1, 0)
        if smry_type == 'hly' or smry_type == 'dly' or smry_type == 'hly0' or smry_type == 'dly0':
            start_date_dt = req_date_dt
        else:
            start_date_dt = DateTime.DateTime(year, 1, 1, 0)
        end_date_dt = req_date_dt + DateTime.RelativeDate(months=+1)

        orig_stn = copy.deepcopy(stn)
        if stn[0:3] == '42.' or stn[0:3] == '43.':
            station_type = 'ucc'
        elif stn[0:1] >= '1' and stn[0:1] <= '9' and stn[1:2] >= '0' and stn[
                1:2] <= '9':
            station_type = 'njwx'
        elif len(stn) == 4 and stn[0:1].upper() == 'K':
            station_type = 'icao'
        elif len(stn) == 4:
            station_type = 'oardc'
        elif stn[0:3] == "cu_" or stn[0:3] == "um_" or stn[
                0:3] == "uc_" or stn[0:3] == "un_":
            station_type = 'cu_log'
        elif stn[0:3] == "ew_":
            stn = stn[3:]
            station_type = 'miwx'
        elif stn[0:5] == "nysm_":
            stn = stn[5:]
            station_type = 'nysm'
        elif len(stn) == 7 and stn[2:3] == "_":
            station_type = 'nwon'
        elif len(stn) == 3 or len(stn) == 6:
            station_type = 'newa'
        else:
            return newaCommon_io.errmsg(
                'Error processing request; check station input')

#		get ucanid and station name from metadata
        if smry_type != 'hly' and smry_type != 'dly':
            ucanid, station_name = newaCommon.get_metadata(stn, station_type)
            if station_type == 'icao':
                staid = stn.upper()
            else:
                staid = ucanid

        if smry_type == 'est_info':
            var_sister = get_sister_info(orig_stn)
            return newaLister_io.estimation_info(stn, station_name, var_sister,
                                                 year, month)

# 		obtain all hourly and daily data for station
        if smry_type != 'hly' and smry_type != 'dly':
            hourly_data, daily_data, avail_vars = newaCommon.get_newa_data(
                staid, stn, start_date_dt, end_date_dt, station_type)
        if smry_type == 'hly' or smry_type == 'dly' or len(avail_vars) > 0:
            if smry_type == 'dly0':
                monthly_data = monthly_summary(daily_data, year, month)
                numcols = len(avail_vars)
                if 'dwpt' in avail_vars: numcols = numcols - 1  #not used
                if 'temp' in avail_vars: numcols = numcols + 2  #max, min, avg
                if 'st4i' in avail_vars: numcols = numcols + 2  #max, min, avg
                return newaLister_io.dly_list_html(stn, station_name, year,
                                                   month, daily_data,
                                                   monthly_data, avail_vars,
                                                   numcols, miss)
            elif smry_type == 'dly':
                return newaLister_io.dly_listWS_html(stn, station_type, year,
                                                     month)
            elif smry_type == 'hly0':
                if 'dwpt' not in avail_vars and 'temp' in avail_vars and 'rhum' in avail_vars:
                    avail_vars.append('dwpt')
                return newaLister_io.hly_list_html(orig_stn, station_name,
                                                   year, month, hourly_data,
                                                   avail_vars, miss,
                                                   station_type)
            elif smry_type == 'hly':
                return newaLister_io.hly_listWS_html(stn, station_type, year,
                                                     month)
            if smry_type in [
                    'dd4c', 'dd143c', 'dd32', 'dd39', 'dd40', 'dd41', 'dd43',
                    'dd45', 'dd48', 'dd50', 'dd8650', 'dd55', 'dd43be',
                    'dd45be', 'dd50be', 'dd4714', 'dd4cbe'
            ]:
                degday_data, degday_miss = degday_summary(
                    daily_data, year, month, smry_type)
                if len(degday_data) == 0:
                    #			no data - try to provide additional information
                    if newaCommon.sta_por.has_key(stn):
                        bd, ed = newaCommon.sta_por[stn]
                        spor_dt = DateTime.DateTime(int(bd[0:4]), int(bd[4:6]),
                                                    int(bd[6:8]))
                        if ed == '99991231':
                            epor_dt = DateTime.now()
                        else:
                            epor_dt = DateTime.DateTime(
                                int(ed[0:4]), int(ed[4:6]), int(ed[6:8]))
                        if req_date_dt < spor_dt:
                            addl_line = 'Data for %s starts %d/%d' % (
                                station_name, spor_dt.month, spor_dt.year)
                        elif end_date_dt > epor_dt:
                            addl_line = 'Data for %s have been collected up to %d/%d' % (
                                station_name, epor_dt.month, epor_dt.year)
                        else:
                            addl_line = None
                    else:
                        addl_line = None
                    return newaCommon_io.nodata(addl_line)
                return newaLister_io.degday_list_html(stn, station_name, year,
                                                      month, degday_data,
                                                      degday_miss, miss,
                                                      smry_type)
            else:
                return newaCommon_io.errmsg('Error processing request')
        else:
            #			no data - try to provide additional information
            if newaCommon.sta_por.has_key(stn):
                bd, ed = newaCommon.sta_por[stn]
                spor_dt = DateTime.DateTime(int(bd[0:4]), int(bd[4:6]),
                                            int(bd[6:8]))
                if ed == '99991231':
                    epor_dt = DateTime.now()
                else:
                    epor_dt = DateTime.DateTime(int(ed[0:4]), int(ed[4:6]),
                                                int(ed[6:8]))
                if req_date_dt < spor_dt:
                    addl_line = 'Data for %s starts %d/%d' % (
                        station_name, spor_dt.month, spor_dt.year)
                elif end_date_dt > epor_dt:
                    addl_line = 'Data for %s has been collected up to %d/%d' % (
                        station_name, epor_dt.month, epor_dt.year)
                else:
                    addl_line = None
            else:
                addl_line = None
            return newaCommon_io.nodata(addl_line)
    except program_exit, logmsg:
        print logmsg
        return newaCommon_io.errmsg('Error processing request; check input')
Esempio n. 16
0
def process_input(request, path):
    try:
        stn = None
        accend = None
        pest = None
        tech_choice = "conventional"
        output = "tab"
        #	 	retrieve input
        newForm = {}
        for k, v in request.form.items():
            newForm[str(k)] = str(v)
        request.form = newForm
        if path is None:
            if request and request.form:
                #				print 'form',request.form
                try:
                    smry_type = request.form['type'].strip()
                    if request.form.has_key('stn'):
                        stn = request.form['stn'].strip()
                    if request.form.has_key('pest'):
                        pest = request.form['pest']
                    if request.form.has_key('tech_choice'):
                        tech_choice = request.form['tech_choice']
                    if request.form.has_key('output'):
                        output = request.form['output']
                    if request.form.has_key('accend'):
                        try:
                            mm, dd, yy = request.form['accend'].split("/")
                            accend = DateTime.DateTime(int(yy), int(mm),
                                                       int(dd), 23)
                        except:
                            accend = None
                except:
                    print_exception()
                    raise program_exit('Error processing request')
            else:
                return newaCommon_io.errmsg(
                    'Error processing form; check input')
        elif path[0] in ['crucifer_disease']:
            #			print 'path:',path
            try:
                smry_type = path[0]
                pest = path[1]
                if len(path) > 2: stn = path[2]
                output = "standalone"
            except IndexError:
                raise program_exit('Error processing request - index error')
            except:
                print_exception()
                raise program_exit('Error processing request')
        else:
            #			print 'path:',path
            try:
                smry_type = path[0]
                pest = path[0]
                if len(path) > 1: stn = path[1]
                output = "standalone"
            except IndexError:
                raise program_exit('Error processing request - index error')
            except:
                print_exception()
                raise program_exit('Error processing request')

# 		send input to appropriate routine
        if pest:
            return Crucifer().run_crucifer_disease(stn, pest, accend,
                                                   tech_choice, output)
        else:
            return newaCommon_io.errmsg('Error processing form; check disease')
    except program_exit, msg:
        print msg
        return newaCommon_io.errmsg('Error processing form; check input')
Esempio n. 17
0
def process_input (request,path):
	try:
#	 	retrieve input
		if path[0] in ['stationList','stateStationList','stateInactiveStationList','stationSisterInfo','diseaseStations','getForecastUrl','stationInfo','stationModels','getFcstData','gridSoilTemps']:
			try:
				smry_type = path[0]
				if len(path) > 1:
					if path[0] == 'stateStationList' or path[0] == 'stateInactiveStationList':
						list_options = {}
						list_options['reqvar'] = path[1]
						if len(path) > 2:
							list_options['state'] = path[2].upper()
						else:
							list_options['state'] = ''
					elif path[0] == 'stationSisterInfo':
						list_options = {}
						list_options['station'] = path[1]
						list_options['network'] = path[2]
					elif path[0] == 'getFcstData':
						list_options = {}
						list_options['station'] = path[1]
						list_options['network'] = path[2]
						list_options['variable'] = path[3]
						list_options['startdate'] = path[4]
						list_options['enddate'] = path[5]
					elif path[0] == 'gridSoilTemps':
						raise program_exit('Unexpected path to gridSoilTemps')
					else:
						list_options = path[1]
						if list_options == 'robots.txt': return newaUtil_io.robots()
				else:
					list_options = None
			except IndexError:
				raise program_exit('Error processing request')
			except:
				print_exception()
				raise program_exit('Error processing request')
		elif path[0] == 'robots.txt':
			return newaUtil_io.robots()
		else:
			return program_exit('Error processing input')
			
# 		send input to appropriate routine
		if smry_type == 'stationList':
			return run_stationList(list_options)
		if smry_type == 'stateStationList':
			return run_stateStationList(list_options)
		if smry_type == 'stationSisterInfo':
			return run_stationSisterInfo(list_options)
		if smry_type == 'stateInactiveStationList':
			return run_stateInactiveStationList(list_options)
		if smry_type == 'stationInfo':
			return run_stationInfo(list_options)
		if smry_type == 'stationModels':
			return run_stationModels(list_options)
		elif smry_type == 'diseaseStations':
			return run_diseaseStations(list_options)
		elif smry_type == 'getForecastUrl':
			return getForecastUrl(list_options)
		elif smry_type == 'getFcstData':
			return run_getFcstData(list_options)
		elif smry_type == 'gridSoilTemps':
			return run_gridSoilTemps(ll,cover,sdate,edate)
		else:
			return program_exit('Error processing request')
	except program_exit,msg:
		print msg
		return newaCommon_io.errmsg('Error processing request')
Esempio n. 18
0
    def run_crucifer_disease(self, stn, pest, accend, tech_choice, output):
        try:
            smry_dict = {}
            smry_dict['pest'] = pest
            if not accend:
                accend = DateTime.now()
            smry_dict['output'] = output
            if output == 'standalone':
                smry_dict['stn'] = stn
                smry_dict['accend'] = accend

            # determine information needed for particular disease
            pest_status_management = import_info_dict(pest)
            if not pest_status_management:
                return newaCommon_io.errmsg(
                    'A model is not available for the disease you selected.')
            smry_dict['pest_name'] = pest_status_management['pest_name']
            smry_dict['crop_stages'] = pest_status_management['messages'].keys(
            )

            # get station name - don't need this for Crucifers
            # ucanid,smry_dict['station_name'] = get_metadata (stn)

            # get status and recommendations
            smry_dict['stage'] = "Not defined"
            smry_dict['status'] = "Not defined"
            smry_dict['manage'] = "Not defined"
            for k in smry_dict['crop_stages']:
                psmk = pest_status_management['messages'][k]
                if psmk.has_key('datelo'):
                    datelo = DateTime.DateTime(accend.year, *psmk['datelo'])
                    datehi = DateTime.DateTime(accend.year, *psmk['datehi'])
                    if accend >= datelo and accend <= datehi:
                        smry_dict = self.filldict(psmk, k, tech_choice,
                                                  smry_dict)
                        break
            else:
                # didn't fall within any date ranges; now get dd values and check dd ranges
                start_date_dt = DateTime.DateTime(accend.year, 1, 1)
                daily_data, station_name = self.get_daily(
                    stn, start_date_dt, accend)
                smry_dict['station_name'] = station_name
                if len(daily_data) > 0:
                    degday_data = self.degday_calcs(daily_data, start_date_dt,
                                                    accend, 'dd4c', 'accum')
                    if len(degday_data) > 0 and degday_data[-1][4] != miss:
                        ddaccum = degday_data[-1][4]
                        for k in smry_dict['crop_stages']:
                            psmk = pest_status_management['messages'][k]
                            if psmk.has_key('ddlo'):
                                if ddaccum >= psmk['ddlo'] and ddaccum <= psmk[
                                        'ddhi']:
                                    smry_dict = self.filldict(
                                        psmk, k, tech_choice, smry_dict)
                                    break
                        else:
                            print "Error determining recommendations:", pest, stn, accend
                    else:
                        return self.nodata(stn, station_name, start_date_dt,
                                           accend)
                else:
                    return self.nodata(stn, station_name, start_date_dt,
                                       accend)

            return newaVegModel_io.crucifer_results(smry_dict)
        except:
            print_exception()
Esempio n. 19
0
# 		send input to appropriate routine
		if smry_type == 'apple_et':
			return newaTools_io.helppage([("Model overview","/apple_et_help.html"),
										  ("Station inclusion","/apple_tool_stations.html")])
		elif smry_type == 'apple_thin':
			return newaTools_io.helppage([("Model overview","/apple_thin_help.html"),
										  ("Station inclusion","/apple_tool_stations.html")])
		else:
			return newaCommon_io.errmsg('Error processing input')
	except program_exit,msg:
		print msg
		return newaCommon_io.errmsg('Error processing input')
	except:
		print_exception()
		return newaCommon_io.errmsg('Unexpected error')

#--------------------------------------------------------------------------------------------					
def process_input (request,path):
	try:
		stn = None
		accend = None
		greentip = None
		bloom = None
		percentflowerspurs = None
		output = "tab"
#	 	retrieve input
		newForm = {}
		for k,v in request.form.items() :
			newForm[str(k)] = str(v)
		request.form = newForm