-CREATE OR REPLACE FUNCTION get_osm_views(centroid GEOMETRY)
- RETURNS BIGINT
- AS $$
-DECLARE
- result BIGINT;
-BEGIN
- SELECT ST_Value(osm_views.rast, centroid)
- FROM osm_views
- WHERE ST_Intersects(ST_ConvexHull(osm_views.rast), centroid) LIMIT 1 INTO result;
-
- return COALESCE(result, 0);
-END;
-$$
-LANGUAGE plpgsql STABLE;
-
-
-CREATE OR REPLACE FUNCTION normalize_osm_views(views BIGINT)
- RETURNS FLOAT
- AS $$
- DECLARE
- normalized_osm_views FLOAT;
- max_views BIGINT;
- BEGIN
- IF views > 0 THEN
- -- Get the highest view count to use it in normalizing the data
- SELECT max_views_count FROM osm_views_stat INTO max_views;
- normalized_osm_views := (LOG(views))/(LOG(max_views));
- ELSE
- normalized_osm_views := 0.0;
- END IF;
-
- RETURN normalized_osm_views;
- END;
-$$
-LANGUAGE plpgsql;
-
-