1111 # rest API backend endpoints
1212 "flows/unique_targets/(.*)/" , "flows" ,
1313 "story/metric/(\d+)/" , "metrics" ,
14- "angular/directives/(.*)/" , "ng_directives" ,
15- "countries/groups/" , "node_groups" ,
16- "geojson/(.*)/" , "geojson" ,
14+ "angular/directives/(.*)/" , "ng_directives" ,
15+ "countries/groups/" , "node_groups" ,
16+ "geojson/(.*)/" , "geojson" ,
1717 "(.*)/" , "nodes"
1818
1919)
@@ -27,22 +27,22 @@ def GET(self, source_id, connection_string=helper.get_connection_string(os.envir
2727 # execute query
2828 self .cursor .execute ("""
2929 select gn.name as source_name,
30- cy.iso2code as source,
31- gnt.name as target_name,
32- cyt.iso2code as target,
33- cy.id as source_id,
34- count(cdis.target_id) as value
35- from """ + helper .table_prefix + """cdis cdis
36- left join """ + helper .table_prefix + """geography_name gn on gn.id = cdis.source_id
37- left join """ + helper .table_prefix + """geography_name gnt on gnt.id = cdis.target_id
38- left join """ + helper .table_prefix + """country cy on cy.id = cdis.source_id
39- left join """ + helper .table_prefix + """country cyt on cyt.id = cdis.target_id
40- where source_id = """ + source_id + """ and cyt.iso2code is not null
41- group by gn.name,
42- cy.iso2code,
43- cy.id,
44- gnt.name,
45- cyt.iso2code
30+ cy.iso2code as source,
31+ gnt.name as target_name,
32+ cyt.iso2code as target,
33+ cy.id as source_id,
34+ count(cdis.target_id) as value
35+ from """ + helper .table_prefix + """cdis cdis
36+ left join """ + helper .table_prefix + """geography_name gn on gn.id = cdis.source_id
37+ left join """ + helper .table_prefix + """geography_name gnt on gnt.id = cdis.target_id
38+ left join """ + helper .table_prefix + """country cy on cy.id = cdis.source_id
39+ left join """ + helper .table_prefix + """country cyt on cyt.id = cdis.target_id
40+ where source_id = """ + source_id + """ and cyt.iso2code is not null
41+ group by gn.name,
42+ cy.iso2code,
43+ cy.id,
44+ gnt.name,
45+ cyt.iso2code
4646 """ )
4747 # obtain the data
4848 data = self .cursor .fetchall ()
@@ -57,17 +57,17 @@ def GET(self, table, connection_string=helper.get_connection_string(os.environ['
5757 self .cursor = connection .cursor (cursor_factory = psycopg2 .extras .RealDictCursor )
5858 # execute query
5959 self .cursor .execute ("""
60- select distinct on (gn.name) gn.name,
61- cy.iso2code as iso,
62- cy.id,
63- count(distinct cdis.target_id) as count
64- from """ + helper .table_prefix + """country cy
65- left join """ + helper .table_prefix + """geography_name gn on gn.id = cy.name_id
66- left join """ + helper .table_prefix + """geography geo on geo.name_id = cy.name_id
67- left join """ + helper .table_prefix + """cdis cdis on source_id = cy.id
68- group by gn.name,
69- cy.iso2code,
70- cy.id
60+ select distinct on (gn.name) gn.name,
61+ cy.iso2code as iso,
62+ cy.id,
63+ count(distinct cdis.target_id) as count
64+ from """ + helper .table_prefix + """country cy
65+ left join """ + helper .table_prefix + """geography_name gn on gn.id = cy.name_id
66+ left join """ + helper .table_prefix + """geography geo on geo.name_id = cy.name_id
67+ left join """ + helper .table_prefix + """cdis cdis on source_id = cy.id
68+ group by gn.name,
69+ cy.iso2code,
70+ cy.id
7171 """ )
7272 # obtain the data
7373 data = self .cursor .fetchall ()
@@ -146,20 +146,20 @@ def GET(self, grid, connection_string=helper.get_connection_string(os.environ['D
146146 row_to_json(f) as properties,
147147 row_to_json(c) as geometry
148148 from t,
149- """ + helper .table_prefix + """geography geo
149+ """ + helper .table_prefix + """geography geo
150150 left join (
151- select geo.id,
151+ select geo.id,
152152 gn.name,
153153 cy.iso2code as iso
154154 from """ + helper .table_prefix + """geography geo
155155 left join """ + helper .table_prefix + """geography_name gn on gn.id = geo.name_id
156156 left join """ + helper .table_prefix + """country cy on cy.id = geo.name_id
157- ) f on f.id = geo.id
158- left join (
159- with t as (
160- select 'Polygon'::text
161- )
162- select t.text as type,
157+ ) f on f.id = geo.id
158+ left join (
159+ with t as (
160+ select 'Polygon'::text
161+ )
162+ select t.text as type,
163163 geo.hexagon_polygon as coordinates
164164 from t,
165165 """ + helper .table_prefix + """geography geo
@@ -172,7 +172,7 @@ def GET(self, grid, connection_string=helper.get_connection_string(os.environ['D
172172 data = self .cursor .fetchall ()
173173 # convert data to a string
174174 return json .dumps (data )
175-
175+
176176class ng_directives :
177177 def GET (self , vis_id , connection_string = helper .get_connection_string (os .environ ['DATABASE_URL' ])):
178178 # connect to postgresql based on configuration in connection_string
@@ -182,13 +182,13 @@ def GET(self, vis_id, connection_string=helper.get_connection_string(os.environ[
182182 # execute query
183183 self .cursor .execute ("""
184184 select *
185- from gestalt_vis
186- where id = """ + vis_id + """;
185+ from gestalt_vis
186+ where id = """ + vis_id + """;
187187 """ )
188188 # obtain the data
189189 data = self .cursor .fetchall ()
190190 # convert data to a string
191191 return json .dumps (data )
192192
193193# instantiate the application
194- app = web .application (urls , locals ())
194+ app = web .application (urls , locals ())
0 commit comments