void test_array() { START_CODE(node) IF IN RAW_PARAM(3) ARRAY_CONSTANT(array_create(3, 1,2,3)); END; THEN CATEGORY_CONSTANT(1) ELSE CATEGORY_CONSTANT(2) END; END_CODE; node_print(node); node = test_serialization(node); environment_t env = test_environment(); constant_t v = node_eval(node, &env); assert(v.c == 2); assert(v.type == CONSTANT_CATEGORY); env.row->inputs[3].category = 3; v = node_eval(node, &env); assert(v.c == 1); assert(v.type == CONSTANT_CATEGORY); row_destroy(env.row); node_destroy(node); }
void menu_allocation(Menu *menu, int size) { if(menu->size == 0) { menu->title = malloc(sizeof(char)*32); menu->row = malloc(sizeof(Row*)*size); for(int i = 0; i < size; i++) { menu->row[i] = row_create(); } } if(menu->size != size && menu->size != 0) { if(menu->size > size) { for(int i = size; i < menu->size; i++) { row_destroy(menu->row[i]); } } menu->row = realloc(menu->row, sizeof(Row*)*size); if(menu->size < size) { for(int i = menu->size; i < size; i++) { menu->row[i] = row_create(); } } } menu->size = size; }
static PyObject* py_model_predict(PyObject* _self, PyObject* args, PyObject* kwargs) { ModelObject* self = (ModelObject*)_self; PyObject*data = 0; static char *kwlist[] = {"data", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O", kwlist, &data)) return NULL; example_t*e = pylist_to_example(data); if(!e) return NULL; if(e->num_inputs != self->model->sig->num_inputs) { PY_ERROR("You supplied %d inputs for a model with %d inputs", e->num_inputs, self->model->sig->num_inputs); example_destroy(e); return NULL; } row_t*row = example_to_row(e, self->model->sig->column_names); if(!row) return PY_ERROR("Can't create row from data"); variable_t i = model_predict(self->model, row); row_destroy(row); example_destroy(e); if(i.type == TEXT) return pystring_fromstring(i.text); else if(i.type == CATEGORICAL) return pyint_fromlong(i.category); else if(i.type == CONTINUOUS) return PyFloat_FromDouble(i.value); else if(i.type == MISSING) return PY_NONE; else return PY_ERROR("internal error: bad variable type %d", i.type); }
void menu_free_rows(Menu *menu) { if(menu->size != 0) { for(int i = 0; i < menu->size; i++) { row_destroy(menu->row[i]); } free(menu->row); free(menu->title); } }
void test_if() { START_CODE(node) IF GT ADD RAW_PARAM(0) RAW_PARAM(1) END; RAW_PARAM(2) END; THEN CATEGORY_CONSTANT(1) ELSE CATEGORY_CONSTANT(2) END; END_CODE; node_print(node); node = test_serialization(node); environment_t env = test_environment(); constant_t v = node_eval(node, &env); constant_print(&v);puts("\n"); v = node_eval(node, &env); assert(v.c == 2); assert(v.type == CONSTANT_CATEGORY); env.row->inputs[2].value = 2.5; v = node_eval(node, &env); assert(v.c == 1); assert(v.type == CONSTANT_CATEGORY); row_destroy(env.row); node_destroy(node); }
int processData(RES_T *res, DB_T *dbw,DB_T *dbr) { ROW_T *row; int rx_id,loc_id; frm_cmd_gps_t gps; unsigned char *buf; size_t len,gpsLen; int count; int status=2; int ok; if (res_isClosed(res)) { LOG_E("Recordset is closed"); return EXIT_FAILURE; } loc_id = 1; gpsLen = sizeof(gps); while (!row_isClosed(row=res_next(res)) ) { rx_id = atoi(row_getFieldValue(row, row_getFieldIndex(row,"id"))); len = atoi(row_getFieldValue(row, row_getFieldIndex(row,"len"))); loc_id = atoi(row_getFieldValue(row, row_getFieldIndex(row,"ns"))); buf = row_getFieldValue(row, row_getFieldIndex(row,"data")); //FIXME La gestion de decodermanager no está funcionando... // actualmenet solo sirve para contar cuantas posibles subtramas pudiera haber.. // ok=frame_decodermanager_decode(buf,len,&count); if (count>0) { if (ok) status = 1; //FIXME Cambiar esto que solo esta para guardar tramas GPS y tiene que ser generico if ( frame_decode_gps(buf,len,&gps,&gpsLen) ) { if ( !mydb_insert_gps_subframe(dbw,rx_id,loc_id,&gps,gpsLen) ) { status = 3; } } // FIXME Megachapuzada para grabar las tramas 0x15... Niños no hagais esto en casa. Va en contra de toda logíca y raciocinio... // es mas ver esto puede producir trastornos cerebrales severos... if ( frame_decode_rally_gps_old(buf,len,NULL,NULL)) { int recCount; recCount=mydb_insert_rally_old_gps_frame(dbw,rx_id,loc_id,buf,len); LOG_F_D("Trama 0x15 (loc_id = %d, rx_id=%d) : Decodificados %d registros",loc_id,rx_id,recCount); if (!recCount) status = 3; } } else { status = -1; LOG_E("No se pudo decodificar nada"); } // if ( frame_decode_gps(buf,len,&gps,&gpsLen) ) { // // if ( mydb_insert_gps_subframe(dbw,rx_id,loc_id,&gps,gpsLen) ) // mydb_update_transport_frame_status(dbr,rx_id,1); // else // mydb_update_transport_frame_status(dbr,rx_id,3); // // } else { // mydb_update_transport_frame_status(dbr,rx_id,2); // LOG_E("No es una trama gps"); // } mydb_update_transport_frame_status(dbr,rx_id,status); } row_destroy(row); return EXIT_SUCCESS; // int num_fields; // MYSQL_FIELD *fields; // // MYSQL_ROW row; // // MYSQL *conWrite; // // // num_fields = mysql_num_fields(res); // // fields = mysql_fetch_fields(res); // // //TODO: Leer los datos descomprimirlos y guardarlos en la BBDD // while ((row = mysql_fetch_row(res)) != NULL ) { // // for(int i = 0; i < num_fields; i++) { // // LOG_F_D("%s = %s\t", fields[i].name, row[i]?row[i]:"NULL"); // // } // // } }