Example #1
0
void MetricDataTable::setMetricModel(){

    delete model_;

    SmartPtr<Named_interface> ni =
            Root::instance()->interface( metricData_manager + "/metricRegistrar");

    //MetricDataManager* mDataRegistrar = dynamic_cast<MetricDataManager*>(ni.raw_ptr());
    MetricDataManager* mDataRegistrar = (MetricDataManager*)(ni.raw_ptr());
    //MetricDataManager* mDataRegistrar;
    std::vector<std::string> metric_names = mDataRegistrar->get_metric_names();

    model_ = new QStandardItemModel(metric_names.size(), 2, this);
    model_->setHeaderData(0, Qt::Horizontal, tr("Name"));
    model_->setHeaderData(1, Qt::Horizontal, tr("Type"));
    for(unsigned int i=0; i<metric_names.size(); ++i ) {
        const MetricDataToProperties m = mDataRegistrar->get_properties_for_metric(metric_names[i]);
        std::cout << "Current Metric Name " << metric_names[i] <<std::endl;
        //MetricDataToProperties m;
        model_->setData(model_->index(i,0, QModelIndex()), QString::fromStdString(metric_names[i]) );
        model_->setData(model_->index(i,0, QModelIndex()), QString::fromStdString(m.type()) );
    }

    tableView_->setModel(model_);

}
VectorXf param_sensitivity_widget::readResponseValues(
    QStringList realizations,QString response)
{

    // Sort the realizations stringlist
    realizations.sort();


    SmartPtr<Named_interface> ni =
        Root::instance()->interface( metricData_manager +
                                     "/metricRegistrar");

    MetricDataManager* mRegistrar =
        dynamic_cast<MetricDataManager*>(ni.raw_ptr());

    // Grab the grid name
    std::string gridName = mdsObject_->getGridName(0);

    // Obtain pointer to metricToProperties map
    MetricDataToProperties  propFromMetricRegistrar =
        mRegistrar->get_properties_for_metric(response.toStdString());

    // Determine what kind of metricData we are looking at
    std::string response_type = propFromMetricRegistrar.
                                data_type().toStdString();

    // Response values
    VectorXf responseValue(realizations.size());

    if (response_type == "MetricTimeSeriesData")
    {

        for (unsigned int i = 0; i < realizations.size(); ++i )
        {
            MetricData* mdata = mRegistrar->getMetricData(gridName,
                                realizations.at(i).
                                toStdString(),
                                response.toStdString());

            // Should be a safe cast as this function is only called for data that
            // has form "TimeSeries"
            MetricTimeSeriesData *mDataTS =
                static_cast<MetricTimeSeriesData*>(mdata);

            // Get number of data points in this response for particular property
            // We assume that the data/time have same number of points
            int numDataPoints = mDataTS->data().size();

            responseValue[i] = (mDataTS->data().at(numDataPoints -1));
        }
    }

    return responseValue;
}