utils.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:census-loader 作者: minus34 项目源码 文件源码
def get_min_max(data_table, boundary_table, stat_field, num_classes, min_val, map_type, pg_cur, settings):

    # query to get min and max values (filter small populations that overly influence the map visualisation)
    try:
        # if map_type == "values":
        sql = "SELECT MIN(%s) AS min, MAX(%s) AS max FROM %s AS tab " \
              "INNER JOIN %s AS bdy ON tab.{0} = bdy.id " \
              "WHERE %s > 0 " \
              "AND bdy.population > {1}" \
            .format(settings['region_id_field'], float(min_val))

        sql_string = pg_cur.mogrify(sql, (AsIs(stat_field), AsIs(stat_field), AsIs(data_table),
                                          AsIs(boundary_table), AsIs(stat_field)))

        pg_cur.execute(sql_string)
        row = pg_cur.fetchone()

    except Exception as ex:
        print("{0} - {1} Failed: {2}".format(data_table, stat_field, ex))
        return list()

    output_dict = {
        "min": row["min"],
        "max": row["max"]
    }

    return output_dict
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号