Exemple #1
0
def get_sister_info(stn):
    var_sister = []
    try:
        from sister_info import sister_info

        if sister_info.has_key(stn):
            sister = sister_info[stn]
            for var in sister.keys():
                if (
                    sister[var][0:1] >= "1"
                    and sister[var][0:1] <= "9"
                    and sister[var][1:2] >= "0"
                    and sister[var][1:2] <= "9"
                ):
                    station_type = "njwx"
                elif len(sister[var]) == 4:
                    sister[var] = sister[var].upper()
                    station_type = "icao"
                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_type = "cu_log"
                elif len(sister[var]) == 3 or len(sister[var]) == 6:
                    station_type = "newa"
                est_staid, sister_name = newaCommon.get_metadata(sister[var], station_type)
                var_sister.append((var, sister_name))
    except:
        print "Error finding sister info"
        print_exception()
    return var_sister
Exemple #2
0
def process_input(request, path):
    try:
        # 		retrieve input
        if path is None:
            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") 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":
            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)

        if 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:
            station_type = "icao"
        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 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
        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(stn)
            return newaLister_io.estimation_info(stn, station_name, var_sister, year, month)

        # 		obtain all hourly and daily data for station
        hourly_data, daily_data, avail_vars = newaCommon.get_newa_data(
            staid, stn, start_date_dt, end_date_dt, station_type
        )
        if len(avail_vars) > 0:
            if smry_type == "dly":
                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 == "hly":
                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(
                    stn, station_name, year, month, hourly_data, avail_vars, miss, station_type
                )
            if smry_type in [
                "dd4c",
                "dd143c",
                "dd32",
                "dd39",
                "dd40",
                "dd43",
                "dd45",
                "dd48",
                "dd50",
                "dd8650",
                "dd55",
                "dd43be",
                "dd50be",
                "dd4714",
            ]:
                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")