Skip to content

Commit

Permalink
Update GAMA BAckEnd Examples to send bith Grid and Agent data
Browse files Browse the repository at this point in the history
  • Loading branch information
agrignard committed Apr 10, 2019
1 parent b58e2de commit 1798302
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 16 deletions.
7 changes: 7 additions & 0 deletions examples/GAMA/cityIO_Gama/.project
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
<nature>msi.gama.application.gamaNature</nature>
</natures>
<linkedResources>
<link>
<name>external/grasbrook</name>
<type>1</type>
<locationURI>CACHE_LOC/cityio.media.mit.edu+_++_+api+_+table+_+grasbrook</locationURI>
</link>
</linkedResources>
</projectDescription>
2 changes: 1 addition & 1 deletion examples/GAMA/cityIO_Gama/headless/cityIO_Gama.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Experiment_plan>
<Simulation id="1" sourcePath="./../models/cityIO.gaml" finalStep="1000" experiment="cityIO">
<Simulation id="1" sourcePath="./../models/cityIO.gaml" finalStep="1000" experiment="Display">
<Parameters>
</Parameters>
<Outputs>
Expand Down
1 change: 1 addition & 0 deletions examples/GAMA/cityIO_Gama/includes/cityIO_Gama_Agent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"grid":[[1,0,270],[0,7,270],[0,8,90],[4,7,0],[2,6,270],[1,2,0],[4,4,180],[6,3,270],[6,2,90],[0,2,90],[3,5,180],[6,4,90],[1,7,90],[5,7,0],[3,5,0],[5,6,180],[1,7,0],[5,0,180],[6,2,270],[1,7,90],[4,5,180],[2,8,90],[3,6,90],[5,7,180],[1,4,180],[1,3,0],[5,9,0],[5,7,180],[4,0,180],[0,5,90],[0,8,180],[2,9,180],[1,7,90],[3,4,270],[4,0,90],[1,5,0],[0,1,270],[4,6,0],[3,3,90],[2,1,270],[0,6,180],[0,2,90],[4,3,270],[6,4,180],[0,7,270],[2,2,0],[6,1,0],[6,0,270],[1,1,180],[4,6,270],[2,4,90],[1,1,0],[6,9,270],[4,9,90],[4,5,180],[6,0,270],[4,6,270],[1,2,270],[0,7,270],[3,4,180],[6,3,0],[1,3,180],[2,5,180],[0,6,270],[3,9,180],[0,3,90],[5,5,0],[3,9,0],[1,8,90],[6,6,90],[6,6,270],[5,3,90],[5,9,270],[6,5,270],[1,3,90],[4,2,270],[6,2,0],[6,1,180],[5,4,90],[5,9,180],[1,1,270],[4,9,90],[0,0,270],[4,9,90],[1,5,270],[1,0,0],[4,7,0],[4,2,0],[2,0,90],[3,2,270],[1,0,270],[4,4,270],[5,1,180],[0,3,180],[4,2,270],[5,3,270],[4,1,180],[2,9,180],[1,4,90],[1,3,0],[1,3,90],[6,4,270],[3,4,0],[4,1,0],[6,4,270],[0,2,0],[4,7,90],[3,4,0],[1,0,180],[4,3,270],[2,5,180],[6,5,0],[6,0,90],[3,5,90],[5,7,0],[4,3,90],[0,2,180],[2,2,180],[3,2,90],[0,9,180],[4,8,270],[1,4,90],[5,2,0],[5,9,90],[4,6,270],[5,5,90],[2,5,90],[3,0,270],[2,7,0],[3,6,180],[5,0,180],[1,5,0],[5,1,180],[6,5,0],[4,0,270],[6,4,270],[6,6,270],[5,7,90],[4,0,0],[3,9,270],[2,0,0],[1,8,90],[4,0,180],[3,1,90],[6,6,90],[6,2,90],[0,1,270],[2,5,270],[2,3,90],[2,7,0],[3,9,270],[4,3,180],[1,0,180],[3,9,0],[0,2,270],[4,9,90],[0,4,90],[2,1,270],[3,0,0],[3,1,180],[2,8,90],[2,1,180],[3,5,0],[4,4,0],[4,2,0],[5,7,0],[6,3,90],[1,9,0],[2,4,90],[6,8,90],[1,8,90],[5,5,90],[6,3,180],[5,3,270],[4,9,180],[1,1,0],[3,6,90],[1,8,270],[4,2,270],[4,2,180],[0,7,180],[0,8,0],[0,5,270],[1,9,270],[4,8,180],[5,8,90],[2,3,90],[3,4,270],[1,6,0],[3,2,90],[3,5,90],[2,4,0],[5,2,90],[1,6,0],[1,2,270],[6,7,90],[5,6,270],[3,7,270],[2,3,0],[4,1,0],[6,7,180],[6,5,0],[5,6,270],[2,7,0],[1,4,90],[3,5,90],[3,4,270],[2,0,180],[5,4,180],[3,5,0],[3,1,270],[6,3,270],[5,1,90],[2,5,0],[6,8,90],[1,0,90],[6,5,270],[2,8,180],[4,8,90],[3,7,270],[4,2,0],[5,8,270],[2,0,180],[2,5,270],[6,6,0],[1,6,270],[4,6,270],[3,9,270],[6,0,270],[4,9,90],[0,2,90],[4,5,0],[4,6,270],[6,9,270],[4,6,270],[5,6,180],[6,0,90],[4,2,0],[1,9,90],[1,2,0],[3,3,270],[3,6,0],[6,5,270],[5,2,90],[5,2,180],[3,2,180],[1,8,180],[3,3,0],[4,1,180],[2,0,180],[4,9,270],[2,2,180],[5,3,270],[4,5,270],[1,9,270],[3,3,90],[5,0,270],[3,7,180],[5,3,180],[5,9,90],[6,6,0],[4,0,0],[0,7,90],[3,5,180],[1,1,90],[5,5,0],[2,1,90],[2,0,180],[2,1,180],[0,9,90],[2,1,90],[5,4,0],[2,1,90],[6,5,270],[1,4,180],[5,2,0],[3,4,90],[4,6,90],[3,7,180],[4,7,270],[5,7,0],[0,8,90],[4,6,270],[1,4,180],[4,8,180],[3,5,90],[5,8,180],[0,2,180],[3,3,180],[2,4,270],[4,8,270],[1,3,90],[3,3,270],[3,8,270],[6,0,90],[2,4,270],[4,3,0],[3,2,90],[1,9,90],[1,1,0],[4,1,0],[3,4,180],[1,0,0],[4,1,180],[2,3,0],[0,2,270],[4,2,180],[0,2,180],[6,6,90],[4,8,270],[6,0,180],[6,0,180],[3,2,270],[4,7,0],[4,6,90],[3,5,90],[5,6,180],[3,0,90],[2,5,90],[5,0,270],[4,8,90],[3,2,270],[0,0,0],[2,6,180],[1,3,0],[0,0,0],[3,2,90],[6,7,90],[0,7,180],[0,1,180],[5,7,0],[0,2,0],[1,3,0],[0,7,0],[0,5,180],[3,1,270],[6,9,0],[4,2,0],[3,8,180],[0,7,180],[3,3,270],[5,7,180],[0,5,270],[6,4,180],[4,1,180],[5,8,90],[2,3,270],[4,0,270],[0,8,270],[5,4,90],[0,1,90],[6,4,90],[3,5,0],[2,4,0],[5,1,180],[4,8,180],[4,3,90],[4,5,0],[5,6,0],[1,7,270],[4,5,180],[1,7,270],[0,4,0],[0,4,270],[3,3,270],[1,9,90],[4,8,180],[3,4,90],[4,6,180],[4,9,0],[1,9,0],[4,4,180],[1,0,180],[6,7,90],[4,6,0],[2,2,0],[5,6,270],[4,4,180],[4,8,90],[6,1,0],[5,8,180],[4,2,270],[0,1,270],[0,4,0],[6,3,0],[4,2,270],[2,1,90],[5,8,0],[0,9,0],[4,6,270],[4,8,270],[6,9,180],[1,8,180],[4,7,0],[0,3,270],[3,3,0],[0,6,180],[6,3,90],[3,2,0],[4,5,90]],"meta":{"apiv":2,"id":"hnkyCam","timestamp":-290419029},"objects":{"points":{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"coordinates":[100.51134639265322,2.7791355017715657E-4,0.0],"type":"Point"},"properties":{"property_1":2},"id":0},{"type":"Feature","geometry":{"coordinates":[100.51157514652954,4.8014752316950977E-4,0.0],"type":"Point"},"properties":{"property_1":2},"id":1},{"type":"Feature","geometry":{"coordinates":[100.5113887559565,9.688871223804664E-5,0.0],"type":"Point"},"properties":{"property_1":2},"id":2},{"type":"Feature","geometry":{"coordinates":[100.5115218987927,6.001914043000524E-4,0.0],"type":"Point"},"properties":{"property_1":2},"id":3},{"type":"Feature","geometry":{"coordinates":[100.51173674255995,8.033106972697403E-4,0.0],"type":"Point"},"properties":{"property_1":2},"id":4},{"type":"Feature","geometry":{"coordinates":[100.51187282369874,3.518491001998085E-4,0.0],"type":"Point"},"properties":{"property_1":2},"id":5},{"type":"Feature","geometry":{"coordinates":[100.5119730780425,1.891047244458317E-4,0.0],"type":"Point"},"properties":{"property_1":2},"id":6},{"type":"Feature","geometry":{"coordinates":[100.51141292318675,8.794659746523952E-4,0.0],"type":"Point"},"properties":{"property_1":2},"id":7},{"type":"Feature","geometry":{"coordinates":[100.51162315143507,4.7290712707538483E-4,0.0],"type":"Point"},"properties":{"property_1":2},"id":8},{"type":"Feature","geometry":{"coordinates":[100.51186226058564,6.902409733729597E-4,0.0],"type":"Point"},"properties":{"property_1":2},"id":9}]}},"header":{"owner":{"name":"Arnaud Grignard","institute":"Gama Platform","title":"Research Assistant"},"mapping":{"type":{"0":"RL","1":"RM","2":"RS","3":"OL","4":"OM","5":"OS","6":"ROAD"}},"name":"virtual_table","block":["type","height","rotation"],"spatial":{"physical_longitude":105.84,"nrows":20,"rotation":0,"latitude":21.02,"physical_latitude":21.02,"ncols":20,"cellsize":10,"longitude":105.84}},"id":"","error":"","timestamp":-290419008}
63 changes: 49 additions & 14 deletions examples/GAMA/cityIO_Gama/models/cityIO.gaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**
* Name: cityIO API for GAMA
* Author: Arnaud Grignard
* Description: Gives the basic read and write feature for cityIO
Expand All @@ -19,9 +19,15 @@ global {
map<int,rgb> buildingColors <-[-2::#red, -1::#orange,0::rgb(189,183,107), 1::rgb(189,183,107), 2::rgb(189,183,107),3::rgb(230,230,230), 4::rgb(230,230,230), 5::rgb(230,230,230),6::rgb(40,40,40),7::#cyan,8::#green,9::#gray];
map<string, unknown> header;
map<string, unknown> spatial;
int refresh <- 100 min: 1 max:1000 parameter: "Refresh Grid rate (cycle):" category: "Grid";
bool pushToCityIO <- false parameter: "Push to cityIO every refresh cycles" category: "Grid";
bool pushToLocalFile <- false parameter: "Push to a local every refresh cycles" category: "Grid";
bool updateGrid <- false parameter: "Update Grid:" category: "Grid";
int gridRrefresh <- 100 min: 1 max:1000 parameter: "Refresh Grid rate (cycle):" category: "Grid";
bool pushGridToCityIO <- false parameter: "Push Grid to cityIO every refresh cycles" category: "Grid";
bool pushGridToLocalFile <- false parameter: "Push Grid to a local every refresh cycles" category: "Grid";

int agentRrefresh <- 100 min: 1 max:1000 parameter: "Refresh Agent rate (cycle):" category: "Agent";
bool pushAgentToCityIO <- false parameter: "Push Agent to cityIO every refresh cycles" category: "Agent";
bool pushAgentToLocalFile <- false parameter: "Push Agent to a local every refresh cycles" category: "Agent";

int nbCols;
int nbRows;
int cellSize;
Expand Down Expand Up @@ -64,30 +70,59 @@ global {
map(outputMatrixData["header"]["spatial"])["physical_longitude"]<-105.84;
map(outputMatrixData["header"]["spatial"])["physical_latitude"]<-21.02;

if(pushToCityIO){
if(pushGridToCityIO){
try{
save(json_file("https://cityio.media.mit.edu/api/table/update/cityIO_Gama", outputMatrixData));
}catch{
write #current_error + " Impossible to write to cityIO - Connection to Internet lost or cityIO is offline";
}
}
if(pushToLocalFile){
if(pushGridToLocalFile){
save(json_file("./../includes/cityIO_Gama.json", outputMatrixData));
}

}

action pushAgent(map<string, unknown> _matrixData){
outputMatrixData <- _matrixData;
map(outputMatrixData["header"]["owner"])["institute"]<-"Gama Platform";
map(outputMatrixData["header"]["owner"])["institute"]<-"Gama Platform";
map(outputMatrixData["header"]["owner"])["name"]<-"Arnaud Grignard";
map(outputMatrixData["header"]["spatial"])["longitude"]<-105.84;
map(outputMatrixData["header"]["spatial"])["latitude"]<-21.02;
map(outputMatrixData["header"]["spatial"])["physical_longitude"]<-105.84;
map(outputMatrixData["header"]["spatial"])["physical_latitude"]<-21.02;
list projected_points <- people collect ([each.location]);
list<map> features<-list_with(length(projected_points), map([]));
loop i from: 0 to:length(projected_points)-1{
list unprojected_point <-point(projected_points[i][0] CRS_transform "EPSG:4326");
map point_geometry<-['coordinates'::unprojected_point, 'type'::'Point'];
map point_properties<-['property_1'::2];
map feature<-["type":: "Feature",'geometry'::point_geometry, 'properties'::point_properties, 'id'::i];
features[i]<-feature;
}
map output_geo<-["type":: "FeatureCollection",'features'::features];
outputMatrixData["objects"]<-["points"::output_geo];
if(pushAgentToCityIO){
try{
save(json_file("https://cityio.media.mit.edu/api/table/update/cityIO_Gama_Agent", outputMatrixData));
}catch{
write #current_error + " Impossible to write to cityIO - Connection to Internet lost or cityIO is offline";
}
}
if(pushAgentToLocalFile){
save(json_file("./../includes/cityIO_Gama_Agent.json", outputMatrixData));
}
}

reflex updateGrid when: ((cycle mod refresh) = 0){
reflex updateGrid when: ((cycle mod gridRrefresh) = 0 and updateGrid){
do initGrid;
if(pushToCityIO){
if(pushGridToCityIO){
do pushGrid(inputMatrixData);
}
}

reflex updateGeoJson when: ((cycle mod refresh) = 0){
save people to:"../results/people.geojson" type:"json" with: [attribute1:"attribute1",attribute2:"attribute2"];
outputSimulationData <- json_file("../results/people.geojson").contents;
save(json_file("https://cityio.media.mit.edu/api/table/update/cityIO_Gama_Simulation", outputSimulationData));
reflex updateAgent when: ((cycle mod agentRrefresh) = 0){
do pushAgent(inputMatrixData);
}
}

Expand All @@ -113,7 +148,7 @@ species people skills:[moving]{
}


experiment Display type: gui {
experiment Display type: gui autorun:true{
action _init_ {
map<string, unknown> data;
try {
Expand Down
1 change: 0 additions & 1 deletion examples/GAMA/cityIO_Gama/results/people.geojson

This file was deleted.

0 comments on commit 1798302

Please sign in to comment.