Compare commits
94 Commits
python-0.9
...
python-0.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59ed8b88a3 | ||
|
|
ab4584bed3 | ||
|
|
2b2691d0b9 | ||
|
|
3524aabd9e | ||
|
|
9c6eabc59e | ||
|
|
0d92eb4ba8 | ||
|
|
769b740ba4 | ||
|
|
c2ede37d75 | ||
|
|
4c75c5f261 | ||
|
|
f07d2f9302 | ||
|
|
37a3214f67 | ||
|
|
efb10e43e4 | ||
|
|
1dc6060570 | ||
|
|
a2da597e00 | ||
|
|
4af5975ac1 | ||
|
|
579d11ebd5 | ||
|
|
a1eae3934c | ||
|
|
d70d149eed | ||
|
|
decc7626a8 | ||
|
|
abbb227ad5 | ||
|
|
970927375e | ||
|
|
6f2883be5d | ||
|
|
06df5a84c4 | ||
|
|
5d94a852e4 | ||
|
|
f0474852f2 | ||
|
|
975efb0f92 | ||
|
|
7f963d2f7a | ||
|
|
8396eae733 | ||
|
|
25cd40164a | ||
|
|
dfaa037475 | ||
|
|
c92ab9c207 | ||
|
|
27806ead54 | ||
|
|
d1b17da70b | ||
|
|
2e6f37af56 | ||
|
|
b5f4c507b3 | ||
|
|
95dda082e7 | ||
|
|
d65a0d9ac5 | ||
|
|
9f9034f4f1 | ||
|
|
603fbbbc3f | ||
|
|
3fa686ec65 | ||
|
|
429a71ef37 | ||
|
|
b2cdb1c74b | ||
|
|
84061dec4f | ||
|
|
08debb83ed | ||
|
|
dac5e76e98 | ||
|
|
7a32ace1ac | ||
|
|
7a56dc698f | ||
|
|
4945b4d0bf | ||
|
|
e6963198dc | ||
|
|
9ae04aaad2 | ||
|
|
b392eaf74b | ||
|
|
040b094b01 | ||
|
|
a006f76285 | ||
|
|
38f2592b22 | ||
|
|
eb7188235d | ||
|
|
3e059003b6 | ||
|
|
94099540d7 | ||
|
|
b403e1d69a | ||
|
|
623faf1a22 | ||
|
|
0e38af6ecd | ||
|
|
b00edf218a | ||
|
|
6f9feb07a0 | ||
|
|
2c76fa4501 | ||
|
|
4169bc0f88 | ||
|
|
7d9dc554c5 | ||
|
|
fffb64de36 | ||
|
|
6177f0ac76 | ||
|
|
2c49f09aad | ||
|
|
22fdbd0f4e | ||
|
|
352d4217bc | ||
|
|
2fd560f3cf | ||
|
|
a4858bbf3c | ||
|
|
88ed777785 | ||
|
|
6f0db20163 | ||
|
|
73aa26590b | ||
|
|
c571edb21e | ||
|
|
e878031744 | ||
|
|
49fd51f6da | ||
|
|
708bee2912 | ||
|
|
6b56c4ad0d | ||
|
|
1f8fb28449 | ||
|
|
7fd13f416d | ||
|
|
f41a30316e | ||
|
|
cf3c6f2ce5 | ||
|
|
5499bd1e69 | ||
|
|
93579532e3 | ||
|
|
0533018326 | ||
|
|
e380d51bec | ||
|
|
6058960ec5 | ||
|
|
336d8be977 | ||
|
|
75557837b0 | ||
|
|
e7c35457e1 | ||
|
|
80963e2589 | ||
|
|
19d6cacdb3 |
95
NEWS.md
95
NEWS.md
@@ -1,3 +1,22 @@
|
|||||||
|
November 7st, 2016
|
||||||
|
==================
|
||||||
|
* Version 0.17.0 of the server and version 0.10.0 of the python package
|
||||||
|
* Added metrics context manager to gather data from different parts of the server functions
|
||||||
|
* Support multiple response data for one server function call: For example in the one_to_many matrix client
|
||||||
|
* Metrics files configuration is not mandatory
|
||||||
|
* All the services covered and gathering metrics
|
||||||
|
|
||||||
|
October 27st, 2016
|
||||||
|
==================
|
||||||
|
* Version 0.9.4 of the python package
|
||||||
|
* Added timeouts to all the third-party connections using requests because requests by default doesn't add timeouts.
|
||||||
|
|
||||||
|
October 26st, 2016
|
||||||
|
==================
|
||||||
|
* Version 0.9.3 of the python package
|
||||||
|
* Fixes https://github.com/CartoDB/dataservices-api/issues/293
|
||||||
|
* Mitigate problem with 504 errors coming from Mapzen
|
||||||
|
|
||||||
October 21st, 2016
|
October 21st, 2016
|
||||||
==================
|
==================
|
||||||
* Version 0.9.2 of the python package
|
* Version 0.9.2 of the python package
|
||||||
@@ -39,7 +58,7 @@ August 11, 2016
|
|||||||
===========
|
===========
|
||||||
* Released server version 0.14.2
|
* Released server version 0.14.2
|
||||||
* Released client version 0.10.2
|
* Released client version 0.10.2
|
||||||
* Always default arguments for DO functions to NULL, which prevents duplication & overwrite
|
* Always default arguments for DO functions to NULL, which prevents duplication & overwrite
|
||||||
|
|
||||||
August 5, 2016
|
August 5, 2016
|
||||||
===========
|
===========
|
||||||
@@ -95,7 +114,7 @@ July 15, 2016:
|
|||||||
* __OBS_ConnectUserTable
|
* __OBS_ConnectUserTable
|
||||||
|
|
||||||
This change does not require any client change.
|
This change does not require any client change.
|
||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.13.1-server
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.13.1-server
|
||||||
|
|
||||||
Jul 12, 2016:
|
Jul 12, 2016:
|
||||||
@@ -105,14 +124,14 @@ Jul 12, 2016:
|
|||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.13.0-server
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.13.0-server
|
||||||
|
|
||||||
Jul 12, 2016:
|
Jul 12, 2016:
|
||||||
===========
|
===========
|
||||||
* Release client 0.10.0
|
* Release client 0.10.0
|
||||||
* [Client] Add beta augment functions, isoline fixes, observatory dump version
|
* [Client] Add beta augment functions, isoline fixes, observatory dump version
|
||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.10.0-client
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.10.0-client
|
||||||
|
|
||||||
Jul 7, 2016:
|
Jul 7, 2016:
|
||||||
===========
|
===========
|
||||||
* Release client 0.9.0
|
* Release client 0.9.0
|
||||||
* This release adds two new functions in the Data Services extension client:
|
* This release adds two new functions in the Data Services extension client:
|
||||||
@@ -122,7 +141,7 @@ Jul 7, 2016:
|
|||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.9.0-client
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.9.0-client
|
||||||
|
|
||||||
Jul 7, 2016:
|
Jul 7, 2016:
|
||||||
===========
|
===========
|
||||||
* Release server 0.12.0
|
* Release server 0.12.0
|
||||||
* This release adds four new functions in the Data Services extension server:
|
* This release adds four new functions in the Data Services extension server:
|
||||||
@@ -134,7 +153,7 @@ Jul 7, 2016:
|
|||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.12.0-server
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.12.0-server
|
||||||
|
|
||||||
Jul 5, 2016:
|
Jul 5, 2016:
|
||||||
===========
|
===========
|
||||||
* Release server 0.11.0
|
* Release server 0.11.0
|
||||||
* Added three new public functions for each geocoding provider:
|
* Added three new public functions for each geocoding provider:
|
||||||
@@ -147,40 +166,40 @@ Jul 5, 2016:
|
|||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.11.0-server
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.11.0-server
|
||||||
|
|
||||||
Jul 5, 2016:
|
Jul 5, 2016:
|
||||||
===========
|
===========
|
||||||
* Release client 0.8.0
|
* Release client 0.8.0
|
||||||
* Expose providers in high-precision geocoder functions
|
* Expose providers in high-precision geocoder functions
|
||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.8.0-client
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.8.0-client
|
||||||
|
|
||||||
Jun 15, 2016:
|
Jun 15, 2016:
|
||||||
===========
|
===========
|
||||||
* [server python] Write quota info from services with zero padding. Closes issue #204.
|
* [server python] Write quota info from services with zero padding. Closes issue #204.
|
||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.10.0-server3
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.10.0-server3
|
||||||
|
|
||||||
Jun 13, 2016:
|
Jun 13, 2016:
|
||||||
===========
|
===========
|
||||||
* [server python] Read quota info from services with and without zero padding. Closes issue #201.
|
* [server python] Read quota info from services with and without zero padding. Closes issue #201.
|
||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.10.0-server2
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.10.0-server2
|
||||||
|
|
||||||
May 31, 2016:
|
May 31, 2016:
|
||||||
===========
|
===========
|
||||||
* Release client 0.7.0
|
* Release client 0.7.0
|
||||||
* Adds new function OBS_GetMeasureById
|
* Adds new function OBS_GetMeasureById
|
||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.7.0-client
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.7.0-client
|
||||||
|
|
||||||
May 31, 2016:
|
May 31, 2016:
|
||||||
===========
|
===========
|
||||||
* Release server 0.10.0
|
* Release server 0.10.0
|
||||||
* Adds new function OBS_GetMeasureById
|
* Adds new function OBS_GetMeasureById
|
||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.10.0-server
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.10.0-server
|
||||||
|
|
||||||
May 25, 2016:
|
May 25, 2016:
|
||||||
===========
|
===========
|
||||||
* Release server 0.9.0
|
* Release server 0.9.0
|
||||||
* Added a new routing function which allows to generate routes from an origin to a destination, which passes through a set of defined locations:
|
* Added a new routing function which allows to generate routes from an origin to a destination, which passes through a set of defined locations:
|
||||||
@@ -197,7 +216,7 @@ May 25, 2016:
|
|||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.9.0-server
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.9.0-server
|
||||||
|
|
||||||
May 25, 2016:
|
May 25, 2016:
|
||||||
===========
|
===========
|
||||||
* Release client 0.6.0
|
* Release client 0.6.0
|
||||||
* Includes new client function to obtain a route with waypoints:
|
* Includes new client function to obtain a route with waypoints:
|
||||||
@@ -205,7 +224,7 @@ May 25, 2016:
|
|||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.6.0-client
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.6.0-client
|
||||||
|
|
||||||
May 18, 2016:
|
May 18, 2016:
|
||||||
===========
|
===========
|
||||||
* Release client 0.5.0
|
* Release client 0.5.0
|
||||||
* Added new functions for the data observatory:
|
* Added new functions for the data observatory:
|
||||||
@@ -228,7 +247,7 @@ May 18, 2016:
|
|||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.5.0-client
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.5.0-client
|
||||||
|
|
||||||
May 18, 2016:
|
May 18, 2016:
|
||||||
===========
|
===========
|
||||||
* Release server 0.8.0: Data Observatory release
|
* Release server 0.8.0: Data Observatory release
|
||||||
* Added new functions for the data observatory:
|
* Added new functions for the data observatory:
|
||||||
@@ -252,28 +271,28 @@ May 18, 2016:
|
|||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.8.0-server
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.8.0-server
|
||||||
|
|
||||||
May 10, 2016:
|
May 10, 2016:
|
||||||
===========
|
===========
|
||||||
* Release server 0.7.4
|
* Release server 0.7.4
|
||||||
* In case we receive a 4xx error from one of the services: isolines, here geocoder, etc we have to return an empty value an increment the empty counter. We have to raise exception in 5xx or unhandled exceptions
|
* In case we receive a 4xx error from one of the services: isolines, here geocoder, etc we have to return an empty value an increment the empty counter. We have to raise exception in 5xx or unhandled exceptions
|
||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.7.4-server
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.7.4-server
|
||||||
|
|
||||||
May 10, 2016:
|
May 10, 2016:
|
||||||
===========
|
===========
|
||||||
* Release server 0.7.3
|
* Release server 0.7.3
|
||||||
* Change how the blue/green system is working in the server side. Now the loopback is only in the observatory extension functions call instead in all the dataservices-api function for observatory
|
* Change how the blue/green system is working in the server side. Now the loopback is only in the observatory extension functions call instead in all the dataservices-api function for observatory
|
||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.7.3-server
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.7.3-server
|
||||||
|
|
||||||
May 4, 2016:
|
May 4, 2016:
|
||||||
===========
|
===========
|
||||||
* Release server 0.7.2
|
* Release server 0.7.2
|
||||||
* Added Blue/Green capability to the data observatory functions in order to be able to use staging or production databases
|
* Added Blue/Green capability to the data observatory functions in order to be able to use staging or production databases
|
||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.7.2-server
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.7.2-server
|
||||||
|
|
||||||
Apr 25, 2016:
|
Apr 25, 2016:
|
||||||
===========
|
===========
|
||||||
* Release server 0.7.1
|
* Release server 0.7.1
|
||||||
* Use redis based config if exists, if not use the db config value
|
* Use redis based config if exists, if not use the db config value
|
||||||
@@ -281,7 +300,7 @@ Apr 25, 2016:
|
|||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.7.1-server
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.7.1-server
|
||||||
|
|
||||||
Apr 21, 2016:
|
Apr 21, 2016:
|
||||||
===========
|
===========
|
||||||
* Release client 0.4.0
|
* Release client 0.4.0
|
||||||
* Remove old versioning system for client side
|
* Remove old versioning system for client side
|
||||||
@@ -291,7 +310,7 @@ Apr 21, 2016:
|
|||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.4.0-client
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.4.0-client
|
||||||
|
|
||||||
Apr 21, 2016:
|
Apr 21, 2016:
|
||||||
===========
|
===========
|
||||||
* Release server 0.7.0
|
* Release server 0.7.0
|
||||||
* Added obs_get_demography_snapshot function
|
* Added obs_get_demography_snapshot function
|
||||||
@@ -300,14 +319,14 @@ Apr 21, 2016:
|
|||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.7.0-server
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.7.0-server
|
||||||
|
|
||||||
Apr 19, 2016:
|
Apr 19, 2016:
|
||||||
===========
|
===========
|
||||||
* Release server 0.6.2
|
* Release server 0.6.2
|
||||||
* Add Mapzen routing and geocoder quota check
|
* Add Mapzen routing and geocoder quota check
|
||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.6.2-server
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.6.2-server
|
||||||
|
|
||||||
Apr 14, 2016:
|
Apr 14, 2016:
|
||||||
===========
|
===========
|
||||||
* Release server 0.6.1
|
* Release server 0.6.1
|
||||||
* Now the implementation knows how to get the iso3 for the passed country in order to pass it to Mapzen
|
* Now the implementation knows how to get the iso3 for the passed country in order to pass it to Mapzen
|
||||||
@@ -328,8 +347,8 @@ Mar 28, 2016:
|
|||||||
* Integrated Mapzen geocoder for street level geocoding function
|
* Integrated Mapzen geocoder for street level geocoding function
|
||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.6.0-server
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.6.0-server
|
||||||
|
|
||||||
Mar 23, 2016:
|
Mar 23, 2016:
|
||||||
===========
|
===========
|
||||||
* Release server 0.5.2
|
* Release server 0.5.2
|
||||||
* Deleted old versioning system
|
* Deleted old versioning system
|
||||||
@@ -338,7 +357,7 @@ Mar 23, 2016:
|
|||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.5.2-server
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.5.2-server
|
||||||
|
|
||||||
Mar 17, 2016:
|
Mar 17, 2016:
|
||||||
===========
|
===========
|
||||||
* Release server 0.5.1
|
* Release server 0.5.1
|
||||||
* Renamed the python library metrics functions
|
* Renamed the python library metrics functions
|
||||||
@@ -348,7 +367,7 @@ Mar 17, 2016:
|
|||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.5.1-server
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.5.1-server
|
||||||
|
|
||||||
Mar 14, 2016:
|
Mar 14, 2016:
|
||||||
===========
|
===========
|
||||||
* Release server 0.5.0
|
* Release server 0.5.0
|
||||||
* Mapzen routing functions to calculate a route point to point
|
* Mapzen routing functions to calculate a route point to point
|
||||||
@@ -356,28 +375,28 @@ Mar 14, 2016:
|
|||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.5.0-server
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.5.0-server
|
||||||
|
|
||||||
Mar 14, 2016:
|
Mar 14, 2016:
|
||||||
===========
|
===========
|
||||||
* Release client 0.3.0
|
* Release client 0.3.0
|
||||||
* Added cdb_routing_point_to_point function using Mapzen as provider
|
* Added cdb_routing_point_to_point function using Mapzen as provider
|
||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.3.0-client
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.3.0-client
|
||||||
|
|
||||||
Feb 26, 2016:
|
Feb 26, 2016:
|
||||||
===========
|
===========
|
||||||
* Release client 0.2.0
|
* Release client 0.2.0
|
||||||
* Added routing isolines capabilities to the client and public API
|
* Added routing isolines capabilities to the client and public API
|
||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.2.0-client
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.2.0-client
|
||||||
|
|
||||||
Feb 26, 2016:
|
Feb 26, 2016:
|
||||||
===========
|
===========
|
||||||
* Release server 0.4.0
|
* Release server 0.4.0
|
||||||
* Added routing isolines capabilities
|
* Added routing isolines capabilities
|
||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.4.0-server
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.4.0-server
|
||||||
|
|
||||||
Feb 11, 2016:
|
Feb 11, 2016:
|
||||||
===========
|
===========
|
||||||
* Release server 0.3.0
|
* Release server 0.3.0
|
||||||
* Extension refactor, now is called cdb_dataservices_[client|server] in order to include more services aside the geocoder.
|
* Extension refactor, now is called cdb_dataservices_[client|server] in order to include more services aside the geocoder.
|
||||||
@@ -386,7 +405,7 @@ Feb 11, 2016:
|
|||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.3.0-server
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.3.0-server
|
||||||
|
|
||||||
Feb 4, 2016:
|
Feb 4, 2016:
|
||||||
===========
|
===========
|
||||||
* Release server 0.2.0
|
* Release server 0.2.0
|
||||||
* Logic for the google geocoder so the users with this geocoder setted up can use street level geocoding too
|
* Logic for the google geocoder so the users with this geocoder setted up can use street level geocoding too
|
||||||
@@ -394,7 +413,7 @@ Feb 4, 2016:
|
|||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.2.0-server
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.2.0-server
|
||||||
|
|
||||||
Jan 25, 2016:
|
Jan 25, 2016:
|
||||||
===========
|
===========
|
||||||
* Release Geocoder API 0.1.0
|
* Release Geocoder API 0.1.0
|
||||||
* Street geocoding available through the cdb_geocoder_street_point_v2 function (only working Heremaps geocoder)
|
* Street geocoding available through the cdb_geocoder_street_point_v2 function (only working Heremaps geocoder)
|
||||||
@@ -403,27 +422,27 @@ Jan 25, 2016:
|
|||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.1.0
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.1.0
|
||||||
|
|
||||||
Jan 25, 2016:
|
Jan 25, 2016:
|
||||||
===========
|
===========
|
||||||
* Release Geocoder API 0.0.1 production ready
|
* Release Geocoder API 0.0.1 production ready
|
||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.0.1
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.0.1
|
||||||
|
|
||||||
Dec 23, 2015:
|
Dec 23, 2015:
|
||||||
===========
|
===========
|
||||||
* Release Geocoder API 0.0.2 beta
|
* Release Geocoder API 0.0.2 beta
|
||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.0.2
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.0.2
|
||||||
|
|
||||||
Dec 3, 2015:
|
Dec 3, 2015:
|
||||||
===========
|
===========
|
||||||
* Release Geocoder API 0.0.1 Beta2
|
* Release Geocoder API 0.0.1 Beta2
|
||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.0.1-beta2
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.0.1-beta2
|
||||||
|
|
||||||
Nov 27, 2015:
|
Nov 27, 2015:
|
||||||
===========
|
===========
|
||||||
* Release Geocoder API BETA 1
|
* Release Geocoder API BETA 1
|
||||||
* Added the organization public user to the api key check
|
* Added the organization public user to the api key check
|
||||||
|
|
||||||
https://github.com/CartoDB/dataservices-api/releases/tag/0.0.1-beta
|
https://github.com/CartoDB/dataservices-api/releases/tag/0.0.1-beta
|
||||||
|
|||||||
@@ -4,29 +4,31 @@ EXTENSION = cdb_dataservices_client
|
|||||||
EXTVERSION = $(shell grep default_version $(EXTENSION).control | sed -e "s/default_version[[:space:]]*=[[:space:]]*'\([^']*\)'/\1/")
|
EXTVERSION = $(shell grep default_version $(EXTENSION).control | sed -e "s/default_version[[:space:]]*=[[:space:]]*'\([^']*\)'/\1/")
|
||||||
|
|
||||||
# The new version to be generated from templates
|
# The new version to be generated from templates
|
||||||
|
SED = sed
|
||||||
|
ERB = erb
|
||||||
|
REPLACEMENTS = -i 's/$(EXTVERSION)/$(NEW_VERSION)/g'
|
||||||
NEW_EXTENSION_ARTIFACT = $(EXTENSION)--$(EXTVERSION).sql
|
NEW_EXTENSION_ARTIFACT = $(EXTENSION)--$(EXTVERSION).sql
|
||||||
|
|
||||||
|
# OLD_VERSIONS = $(wildcard old_versions/*.sql)
|
||||||
|
# DATA = $(NEW_EXTENSION_ARTIFACT) \
|
||||||
|
# $(OLD_VERSIONS) \
|
||||||
|
# cdb_dataservices_client--0.11.0--0.11.1.sql \
|
||||||
|
# cdb_dataservices_client--0.11.1--0.11.0.sql
|
||||||
OLD_VERSIONS = $(wildcard old_versions/*.sql)
|
OLD_VERSIONS = $(wildcard old_versions/*.sql)
|
||||||
|
DATA = $(NEW_EXTENSION_ARTIFACT) \
|
||||||
|
$(EXTENSION)--*--*.sql \
|
||||||
|
$(OLD_VERSIONS)
|
||||||
|
SOURCES_DATA_DIR = sql/
|
||||||
|
|
||||||
|
|
||||||
|
REGRESS = $(notdir $(basename $(wildcard test/sql/*test.sql)))
|
||||||
|
TEST_DIR = test/
|
||||||
|
REGRESS_OPTS = --inputdir='$(TEST_DIR)' --outputdir='$(TEST_DIR)' --user='postgres'
|
||||||
|
|
||||||
# DATA is a special variable used by postgres build infrastructure
|
# DATA is a special variable used by postgres build infrastructure
|
||||||
# These are the files to be installed in the server shared dir,
|
# These are the files to be installed in the server shared dir,
|
||||||
# for installation from scratch, upgrades and downgrades.
|
# for installation from scratch, upgrades and downgrades.
|
||||||
# @see http://www.postgresql.org/docs/current/static/extend-pgxs.html
|
# @see http://www.postgresql.org/docs/current/static/extend-pgxs.html
|
||||||
DATA = $(NEW_EXTENSION_ARTIFACT) \
|
|
||||||
$(OLD_VERSIONS) \
|
|
||||||
cdb_dataservices_client--0.11.0--0.11.1.sql \
|
|
||||||
cdb_dataservices_client--0.11.1--0.11.0.sql
|
|
||||||
|
|
||||||
|
|
||||||
REGRESS = $(notdir $(basename $(wildcard test/sql/*test.sql)))
|
|
||||||
TEST_DIR = test/
|
|
||||||
REGRESS_OPTS = --inputdir='$(TEST_DIR)' --outputdir='$(TEST_DIR)'
|
|
||||||
|
|
||||||
# postgres build stuff
|
|
||||||
PG_CONFIG = pg_config
|
|
||||||
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
|
||||||
include $(PGXS)
|
|
||||||
|
|
||||||
SOURCES_DATA_DIR = sql/
|
|
||||||
|
|
||||||
# The interface definition is used along with some templates to automatically generate code
|
# The interface definition is used along with some templates to automatically generate code
|
||||||
RENDERER = renderer/sql-template-renderer
|
RENDERER = renderer/sql-template-renderer
|
||||||
@@ -35,6 +37,11 @@ TEMPLATE_DIR = renderer/templates
|
|||||||
TEMPLATE_FILES = $(wildcard $(TEMPLATE_DIR)/*.erb)
|
TEMPLATE_FILES = $(wildcard $(TEMPLATE_DIR)/*.erb)
|
||||||
GENERATED_SQL_FILES = $(patsubst $(TEMPLATE_DIR)/%.erb, $(SOURCES_DATA_DIR)/%.sql, $(TEMPLATE_FILES))
|
GENERATED_SQL_FILES = $(patsubst $(TEMPLATE_DIR)/%.erb, $(SOURCES_DATA_DIR)/%.sql, $(TEMPLATE_FILES))
|
||||||
|
|
||||||
|
# postgres build stuff
|
||||||
|
PG_CONFIG = pg_config
|
||||||
|
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
||||||
|
include $(PGXS)
|
||||||
|
|
||||||
$(GENERATED_SQL_FILES): $(SOURCES_DATA_DIR)/%.sql: $(TEMPLATE_DIR)/%.erb $(INTERFACE_FILE) $(RENDERER)
|
$(GENERATED_SQL_FILES): $(SOURCES_DATA_DIR)/%.sql: $(TEMPLATE_DIR)/%.erb $(INTERFACE_FILE) $(RENDERER)
|
||||||
$(RENDERER) $(INTERFACE_FILE) $< > $@
|
$(RENDERER) $(INTERFACE_FILE) $< > $@
|
||||||
|
|
||||||
@@ -44,9 +51,20 @@ $(NEW_EXTENSION_ARTIFACT): $(SOURCES_DATA)
|
|||||||
rm -f $@
|
rm -f $@
|
||||||
cat $(SOURCES_DATA_DIR)/*.sql >> $@
|
cat $(SOURCES_DATA_DIR)/*.sql >> $@
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
all: $(DATA)
|
all: $(DATA)
|
||||||
|
|
||||||
|
.PHONY: release
|
||||||
|
release: $(EXTENSION).control $(SOURCES_DATA)
|
||||||
|
test -n "$(NEW_VERSION)" # $$NEW_VERSION VARIABLE MISSING. Eg. make release NEW_VERSION=0.x.0
|
||||||
|
mv *.sql old_versions
|
||||||
|
$(SED) $(REPLACEMENTS) $(EXTENSION).control
|
||||||
|
cat $(SOURCES_DATA_DIR)/*.sql > $(EXTENSION)--$(NEW_VERSION).sql
|
||||||
|
$(ERB) version=$(NEW_VERSION) upgrade_downgrade_template.erb > $(EXTENSION)--$(EXTVERSION)--$(NEW_VERSION).sql
|
||||||
|
$(ERB) version=$(EXTVERSION) upgrade_downgrade_template.erb > $(EXTENSION)--$(NEW_VERSION)--$(EXTVERSION).sql
|
||||||
|
|
||||||
# Only meant for development time, do not use once a version is released
|
# Only meant for development time, do not use once a version is released
|
||||||
|
.PHONY: devclean
|
||||||
devclean:
|
devclean:
|
||||||
rm -f $(NEW_EXTENSION_ARTIFACT)
|
rm -f $(NEW_EXTENSION_ARTIFACT)
|
||||||
rm -f $(GENERATED_SQL_FILES)
|
rm -f $(GENERATED_SQL_FILES)
|
||||||
|
|||||||
115
client/cdb_dataservices_client--0.12.1--0.13.0.sql
Normal file
115
client/cdb_dataservices_client--0.12.1--0.13.0.sql
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.13.0'" to load this file. \quit
|
||||||
|
|
||||||
|
-- Added for consistency (SELECT func instead of SELECT * FROM)
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client.obs_dumpversion ()
|
||||||
|
RETURNS text AS $$
|
||||||
|
DECLARE
|
||||||
|
ret text;
|
||||||
|
username text;
|
||||||
|
orgname text;
|
||||||
|
BEGIN
|
||||||
|
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||||
|
RAISE EXCEPTION 'The api_key must be provided';
|
||||||
|
END IF;
|
||||||
|
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||||
|
-- JSON value stored "" is taken as literal
|
||||||
|
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||||
|
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
SELECT cdb_dataservices_client._obs_dumpversion(username, orgname) INTO ret;
|
||||||
|
RETURN ret;
|
||||||
|
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client._obs_dumpversion (username text, organization_name text)
|
||||||
|
RETURNS text AS $$
|
||||||
|
CONNECT cdb_dataservices_client._server_conn_str();
|
||||||
|
|
||||||
|
SELECT cdb_dataservices_server.obs_dumpversion (username, organization_name);
|
||||||
|
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
|
||||||
|
-- For quotas and services configuration
|
||||||
|
CREATE TYPE cdb_dataservices_client.service_type AS ENUM (
|
||||||
|
'isolines',
|
||||||
|
'hires_geocoder',
|
||||||
|
'routing',
|
||||||
|
'observatory'
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TYPE cdb_dataservices_client.service_quota_info AS (
|
||||||
|
service cdb_dataservices_client.service_type,
|
||||||
|
monthly_quota NUMERIC,
|
||||||
|
used_quota NUMERIC,
|
||||||
|
soft_limit BOOLEAN,
|
||||||
|
provider TEXT
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_service_quota_info ()
|
||||||
|
RETURNS SETOF service_quota_info AS $$
|
||||||
|
DECLARE
|
||||||
|
|
||||||
|
username text;
|
||||||
|
orgname text;
|
||||||
|
BEGIN
|
||||||
|
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||||
|
RAISE EXCEPTION 'The api_key must be provided';
|
||||||
|
END IF;
|
||||||
|
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||||
|
-- JSON value stored "" is taken as literal
|
||||||
|
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||||
|
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
RETURN QUERY
|
||||||
|
SELECT * FROM cdb_dataservices_client._cdb_service_quota_info(username, orgname);
|
||||||
|
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client.cdb_enough_quota (service TEXT ,input_size NUMERIC)
|
||||||
|
RETURNS BOOLEAN AS $$
|
||||||
|
DECLARE
|
||||||
|
ret BOOLEAN;
|
||||||
|
username text;
|
||||||
|
orgname text;
|
||||||
|
BEGIN
|
||||||
|
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||||
|
RAISE EXCEPTION 'The api_key must be provided';
|
||||||
|
END IF;
|
||||||
|
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||||
|
-- JSON value stored "" is taken as literal
|
||||||
|
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||||
|
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
SELECT cdb_dataservices_client._cdb_enough_quota(username, orgname, service, input_size) INTO ret;
|
||||||
|
RETURN ret;
|
||||||
|
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_service_quota_info (username text, organization_name text)
|
||||||
|
RETURNS SETOF service_quota_info AS $$
|
||||||
|
CONNECT cdb_dataservices_client._server_conn_str();
|
||||||
|
|
||||||
|
SELECT * FROM cdb_dataservices_server.cdb_service_quota_info (username, organization_name);
|
||||||
|
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client._cdb_enough_quota (username text, organization_name text, service TEXT, input_size NUMERIC)
|
||||||
|
RETURNS BOOLEAN AS $$
|
||||||
|
CONNECT cdb_dataservices_client._server_conn_str();
|
||||||
|
|
||||||
|
SELECT cdb_dataservices_server.cdb_enough_quota (username, organization_name, service, input_size);
|
||||||
|
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
|
||||||
|
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_service_quota_info() TO publicuser;
|
||||||
|
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.cdb_enough_quota(service TEXT, input_size NUMERIC) TO publicuser;
|
||||||
44
client/cdb_dataservices_client--0.13.0--0.12.1.sql
Normal file
44
client/cdb_dataservices_client--0.13.0--0.12.1.sql
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.12.1'" to load this file. \quit
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client.obs_dumpversion ()
|
||||||
|
RETURNS text AS $$
|
||||||
|
DECLARE
|
||||||
|
ret text;
|
||||||
|
username text;
|
||||||
|
orgname text;
|
||||||
|
BEGIN
|
||||||
|
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||||
|
RAISE EXCEPTION 'The api_key must be provided';
|
||||||
|
END IF;
|
||||||
|
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||||
|
-- JSON value stored "" is taken as literal
|
||||||
|
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||||
|
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
SELECT * FROM cdb_dataservices_client._obs_dumpversion(username, orgname) INTO ret;
|
||||||
|
RETURN ret;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client._obs_dumpversion (username text, organization_name text)
|
||||||
|
RETURNS text AS $$
|
||||||
|
CONNECT cdb_dataservices_client._server_conn_str();
|
||||||
|
|
||||||
|
SELECT * FROM cdb_dataservices_server.obs_dumpversion (username, organization_name);
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_enough_quota (username text, organization_name text, service TEXT, input_size NUMERIC);
|
||||||
|
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._cdb_service_quota_info (username text, organization_name text);
|
||||||
|
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client.cdb_enough_quota (service TEXT ,input_size NUMERIC)
|
||||||
|
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client.cdb_service_quota_info ();
|
||||||
|
|
||||||
|
DROP TYPE IF EXISTS cdb_dataservices_client.service_quota_info;
|
||||||
|
|
||||||
|
DROP TYPE IF EXISTS cdb_dataservices_client.service_type;
|
||||||
1986
client/cdb_dataservices_client--0.13.0.sql
Normal file
1986
client/cdb_dataservices_client--0.13.0.sql
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
comment = 'CartoDB dataservices client API extension'
|
comment = 'CartoDB dataservices client API extension'
|
||||||
default_version = '0.11.1'
|
default_version = '0.13.0'
|
||||||
requires = 'plproxy, cartodb'
|
requires = 'plproxy, cartodb'
|
||||||
superuser = true
|
superuser = true
|
||||||
schema = cdb_dataservices_client
|
schema = cdb_dataservices_client
|
||||||
|
|||||||
172
client/old_versions/cdb_dataservices_client--0.11.1--0.12.0.sql
Normal file
172
client/old_versions/cdb_dataservices_client--0.11.1--0.12.0.sql
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.12.0'" to load this file. \quit
|
||||||
|
|
||||||
|
-- HERE goes your code to upgrade/downgrade
|
||||||
|
CREATE TYPE cdb_dataservices_client.obs_meta_numerator AS (numer_id text, numer_name text, numer_description text, numer_weight text, numer_license text, numer_source text, numer_type text, numer_aggregate text, numer_extra jsonb, numer_tags jsonb, valid_denom boolean, valid_geom boolean, valid_timespan boolean);
|
||||||
|
|
||||||
|
CREATE TYPE cdb_dataservices_client.obs_meta_denominator AS (denom_id text, denom_name text, denom_description text, denom_weight text, denom_license text, denom_source text, denom_type text, denom_aggregate text, denom_extra jsonb, denom_tags jsonb, valid_numer boolean, valid_geom boolean, valid_timespan boolean);
|
||||||
|
|
||||||
|
CREATE TYPE cdb_dataservices_client.obs_meta_geometry AS (geom_id text, geom_name text, geom_description text, geom_weight text, geom_aggregate text, geom_license text, geom_source text, valid_numer boolean, valid_denom boolean, valid_timespan boolean);
|
||||||
|
|
||||||
|
CREATE TYPE cdb_dataservices_client.obs_meta_timespan AS (timespan_id text, timespan_name text, timespan_description text, timespan_weight text, timespan_aggregate text, timespan_license text, timespan_source text, valid_numer boolean, valid_denom boolean, valid_geom boolean);
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client.obs_getavailablenumerators (bounds geometry(Geometry, 4326) DEFAULT NULL, filter_tags text[] DEFAULT NULL, denom_id text DEFAULT NULL, geom_id text DEFAULT NULL, timespan text DEFAULT NULL)
|
||||||
|
RETURNS SETOF cdb_dataservices_client.obs_meta_numerator AS $$
|
||||||
|
DECLARE
|
||||||
|
|
||||||
|
username text;
|
||||||
|
orgname text;
|
||||||
|
BEGIN
|
||||||
|
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||||
|
RAISE EXCEPTION 'The api_key must be provided';
|
||||||
|
END IF;
|
||||||
|
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||||
|
-- JSON value stored "" is taken as literal
|
||||||
|
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||||
|
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
RETURN QUERY
|
||||||
|
SELECT * FROM cdb_dataservices_client._obs_getavailablenumerators(username, orgname, bounds, filter_tags, denom_id, geom_id, timespan);
|
||||||
|
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client.obs_getavailabledenominators (bounds geometry(Geometry, 4326) DEFAULT NULL, filter_tags text[] DEFAULT NULL, numer_id text DEFAULT NULL, geom_id text DEFAULT NULL, timespan text DEFAULT NULL)
|
||||||
|
RETURNS SETOF cdb_dataservices_client.obs_meta_denominator AS $$
|
||||||
|
DECLARE
|
||||||
|
|
||||||
|
username text;
|
||||||
|
orgname text;
|
||||||
|
BEGIN
|
||||||
|
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||||
|
RAISE EXCEPTION 'The api_key must be provided';
|
||||||
|
END IF;
|
||||||
|
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||||
|
-- JSON value stored "" is taken as literal
|
||||||
|
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||||
|
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
RETURN QUERY
|
||||||
|
SELECT * FROM cdb_dataservices_client._obs_getavailabledenominators(username, orgname, bounds, filter_tags, numer_id, geom_id, timespan);
|
||||||
|
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client.obs_getavailablegeometries (bounds geometry(Geometry, 4326) DEFAULT NULL, filter_tags text[] DEFAULT NULL, numer_id text DEFAULT NULL, denom_id text DEFAULT NULL, timespan text DEFAULT NULL)
|
||||||
|
RETURNS SETOF cdb_dataservices_client.obs_meta_geometry AS $$
|
||||||
|
DECLARE
|
||||||
|
|
||||||
|
username text;
|
||||||
|
orgname text;
|
||||||
|
BEGIN
|
||||||
|
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||||
|
RAISE EXCEPTION 'The api_key must be provided';
|
||||||
|
END IF;
|
||||||
|
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||||
|
-- JSON value stored "" is taken as literal
|
||||||
|
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||||
|
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
RETURN QUERY
|
||||||
|
SELECT * FROM cdb_dataservices_client._obs_getavailablegeometries(username, orgname, bounds, filter_tags, numer_id, denom_id, timespan);
|
||||||
|
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client.obs_getavailabletimespans (bounds geometry(Geometry, 4326) DEFAULT NULL, filter_tags text[] DEFAULT NULL, numer_id text DEFAULT NULL, denom_id text DEFAULT NULL, geom_id text DEFAULT NULL)
|
||||||
|
RETURNS SETOF cdb_dataservices_client.obs_meta_timespan AS $$
|
||||||
|
DECLARE
|
||||||
|
|
||||||
|
username text;
|
||||||
|
orgname text;
|
||||||
|
BEGIN
|
||||||
|
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||||
|
RAISE EXCEPTION 'The api_key must be provided';
|
||||||
|
END IF;
|
||||||
|
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||||
|
-- JSON value stored "" is taken as literal
|
||||||
|
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||||
|
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
RETURN QUERY
|
||||||
|
SELECT * FROM cdb_dataservices_client._obs_getavailabletimespans(username, orgname, bounds, filter_tags, numer_id, denom_id, geom_id);
|
||||||
|
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client.obs_legacybuildermetadata (aggregate_type text DEFAULT NULL)
|
||||||
|
RETURNS TABLE(name text, subsection json) AS $$
|
||||||
|
DECLARE
|
||||||
|
|
||||||
|
username text;
|
||||||
|
orgname text;
|
||||||
|
BEGIN
|
||||||
|
IF session_user = 'publicuser' OR session_user ~ 'cartodb_publicuser_*' THEN
|
||||||
|
RAISE EXCEPTION 'The api_key must be provided';
|
||||||
|
END IF;
|
||||||
|
SELECT u, o INTO username, orgname FROM cdb_dataservices_client._cdb_entity_config() AS (u text, o text);
|
||||||
|
-- JSON value stored "" is taken as literal
|
||||||
|
IF username IS NULL OR username = '' OR username = '""' THEN
|
||||||
|
RAISE EXCEPTION 'Username is a mandatory argument, check it out';
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
RETURN QUERY
|
||||||
|
SELECT * FROM cdb_dataservices_client._obs_legacybuildermetadata(username, orgname, aggregate_type);
|
||||||
|
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql' SECURITY DEFINER;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client._obs_getavailablenumerators (username text, organization_name text, bounds geometry(Geometry, 4326) DEFAULT NULL, filter_tags text[] DEFAULT NULL, denom_id text DEFAULT NULL, geom_id text DEFAULT NULL, timespan text DEFAULT NULL)
|
||||||
|
RETURNS SETOF cdb_dataservices_client.obs_meta_numerator AS $$
|
||||||
|
CONNECT cdb_dataservices_client._server_conn_str();
|
||||||
|
|
||||||
|
SELECT * FROM cdb_dataservices_server.obs_getavailablenumerators (username, organization_name, bounds, filter_tags, denom_id, geom_id, timespan);
|
||||||
|
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client._obs_getavailabledenominators (username text, organization_name text, bounds geometry(Geometry, 4326) DEFAULT NULL, filter_tags text[] DEFAULT NULL, numer_id text DEFAULT NULL, geom_id text DEFAULT NULL, timespan text DEFAULT NULL)
|
||||||
|
|
||||||
|
RETURNS SETOF cdb_dataservices_client.obs_meta_denominator AS $$
|
||||||
|
CONNECT cdb_dataservices_client._server_conn_str();
|
||||||
|
|
||||||
|
SELECT * FROM cdb_dataservices_server.obs_getavailabledenominators (username, organization_name, bounds, filter_tags, numer_id, geom_id, timespan);
|
||||||
|
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client._obs_getavailablegeometries (username text, organization_name text, bounds geometry(Geometry, 4326) DEFAULT NULL, filter_tags text[] DEFAULT NULL, numer_id text DEFAULT NULL, denom_id text DEFAULT NULL, timespan text DEFAULT NULL)
|
||||||
|
|
||||||
|
RETURNS SETOF cdb_dataservices_client.obs_meta_geometry AS $$
|
||||||
|
CONNECT cdb_dataservices_client._server_conn_str();
|
||||||
|
|
||||||
|
SELECT * FROM cdb_dataservices_server.obs_getavailablegeometries (username, organization_name, bounds, filter_tags, numer_id, denom_id, timespan);
|
||||||
|
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client._obs_getavailabletimespans (username text, organization_name text, bounds geometry(Geometry, 4326) DEFAULT NULL, filter_tags text[] DEFAULT NULL, numer_id text DEFAULT NULL, denom_id text DEFAULT NULL, geom_id text DEFAULT NULL)
|
||||||
|
|
||||||
|
RETURNS SETOF cdb_dataservices_client.obs_meta_timespan AS $$
|
||||||
|
CONNECT cdb_dataservices_client._server_conn_str();
|
||||||
|
|
||||||
|
SELECT * FROM cdb_dataservices_server.obs_getavailabletimespans (username, organization_name, bounds, filter_tags, numer_id, denom_id, geom_id);
|
||||||
|
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_client._obs_legacybuildermetadata (username text, organization_name text, aggregate_type text DEFAULT NULL)
|
||||||
|
|
||||||
|
RETURNS TABLE(name text, subsection json) AS $$
|
||||||
|
CONNECT cdb_dataservices_client._server_conn_str();
|
||||||
|
|
||||||
|
SELECT * FROM cdb_dataservices_server.obs_legacybuildermetadata (username, organization_name, aggregate_type);
|
||||||
|
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.obs_getavailablenumerators(bounds geometry(Geometry, 4326), filter_tags text[], denom_id text, geom_id text, timespan text) TO publicuser;
|
||||||
|
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.obs_getavailabledenominators(bounds geometry(Geometry, 4326), filter_tags text[], numer_id text, geom_id text, timespan text) TO publicuser;
|
||||||
|
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.obs_getavailablegeometries(bounds geometry(Geometry, 4326), filter_tags text[], numer_id text, denom_id text, timespan text) TO publicuser;
|
||||||
|
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.obs_getavailabletimespans(bounds geometry(Geometry, 4326), filter_tags text[], numer_id text, denom_id text, geom_id text) TO publicuser;
|
||||||
|
GRANT EXECUTE ON FUNCTION cdb_dataservices_client.obs_legacybuildermetadata(aggregate_type text) TO publicuser;
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.11.1'" to load this file. \quit
|
||||||
|
|
||||||
|
-- HERE goes your code to upgrade/downgrade
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getavailablenumerators (geometry(Geometry, 4326), text[], text, text, text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getavailabledenominators (geometry(Geometry, 4326), text[], text, text, text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getavailablegeometries (geometry(Geometry, 4326), text[], text, text, text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_getavailabletimespans (geometry(Geometry, 4326), text[], text, text, text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client.obs_legacybuildermetadata(text);
|
||||||
|
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getavailablenumerators (text, text, geometry(Geometry, 4326), text[], text, text, text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getavailabledenominators (text, text, geometry(Geometry, 4326), text[], text, text, text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getavailablegeometries (text, text, geometry(Geometry, 4326), text[], text, text, text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_getavailabletimespans (text, text, geometry(Geometry, 4326), text[], text, text, text);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_client._obs_legacybuildermetadata(text, text, text);
|
||||||
|
|
||||||
|
DROP TYPE IF EXISTS cdb_dataservices_client.obs_meta_numerator;
|
||||||
|
DROP TYPE IF EXISTS cdb_dataservices_client.obs_meta_denominator;
|
||||||
|
DROP TYPE IF EXISTS cdb_dataservices_client.obs_meta_geometry;
|
||||||
|
DROP TYPE IF EXISTS cdb_dataservices_client.obs_meta_timespan;
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.12.1'" to load this file. \quit
|
||||||
|
|
||||||
|
-- HERE goes your code to upgrade/downgrade
|
||||||
|
ALTER TYPE cdb_dataservices_client.obs_meta_geometry ADD ATTRIBUTE score numeric;
|
||||||
|
ALTER TYPE cdb_dataservices_client.obs_meta_geometry ADD ATTRIBUTE numtiles bigint;
|
||||||
|
ALTER TYPE cdb_dataservices_client.obs_meta_geometry ADD ATTRIBUTE notnull_percent numeric;
|
||||||
|
ALTER TYPE cdb_dataservices_client.obs_meta_geometry ADD ATTRIBUTE numgeoms numeric;
|
||||||
|
ALTER TYPE cdb_dataservices_client.obs_meta_geometry ADD ATTRIBUTE percentfill numeric;
|
||||||
|
ALTER TYPE cdb_dataservices_client.obs_meta_geometry ADD ATTRIBUTE estnumgeoms numeric;
|
||||||
|
ALTER TYPE cdb_dataservices_client.obs_meta_geometry ADD ATTRIBUTE meanmediansize numeric;
|
||||||
1987
client/old_versions/cdb_dataservices_client--0.12.0.sql
Normal file
1987
client/old_versions/cdb_dataservices_client--0.12.0.sql
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,12 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '0.12.0'" to load this file. \quit
|
||||||
|
|
||||||
|
-- HERE goes your code to upgrade/downgrade
|
||||||
|
ALTER TYPE cdb_dataservices_client.obs_meta_geometry DROP ATTRIBUTE score;
|
||||||
|
ALTER TYPE cdb_dataservices_client.obs_meta_geometry DROP ATTRIBUTE numtiles;
|
||||||
|
ALTER TYPE cdb_dataservices_client.obs_meta_geometry DROP ATTRIBUTE notnull_percent;
|
||||||
|
ALTER TYPE cdb_dataservices_client.obs_meta_geometry DROP ATTRIBUTE numgeoms;
|
||||||
|
ALTER TYPE cdb_dataservices_client.obs_meta_geometry DROP ATTRIBUTE percentfill;
|
||||||
|
ALTER TYPE cdb_dataservices_client.obs_meta_geometry DROP ATTRIBUTE estnumgeoms;
|
||||||
|
ALTER TYPE cdb_dataservices_client.obs_meta_geometry DROP ATTRIBUTE meanmediansize;
|
||||||
1987
client/old_versions/cdb_dataservices_client--0.12.1.sql
Normal file
1987
client/old_versions/cdb_dataservices_client--0.12.1.sql
Normal file
File diff suppressed because it is too large
Load Diff
@@ -323,6 +323,69 @@
|
|||||||
|
|
||||||
- name: obs_dumpversion
|
- name: obs_dumpversion
|
||||||
return_type: text
|
return_type: text
|
||||||
no_params: true
|
|
||||||
params:
|
params:
|
||||||
- {}
|
- {}
|
||||||
|
|
||||||
|
- name: obs_getavailablenumerators
|
||||||
|
return_type: SETOF cdb_dataservices_client.obs_meta_numerator
|
||||||
|
multi_row: true
|
||||||
|
multi_field: true
|
||||||
|
params:
|
||||||
|
- { name: bounds, type: "geometry(Geometry, 4326)", default: 'NULL' }
|
||||||
|
- { name: filter_tags, type: "text[]", default: 'NULL' }
|
||||||
|
- { name: denom_id, type: text, default: 'NULL' }
|
||||||
|
- { name: geom_id, type: text, default: 'NULL' }
|
||||||
|
- { name: timespan, type: text, default: 'NULL'}
|
||||||
|
|
||||||
|
- name: obs_getavailabledenominators
|
||||||
|
return_type: SETOF cdb_dataservices_client.obs_meta_denominator
|
||||||
|
multi_row: true
|
||||||
|
multi_field: true
|
||||||
|
params:
|
||||||
|
- { name: bounds, type: "geometry(Geometry, 4326)", default: 'NULL' }
|
||||||
|
- { name: filter_tags, type: "text[]", default: 'NULL' }
|
||||||
|
- { name: numer_id, type: text, default: 'NULL' }
|
||||||
|
- { name: geom_id, type: text, default: 'NULL' }
|
||||||
|
- { name: timespan, type: text, default: 'NULL'}
|
||||||
|
|
||||||
|
- name: obs_getavailablegeometries
|
||||||
|
return_type: SETOF cdb_dataservices_client.obs_meta_geometry
|
||||||
|
multi_row: true
|
||||||
|
multi_field: true
|
||||||
|
params:
|
||||||
|
- { name: bounds, type: "geometry(Geometry, 4326)", default: 'NULL' }
|
||||||
|
- { name: filter_tags, type: "text[]", default: 'NULL' }
|
||||||
|
- { name: numer_id, type: text, default: 'NULL' }
|
||||||
|
- { name: denom_id, type: text, default: 'NULL' }
|
||||||
|
- { name: timespan, type: text, default: 'NULL'}
|
||||||
|
|
||||||
|
- name: obs_getavailabletimespans
|
||||||
|
return_type: SETOF cdb_dataservices_client.obs_meta_timespan
|
||||||
|
multi_row: true
|
||||||
|
multi_field: true
|
||||||
|
params:
|
||||||
|
- { name: bounds, type: "geometry(Geometry, 4326)", default: 'NULL' }
|
||||||
|
- { name: filter_tags, type: "text[]", default: 'NULL' }
|
||||||
|
- { name: numer_id, type: text, default: 'NULL' }
|
||||||
|
- { name: denom_id, type: text, default: 'NULL' }
|
||||||
|
- { name: geom_id, type: text, default: 'NULL'}
|
||||||
|
|
||||||
|
- name: obs_legacybuildermetadata
|
||||||
|
return_type: TABLE(name text, subsection json)
|
||||||
|
multi_row: true
|
||||||
|
multi_field: true
|
||||||
|
params:
|
||||||
|
- { name: aggregate_type, type: text, default: 'NULL' }
|
||||||
|
|
||||||
|
- name: cdb_service_quota_info
|
||||||
|
return_type: SETOF service_quota_info
|
||||||
|
multi_row: true
|
||||||
|
multi_field: true
|
||||||
|
params:
|
||||||
|
- {}
|
||||||
|
|
||||||
|
- name: cdb_enough_quota
|
||||||
|
return_type: BOOLEAN
|
||||||
|
params:
|
||||||
|
- { name: service, type: TEXT }
|
||||||
|
- { name: input_size, type: NUMERIC }
|
||||||
@@ -36,10 +36,6 @@ class SqlTemplateRenderer
|
|||||||
@function_signature['multi_row']
|
@function_signature['multi_row']
|
||||||
end
|
end
|
||||||
|
|
||||||
def no_params
|
|
||||||
@function_signature['no_params']
|
|
||||||
end
|
|
||||||
|
|
||||||
def user_config_key
|
def user_config_key
|
||||||
@function_signature['user_config_key']
|
@function_signature['user_config_key']
|
||||||
end
|
end
|
||||||
@@ -49,11 +45,11 @@ class SqlTemplateRenderer
|
|||||||
end
|
end
|
||||||
|
|
||||||
def params
|
def params
|
||||||
@function_signature['params'].reject(&:empty?).map { |p| "#{p['name']}"}.join(', ')
|
@function_signature['params'].reject(&:empty?).map { |p| "#{p['name']}"}
|
||||||
end
|
end
|
||||||
|
|
||||||
def params_with_type
|
def params_with_type
|
||||||
@function_signature['params'].reject(&:empty?).map { |p| "#{p['name']} #{p['type']}" }.join(', ')
|
@function_signature['params'].reject(&:empty?).map { |p| "#{p['name']} #{p['type']}" }
|
||||||
end
|
end
|
||||||
|
|
||||||
def params_with_type_and_default
|
def params_with_type_and_default
|
||||||
@@ -64,7 +60,7 @@ class SqlTemplateRenderer
|
|||||||
"#{p['name']} #{p['type']}"
|
"#{p['name']} #{p['type']}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return parameters.join(', ')
|
return parameters
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
-- These are the only ones with permissions to publicuser role
|
-- These are the only ones with permissions to publicuser role
|
||||||
-- and should also be the only ones with SECURITY DEFINER
|
-- and should also be the only ones with SECURITY DEFINER
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>.<%= name %> (<%= params_with_type_and_default %>)
|
CREATE OR REPLACE FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>.<%= name %> (<%= params_with_type_and_default.join(' ,') %>)
|
||||||
RETURNS <%= return_type %> AS $$
|
RETURNS <%= return_type %> AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
<% if not multi_row %>ret <%= return_type %>;<% end %>
|
<% if not multi_row %>ret <%= return_type %>;<% end %>
|
||||||
@@ -21,15 +21,12 @@ BEGIN
|
|||||||
END IF;
|
END IF;
|
||||||
<% if multi_row %>
|
<% if multi_row %>
|
||||||
RETURN QUERY
|
RETURN QUERY
|
||||||
SELECT * FROM <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>(username, orgname, <%= params %>);
|
SELECT * FROM <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>(<%= ['username', 'orgname'].concat(params).join(', ') %>);
|
||||||
<% elsif multi_field %>
|
<% elsif multi_field %>
|
||||||
SELECT * FROM <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>(username, orgname, <%= params %>) INTO ret;
|
SELECT * FROM <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>(<%= ['username', 'orgname'].concat(params).join(', ') %>) INTO ret;
|
||||||
RETURN ret;
|
|
||||||
<% elsif no_params %>
|
|
||||||
SELECT * FROM <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>(username, orgname) INTO ret;
|
|
||||||
RETURN ret;
|
RETURN ret;
|
||||||
<% else %>
|
<% else %>
|
||||||
SELECT <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>(username, orgname, <%= params %>) INTO ret;
|
SELECT <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %>(<%= ['username', 'orgname'].concat(params).join(', ') %>) INTO ret;
|
||||||
RETURN ret;
|
RETURN ret;
|
||||||
<% end %>
|
<% end %>
|
||||||
END;
|
END;
|
||||||
|
|||||||
@@ -1,15 +1,9 @@
|
|||||||
<% if no_params %>
|
CREATE OR REPLACE FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %> (<%= ['username text', 'organization_name text'].concat(params_with_type_and_default).join(', ') %>)
|
||||||
CREATE OR REPLACE FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %> (username text, organization_name text)
|
|
||||||
<% else %>
|
|
||||||
CREATE OR REPLACE FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>._<%= name %> (username text, organization_name text, <%= params_with_type_and_default %>)
|
|
||||||
<% end %>
|
|
||||||
RETURNS <%= return_type %> AS $$
|
RETURNS <%= return_type %> AS $$
|
||||||
CONNECT <%= DATASERVICES_CLIENT_SCHEMA %>._server_conn_str();
|
CONNECT <%= DATASERVICES_CLIENT_SCHEMA %>._server_conn_str();
|
||||||
<% if multi_field %>
|
<% if multi_field %>
|
||||||
SELECT * FROM <%= DATASERVICES_SERVER_SCHEMA %>.<%= name %> (username, organization_name, <%= params %>);
|
SELECT * FROM <%= DATASERVICES_SERVER_SCHEMA %>.<%= name %> (<%= ['username', 'organization_name'].concat(params).join(', ') %>);
|
||||||
<% elsif no_params %>
|
|
||||||
SELECT * FROM <%= DATASERVICES_SERVER_SCHEMA %>.<%= name %> (username, organization_name);
|
|
||||||
<% else %>
|
<% else %>
|
||||||
SELECT <%= DATASERVICES_SERVER_SCHEMA %>.<%= name %> (username, organization_name, <%= params %>);
|
SELECT <%= DATASERVICES_SERVER_SCHEMA %>.<%= name %> (<%= ['username', 'organization_name'].concat(params).join(', ') %>);
|
||||||
<% end %>
|
<% end %>
|
||||||
$$ LANGUAGE plproxy;
|
$$ LANGUAGE plproxy;
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
GRANT EXECUTE ON FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>.<%= name %>(<%= params_with_type %>) TO publicuser;
|
GRANT EXECUTE ON FUNCTION <%= DATASERVICES_CLIENT_SCHEMA %>.<%= name %>(<%= params_with_type.join(', ') %>) TO publicuser;
|
||||||
|
|||||||
@@ -8,4 +8,30 @@ CREATE TYPE cdb_dataservices_client.simple_route AS (
|
|||||||
shape geometry(LineString,4326),
|
shape geometry(LineString,4326),
|
||||||
length real,
|
length real,
|
||||||
duration integer
|
duration integer
|
||||||
);
|
);
|
||||||
|
|
||||||
|
-- For the OBS_Meta functions
|
||||||
|
CREATE TYPE cdb_dataservices_client.obs_meta_numerator AS (numer_id text, numer_name text, numer_description text, numer_weight text, numer_license text, numer_source text, numer_type text, numer_aggregate text, numer_extra jsonb, numer_tags jsonb, valid_denom boolean, valid_geom boolean, valid_timespan boolean);
|
||||||
|
|
||||||
|
CREATE TYPE cdb_dataservices_client.obs_meta_denominator AS (denom_id text, denom_name text, denom_description text, denom_weight text, denom_license text, denom_source text, denom_type text, denom_aggregate text, denom_extra jsonb, denom_tags jsonb, valid_numer boolean, valid_geom boolean, valid_timespan boolean);
|
||||||
|
|
||||||
|
CREATE TYPE cdb_dataservices_client.obs_meta_geometry AS (geom_id text, geom_name text, geom_description text, geom_weight text, geom_aggregate text, geom_license text, geom_source text, valid_numer boolean, valid_denom boolean, valid_timespan boolean, score numeric, numtiles bigint, notnull_percent numeric, numgeoms numeric, percentfill numeric, estnumgeoms numeric, meanmediansize numeric);
|
||||||
|
|
||||||
|
CREATE TYPE cdb_dataservices_client.obs_meta_timespan AS (timespan_id text, timespan_name text, timespan_description text, timespan_weight text, timespan_aggregate text, timespan_license text, timespan_source text, valid_numer boolean, valid_denom boolean, valid_geom boolean);
|
||||||
|
|
||||||
|
|
||||||
|
-- For quotas and services configuration
|
||||||
|
CREATE TYPE cdb_dataservices_client.service_type AS ENUM (
|
||||||
|
'isolines',
|
||||||
|
'hires_geocoder',
|
||||||
|
'routing',
|
||||||
|
'observatory'
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TYPE cdb_dataservices_client.service_quota_info AS (
|
||||||
|
service cdb_dataservices_client.service_type,
|
||||||
|
monthly_quota NUMERIC,
|
||||||
|
used_quota NUMERIC,
|
||||||
|
soft_limit BOOLEAN,
|
||||||
|
provider TEXT
|
||||||
|
);
|
||||||
|
|||||||
5
client/upgrade_downgrade_template.erb
Normal file
5
client/upgrade_downgrade_template.erb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_client UPDATE TO '<%= version %>'" to load this file. \quit
|
||||||
|
|
||||||
|
-- HERE goes your code to upgrade/downgrade
|
||||||
@@ -215,7 +215,7 @@ INSERT INTO {tablename} (the_geom) SELECT cdb_geocode_namedplace_point('New York
|
|||||||
|
|
||||||
## Postal Code Geocoder
|
## Postal Code Geocoder
|
||||||
|
|
||||||
This function geocodes your data into point, or polygon, geometries for postal codes. The postal code polygon geocoder covers the United States, France, Australia and Canada; a request for a different country will return an empty response.
|
These functions geocode your data into point, or polygon, geometries for postal codes. The postal code geocoder covers the United States, France, Australia and Canada; a request for a different country will return an empty response.
|
||||||
|
|
||||||
**Note:** For the USA, US Census [Zip Code Tabulation Areas](https://www.census.gov/geo/reference/zctas.html) (ZCTA) are used to reference geocodes for USPS postal codes service areas. See the [FAQs](https://carto.com/docs/faqs/datasets-and-data/#why-does-carto-use-census-bureau-zctas-and-not-usps-zip-codes-for-postal-codes) about datasets and data for details.
|
**Note:** For the USA, US Census [Zip Code Tabulation Areas](https://www.census.gov/geo/reference/zctas.html) (ZCTA) are used to reference geocodes for USPS postal codes service areas. See the [FAQs](https://carto.com/docs/faqs/datasets-and-data/#why-does-carto-use-census-bureau-zctas-and-not-usps-zip-codes-for-postal-codes) about datasets and data for details.
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ _The Data Services API is collaborating with [Mapzen](https://mapzen.com/), and
|
|||||||
|
|
||||||
By using the SQL API to query the Data Services API functions, you can manage specific operations and the corresponding geometries (a `polygon` or a `point`), according to the input information.
|
By using the SQL API to query the Data Services API functions, you can manage specific operations and the corresponding geometries (a `polygon` or a `point`), according to the input information.
|
||||||
|
|
||||||
The Data Services API decouples the geocoding and isoline services from the CARTO Editor. The API allows you to geocode data (from single rows, complete datasets, or simple inputs) and to perform trade areas analysis (computing isodistances or isochrones) programatically, through authenticated requests.
|
The Data Services API also exposes its services directly through CARTO Builder. For example, you can geocode data (from single rows, complete datasets, or simple inputs) and perform trade areas analysis (computing isodistances or isochrones) programatically, through authenticated SQL requests, or by using the ANALYSIS options.
|
||||||
|
|
||||||
The geometries provided by this API are projected in the projection [WGS 84 SRID 4326](http://spatialreference.org/ref/epsg/wgs-84/).
|
The geometries provided by this API are projected in the projection [WGS 84 SRID 4326](http://spatialreference.org/ref/epsg/wgs-84/).
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ Name | Type | Description | Accepted values
|
|||||||
--- | --- | --- | ---
|
--- | --- | --- | ---
|
||||||
`origin` | `geometry(Point)` | Origin point, in 4326 projection, which defines the start location. |
|
`origin` | `geometry(Point)` | Origin point, in 4326 projection, which defines the start location. |
|
||||||
`destination` | `geometry(Point)` | Destination point, in 4326 projection, which defines the end location. |
|
`destination` | `geometry(Point)` | Destination point, in 4326 projection, which defines the end location. |
|
||||||
`mode` | `text` | Type of transport used to calculate the isolines. | `car`, `walk`, `bicycle` or `public_transport`
|
`mode` | `text` | Type of transport used to calculate the routes. | `car`, `walk`, `bicycle` or `public_transport`
|
||||||
`options` | `text[]` | (Optional) Multiple options to add more capabilities to the analysis. See [Optional routing parameters](#optional-routing-parameters) for details.
|
`options` | `text[]` | (Optional) Multiple options to add more capabilities to the analysis. See [Optional routing parameters](#optional-routing-parameters) for details.
|
||||||
`units` | `text` | Unit used to represent the length of the route. | `kilometers`, `miles`. By default is `kilometers`
|
`units` | `text` | Unit used to represent the length of the route. | `kilometers`, `miles`. By default is `kilometers`
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ Returns a route that goes from origin to destination and whose path travels thro
|
|||||||
Name | Type | Description | Accepted values
|
Name | Type | Description | Accepted values
|
||||||
--- | --- | --- | ---
|
--- | --- | --- | ---
|
||||||
`waypoints` | `geometry(Point)[]` | Array of ordered points, in 4326 projection, which defines the origin point, one or more locations for the route path to travel through, and the destination. The first element of the array defines the origin and the last element the destination of the route. |
|
`waypoints` | `geometry(Point)[]` | Array of ordered points, in 4326 projection, which defines the origin point, one or more locations for the route path to travel through, and the destination. The first element of the array defines the origin and the last element the destination of the route. |
|
||||||
`mode` | `text` | Type of transport used to calculate the isolines. | `car`, `walk`, `bicycle` or `public_transport`
|
`mode` | `text` | Type of transport used to calculate the routes. | `car`, `walk`, `bicycle` or `public_transport`
|
||||||
`options` | `text[]` | (Optional) Multiple options to add more capabilities to the analysis. See [Optional routing parameters](#optional-routing-parameters) for details.
|
`options` | `text[]` | (Optional) Multiple options to add more capabilities to the analysis. See [Optional routing parameters](#optional-routing-parameters) for details.
|
||||||
`units` | `text` | Unit used to represent the length of the route. | `kilometers`, `miles`. By default is `kilometers`
|
`units` | `text` | Unit used to represent the length of the route. | `kilometers`, `miles`. By default is `kilometers`
|
||||||
|
|
||||||
|
|||||||
109
server/extension/cdb_dataservices_server--0.18.1--0.19.0.sql
Normal file
109
server/extension/cdb_dataservices_server--0.18.1--0.19.0.sql
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_server UPDATE TO '0.19.0'" to load this file. \quit
|
||||||
|
|
||||||
|
DO $$
|
||||||
|
BEGIN
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'service_type') THEN
|
||||||
|
CREATE TYPE cdb_dataservices_server.service_type AS ENUM (
|
||||||
|
'isolines',
|
||||||
|
'hires_geocoder',
|
||||||
|
'routing',
|
||||||
|
'observatory'
|
||||||
|
);
|
||||||
|
END IF;
|
||||||
|
END $$;
|
||||||
|
|
||||||
|
DO $$
|
||||||
|
BEGIN
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'service_quota_info') THEN
|
||||||
|
CREATE TYPE cdb_dataservices_server.service_quota_info AS (
|
||||||
|
service cdb_dataservices_server.service_type,
|
||||||
|
monthly_quota NUMERIC,
|
||||||
|
used_quota NUMERIC,
|
||||||
|
soft_limit BOOLEAN,
|
||||||
|
provider TEXT
|
||||||
|
);
|
||||||
|
END IF;
|
||||||
|
END $$;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_service_quota_info(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT)
|
||||||
|
RETURNS SETOF cdb_dataservices_server.service_quota_info AS $$
|
||||||
|
from cartodb_services.metrics.user import UserMetricsService
|
||||||
|
from datetime import date
|
||||||
|
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
|
|
||||||
|
today = date.today()
|
||||||
|
ret = []
|
||||||
|
|
||||||
|
#-- Isolines
|
||||||
|
service = 'isolines'
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_isolines_routing_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
|
user_isolines_config = GD["user_isolines_routing_config_{0}".format(username)]
|
||||||
|
user_service = UserMetricsService(user_isolines_config, redis_conn)
|
||||||
|
|
||||||
|
monthly_quota = user_isolines_config.isolines_quota
|
||||||
|
used_quota = user_service.used_quota(user_isolines_config.service_type, today)
|
||||||
|
soft_limit = user_isolines_config.soft_isolines_limit
|
||||||
|
provider = user_isolines_config.provider
|
||||||
|
ret += [[service, monthly_quota, used_quota, soft_limit, provider]]
|
||||||
|
|
||||||
|
#-- Hires Geocoder
|
||||||
|
service = 'hires_geocoder'
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
|
user_geocoder_config = GD["user_geocoder_config_{0}".format(username)]
|
||||||
|
user_service = UserMetricsService(user_geocoder_config, redis_conn)
|
||||||
|
|
||||||
|
monthly_quota = user_geocoder_config.geocoding_quota
|
||||||
|
used_quota = user_service.used_quota(user_geocoder_config.service_type, today)
|
||||||
|
soft_limit = user_geocoder_config.soft_geocoding_limit
|
||||||
|
provider = user_geocoder_config.provider
|
||||||
|
ret += [[service, monthly_quota, used_quota, soft_limit, provider]]
|
||||||
|
|
||||||
|
#-- Routing
|
||||||
|
service = 'routing'
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_routing_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
|
user_routing_config = GD["user_routing_config_{0}".format(username)]
|
||||||
|
user_service = UserMetricsService(user_routing_config, redis_conn)
|
||||||
|
|
||||||
|
monthly_quota = user_routing_config.monthly_quota
|
||||||
|
used_quota = user_service.used_quota(user_routing_config.service_type, today)
|
||||||
|
soft_limit = user_routing_config.soft_limit
|
||||||
|
provider = user_routing_config.provider
|
||||||
|
ret += [[service, monthly_quota, used_quota, soft_limit, provider]]
|
||||||
|
|
||||||
|
#-- Observatory
|
||||||
|
service = 'observatory'
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_obs_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
|
user_obs_config = GD["user_obs_config_{0}".format(username)]
|
||||||
|
user_service = UserMetricsService(user_obs_config, redis_conn)
|
||||||
|
|
||||||
|
monthly_quota = user_obs_config.monthly_quota
|
||||||
|
used_quota = user_service.used_quota(user_obs_config.service_type, today)
|
||||||
|
soft_limit = user_obs_config.soft_limit
|
||||||
|
provider = user_obs_config.provider
|
||||||
|
ret += [[service, monthly_quota, used_quota, soft_limit, provider]]
|
||||||
|
|
||||||
|
return ret
|
||||||
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_enough_quota(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
service_ TEXT,
|
||||||
|
input_size NUMERIC)
|
||||||
|
returns BOOLEAN AS $$
|
||||||
|
DECLARE
|
||||||
|
params cdb_dataservices_server.service_quota_info;
|
||||||
|
BEGIN
|
||||||
|
SELECT * INTO params
|
||||||
|
FROM cdb_dataservices_server.cdb_service_quota_info(username, orgname) AS p
|
||||||
|
WHERE p.service = service_::cdb_dataservices_server.service_type;
|
||||||
|
RETURN params.soft_limit OR ((params.used_quota + input_size) <= params.monthly_quota);
|
||||||
|
END
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
17
server/extension/cdb_dataservices_server--0.19.0--0.18.1.sql
Normal file
17
server/extension/cdb_dataservices_server--0.19.0--0.18.1.sql
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_server UPDATE TO '0.18.1'" to load this file. \quit
|
||||||
|
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_server.cdb_enough_quota(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
service_ TEXT,
|
||||||
|
input_size NUMERIC);
|
||||||
|
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_server.cdb_service_quota_info(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT);
|
||||||
|
|
||||||
|
DROP TYPE IF EXISTS cdb_dataservices_server.service_quota_info;
|
||||||
|
|
||||||
|
DROP TYPE IF EXISTS cdb_dataservices_server.service_type;
|
||||||
2669
server/extension/cdb_dataservices_server--0.19.0.sql
Normal file
2669
server/extension/cdb_dataservices_server--0.19.0.sql
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
comment = 'CartoDB dataservices server extension'
|
comment = 'CartoDB dataservices server extension'
|
||||||
default_version = '0.16.0'
|
default_version = '0.19.0'
|
||||||
requires = 'plpythonu, plproxy, postgis, cdb_geocoder'
|
requires = 'plpythonu, plproxy, postgis, cdb_geocoder'
|
||||||
superuser = true
|
superuser = true
|
||||||
schema = cdb_dataservices_server
|
schema = cdb_dataservices_server
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,73 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_server UPDATE TO '0.18.0'" to load this file. \quit
|
||||||
|
|
||||||
|
-- HERE goes your code to upgrade/downgrade
|
||||||
|
CREATE TYPE cdb_dataservices_server.obs_meta_numerator AS (numer_id text, numer_name text, numer_description text, numer_weight text, numer_license text, numer_source text, numer_type text, numer_aggregate text, numer_extra jsonb, numer_tags jsonb, valid_denom boolean, valid_geom boolean, valid_timespan boolean);
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetAvailableNumerators(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
bounds geometry(Geometry, 4326) DEFAULT NULL,
|
||||||
|
filter_tags TEXT[] DEFAULT NULL,
|
||||||
|
denom_id TEXT DEFAULT NULL,
|
||||||
|
geom_id TEXT DEFAULT NULL,
|
||||||
|
timespan TEXT DEFAULT NULL)
|
||||||
|
RETURNS SETOF cdb_dataservices_server.obs_meta_numerator AS $$
|
||||||
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||||
|
SELECT * FROM cdb_observatory.OBS_GetAvailableNumerators(bounds, filter_tags, denom_id, geom_id, timespan);
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
CREATE TYPE cdb_dataservices_server.obs_meta_denominator AS (denom_id text, denom_name text, denom_description text, denom_weight text, denom_license text, denom_source text, denom_type text, denom_aggregate text, denom_extra jsonb, denom_tags jsonb, valid_numer boolean, valid_geom boolean, valid_timespan boolean);
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetAvailableDenominators(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
bounds geometry(Geometry, 4326) DEFAULT NULL,
|
||||||
|
filter_tags TEXT[] DEFAULT NULL,
|
||||||
|
numer_id TEXT DEFAULT NULL,
|
||||||
|
geom_id TEXT DEFAULT NULL,
|
||||||
|
timespan TEXT DEFAULT NULL)
|
||||||
|
RETURNS SETOF cdb_dataservices_server.obs_meta_denominator AS $$
|
||||||
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||||
|
SELECT * FROM cdb_observatory.OBS_GetAvailableDenominators(bounds, filter_tags, numer_id, geom_id, timespan);
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
CREATE TYPE cdb_dataservices_server.obs_meta_geometry AS (geom_id text, geom_name text, geom_description text, geom_weight text, geom_aggregate text, geom_license text, geom_source text, valid_numer boolean, valid_denom boolean, valid_timespan boolean);
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetAvailableGeometries(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
bounds geometry(Geometry, 4326) DEFAULT NULL,
|
||||||
|
filter_tags TEXT[] DEFAULT NULL,
|
||||||
|
numer_id TEXT DEFAULT NULL,
|
||||||
|
denom_id TEXT DEFAULT NULL,
|
||||||
|
timespan TEXT DEFAULT NULL)
|
||||||
|
RETURNS SETOF cdb_dataservices_server.obs_meta_geometry AS $$
|
||||||
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||||
|
SELECT * FROM cdb_observatory.OBS_GetAvailableGeometries(bounds, filter_tags, numer_id, denom_id, timespan);
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
CREATE TYPE cdb_dataservices_server.obs_meta_timespan AS (timespan_id text, timespan_name text, timespan_description text, timespan_weight text, timespan_aggregate text, timespan_license text, timespan_source text, valid_numer boolean, valid_denom boolean, valid_geom boolean);
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetAvailableTimespans(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
bounds geometry(Geometry, 4326) DEFAULT NULL,
|
||||||
|
filter_tags TEXT[] DEFAULT NULL,
|
||||||
|
numer_id TEXT DEFAULT NULL,
|
||||||
|
denom_id TEXT DEFAULT NULL,
|
||||||
|
geom_id TEXT DEFAULT NULL)
|
||||||
|
RETURNS SETOF cdb_dataservices_server.obs_meta_timespan AS $$
|
||||||
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||||
|
SELECT * FROM cdb_observatory.OBS_GetAvailableTimespans(bounds, filter_tags, numer_id, denom_id, geom_id);
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_LegacyBuilderMetadata(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
aggregate_type TEXT DEFAULT NULL)
|
||||||
|
RETURNS TABLE(name TEXT, subsection JSON) AS $$
|
||||||
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||||
|
SELECT * FROM cdb_observatory.OBS_LegacyBuilderMetadata(aggregate_type);
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
2492
server/extension/old_versions/cdb_dataservices_server--0.17.0.sql
Normal file
2492
server/extension/old_versions/cdb_dataservices_server--0.17.0.sql
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,15 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_server UPDATE TO '0.17.0'" to load this file. \quit
|
||||||
|
|
||||||
|
-- HERE goes your code to upgrade/downgrade
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_server.obs_getavailablenumerators(TEXT, TEXT, geometry(Geometry, 4326), TEXT[], TEXT, TEXT, TEXT);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_server.obs_getavailabledenominators(TEXT, TEXT, geometry(Geometry, 4326), TEXT[], TEXT, TEXT, TEXT);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_server.obs_getavailablegeometries(TEXT, TEXT, geometry(Geometry, 4326), TEXT[], TEXT, TEXT, TEXT);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_server.obs_getavailabletimespans(TEXT, TEXT, geometry(Geometry, 4326), TEXT[], TEXT, TEXT, TEXT);
|
||||||
|
DROP FUNCTION IF EXISTS cdb_dataservices_server.obs_legacybuildermetadata(TEXT, TEXT, TEXT);
|
||||||
|
|
||||||
|
DROP TYPE IF EXISTS cdb_dataservices_server.obs_meta_numerator;
|
||||||
|
DROP TYPE IF EXISTS cdb_dataservices_server.obs_meta_denominator;
|
||||||
|
DROP TYPE IF EXISTS cdb_dataservices_server.obs_meta_geometry;
|
||||||
|
DROP TYPE IF EXISTS cdb_dataservices_server.obs_meta_timespan;
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_server UPDATE TO '0.18.1'" to load this file. \quit
|
||||||
|
|
||||||
|
-- HERE goes your code to upgrade/downgrade
|
||||||
|
ALTER TYPE cdb_dataservices_server.obs_meta_geometry ADD ATTRIBUTE score numeric;
|
||||||
|
ALTER TYPE cdb_dataservices_server.obs_meta_geometry ADD ATTRIBUTE numtiles bigint;
|
||||||
|
ALTER TYPE cdb_dataservices_server.obs_meta_geometry ADD ATTRIBUTE notnull_percent numeric;
|
||||||
|
ALTER TYPE cdb_dataservices_server.obs_meta_geometry ADD ATTRIBUTE numgeoms numeric;
|
||||||
|
ALTER TYPE cdb_dataservices_server.obs_meta_geometry ADD ATTRIBUTE percentfill numeric;
|
||||||
|
ALTER TYPE cdb_dataservices_server.obs_meta_geometry ADD ATTRIBUTE estnumgeoms numeric;
|
||||||
|
ALTER TYPE cdb_dataservices_server.obs_meta_geometry ADD ATTRIBUTE meanmediansize numeric;
|
||||||
2564
server/extension/old_versions/cdb_dataservices_server--0.18.0.sql
Normal file
2564
server/extension/old_versions/cdb_dataservices_server--0.18.0.sql
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,12 @@
|
|||||||
|
--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES
|
||||||
|
-- Complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||||
|
\echo Use "ALTER EXTENSION cdb_dataservices_server UPDATE TO '0.18.0'" to load this file. \quit
|
||||||
|
|
||||||
|
-- HERE goes your code to upgrade/downgrade
|
||||||
|
ALTER TYPE cdb_dataservices_server.obs_meta_geometry DROP ATTRIBUTE score;
|
||||||
|
ALTER TYPE cdb_dataservices_server.obs_meta_geometry DROP ATTRIBUTE numtiles;
|
||||||
|
ALTER TYPE cdb_dataservices_server.obs_meta_geometry DROP ATTRIBUTE notnull_percent;
|
||||||
|
ALTER TYPE cdb_dataservices_server.obs_meta_geometry DROP ATTRIBUTE numgeoms;
|
||||||
|
ALTER TYPE cdb_dataservices_server.obs_meta_geometry DROP ATTRIBUTE percentfill;
|
||||||
|
ALTER TYPE cdb_dataservices_server.obs_meta_geometry DROP ATTRIBUTE estnumgeoms;
|
||||||
|
ALTER TYPE cdb_dataservices_server.obs_meta_geometry DROP ATTRIBUTE meanmediansize;
|
||||||
2564
server/extension/old_versions/cdb_dataservices_server--0.18.1.sql
Normal file
2564
server/extension/old_versions/cdb_dataservices_server--0.18.1.sql
Normal file
File diff suppressed because it is too large
Load Diff
@@ -7,15 +7,21 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_route_point_to_point(
|
|||||||
options text[] DEFAULT ARRAY[]::text[],
|
options text[] DEFAULT ARRAY[]::text[],
|
||||||
units text DEFAULT 'kilometers')
|
units text DEFAULT 'kilometers')
|
||||||
RETURNS cdb_dataservices_server.simple_route AS $$
|
RETURNS cdb_dataservices_server.simple_route AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
|
from cartodb_services.tools import Logger
|
||||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
plpy.execute("SELECT cdb_dataservices_server._get_routing_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
plpy.execute("SELECT cdb_dataservices_server._get_routing_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
user_routing_config = GD["user_routing_config_{0}".format(username)]
|
user_routing_config = GD["user_routing_config_{0}".format(username)]
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
|
logger_config = GD["logger_config"]
|
||||||
|
logger = Logger(logger_config)
|
||||||
|
|
||||||
waypoints = [origin, destination]
|
with metrics('cdb_route_with_point', user_routing_config, logger):
|
||||||
mapzen_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapzen_route_with_waypoints($1, $2, $3, $4, $5, $6) as route;", ["text", "text", "geometry(Point, 4326)[]", "text", "text[]", "text"])
|
waypoints = [origin, destination]
|
||||||
result = plpy.execute(mapzen_plan, [username, orgname, waypoints, mode, options, units])
|
mapzen_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapzen_route_with_waypoints($1, $2, $3, $4, $5, $6) as route;", ["text", "text", "geometry(Point, 4326)[]", "text", "text[]", "text"])
|
||||||
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
result = plpy.execute(mapzen_plan, [username, orgname, waypoints, mode, options, units])
|
||||||
|
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
|
|
||||||
@@ -27,12 +33,18 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_route_with_waypoints(
|
|||||||
options text[] DEFAULT ARRAY[]::text[],
|
options text[] DEFAULT ARRAY[]::text[],
|
||||||
units text DEFAULT 'kilometers')
|
units text DEFAULT 'kilometers')
|
||||||
RETURNS cdb_dataservices_server.simple_route AS $$
|
RETURNS cdb_dataservices_server.simple_route AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
|
from cartodb_services.tools import Logger
|
||||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
plpy.execute("SELECT cdb_dataservices_server._get_routing_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
plpy.execute("SELECT cdb_dataservices_server._get_routing_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
user_routing_config = GD["user_routing_config_{0}".format(username)]
|
user_routing_config = GD["user_routing_config_{0}".format(username)]
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
|
logger_config = GD["logger_config"]
|
||||||
|
logger = Logger(logger_config)
|
||||||
|
|
||||||
mapzen_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapzen_route_with_waypoints($1, $2, $3, $4, $5, $6) as route;", ["text", "text", "geometry(Point, 4326)[]", "text", "text[]", "text"])
|
with metrics('cdb_route_with_waypoints', user_routing_config, logger):
|
||||||
result = plpy.execute(mapzen_plan, [username, orgname, waypoints, mode, options, units])
|
mapzen_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapzen_route_with_waypoints($1, $2, $3, $4, $5, $6) as route;", ["text", "text", "geometry(Point, 4326)[]", "text", "text[]", "text"])
|
||||||
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
result = plpy.execute(mapzen_plan, [username, orgname, waypoints, mode, options, units])
|
||||||
|
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ RETURNS text AS $$
|
|||||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
plpy.execute("SELECT cdb_dataservices_server._get_obs_snapshot_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
plpy.execute("SELECT cdb_dataservices_server._get_obs_snapshot_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
user_obs_snapshot_config = GD["user_obs_snapshot_config_{0}".format(username)]
|
user_obs_config = GD["user_obs_snapshot_config_{0}".format(username)]
|
||||||
|
|
||||||
return user_obs_snapshot_config.connection_str
|
return user_obs_config.connection_str
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetDemographicSnapshotJSON(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetDemographicSnapshotJSON(
|
||||||
@@ -34,6 +34,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_get_demographic_snapshot(
|
|||||||
time_span TEXT DEFAULT NULL,
|
time_span TEXT DEFAULT NULL,
|
||||||
geometry_level TEXT DEFAULT NULL)
|
geometry_level TEXT DEFAULT NULL)
|
||||||
RETURNS json AS $$
|
RETURNS json AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
import json
|
import json
|
||||||
@@ -41,31 +42,32 @@ RETURNS json AS $$
|
|||||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
plpy.execute("SELECT cdb_dataservices_server._get_obs_snapshot_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
plpy.execute("SELECT cdb_dataservices_server._get_obs_snapshot_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
user_obs_snapshot_config = GD["user_obs_snapshot_config_{0}".format(username)]
|
user_obs_config = GD["user_obs_snapshot_config_{0}".format(username)]
|
||||||
|
|
||||||
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
logger_config = GD["logger_config"]
|
logger_config = GD["logger_config"]
|
||||||
logger = Logger(logger_config)
|
logger = Logger(logger_config)
|
||||||
quota_service = QuotaService(user_obs_snapshot_config, redis_conn)
|
quota_service = QuotaService(user_obs_config, redis_conn)
|
||||||
if not quota_service.check_user_quota():
|
if not quota_service.check_user_quota():
|
||||||
raise Exception('You have reached the limit of your quota')
|
raise Exception('You have reached the limit of your quota')
|
||||||
|
|
||||||
try:
|
with metrics('obs_getdemographicsnapshot', user_obs_config, logger):
|
||||||
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetDemographicSnapshotJSON($1, $2, $3, $4, $5) as snapshot;", ["text", "text", "geometry(Geometry, 4326)", "text", "text"])
|
try:
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geom, time_span, geometry_level])
|
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetDemographicSnapshotJSON($1, $2, $3, $4, $5) as snapshot;", ["text", "text", "geometry(Geometry, 4326)", "text", "text"])
|
||||||
if result:
|
result = plpy.execute(obs_plan, [username, orgname, geom, time_span, geometry_level])
|
||||||
quota_service.increment_success_service_use()
|
if result:
|
||||||
return result[0]['snapshot']
|
quota_service.increment_success_service_use()
|
||||||
else:
|
return result[0]['snapshot']
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return None
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return None
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to obs_get_demographic_snapshot', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to obs_get_demographic_snapshot')
|
logger.error('Error trying to obs_get_demographic_snapshot', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to obs_get_demographic_snapshot')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetDemographicSnapshot(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetDemographicSnapshot(
|
||||||
@@ -86,41 +88,43 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetDemographicSnapshot(
|
|||||||
time_span TEXT DEFAULT NULL,
|
time_span TEXT DEFAULT NULL,
|
||||||
geometry_level TEXT DEFAULT NULL)
|
geometry_level TEXT DEFAULT NULL)
|
||||||
RETURNS SETOF JSON AS $$
|
RETURNS SETOF JSON AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
plpy.execute("SELECT cdb_dataservices_server._get_obs_snapshot_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
plpy.execute("SELECT cdb_dataservices_server._get_obs_snapshot_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
user_obs_snapshot_config = GD["user_obs_snapshot_config_{0}".format(username)]
|
user_obs_config = GD["user_obs_snapshot_config_{0}".format(username)]
|
||||||
|
|
||||||
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
logger_config = GD["logger_config"]
|
logger_config = GD["logger_config"]
|
||||||
logger = Logger(logger_config)
|
logger = Logger(logger_config)
|
||||||
quota_service = QuotaService(user_obs_snapshot_config, redis_conn)
|
quota_service = QuotaService(user_obs_config, redis_conn)
|
||||||
if not quota_service.check_user_quota():
|
if not quota_service.check_user_quota():
|
||||||
raise Exception('You have reached the limit of your quota')
|
raise Exception('You have reached the limit of your quota')
|
||||||
|
|
||||||
try:
|
with metrics('obs_getdemographicsnapshot', user_obs_config, logger):
|
||||||
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetDemographicSnapshot($1, $2, $3, $4, $5) as snapshot;", ["text", "text", "geometry(Geometry, 4326)", "text", "text"])
|
try:
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geom, time_span, geometry_level])
|
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetDemographicSnapshot($1, $2, $3, $4, $5) as snapshot;", ["text", "text", "geometry(Geometry, 4326)", "text", "text"])
|
||||||
if result:
|
result = plpy.execute(obs_plan, [username, orgname, geom, time_span, geometry_level])
|
||||||
resp = []
|
if result:
|
||||||
for element in result:
|
resp = []
|
||||||
value = element['snapshot']
|
for element in result:
|
||||||
resp.append(value)
|
value = element['snapshot']
|
||||||
quota_service.increment_success_service_use()
|
resp.append(value)
|
||||||
return resp
|
quota_service.increment_success_service_use()
|
||||||
else:
|
return resp
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return []
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return []
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to obs_get_demographic_snapshot', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to obs_get_demographic_snapshot')
|
logger.error('Error trying to obs_get_demographic_snapshot', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to obs_get_demographic_snapshot')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetSegmentSnapshotJSON(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetSegmentSnapshotJSON(
|
||||||
@@ -139,6 +143,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.obs_get_segment_snapshot(
|
|||||||
geom geometry(Geometry, 4326),
|
geom geometry(Geometry, 4326),
|
||||||
geometry_level TEXT DEFAULT NULL)
|
geometry_level TEXT DEFAULT NULL)
|
||||||
RETURNS json AS $$
|
RETURNS json AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
import json
|
import json
|
||||||
@@ -146,31 +151,32 @@ RETURNS json AS $$
|
|||||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
plpy.execute("SELECT cdb_dataservices_server._get_obs_snapshot_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
plpy.execute("SELECT cdb_dataservices_server._get_obs_snapshot_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
user_obs_snapshot_config = GD["user_obs_snapshot_config_{0}".format(username)]
|
user_obs_config = GD["user_obs_snapshot_config_{0}".format(username)]
|
||||||
|
|
||||||
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
logger_config = GD["logger_config"]
|
logger_config = GD["logger_config"]
|
||||||
logger = Logger(logger_config)
|
logger = Logger(logger_config)
|
||||||
quota_service = QuotaService(user_obs_snapshot_config, redis_conn)
|
quota_service = QuotaService(user_obs_config, redis_conn)
|
||||||
if not quota_service.check_user_quota():
|
if not quota_service.check_user_quota():
|
||||||
raise Exception('You have reached the limit of your quota')
|
raise Exception('You have reached the limit of your quota')
|
||||||
|
|
||||||
try:
|
with metrics('obs_getsegmentsnapshot', user_obs_config, logger):
|
||||||
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetSegmentSnapshotJSON($1, $2, $3, $4) as snapshot;", ["text", "text", "geometry(Geometry, 4326)", "text"])
|
try:
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geom, geometry_level])
|
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetSegmentSnapshotJSON($1, $2, $3, $4) as snapshot;", ["text", "text", "geometry(Geometry, 4326)", "text"])
|
||||||
if result:
|
result = plpy.execute(obs_plan, [username, orgname, geom, geometry_level])
|
||||||
quota_service.increment_success_service_use()
|
if result:
|
||||||
return result[0]['snapshot']
|
quota_service.increment_success_service_use()
|
||||||
else:
|
return result[0]['snapshot']
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return None
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return None
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to obs_get_segment_snapshot', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to obs_get_segment_snapshot')
|
logger.error('Error trying to obs_get_segment_snapshot', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to obs_get_segment_snapshot')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetSegmentSnapshot(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetSegmentSnapshot(
|
||||||
@@ -189,41 +195,43 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetSegmentSnapshot(
|
|||||||
geom geometry(Geometry, 4326),
|
geom geometry(Geometry, 4326),
|
||||||
geometry_level TEXT DEFAULT NULL)
|
geometry_level TEXT DEFAULT NULL)
|
||||||
RETURNS SETOF JSON AS $$
|
RETURNS SETOF JSON AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
plpy.execute("SELECT cdb_dataservices_server._get_obs_snapshot_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
plpy.execute("SELECT cdb_dataservices_server._get_obs_snapshot_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
user_obs_snapshot_config = GD["user_obs_snapshot_config_{0}".format(username)]
|
user_obs_config = GD["user_obs_snapshot_config_{0}".format(username)]
|
||||||
|
|
||||||
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
logger_config = GD["logger_config"]
|
logger_config = GD["logger_config"]
|
||||||
logger = Logger(logger_config)
|
logger = Logger(logger_config)
|
||||||
quota_service = QuotaService(user_obs_snapshot_config, redis_conn)
|
quota_service = QuotaService(user_obs_config, redis_conn)
|
||||||
if not quota_service.check_user_quota():
|
if not quota_service.check_user_quota():
|
||||||
raise Exception('You have reached the limit of your quota')
|
raise Exception('You have reached the limit of your quota')
|
||||||
|
|
||||||
try:
|
with metrics('obs_getsegmentsnapshot', user_obs_config, logger):
|
||||||
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetSegmentSnapshot($1, $2, $3, $4) as snapshot;", ["text", "text", "geometry(Geometry, 4326)", "text"])
|
try:
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geom, geometry_level])
|
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetSegmentSnapshot($1, $2, $3, $4) as snapshot;", ["text", "text", "geometry(Geometry, 4326)", "text"])
|
||||||
if result:
|
result = plpy.execute(obs_plan, [username, orgname, geom, geometry_level])
|
||||||
resp = []
|
if result:
|
||||||
for element in result:
|
resp = []
|
||||||
value = element['snapshot']
|
for element in result:
|
||||||
resp.append(value)
|
value = element['snapshot']
|
||||||
quota_service.increment_success_service_use()
|
resp.append(value)
|
||||||
return resp
|
quota_service.increment_success_service_use()
|
||||||
else:
|
return resp
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return []
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return []
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to OBS_GetSegmentSnapshot', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to OBS_GetSegmentSnapshot')
|
logger.error('Error trying to OBS_GetSegmentSnapshot', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to OBS_GetSegmentSnapshot')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetMeasure(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetMeasure(
|
||||||
@@ -248,6 +256,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetMeasure(
|
|||||||
boundary_id TEXT DEFAULT NULL,
|
boundary_id TEXT DEFAULT NULL,
|
||||||
time_span TEXT DEFAULT NULL)
|
time_span TEXT DEFAULT NULL)
|
||||||
RETURNS NUMERIC AS $$
|
RETURNS NUMERIC AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
@@ -263,22 +272,23 @@ RETURNS NUMERIC AS $$
|
|||||||
if not quota_service.check_user_quota():
|
if not quota_service.check_user_quota():
|
||||||
raise Exception('You have reached the limit of your quota')
|
raise Exception('You have reached the limit of your quota')
|
||||||
|
|
||||||
try:
|
with metrics('obs_getmeasure', user_obs_config, logger):
|
||||||
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetMeasure($1, $2, $3, $4, $5, $6, $7) as measure;", ["text", "text", "geometry(Geometry, 4326)", "text", "text", "text", "text"])
|
try:
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geom, measure_id, normalize, boundary_id, time_span])
|
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetMeasure($1, $2, $3, $4, $5, $6, $7) as measure;", ["text", "text", "geometry(Geometry, 4326)", "text", "text", "text", "text"])
|
||||||
if result:
|
result = plpy.execute(obs_plan, [username, orgname, geom, measure_id, normalize, boundary_id, time_span])
|
||||||
quota_service.increment_success_service_use()
|
if result:
|
||||||
return result[0]['measure']
|
quota_service.increment_success_service_use()
|
||||||
else:
|
return result[0]['measure']
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return None
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return None
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to OBS_GetMeasure', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to OBS_GetMeasure')
|
logger.error('Error trying to OBS_GetMeasure', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to OBS_GetMeasure')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetCategory(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetCategory(
|
||||||
@@ -301,6 +311,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetCategory(
|
|||||||
boundary_id TEXT DEFAULT NULL,
|
boundary_id TEXT DEFAULT NULL,
|
||||||
time_span TEXT DEFAULT NULL)
|
time_span TEXT DEFAULT NULL)
|
||||||
RETURNS TEXT AS $$
|
RETURNS TEXT AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
@@ -316,22 +327,23 @@ RETURNS TEXT AS $$
|
|||||||
if not quota_service.check_user_quota():
|
if not quota_service.check_user_quota():
|
||||||
raise Exception('You have reached the limit of your quota')
|
raise Exception('You have reached the limit of your quota')
|
||||||
|
|
||||||
try:
|
with metrics('obs_getcategory', user_obs_config, logger):
|
||||||
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetCategory($1, $2, $3, $4, $5, $6) as category;", ["text", "text", "geometry(Geometry, 4326)", "text", "text", "text"])
|
try:
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geom, category_id, boundary_id, time_span])
|
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetCategory($1, $2, $3, $4, $5, $6) as category;", ["text", "text", "geometry(Geometry, 4326)", "text", "text", "text"])
|
||||||
if result:
|
result = plpy.execute(obs_plan, [username, orgname, geom, category_id, boundary_id, time_span])
|
||||||
quota_service.increment_success_service_use()
|
if result:
|
||||||
return result[0]['category']
|
quota_service.increment_success_service_use()
|
||||||
else:
|
return result[0]['category']
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return None
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return None
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to OBS_GetCategory', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to OBS_GetCategory')
|
logger.error('Error trying to OBS_GetCategory', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to OBS_GetCategory')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetUSCensusMeasure(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetUSCensusMeasure(
|
||||||
@@ -356,6 +368,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetUSCensusMeasure(
|
|||||||
boundary_id TEXT DEFAULT NULL,
|
boundary_id TEXT DEFAULT NULL,
|
||||||
time_span TEXT DEFAULT NULL)
|
time_span TEXT DEFAULT NULL)
|
||||||
RETURNS NUMERIC AS $$
|
RETURNS NUMERIC AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
@@ -371,22 +384,23 @@ RETURNS NUMERIC AS $$
|
|||||||
if not quota_service.check_user_quota():
|
if not quota_service.check_user_quota():
|
||||||
raise Exception('You have reached the limit of your quota')
|
raise Exception('You have reached the limit of your quota')
|
||||||
|
|
||||||
try:
|
with metrics('obs_getuscensusmeasure', user_obs_config, logger):
|
||||||
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetUSCensusMeasure($1, $2, $3, $4, $5, $6, $7) as census_measure;", ["text", "text", "geometry(Geometry, 4326)", "text", "text", "text", "text"])
|
try:
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geom, name, normalize, boundary_id, time_span])
|
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetUSCensusMeasure($1, $2, $3, $4, $5, $6, $7) as census_measure;", ["text", "text", "geometry(Geometry, 4326)", "text", "text", "text", "text"])
|
||||||
if result:
|
result = plpy.execute(obs_plan, [username, orgname, geom, name, normalize, boundary_id, time_span])
|
||||||
quota_service.increment_success_service_use()
|
if result:
|
||||||
return result[0]['census_measure']
|
quota_service.increment_success_service_use()
|
||||||
else:
|
return result[0]['census_measure']
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return None
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return None
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to OBS_GetUSCensusMeasure', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to OBS_GetUSCensusMeasure')
|
logger.error('Error trying to OBS_GetUSCensusMeasure', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to OBS_GetUSCensusMeasure')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetUSCensusCategory(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetUSCensusCategory(
|
||||||
@@ -409,6 +423,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetUSCensusCategory(
|
|||||||
boundary_id TEXT DEFAULT NULL,
|
boundary_id TEXT DEFAULT NULL,
|
||||||
time_span TEXT DEFAULT NULL)
|
time_span TEXT DEFAULT NULL)
|
||||||
RETURNS TEXT AS $$
|
RETURNS TEXT AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
@@ -424,22 +439,23 @@ RETURNS TEXT AS $$
|
|||||||
if not quota_service.check_user_quota():
|
if not quota_service.check_user_quota():
|
||||||
raise Exception('You have reached the limit of your quota')
|
raise Exception('You have reached the limit of your quota')
|
||||||
|
|
||||||
try:
|
with metrics('obs_getuscensuscategory', user_obs_config, logger):
|
||||||
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetUSCensusCategory($1, $2, $3, $4, $5, $6) as census_category;", ["text", "text", "geometry(Geometry, 4326)", "text", "text", "text"])
|
try:
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geom, name, boundary_id, time_span])
|
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetUSCensusCategory($1, $2, $3, $4, $5, $6) as census_category;", ["text", "text", "geometry(Geometry, 4326)", "text", "text", "text"])
|
||||||
if result:
|
result = plpy.execute(obs_plan, [username, orgname, geom, name, boundary_id, time_span])
|
||||||
quota_service.increment_success_service_use()
|
if result:
|
||||||
return result[0]['census_category']
|
quota_service.increment_success_service_use()
|
||||||
else:
|
return result[0]['census_category']
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return None
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return None
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to OBS_GetUSCensusCategory', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to OBS_GetUSCensusCategory')
|
logger.error('Error trying to OBS_GetUSCensusCategory', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to OBS_GetUSCensusCategory')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetPopulation(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetPopulation(
|
||||||
@@ -462,6 +478,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetPopulation(
|
|||||||
boundary_id TEXT DEFAULT NULL,
|
boundary_id TEXT DEFAULT NULL,
|
||||||
time_span TEXT DEFAULT NULL)
|
time_span TEXT DEFAULT NULL)
|
||||||
RETURNS NUMERIC AS $$
|
RETURNS NUMERIC AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
@@ -477,22 +494,23 @@ RETURNS NUMERIC AS $$
|
|||||||
if not quota_service.check_user_quota():
|
if not quota_service.check_user_quota():
|
||||||
raise Exception('You have reached the limit of your quota')
|
raise Exception('You have reached the limit of your quota')
|
||||||
|
|
||||||
try:
|
with metrics('obs_getpopulation', user_obs_config, logger):
|
||||||
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetPopulation($1, $2, $3, $4, $5, $6) as population;", ["text", "text", "geometry(Geometry, 4326)", "text", "text", "text"])
|
try:
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geom, normalize, boundary_id, time_span])
|
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetPopulation($1, $2, $3, $4, $5, $6) as population;", ["text", "text", "geometry(Geometry, 4326)", "text", "text", "text"])
|
||||||
if result:
|
result = plpy.execute(obs_plan, [username, orgname, geom, normalize, boundary_id, time_span])
|
||||||
quota_service.increment_success_service_use()
|
if result:
|
||||||
return result[0]['population']
|
quota_service.increment_success_service_use()
|
||||||
else:
|
return result[0]['population']
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return None
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return None
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to OBS_GetPopulation', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to OBS_GetPopulation')
|
logger.error('Error trying to OBS_GetPopulation', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to OBS_GetPopulation')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetMeasureById(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetMeasureById(
|
||||||
@@ -515,6 +533,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetMeasureById(
|
|||||||
boundary_id TEXT,
|
boundary_id TEXT,
|
||||||
time_span TEXT DEFAULT NULL)
|
time_span TEXT DEFAULT NULL)
|
||||||
RETURNS NUMERIC AS $$
|
RETURNS NUMERIC AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
@@ -530,20 +549,21 @@ RETURNS NUMERIC AS $$
|
|||||||
if not quota_service.check_user_quota():
|
if not quota_service.check_user_quota():
|
||||||
raise Exception('You have reached the limit of your quota')
|
raise Exception('You have reached the limit of your quota')
|
||||||
|
|
||||||
try:
|
with metrics('obs_getmeasurebyid', user_obs_config, logger):
|
||||||
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetMeasureById($1, $2, $3, $4, $5, $6) as measure;", ["text", "text", "text", "text", "text", "text"])
|
try:
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geom_ref, measure_id, boundary_id, time_span])
|
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetMeasureById($1, $2, $3, $4, $5, $6) as measure;", ["text", "text", "text", "text", "text", "text"])
|
||||||
if result:
|
result = plpy.execute(obs_plan, [username, orgname, geom_ref, measure_id, boundary_id, time_span])
|
||||||
quota_service.increment_success_service_use()
|
if result:
|
||||||
return result[0]['measure']
|
quota_service.increment_success_service_use()
|
||||||
else:
|
return result[0]['measure']
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return None
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return None
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to OBS_GetMeasureById', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to OBS_GetMeasureById')
|
logger.error('Error trying to OBS_GetMeasureById', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to OBS_GetMeasureById')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_Search(
|
|||||||
search_term TEXT,
|
search_term TEXT,
|
||||||
relevant_boundary TEXT DEFAULT NULL)
|
relevant_boundary TEXT DEFAULT NULL)
|
||||||
RETURNS TABLE(id text, description text, name text, aggregate text, source text) AS $$
|
RETURNS TABLE(id text, description text, name text, aggregate text, source text) AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
@@ -29,30 +30,31 @@ RETURNS TABLE(id text, description text, name text, aggregate text, source text)
|
|||||||
if not quota_service.check_user_quota():
|
if not quota_service.check_user_quota():
|
||||||
raise Exception('You have reached the limit of your quota')
|
raise Exception('You have reached the limit of your quota')
|
||||||
|
|
||||||
try:
|
with metrics('obs_search', user_obs_config, logger):
|
||||||
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_Search($1, $2, $3, $4);", ["text", "text", "text", "text"])
|
try:
|
||||||
result = plpy.execute(obs_plan, [username, orgname, search_term, relevant_boundary])
|
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_Search($1, $2, $3, $4);", ["text", "text", "text", "text"])
|
||||||
if result:
|
result = plpy.execute(obs_plan, [username, orgname, search_term, relevant_boundary])
|
||||||
resp = []
|
if result:
|
||||||
for element in result:
|
resp = []
|
||||||
id = element['id']
|
for element in result:
|
||||||
description = element['description']
|
id = element['id']
|
||||||
name = element['name']
|
description = element['description']
|
||||||
aggregate = element['aggregate']
|
name = element['name']
|
||||||
source = element['source']
|
aggregate = element['aggregate']
|
||||||
resp.append([id, description, name, aggregate, source])
|
source = element['source']
|
||||||
quota_service.increment_success_service_use()
|
resp.append([id, description, name, aggregate, source])
|
||||||
return resp
|
quota_service.increment_success_service_use()
|
||||||
else:
|
return resp
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return [None, None, None, None, None]
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return [None, None, None, None, None]
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to OBS_Search', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to OBS_Search')
|
logger.error('Error trying to OBS_Search', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to OBS_Search')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetAvailableBoundaries(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetAvailableBoundaries(
|
||||||
@@ -71,6 +73,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetAvailableBoundaries(
|
|||||||
geom geometry(Geometry, 4326),
|
geom geometry(Geometry, 4326),
|
||||||
time_span TEXT DEFAULT NULL)
|
time_span TEXT DEFAULT NULL)
|
||||||
RETURNS TABLE(boundary_id text, description text, time_span text, tablename text) AS $$
|
RETURNS TABLE(boundary_id text, description text, time_span text, tablename text) AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
@@ -86,27 +89,28 @@ RETURNS TABLE(boundary_id text, description text, time_span text, tablename text
|
|||||||
if not quota_service.check_user_quota():
|
if not quota_service.check_user_quota():
|
||||||
raise Exception('You have reached the limit of your quota')
|
raise Exception('You have reached the limit of your quota')
|
||||||
|
|
||||||
try:
|
with metrics('obs_getavailableboundaries', user_obs_config, logger):
|
||||||
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetAvailableBoundaries($1, $2, $3, $4) as available_boundaries;", ["text", "text", "geometry(Geometry, 4326)", "text"])
|
try:
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geom, time_span])
|
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetAvailableBoundaries($1, $2, $3, $4) as available_boundaries;", ["text", "text", "geometry(Geometry, 4326)", "text"])
|
||||||
if result:
|
result = plpy.execute(obs_plan, [username, orgname, geom, time_span])
|
||||||
resp = []
|
if result:
|
||||||
for element in result:
|
resp = []
|
||||||
id = element['boundary_id']
|
for element in result:
|
||||||
description = element['description']
|
id = element['boundary_id']
|
||||||
tspan = element['time_span']
|
description = element['description']
|
||||||
tablename = element['tablename']
|
tspan = element['time_span']
|
||||||
resp.append([id, description, tspan, tablename])
|
tablename = element['tablename']
|
||||||
quota_service.increment_success_service_use()
|
resp.append([id, description, tspan, tablename])
|
||||||
return resp
|
quota_service.increment_success_service_use()
|
||||||
else:
|
return resp
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return []
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return []
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to OBS_GetMeasureById', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to OBS_GetMeasureById')
|
logger.error('Error trying to OBS_GetMeasureById', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to OBS_GetMeasureById')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetBoundary(
|
|||||||
boundary_id TEXT,
|
boundary_id TEXT,
|
||||||
time_span TEXT DEFAULT NULL)
|
time_span TEXT DEFAULT NULL)
|
||||||
RETURNS geometry(Geometry, 4326) AS $$
|
RETURNS geometry(Geometry, 4326) AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
@@ -31,22 +32,23 @@ RETURNS geometry(Geometry, 4326) AS $$
|
|||||||
if not quota_service.check_user_quota():
|
if not quota_service.check_user_quota():
|
||||||
raise Exception('You have reached the limit of your quota')
|
raise Exception('You have reached the limit of your quota')
|
||||||
|
|
||||||
try:
|
with metrics('obs_getboundary', user_obs_config, logger):
|
||||||
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetBoundary($1, $2, $3, $4) as boundary;", ["text", "text", "geometry(Point, 4326)", "text", "text"])
|
try:
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geom, boundary_id, time_span])
|
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetBoundary($1, $2, $3, $4) as boundary;", ["text", "text", "geometry(Point, 4326)", "text", "text"])
|
||||||
if result:
|
result = plpy.execute(obs_plan, [username, orgname, geom, boundary_id, time_span])
|
||||||
quota_service.increment_success_service_use()
|
if result:
|
||||||
return result[0]['boundary']
|
quota_service.increment_success_service_use()
|
||||||
else:
|
return result[0]['boundary']
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return None
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return None
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to OBS_GetBoundary', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to OBS_GetBoundary')
|
logger.error('Error trying to OBS_GetBoundary', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to OBS_GetBoundary')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetBoundaryId(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetBoundaryId(
|
||||||
@@ -67,6 +69,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetBoundaryId(
|
|||||||
boundary_id TEXT,
|
boundary_id TEXT,
|
||||||
time_span TEXT DEFAULT NULL)
|
time_span TEXT DEFAULT NULL)
|
||||||
RETURNS TEXT AS $$
|
RETURNS TEXT AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
@@ -82,22 +85,23 @@ RETURNS TEXT AS $$
|
|||||||
if not quota_service.check_user_quota():
|
if not quota_service.check_user_quota():
|
||||||
raise Exception('You have reached the limit of your quota')
|
raise Exception('You have reached the limit of your quota')
|
||||||
|
|
||||||
try:
|
with metrics('obs_getboundaryid', user_obs_config, logger):
|
||||||
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetBoundaryId($1, $2, $3, $4, $5) as boundary;", ["text", "text", "geometry(Point, 4326)", "text", "text"])
|
try:
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geom, boundary_id, time_span])
|
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetBoundaryId($1, $2, $3, $4, $5) as boundary;", ["text", "text", "geometry(Point, 4326)", "text", "text"])
|
||||||
if result:
|
result = plpy.execute(obs_plan, [username, orgname, geom, boundary_id, time_span])
|
||||||
quota_service.increment_success_service_use()
|
if result:
|
||||||
return result[0]['boundary']
|
quota_service.increment_success_service_use()
|
||||||
else:
|
return result[0]['boundary']
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return None
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return None
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to OBS_GetBoundaryId', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to OBS_GetBoundaryId')
|
logger.error('Error trying to OBS_GetBoundaryId', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to OBS_GetBoundaryId')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetBoundaryById(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetBoundaryById(
|
||||||
@@ -118,6 +122,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetBoundaryById(
|
|||||||
boundary_id TEXT,
|
boundary_id TEXT,
|
||||||
time_span TEXT DEFAULT NULL)
|
time_span TEXT DEFAULT NULL)
|
||||||
RETURNS geometry(Geometry, 4326) AS $$
|
RETURNS geometry(Geometry, 4326) AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
@@ -133,22 +138,23 @@ RETURNS geometry(Geometry, 4326) AS $$
|
|||||||
if not quota_service.check_user_quota():
|
if not quota_service.check_user_quota():
|
||||||
raise Exception('You have reached the limit of your quota')
|
raise Exception('You have reached the limit of your quota')
|
||||||
|
|
||||||
try:
|
with metrics('obs_getboundarybyid', user_obs_config, logger):
|
||||||
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetBoundaryById($1, $2, $3, $4, $5) as boundary;", ["text", "text", "text", "text", "text"])
|
try:
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geometry_id, boundary_id, time_span])
|
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetBoundaryById($1, $2, $3, $4, $5) as boundary;", ["text", "text", "text", "text", "text"])
|
||||||
if result:
|
result = plpy.execute(obs_plan, [username, orgname, geometry_id, boundary_id, time_span])
|
||||||
quota_service.increment_success_service_use()
|
if result:
|
||||||
return result[0]['boundary']
|
quota_service.increment_success_service_use()
|
||||||
else:
|
return result[0]['boundary']
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return None
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return None
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to OBS_GetBoundaryById', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to OBS_GetBoundaryById')
|
logger.error('Error trying to OBS_GetBoundaryById', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to OBS_GetBoundaryById')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetBoundariesByGeometry(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetBoundariesByGeometry(
|
||||||
@@ -171,6 +177,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetBoundariesByGeometry(
|
|||||||
time_span TEXT DEFAULT NULL,
|
time_span TEXT DEFAULT NULL,
|
||||||
overlap_type TEXT DEFAULT NULL)
|
overlap_type TEXT DEFAULT NULL)
|
||||||
RETURNS TABLE(the_geom geometry, geom_refs text) AS $$
|
RETURNS TABLE(the_geom geometry, geom_refs text) AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
@@ -186,27 +193,28 @@ RETURNS TABLE(the_geom geometry, geom_refs text) AS $$
|
|||||||
if not quota_service.check_user_quota():
|
if not quota_service.check_user_quota():
|
||||||
raise Exception('You have reached the limit of your quota')
|
raise Exception('You have reached the limit of your quota')
|
||||||
|
|
||||||
try:
|
with metrics('obs_getboundariesbygeometry', user_obs_config, logger):
|
||||||
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetBoundariesByGeometry($1, $2, $3, $4, $5, $6) as boundary;", ["text", "text", "geometry(Point, 4326)", "text", "text", "text"])
|
try:
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geom, boundary_id, time_span, overlap_type])
|
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetBoundariesByGeometry($1, $2, $3, $4, $5, $6) as boundary;", ["text", "text", "geometry(Point, 4326)", "text", "text", "text"])
|
||||||
if result:
|
result = plpy.execute(obs_plan, [username, orgname, geom, boundary_id, time_span, overlap_type])
|
||||||
resp = []
|
if result:
|
||||||
for element in result:
|
resp = []
|
||||||
the_geom = element['the_geom']
|
for element in result:
|
||||||
geom_refs = element['geom_refs']
|
the_geom = element['the_geom']
|
||||||
resp.append([the_geom, geom_refs])
|
geom_refs = element['geom_refs']
|
||||||
quota_service.increment_success_service_use()
|
resp.append([the_geom, geom_refs])
|
||||||
return resp
|
quota_service.increment_success_service_use()
|
||||||
else:
|
return resp
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return []
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return []
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to OBS_GetBoundariesByGeometry', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to OBS_GetBoundariesByGeometry')
|
logger.error('Error trying to OBS_GetBoundariesByGeometry', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to OBS_GetBoundariesByGeometry')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetBoundariesByPointAndRadius(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetBoundariesByPointAndRadius(
|
||||||
@@ -231,6 +239,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetBoundariesByPointAndRa
|
|||||||
time_span TEXT DEFAULT NULL,
|
time_span TEXT DEFAULT NULL,
|
||||||
overlap_type TEXT DEFAULT NULL)
|
overlap_type TEXT DEFAULT NULL)
|
||||||
RETURNS TABLE(the_geom geometry, geom_refs text) AS $$
|
RETURNS TABLE(the_geom geometry, geom_refs text) AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
@@ -246,27 +255,28 @@ RETURNS TABLE(the_geom geometry, geom_refs text) AS $$
|
|||||||
if not quota_service.check_user_quota():
|
if not quota_service.check_user_quota():
|
||||||
raise Exception('You have reached the limit of your quota')
|
raise Exception('You have reached the limit of your quota')
|
||||||
|
|
||||||
try:
|
with metrics('obs_getboundariesbypointandradius', user_obs_config, logger):
|
||||||
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetBoundariesByPointAndRadius($1, $2, $3, $4, $5, $6, $7) as boundary;", ["text", "text", "geometry(Point, 4326)", "numeric", "text", "text", "text"])
|
try:
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geom, radius, boundary_id, time_span, overlap_type])
|
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetBoundariesByPointAndRadius($1, $2, $3, $4, $5, $6, $7) as boundary;", ["text", "text", "geometry(Point, 4326)", "numeric", "text", "text", "text"])
|
||||||
if result:
|
result = plpy.execute(obs_plan, [username, orgname, geom, radius, boundary_id, time_span, overlap_type])
|
||||||
resp = []
|
if result:
|
||||||
for element in result:
|
resp = []
|
||||||
the_geom = element['the_geom']
|
for element in result:
|
||||||
geom_refs = element['geom_refs']
|
the_geom = element['the_geom']
|
||||||
resp.append([the_geom, geom_refs])
|
geom_refs = element['geom_refs']
|
||||||
quota_service.increment_success_service_use()
|
resp.append([the_geom, geom_refs])
|
||||||
return resp
|
quota_service.increment_success_service_use()
|
||||||
else:
|
return resp
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return []
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return []
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to OBS_GetBoundariesByPointAndRadius', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to OBS_GetBoundariesByPointAndRadius')
|
logger.error('Error trying to OBS_GetBoundariesByPointAndRadius', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to OBS_GetBoundariesByPointAndRadius')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetPointsByGeometry(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetPointsByGeometry(
|
||||||
@@ -289,6 +299,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetPointsByGeometry(
|
|||||||
time_span TEXT DEFAULT NULL,
|
time_span TEXT DEFAULT NULL,
|
||||||
overlap_type TEXT DEFAULT NULL)
|
overlap_type TEXT DEFAULT NULL)
|
||||||
RETURNS TABLE(the_geom geometry, geom_refs text) AS $$
|
RETURNS TABLE(the_geom geometry, geom_refs text) AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
@@ -304,27 +315,28 @@ RETURNS TABLE(the_geom geometry, geom_refs text) AS $$
|
|||||||
if not quota_service.check_user_quota():
|
if not quota_service.check_user_quota():
|
||||||
raise Exception('You have reached the limit of your quota')
|
raise Exception('You have reached the limit of your quota')
|
||||||
|
|
||||||
try:
|
with metrics('obs_getpointsbygeometry', user_obs_config, logger):
|
||||||
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetPointsByGeometry($1, $2, $3, $4, $5, $6) as boundary;", ["text", "text", "geometry(Point, 4326)", "text", "text", "text"])
|
try:
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geom, boundary_id, time_span, overlap_type])
|
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetPointsByGeometry($1, $2, $3, $4, $5, $6) as boundary;", ["text", "text", "geometry(Point, 4326)", "text", "text", "text"])
|
||||||
if result:
|
result = plpy.execute(obs_plan, [username, orgname, geom, boundary_id, time_span, overlap_type])
|
||||||
resp = []
|
if result:
|
||||||
for element in result:
|
resp = []
|
||||||
the_geom = element['the_geom']
|
for element in result:
|
||||||
geom_refs = element['geom_refs']
|
the_geom = element['the_geom']
|
||||||
resp.append([the_geom, geom_refs])
|
geom_refs = element['geom_refs']
|
||||||
quota_service.increment_success_service_use()
|
resp.append([the_geom, geom_refs])
|
||||||
return resp
|
quota_service.increment_success_service_use()
|
||||||
else:
|
return resp
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return []
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return []
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to OBS_GetPointsByGeometry', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to OBS_GetPointsByGeometry')
|
logger.error('Error trying to OBS_GetPointsByGeometry', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to OBS_GetPointsByGeometry')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetPointsByPointAndRadius(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetPointsByPointAndRadius(
|
||||||
@@ -349,6 +361,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetPointsByPointAndRadius
|
|||||||
time_span TEXT DEFAULT NULL,
|
time_span TEXT DEFAULT NULL,
|
||||||
overlap_type TEXT DEFAULT NULL)
|
overlap_type TEXT DEFAULT NULL)
|
||||||
RETURNS TABLE(the_geom geometry, geom_refs text) AS $$
|
RETURNS TABLE(the_geom geometry, geom_refs text) AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
@@ -364,25 +377,26 @@ RETURNS TABLE(the_geom geometry, geom_refs text) AS $$
|
|||||||
if not quota_service.check_user_quota():
|
if not quota_service.check_user_quota():
|
||||||
raise Exception('You have reached the limit of your quota')
|
raise Exception('You have reached the limit of your quota')
|
||||||
|
|
||||||
try:
|
with metrics('obs_getpointsbypointandradius', user_obs_config, logger):
|
||||||
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetPointsByPointAndRadius($1, $2, $3, $4, $5, $6, $7) as boundary;", ["text", "text", "geometry(Point, 4326)", "numeric", "text", "text", "text"])
|
try:
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geom, radius, boundary_id, time_span, overlap_type])
|
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetPointsByPointAndRadius($1, $2, $3, $4, $5, $6, $7) as boundary;", ["text", "text", "geometry(Point, 4326)", "numeric", "text", "text", "text"])
|
||||||
if result:
|
result = plpy.execute(obs_plan, [username, orgname, geom, radius, boundary_id, time_span, overlap_type])
|
||||||
resp = []
|
if result:
|
||||||
for element in result:
|
resp = []
|
||||||
the_geom = element['the_geom']
|
for element in result:
|
||||||
geom_refs = element['geom_refs']
|
the_geom = element['the_geom']
|
||||||
resp.append([the_geom, geom_refs])
|
geom_refs = element['geom_refs']
|
||||||
quota_service.increment_success_service_use()
|
resp.append([the_geom, geom_refs])
|
||||||
return resp
|
quota_service.increment_success_service_use()
|
||||||
else:
|
return resp
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return None
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return None
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to OBS_GetPointsByPointAndRadius', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to OBS_GetPointsByPointAndRadius')
|
logger.error('Error trying to OBS_GetPointsByPointAndRadius', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to OBS_GetPointsByPointAndRadius')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|||||||
@@ -3,3 +3,73 @@ RETURNS text AS $$
|
|||||||
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||||
SELECT cdb_observatory.obs_dumpversion();
|
SELECT cdb_observatory.obs_dumpversion();
|
||||||
$$ LANGUAGE plproxy;
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
-- We could create a super type for the common data like id, name and so on but we need to parse inside the functions because the -- the return data tha comes from OBS is a TABLE() with them
|
||||||
|
CREATE TYPE cdb_dataservices_server.obs_meta_numerator AS (numer_id text, numer_name text, numer_description text, numer_weight text, numer_license text, numer_source text, numer_type text, numer_aggregate text, numer_extra jsonb, numer_tags jsonb, valid_denom boolean, valid_geom boolean, valid_timespan boolean);
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetAvailableNumerators(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
bounds geometry(Geometry, 4326) DEFAULT NULL,
|
||||||
|
filter_tags TEXT[] DEFAULT NULL,
|
||||||
|
denom_id TEXT DEFAULT NULL,
|
||||||
|
geom_id TEXT DEFAULT NULL,
|
||||||
|
timespan TEXT DEFAULT NULL)
|
||||||
|
RETURNS SETOF cdb_dataservices_server.obs_meta_numerator AS $$
|
||||||
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||||
|
SELECT * FROM cdb_observatory.OBS_GetAvailableNumerators(bounds, filter_tags, denom_id, geom_id, timespan);
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
CREATE TYPE cdb_dataservices_server.obs_meta_denominator AS (denom_id text, denom_name text, denom_description text, denom_weight text, denom_license text, denom_source text, denom_type text, denom_aggregate text, denom_extra jsonb, denom_tags jsonb, valid_numer boolean, valid_geom boolean, valid_timespan boolean);
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetAvailableDenominators(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
bounds geometry(Geometry, 4326) DEFAULT NULL,
|
||||||
|
filter_tags TEXT[] DEFAULT NULL,
|
||||||
|
numer_id TEXT DEFAULT NULL,
|
||||||
|
geom_id TEXT DEFAULT NULL,
|
||||||
|
timespan TEXT DEFAULT NULL)
|
||||||
|
RETURNS SETOF cdb_dataservices_server.obs_meta_denominator AS $$
|
||||||
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||||
|
SELECT * FROM cdb_observatory.OBS_GetAvailableDenominators(bounds, filter_tags, numer_id, geom_id, timespan);
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
CREATE TYPE cdb_dataservices_server.obs_meta_geometry AS (geom_id text, geom_name text, geom_description text, geom_weight text, geom_aggregate text, geom_license text, geom_source text, valid_numer boolean, valid_denom boolean, valid_timespan boolean, score numeric, numtiles bigint, notnull_percent numeric, numgeoms numeric, percentfill numeric, estnumgeoms numeric, meanmediansize numeric);
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetAvailableGeometries(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
bounds geometry(Geometry, 4326) DEFAULT NULL,
|
||||||
|
filter_tags TEXT[] DEFAULT NULL,
|
||||||
|
numer_id TEXT DEFAULT NULL,
|
||||||
|
denom_id TEXT DEFAULT NULL,
|
||||||
|
timespan TEXT DEFAULT NULL)
|
||||||
|
RETURNS SETOF cdb_dataservices_server.obs_meta_geometry AS $$
|
||||||
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||||
|
SELECT * FROM cdb_observatory.OBS_GetAvailableGeometries(bounds, filter_tags, numer_id, denom_id, timespan);
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
CREATE TYPE cdb_dataservices_server.obs_meta_timespan AS (timespan_id text, timespan_name text, timespan_description text, timespan_weight text, timespan_aggregate text, timespan_license text, timespan_source text, valid_numer boolean, valid_denom boolean, valid_geom boolean);
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetAvailableTimespans(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
bounds geometry(Geometry, 4326) DEFAULT NULL,
|
||||||
|
filter_tags TEXT[] DEFAULT NULL,
|
||||||
|
numer_id TEXT DEFAULT NULL,
|
||||||
|
denom_id TEXT DEFAULT NULL,
|
||||||
|
geom_id TEXT DEFAULT NULL)
|
||||||
|
RETURNS SETOF cdb_dataservices_server.obs_meta_timespan AS $$
|
||||||
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||||
|
SELECT * FROM cdb_observatory.OBS_GetAvailableTimespans(bounds, filter_tags, numer_id, denom_id, geom_id);
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_LegacyBuilderMetadata(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
aggregate_type TEXT DEFAULT NULL)
|
||||||
|
RETURNS TABLE(name TEXT, subsection JSON) AS $$
|
||||||
|
CONNECT cdb_dataservices_server._obs_server_conn_str(username, orgname);
|
||||||
|
SELECT * FROM cdb_observatory.OBS_LegacyBuilderMetadata(aggregate_type);
|
||||||
|
$$ LANGUAGE plproxy;
|
||||||
|
|||||||
105
server/extension/sql/200_quotas.sql
Normal file
105
server/extension/sql/200_quotas.sql
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
DO $$
|
||||||
|
BEGIN
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'service_type') THEN
|
||||||
|
CREATE TYPE cdb_dataservices_server.service_type AS ENUM (
|
||||||
|
'isolines',
|
||||||
|
'hires_geocoder',
|
||||||
|
'routing',
|
||||||
|
'observatory'
|
||||||
|
);
|
||||||
|
END IF;
|
||||||
|
END $$;
|
||||||
|
|
||||||
|
DO $$
|
||||||
|
BEGIN
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'service_quota_info') THEN
|
||||||
|
CREATE TYPE cdb_dataservices_server.service_quota_info AS (
|
||||||
|
service cdb_dataservices_server.service_type,
|
||||||
|
monthly_quota NUMERIC,
|
||||||
|
used_quota NUMERIC,
|
||||||
|
soft_limit BOOLEAN,
|
||||||
|
provider TEXT
|
||||||
|
);
|
||||||
|
END IF;
|
||||||
|
END $$;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_service_quota_info(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT)
|
||||||
|
RETURNS SETOF cdb_dataservices_server.service_quota_info AS $$
|
||||||
|
from cartodb_services.metrics.user import UserMetricsService
|
||||||
|
from datetime import date
|
||||||
|
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
|
|
||||||
|
today = date.today()
|
||||||
|
ret = []
|
||||||
|
|
||||||
|
#-- Isolines
|
||||||
|
service = 'isolines'
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_isolines_routing_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
|
user_isolines_config = GD["user_isolines_routing_config_{0}".format(username)]
|
||||||
|
user_service = UserMetricsService(user_isolines_config, redis_conn)
|
||||||
|
|
||||||
|
monthly_quota = user_isolines_config.isolines_quota
|
||||||
|
used_quota = user_service.used_quota(user_isolines_config.service_type, today)
|
||||||
|
soft_limit = user_isolines_config.soft_isolines_limit
|
||||||
|
provider = user_isolines_config.provider
|
||||||
|
ret += [[service, monthly_quota, used_quota, soft_limit, provider]]
|
||||||
|
|
||||||
|
#-- Hires Geocoder
|
||||||
|
service = 'hires_geocoder'
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
|
user_geocoder_config = GD["user_geocoder_config_{0}".format(username)]
|
||||||
|
user_service = UserMetricsService(user_geocoder_config, redis_conn)
|
||||||
|
|
||||||
|
monthly_quota = user_geocoder_config.geocoding_quota
|
||||||
|
used_quota = user_service.used_quota(user_geocoder_config.service_type, today)
|
||||||
|
soft_limit = user_geocoder_config.soft_geocoding_limit
|
||||||
|
provider = user_geocoder_config.provider
|
||||||
|
ret += [[service, monthly_quota, used_quota, soft_limit, provider]]
|
||||||
|
|
||||||
|
#-- Routing
|
||||||
|
service = 'routing'
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_routing_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
|
user_routing_config = GD["user_routing_config_{0}".format(username)]
|
||||||
|
user_service = UserMetricsService(user_routing_config, redis_conn)
|
||||||
|
|
||||||
|
monthly_quota = user_routing_config.monthly_quota
|
||||||
|
used_quota = user_service.used_quota(user_routing_config.service_type, today)
|
||||||
|
soft_limit = user_routing_config.soft_limit
|
||||||
|
provider = user_routing_config.provider
|
||||||
|
ret += [[service, monthly_quota, used_quota, soft_limit, provider]]
|
||||||
|
|
||||||
|
#-- Observatory
|
||||||
|
service = 'observatory'
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_obs_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
|
user_obs_config = GD["user_obs_config_{0}".format(username)]
|
||||||
|
user_service = UserMetricsService(user_obs_config, redis_conn)
|
||||||
|
|
||||||
|
monthly_quota = user_obs_config.monthly_quota
|
||||||
|
used_quota = user_service.used_quota(user_obs_config.service_type, today)
|
||||||
|
soft_limit = user_obs_config.soft_limit
|
||||||
|
provider = user_obs_config.provider
|
||||||
|
ret += [[service, monthly_quota, used_quota, soft_limit, provider]]
|
||||||
|
|
||||||
|
return ret
|
||||||
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_enough_quota(
|
||||||
|
username TEXT,
|
||||||
|
orgname TEXT,
|
||||||
|
service_ TEXT,
|
||||||
|
input_size NUMERIC)
|
||||||
|
returns BOOLEAN AS $$
|
||||||
|
DECLARE
|
||||||
|
params cdb_dataservices_server.service_quota_info;
|
||||||
|
BEGIN
|
||||||
|
SELECT * INTO params
|
||||||
|
FROM cdb_dataservices_server.cdb_service_quota_info(username, orgname) AS p
|
||||||
|
WHERE p.service = service_::cdb_dataservices_server.service_type;
|
||||||
|
RETURN params.soft_limit OR ((params.used_quota + input_size) <= params.monthly_quota);
|
||||||
|
END
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
@@ -1,22 +1,28 @@
|
|||||||
-- Geocodes a street address given a searchtext and a state and/or country
|
-- Geocodes a street address given a searchtext and a state and/or country
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL)
|
||||||
RETURNS Geometry AS $$
|
RETURNS Geometry AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
plpy.execute("SELECT cdb_dataservices_server._get_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
plpy.execute("SELECT cdb_dataservices_server._get_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
user_geocoder_config = GD["user_geocoder_config_{0}".format(username)]
|
user_geocoder_config = GD["user_geocoder_config_{0}".format(username)]
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
|
logger_config = GD["logger_config"]
|
||||||
|
logger = Logger(logger_config)
|
||||||
|
|
||||||
if user_geocoder_config.heremaps_geocoder:
|
with metrics('cdb_geocode_street_point', user_geocoder_config, logger):
|
||||||
here_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_here_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
if user_geocoder_config.heremaps_geocoder:
|
||||||
return plpy.execute(here_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
|
here_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_here_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||||
elif user_geocoder_config.google_geocoder:
|
return plpy.execute(here_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
|
||||||
google_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_google_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
elif user_geocoder_config.google_geocoder:
|
||||||
return plpy.execute(google_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
|
google_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_google_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||||
elif user_geocoder_config.mapzen_geocoder:
|
return plpy.execute(google_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
|
||||||
mapzen_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_mapzen_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
elif user_geocoder_config.mapzen_geocoder:
|
||||||
return plpy.execute(mapzen_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
|
mapzen_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_mapzen_geocode_street_point($1, $2, $3, $4, $5, $6) as point; ", ["text", "text", "text", "text", "text", "text"])
|
||||||
else:
|
return plpy.execute(mapzen_plan, [username, orgname, searchtext, city, state_province, country], 1)[0]['point']
|
||||||
raise Exception('Requested geocoder is not available')
|
else:
|
||||||
|
raise Exception('Requested geocoder is not available')
|
||||||
|
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin0_polygon(us
|
|||||||
RETURNS Geometry AS $$
|
RETURNS Geometry AS $$
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.metrics import InternalGeocoderConfig
|
from cartodb_services.metrics import InternalGeocoderConfig
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
@@ -13,23 +14,24 @@ RETURNS Geometry AS $$
|
|||||||
logger_config = GD["logger_config"]
|
logger_config = GD["logger_config"]
|
||||||
logger = Logger(logger_config)
|
logger = Logger(logger_config)
|
||||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||||
try:
|
with metrics('cdb_geocode_admin0_polygon', user_geocoder_config, logger):
|
||||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin0_polygon(trim($1)) AS mypolygon", ["text"])
|
try:
|
||||||
rv = plpy.execute(plan, [country_name], 1)
|
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin0_polygon(trim($1)) AS mypolygon", ["text"])
|
||||||
result = rv[0]["mypolygon"]
|
rv = plpy.execute(plan, [country_name], 1)
|
||||||
if result:
|
result = rv[0]["mypolygon"]
|
||||||
quota_service.increment_success_service_use()
|
if result:
|
||||||
return result
|
quota_service.increment_success_service_use()
|
||||||
else:
|
return result
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return None
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return None
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to geocode admin0 polygon', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to geocode admin0 polygon')
|
logger.error('Error trying to geocode admin0 polygon', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to geocode admin0 polygon')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
---- cdb_geocode_admin1_polygon(admin1_name text)
|
---- cdb_geocode_admin1_polygon(admin1_name text)
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text)
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text)
|
||||||
RETURNS Geometry AS $$
|
RETURNS Geometry AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.metrics import InternalGeocoderConfig
|
from cartodb_services.metrics import InternalGeocoderConfig
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
@@ -14,44 +15,11 @@ RETURNS Geometry AS $$
|
|||||||
logger_config = GD["logger_config"]
|
logger_config = GD["logger_config"]
|
||||||
logger = Logger(logger_config)
|
logger = Logger(logger_config)
|
||||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||||
try:
|
|
||||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin1_polygon(trim($1)) AS mypolygon", ["text"])
|
|
||||||
rv = plpy.execute(plan, [admin1_name], 1)
|
|
||||||
result = rv[0]["mypolygon"]
|
|
||||||
if result:
|
|
||||||
quota_service.increment_success_service_use()
|
|
||||||
return result
|
|
||||||
else:
|
|
||||||
quota_service.increment_empty_service_use()
|
|
||||||
return None
|
|
||||||
except BaseException as e:
|
|
||||||
import sys
|
|
||||||
quota_service.increment_failed_service_use()
|
|
||||||
logger.error('Error trying to geocode admin1 polygon', sys.exc_info(), data={"username": username, "orgname": orgname})
|
|
||||||
raise Exception('Error trying to geocode admin1 polygon')
|
|
||||||
finally:
|
|
||||||
quota_service.increment_total_service_use()
|
|
||||||
$$ LANGUAGE plpythonu;
|
|
||||||
|
|
||||||
---- cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
with metrics('cdb_geocode_admin1_polygon', user_geocoder_config, logger):
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text)
|
|
||||||
RETURNS Geometry AS $$
|
|
||||||
from cartodb_services.metrics import QuotaService
|
|
||||||
from cartodb_services.metrics import InternalGeocoderConfig
|
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
|
||||||
|
|
||||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
|
||||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
|
||||||
plpy.execute("SELECT cdb_dataservices_server._get_internal_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
|
||||||
user_geocoder_config = GD["user_internal_geocoder_config_{0}".format(username)]
|
|
||||||
|
|
||||||
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
|
||||||
logger_config = GD["logger_config"]
|
|
||||||
logger = Logger(logger_config)
|
|
||||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
|
||||||
try:
|
try:
|
||||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin1_polygon(trim($1), trim($2)) AS mypolygon", ["text", "text"])
|
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin1_polygon(trim($1)) AS mypolygon", ["text"])
|
||||||
rv = plpy.execute(plan, [admin1_name, country_name], 1)
|
rv = plpy.execute(plan, [admin1_name], 1)
|
||||||
result = rv[0]["mypolygon"]
|
result = rv[0]["mypolygon"]
|
||||||
if result:
|
if result:
|
||||||
quota_service.increment_success_service_use()
|
quota_service.increment_success_service_use()
|
||||||
@@ -68,6 +36,44 @@ RETURNS Geometry AS $$
|
|||||||
quota_service.increment_total_service_use()
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
|
---- cdb_geocode_admin1_polygon(admin1_name text, country_name text)
|
||||||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_admin1_polygon(username text, orgname text, admin1_name text, country_name text)
|
||||||
|
RETURNS Geometry AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
|
from cartodb_services.metrics import QuotaService
|
||||||
|
from cartodb_services.metrics import InternalGeocoderConfig
|
||||||
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_internal_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
|
user_geocoder_config = GD["user_internal_geocoder_config_{0}".format(username)]
|
||||||
|
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
|
logger_config = GD["logger_config"]
|
||||||
|
logger = Logger(logger_config)
|
||||||
|
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||||
|
|
||||||
|
with metrics('cdb_geocode_admin1_polygon', user_geocoder_config, logger):
|
||||||
|
try:
|
||||||
|
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_admin1_polygon(trim($1), trim($2)) AS mypolygon", ["text", "text"])
|
||||||
|
rv = plpy.execute(plan, [admin1_name, country_name], 1)
|
||||||
|
result = rv[0]["mypolygon"]
|
||||||
|
if result:
|
||||||
|
quota_service.increment_success_service_use()
|
||||||
|
return result
|
||||||
|
else:
|
||||||
|
quota_service.increment_empty_service_use()
|
||||||
|
return None
|
||||||
|
except BaseException as e:
|
||||||
|
import sys
|
||||||
|
quota_service.increment_failed_service_use()
|
||||||
|
logger.error('Error trying to geocode admin1 polygon', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
|
raise Exception('Error trying to geocode admin1 polygon')
|
||||||
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- Implementation of the server extension
|
-- Implementation of the server extension
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_mapzen_geocode_namedplac
|
|||||||
RETURNS Geometry AS $$
|
RETURNS Geometry AS $$
|
||||||
from cartodb_services.mapzen import MapzenGeocoder
|
from cartodb_services.mapzen import MapzenGeocoder
|
||||||
from cartodb_services.mapzen.types import country_to_iso3
|
from cartodb_services.mapzen.types import country_to_iso3
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService, metrics
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
@@ -50,35 +50,36 @@ RETURNS Geometry AS $$
|
|||||||
if not quota_service.check_user_quota():
|
if not quota_service.check_user_quota():
|
||||||
raise Exception('You have reached the limit of your quota')
|
raise Exception('You have reached the limit of your quota')
|
||||||
|
|
||||||
try:
|
with metrics('cdb_geocode_namedplace_point', user_geocoder_config, logger):
|
||||||
geocoder = MapzenGeocoder(user_geocoder_config.mapzen_api_key, logger)
|
try:
|
||||||
country_iso3 = None
|
geocoder = MapzenGeocoder(user_geocoder_config.mapzen_api_key, logger)
|
||||||
if country_name:
|
country_iso3 = None
|
||||||
country_iso3 = country_to_iso3(country_name)
|
if country_name:
|
||||||
coordinates = geocoder.geocode(searchtext=city_name, city=None,
|
country_iso3 = country_to_iso3(country_name)
|
||||||
state_province=admin1_name,
|
coordinates = geocoder.geocode(searchtext=city_name, city=None,
|
||||||
country=country_iso3, search_type='locality')
|
state_province=admin1_name,
|
||||||
if coordinates:
|
country=country_iso3, search_type='locality')
|
||||||
quota_service.increment_success_service_use()
|
if coordinates:
|
||||||
plan = plpy.prepare("SELECT ST_SetSRID(ST_MakePoint($1, $2), 4326); ", ["double precision", "double precision"])
|
quota_service.increment_success_service_use()
|
||||||
point = plpy.execute(plan, [coordinates[0], coordinates[1]], 1)[0]
|
plan = plpy.prepare("SELECT ST_SetSRID(ST_MakePoint($1, $2), 4326); ", ["double precision", "double precision"])
|
||||||
return point['st_setsrid']
|
point = plpy.execute(plan, [coordinates[0], coordinates[1]], 1)[0]
|
||||||
else:
|
return point['st_setsrid']
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return None
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return None
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to geocode city point using mapzen', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to geocode city point using mapzen')
|
logger.error('Error trying to geocode city point using mapzen', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to geocode city point using mapzen')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_internal_geocode_namedplace(username text, orgname text, city_name text, admin1_name text DEFAULT NULL, country_name text DEFAULT NULL)
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_internal_geocode_namedplace(username text, orgname text, city_name text, admin1_name text DEFAULT NULL, country_name text DEFAULT NULL)
|
||||||
RETURNS Geometry AS $$
|
RETURNS Geometry AS $$
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.metrics import InternalGeocoderConfig
|
from cartodb_services.metrics import InternalGeocoderConfig, metrics
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
@@ -90,30 +91,32 @@ RETURNS Geometry AS $$
|
|||||||
logger_config = GD["logger_config"]
|
logger_config = GD["logger_config"]
|
||||||
logger = Logger(logger_config)
|
logger = Logger(logger_config)
|
||||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||||
try:
|
|
||||||
if admin1_name and country_name:
|
with metrics('cdb_geocode_namedplace_point', user_geocoder_config, logger):
|
||||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_namedplace_point(trim($1), trim($2), trim($3)) AS mypoint", ["text", "text", "text"])
|
try:
|
||||||
rv = plpy.execute(plan, [city_name, admin1_name, country_name], 1)
|
if admin1_name and country_name:
|
||||||
elif country_name:
|
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_namedplace_point(trim($1), trim($2), trim($3)) AS mypoint", ["text", "text", "text"])
|
||||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_namedplace_point(trim($1), trim($2)) AS mypoint", ["text", "text"])
|
rv = plpy.execute(plan, [city_name, admin1_name, country_name], 1)
|
||||||
rv = plpy.execute(plan, [city_name, country_name], 1)
|
elif country_name:
|
||||||
else:
|
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_namedplace_point(trim($1), trim($2)) AS mypoint", ["text", "text"])
|
||||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_namedplace_point(trim($1)) AS mypoint", ["text"])
|
rv = plpy.execute(plan, [city_name, country_name], 1)
|
||||||
rv = plpy.execute(plan, [city_name], 1)
|
else:
|
||||||
result = rv[0]["mypoint"]
|
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_namedplace_point(trim($1)) AS mypoint", ["text"])
|
||||||
if result:
|
rv = plpy.execute(plan, [city_name], 1)
|
||||||
quota_service.increment_success_service_use()
|
result = rv[0]["mypoint"]
|
||||||
return result
|
if result:
|
||||||
else:
|
quota_service.increment_success_service_use()
|
||||||
quota_service.increment_empty_service_use()
|
return result
|
||||||
return None
|
else:
|
||||||
except BaseException as e:
|
quota_service.increment_empty_service_use()
|
||||||
import sys
|
return None
|
||||||
quota_service.increment_failed_service_use()
|
except BaseException as e:
|
||||||
logger.error('Error trying to geocode namedplace point', sys.exc_info(), data={"username": username, "orgname": orgname})
|
import sys
|
||||||
raise Exception('Error trying to geocode namedplace point')
|
quota_service.increment_failed_service_use()
|
||||||
finally:
|
logger.error('Error trying to geocode namedplace point', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
quota_service.increment_total_service_use()
|
raise Exception('Error trying to geocode namedplace point')
|
||||||
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, code text)
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, code text)
|
||||||
RETURNS Geometry AS $$
|
RETURNS Geometry AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.metrics import InternalGeocoderConfig
|
from cartodb_services.metrics import InternalGeocoderConfig
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
@@ -13,27 +14,29 @@ RETURNS Geometry AS $$
|
|||||||
logger_config = GD["logger_config"]
|
logger_config = GD["logger_config"]
|
||||||
logger = Logger(logger_config)
|
logger = Logger(logger_config)
|
||||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||||
try:
|
with metrics('cdb_geocode_postalcode_point', user_geocoder_config, logger):
|
||||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_point(trim($1)) AS mypoint", ["text"])
|
try:
|
||||||
rv = plpy.execute(plan, [code], 1)
|
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_point(trim($1)) AS mypoint", ["text"])
|
||||||
result = rv[0]["mypoint"]
|
rv = plpy.execute(plan, [code], 1)
|
||||||
if result:
|
result = rv[0]["mypoint"]
|
||||||
quota_service.increment_success_service_use()
|
if result:
|
||||||
return result
|
quota_service.increment_success_service_use()
|
||||||
else:
|
return result
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return None
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return None
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to geocode postal code point', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to geocode postal code point')
|
logger.error('Error trying to geocode postal code point', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to geocode postal code point')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, code text, country text)
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_point(username text, orgname text, code text, country text)
|
||||||
RETURNS Geometry AS $$
|
RETURNS Geometry AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.metrics import InternalGeocoderConfig
|
from cartodb_services.metrics import InternalGeocoderConfig
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
@@ -47,27 +50,29 @@ RETURNS Geometry AS $$
|
|||||||
logger_config = GD["logger_config"]
|
logger_config = GD["logger_config"]
|
||||||
logger = Logger(logger_config)
|
logger = Logger(logger_config)
|
||||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||||
try:
|
with metrics('cdb_geocode_postalcode_point', user_geocoder_config, logger):
|
||||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_point(trim($1), trim($2)) AS mypoint", ["TEXT", "TEXT"])
|
try:
|
||||||
rv = plpy.execute(plan, [code, country], 1)
|
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_point(trim($1), trim($2)) AS mypoint", ["TEXT", "TEXT"])
|
||||||
result = rv[0]["mypoint"]
|
rv = plpy.execute(plan, [code, country], 1)
|
||||||
if result:
|
result = rv[0]["mypoint"]
|
||||||
quota_service.increment_success_service_use()
|
if result:
|
||||||
return result
|
quota_service.increment_success_service_use()
|
||||||
else:
|
return result
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return None
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return None
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to geocode postal code point', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to geocode postal code point')
|
logger.error('Error trying to geocode postal code point', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to geocode postal code point')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text)
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text)
|
||||||
RETURNS Geometry AS $$
|
RETURNS Geometry AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.metrics import InternalGeocoderConfig
|
from cartodb_services.metrics import InternalGeocoderConfig
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
@@ -81,27 +86,29 @@ RETURNS Geometry AS $$
|
|||||||
logger_config = GD["logger_config"]
|
logger_config = GD["logger_config"]
|
||||||
logger = Logger(logger_config)
|
logger = Logger(logger_config)
|
||||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||||
try:
|
with metrics('cdb_geocode_postalcode_point', user_geocoder_config, logger):
|
||||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_polygon(trim($1)) AS mypolygon", ["text"])
|
try:
|
||||||
rv = plpy.execute(plan, [code], 1)
|
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_polygon(trim($1)) AS mypolygon", ["text"])
|
||||||
result = rv[0]["mypolygon"]
|
rv = plpy.execute(plan, [code], 1)
|
||||||
if result:
|
result = rv[0]["mypolygon"]
|
||||||
quota_service.increment_success_service_use()
|
if result:
|
||||||
return result
|
quota_service.increment_success_service_use()
|
||||||
else:
|
return result
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return None
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return None
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to geocode postal code polygon', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to geocode postal code polygon')
|
logger.error('Error trying to geocode postal code polygon', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to geocode postal code polygon')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text, country text)
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_postalcode_polygon(username text, orgname text, code text, country text)
|
||||||
RETURNS Geometry AS $$
|
RETURNS Geometry AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.metrics import InternalGeocoderConfig
|
from cartodb_services.metrics import InternalGeocoderConfig
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
@@ -115,23 +122,24 @@ RETURNS Geometry AS $$
|
|||||||
logger_config = GD["logger_config"]
|
logger_config = GD["logger_config"]
|
||||||
logger = Logger(logger_config)
|
logger = Logger(logger_config)
|
||||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||||
try:
|
with metrics('cdb_geocode_postalcode_point', user_geocoder_config, logger):
|
||||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_polygon(trim($1), trim($2)) AS mypolygon", ["TEXT", "TEXT"])
|
try:
|
||||||
rv = plpy.execute(plan, [code, country], 1)
|
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_postalcode_polygon(trim($1), trim($2)) AS mypolygon", ["TEXT", "TEXT"])
|
||||||
result = rv[0]["mypolygon"]
|
rv = plpy.execute(plan, [code, country], 1)
|
||||||
if result:
|
result = rv[0]["mypolygon"]
|
||||||
quota_service.increment_success_service_use()
|
if result:
|
||||||
return result
|
quota_service.increment_success_service_use()
|
||||||
else:
|
return result
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return None
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return None
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to geocode postal code polygon', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to geocode postal code polygon')
|
logger.error('Error trying to geocode postal code polygon', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to geocode postal code polygon')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_ipaddress_point(username text, orgname text, ip text)
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_geocode_ipaddress_point(username text, orgname text, ip text)
|
||||||
RETURNS Geometry AS $$
|
RETURNS Geometry AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.metrics import InternalGeocoderConfig
|
from cartodb_services.metrics import InternalGeocoderConfig
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
@@ -13,23 +14,24 @@ RETURNS Geometry AS $$
|
|||||||
logger_config = GD["logger_config"]
|
logger_config = GD["logger_config"]
|
||||||
logger = Logger(logger_config)
|
logger = Logger(logger_config)
|
||||||
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
quota_service = QuotaService(user_geocoder_config, redis_conn)
|
||||||
try:
|
with metrics('cdb_geocode_ipaddress_point', user_geocoder_config, logger):
|
||||||
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_ipaddress_point(trim($1)) AS mypoint", ["TEXT"])
|
try:
|
||||||
rv = plpy.execute(plan, [ip], 1)
|
plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_geocode_ipaddress_point(trim($1)) AS mypoint", ["TEXT"])
|
||||||
result = rv[0]["mypoint"]
|
rv = plpy.execute(plan, [ip], 1)
|
||||||
if result:
|
result = rv[0]["mypoint"]
|
||||||
quota_service.increment_success_service_use()
|
if result:
|
||||||
return result
|
quota_service.increment_success_service_use()
|
||||||
else:
|
return result
|
||||||
quota_service.increment_empty_service_use()
|
else:
|
||||||
return None
|
quota_service.increment_empty_service_use()
|
||||||
except BaseException as e:
|
return None
|
||||||
import sys
|
except BaseException as e:
|
||||||
quota_service.increment_failed_service_use()
|
import sys
|
||||||
logger.error('Error trying to geocode postal code polygon', sys.exc_info(), data={"username": username, "orgname": orgname})
|
quota_service.increment_failed_service_use()
|
||||||
raise Exception('Error trying to geocode postal code polygon')
|
logger.error('Error trying to geocode postal code polygon', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
finally:
|
raise Exception('Error trying to geocode postal code polygon')
|
||||||
quota_service.increment_total_service_use()
|
finally:
|
||||||
|
quota_service.increment_total_service_use()
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,21 +1,28 @@
|
|||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_isochrone(username TEXT, orgname TEXT, source geometry(Geometry, 4326), mode TEXT, range integer[], options text[] DEFAULT array[]::text[])
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_isochrone(username TEXT, orgname TEXT, source geometry(Geometry, 4326), mode TEXT, range integer[], options text[] DEFAULT array[]::text[])
|
||||||
RETURNS SETOF cdb_dataservices_server.isoline AS $$
|
RETURNS SETOF cdb_dataservices_server.isoline AS $$
|
||||||
|
from cartodb_services.metrics import metrics
|
||||||
|
from cartodb_services.tools import Logger
|
||||||
|
|
||||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection']
|
||||||
plpy.execute("SELECT cdb_dataservices_server._get_isolines_routing_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
plpy.execute("SELECT cdb_dataservices_server._get_isolines_routing_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||||||
user_isolines_config = GD["user_isolines_routing_config_{0}".format(username)]
|
user_isolines_config = GD["user_isolines_routing_config_{0}".format(username)]
|
||||||
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
|
logger_config = GD["logger_config"]
|
||||||
|
logger = Logger(logger_config)
|
||||||
|
|
||||||
if user_isolines_config.google_services_user:
|
if user_isolines_config.google_services_user:
|
||||||
raise Exception('This service is not available for google service users.')
|
raise Exception('This service is not available for google service users.')
|
||||||
|
|
||||||
if user_isolines_config.heremaps_provider:
|
with metrics('cb_isochrone', user_isolines_config, logger):
|
||||||
here_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server.cdb_here_isochrone($1, $2, $3, $4, $5, $6) as isoline; ", ["text", "text", "geometry(geometry, 4326)", "text", "integer[]", "text[]"])
|
if user_isolines_config.heremaps_provider:
|
||||||
return plpy.execute(here_plan, [username, orgname, source, mode, range, options])
|
here_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server.cdb_here_isochrone($1, $2, $3, $4, $5, $6) as isoline; ", ["text", "text", "geometry(geometry, 4326)", "text", "integer[]", "text[]"])
|
||||||
elif user_isolines_config.mapzen_provider:
|
return plpy.execute(here_plan, [username, orgname, source, mode, range, options])
|
||||||
mapzen_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server.cdb_mapzen_isochrone($1, $2, $3, $4, $5, $6) as isoline; ", ["text", "text", "geometry(geometry, 4326)", "text", "integer[]", "text[]"])
|
elif user_isolines_config.mapzen_provider:
|
||||||
return plpy.execute(mapzen_plan, [username, orgname, source, mode, range, options])
|
mapzen_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server.cdb_mapzen_isochrone($1, $2, $3, $4, $5, $6) as isoline; ", ["text", "text", "geometry(geometry, 4326)", "text", "integer[]", "text[]"])
|
||||||
else:
|
return plpy.execute(mapzen_plan, [username, orgname, source, mode, range, options])
|
||||||
raise Exception('Requested isolines provider is not available')
|
else:
|
||||||
|
raise Exception('Requested isolines provider is not available')
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
-- heremaps isochrone
|
-- heremaps isochrone
|
||||||
|
|||||||
@@ -185,3 +185,58 @@ SELECT exists(SELECT *
|
|||||||
t
|
t
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
SELECT exists(SELECT *
|
||||||
|
FROM pg_proc p
|
||||||
|
INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)
|
||||||
|
WHERE ns.nspname = 'cdb_dataservices_server'
|
||||||
|
AND proname = 'obs_getavailablenumerators'
|
||||||
|
AND oidvectortypes(p.proargtypes) = 'text, text, geometry, text[], text, text, text');
|
||||||
|
exists
|
||||||
|
--------
|
||||||
|
t
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT exists(SELECT *
|
||||||
|
FROM pg_proc p
|
||||||
|
INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)
|
||||||
|
WHERE ns.nspname = 'cdb_dataservices_server'
|
||||||
|
AND proname = 'obs_getavailabledenominators'
|
||||||
|
AND oidvectortypes(p.proargtypes) = 'text, text, geometry, text[], text, text, text');
|
||||||
|
exists
|
||||||
|
--------
|
||||||
|
t
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT exists(SELECT *
|
||||||
|
FROM pg_proc p
|
||||||
|
INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)
|
||||||
|
WHERE ns.nspname = 'cdb_dataservices_server'
|
||||||
|
AND proname = 'obs_getavailablegeometries'
|
||||||
|
AND oidvectortypes(p.proargtypes) = 'text, text, geometry, text[], text, text, text');
|
||||||
|
exists
|
||||||
|
--------
|
||||||
|
t
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT exists(SELECT *
|
||||||
|
FROM pg_proc p
|
||||||
|
INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)
|
||||||
|
WHERE ns.nspname = 'cdb_dataservices_server'
|
||||||
|
AND proname = 'obs_getavailabletimespans'
|
||||||
|
AND oidvectortypes(p.proargtypes) = 'text, text, geometry, text[], text, text, text');
|
||||||
|
exists
|
||||||
|
--------
|
||||||
|
t
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SELECT exists(SELECT *
|
||||||
|
FROM pg_proc p
|
||||||
|
INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)
|
||||||
|
WHERE ns.nspname = 'cdb_dataservices_server'
|
||||||
|
AND proname = 'obs_legacybuildermetadata'
|
||||||
|
AND oidvectortypes(p.proargtypes) = 'text, text, text');
|
||||||
|
exists
|
||||||
|
--------
|
||||||
|
t
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
|||||||
@@ -115,4 +115,39 @@ SELECT exists(SELECT *
|
|||||||
INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)
|
INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)
|
||||||
WHERE ns.nspname = 'cdb_dataservices_server'
|
WHERE ns.nspname = 'cdb_dataservices_server'
|
||||||
AND proname = 'obs_getpointsbypointandradius'
|
AND proname = 'obs_getpointsbypointandradius'
|
||||||
AND oidvectortypes(p.proargtypes) = 'text, text, geometry, numeric, text, text, text');
|
AND oidvectortypes(p.proargtypes) = 'text, text, geometry, numeric, text, text, text');
|
||||||
|
|
||||||
|
SELECT exists(SELECT *
|
||||||
|
FROM pg_proc p
|
||||||
|
INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)
|
||||||
|
WHERE ns.nspname = 'cdb_dataservices_server'
|
||||||
|
AND proname = 'obs_getavailablenumerators'
|
||||||
|
AND oidvectortypes(p.proargtypes) = 'text, text, geometry, text[], text, text, text');
|
||||||
|
|
||||||
|
SELECT exists(SELECT *
|
||||||
|
FROM pg_proc p
|
||||||
|
INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)
|
||||||
|
WHERE ns.nspname = 'cdb_dataservices_server'
|
||||||
|
AND proname = 'obs_getavailabledenominators'
|
||||||
|
AND oidvectortypes(p.proargtypes) = 'text, text, geometry, text[], text, text, text');
|
||||||
|
|
||||||
|
SELECT exists(SELECT *
|
||||||
|
FROM pg_proc p
|
||||||
|
INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)
|
||||||
|
WHERE ns.nspname = 'cdb_dataservices_server'
|
||||||
|
AND proname = 'obs_getavailablegeometries'
|
||||||
|
AND oidvectortypes(p.proargtypes) = 'text, text, geometry, text[], text, text, text');
|
||||||
|
|
||||||
|
SELECT exists(SELECT *
|
||||||
|
FROM pg_proc p
|
||||||
|
INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)
|
||||||
|
WHERE ns.nspname = 'cdb_dataservices_server'
|
||||||
|
AND proname = 'obs_getavailabletimespans'
|
||||||
|
AND oidvectortypes(p.proargtypes) = 'text, text, geometry, text[], text, text, text');
|
||||||
|
|
||||||
|
SELECT exists(SELECT *
|
||||||
|
FROM pg_proc p
|
||||||
|
INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)
|
||||||
|
WHERE ns.nspname = 'cdb_dataservices_server'
|
||||||
|
AND proname = 'obs_legacybuildermetadata'
|
||||||
|
AND oidvectortypes(p.proargtypes) = 'text, text, text');
|
||||||
|
|||||||
@@ -29,12 +29,12 @@ NOTE: a system installation is required at present because the library is meant
|
|||||||
|
|
||||||
|
|
||||||
## Running the unit tests
|
## Running the unit tests
|
||||||
Just run `nosetests`
|
Just run `nosetests test/`
|
||||||
```shell
|
```shell
|
||||||
$ nosetests
|
$ nosetests test/
|
||||||
.................................................
|
......................................................................................................
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
Ran 49 tests in 0.131s
|
Ran 102 tests in 0.122s
|
||||||
|
|
||||||
OK
|
OK
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -5,15 +5,18 @@ import json
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
from exceptions import *
|
from exceptions import *
|
||||||
|
from cartodb_services.metrics import Traceable
|
||||||
|
|
||||||
|
|
||||||
class HereMapsGeocoder:
|
class HereMapsGeocoder(Traceable):
|
||||||
'A Here Maps Geocoder wrapper for python'
|
'A Here Maps Geocoder wrapper for python'
|
||||||
|
|
||||||
PRODUCTION_GEOCODE_JSON_URL = 'https://geocoder.api.here.com/6.2/geocode.json'
|
PRODUCTION_GEOCODE_JSON_URL = 'https://geocoder.api.here.com/6.2/geocode.json'
|
||||||
STAGING_GEOCODE_JSON_URL = 'https://geocoder.cit.api.here.com/6.2/geocode.json'
|
STAGING_GEOCODE_JSON_URL = 'https://geocoder.cit.api.here.com/6.2/geocode.json'
|
||||||
DEFAULT_MAXRESULTS = 1
|
DEFAULT_MAXRESULTS = 1
|
||||||
DEFAULT_GEN = 9
|
DEFAULT_GEN = 9
|
||||||
|
READ_TIMEOUT = 60
|
||||||
|
CONNECT_TIMEOUT = 10
|
||||||
|
|
||||||
ADDRESS_PARAMS = [
|
ADDRESS_PARAMS = [
|
||||||
'city',
|
'city',
|
||||||
@@ -85,7 +88,9 @@ class HereMapsGeocoder:
|
|||||||
'gen': self.gen
|
'gen': self.gen
|
||||||
}
|
}
|
||||||
request_params.update(params)
|
request_params.update(params)
|
||||||
response = requests.get(self.host, params=request_params)
|
response = requests.get(self.host, params=request_params,
|
||||||
|
timeout=(self.CONNECT_TIMEOUT, self.READ_TIMEOUT))
|
||||||
|
self.add_response_data(response, self._logger)
|
||||||
if response.status_code == requests.codes.ok:
|
if response.status_code == requests.codes.ok:
|
||||||
return json.loads(response.text)
|
return json.loads(response.text)
|
||||||
elif response.status_code == requests.codes.bad_request:
|
elif response.status_code == requests.codes.bad_request:
|
||||||
|
|||||||
@@ -2,14 +2,17 @@ import requests
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from exceptions import WrongParams
|
from exceptions import WrongParams
|
||||||
|
from cartodb_services.metrics import Traceable
|
||||||
|
|
||||||
|
|
||||||
class HereMapsRoutingIsoline:
|
class HereMapsRoutingIsoline(Traceable):
|
||||||
'A Here Maps Routing wrapper for python'
|
'A Here Maps Routing wrapper for python'
|
||||||
|
|
||||||
PRODUCTION_ROUTING_BASE_URL = 'https://isoline.route.api.here.com'
|
PRODUCTION_ROUTING_BASE_URL = 'https://isoline.route.api.here.com'
|
||||||
STAGING_ROUTING_BASE_URL = 'https://isoline.route.cit.api.here.com'
|
STAGING_ROUTING_BASE_URL = 'https://isoline.route.cit.api.here.com'
|
||||||
ISOLINE_PATH = '/routing/7.2/calculateisoline.json'
|
ISOLINE_PATH = '/routing/7.2/calculateisoline.json'
|
||||||
|
READ_TIMEOUT = 60
|
||||||
|
CONNECT_TIMEOUT = 10
|
||||||
|
|
||||||
ACCEPTED_MODES = {
|
ACCEPTED_MODES = {
|
||||||
"walk": "pedestrian",
|
"walk": "pedestrian",
|
||||||
@@ -50,7 +53,9 @@ class HereMapsRoutingIsoline:
|
|||||||
data_range,
|
data_range,
|
||||||
range_type,
|
range_type,
|
||||||
parsed_options)
|
parsed_options)
|
||||||
response = requests.get(self._url, params=request_params)
|
response = requests.get(self._url, params=request_params,
|
||||||
|
timeout=(self.CONNECT_TIMEOUT, self.READ_TIMEOUT))
|
||||||
|
self.add_response_data(response, self._logger)
|
||||||
if response.status_code == requests.codes.ok:
|
if response.status_code == requests.codes.ok:
|
||||||
return self.__parse_isolines_response(response.text)
|
return self.__parse_isolines_response(response.text)
|
||||||
elif response.status_code == requests.codes.bad_request:
|
elif response.status_code == requests.codes.bad_request:
|
||||||
|
|||||||
@@ -5,12 +5,15 @@ import re
|
|||||||
from exceptions import WrongParams, MalformedResult, ServiceException
|
from exceptions import WrongParams, MalformedResult, ServiceException
|
||||||
from qps import qps_retry
|
from qps import qps_retry
|
||||||
from cartodb_services.tools import Coordinate, PolyLine
|
from cartodb_services.tools import Coordinate, PolyLine
|
||||||
|
from cartodb_services.metrics import Traceable
|
||||||
|
|
||||||
|
|
||||||
class MapzenGeocoder:
|
class MapzenGeocoder(Traceable):
|
||||||
'A Mapzen Geocoder wrapper for python'
|
'A Mapzen Geocoder wrapper for python'
|
||||||
|
|
||||||
BASE_URL = 'https://search.mapzen.com/v1/search'
|
BASE_URL = 'https://search.mapzen.com/v1/search'
|
||||||
|
READ_TIMEOUT = 60
|
||||||
|
CONNECT_TIMEOUT = 10
|
||||||
|
|
||||||
def __init__(self, app_key, logger, base_url=BASE_URL):
|
def __init__(self, app_key, logger, base_url=BASE_URL):
|
||||||
self._app_key = app_key
|
self._app_key = app_key
|
||||||
@@ -24,7 +27,9 @@ class MapzenGeocoder:
|
|||||||
state_province,
|
state_province,
|
||||||
country, search_type)
|
country, search_type)
|
||||||
try:
|
try:
|
||||||
response = requests.get(self._url, params=request_params)
|
response = requests.get(self._url, params=request_params,
|
||||||
|
timeout=(self.CONNECT_TIMEOUT, self.READ_TIMEOUT))
|
||||||
|
self.add_response_data(response, self._logger)
|
||||||
if response.status_code == requests.codes.ok:
|
if response.status_code == requests.codes.ok:
|
||||||
return self.__parse_response(response.text)
|
return self.__parse_response(response.text)
|
||||||
elif response.status_code == requests.codes.bad_request:
|
elif response.status_code == requests.codes.bad_request:
|
||||||
@@ -41,6 +46,12 @@ class MapzenGeocoder:
|
|||||||
"state_province": state_province})
|
"state_province": state_province})
|
||||||
raise ServiceException('Error trying to geocode {0} using mapzen'.format(searchtext),
|
raise ServiceException('Error trying to geocode {0} using mapzen'.format(searchtext),
|
||||||
response)
|
response)
|
||||||
|
except requests.Timeout as te:
|
||||||
|
# In case of timeout we want to stop the job because the server
|
||||||
|
# could be down
|
||||||
|
self._logger.error('Timeout connecting to Mapzen geocoding server')
|
||||||
|
raise ServiceException('Error trying to geocode {0} using mapzen'.format(searchtext),
|
||||||
|
None)
|
||||||
except requests.ConnectionError as e:
|
except requests.ConnectionError as e:
|
||||||
# Don't raise the exception to continue with the geocoding job
|
# Don't raise the exception to continue with the geocoding job
|
||||||
self._logger.error('Error connecting to Mapzen geocoding server',
|
self._logger.error('Error connecting to Mapzen geocoding server',
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ class MapzenIsolines:
|
|||||||
def calculate_isoline(self, origin, costing_model, isorange, upper_rmax, cost_variable, unit_factor=1.0):
|
def calculate_isoline(self, origin, costing_model, isorange, upper_rmax, cost_variable, unit_factor=1.0):
|
||||||
|
|
||||||
# NOTE: not for production
|
# NOTE: not for production
|
||||||
self._logger.debug('Calculate isoline', data={"origin": origin, "costing_model": costing_model, "isorange": isorange})
|
# self._logger.debug('Calculate isoline', data={"origin": origin, "costing_model": costing_model, "isorange": isorange})
|
||||||
|
|
||||||
# Formally, a solution is an array of {angle, radius, lat, lon, cost} with cardinality NUMBER_OF_ANGLES
|
# Formally, a solution is an array of {angle, radius, lat, lon, cost} with cardinality NUMBER_OF_ANGLES
|
||||||
# we're looking for a solution in which abs(cost - isorange) / isorange <= TOLERANCE
|
# we're looking for a solution in which abs(cost - isorange) / isorange <= TOLERANCE
|
||||||
@@ -105,14 +105,16 @@ class MapzenIsolines:
|
|||||||
|
|
||||||
response = self._matrix_client.one_to_many([origin] + location_estimates, costing_model)
|
response = self._matrix_client.one_to_many([origin] + location_estimates, costing_model)
|
||||||
costs = [None] * self.NUMBER_OF_ANGLES
|
costs = [None] * self.NUMBER_OF_ANGLES
|
||||||
|
if not response:
|
||||||
|
# In case the matrix client doesn't return any data
|
||||||
|
break
|
||||||
|
|
||||||
for idx, c in enumerate(response['one_to_many'][0][1:]):
|
for idx, c in enumerate(response['one_to_many'][0][1:]):
|
||||||
if c[cost_variable]:
|
if c[cost_variable]:
|
||||||
costs[idx] = c[cost_variable]*unit_factor
|
costs[idx] = c[cost_variable]*unit_factor
|
||||||
else:
|
else:
|
||||||
costs[idx] = isorange
|
costs[idx] = isorange
|
||||||
|
|
||||||
# self._logger.debug('i = %d, costs = %s' % (i, costs))
|
|
||||||
|
|
||||||
errors = [(cost - isorange) / float(isorange) for cost in costs]
|
errors = [(cost - isorange) / float(isorange) for cost in costs]
|
||||||
max_abs_error = max([abs(e) for e in errors])
|
max_abs_error = max([abs(e) for e in errors])
|
||||||
if max_abs_error <= self.TOLERANCE:
|
if max_abs_error <= self.TOLERANCE:
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ import requests
|
|||||||
import json
|
import json
|
||||||
from qps import qps_retry
|
from qps import qps_retry
|
||||||
from exceptions import ServiceException
|
from exceptions import ServiceException
|
||||||
|
from cartodb_services.metrics import Traceable
|
||||||
|
|
||||||
|
|
||||||
class MatrixClient:
|
class MatrixClient(Traceable):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
A minimal client for Mapzen Time-Distance Matrix Service
|
A minimal client for Mapzen Time-Distance Matrix Service
|
||||||
@@ -19,6 +20,8 @@ class MatrixClient:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
ONE_TO_MANY_URL = 'https://matrix.mapzen.com/one_to_many'
|
ONE_TO_MANY_URL = 'https://matrix.mapzen.com/one_to_many'
|
||||||
|
READ_TIMEOUT = 60
|
||||||
|
CONNECT_TIMEOUT = 10
|
||||||
|
|
||||||
def __init__(self, matrix_key, logger):
|
def __init__(self, matrix_key, logger):
|
||||||
self._matrix_key = matrix_key
|
self._matrix_key = matrix_key
|
||||||
@@ -41,9 +44,11 @@ class MatrixClient:
|
|||||||
'costing': costing,
|
'costing': costing,
|
||||||
'api_key': self._matrix_key
|
'api_key': self._matrix_key
|
||||||
}
|
}
|
||||||
response = requests.get(self.ONE_TO_MANY_URL, params=request_params)
|
response = requests.get(self.ONE_TO_MANY_URL, params=request_params,
|
||||||
|
timeout=(self.CONNECT_TIMEOUT, self.READ_TIMEOUT))
|
||||||
|
self.add_response_data(response, self._logger)
|
||||||
|
|
||||||
if not requests.codes.ok:
|
if response.status_code != requests.codes.ok:
|
||||||
self._logger.error('Error trying to get matrix distance from mapzen',
|
self._logger.error('Error trying to get matrix distance from mapzen',
|
||||||
data={"response_status": response.status_code,
|
data={"response_status": response.status_code,
|
||||||
"response_reason": response.reason,
|
"response_reason": response.reason,
|
||||||
@@ -52,6 +57,22 @@ class MatrixClient:
|
|||||||
"response_headers": response.headers,
|
"response_headers": response.headers,
|
||||||
"locations": locations,
|
"locations": locations,
|
||||||
"costing": costing})
|
"costing": costing})
|
||||||
raise ServiceException("Error trying to get matrix distance from mapzen", response)
|
# In case 4xx error we return empty because the error comes from
|
||||||
|
# the provided info by the user and we don't want to top the
|
||||||
|
# isolines generation
|
||||||
|
if response.status_code == requests.codes.bad_request:
|
||||||
|
return {}
|
||||||
|
elif response.status_code == 504:
|
||||||
|
# Due to some unsolved problems in the Mapzen Matrix API we're
|
||||||
|
# getting randomly 504, probably timeouts. To avoid raise an
|
||||||
|
# exception in all the jobs, for now we're going to return
|
||||||
|
# empty in that case
|
||||||
|
return {}
|
||||||
|
else:
|
||||||
|
raise ServiceException("Error trying to get matrix distance from mapzen", response)
|
||||||
|
|
||||||
return response.json()
|
# response could return with empty json
|
||||||
|
try:
|
||||||
|
return response.json()
|
||||||
|
except:
|
||||||
|
return {}
|
||||||
|
|||||||
@@ -5,12 +5,15 @@ import re
|
|||||||
from exceptions import WrongParams, MalformedResult, ServiceException
|
from exceptions import WrongParams, MalformedResult, ServiceException
|
||||||
from qps import qps_retry
|
from qps import qps_retry
|
||||||
from cartodb_services.tools import Coordinate, PolyLine
|
from cartodb_services.tools import Coordinate, PolyLine
|
||||||
|
from cartodb_services.metrics import MetricsDataGatherer, Traceable
|
||||||
|
|
||||||
|
|
||||||
class MapzenRouting:
|
class MapzenRouting(Traceable):
|
||||||
'A Mapzen Routing wrapper for python'
|
'A Mapzen Routing wrapper for python'
|
||||||
|
|
||||||
PRODUCTION_ROUTING_BASE_URL = 'https://valhalla.mapzen.com/route'
|
PRODUCTION_ROUTING_BASE_URL = 'https://valhalla.mapzen.com/route'
|
||||||
|
READ_TIMEOUT = 60
|
||||||
|
CONNECT_TIMEOUT = 10
|
||||||
|
|
||||||
ACCEPTED_MODES = {
|
ACCEPTED_MODES = {
|
||||||
"walk": "pedestrian",
|
"walk": "pedestrian",
|
||||||
@@ -43,7 +46,9 @@ class MapzenRouting:
|
|||||||
mode_param,
|
mode_param,
|
||||||
units)
|
units)
|
||||||
request_params = self.__parse_request_parameters(json_request_params)
|
request_params = self.__parse_request_parameters(json_request_params)
|
||||||
response = requests.get(self._url, params=request_params)
|
response = requests.get(self._url, params=request_params,
|
||||||
|
timeout=(self.CONNECT_TIMEOUT, self.READ_TIMEOUT))
|
||||||
|
self.add_response_data(response, self._logger)
|
||||||
if response.status_code == requests.codes.ok:
|
if response.status_code == requests.codes.ok:
|
||||||
return self.__parse_routing_response(response.text)
|
return self.__parse_routing_response(response.text)
|
||||||
elif response.status_code == requests.codes.bad_request:
|
elif response.status_code == requests.codes.bad_request:
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
from config import GeocoderConfig, IsolinesRoutingConfig, InternalGeocoderConfig, RoutingConfig, ConfigException, ObservatorySnapshotConfig, ObservatoryConfig
|
from config import GeocoderConfig, IsolinesRoutingConfig, InternalGeocoderConfig, RoutingConfig, ConfigException, ObservatorySnapshotConfig, ObservatoryConfig
|
||||||
from quota import QuotaService
|
from quota import QuotaService
|
||||||
from user import UserMetricsService
|
from user import UserMetricsService
|
||||||
|
from log import metrics, MetricsDataGatherer, Traceable
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class ServiceConfig(object):
|
|||||||
self._username = username
|
self._username = username
|
||||||
self._orgname = orgname
|
self._orgname = orgname
|
||||||
self._db_config = ServicesDBConfig(db_conn, username, orgname)
|
self._db_config = ServicesDBConfig(db_conn, username, orgname)
|
||||||
|
self._metrics_log_path = self.__get_metrics_log_path()
|
||||||
self._environment = self._db_config._server_environment
|
self._environment = self._db_config._server_environment
|
||||||
if redis_connection:
|
if redis_connection:
|
||||||
self._redis_config = ServicesRedisConfig(redis_connection).build(
|
self._redis_config = ServicesRedisConfig(redis_connection).build(
|
||||||
@@ -38,9 +39,20 @@ class ServiceConfig(object):
|
|||||||
def environment(self):
|
def environment(self):
|
||||||
return self._environment
|
return self._environment
|
||||||
|
|
||||||
|
@property
|
||||||
|
def metrics_log_path(self):
|
||||||
|
return self._metrics_log_path
|
||||||
|
|
||||||
|
def __get_metrics_log_path(self):
|
||||||
|
if self.METRICS_LOG_KEY:
|
||||||
|
return self._db_config.logger_config.get(self.METRICS_LOG_KEY, None)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
class DataObservatoryConfig(ServiceConfig):
|
class DataObservatoryConfig(ServiceConfig):
|
||||||
|
|
||||||
|
METRICS_LOG_KEY = 'do_log_path'
|
||||||
|
|
||||||
def __init__(self, redis_connection, db_conn, username, orgname=None):
|
def __init__(self, redis_connection, db_conn, username, orgname=None):
|
||||||
super(DataObservatoryConfig, self).__init__(redis_connection, db_conn,
|
super(DataObservatoryConfig, self).__init__(redis_connection, db_conn,
|
||||||
username, orgname)
|
username, orgname)
|
||||||
@@ -61,6 +73,10 @@ class DataObservatoryConfig(ServiceConfig):
|
|||||||
def connection_str(self):
|
def connection_str(self):
|
||||||
return self._connection_str
|
return self._connection_str
|
||||||
|
|
||||||
|
@property
|
||||||
|
def provider(self):
|
||||||
|
return 'data observatory'
|
||||||
|
|
||||||
|
|
||||||
class ObservatorySnapshotConfig(DataObservatoryConfig):
|
class ObservatorySnapshotConfig(DataObservatoryConfig):
|
||||||
|
|
||||||
@@ -78,7 +94,7 @@ class ObservatorySnapshotConfig(DataObservatoryConfig):
|
|||||||
self._soft_limit = False
|
self._soft_limit = False
|
||||||
self._monthly_quota = 0
|
self._monthly_quota = 0
|
||||||
if self.QUOTA_KEY in self._redis_config:
|
if self.QUOTA_KEY in self._redis_config:
|
||||||
self._monthly_quota = float(self._redis_config[self.QUOTA_KEY])
|
self._monthly_quota = int(self._redis_config[self.QUOTA_KEY])
|
||||||
self._connection_str = self._db_config.data_observatory_connection_str
|
self._connection_str = self._db_config.data_observatory_connection_str
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -102,7 +118,7 @@ class ObservatoryConfig(DataObservatoryConfig):
|
|||||||
self._soft_limit = False
|
self._soft_limit = False
|
||||||
self._monthly_quota = 0
|
self._monthly_quota = 0
|
||||||
if self.QUOTA_KEY in self._redis_config:
|
if self.QUOTA_KEY in self._redis_config:
|
||||||
self._monthly_quota = float(self._redis_config[self.QUOTA_KEY])
|
self._monthly_quota = int(self._redis_config[self.QUOTA_KEY])
|
||||||
self._connection_str = self._db_config.data_observatory_connection_str
|
self._connection_str = self._db_config.data_observatory_connection_str
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -118,6 +134,7 @@ class RoutingConfig(ServiceConfig):
|
|||||||
DEFAULT_PROVIDER = 'mapzen'
|
DEFAULT_PROVIDER = 'mapzen'
|
||||||
QUOTA_KEY = 'mapzen_routing_quota'
|
QUOTA_KEY = 'mapzen_routing_quota'
|
||||||
SOFT_LIMIT_KEY = 'soft_mapzen_routing_limit'
|
SOFT_LIMIT_KEY = 'soft_mapzen_routing_limit'
|
||||||
|
METRICS_LOG_KEY = 'routing_log_path'
|
||||||
|
|
||||||
def __init__(self, redis_connection, db_conn, username, orgname=None):
|
def __init__(self, redis_connection, db_conn, username, orgname=None):
|
||||||
super(RoutingConfig, self).__init__(redis_connection, db_conn,
|
super(RoutingConfig, self).__init__(redis_connection, db_conn,
|
||||||
@@ -135,6 +152,10 @@ class RoutingConfig(ServiceConfig):
|
|||||||
if self._routing_provider == self.MAPZEN_PROVIDER:
|
if self._routing_provider == self.MAPZEN_PROVIDER:
|
||||||
return 'routing_mapzen'
|
return 'routing_mapzen'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def provider(self):
|
||||||
|
return self._routing_provider
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def mapzen_api_key(self):
|
def mapzen_api_key(self):
|
||||||
return self._mapzen_api_key
|
return self._mapzen_api_key
|
||||||
@@ -151,7 +172,6 @@ class RoutingConfig(ServiceConfig):
|
|||||||
def soft_limit(self):
|
def soft_limit(self):
|
||||||
return self._soft_limit
|
return self._soft_limit
|
||||||
|
|
||||||
|
|
||||||
def _set_monthly_quota(self):
|
def _set_monthly_quota(self):
|
||||||
self._monthly_quota = self._get_effective_monthly_quota()
|
self._monthly_quota = self._get_effective_monthly_quota()
|
||||||
|
|
||||||
@@ -169,7 +189,6 @@ class RoutingConfig(ServiceConfig):
|
|||||||
self._soft_limit = False
|
self._soft_limit = False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class IsolinesRoutingConfig(ServiceConfig):
|
class IsolinesRoutingConfig(ServiceConfig):
|
||||||
|
|
||||||
ISOLINES_CONFIG_KEYS = ['here_isolines_quota', 'soft_here_isolines_limit',
|
ISOLINES_CONFIG_KEYS = ['here_isolines_quota', 'soft_here_isolines_limit',
|
||||||
@@ -184,6 +203,7 @@ class IsolinesRoutingConfig(ServiceConfig):
|
|||||||
MAPZEN_PROVIDER = 'mapzen'
|
MAPZEN_PROVIDER = 'mapzen'
|
||||||
HEREMAPS_PROVIDER = 'heremaps'
|
HEREMAPS_PROVIDER = 'heremaps'
|
||||||
DEFAULT_PROVIDER = 'heremaps'
|
DEFAULT_PROVIDER = 'heremaps'
|
||||||
|
METRICS_LOG_KEY = 'isolines_log_path'
|
||||||
|
|
||||||
def __init__(self, redis_connection, db_conn, username, orgname=None):
|
def __init__(self, redis_connection, db_conn, username, orgname=None):
|
||||||
super(IsolinesRoutingConfig, self).__init__(redis_connection, db_conn,
|
super(IsolinesRoutingConfig, self).__init__(redis_connection, db_conn,
|
||||||
@@ -198,7 +218,7 @@ class IsolinesRoutingConfig(ServiceConfig):
|
|||||||
self._geocoder_provider = filtered_config[self.GEOCODER_PROVIDER_KEY].lower()
|
self._geocoder_provider = filtered_config[self.GEOCODER_PROVIDER_KEY].lower()
|
||||||
self._period_end_date = date_parse(filtered_config[self.PERIOD_END_DATE])
|
self._period_end_date = date_parse(filtered_config[self.PERIOD_END_DATE])
|
||||||
if self._isolines_provider == self.HEREMAPS_PROVIDER:
|
if self._isolines_provider == self.HEREMAPS_PROVIDER:
|
||||||
self._isolines_quota = float(filtered_config[self.QUOTA_KEY])
|
self._isolines_quota = int(filtered_config[self.QUOTA_KEY])
|
||||||
self._heremaps_app_id = db_config.heremaps_isolines_app_id
|
self._heremaps_app_id = db_config.heremaps_isolines_app_id
|
||||||
self._heremaps_app_code = db_config.heremaps_isolines_app_code
|
self._heremaps_app_code = db_config.heremaps_isolines_app_code
|
||||||
if filtered_config[self.SOFT_LIMIT_KEY].lower() == 'true':
|
if filtered_config[self.SOFT_LIMIT_KEY].lower() == 'true':
|
||||||
@@ -260,11 +280,12 @@ class IsolinesRoutingConfig(ServiceConfig):
|
|||||||
|
|
||||||
class InternalGeocoderConfig(ServiceConfig):
|
class InternalGeocoderConfig(ServiceConfig):
|
||||||
|
|
||||||
|
METRICS_LOG_KEY = 'geocoder_log_path'
|
||||||
|
|
||||||
def __init__(self, redis_connection, db_conn, username, orgname=None):
|
def __init__(self, redis_connection, db_conn, username, orgname=None):
|
||||||
# For now, internal geocoder doesn't use the redis config
|
# For now, internal geocoder doesn't use the redis config
|
||||||
super(InternalGeocoderConfig, self).__init__(None, db_conn,
|
super(InternalGeocoderConfig, self).__init__(None, db_conn,
|
||||||
username, orgname)
|
username, orgname)
|
||||||
self._log_path = self._db_config.geocoder_log_path
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def service_type(self):
|
def service_type(self):
|
||||||
@@ -283,8 +304,8 @@ class InternalGeocoderConfig(ServiceConfig):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def log_path(self):
|
def provider(self):
|
||||||
return self._log_path
|
return 'internal'
|
||||||
|
|
||||||
|
|
||||||
class GeocoderConfig(ServiceConfig):
|
class GeocoderConfig(ServiceConfig):
|
||||||
@@ -310,6 +331,7 @@ class GeocoderConfig(ServiceConfig):
|
|||||||
ORGNAME_KEY = 'orgname'
|
ORGNAME_KEY = 'orgname'
|
||||||
PERIOD_END_DATE = 'period_end_date'
|
PERIOD_END_DATE = 'period_end_date'
|
||||||
DEFAULT_PROVIDER = 'mapzen'
|
DEFAULT_PROVIDER = 'mapzen'
|
||||||
|
METRICS_LOG_KEY = 'geocoder_log_path'
|
||||||
|
|
||||||
def __init__(self, redis_connection, db_conn, username, orgname=None, forced_provider=None):
|
def __init__(self, redis_connection, db_conn, username, orgname=None, forced_provider=None):
|
||||||
super(GeocoderConfig, self).__init__(redis_connection, db_conn,
|
super(GeocoderConfig, self).__init__(redis_connection, db_conn,
|
||||||
@@ -339,9 +361,8 @@ class GeocoderConfig(ServiceConfig):
|
|||||||
self._geocoder_provider = filtered_config[self.GEOCODER_PROVIDER].lower()
|
self._geocoder_provider = filtered_config[self.GEOCODER_PROVIDER].lower()
|
||||||
else:
|
else:
|
||||||
self._geocoder_provider = self.DEFAULT_PROVIDER
|
self._geocoder_provider = self.DEFAULT_PROVIDER
|
||||||
self._geocoding_quota = float(filtered_config[self.QUOTA_KEY])
|
self._geocoding_quota = int(filtered_config[self.QUOTA_KEY])
|
||||||
self._period_end_date = date_parse(filtered_config[self.PERIOD_END_DATE])
|
self._period_end_date = date_parse(filtered_config[self.PERIOD_END_DATE])
|
||||||
self._log_path = db_config.geocoder_log_path
|
|
||||||
if filtered_config[self.SOFT_LIMIT_KEY].lower() == 'true':
|
if filtered_config[self.SOFT_LIMIT_KEY].lower() == 'true':
|
||||||
self._soft_geocoding_limit = True
|
self._soft_geocoding_limit = True
|
||||||
else:
|
else:
|
||||||
@@ -424,8 +445,8 @@ class GeocoderConfig(ServiceConfig):
|
|||||||
return self._cost_per_hit
|
return self._cost_per_hit
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def log_path(self):
|
def provider(self):
|
||||||
return self._log_path
|
return self._geocoder_provider
|
||||||
|
|
||||||
|
|
||||||
class ServicesDBConfig:
|
class ServicesDBConfig:
|
||||||
@@ -440,7 +461,6 @@ class ServicesDBConfig:
|
|||||||
self._get_server_config()
|
self._get_server_config()
|
||||||
self._get_here_config()
|
self._get_here_config()
|
||||||
self._get_mapzen_config()
|
self._get_mapzen_config()
|
||||||
self._get_logger_config()
|
|
||||||
self._get_data_observatory_config()
|
self._get_data_observatory_config()
|
||||||
|
|
||||||
def _get_server_config(self):
|
def _get_server_config(self):
|
||||||
@@ -493,13 +513,6 @@ class ServicesDBConfig:
|
|||||||
else:
|
else:
|
||||||
self._data_observatory_connection_str = do_conf['connection']['production']
|
self._data_observatory_connection_str = do_conf['connection']['production']
|
||||||
|
|
||||||
def _get_logger_config(self):
|
|
||||||
logger_conf_json = self._get_conf('logger_conf')
|
|
||||||
if not logger_conf_json:
|
|
||||||
raise ConfigException('Logger configuration missing')
|
|
||||||
else:
|
|
||||||
logger_conf = json.loads(logger_conf_json)
|
|
||||||
self._geocoder_log_path = logger_conf['geocoder_log_path']
|
|
||||||
|
|
||||||
def _get_conf(self, key):
|
def _get_conf(self, key):
|
||||||
try:
|
try:
|
||||||
@@ -507,7 +520,7 @@ class ServicesDBConfig:
|
|||||||
conf = self._db_conn.execute(sql, 1)
|
conf = self._db_conn.execute(sql, 1)
|
||||||
return conf[0]['conf']
|
return conf[0]['conf']
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ConfigException("Malformed config for {0}: {1}".format(key, e))
|
raise ConfigException("Error trying to get config for {0}: {1}".format(key, e))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def server_environment(self):
|
def server_environment(self):
|
||||||
@@ -557,14 +570,18 @@ class ServicesDBConfig:
|
|||||||
def mapzen_geocoder_monthly_quota(self):
|
def mapzen_geocoder_monthly_quota(self):
|
||||||
return self._mapzen_geocoder_quota
|
return self._mapzen_geocoder_quota
|
||||||
|
|
||||||
@property
|
|
||||||
def geocoder_log_path(self):
|
|
||||||
return self._geocoder_log_path
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def data_observatory_connection_str(self):
|
def data_observatory_connection_str(self):
|
||||||
return self._data_observatory_connection_str
|
return self._data_observatory_connection_str
|
||||||
|
|
||||||
|
@property
|
||||||
|
def logger_config(self):
|
||||||
|
logger_conf_json = self._get_conf('logger_conf')
|
||||||
|
if not logger_conf_json:
|
||||||
|
raise ConfigException('Logger configuration missing')
|
||||||
|
else:
|
||||||
|
return json.loads(logger_conf_json)
|
||||||
|
|
||||||
|
|
||||||
class ServicesRedisConfig:
|
class ServicesRedisConfig:
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,130 @@
|
|||||||
from datetime import datetime
|
|
||||||
import abc
|
import abc
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
|
import time
|
||||||
|
import uuid
|
||||||
|
import plpy
|
||||||
|
from datetime import datetime
|
||||||
|
from contextlib import contextmanager
|
||||||
|
from urlparse import urlparse
|
||||||
|
|
||||||
|
|
||||||
class MetricsLoggerFactory:
|
@contextmanager
|
||||||
|
def metrics(function, service_config, logger=None):
|
||||||
|
try:
|
||||||
|
start_time = time.time()
|
||||||
|
yield
|
||||||
|
finally:
|
||||||
|
end_time = time.time()
|
||||||
|
MetricsDataGatherer.add('uuid', str(uuid.uuid1()))
|
||||||
|
MetricsDataGatherer.add('function_name', function)
|
||||||
|
MetricsDataGatherer.add('function_execution_time', (end_time - start_time))
|
||||||
|
metrics_logger = MetricsServiceLoggerFactory.build(service_config,
|
||||||
|
logger)
|
||||||
|
if metrics_logger:
|
||||||
|
data = MetricsDataGatherer.get()
|
||||||
|
metrics_logger.log(data)
|
||||||
|
MetricsDataGatherer.clean()
|
||||||
|
|
||||||
|
|
||||||
|
class Traceable:
|
||||||
|
"""
|
||||||
|
Module to add metrics traceability, for example to get response object
|
||||||
|
in order to add to the metrics dump
|
||||||
|
"""
|
||||||
|
def add_response_data(self, response, logger=None):
|
||||||
|
try:
|
||||||
|
response_data = {}
|
||||||
|
response_data['type'] = "request"
|
||||||
|
response_data['date'] = datetime.now().isoformat()
|
||||||
|
response_data['elapsed_time'] = response.elapsed.total_seconds()
|
||||||
|
response_data['code'] = response.status_code
|
||||||
|
response_data['message'] = response.reason
|
||||||
|
response_data['url'] = self._parse_response_url(response.url)
|
||||||
|
stored_data = MetricsDataGatherer.get_element('response')
|
||||||
|
if stored_data:
|
||||||
|
stored_data.append(response_data)
|
||||||
|
else:
|
||||||
|
MetricsDataGatherer.add('response', [response_data])
|
||||||
|
except BaseException as e:
|
||||||
|
# We don't want to stop the job for some error processing response
|
||||||
|
if logger:
|
||||||
|
logger.error("Error trying to process response metricd data",
|
||||||
|
exception=e)
|
||||||
|
|
||||||
|
def _parse_response_url(self, url):
|
||||||
|
u = urlparse(url)
|
||||||
|
return "{0}://{1}{2}".format(u.scheme, u.netloc, u.path)
|
||||||
|
|
||||||
|
|
||||||
|
class MetricsDataGatherer:
|
||||||
|
"""
|
||||||
|
Metrics gatherer used as a singleton. The intend is to use it as a global
|
||||||
|
storage for the metrics along the function request.
|
||||||
|
"""
|
||||||
|
|
||||||
|
class __MetricsDataGatherer:
|
||||||
|
def __init__(self):
|
||||||
|
self.data = {}
|
||||||
|
|
||||||
|
def add(self, key, value):
|
||||||
|
self.data[key] = value
|
||||||
|
|
||||||
|
def get(self):
|
||||||
|
return self.data
|
||||||
|
|
||||||
|
def get_element(self, key):
|
||||||
|
return self.data.get(key, None)
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
self.data = {}
|
||||||
|
|
||||||
|
|
||||||
|
# We use pgbouncer so we need to have multiples instances per request id
|
||||||
|
__instance = {}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def build(self, service_config):
|
def add(self, key, value):
|
||||||
if re.match('geocoder_*', service_config.service_type):
|
MetricsDataGatherer.instance().add(key, value)
|
||||||
return MetricsGeocoderLogger(service_config)
|
|
||||||
|
@classmethod
|
||||||
|
def get(self):
|
||||||
|
return MetricsDataGatherer.instance().get()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_element(self, key):
|
||||||
|
return MetricsDataGatherer.instance().get_element(key)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def clean(self):
|
||||||
|
MetricsDataGatherer.instance().clean()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def instance(self):
|
||||||
|
txid = MetricsDataGatherer._get_txid()
|
||||||
|
if txid not in MetricsDataGatherer.__instance:
|
||||||
|
MetricsDataGatherer.__instance[txid] = MetricsDataGatherer.__MetricsDataGatherer()
|
||||||
|
|
||||||
|
return MetricsDataGatherer.__instance[txid]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _get_txid(self):
|
||||||
|
result = plpy.execute('select txid_current() as txid')
|
||||||
|
return result[0]['txid']
|
||||||
|
|
||||||
|
|
||||||
|
class MetricsServiceLoggerFactory:
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def build(self, service_config, logger=None):
|
||||||
|
if re.search('^geocoder_*', service_config.service_type):
|
||||||
|
return MetricsGeocoderLogger(service_config, logger)
|
||||||
|
elif re.search('^routing_*', service_config.service_type):
|
||||||
|
return MetricsGenericLogger(service_config, logger)
|
||||||
|
elif re.search('_isolines$', service_config.service_type):
|
||||||
|
return MetricsIsolinesLogger(service_config, logger)
|
||||||
|
elif re.search('^obs_*', service_config.service_type):
|
||||||
|
return MetricsGenericLogger(service_config, logger)
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -17,58 +132,119 @@ class MetricsLoggerFactory:
|
|||||||
class MetricsLogger(object):
|
class MetricsLogger(object):
|
||||||
__metaclass__ = abc.ABCMeta
|
__metaclass__ = abc.ABCMeta
|
||||||
|
|
||||||
def __init__(self, file_path):
|
def __init__(self, service_config, logger):
|
||||||
self._file_path = file_path
|
self._service_config = service_config
|
||||||
|
self._logger = logger
|
||||||
|
|
||||||
def dump_to_file(self, data):
|
def dump_to_file(self, data):
|
||||||
with open(self._file_path, 'a') as logfile:
|
try:
|
||||||
json.dump(data, logfile)
|
log_path = self.service_config.metrics_log_path
|
||||||
logfile.write('\n')
|
response_data = data.pop('response', [])
|
||||||
|
uuid = data.get('uuid')
|
||||||
|
if log_path:
|
||||||
|
with open(log_path, 'a') as logfile:
|
||||||
|
self._dump_response_to_file(uuid, response_data, logfile)
|
||||||
|
json.dump(data, logfile)
|
||||||
|
logfile.write('\n')
|
||||||
|
except BaseException as e:
|
||||||
|
self._logger("Error dumping metrics to file {0}".format(log_path),
|
||||||
|
exception=e)
|
||||||
|
|
||||||
|
def collect_data(self, data):
|
||||||
|
return {
|
||||||
|
"uuid": data.get('uuid', uuid.uuid1()),
|
||||||
|
"type": 'function',
|
||||||
|
"function_name": data.get('function_name', None),
|
||||||
|
"function_execution_time": data.get('function_execution_time',
|
||||||
|
None),
|
||||||
|
"service": self._service_config.service_type,
|
||||||
|
"processable_rows": 1,
|
||||||
|
"success": data.get('success', False),
|
||||||
|
"successful_rows": data.get('successful_rows', 0),
|
||||||
|
"failed_rows": data.get('failed_rows', 0),
|
||||||
|
"empty_rows": data.get('empty_rows', 0),
|
||||||
|
"created_at": datetime.now().isoformat(),
|
||||||
|
"provider": self._service_config.provider,
|
||||||
|
"username": self._service_config.username,
|
||||||
|
"organization": self._service_config.organization,
|
||||||
|
"response": data.get('response', [])
|
||||||
|
}
|
||||||
|
|
||||||
|
def _dump_response_to_file(self, uuid, response_data, log_file):
|
||||||
|
for r in response_data:
|
||||||
|
r['uuid'] = uuid
|
||||||
|
json.dump(r, log_file)
|
||||||
|
log_file.write('\n')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def service_config(self):
|
||||||
|
return self._service_config
|
||||||
|
|
||||||
@abc.abstractproperty
|
@abc.abstractproperty
|
||||||
def log(self, **data):
|
def log(self, data):
|
||||||
raise NotImplementedError('log method must be defined')
|
raise NotImplementedError('log method must be defined')
|
||||||
|
|
||||||
|
|
||||||
class MetricsGeocoderLogger(MetricsLogger):
|
class MetricsGeocoderLogger(MetricsLogger):
|
||||||
|
|
||||||
def __init__(self, service_config):
|
def __init__(self, service_config, logger):
|
||||||
super(MetricsGeocoderLogger, self).__init__(service_config.log_path)
|
super(MetricsGeocoderLogger, self).__init__(service_config, logger)
|
||||||
self._service_config = service_config
|
|
||||||
|
|
||||||
def log(self, **data):
|
def log(self, data):
|
||||||
dump_data = self._dump_data(**data)
|
dump_data = self.collect_data(data)
|
||||||
self.dump_to_file(dump_data)
|
self.dump_to_file(dump_data)
|
||||||
|
|
||||||
def _dump_data(self, **data):
|
def collect_data(self, data):
|
||||||
if data['success']:
|
dump_data = super(MetricsGeocoderLogger, self).collect_data(data)
|
||||||
cost = self._service_config.cost_per_hit
|
if data.get('success', False):
|
||||||
failed_rows = 0
|
cost = self.service_config.cost_per_hit
|
||||||
successful_rows = 1
|
|
||||||
else:
|
else:
|
||||||
cost = 0
|
cost = 0
|
||||||
failed_rows = 1
|
|
||||||
successful_rows = 0
|
|
||||||
|
|
||||||
if self._service_config.is_high_resolution:
|
if self.service_config.is_high_resolution:
|
||||||
kind = 'high-resolution'
|
kind = 'high-resolution'
|
||||||
else:
|
else:
|
||||||
kind = 'internal'
|
kind = 'internal'
|
||||||
|
|
||||||
return {
|
dump_data.update({
|
||||||
"batched": False,
|
"batched": False,
|
||||||
"cache_hits": 0, # Always 0 because no cache involved
|
"cache_hits": 0, # Always 0 because no cache involved
|
||||||
# https://github.com/CartoDB/cartodb/blob/master/app/models/geocoding.rb#L208-L211
|
# https://github.com/CartoDB/cartodb/blob/master/app/models/geocoding.rb#L208-L211
|
||||||
"cost": cost,
|
"cost": cost,
|
||||||
"created_at": datetime.now().isoformat(),
|
"geocoder_type": self.service_config.service_type,
|
||||||
"failed_rows": failed_rows,
|
|
||||||
"geocoder_type": self._service_config.service_type,
|
|
||||||
"kind": kind,
|
"kind": kind,
|
||||||
"processable_rows": 1,
|
"processed_rows": data.get('successful_rows', 0),
|
||||||
"processed_rows": successful_rows,
|
"real_rows": data.get('successful_rows', 0),
|
||||||
"real_rows": successful_rows,
|
})
|
||||||
"success": data['success'],
|
|
||||||
"successful_rows": successful_rows,
|
return dump_data
|
||||||
"username": self._service_config.username,
|
|
||||||
"organization": self._service_config.organization
|
|
||||||
}
|
class MetricsGenericLogger(MetricsLogger):
|
||||||
|
|
||||||
|
def __init__(self, service_config, logger):
|
||||||
|
super(MetricsGenericLogger, self).__init__(service_config, logger)
|
||||||
|
|
||||||
|
def log(self, data):
|
||||||
|
dump_data = self.collect_data(data)
|
||||||
|
self.dump_to_file(dump_data)
|
||||||
|
|
||||||
|
def collect_data(self, data):
|
||||||
|
return super(MetricsGenericLogger, self).collect_data(data)
|
||||||
|
|
||||||
|
|
||||||
|
class MetricsIsolinesLogger(MetricsLogger):
|
||||||
|
|
||||||
|
def __init__(self, service_config, logger):
|
||||||
|
super(MetricsIsolinesLogger, self).__init__(service_config, logger)
|
||||||
|
|
||||||
|
def log(self, data):
|
||||||
|
dump_data = self.collect_data(data)
|
||||||
|
self.dump_to_file(dump_data)
|
||||||
|
|
||||||
|
def collect_data(self, data):
|
||||||
|
dump_data = super(MetricsIsolinesLogger, self).collect_data(data)
|
||||||
|
dump_data.update({
|
||||||
|
"isolines_generated": data.get('isolines_generated', 0)
|
||||||
|
})
|
||||||
|
return dump_data
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from user import UserMetricsService
|
from user import UserMetricsService
|
||||||
from log import MetricsLoggerFactory
|
from log import MetricsDataGatherer
|
||||||
from datetime import date
|
from datetime import date
|
||||||
import re
|
import re
|
||||||
|
|
||||||
@@ -14,7 +14,6 @@ class QuotaService:
|
|||||||
redis_connection)
|
redis_connection)
|
||||||
self._user_service = UserMetricsService(self._user_service_config,
|
self._user_service = UserMetricsService(self._user_service_config,
|
||||||
redis_connection)
|
redis_connection)
|
||||||
self._metrics_logger = MetricsLoggerFactory.build(user_service_config)
|
|
||||||
|
|
||||||
def check_user_quota(self):
|
def check_user_quota(self):
|
||||||
return self._quota_checker.check()
|
return self._quota_checker.check()
|
||||||
@@ -46,13 +45,19 @@ class QuotaService:
|
|||||||
self._user_service.increment_service_use(
|
self._user_service.increment_service_use(
|
||||||
self._user_service_config.service_type, "isolines_generated",
|
self._user_service_config.service_type, "isolines_generated",
|
||||||
amount=amount)
|
amount=amount)
|
||||||
|
MetricsDataGatherer.add('isolines_generated', amount)
|
||||||
|
|
||||||
def _log_service_process(self, event):
|
def _log_service_process(self, event):
|
||||||
if self._metrics_logger:
|
if event is 'success':
|
||||||
if event is 'success' or event is 'empty':
|
MetricsDataGatherer.add('success', True)
|
||||||
self._metrics_logger.log(success=True)
|
MetricsDataGatherer.add('successful_rows', 1)
|
||||||
elif event is 'empty':
|
elif event is 'empty':
|
||||||
self._metrics_logger.log(success=False)
|
MetricsDataGatherer.add('success', True)
|
||||||
|
MetricsDataGatherer.add('successful_rows', 1)
|
||||||
|
MetricsDataGatherer.add('empty_rows', 1)
|
||||||
|
elif event is 'fail':
|
||||||
|
MetricsDataGatherer.add('success', False)
|
||||||
|
MetricsDataGatherer.add('failed_rows', 1)
|
||||||
|
|
||||||
|
|
||||||
class QuotaChecker:
|
class QuotaChecker:
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ class UserMetricsService:
|
|||||||
SERVICE_GEOCODER_CACHE = 'geocoder_cache'
|
SERVICE_GEOCODER_CACHE = 'geocoder_cache'
|
||||||
SERVICE_HERE_ISOLINES = 'here_isolines'
|
SERVICE_HERE_ISOLINES = 'here_isolines'
|
||||||
SERVICE_MAPZEN_ROUTING = 'routing_mapzen'
|
SERVICE_MAPZEN_ROUTING = 'routing_mapzen'
|
||||||
|
SERVICE_OBSERVATORY = 'obs_general'
|
||||||
DAY_OF_MONTH_ZERO_PADDED = '%d'
|
DAY_OF_MONTH_ZERO_PADDED = '%d'
|
||||||
|
|
||||||
def __init__(self, user_geocoder_config, redis_connection):
|
def __init__(self, user_geocoder_config, redis_connection):
|
||||||
@@ -22,6 +23,8 @@ class UserMetricsService:
|
|||||||
return self.__used_isolines_quota(service_type, date)
|
return self.__used_isolines_quota(service_type, date)
|
||||||
elif service_type == self.SERVICE_MAPZEN_ROUTING:
|
elif service_type == self.SERVICE_MAPZEN_ROUTING:
|
||||||
return self.__used_routing_quota(service_type, date)
|
return self.__used_routing_quota(service_type, date)
|
||||||
|
elif service_type == self.SERVICE_OBSERVATORY:
|
||||||
|
return self.__used_observatory_quota(service_type, date)
|
||||||
else:
|
else:
|
||||||
return self.__used_geocoding_quota(service_type, date)
|
return self.__used_geocoding_quota(service_type, date)
|
||||||
|
|
||||||
@@ -72,6 +75,19 @@ class UserMetricsService:
|
|||||||
|
|
||||||
return current_use
|
return current_use
|
||||||
|
|
||||||
|
def __used_observatory_quota(self, service_type, date):
|
||||||
|
date_from, date_to = self.__current_billing_cycle()
|
||||||
|
current_use = 0
|
||||||
|
success_responses = self.get_metrics(service_type,
|
||||||
|
'success_responses', date_from,
|
||||||
|
date_to)
|
||||||
|
empty_responses = self.get_metrics(service_type,
|
||||||
|
'empty_responses', date_from,
|
||||||
|
date_to)
|
||||||
|
current_use += (success_responses + empty_responses)
|
||||||
|
|
||||||
|
return current_use
|
||||||
|
|
||||||
def increment_service_use(self, service_type, metric, date=date.today(),
|
def increment_service_use(self, service_type, metric, date=date.today(),
|
||||||
amount=1):
|
amount=1):
|
||||||
""" Increment the services uses in monthly and daily basis"""
|
""" Increment the services uses in monthly and daily basis"""
|
||||||
@@ -88,11 +104,11 @@ class UserMetricsService:
|
|||||||
redis_prefix = self.__parse_redis_prefix(key_prefix, entity_name,
|
redis_prefix = self.__parse_redis_prefix(key_prefix, entity_name,
|
||||||
service, metric, date)
|
service, metric, date)
|
||||||
score = self._redis_connection.zscore(redis_prefix, date.day)
|
score = self._redis_connection.zscore(redis_prefix, date.day)
|
||||||
aggregated_metric += score if score else 0
|
aggregated_metric += int(score) if score else 0
|
||||||
zero_padded_day = date.strftime(self.DAY_OF_MONTH_ZERO_PADDED)
|
zero_padded_day = date.strftime(self.DAY_OF_MONTH_ZERO_PADDED)
|
||||||
if str(date.day) != zero_padded_day:
|
if str(date.day) != zero_padded_day:
|
||||||
score = self._redis_connection.zscore(redis_prefix, zero_padded_day)
|
score = self._redis_connection.zscore(redis_prefix, zero_padded_day)
|
||||||
aggregated_metric += score if score else 0
|
aggregated_metric += int(score) if score else 0
|
||||||
|
|
||||||
return aggregated_metric
|
return aggregated_metric
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ class MapzenGeocoderConfigBuilder(object):
|
|||||||
geocoding_quota = mapzen_server_conf['geocoder']['monthly_quota']
|
geocoding_quota = mapzen_server_conf['geocoder']['monthly_quota']
|
||||||
mapzen_api_key = mapzen_server_conf['geocoder']['api_key']
|
mapzen_api_key = mapzen_server_conf['geocoder']['api_key']
|
||||||
|
|
||||||
soft_geocoding_limit = self._user_conf.get('soft_geocoding_limit')
|
soft_geocoding_limit = self._user_conf.get('soft_geocoding_limit').lower() == 'true'
|
||||||
|
|
||||||
cost_per_hit=0
|
cost_per_hit=0
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ class MapzenGeocoderConfigBuilder(object):
|
|||||||
period_end_date = date_parse(period_end_date_str)
|
period_end_date = date_parse(period_end_date_str)
|
||||||
|
|
||||||
logger_conf = self._server_conf.get('logger_conf')
|
logger_conf = self._server_conf.get('logger_conf')
|
||||||
log_path = logger_conf['geocoder_log_path']
|
log_path = logger_conf.get('geocoder_log_path', None)
|
||||||
|
|
||||||
return MapzenGeocoderConfig(geocoding_quota,
|
return MapzenGeocoderConfig(geocoding_quota,
|
||||||
soft_geocoding_limit,
|
soft_geocoding_limit,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from setuptools import setup, find_packages
|
|||||||
setup(
|
setup(
|
||||||
name='cartodb_services',
|
name='cartodb_services',
|
||||||
|
|
||||||
version='0.9.2',
|
version='0.11.0',
|
||||||
|
|
||||||
description='CartoDB Services API Python Library',
|
description='CartoDB Services API Python Library',
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
from test_helper import plpy_mock_config
|
||||||
|
|
||||||
|
|
||||||
|
def setup():
|
||||||
|
plpy_mock_config()
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from mockredis import MockRedis
|
from mockredis import MockRedis
|
||||||
|
from ..test_helper import *
|
||||||
from cartodb_services.metrics.config import RoutingConfig, ServicesRedisConfig
|
from cartodb_services.metrics.config import RoutingConfig, ServicesRedisConfig
|
||||||
from ..test_helper import build_plpy_mock
|
|
||||||
|
|
||||||
class TestRoutingConfig(TestCase):
|
class TestRoutingConfig(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self._redis_conn = MockRedis()
|
self._redis_conn = MockRedis()
|
||||||
self._db_conn = build_plpy_mock()
|
self._db_conn = plpy_mock
|
||||||
self._username = 'my_test_user'
|
self._username = 'my_test_user'
|
||||||
self._user_key = "rails:users:{0}".format(self._username)
|
self._user_key = "rails:users:{0}".format(self._username)
|
||||||
self._redis_conn.hset(self._user_key, 'period_end_date', '2016-10-10')
|
self._redis_conn.hset(self._user_key, 'period_end_date', '2016-10-10')
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from mockredis import MockRedis
|
from mockredis import MockRedis
|
||||||
from ..test_helper import build_plpy_mock
|
from ..test_helper import *
|
||||||
from cartodb_services.metrics.quota import QuotaChecker
|
from cartodb_services.metrics.quota import QuotaChecker
|
||||||
from cartodb_services.metrics import RoutingConfig
|
from cartodb_services.metrics import RoutingConfig
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|||||||
53
server/lib/python/cartodb_services/test/mock_plpy.py
Normal file
53
server/lib/python/cartodb_services/test/mock_plpy.py
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
class MockCursor:
|
||||||
|
def __init__(self, data):
|
||||||
|
self.cursor_pos = 0
|
||||||
|
self.data = data
|
||||||
|
|
||||||
|
def fetch(self, batch_size):
|
||||||
|
batch = self.data[self.cursor_pos: self.cursor_pos + batch_size]
|
||||||
|
self.cursor_pos += batch_size
|
||||||
|
return batch
|
||||||
|
|
||||||
|
|
||||||
|
class MockPlPy:
|
||||||
|
def __init__(self):
|
||||||
|
self._reset()
|
||||||
|
|
||||||
|
def _reset(self):
|
||||||
|
self.infos = []
|
||||||
|
self.notices = []
|
||||||
|
self.debugs = []
|
||||||
|
self.logs = []
|
||||||
|
self.warnings = []
|
||||||
|
self.errors = []
|
||||||
|
self.fatals = []
|
||||||
|
self.executes = []
|
||||||
|
self.results = []
|
||||||
|
self.prepares = []
|
||||||
|
self.results = {}
|
||||||
|
|
||||||
|
def _define_result(self, query, result):
|
||||||
|
pattern = re.compile(query, re.IGNORECASE | re.MULTILINE)
|
||||||
|
self.results[pattern] = result
|
||||||
|
|
||||||
|
def notice(self, msg):
|
||||||
|
self.notices.append(msg)
|
||||||
|
|
||||||
|
def debug(self, msg):
|
||||||
|
self.notices.append(msg)
|
||||||
|
|
||||||
|
def info(self, msg):
|
||||||
|
self.infos.append(msg)
|
||||||
|
|
||||||
|
def cursor(self, query):
|
||||||
|
data = self.execute(query)
|
||||||
|
return MockCursor(data)
|
||||||
|
|
||||||
|
def execute(self, query, rows=1):
|
||||||
|
for pattern, result in self.results.iteritems():
|
||||||
|
if pattern.search(query):
|
||||||
|
return result
|
||||||
|
return []
|
||||||
@@ -1,20 +1,20 @@
|
|||||||
import test_helper
|
from test_helper import *
|
||||||
from cartodb_services.metrics import GeocoderConfig, ObservatorySnapshotConfig, ConfigException
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from nose.tools import assert_raises
|
from nose.tools import assert_raises
|
||||||
from mockredis import MockRedis
|
from mockredis import MockRedis
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
from cartodb_services.metrics import GeocoderConfig, ObservatorySnapshotConfig, ConfigException
|
||||||
|
|
||||||
|
|
||||||
class TestConfig(TestCase):
|
class TestConfig(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.redis_conn = MockRedis()
|
self.redis_conn = MockRedis()
|
||||||
self.plpy_mock = test_helper.build_plpy_mock()
|
plpy_mock_config()
|
||||||
|
|
||||||
def test_should_return_list_of_nokia_geocoder_config_if_its_ok(self):
|
def test_should_return_list_of_nokia_geocoder_config_if_its_ok(self):
|
||||||
test_helper.build_redis_user_config(self.redis_conn, 'test_user')
|
build_redis_user_config(self.redis_conn, 'test_user')
|
||||||
geocoder_config = GeocoderConfig(self.redis_conn, self.plpy_mock,
|
geocoder_config = GeocoderConfig(self.redis_conn, plpy_mock,
|
||||||
'test_user', None)
|
'test_user', None)
|
||||||
assert geocoder_config.heremaps_geocoder is True
|
assert geocoder_config.heremaps_geocoder is True
|
||||||
assert geocoder_config.geocoding_quota == 100
|
assert geocoder_config.geocoding_quota == 100
|
||||||
@@ -22,10 +22,10 @@ class TestConfig(TestCase):
|
|||||||
|
|
||||||
def test_should_return_list_of_nokia_geocoder_config_ok_for_org(self):
|
def test_should_return_list_of_nokia_geocoder_config_ok_for_org(self):
|
||||||
yesterday = datetime.today() - timedelta(days=1)
|
yesterday = datetime.today() - timedelta(days=1)
|
||||||
test_helper.build_redis_user_config(self.redis_conn, 'test_user')
|
build_redis_user_config(self.redis_conn, 'test_user')
|
||||||
test_helper.build_redis_org_config(self.redis_conn, 'test_org',
|
build_redis_org_config(self.redis_conn, 'test_org',
|
||||||
quota=200, end_date=yesterday)
|
quota=200, end_date=yesterday)
|
||||||
geocoder_config = GeocoderConfig(self.redis_conn, self.plpy_mock,
|
geocoder_config = GeocoderConfig(self.redis_conn, plpy_mock,
|
||||||
'test_user', 'test_org')
|
'test_user', 'test_org')
|
||||||
assert geocoder_config.heremaps_geocoder is True
|
assert geocoder_config.heremaps_geocoder is True
|
||||||
assert geocoder_config.geocoding_quota == 200
|
assert geocoder_config.geocoding_quota == 200
|
||||||
@@ -34,10 +34,10 @@ class TestConfig(TestCase):
|
|||||||
|
|
||||||
def test_should_return_config_for_obs_snapshot(self):
|
def test_should_return_config_for_obs_snapshot(self):
|
||||||
yesterday = datetime.today() - timedelta(days=1)
|
yesterday = datetime.today() - timedelta(days=1)
|
||||||
test_helper.build_redis_user_config(self.redis_conn, 'test_user',
|
build_redis_user_config(self.redis_conn, 'test_user',
|
||||||
do_quota=100, soft_do_limit=True,
|
do_quota=100, soft_do_limit=True,
|
||||||
end_date=yesterday)
|
end_date=yesterday)
|
||||||
do_config = ObservatorySnapshotConfig(self.redis_conn, self.plpy_mock,
|
do_config = ObservatorySnapshotConfig(self.redis_conn, plpy_mock,
|
||||||
'test_user')
|
'test_user')
|
||||||
assert do_config.monthly_quota == 100
|
assert do_config.monthly_quota == 100
|
||||||
assert do_config.soft_limit is True
|
assert do_config.soft_limit is True
|
||||||
@@ -45,16 +45,16 @@ class TestConfig(TestCase):
|
|||||||
|
|
||||||
def test_should_return_db_quota_if_not_redis_quota_config_obs_snapshot(self):
|
def test_should_return_db_quota_if_not_redis_quota_config_obs_snapshot(self):
|
||||||
yesterday = datetime.today() - timedelta(days=1)
|
yesterday = datetime.today() - timedelta(days=1)
|
||||||
test_helper.build_redis_user_config(self.redis_conn, 'test_user',
|
build_redis_user_config(self.redis_conn, 'test_user',
|
||||||
end_date=yesterday)
|
end_date=yesterday)
|
||||||
do_config = ObservatorySnapshotConfig(self.redis_conn, self.plpy_mock,
|
do_config = ObservatorySnapshotConfig(self.redis_conn, plpy_mock,
|
||||||
'test_user')
|
'test_user')
|
||||||
assert do_config.monthly_quota == 0
|
assert do_config.monthly_quota == 0
|
||||||
assert do_config.soft_limit is False
|
assert do_config.soft_limit is False
|
||||||
assert do_config.period_end_date.date() == yesterday.date()
|
assert do_config.period_end_date.date() == yesterday.date()
|
||||||
|
|
||||||
def test_should_raise_exception_when_missing_parameters(self):
|
def test_should_raise_exception_when_missing_parameters(self):
|
||||||
plpy_mock = test_helper.build_plpy_mock(empty=True)
|
plpy_mock._reset()
|
||||||
test_helper.build_redis_user_config(self.redis_conn, 'test_user')
|
build_redis_user_config(self.redis_conn, 'test_user')
|
||||||
assert_raises(ConfigException, GeocoderConfig, self.redis_conn,
|
assert_raises(ConfigException, GeocoderConfig, self.redis_conn,
|
||||||
plpy_mock, 'test_user', None)
|
plpy_mock, 'test_user', None)
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
from datetime import datetime, date
|
from datetime import datetime, date
|
||||||
from mock import Mock
|
from mock import Mock, MagicMock
|
||||||
|
import random
|
||||||
import sys
|
import sys
|
||||||
sys.modules['plpy'] = Mock()
|
from mock_plpy import MockPlPy
|
||||||
|
|
||||||
|
plpy_mock = MockPlPy()
|
||||||
|
sys.modules['plpy'] = plpy_mock
|
||||||
|
|
||||||
|
|
||||||
def build_redis_user_config(redis_conn, username, quota=100, soft_limit=False,
|
def build_redis_user_config(redis_conn, username, quota=100, soft_limit=False,
|
||||||
@@ -57,22 +61,10 @@ def increment_service_uses(redis_conn, username, orgname=None,
|
|||||||
redis_conn.zincrby(redis_name, date.day, amount)
|
redis_conn.zincrby(redis_name, date.day, amount)
|
||||||
|
|
||||||
|
|
||||||
def build_plpy_mock(empty=False):
|
def plpy_mock_config():
|
||||||
plpy_mock = Mock()
|
plpy_mock._define_result("CDB_Conf_GetConf\('heremaps_conf'\)", [{'conf': '{"geocoder": {"app_id": "app_id", "app_code": "code", "geocoder_cost_per_hit": 1}, "isolines": {"app_id": "app_id", "app_code": "code"}}'}])
|
||||||
if not empty:
|
plpy_mock._define_result("CDB_Conf_GetConf\('mapzen_conf'\)", [{'conf': '{"routing": {"api_key": "api_key_rou", "monthly_quota": 1500000}, "geocoder": {"api_key": "api_key_geo", "monthly_quota": 1500000}, "matrix": {"api_key": "api_key_mat", "monthly_quota": 1500000}}'}])
|
||||||
plpy_mock.execute.side_effect = _plpy_execute_side_effect
|
plpy_mock._define_result("CDB_Conf_GetConf\('logger_conf'\)", [{'conf': '{"geocoder_log_path": "/dev/null"}'}])
|
||||||
|
plpy_mock._define_result("CDB_Conf_GetConf\('data_observatory_conf'\)", [{'conf': '{"connection": {"whitelist": ["ethervoid"], "production": "host=localhost port=5432 dbname=dataservices_db user=geocoder_api", "staging": "host=localhost port=5432 dbname=dataservices_db user=geocoder_api"}}'}])
|
||||||
return plpy_mock
|
plpy_mock._define_result("CDB_Conf_GetConf\('server_conf'\)", [{'conf': '{"environment": "testing"}'}])
|
||||||
|
plpy_mock._define_result("select txid_current", [{'txid': random.randint(0, 1000)}])
|
||||||
|
|
||||||
def _plpy_execute_side_effect(*args, **kwargs):
|
|
||||||
if args[0] == "SELECT cartodb.CDB_Conf_GetConf('heremaps_conf') as conf":
|
|
||||||
return [{'conf': '{"geocoder": {"app_id": "app_id", "app_code": "code", "geocoder_cost_per_hit": 1}, "isolines": {"app_id": "app_id", "app_code": "code"}}'}]
|
|
||||||
elif args[0] == "SELECT cartodb.CDB_Conf_GetConf('mapzen_conf') as conf":
|
|
||||||
return [{'conf': '{"routing": {"api_key": "api_key_rou", "monthly_quota": 1500000}, "geocoder": {"api_key": "api_key_geo", "monthly_quota": 1500000}, "matrix": {"api_key": "api_key_mat", "monthly_quota": 1500000}}'}]
|
|
||||||
elif args[0] == "SELECT cartodb.CDB_Conf_GetConf('logger_conf') as conf":
|
|
||||||
return [{'conf': '{"geocoder_log_path": "/dev/null"}'}]
|
|
||||||
elif args[0] == "SELECT cartodb.CDB_Conf_GetConf('data_observatory_conf') as conf":
|
|
||||||
return [{'conf': '{"connection": {"whitelist": ["ethervoid"], "production": "host=localhost port=5432 dbname=dataservices_db user=geocoder_api", "staging": "host=localhost port=5432 dbname=dataservices_db user=geocoder_api"}}'}]
|
|
||||||
elif args[0] == "SELECT cartodb.CDB_Conf_GetConf('server_conf') as conf":
|
|
||||||
return [{'conf': '{"environment": "testing"}'}]
|
|
||||||
|
|||||||
23
server/lib/python/cartodb_services/test/test_metrics_log.py
Normal file
23
server/lib/python/cartodb_services/test/test_metrics_log.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
from test_helper import *
|
||||||
|
from cartodb_services.metrics import MetricsDataGatherer
|
||||||
|
from unittest import TestCase
|
||||||
|
from mock import Mock, MagicMock
|
||||||
|
from nose.tools import assert_raises
|
||||||
|
from datetime import datetime, date
|
||||||
|
|
||||||
|
|
||||||
|
class TestMetricsDataGatherer(TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
plpy_mock_config()
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_use_multiple_instances_for_multiples_requests(self):
|
||||||
|
plpy_mock._define_result("select txid_current", [{'txid': 100}])
|
||||||
|
MetricsDataGatherer.add('test', 1)
|
||||||
|
plpy_mock._define_result("select txid_current", [{'txid': 101}])
|
||||||
|
MetricsDataGatherer.add('test', 2)
|
||||||
|
plpy_mock._define_result("select txid_current", [{'txid': 100}])
|
||||||
|
assert MetricsDataGatherer.get_element('test') is 1
|
||||||
|
plpy_mock._define_result("select txid_current", [{'txid': 101}])
|
||||||
|
assert MetricsDataGatherer.get_element('test') is 2
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import test_helper
|
|
||||||
import requests
|
import requests
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from nose.tools import assert_raises
|
from nose.tools import assert_raises
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import test_helper
|
from test_helper import *
|
||||||
from mockredis import MockRedis
|
from mockredis import MockRedis
|
||||||
from cartodb_services.metrics import QuotaService
|
from cartodb_services.metrics import QuotaService
|
||||||
from cartodb_services.metrics import GeocoderConfig, RoutingConfig, ObservatorySnapshotConfig, IsolinesRoutingConfig
|
from cartodb_services.metrics import GeocoderConfig, RoutingConfig, ObservatorySnapshotConfig, IsolinesRoutingConfig
|
||||||
@@ -28,32 +28,32 @@ class TestQuotaService(TestCase):
|
|||||||
|
|
||||||
def test_should_return_true_if_user_quota_is_not_completely_used(self):
|
def test_should_return_true_if_user_quota_is_not_completely_used(self):
|
||||||
qs = self.__build_geocoder_quota_service('test_user')
|
qs = self.__build_geocoder_quota_service('test_user')
|
||||||
test_helper.increment_service_uses(self.redis_conn, 'test_user')
|
increment_service_uses(self.redis_conn, 'test_user')
|
||||||
assert qs.check_user_quota() is True
|
assert qs.check_user_quota() is True
|
||||||
|
|
||||||
def test_should_return_true_if_org_quota_is_not_completely_used(self):
|
def test_should_return_true_if_org_quota_is_not_completely_used(self):
|
||||||
qs = self.__build_geocoder_quota_service('test_user',
|
qs = self.__build_geocoder_quota_service('test_user',
|
||||||
orgname='test_org')
|
orgname='test_org')
|
||||||
test_helper.increment_service_uses(self.redis_conn, 'test_user',
|
increment_service_uses(self.redis_conn, 'test_user',
|
||||||
orgname='test_org')
|
orgname='test_org')
|
||||||
assert qs.check_user_quota() is True
|
assert qs.check_user_quota() is True
|
||||||
|
|
||||||
def test_should_return_false_if_user_quota_is_surpassed(self):
|
def test_should_return_false_if_user_quota_is_surpassed(self):
|
||||||
qs = self.__build_geocoder_quota_service('test_user')
|
qs = self.__build_geocoder_quota_service('test_user')
|
||||||
test_helper.increment_service_uses(self.redis_conn, 'test_user',
|
increment_service_uses(self.redis_conn, 'test_user',
|
||||||
amount=300)
|
amount=300)
|
||||||
assert qs.check_user_quota() is False
|
assert qs.check_user_quota() is False
|
||||||
|
|
||||||
def test_should_return_false_if_org_quota_is_surpassed(self):
|
def test_should_return_false_if_org_quota_is_surpassed(self):
|
||||||
qs = self.__build_geocoder_quota_service('test_user',
|
qs = self.__build_geocoder_quota_service('test_user',
|
||||||
orgname='test_org')
|
orgname='test_org')
|
||||||
test_helper.increment_service_uses(self.redis_conn, 'test_user',
|
increment_service_uses(self.redis_conn, 'test_user',
|
||||||
orgname='test_org', amount=400)
|
orgname='test_org', amount=400)
|
||||||
assert qs.check_user_quota() is False
|
assert qs.check_user_quota() is False
|
||||||
|
|
||||||
def test_should_return_true_if_user_quota_is_surpassed_but_soft_limit_is_enabled(self):
|
def test_should_return_true_if_user_quota_is_surpassed_but_soft_limit_is_enabled(self):
|
||||||
qs = self.__build_geocoder_quota_service('test_user', soft_limit=True)
|
qs = self.__build_geocoder_quota_service('test_user', soft_limit=True)
|
||||||
test_helper.increment_service_uses(self.redis_conn, 'test_user',
|
increment_service_uses(self.redis_conn, 'test_user',
|
||||||
amount=300)
|
amount=300)
|
||||||
assert qs.check_user_quota() is True
|
assert qs.check_user_quota() is True
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ class TestQuotaService(TestCase):
|
|||||||
qs = self.__build_geocoder_quota_service('test_user',
|
qs = self.__build_geocoder_quota_service('test_user',
|
||||||
orgname='test_org',
|
orgname='test_org',
|
||||||
soft_limit=True)
|
soft_limit=True)
|
||||||
test_helper.increment_service_uses(self.redis_conn, 'test_user',
|
increment_service_uses(self.redis_conn, 'test_user',
|
||||||
orgname='test_org', amount=400)
|
orgname='test_org', amount=400)
|
||||||
assert qs.check_user_quota() is True
|
assert qs.check_user_quota() is True
|
||||||
|
|
||||||
@@ -140,18 +140,17 @@ class TestQuotaService(TestCase):
|
|||||||
|
|
||||||
def __prepare_quota_service(self, username, quota, service, orgname,
|
def __prepare_quota_service(self, username, quota, service, orgname,
|
||||||
soft_limit, do_quota, soft_do_limit, end_date):
|
soft_limit, do_quota, soft_do_limit, end_date):
|
||||||
test_helper.build_redis_user_config(self.redis_conn, username,
|
build_redis_user_config(self.redis_conn, username,
|
||||||
quota=quota, service=service,
|
quota=quota, service=service,
|
||||||
soft_limit=soft_limit,
|
soft_limit=soft_limit,
|
||||||
soft_do_limit=soft_do_limit,
|
soft_do_limit=soft_do_limit,
|
||||||
do_quota=do_quota,
|
do_quota=do_quota,
|
||||||
end_date=end_date)
|
end_date=end_date)
|
||||||
if orgname:
|
if orgname:
|
||||||
test_helper.build_redis_org_config(self.redis_conn, orgname,
|
build_redis_org_config(self.redis_conn, orgname,
|
||||||
quota=quota, service=service,
|
quota=quota, service=service,
|
||||||
do_quota=do_quota,
|
do_quota=do_quota,
|
||||||
end_date=end_date)
|
end_date=end_date)
|
||||||
self._plpy_mock = test_helper.build_plpy_mock()
|
|
||||||
|
|
||||||
def __build_geocoder_quota_service(self, username, quota=100,
|
def __build_geocoder_quota_service(self, username, quota=100,
|
||||||
service='heremaps', orgname=None,
|
service='heremaps', orgname=None,
|
||||||
@@ -159,7 +158,7 @@ class TestQuotaService(TestCase):
|
|||||||
end_date=datetime.today()):
|
end_date=datetime.today()):
|
||||||
self.__prepare_quota_service(username, quota, service, orgname,
|
self.__prepare_quota_service(username, quota, service, orgname,
|
||||||
soft_limit, 0, False, end_date)
|
soft_limit, 0, False, end_date)
|
||||||
geocoder_config = GeocoderConfig(self.redis_conn, self._plpy_mock,
|
geocoder_config = GeocoderConfig(self.redis_conn, plpy_mock,
|
||||||
username, orgname)
|
username, orgname)
|
||||||
return QuotaService(geocoder_config, redis_connection=self.redis_conn)
|
return QuotaService(geocoder_config, redis_connection=self.redis_conn)
|
||||||
|
|
||||||
@@ -168,7 +167,7 @@ class TestQuotaService(TestCase):
|
|||||||
quota=100, end_date=datetime.today()):
|
quota=100, end_date=datetime.today()):
|
||||||
self.__prepare_quota_service(username, quota, service, orgname,
|
self.__prepare_quota_service(username, quota, service, orgname,
|
||||||
soft_limit, 0, False, end_date)
|
soft_limit, 0, False, end_date)
|
||||||
routing_config = RoutingConfig(self.redis_conn, self._plpy_mock,
|
routing_config = RoutingConfig(self.redis_conn, plpy_mock,
|
||||||
username, orgname)
|
username, orgname)
|
||||||
return QuotaService(routing_config, redis_connection=self.redis_conn)
|
return QuotaService(routing_config, redis_connection=self.redis_conn)
|
||||||
|
|
||||||
@@ -177,7 +176,7 @@ class TestQuotaService(TestCase):
|
|||||||
quota=100, end_date=datetime.today()):
|
quota=100, end_date=datetime.today()):
|
||||||
self.__prepare_quota_service(username, quota, service, orgname,
|
self.__prepare_quota_service(username, quota, service, orgname,
|
||||||
soft_limit, 0, False, end_date)
|
soft_limit, 0, False, end_date)
|
||||||
isolines_config = IsolinesRoutingConfig(self.redis_conn, self._plpy_mock,
|
isolines_config = IsolinesRoutingConfig(self.redis_conn, plpy_mock,
|
||||||
username, orgname)
|
username, orgname)
|
||||||
return QuotaService(isolines_config, redis_connection=self.redis_conn)
|
return QuotaService(isolines_config, redis_connection=self.redis_conn)
|
||||||
|
|
||||||
@@ -188,6 +187,6 @@ class TestQuotaService(TestCase):
|
|||||||
end_date=datetime.today()):
|
end_date=datetime.today()):
|
||||||
self.__prepare_quota_service(username, 0, service, orgname, False,
|
self.__prepare_quota_service(username, 0, service, orgname, False,
|
||||||
quota, soft_limit, end_date)
|
quota, soft_limit, end_date)
|
||||||
do_config = ObservatorySnapshotConfig(self.redis_conn, self._plpy_mock,
|
do_config = ObservatorySnapshotConfig(self.redis_conn, plpy_mock,
|
||||||
username, orgname)
|
username, orgname)
|
||||||
return QuotaService(do_config, redis_connection=self.redis_conn)
|
return QuotaService(do_config, redis_connection=self.redis_conn)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import test_helper
|
from test_helper import *
|
||||||
from mockredis import MockRedis
|
from mockredis import MockRedis
|
||||||
from cartodb_services.metrics import UserMetricsService
|
from cartodb_services.metrics import UserMetricsService
|
||||||
from cartodb_services.metrics import GeocoderConfig
|
from cartodb_services.metrics import GeocoderConfig
|
||||||
@@ -19,13 +19,13 @@ class TestUserService(TestCase):
|
|||||||
|
|
||||||
def test_user_used_quota_for_a_day(self):
|
def test_user_used_quota_for_a_day(self):
|
||||||
us = self.__build_user_service('test_user')
|
us = self.__build_user_service('test_user')
|
||||||
test_helper.increment_service_uses(self.redis_conn, 'test_user',
|
increment_service_uses(self.redis_conn, 'test_user',
|
||||||
amount=400)
|
amount=400)
|
||||||
assert us.used_quota(self.NOKIA_GEOCODER, date.today()) == 400
|
assert us.used_quota(self.NOKIA_GEOCODER, date.today()) == 400
|
||||||
|
|
||||||
def test_org_used_quota_for_a_day(self):
|
def test_org_used_quota_for_a_day(self):
|
||||||
us = self.__build_user_service('test_user', orgname='test_org')
|
us = self.__build_user_service('test_user', orgname='test_org')
|
||||||
test_helper.increment_service_uses(self.redis_conn, 'test_user',
|
increment_service_uses(self.redis_conn, 'test_user',
|
||||||
orgname='test_org',
|
orgname='test_org',
|
||||||
amount=400)
|
amount=400)
|
||||||
assert us.used_quota(self.NOKIA_GEOCODER, date.today()) == 400
|
assert us.used_quota(self.NOKIA_GEOCODER, date.today()) == 400
|
||||||
@@ -135,14 +135,13 @@ class TestUserService(TestCase):
|
|||||||
def __build_user_service(self, username, quota=100, service='heremaps',
|
def __build_user_service(self, username, quota=100, service='heremaps',
|
||||||
orgname=None, soft_limit=False,
|
orgname=None, soft_limit=False,
|
||||||
end_date=date.today()):
|
end_date=date.today()):
|
||||||
test_helper.build_redis_user_config(self.redis_conn, username,
|
build_redis_user_config(self.redis_conn, username,
|
||||||
quota=quota, service=service,
|
quota=quota, service=service,
|
||||||
soft_limit=soft_limit,
|
soft_limit=soft_limit,
|
||||||
end_date=end_date)
|
end_date=end_date)
|
||||||
if orgname:
|
if orgname:
|
||||||
test_helper.build_redis_org_config(self.redis_conn, orgname,
|
build_redis_org_config(self.redis_conn, orgname,
|
||||||
quota=quota, end_date=end_date)
|
quota=quota, end_date=end_date)
|
||||||
plpy_mock = test_helper.build_plpy_mock()
|
|
||||||
geocoder_config = GeocoderConfig(self.redis_conn, plpy_mock,
|
geocoder_config = GeocoderConfig(self.redis_conn, plpy_mock,
|
||||||
username, orgname)
|
username, orgname)
|
||||||
return UserMetricsService(geocoder_config, self.redis_conn)
|
return UserMetricsService(geocoder_config, self.redis_conn)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ This are the automatic integration tests for geocoder api (both client and serve
|
|||||||
In order to execute the tests you have to execute the `run_tests.py` python script:
|
In order to execute the tests you have to execute the `run_tests.py` python script:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
python run_tests.py [--host=cartodb.com] username api_key
|
python run_tests.py [--host=cartodb.com --schema=https] username api_key
|
||||||
```
|
```
|
||||||
|
|
||||||
You can define the host where is going to execute the SQL API queries to test the
|
You can define the host where is going to execute the SQL API queries to test the
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ import time
|
|||||||
class ImportHelper:
|
class ImportHelper:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def import_test_dataset(cls, username, api_key, host):
|
def import_test_dataset(cls, username, api_key, host, schema):
|
||||||
requests.packages.urllib3.disable_warnings()
|
requests.packages.urllib3.disable_warnings()
|
||||||
url = "https://{0}.{1}/api/v1/imports/"\
|
url = "{0}://{1}.{2}/api/v1/imports/"\
|
||||||
"?type_guessing=false&privacy=public&api_key={2}".format(
|
"?type_guessing=false&privacy=public&api_key={3}".format(
|
||||||
username, host, api_key)
|
schema, username, host, api_key)
|
||||||
dataset = {
|
dataset = {
|
||||||
'file': open('fixtures/geocoder_api_test_dataset.csv', 'rb')}
|
'file': open('fixtures/geocoder_api_test_dataset.csv', 'rb')}
|
||||||
response = requests.post(url, files=dataset)
|
response = requests.post(url, files=dataset)
|
||||||
@@ -27,7 +27,8 @@ class ImportHelper:
|
|||||||
username,
|
username,
|
||||||
host,
|
host,
|
||||||
api_key,
|
api_key,
|
||||||
response_json['item_queue_id']
|
response_json['item_queue_id'],
|
||||||
|
schema
|
||||||
)
|
)
|
||||||
if table_name:
|
if table_name:
|
||||||
return table_name
|
return table_name
|
||||||
@@ -35,10 +36,10 @@ class ImportHelper:
|
|||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_imported_table_name(cls, username, host, api_key, import_id):
|
def get_imported_table_name(cls, username, host, api_key, import_id, schema):
|
||||||
requests.packages.urllib3.disable_warnings()
|
requests.packages.urllib3.disable_warnings()
|
||||||
import_url = "https://{0}.{1}/api/v1/imports/{2}?api_key={3}".format(
|
import_url = "{0}://{1}.{2}/api/v1/imports/{3}?api_key={4}".format(
|
||||||
username, host, import_id, api_key)
|
schema, username, host, import_id, api_key)
|
||||||
import_data_response = requests.get(import_url)
|
import_data_response = requests.get(import_url)
|
||||||
if import_data_response.status_code != 200:
|
if import_data_response.status_code != 200:
|
||||||
print "Error getting the table name from " \
|
print "Error getting the table name from " \
|
||||||
@@ -49,10 +50,10 @@ class ImportHelper:
|
|||||||
return import_data_json['table_name']
|
return import_data_json['table_name']
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def clean_test_dataset(cls, username, api_key, table_name, host):
|
def clean_test_dataset(cls, username, api_key, table_name, host, schema):
|
||||||
requests.packages.urllib3.disable_warnings()
|
requests.packages.urllib3.disable_warnings()
|
||||||
url = "https://{0}.{1}/api/v2/sql?q=drop table {2}&api_key={3}".format(
|
url = "{0}://{1}.{2}/api/v2/sql?q=drop table {3}&api_key={4}".format(
|
||||||
username, host, table_name, api_key
|
schema, username, host, table_name, api_key
|
||||||
)
|
)
|
||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
|
|||||||
@@ -10,11 +10,13 @@ class IntegrationTestHelper:
|
|||||||
username = os.environ["GEOCODER_API_TEST_USERNAME"]
|
username = os.environ["GEOCODER_API_TEST_USERNAME"]
|
||||||
api_key = os.environ["GEOCODER_API_TEST_API_KEY"]
|
api_key = os.environ["GEOCODER_API_TEST_API_KEY"]
|
||||||
host = os.environ["GEOCODER_API_TEST_HOST"]
|
host = os.environ["GEOCODER_API_TEST_HOST"]
|
||||||
|
schema = os.environ["GEOCODER_API_TEST_SCHEMA"]
|
||||||
table_name = os.environ["GEOCODER_API_TEST_TABLE_NAME"]
|
table_name = os.environ["GEOCODER_API_TEST_TABLE_NAME"]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"username": username,
|
"username": username,
|
||||||
"api_key": api_key,
|
"api_key": api_key,
|
||||||
|
"schema": schema,
|
||||||
"host": host,
|
"host": host,
|
||||||
"table_name": table_name
|
"table_name": table_name
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ class TestAdmin0Functions(TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.env_variables = IntegrationTestHelper.get_environment_variables()
|
self.env_variables = IntegrationTestHelper.get_environment_variables()
|
||||||
self.sql_api_url = "https://{0}.{1}/api/v1/sql".format(
|
self.sql_api_url = "{0}://{1}.{2}/api/v1/sql".format(
|
||||||
|
self.env_variables['schema'],
|
||||||
self.env_variables['username'],
|
self.env_variables['username'],
|
||||||
self.env_variables['host'],
|
self.env_variables['host'],
|
||||||
self.env_variables['api_key']
|
self.env_variables['api_key']
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ class TestAdmin1Functions(TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.env_variables = IntegrationTestHelper.get_environment_variables()
|
self.env_variables = IntegrationTestHelper.get_environment_variables()
|
||||||
self.sql_api_url = "https://{0}.{1}/api/v1/sql".format(
|
self.sql_api_url = "{0}://{1}.{2}/api/v1/sql".format(
|
||||||
|
self.env_variables['schema'],
|
||||||
self.env_variables['username'],
|
self.env_variables['username'],
|
||||||
self.env_variables['host'],
|
self.env_variables['host'],
|
||||||
self.env_variables['api_key']
|
self.env_variables['api_key']
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ class TestDataObservatoryFunctions(TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.env_variables = IntegrationTestHelper.get_environment_variables()
|
self.env_variables = IntegrationTestHelper.get_environment_variables()
|
||||||
self.sql_api_url = "https://{0}.{1}/api/v1/sql".format(
|
self.sql_api_url = "{0}://{1}.{2}/api/v1/sql".format(
|
||||||
|
self.env_variables['schema'],
|
||||||
self.env_variables['username'],
|
self.env_variables['username'],
|
||||||
self.env_variables['host'],
|
self.env_variables['host'],
|
||||||
self.env_variables['api_key']
|
self.env_variables['api_key']
|
||||||
@@ -230,3 +231,62 @@ class TestDataObservatoryFunctions(TestCase):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
assert_equal(e.message[0], "The api_key must be provided")
|
assert_equal(e.message[0], "The api_key must be provided")
|
||||||
|
|
||||||
|
def test_if_obs_get_legacy_builder_metadata_is_ok(self):
|
||||||
|
query = "SELECT name FROM OBS_LegacyBuilderMetadata() LIMIT 1;&api_key={0}".format(self.env_variables['api_key'])
|
||||||
|
result = IntegrationTestHelper.execute_query(self.sql_api_url, query)
|
||||||
|
assert_not_equal(result['name'], None)
|
||||||
|
|
||||||
|
def test_if_obs_get_points_by_point_and_radius_without_api_key_raise_error(self):
|
||||||
|
query = "SELECT name FROM OBS_LegacyBuilderMetadata() LIMIT 1;"
|
||||||
|
try:
|
||||||
|
IntegrationTestHelper.execute_query(self.sql_api_url, query)
|
||||||
|
except Exception as e:
|
||||||
|
assert_equal(e.message[0], "The api_key must be provided")
|
||||||
|
|
||||||
|
def test_if_obs_get_available_numerators_is_ok(self):
|
||||||
|
query = "SELECT numer_id FROM OBS_GetAvailableNumerators() LIMIT 1;&api_key={0}".format(self.env_variables['api_key'])
|
||||||
|
result = IntegrationTestHelper.execute_query(self.sql_api_url, query)
|
||||||
|
assert_not_equal(result['numer_id'], None)
|
||||||
|
|
||||||
|
def test_if_obs_get_available_numerators_without_api_key_raise_error(self):
|
||||||
|
query = "SELECT numer_id FROM OBS_GetAvailableNumerators() LIMIT 1;"
|
||||||
|
try:
|
||||||
|
IntegrationTestHelper.execute_query(self.sql_api_url, query)
|
||||||
|
except Exception as e:
|
||||||
|
assert_equal(e.message[0], "The api_key must be provided")
|
||||||
|
|
||||||
|
def test_if_obs_get_available_denominators_is_ok(self):
|
||||||
|
query = "SELECT denom_id FROM OBS_GetAvailableDenominators() LIMIT 1;&api_key={0}".format(self.env_variables['api_key'])
|
||||||
|
result = IntegrationTestHelper.execute_query(self.sql_api_url, query)
|
||||||
|
assert_not_equal(result['denom_id'], None)
|
||||||
|
|
||||||
|
def test_if_obs_get_available_denominators_without_api_key_raise_error(self):
|
||||||
|
query = "SELECT denom_id FROM OBS_GetAvailableDenominators() LIMIT 1;"
|
||||||
|
try:
|
||||||
|
IntegrationTestHelper.execute_query(self.sql_api_url, query)
|
||||||
|
except Exception as e:
|
||||||
|
assert_equal(e.message[0], "The api_key must be provided")
|
||||||
|
|
||||||
|
def test_if_obs_get_available_geometries_is_ok(self):
|
||||||
|
query = "SELECT geom_id FROM OBS_GetAvailableGeometries() LIMIT 1;&api_key={0}".format(self.env_variables['api_key'])
|
||||||
|
result = IntegrationTestHelper.execute_query(self.sql_api_url, query)
|
||||||
|
assert_not_equal(result['geom_id'], None)
|
||||||
|
|
||||||
|
def test_if_obs_get_available_geometries_without_api_key_raise_error(self):
|
||||||
|
query = "SELECT geom_id FROM OBS_GetAvailableGeometries() LIMIT 1;"
|
||||||
|
try:
|
||||||
|
IntegrationTestHelper.execute_query(self.sql_api_url, query)
|
||||||
|
except Exception as e:
|
||||||
|
assert_equal(e.message[0], "The api_key must be provided")
|
||||||
|
|
||||||
|
def test_if_obs_get_available_timespans_is_ok(self):
|
||||||
|
query = "SELECT timespan_id FROM OBS_GetAvailableTimespans() LIMIT 1;&api_key={0}".format(self.env_variables['api_key'])
|
||||||
|
result = IntegrationTestHelper.execute_query(self.sql_api_url, query)
|
||||||
|
assert_not_equal(result['timespan_id'], None)
|
||||||
|
|
||||||
|
def test_if_obs_get_available_timespans_without_api_key_raise_error(self):
|
||||||
|
query = "SELECT timespan_id FROM OBS_GetAvailableTimespans() LIMIT 1;"
|
||||||
|
try:
|
||||||
|
IntegrationTestHelper.execute_query(self.sql_api_url, query)
|
||||||
|
except Exception as e:
|
||||||
|
assert_equal(e.message[0], "The api_key must be provided")
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ class TestPostalcodeFunctions(TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.env_variables = IntegrationTestHelper.get_environment_variables()
|
self.env_variables = IntegrationTestHelper.get_environment_variables()
|
||||||
self.sql_api_url = "https://{0}.{1}/api/v1/sql".format(
|
self.sql_api_url = "{0}://{1}.{2}/api/v1/sql".format(
|
||||||
|
self.env_variables['schema'],
|
||||||
self.env_variables['username'],
|
self.env_variables['username'],
|
||||||
self.env_variables['host'],
|
self.env_variables['host'],
|
||||||
self.env_variables['api_key']
|
self.env_variables['api_key']
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ class TestIsolinesFunctions(TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.env_variables = IntegrationTestHelper.get_environment_variables()
|
self.env_variables = IntegrationTestHelper.get_environment_variables()
|
||||||
self.sql_api_url = "https://{0}.{1}/api/v1/sql".format(
|
self.sql_api_url = "{0}://{1}.{2}/api/v1/sql".format(
|
||||||
|
self.env_variables['schema'],
|
||||||
self.env_variables['username'],
|
self.env_variables['username'],
|
||||||
self.env_variables['host'],
|
self.env_variables['host'],
|
||||||
self.env_variables['api_key']
|
self.env_variables['api_key']
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ class TestNameplaceFunctions(TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.env_variables = IntegrationTestHelper.get_environment_variables()
|
self.env_variables = IntegrationTestHelper.get_environment_variables()
|
||||||
self.sql_api_url = "https://{0}.{1}/api/v1/sql".format(
|
self.sql_api_url = "{0}://{1}.{2}/api/v1/sql".format(
|
||||||
|
self.env_variables['schema'],
|
||||||
self.env_variables['username'],
|
self.env_variables['username'],
|
||||||
self.env_variables['host'],
|
self.env_variables['host'],
|
||||||
self.env_variables['api_key']
|
self.env_variables['api_key']
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ class TestPostalcodeFunctions(TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.env_variables = IntegrationTestHelper.get_environment_variables()
|
self.env_variables = IntegrationTestHelper.get_environment_variables()
|
||||||
self.sql_api_url = "https://{0}.{1}/api/v1/sql".format(
|
self.sql_api_url = "{0}://{1}.{2}/api/v1/sql".format(
|
||||||
|
self.env_variables['schema'],
|
||||||
self.env_variables['username'],
|
self.env_variables['username'],
|
||||||
self.env_variables['host'],
|
self.env_variables['host'],
|
||||||
self.env_variables['api_key']
|
self.env_variables['api_key']
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ class TestRoutingFunctions(TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.env_variables = IntegrationTestHelper.get_environment_variables()
|
self.env_variables = IntegrationTestHelper.get_environment_variables()
|
||||||
self.sql_api_url = "https://{0}.{1}/api/v1/sql".format(
|
self.sql_api_url = "{0}://{1}.{2}/api/v1/sql".format(
|
||||||
|
self.env_variables['schema'],
|
||||||
self.env_variables['username'],
|
self.env_variables['username'],
|
||||||
self.env_variables['host'],
|
self.env_variables['host'],
|
||||||
self.env_variables['api_key']
|
self.env_variables['api_key']
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ class TestStreetFunctions(TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.env_variables = IntegrationTestHelper.get_environment_variables()
|
self.env_variables = IntegrationTestHelper.get_environment_variables()
|
||||||
self.sql_api_url = "https://{0}.{1}/api/v1/sql".format(
|
self.sql_api_url = "{0}://{1}.{2}/api/v1/sql".format(
|
||||||
|
self.env_variables['schema'],
|
||||||
self.env_variables['username'],
|
self.env_variables['username'],
|
||||||
self.env_variables['host'],
|
self.env_variables['host'],
|
||||||
self.env_variables['api_key']
|
self.env_variables['api_key']
|
||||||
|
|||||||
@@ -8,12 +8,13 @@ from helpers.import_helper import ImportHelper
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
opts, args = getopt.getopt(sys.argv[1:], "h", ["help", "host="])
|
opts, args = getopt.getopt(sys.argv[1:], "h", ["help", "host=", "schema="])
|
||||||
|
|
||||||
if len(args) < 2:
|
if len(args) < 2:
|
||||||
usage()
|
usage()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
schema = "https"
|
||||||
host = "cartodb.com"
|
host = "cartodb.com"
|
||||||
username = args[0]
|
username = args[0]
|
||||||
api_key = args[1]
|
api_key = args[1]
|
||||||
@@ -24,26 +25,31 @@ def main():
|
|||||||
sys.exit()
|
sys.exit()
|
||||||
elif o in ("--host"):
|
elif o in ("--host"):
|
||||||
host = opts[0][1]
|
host = opts[0][1]
|
||||||
|
elif o in ("--schema"):
|
||||||
|
schema = opts[1][1]
|
||||||
else:
|
else:
|
||||||
assert False, "unhandled option"
|
assert False, "unhandled option"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
table_name = ImportHelper.import_test_dataset(username, api_key, host)
|
table_name = ImportHelper.import_test_dataset(username, api_key, host,
|
||||||
set_environment_variables(username, api_key, table_name, host)
|
schema)
|
||||||
|
set_environment_variables(username, api_key, table_name, host, schema)
|
||||||
execute_tests()
|
execute_tests()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print e.message
|
print e.message
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
finally:
|
finally:
|
||||||
clean_environment_variables()
|
clean_environment_variables()
|
||||||
ImportHelper.clean_test_dataset(username, api_key, table_name, host)
|
ImportHelper.clean_test_dataset(username, api_key, table_name, host,
|
||||||
|
schema)
|
||||||
|
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
print """Usage: run_tests.py [options] username api_key
|
print """Usage: run_tests.py [options] username api_key
|
||||||
Options:
|
Options:
|
||||||
-h: Show this help
|
-h: Show this help
|
||||||
--host: take that host as base (by default is cartodb.com)"""
|
--host: take that host as base (by default is cartodb.com)
|
||||||
|
--schema: define the url schema [http/https] (by default https)"""
|
||||||
|
|
||||||
|
|
||||||
def execute_tests():
|
def execute_tests():
|
||||||
@@ -59,11 +65,12 @@ def execute_tests():
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def set_environment_variables(username, api_key, table_name, host):
|
def set_environment_variables(username, api_key, table_name, host, schema):
|
||||||
os.environ["GEOCODER_API_TEST_USERNAME"] = username
|
os.environ["GEOCODER_API_TEST_USERNAME"] = username
|
||||||
os.environ["GEOCODER_API_TEST_API_KEY"] = api_key
|
os.environ["GEOCODER_API_TEST_API_KEY"] = api_key
|
||||||
os.environ["GEOCODER_API_TEST_TABLE_NAME"] = table_name
|
os.environ["GEOCODER_API_TEST_TABLE_NAME"] = table_name
|
||||||
os.environ["GEOCODER_API_TEST_HOST"] = host
|
os.environ["GEOCODER_API_TEST_HOST"] = host
|
||||||
|
os.environ["GEOCODER_API_TEST_SCHEMA"] = schema
|
||||||
|
|
||||||
|
|
||||||
def clean_environment_variables():
|
def clean_environment_variables():
|
||||||
@@ -71,6 +78,7 @@ def clean_environment_variables():
|
|||||||
del os.environ["GEOCODER_API_TEST_API_KEY"]
|
del os.environ["GEOCODER_API_TEST_API_KEY"]
|
||||||
del os.environ["GEOCODER_API_TEST_TABLE_NAME"]
|
del os.environ["GEOCODER_API_TEST_TABLE_NAME"]
|
||||||
del os.environ["GEOCODER_API_TEST_HOST"]
|
del os.environ["GEOCODER_API_TEST_HOST"]
|
||||||
|
del os.environ["GEOCODER_API_TEST_SCHEMA"]
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user