Skip to content

Commit

Permalink
Added deviation and interpolation to chain.metric. Fixed map saving
Browse files Browse the repository at this point in the history
  • Loading branch information
eflynch committed Sep 2, 2015
1 parent 5cda5ca commit 335caa4
Show file tree
Hide file tree
Showing 6 changed files with 1,481 additions and 132 deletions.
1 change: 1 addition & 0 deletions chain.map/chain.map.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ int C74_EXPORT main(void)
CLASS_ATTR_ACCESSORS(c, "ang_ele", NULL, chain_map_set_ang_ele);

CLASS_ATTR_SYM(c, "name", ATTR_SET_OPAQUE_USER, t_chain_map, s_worker.s_site_name);
CLASS_ATTR_SAVE(c, "name", ATTR_SET_OPAQUE_USER);

CLASS_ATTR_CHAR(c, "trackmouse", 0, t_chain_map, s_trackmouse);
CLASS_ATTR_STYLE_LABEL(c, "trackmouse", 0, "onoff", "Track Mouse");
Expand Down
56 changes: 52 additions & 4 deletions chain.metric/chain.metric.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void chain_metric_send_median(t_chain_metric *x);
static t_class *s_chain_metric_class = NULL;

t_symbol *ps_url, *ps_db;
t_symbol *ps_mean, *ps_std, *ps_deviation, *ps_interpolation, *ps_max, *ps_min, *ps_median;
t_symbol *ps_mean, *ps_std, *ps_deviation, *ps_interpolation, *ps_max, *ps_min, *ps_median, *ps_proximal;
t_symbol *ps_bilinear;

int C74_EXPORT main(void)
Expand Down Expand Up @@ -73,6 +73,7 @@ int C74_EXPORT main(void)
ps_median = gensym("median");

ps_bilinear = gensym("bilinear");
ps_proximal = gensym("proximal");

s_chain_metric_class = c;

Expand All @@ -91,7 +92,7 @@ void *chain_metric_new(t_symbol *s, long argc, t_atom *argv)
x->s_pos_z = 0.0;

x->s_measure = ps_mean;
x->s_interp = ps_bilinear;
x->s_interp = ps_proximal;

attr_args_process(x, argc, argv);

Expand Down Expand Up @@ -190,12 +191,59 @@ void chain_metric_send_std(t_chain_metric *x)
free(argv);
}


void chain_metric_send_deviation(t_chain_metric *x){
chain_error("Unimplemented");
if (x->s_interp == ps_bilinear){
chain_error("Unimplemented");
return;
} else if (x->s_interp == ps_proximal){
t_db_result *db_result = NULL;

// This is basically a hack ... TODO: make this not a hack
double radius = x->s_radius;
if (radius <= 0.0){
radius = 1000000.0;
}

query_near_data_by_metric_name(x->s_worker.s_db, x->s_pos_x,
x->s_pos_z, radius, x->s_metric_name->s_name, &db_result);
double *argv;
long argc;
chain_metric_unpack_values(db_result, &argv, &argc);
if (argc < 1){
chain_error("No data returned for interpolation");
return;
}
outlet_float(x->s_outlet, (*argv - chain_mean(argv,argc)) / chain_std(argv,argc));
free(argv);
}
}

void chain_metric_send_interpolation(t_chain_metric *x){
chain_error("Unimplemented");
if (x->s_interp == ps_bilinear){
chain_error("Unimplemented");
return;
} else if (x->s_interp == ps_proximal){
t_db_result *db_result = NULL;

// This is basically a hack ... TODO: make this not a hack
double radius = x->s_radius;
if (radius <= 0.0){
radius = 1000000.0;
}

query_near_data_by_metric_name(x->s_worker.s_db, x->s_pos_x,
x->s_pos_z, radius, x->s_metric_name->s_name, &db_result);
double *argv;
long argc;
chain_metric_unpack_values(db_result, &argv, &argc);
if (argc < 1){
chain_error("No data returned for interpolation");
return;
}
outlet_float(x->s_outlet, *argv);
free(argv);
}
}

void chain_metric_send_max(t_chain_metric *x){
Expand Down
2 changes: 1 addition & 1 deletion common/queries.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static const char *get_near_data_by_metric_name = \
"SELECT sensors.value, devices.x, devices.z, "
"(((devices.x - %lf) * (devices.x - %lf)) + ((devices.z - %lf) * (devices.z - %lf))) AS distance "
"FROM sensors, devices, metrics WHERE "
"distance <= %lf * %lf AND"
"distance <= %lf * %lf AND "
"sensors.device_id=devices.device_id AND "
"sensors.metric_id=metrics.metric_id AND "
"metrics.name=(\"%s\") "
Expand Down
63 changes: 33 additions & 30 deletions package/maxchain/help/chain.map.maxhelp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"modernui" : 1
}
,
"rect" : [ 61.0, 145.0, 769.0, 800.0 ],
"rect" : [ 91.0, 86.0, 981.0, 800.0 ],
"bgcolor" : [ 1.0, 1.0, 1.0, 1.0 ],
"editing_bgcolor" : [ 1.0, 1.0, 1.0, 1.0 ],
"bglocked" : 0,
Expand Down Expand Up @@ -39,6 +39,19 @@
"style" : "maxchain",
"subpatcher_template" : "",
"boxes" : [ {
"box" : {
"id" : "obj-1",
"maxclass" : "chain.map",
"name" : "maphelp",
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 314.0, 299.0, 370.0, 177.0 ],
"trackmouse" : 0
}

}
, {
"box" : {
"format" : 6,
"id" : "obj-14",
Expand Down Expand Up @@ -144,18 +157,6 @@
"text" : "chain.device maphelp"
}

}
, {
"box" : {
"id" : "obj-1",
"maxclass" : "chain.map",
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 314.0, 273.0, 352.0, 228.0 ],
"trackmouse" : 0
}

}
, {
"box" : {
Expand Down Expand Up @@ -338,6 +339,7 @@
"destination" : [ "obj-2", 0 ],
"disabled" : 0,
"hidden" : 0,
"midpoints" : [ 323.5, 506.0, 323.5, 506.0 ],
"source" : [ "obj-1", 0 ]
}

Expand All @@ -347,7 +349,7 @@
"destination" : [ "obj-9", 0 ],
"disabled" : 0,
"hidden" : 0,
"midpoints" : [ 323.5, 525.0, 495.5, 525.0 ],
"midpoints" : [ 323.5, 523.0, 495.5, 523.0 ],
"source" : [ "obj-1", 0 ]
}

Expand Down Expand Up @@ -385,6 +387,7 @@
"destination" : [ "obj-1", 0 ],
"disabled" : 0,
"hidden" : 0,
"midpoints" : [ 323.5, 267.0, 323.5, 267.0 ],
"source" : [ "obj-3", 0 ]
}

Expand Down Expand Up @@ -412,7 +415,7 @@
"destination" : [ "obj-1", 0 ],
"disabled" : 0,
"hidden" : 0,
"midpoints" : [ 451.0, 267.5, 323.5, 267.5 ],
"midpoints" : [ 451.0, 267.0, 323.5, 267.0 ],
"source" : [ "obj-5", 0 ]
}

Expand All @@ -428,30 +431,36 @@
}
],
"parameters" : {
"obj-7" : [ "number", "number", 0 ],
"obj-11" : [ "number[1]", "number[1]", 0 ]
"obj-11" : [ "number[1]", "number[1]", 0 ],
"obj-7" : [ "number", "number", 0 ]
}
,
"dependency_cache" : [ {
"name" : "chain.site.mxo",
"type" : "iLaX"
}
, {
"name" : "chain.map.mxo",
"name" : "chain.device.mxo",
"type" : "iLaX"
}
, {
"name" : "chain.device.mxo",
"name" : "chain.map.mxo",
"type" : "iLaX"
}
],
"embedsnapshot" : 0,
"styles" : [ {
"name" : "maxchain",
"default" : {
"accentcolor" : [ 0.0, 0.0, 0.0, 1.0 ],
"elementcolor" : [ 0.282353, 0.309804, 0.266667, 1.0 ],
"bgcolor" : [ 0.095481, 0.100396, 0.100293, 1.0 ],
"fontname" : [ "Courier" ],
"color" : [ 0.960784, 0.827451, 0.156863, 1.0 ],
"textjustification" : [ 0 ],
"textcolor_inverse" : [ 1.0, 1.0, 1.0, 1.0 ],
"patchlinecolor" : [ 0.639216, 0.458824, 0.070588, 0.9 ],
"fontface" : [ 0 ],
"bgfillcolor" : {
"type" : "color",
"color" : [ 0.639216, 0.458824, 0.070588, 1.0 ],
Expand All @@ -461,13 +470,7 @@
"proportion" : 0.39,
"autogradient" : 0
}
,
"fontface" : [ 0 ],
"textjustification" : [ 0 ],
"bgcolor" : [ 0.095481, 0.100396, 0.100293, 1.0 ],
"accentcolor" : [ 0.0, 0.0, 0.0, 1.0 ],
"elementcolor" : [ 0.282353, 0.309804, 0.266667, 1.0 ],
"color" : [ 0.960784, 0.827451, 0.156863, 1.0 ]

}
,
"parentstyle" : "",
Expand All @@ -485,8 +488,8 @@
, {
"name" : "maxchain-subtitle",
"default" : {
"fontsize" : [ 20.0 ],
"textcolor" : [ 0.870588, 0.415686, 0.062745, 1.0 ]
"textcolor" : [ 0.870588, 0.415686, 0.062745, 1.0 ],
"fontsize" : [ 20.0 ]
}
,
"parentstyle" : "",
Expand All @@ -496,9 +499,9 @@
"name" : "maxchain-title",
"default" : {
"fontname" : [ "Courier Bold" ],
"textcolor" : [ 0.960784, 0.827451, 0.156863, 1.0 ],
"clearcolor" : [ 0.317647, 0.654902, 0.976471, 0.0 ],
"fontsize" : [ 48.0 ],
"textcolor" : [ 0.960784, 0.827451, 0.156863, 1.0 ]
"fontsize" : [ 48.0 ]
}
,
"parentstyle" : "",
Expand Down
Loading

0 comments on commit 335caa4

Please sign in to comment.