示例#1
0
文件: climate.py 项目: SDLLABS/eden
def climate_station_parameter_range_to(row):

    default = current.messages["NONE"]

    if hasattr(row, "climate_station_parameter"):
        row = row.climate_station_parameter
    try:
        parameter_id = row.parameter_id
        station_id = row.station_id
    except AttributeError:
        return default

    table = current.s3db.table("climate_sample_table_%s" % parameter_id)
    if not table:
        return default

    date = table.time_period.max()
    row = db(table.place_id == station_id).select(date).first()
    if row:
        date = row[date]
        import ClimateDataPortal
        year, month = ClimateDataPortal.month_number_to_year_month(date)
        return "%s-%s" % (month, year)
    else:
        return default
示例#2
0
def climate_station_parameter_range_to(self):
    
    default = current.messages["NONE"]

    if hasattr(row, "climate_station_parameter"):
        row = row.climate_station_parameter
    try:
        parameter_id = row.parameter_id
        station_id = row.station_id
    except AttributeError:
        return default

    table = current.s3db.table("climate_sample_table_%s" % parameter_id)
    if not table:
        return default

    date = table.time_period.max()
    row = db(table.place_id == station_id).select(date).first()
    if row:
        date = row[date]
        import ClimateDataPortal
        year, month = ClimateDataPortal.month_number_to_year_month(date)
        return "%s-%s" % (month, year)
    else:
        return default
示例#3
0
 def range_to(self):
     query = ("SELECT MAX(time_period) "
              "from climate_sample_table_%(parameter_id)i "
              "WHERE place_id = %(station_id)i;") % dict(
                  parameter_id=self.climate_station_parameter.parameter_id,
                  station_id=self.climate_station_parameter.station_id,
              )
     date = current.db.executesql(query)[0][0]
     if date is not None:
         import ClimateDataPortal
         year, month = ClimateDataPortal.month_number_to_year_month(date)
         return "%s-%s" % (month, year)
     else:
         return current.messages.NONE
示例#4
0
 def range_to(self):
     query = (
         "SELECT MAX(time_period) "
         "from climate_sample_table_%(parameter_id)i "
         "WHERE place_id = %(station_id)i;"
     ) % dict(
         parameter_id = self.climate_station_parameter.parameter_id,
         station_id = self.climate_station_parameter.station_id,
     )
     date  = current.db.executesql(query)[0][0]
     if date is not None:
         import ClimateDataPortal
         year, month = ClimateDataPortal.month_number_to_year_month(date)
         return "%s-%s" % (month, year)
     else:
         return current.messages.NONE