# Suitability of Graph Database Technology for the Analysis of Spatio-Temporal Data
## Appendix A Queries
### Gsql
g.V().hasLabel(\"Resource\").has(\"resource_id\", \"2\") .in(\"RESPONSE_RESOURCE\").hasLabel(\"Response\") .has(\"destination\", geoWithin(Geoshape.circle(63.67, 19.11, 0.5))).as(\"RES\").out(\"RESPONSE_SCENE\").as(\"SCN\").select(\"RES\") .groupCount().by(out(\"RESPONSE_PRIORIT\").values(\"priority_id\"))

#### a.5.3. Gsql

Listing A18: A SQL query that returns the total number of responses, grouped by priority of the call, that were the second resource and ended up transferring patients to a given hospital. CREATE QUERY postSim2() FOR GRAPH MyGraph {  SetAccum<STRING> @@vSet;  GroupByAccum<STRING pri, SumAccum<INT> total> @@group;  STRING resource_id = \"2\";  FLOAT lat = 19.11;  FLOAT lon = 63.67;  FLOAT distKm = 0.5;  resources = { Resource. * };  Grids = to_vertex_set(getNearbyGridId(distKm, lat, lon), \"Geo_Grid\");  ResponsesByGeo =  SELECT r  FROM Grids:-(Dest_Geo:e)-Response:r  WHERE geoDistance(lat, lon, e.LATITUDE, e.LONGITUDE) <= distKm;  ResponsesByRsrc =  SELECT r  FROM resources:rsc-(Response_Resource)-Response:r  WHERE rsc.id == resource_id;  ResponsesByGeoAndRsrc = ResponsesByRsrc INTERSECT ResponsesByGeo;  ResponsesByOnScene =  SELECT r  FROM ResponsesByGeoAndRsrc:r-(Response_Scene)-On_Scene;  TargetResponses =  SELECT h  FROM ResponsesByOnScene:h-(Response_Priority)-Priority:p  ACCUM @group += (p.id -> 1);  PRINT @group; }

### Medical: Long Response Count

#### a.6.1 Sql

Listing A19: A SQL query that returns how many responses took longer than 15 min from the time the call was logged until the patient was at the hospital. SELECT count(*) FROM transfer TNS JOIN response RES ON TNS.response_id = RES.id WHERE RES.time_to_ambulance_starts + RES.on_scene_duration + TNS.travel_time_hospital > 15 * 60;

#### a.6.2 Groovy

Listing A20: A SQL query that returns how many responses took longer than 15 min from the time the call was logged until the patient was at the hospital. g.V().hasLabel(\"Transfer\").as(\"tth\") .in(\"RESPONSE_TRANSFER\").as(\"ttas\", \"osd\") .where(math(\"ttas + osd + tth\").by(values(\"time_to_ambulance_starts\")) .by(values(\"on_scene_duration\")) .by(values(\"travel_time_hospital\")) .is(gt(15 * 60))).count()

## Appendix A.6.3 GSQL

Listing A21: A SQL query that returns how many responses took longer than 15 min from the time the call was logged until the patient was at the hospital. CREATE QUERY postSim3() FOR GRAPH MyGraph { SumAccum=INIT> @totalResponses; responses = { Response. * }; LongResponses =  SELECT res  FROM responses:res-(Response_Transfer)-Transfer:tns  WHERE  res.TIME_TO_AMbulANCE_STARTS +  res.ON_SCENE_DURATION +  tns.TRAVEL_TIME_HOSPITAL > 15 * 60  ACCUM @totalResponses += 1; PRINT @totalResponses; }

## Appendix B Database Schemas







Google; Angular. 2010. Available online: https://angulario/ (accessed on 1 March 2020). * (9) GeoMesa. 2019. Available online: [[https://www.geomesa.org/](https://www.geomesa.org/)]([https://www.geomesa.org/](https://www.geomesa.org/)) (accessed on 1 March 2020). * (10) [PERSON]; [PERSON]; [PERSON]; [PERSON] [PERSON]; [PERSON] [PERSON]; [PERSON]; [PERSON] [PERSON]; [PERSON]; [PERSON] [PERSON]: An open source GIS library for large-scale environmental and socio-economic applications. In _Open Source Approaches in Spatial Data Handling_; Springer: Berlin/Heidelberg, Germany, 2008; pp. 247-270. * (11) [PERSON] Comparative study of nosql document, column store databases and evaluation of cassandra. _Int. J. Database Manag. Syst._**2014**, 6, 11. * (12) [PERSON] Distributed, Transactional Key-Value Store. U.S. Patent 9,037,556, 21 April 2015. * (13) [PERSON]; [PERSON]; [PERSON]; [PERSON] TigerGraph: A Native MPP Graph Database. _arXiv_**2019**, arXiv:1901.08248. Available online: [[https://arxiv.org/abs/1901.08248](https://arxiv.org/abs/1901.08248)]([https://arxiv.org/abs/1901.08248](https://arxiv.org/abs/1901.08248)) (accessed on 1 March 2020). * (14) [PERSON]; [PERSON]; [PERSON]; [PERSON]; [PERSON]; [PERSON]; [PERSON]; [PERSON]; [PERSON]; [PERSON]; et al. TAO: Facebook's Distributed Data Store for the Social Graph.