void RewardMappingTools::readFromStream(istream& in, ProbabilisticRewardMapping& rewards) throw (IOException) { try { DataTable* data = DataTable::read(in, "\t", true, -1); vector<string> ids = data->getColumn(0); data->deleteColumn(0); // Remove ids data->deleteColumn(0); // Remove means // Now parse the table: size_t nbSites = data->getNumberOfColumns(); rewards.setNumberOfSites(nbSites); size_t nbBranches = data->getNumberOfRows(); for (size_t i = 0; i < nbBranches; i++) { int id = TextTools::toInt(ids[i]); size_t br = rewards.getNodeIndex(id); for (size_t j = 0; j < nbSites; j++) { rewards(br, j) = TextTools::toDouble((*data)(i, j)); } } // Parse the header: for (size_t i = 0; i < nbSites; i++) { string siteTxt = data->getColumnName(i); int site = 0; if (siteTxt.substr(0, 4) == "Site") site = TextTools::to<int>(siteTxt.substr(4)); else site = TextTools::to<int>(siteTxt); rewards.setSitePosition(i, site); } delete data; } catch (Exception& e) { throw IOException(string("Bad input file. ") + e.what()); } }
void IdeTableQuery::onPreRender() { ControlBase::onPreRender(); shared_ptr<XMLDocument> document = getDocument(); shared_ptr<XMLNode> node_root = document->create(_S("table_query")); DataTable result; if(getPage()->getDatabase()->execute(m_sql,result)) { shared_ptr<XMLNode> node_header = node_root->addChild(_S("header")); for(uint32 c = 0; c < result.columns(); c++) { String columnTitle = getColumnTitle(c); if(columnTitle.empty()) columnTitle = result.getColumnName(c); shared_ptr<XMLNode> node_column = node_header->addChild(_S("column")); node_column->setAttributeString(_S("name"), columnTitle); switch(getColumnType(c)) { case IdeTableQuery::ctString: { node_column->setAttributeString(_S("type"), _S("string")); } break; case IdeTableQuery::ctScore: { node_column->setAttributeString(_S("type"), _S("score")); } break; case IdeTableQuery::ctEntityID: { node_column->setAttributeString(_S("type"), _S("entity-id")); } break; case IdeTableQuery::ctObjectID: { node_column->setAttributeString(_S("type"), _S("object-id")); } break; case IdeTableQuery::ctUserID: { node_column->setAttributeString(_S("type"), _S("user-id")); } break; case IdeTableQuery::ctShortDateTime: { node_column->setAttributeString(_S("type"), _S("short-datetime")); } break; case IdeTableQuery::ctLongDateTime: { node_column->setAttributeString(_S("type"), _S("long-datetime")); } break; } } shared_ptr<XMLNode> node_data = node_root->addChild(_S("data")); for(uint32 r=0;r<result.rows();r++) { shared_ptr<XMLNode> node_data_row = node_data->addChild(_S("row")); for(uint32 c=0;c<result.columns();c++) { shared_ptr<XMLNode> node_data_row_item = node_data_row->addChild(_S("item")); String value = result.get(r,c); switch(getColumnType(c)) { case IdeTableQuery::ctScore: { node_data_row_item->setAttributeString(_S("value"), String::format(_S("%1.1f").c_str(), double(result.get(r,c)))); } break; case IdeTableQuery::ctEntityID: { // Sbagliata shared_ptr<XMLPortalExporter> exporter(OS_NEW XMLPortalExporter(node_data_row_item, getPage(), XMLPortalExporter::emLite)); shared_ptr<ObjectsIObject> object = getPage()->getObject(value.to_ascii()); if(object != nullptr) { object->exportXML(exporter); } } break; case IdeTableQuery::ctObjectID: { shared_ptr<XMLPortalExporter> exporter(OS_NEW XMLPortalExporter(node_data_row_item, getPage(), XMLPortalExporter::emLite)); shared_ptr<ObjectsIObject> object = getPage()->getObject(value.to_ascii()); if(object != nullptr) { object->exportXML(exporter); } } break; case IdeTableQuery::ctUserID: { shared_ptr<XMLPortalExporter> exporter(OS_NEW XMLPortalExporter(node_data_row_item, getPage(), XMLPortalExporter::emLite)); shared_ptr<ObjectsIObject> object = getPage()->getObject(value.to_ascii()); if(object != nullptr) { object->exportXML(exporter); } } break; case IdeTableQuery::ctShortDateTime: case IdeTableQuery::ctLongDateTime: { DateTime dt; dt.fromString(value); node_data_row_item->setAttributeDateTime(_S("value"), dt); } break; default: { node_data_row_item->setAttributeString(_S("value"), value); } break; } } } } }