def get_population_class(values_int, values_ext): bats_in_colonies = sum(get_values(values_int, 'NR_INDIVIZI')) isolated_bats = sum(get_values(values_int, 'NR_INDIVIZI_IZOLATI')) obs_spots = len(get_values(values_ext, 'NR_INDIVIZI')) obs_dates = get_values(values_int, 'DATA') + get_values(values_ext, 'DATA') years = len(set([get_year(d) for d in obs_dates])) return (bats_in_colonies + 30 * isolated_bats + 100 * obs_spots) / years
def get_LL_habitat_trend(specnum, region): where_query = "SPECIE='%s' AND REG_BIOGEO='%s'" % (specnum, region) url = _get_species_url(LL, TREND_HAB) data = generic_rest_call(url, where_query) or [] values = [r['attributes'] for r in data] if not values: return hab_q = most_common(get_values(values, 'CALITATE_HAB')) cons = most_common(get_values(values, 'STARE_CONS')) return hab_q, cons
def get_LL_range_trend(specnum, region): where_query = "SPECIE='%s' AND REG_BIOGEO='%s'" % (specnum, region) url = _get_species_url(LL, TREND) data = generic_rest_call(url, where_query) or [] values = [r['attributes'] for r in data] if not values: return trend = most_common(get_values(values, 'TREND')) cons = most_common(get_values(values, 'STARE_CONS')) rang = most_common(get_values(values, 'RANG')) return trend, cons, rang
def get_PS_trend(habcode, region): where_query = "HABITAT='%s' AND REG_BIOGEO='%s'" % (habcode, region) url = _get_habitat_url(PS, TREND) data = generic_rest_call(url, where_query) or [] values = [r['attributes'] for r in data] if not values: return grad = most_common(get_values(values, 'GRAD')) rang = most_common(get_values(values, 'RANG')) morf_fields = ['MORFOLOGIE_LOC_ST', 'UMPLUTURA', 'REGIM_HIDRO', 'ACUMULARE_APA', 'IVIRE_APA', 'SURSA_MICRO_PICATURI'] morf_frequencies = [] for field in morf_fields: morf_values = get_values(values, field) if not morf_values: continue most_common_value = most_common(morf_values) frequency = (morf_values.count(most_common_value) / float(len(morf_values) or 1)) morf_frequencies.append(frequency) morf_frequency = average(morf_frequencies) env_fields = ['TEMP_INT', 'UMITIDATE_REL'] seasonal_averages = get_seasonal_avg(values, env_fields, average) url = _get_habitat_url(PS, LAST_10) data = generic_rest_call(url, where_query) or [] values = [r['attributes'] for r in data] hist_seasonal_intervals = get_seasonal_intervals(values, env_fields) env_characteristics = 0 for field, seasonal_values in seasonal_averages.iteritems(): for season, value in seasonal_values.iteritems(): min, max = hist_seasonal_intervals[field][season] if min <= value <= max: env_characteristics += 1 else: env_characteristics -= 1 return grad, rang, (env_characteristics >= 0), morf_frequency
def get_population_trend(values_int, values_ext): trend = most_common(get_values(values_ext, 'TREND_EVAL_POP_AR')) if not trend: return 'x' years_dict = get_years_dict(values_int, values_ext) years = sorted(years_dict.keys()) diff = 0 if len(years) > 1: for year in years[:-1]: pop_class = get_class(years_dict[year]) next_year = years[years.index(year) + 1] next_pop_class = get_class(years_dict[next_year]) diff += next_pop_class - pop_class if trend in ('X', '+') and diff > 0: return '+' elif trend in ('X', '-') and diff < 0: return '-' return '0'
def get_ref_population(values_int, values_ext): bats_in_colonies = sum(get_values(values_int, 'NR_INDIVIZI')) isolated_bats = sum(get_values(values_ext, 'NR_INDIVIZI')) return bats_in_colonies + 100 * isolated_bats
def get_max_population(values_int, values_ext): bats_in_colonies = sum(get_values(values_int, 'NR_INDIVIZI')) isolated_bats = sum(get_values(values_int, 'NR_INDIVIZI_IZOLATI')) obs_spots = len(get_values(values_ext, 'NR_INDIVIZI')) return bats_in_colonies + 30 * isolated_bats + 100 * obs_spots
def get_min_population(values_int): return len(get_values(values_int, 'NR_INDIVIZI')) * 100