resolves STREAMS-399

Project: http://git-wip-us.apache.org/repos/asf/incubator-streams/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-streams/commit/a2b29f0a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-streams/tree/a2b29f0a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-streams/diff/a2b29f0a

Branch: refs/heads/master
Commit: a2b29f0a301da0c1933dffb2a70d56b022189408
Parents: d5ef370
Author: Steve Blackmon @steveblackmon <[email protected]>
Authored: Fri Oct 21 12:01:32 2016 -0500
Committer: Steve Blackmon @steveblackmon <[email protected]>
Committed: Sat Oct 22 15:40:25 2016 -0500

----------------------------------------------------------------------
 .../converter/util/TwitterActivityUtil.java     | 27 +++++-
 .../src/main/jsonschema/com/twitter/tweet.json  | 98 ++++++++++++++------
 2 files changed, 93 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/a2b29f0a/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/converter/util/TwitterActivityUtil.java
----------------------------------------------------------------------
diff --git 
a/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/converter/util/TwitterActivityUtil.java
 
b/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/converter/util/TwitterActivityUtil.java
index 0bfa786..ac503cb 100644
--- 
a/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/converter/util/TwitterActivityUtil.java
+++ 
b/streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/converter/util/TwitterActivityUtil.java
@@ -36,6 +36,7 @@ import org.apache.streams.twitter.Url;
 import org.apache.streams.twitter.pojo.Delete;
 import org.apache.streams.twitter.pojo.Entities;
 import org.apache.streams.twitter.pojo.Hashtag;
+import org.apache.streams.twitter.pojo.Place;
 import org.apache.streams.twitter.pojo.Retweet;
 import org.apache.streams.twitter.pojo.Tweet;
 import org.apache.streams.twitter.pojo.User;
@@ -49,6 +50,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import static com.google.common.math.DoubleMath.mean;
 import static org.apache.streams.data.util.ActivityUtil.ensureExtensions;
 
 /**
@@ -273,8 +275,7 @@ public class TwitterActivityUtil {
                         .or(Optional.of(tweet.getId().toString()))
                         .orNull()
         ));
-        location.put("coordinates", tweet.getCoordinates());
-        extensions.put("location", location);
+        location.put("coordinates", boundingBoxCenter(tweet.getPlace()));      
 extensions.put("location", location);
     }
 
     /**
@@ -350,4 +351,26 @@ public class TwitterActivityUtil {
 
         extensions.put("keywords", tweet.getText());
     }
+
+    /**
+     * Compute central coordinates from bounding box
+     * @param place the bounding box to use as the source
+     */
+    public static List<Double> boundingBoxCenter(Place place) {
+        if( place == null ) return new ArrayList<>();
+        if( place.getBoundingBox() == null ) return new ArrayList<>();
+        if( place.getBoundingBox().getCoordinates().size() != 1 ) return new 
ArrayList<>();
+        if( place.getBoundingBox().getCoordinates().get(0).size() != 4 ) 
return new ArrayList<>();
+        List<Double> lats = Lists.newArrayList();
+        List<Double> lons = Lists.newArrayList();
+        for( List<Double> point : 
place.getBoundingBox().getCoordinates().get(0)) {
+            lats.add(point.get(0));
+            lons.add(point.get(1));
+        }
+        List<Double> result = new ArrayList<Double>();
+        result.add(new Double(mean(lats)));
+        result.add(new Double(mean(lons)));
+        return result;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/a2b29f0a/streams-contrib/streams-provider-twitter/src/main/jsonschema/com/twitter/tweet.json
----------------------------------------------------------------------
diff --git 
a/streams-contrib/streams-provider-twitter/src/main/jsonschema/com/twitter/tweet.json
 
b/streams-contrib/streams-provider-twitter/src/main/jsonschema/com/twitter/tweet.json
index bdd2201..e529559 100644
--- 
a/streams-contrib/streams-provider-twitter/src/main/jsonschema/com/twitter/tweet.json
+++ 
b/streams-contrib/streams-provider-twitter/src/main/jsonschema/com/twitter/tweet.json
@@ -2,7 +2,7 @@
     "type": "object",
     "$schema": "http://json-schema.org/draft-03/schema";,
     "$license": [
-      "http://www.apache.org/licenses/LICENSE-2.0";
+        "http://www.apache.org/licenses/LICENSE-2.0";
     ],
     "id": "#",
     "javaType" : "org.apache.streams.twitter.pojo.Tweet",
@@ -30,22 +30,34 @@
                 "type" : "number"
             }]
         },
-        "coordinates": {
+        "place": {
             "type": "object",
-            "javaType" : "org.apache.streams.twitter.pojo.Coordinates",
+            "javaType" : "org.apache.streams.twitter.pojo.Place",
             "javaInterfaces": ["java.io.Serializable"],
-            "items": {
-                "properties": {
-                    "type": {
-                        "type": "string"
-                    },
-                    "coordinates": {
-                        "type": "array",
-                        "items": [
-                            {
-                                "type": "integer"
+            "properties": {
+                "id": {
+                    "type": "string"
+                },
+                "bounding_box": {
+                    "type": "object",
+                    "javaType" : "org.apache.streams.twitter.pojo.BoundingBox",
+                    "javaInterfaces": ["java.io.Serializable"],
+                    "properties": {
+                        "type": {
+                            "type": "string"
+                        },
+                        "coordinates": {
+                            "type": "array",
+                            "items": {
+                                "type": "array",
+                                "items": {
+                                    "type": "array",
+                                    "items": {
+                                        "type": "number"
+                                    }
+                                }
                             }
-                        ]
+                        }
                     }
                 }
             }
@@ -88,20 +100,20 @@
                 "hashtags": {
                     "type": "array",
                     "items": {
-                         "type": "object",
-                         "javaType": "org.apache.streams.twitter.pojo.Hashtag",
-                         "javaInterfaces": ["java.io.Serializable"],
-                         "properties": {
-                             "text": {
-                                 "type": "string"
-                             },
-                             "indices": {
-                                 "type": "array",
-                                 "items": {
-                                     "type": "integer"
-                                 }
-                             }
-                          }
+                        "type": "object",
+                        "javaType": "org.apache.streams.twitter.pojo.Hashtag",
+                        "javaInterfaces": ["java.io.Serializable"],
+                        "properties": {
+                            "text": {
+                                "type": "string"
+                            },
+                            "indices": {
+                                "type": "array",
+                                "items": [{
+                                    "type": "integer"
+                                }]
+                            }
+                        }
                     }
                 },
                 "urls": {
@@ -118,7 +130,7 @@
                                 "type": "array",
                                 "items": [
                                     {
-                                    "type" : "integer"
+                                        "type" : "integer"
                                     }
                                 ]
                             },
@@ -167,6 +179,10 @@
             "ignore_malformed": false,
             "type": "integer"
         },
+        "favorite_count": {
+            "ignore_malformed": false,
+            "type": "integer"
+        },
         "retweet_count": {
             "ignore_malformed": false,
             "type": "integer"
@@ -176,6 +192,28 @@
         },
         "user": {
             "$ref": "User.json"
+        },
+        "is_quote_status": {
+            "type": "boolean"
+        },
+        "quoted_status_id": {
+            "ignore_malformed": false,
+            "type": "integer"
+        },
+        "quoted_status": {
+            "type": "object",
+            "required" : false,
+            "description" : "Describes the tweet being quoted.",
+            "$ref" : "tweet.json"
+        },
+        "retweeted_status_id": {
+            "type": "integer"
+        },
+        "retweeted_status": {
+            "type": "object",
+            "required" : false,
+            "description" : "Describes the tweet being retweeted.",
+            "$ref" : "tweet.json"
         }
     }
-}
\ No newline at end of file
+}

Reply via email to