{"action":"created","comment":{"url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/pulls/comments/63865474","id":63865474,"diff_hunk":"@@ -398,4 +444,138 @@ protected String buildTableName(String servicePath, String entity, String attrib\n         return name;\n     } // buildTableName\n     \n+    private void persistRawAggregation(CartoDBAggregator aggregator) throws Exception {\n+        //String dbName = aggregator.getDbName(); // enable_lowercase is unncessary, PostgreSQL is case insensitive\n+        String tableName = aggregator.getTableName(); // enable_lowercase is unncessary, PostgreSQL is case insensitive\n+        String withs = \"\";\n+        String fields = aggregator.getFields();\n+        String rows = aggregator.getRows();\n+        LOGGER.info(\"[\" + this.getName() + \"] Persisting data at NGSICartoDBSink. Schema (\" + schema\n+                + \"), Table (\" + tableName + \"), Data (\" + rows + \")\");\n+        backend.insert(tableName, withs, fields, rows);\n+    } // persistRawAggregation\n+    \n+    private void persistDistanceEvent(NGSIEvent event) throws Exception {\n+        // Get some values\n+        String servicePath = event.getServicePath();\n+        String entityId = event.getContextElement().getId();\n+        String entityType = event.getContextElement().getType();\n+        \n+        // Iterate on all this context element attributes, if there are attributes\n+        ArrayList<ContextAttribute> contextAttributes = event.getContextElement().getAttributes();\n+\n+        if (contextAttributes == null || contextAttributes.isEmpty()) {\n+            return;\n+        } // if\n+\n+        for (ContextAttribute contextAttribute : contextAttributes) {\n+            long recvTimeMs = event.getRecvTimeTs();\n+            String attrType = contextAttribute.getType();\n+            String attrValue = contextAttribute.getContextValue(false);\n+            String attrMetadata = contextAttribute.getContextMetadata();\n+            String location = NGSIUtils.getLocation(attrValue, attrType, attrMetadata, flipCoordinates);\n+            String tableName = schema\n+                    + \".\" + buildTableName(event.getServicePath(), event.getEntity(), event.getAttribute())\n+                    + \"_distance\";\n+\n+            if (location.startsWith(\"ST_SetSRID(ST_MakePoint(\")) {\n+                // Try creating the table... the cost of checking if it exists and creating it is higher than directly\n+                // attempting to create it. If existing, nothing will be re-created and the new values will be inserted\n+                \n+                try {\n+                    String typedFields = \"(recvTimeMs bigint, fiwareServicePath text, entityId text, entityType text, \"\n+                            + \"stageDistance float, stageTime float, stageSpeed float, sumDistance float, \"\n+                            + \"sumTime float, sumSpeed float, sum2Distance float, sum2Time float, sum2Speed float, \"\n+                            + \"maxDistance float, minDistance float, maxTime float, minTime float, maxSpeed float, \"\n+                            + \"minSpeed float, numSamples bigint)\";\n+                    backend.createTable(schema, tableName, typedFields);\n+                    \n+                    // Once created, insert the first row\n+                    String withs = \"\";\n+                    String fields = \"(recvTimeMs, fiwareServicePath, entityId, entityType, the_geom, stageDistance,\"\n+                            + \"stageTime, stageSpeed, sumDistance, sumTime, sumSpeed, sum2Distance, sum2Time,\"\n+                            + \"sum2Speed, maxDistance, minDistance, maxTime, mintime, maxSpeed, minSpeed, numSamples)\";\n+                    String rows = \"(\" + recvTimeMs + \",'\" + servicePath + \"','\" + entityId + \"','\" + entityType + \"',\"\n+                            + location + \",0,0,0,0,0,0,0,0,0,-999999,999999,-999999,999999,-999999,999999,1)\";","path":"cygnus-ngsi/src/main/java/com/telefonica/iot/cygnus/sinks/NGSICartoDBSink.java","position":206,"original_position":206,"commit_id":"7e16f2ded5694f3629e1416296981a6dcd4ec061","original_commit_id":"7e16f2ded5694f3629e1416296981a6dcd4ec061","user":{"login":"gtorodelvalle","id":667284,"avatar_url":"https://avatars.githubusercontent.com/u/667284?v=3","gravatar_id":"","url":"https://api.github.com/users/gtorodelvalle","html_url":"https://github.com/gtorodelvalle","followers_url":"https://api.github.com/users/gtorodelvalle/followers","following_url":"https://api.github.com/users/gtorodelvalle/following{/other_user}","gists_url":"https://api.github.com/users/gtorodelvalle/gists{/gist_id}","starred_url":"https://api.github.com/users/gtorodelvalle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gtorodelvalle/subscriptions","organizations_url":"https://api.github.com/users/gtorodelvalle/orgs","repos_url":"https://api.github.com/users/gtorodelvalle/repos","events_url":"https://api.github.com/users/gtorodelvalle/events{/privacy}","received_events_url":"https://api.github.com/users/gtorodelvalle/received_events","type":"User","site_admin":false},"body":"Ups, I though it was only an issue related with positive and negative infinite values... :)","created_at":"2016-05-19T11:59:49Z","updated_at":"2016-05-19T11:59:50Z","html_url":"https://github.com/telefonicaid/fiware-cygnus/pull/1031#discussion_r63865474","pull_request_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/pulls/1031","_links":{"self":{"href":"https://api.github.com/repos/telefonicaid/fiware-cygnus/pulls/comments/63865474"},"html":{"href":"https://github.com/telefonicaid/fiware-cygnus/pull/1031#discussion_r63865474"},"pull_request":{"href":"https://api.github.com/repos/telefonicaid/fiware-cygnus/pulls/1031"}}},"pull_request":{"url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/pulls/1031","id":70671786,"html_url":"https://github.com/telefonicaid/fiware-cygnus/pull/1031","diff_url":"https://github.com/telefonicaid/fiware-cygnus/pull/1031.diff","patch_url":"https://github.com/telefonicaid/fiware-cygnus/pull/1031.patch","issue_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/issues/1031","number":1031,"state":"open","locked":false,"title":"feature/1026_add_enable_distance_analysis_ngsicartodbsink","user":{"login":"frbattid","id":3865056,"avatar_url":"https://avatars.githubusercontent.com/u/3865056?v=3","gravatar_id":"","url":"https://api.github.com/users/frbattid","html_url":"https://github.com/frbattid","followers_url":"https://api.github.com/users/frbattid/followers","following_url":"https://api.github.com/users/frbattid/following{/other_user}","gists_url":"https://api.github.com/users/frbattid/gists{/gist_id}","starred_url":"https://api.github.com/users/frbattid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frbattid/subscriptions","organizations_url":"https://api.github.com/users/frbattid/orgs","repos_url":"https://api.github.com/users/frbattid/repos","events_url":"https://api.github.com/users/frbattid/events{/privacy}","received_events_url":"https://api.github.com/users/frbattid/received_events","type":"User","site_admin":false},"body":"* Implements issue #1026 \r\n* 100% unit tests passed:\r\n```\r\nTests run: 43, Failures: 0, Errors: 0, Skipped: 0 --> cygnus-common\r\nTests run: 86, Failures: 0, Errors: 0, Skipped: 0 --> cygnus-ngsi\r\n```\r\n\r\nRelevant tests in this PR:\r\n```\r\n[NGSICartoDBSink.configure] --------------------- Configured `enable_raw` cannot be different than `true` or `false`\r\n[NGSICartoDBSink.configure] --------------  OK  - 'enable_raw=falso' was detected\r\n[NGSICartoDBSink.configure] --------------------- Configured `enable_distance` cannot be different than `true` or `false`\r\n[NGSICartoDBSink.configure] --------------  OK  - 'enable_distance=falso' was detected\r\n```\r\n* (unofficial) e2e tests passed in cartodb.org\r\n* Assignee @pcoello25 but LGTM from @gtorodelvalle is also required","created_at":"2016-05-19T10:38:24Z","updated_at":"2016-05-19T11:59:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"852b3e632cccbba36a9615dac47a0fd74c99dfaf","assignee":{"login":"pcoello25","id":15360342,"avatar_url":"https://avatars.githubusercontent.com/u/15360342?v=3","gravatar_id":"","url":"https://api.github.com/users/pcoello25","html_url":"https://github.com/pcoello25","followers_url":"https://api.github.com/users/pcoello25/followers","following_url":"https://api.github.com/users/pcoello25/following{/other_user}","gists_url":"https://api.github.com/users/pcoello25/gists{/gist_id}","starred_url":"https://api.github.com/users/pcoello25/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pcoello25/subscriptions","organizations_url":"https://api.github.com/users/pcoello25/orgs","repos_url":"https://api.github.com/users/pcoello25/repos","events_url":"https://api.github.com/users/pcoello25/events{/privacy}","received_events_url":"https://api.github.com/users/pcoello25/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/pulls/1031/commits","review_comments_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/pulls/1031/comments","review_comment_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/pulls/comments{/number}","comments_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/issues/1031/comments","statuses_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/statuses/7e16f2ded5694f3629e1416296981a6dcd4ec061","head":{"label":"frbattid:feature/927_add_enable_distance_analysis_ngsicartodbsink","ref":"feature/927_add_enable_distance_analysis_ngsicartodbsink","sha":"7e16f2ded5694f3629e1416296981a6dcd4ec061","user":{"login":"frbattid","id":3865056,"avatar_url":"https://avatars.githubusercontent.com/u/3865056?v=3","gravatar_id":"","url":"https://api.github.com/users/frbattid","html_url":"https://github.com/frbattid","followers_url":"https://api.github.com/users/frbattid/followers","following_url":"https://api.github.com/users/frbattid/following{/other_user}","gists_url":"https://api.github.com/users/frbattid/gists{/gist_id}","starred_url":"https://api.github.com/users/frbattid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frbattid/subscriptions","organizations_url":"https://api.github.com/users/frbattid/orgs","repos_url":"https://api.github.com/users/frbattid/repos","events_url":"https://api.github.com/users/frbattid/events{/privacy}","received_events_url":"https://api.github.com/users/frbattid/received_events","type":"User","site_admin":false},"repo":{"id":57299629,"name":"fiware-cygnus","full_name":"frbattid/fiware-cygnus","owner":{"login":"frbattid","id":3865056,"avatar_url":"https://avatars.githubusercontent.com/u/3865056?v=3","gravatar_id":"","url":"https://api.github.com/users/frbattid","html_url":"https://github.com/frbattid","followers_url":"https://api.github.com/users/frbattid/followers","following_url":"https://api.github.com/users/frbattid/following{/other_user}","gists_url":"https://api.github.com/users/frbattid/gists{/gist_id}","starred_url":"https://api.github.com/users/frbattid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frbattid/subscriptions","organizations_url":"https://api.github.com/users/frbattid/orgs","repos_url":"https://api.github.com/users/frbattid/repos","events_url":"https://api.github.com/users/frbattid/events{/privacy}","received_events_url":"https://api.github.com/users/frbattid/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/frbattid/fiware-cygnus","description":"Being part of FIWARE, Cygnus is a connector in charge of persisting Orion context data in certain configured third-party storages, creating a historical view of such data.","fork":true,"url":"https://api.github.com/repos/frbattid/fiware-cygnus","forks_url":"https://api.github.com/repos/frbattid/fiware-cygnus/forks","keys_url":"https://api.github.com/repos/frbattid/fiware-cygnus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/frbattid/fiware-cygnus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/frbattid/fiware-cygnus/teams","hooks_url":"https://api.github.com/repos/frbattid/fiware-cygnus/hooks","issue_events_url":"https://api.github.com/repos/frbattid/fiware-cygnus/issues/events{/number}","events_url":"https://api.github.com/repos/frbattid/fiware-cygnus/events","assignees_url":"https://api.github.com/repos/frbattid/fiware-cygnus/assignees{/user}","branches_url":"https://api.github.com/repos/frbattid/fiware-cygnus/branches{/branch}","tags_url":"https://api.github.com/repos/frbattid/fiware-cygnus/tags","blobs_url":"https://api.github.com/repos/frbattid/fiware-cygnus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/frbattid/fiware-cygnus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/frbattid/fiware-cygnus/git/refs{/sha}","trees_url":"https://api.github.com/repos/frbattid/fiware-cygnus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/frbattid/fiware-cygnus/statuses/{sha}","languages_url":"https://api.github.com/repos/frbattid/fiware-cygnus/languages","stargazers_url":"https://api.github.com/repos/frbattid/fiware-cygnus/stargazers","contributors_url":"https://api.github.com/repos/frbattid/fiware-cygnus/contributors","subscribers_url":"https://api.github.com/repos/frbattid/fiware-cygnus/subscribers","subscription_url":"https://api.github.com/repos/frbattid/fiware-cygnus/subscription","commits_url":"https://api.github.com/repos/frbattid/fiware-cygnus/commits{/sha}","git_commits_url":"https://api.github.com/repos/frbattid/fiware-cygnus/git/commits{/sha}","comments_url":"https://api.github.com/repos/frbattid/fiware-cygnus/comments{/number}","issue_comment_url":"https://api.github.com/repos/frbattid/fiware-cygnus/issues/comments{/number}","contents_url":"https://api.github.com/repos/frbattid/fiware-cygnus/contents/{+path}","compare_url":"https://api.github.com/repos/frbattid/fiware-cygnus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/frbattid/fiware-cygnus/merges","archive_url":"https://api.github.com/repos/frbattid/fiware-cygnus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/frbattid/fiware-cygnus/downloads","issues_url":"https://api.github.com/repos/frbattid/fiware-cygnus/issues{/number}","pulls_url":"https://api.github.com/repos/frbattid/fiware-cygnus/pulls{/number}","milestones_url":"https://api.github.com/repos/frbattid/fiware-cygnus/milestones{/number}","notifications_url":"https://api.github.com/repos/frbattid/fiware-cygnus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/frbattid/fiware-cygnus/labels{/name}","releases_url":"https://api.github.com/repos/frbattid/fiware-cygnus/releases{/id}","deployments_url":"https://api.github.com/repos/frbattid/fiware-cygnus/deployments","created_at":"2016-04-28T12:18:16Z","updated_at":"2016-04-28T12:18:18Z","pushed_at":"2016-05-19T11:10:38Z","git_url":"git://github.com/frbattid/fiware-cygnus.git","ssh_url":"git@github.com:frbattid/fiware-cygnus.git","clone_url":"https://github.com/frbattid/fiware-cygnus.git","svn_url":"https://github.com/frbattid/fiware-cygnus","homepage":"","size":7900,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"telefonicaid:develop","ref":"develop","sha":"52e77e0a52619aa18b245a2e487ef7c22dd63adc","user":{"login":"telefonicaid","id":968363,"avatar_url":"https://avatars.githubusercontent.com/u/968363?v=3","gravatar_id":"","url":"https://api.github.com/users/telefonicaid","html_url":"https://github.com/telefonicaid","followers_url":"https://api.github.com/users/telefonicaid/followers","following_url":"https://api.github.com/users/telefonicaid/following{/other_user}","gists_url":"https://api.github.com/users/telefonicaid/gists{/gist_id}","starred_url":"https://api.github.com/users/telefonicaid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/telefonicaid/subscriptions","organizations_url":"https://api.github.com/users/telefonicaid/orgs","repos_url":"https://api.github.com/users/telefonicaid/repos","events_url":"https://api.github.com/users/telefonicaid/events{/privacy}","received_events_url":"https://api.github.com/users/telefonicaid/received_events","type":"Organization","site_admin":false},"repo":{"id":16607947,"name":"fiware-cygnus","full_name":"telefonicaid/fiware-cygnus","owner":{"login":"telefonicaid","id":968363,"avatar_url":"https://avatars.githubusercontent.com/u/968363?v=3","gravatar_id":"","url":"https://api.github.com/users/telefonicaid","html_url":"https://github.com/telefonicaid","followers_url":"https://api.github.com/users/telefonicaid/followers","following_url":"https://api.github.com/users/telefonicaid/following{/other_user}","gists_url":"https://api.github.com/users/telefonicaid/gists{/gist_id}","starred_url":"https://api.github.com/users/telefonicaid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/telefonicaid/subscriptions","organizations_url":"https://api.github.com/users/telefonicaid/orgs","repos_url":"https://api.github.com/users/telefonicaid/repos","events_url":"https://api.github.com/users/telefonicaid/events{/privacy}","received_events_url":"https://api.github.com/users/telefonicaid/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/telefonicaid/fiware-cygnus","description":"Being part of FIWARE, Cygnus is a connector in charge of persisting Orion context data in certain configured third-party storages, creating a historical view of such data.","fork":false,"url":"https://api.github.com/repos/telefonicaid/fiware-cygnus","forks_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/forks","keys_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/teams","hooks_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/hooks","issue_events_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/issues/events{/number}","events_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/events","assignees_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/assignees{/user}","branches_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/branches{/branch}","tags_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/tags","blobs_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/git/refs{/sha}","trees_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/statuses/{sha}","languages_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/languages","stargazers_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/stargazers","contributors_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/contributors","subscribers_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/subscribers","subscription_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/subscription","commits_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/commits{/sha}","git_commits_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/git/commits{/sha}","comments_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/comments{/number}","issue_comment_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/issues/comments{/number}","contents_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/contents/{+path}","compare_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/merges","archive_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/downloads","issues_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/issues{/number}","pulls_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/pulls{/number}","milestones_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/milestones{/number}","notifications_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/labels{/name}","releases_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/releases{/id}","deployments_url":"https://api.github.com/repos/telefonicaid/fiware-cygnus/deployments","created_at":"2014-02-07T07:57:41Z","updated_at":"2016-04-19T06:30:21Z","pushed_at":"2016-05-19T11:10:38Z","git_url":"git://github.com/telefonicaid/fiware-cygnus.git","ssh_url":"git@github.com:telefonicaid/fiware-cygnus.git","clone_url":"https://github.com/telefonicaid/fiware-cygnus.git","svn_url":"https://github.com/telefonicaid/fiware-cygnus","homepage":"","size":94663,"stargazers_count":23,"watchers_count":23,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":28,"mirror_url":null,"open_issues_count":75,"forks":28,"open_issues":75,"watchers":23,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/telefonicaid/fiware-cygnus/pulls/1031"},"html":{"href":"https://github.com/telefonicaid/fiware-cygnus/pull/1031"},"issue":{"href":"https://api.github.com/repos/telefonicaid/fiware-cygnus/issues/1031"},"comments":{"href":"https://api.github.com/repos/telefonicaid/fiware-cygnus/issues/1031/comments"},"review_comments":{"href":"https://api.github.com/repos/telefonicaid/fiware-cygnus/pulls/1031/comments"},"review_comment":{"href":"https://api.github.com/repos/telefonicaid/fiware-cygnus/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/telefonicaid/fiware-cygnus/pulls/1031/commits"},"statuses":{"href":"https://api.github.com/repos/telefonicaid/fiware-cygnus/statuses/7e16f2ded5694f3629e1416296981a6dcd4ec061"}}}}