Commit cbec12bb authored by Dave McCormick's avatar Dave McCormick
Browse files

updates to get dynamic loading working

parent b773f0a2
package actors;
import com.fasterxml.jackson.databind.node.ObjectNode;
import play.libs.Json;
import twitter4j.*;
import akka.actor.ActorRef;
import akka.actor.Props;
import akka.actor.UntypedActor;
import twitter4j.Trend;
import twitter4j.conf.ConfigurationBuilder;
import java.util.HashMap;
import java.util.Map;
import model.GibberishHub;
/*
......@@ -39,7 +39,6 @@ public class FizzBuzzActor extends UntypedActor {
*/
public static Props props = Props.create(FizzBuzzActor.class);
Twitter twitter;
TwitterStream twitterStream;
StatusListener listener;
......@@ -50,8 +49,6 @@ public class FizzBuzzActor extends UntypedActor {
.setOAuthConsumerSecret("3cNybn6qSJPpw2AnizXGitOclFV3ZolFXidWBWLpOnafRw7uL8")
.setOAuthAccessToken("315679785-SVT1kCKoow1eCTgTWLzPrh6BPaKA5OiPOfIlmAxt")
.setOAuthAccessTokenSecret("TYTg0PLDbU7isjXxm3uPIeu2xdYg3rXGaEGUdJuBkvCg2");
//TwitterFactory tf = new TwitterFactory(cb.build());
//twitter = tf.getInstance();
twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
......@@ -62,7 +59,12 @@ public class FizzBuzzActor extends UntypedActor {
if (loc == null){
return;
}
reply("@" + status.getUser().getScreenName() + "said " + status.getText() + " - " + loc);
//System.out.println("Got a tweet");
ObjectNode n = Json.newObject();
//n.put("msg", "@" + status.getUser().getScreenName() + "said " + status.getText() + " - " + loc);
n.put("lat", loc.getLatitude());
n.put("lng", loc.getLongitude());
reply(n);
}
@Override
......@@ -95,64 +97,25 @@ public class FizzBuzzActor extends UntypedActor {
@Override
public void onReceive(Object message) throws TwitterException {
System.out.println("Received a call");
if (message.equals("Marshall")) {
/*
* We're given the marshall's ActorRef by a message saying "Marshall". The Marshall will appear
* to be the sender (even though it's actually been sent by Setup)
*/
marshallActor = getSender();
} else if (message.equals("GetTrends")) {
//getTrendByLocation();
// Put this Actor to sleep for 250ms before it checks its next message
try {
Thread.sleep(300000);
} catch (InterruptedException ex) {
// do nothing
}
marshallActor.tell("ActorReadyAgain",getSelf());
} else if (message.equals("Heatmap")){
reply("Got initial message");
System.out.println("Got heatmap call...");
getStreamForHeatmap();
}
}
// int secondsUntilRequestAllowed(){
//
// try {
// RateLimitStatus status = twitter.getRateLimitStatus().get("/trends/place");
//
// return status.getSecondsUntilReset();
// } catch (TwitterException e) {
// e.printStackTrace();
// }
//
// // Twitter queries get reset after 15m, if we cant figure out how long left, default to that to be safe.
// return 900;
// }
//
// void getTrendByLocation(){
// Map<String, Boolean> seenLocations = new HashMap<>();
// ResponseList<Location> locations;
// try {
//
// Trends trends = twitter.getPlaceTrends(1);
// for (int i = 0; i < trends.getTrends().length; i++) {
// reply("Trend: " + trends.getTrends()[i].getName());
// }
//
// } catch (TwitterException e) {
// e.printStackTrace();
// }
//
// }
void reply(String trendName) {
marshallActor.tell(trendName, getSelf());
void reply(ObjectNode tweetDetails) {
GibberishHub.getInstance().send(tweetDetails);
//marshallActor.tell(trendName, getSelf());
// Put this Actor to sleep for 250ms before it checks its next message
try {
......@@ -163,10 +126,9 @@ public class FizzBuzzActor extends UntypedActor {
}
void getStreamForHeatmap(){
reply("Starting streaming...");
FilterQuery fq = new FilterQuery();
double[][] boundingBox= {{112.467,-55.050}, {168.000,-9.133}}; /// whole world;
double[][] boundingBox= {{-180, -90}, {180, 90}}; /// whole world;
FilterQuery filtro = new FilterQuery();
filtro.locations(boundingBox);
twitterStream.addListener(listener);
......
......@@ -24,10 +24,13 @@ public class Setup {
public Setup(ActorSystem system) {
marshallActor = system.actorOf(MarshallActor.props);
//ActorRef fb1 = system.actorOf(FizzBuzzActor.props, "Player1");
//fb1.tell("Marshall", marshallActor);
//fb1.tell("Heatmap", marshallActor);
System.out.println("Booting up..");
ActorRef fb1 = system.actorOf(FizzBuzzActor.props, "Player1");
System.out.println("Built actor Player1");
fb1.tell("Marshall", marshallActor);
System.out.println("Told actor about marshall");
fb1.tell("Heatmap", marshallActor);
System.out.println("Told actor about heatmap");
}
......
......@@ -37,6 +37,7 @@ public class Application extends Controller {
* thenApply is a method on CompletionStage that means "when you get the result, do this with it, and return a new CompletionStage"
*/
return FutureConverters.toJava(ask(actorSetup.marshallActor, "Report!", 1000))
.thenApply(response -> {
String responseString = response.toString();
......
......@@ -12,46 +12,49 @@
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.14/angular.min.js"></script>
<script src="//rawgit.com/angular-ui/angular-google-maps/2.1.5/dist/angular-google-maps.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.min.js"></script>
<script src="/assets/javascript/cbuffer.js"></script>
<script>
angular.module("myApp", ['uiGmapgoogle-maps'])
.controller("Example", function($scope, $interval) {
$scope.tweetRingBuffer = CBuffer(1000);
function MockHeatLayer(heatLayer) {
// Adding 500 Data Points
var map, pointarray, heatmap;
var taxiData = [
new google.maps.LatLng(37.782551, -122.445368),
new google.maps.LatLng(37.782745, -122.444586),
new google.maps.LatLng(37.782842, -122.443688),
new google.maps.LatLng(37.782919, -122.442815),
new google.maps.LatLng(37.782992, -122.442112),
new google.maps.LatLng(37.783100, -122.441461),
new google.maps.LatLng(37.783206, -122.440829),
new google.maps.LatLng(37.783273, -122.440324),
new google.maps.LatLng(37.783316, -122.440023),
new google.maps.LatLng(37.783357, -122.439794),
new google.maps.LatLng(37.783371, -122.439687)
];
var pointArray = new google.maps.MVCArray(taxiData);
heatLayer.setData(pointArray);
$scope.heatLayer = heatLayer;
$scope.pointArray = new google.maps.MVCArray($scope.tweetRingBuffer.toArray());
$scope.heatLayer.setData($scope.pointArray);
};
$scope.map = {
center: {
latitude: 37.782551,
longitude: -122.445368
},
zoom: 12,
heatLayerCallback: function (layer) {
//set the heat layers backend data
var mockHeatLayer = new MockHeatLayer(layer);
},
showHeat: true
};
$scope.map = {
center: {
latitude: 37.782551,
longitude: -122.445368
},
zoom: 12,
heatLayerCallback: function (layer) {
//set the heat layers backend data
var mockHeatLayer = new MockHeatLayer(layer);
},
showHeat: true
};
var ws = new WebSocket("ws://127.0.0.1:9000/websocket?topic=Algernons");
// binding model for the UI
$scope.messages = [];
// what to do when we receive message from the webserver
ws.onmessage = function(msg) {
var obj = JSON.parse(msg.data);
$scope.$digest();
$scope.tweetRingBuffer.push(new google.maps.LatLng(obj.lat, obj.lng));
$scope.pointArray = new google.maps.MVCArray($scope.tweetRingBuffer.toArray());
$scope.heatLayer.setData($scope.pointArray);
};
});
</script>
......@@ -59,13 +62,22 @@ $scope.map = {
</head>
<body>
<style>
.angular-google-map-container { height: 400px; }
.angular-google-map-container { height: 800px; }
</style>
<div ng-app="myApp" ng-controller="Example">
<ui-gmap-google-map center='map.center' zoom='map.zoom'>
<ui-gmap-layer namespace="visualization" type="HeatmapLayer" show="map.showHeat" onCreated="map.heatLayerCallback"></ui-gmap-layer>
</ui-gmap-google-map>
<!--<div>-->
<!--<ul>-->
<!--<li ng-repeat="msg in messages track by $index">-->
<!--{{msg}}-->
<!--</li>-->
<!--</ul>-->
<!--</div>-->
</div>
</body>
</html>
......@@ -4,6 +4,9 @@
GET / controllers.Application.index()
GET /ws controllers.Application.whatDidGitLabSay()
GET /websocket controllers.JsonExample.socket(topic:String)
GET /gibberish controllers.JsonExample.getGibberish(n:Int)
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment