Skip to content

Commit

Permalink
Update weather_predictor demo to the latest graalvm-0.25-dev & CTRL+C…
Browse files Browse the repository at this point in the history
… support
  • Loading branch information
steve-s committed Jul 11, 2017
1 parent 2021f80 commit 9b1c6cd
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion ci.hocon
Expand Up @@ -2,7 +2,7 @@ graal-vm-release: {
downloads: {
GRAALVM_DIR: {
name: graalvm-release,
version: "0.25",
version: "0.25-dev",
platformspecific: true
}
}
Expand Down
4 changes: 4 additions & 0 deletions weather_predictor/demo.sh
@@ -0,0 +1,4 @@
!/bin/bash
export NODE_STACK_SIZE=2000000
$GRAALVM_DIR/bin/node --jvm --jvm.Dtruffle.js.NashornJavaInterop=true --jvm.classpath=./bin --jvm.Dtruffleruby.load_paths=openweather/lib,. --inspect --agent weatherServer.js

2 changes: 1 addition & 1 deletion weather_predictor/run.sh
@@ -1,3 +1,3 @@
#!/bin/bash
export NODE_STACK_SIZE=2000000
$GRAALVM_DIR/bin/node -cp ./bin -J-Dtruffleruby.load_paths=openweather/lib,. weatherServer.js
$GRAALVM_DIR/bin/node --jvm --jvm.Dtruffle.js.NashornJavaInterop=true --jvm.classpath=./bin --jvm.Dtruffleruby.load_paths=openweather/lib,. weatherServer.js
16 changes: 10 additions & 6 deletions weather_predictor/weatherModel.r
Expand Up @@ -4,13 +4,17 @@ tempInCity <- import('tempInCity')
# The lattice library is needed for the visualization
library(lattice)

createModel <- function(size, length, getName, getLat, getLong, getTemp) {
idx <- sample(1:length, size)
createModel <- function(size, cityService) {
# In the final version we should select only some cities:
# idx <- sample(1:length, size)
# cities <- cities[idx]
# ...but now even using all the cities does not work:
cities <- cityService$getAll()
data <- as.data.frame(list(
name = sapply(idx, function(i) getName(i)),
lat = sapply(idx, function(i) getLat(i)),
long = sapply(idx, function(i) getLong(i)),
temp = sapply(idx, function(i) getTemp(i))))
name = sapply(cities, function(x) x$getName()),
lat = sapply(cities, function(x) x$getLat()),
long = sapply(cities, function(x) x$getLong()),
temp = sapply(cities, function(x) x$getTemp())))
list(data=data, model=lm(temp~lat, data=data))
}

Expand Down
7 changes: 1 addition & 6 deletions weather_predictor/weatherServer.js
Expand Up @@ -33,12 +33,7 @@ var updateTemperatures = function() {

// Create the linear regression model
var updateModel = function(size) {
var cities = cityService.getAll();
let getName = function(i) { return cities[i-1].getName(); }
let getLatitude = function(i) { return cities[i-1].getLatitude(); }
let getLongitude = function(i) { return cities[i-1].getLongitude(); }
let getTemperature = function(i) { return cities[i-1].getTemperature(); }
return createModel(size, cities.length, getName, getLatitude, getLongitude, getTemperature);
return createModel(size, cityService);
}

var model = updateModel(5);
Expand Down

0 comments on commit 9b1c6cd

Please sign in to comment.