RoadRunnerData convertCAPIResultData(RRCDataPtr    result)
{
    RoadRunnerData resultData;

    StringList colNames;
    //Copy column names
    for(int i = 0; i < result->CSize; i++)
    {
        colNames.add(result->ColumnHeaders[i]);
    }

    resultData.setColumnNames(colNames);

    //Then the data
    int index = 0;
    resultData.allocate(result->RSize, result->CSize);

    for(int j = 0; j < result->RSize; j++)
    {
        for(int i = 0; i < result->CSize; i++)
        {
            resultData(j,i) = result->Data[index++];
        }
    }

    return resultData;
}
Esempio n. 2
0
void __fastcall TMForm::PlotTestTestSuiteDataExecute(TObject *Sender)
{
    //Read the test suite data
    string file =  FSF->GetSelectedFileInTree();
    string path =  rr::extractFilePath(file);
    vector<string> dirs = rr::splitString(path,"\\");
    string tsDataFile;
    if(dirs.size())
    {
        string caseNr = dirs[dirs.size() -1];
        tsDataFile = rr::joinPath(path, (caseNr + "-results.csv"));
    }

    RoadRunnerData result;
    if(!result.load(tsDataFile))
    {
        return;
    }

    //Fill out data for all series
    int nrOfSeries = result.cSize() -1; //First one is time
    StringList colNames = result.getColumnNames();
    vector<TLineSeries*> series;
    for(int i = 0; i < nrOfSeries; i++)
    {
        TLineSeries* aSeries = new TLineSeries(Chart1);
        aSeries->Title = colNames[i+1].c_str();
        aSeries->Color = clGray;
        aSeries->LinePen->Width = 1;
        aSeries->Pointer->Visible = true;
        series.push_back(aSeries);
        Chart1->AddSeries(aSeries);
    }

    for(int j = 0; j < result.rSize(); j++)
    {
        double xVal = result(j,0);

        for(int i = 0; i < nrOfSeries; i++)
        {
            double yData = result(j, i+1);
            series[i]->AddXY(xVal, yData);
        }
    }
    Chart1->Update();

}
RRCDataPtr createRRCData(const RoadRunnerData& result)
{
    RRCData* rrCData  = new RRCData;
    memset(rrCData, 0, sizeof(RRCData));

    rrCData->ColumnHeaders = new char*[result.cSize()];
    for(int i = 0; i < result.cSize(); i++)
    {
        rrCData->ColumnHeaders[i] = rr::createText(result.getColumnNames()[i]);
    }

    rrCData->RSize = result.rSize();
    rrCData->CSize = result.cSize();
    int size = rrCData->RSize*rrCData->CSize;
    rrCData->Data = new double[size];

    if(result.hasWeights())
    {
    	rrCData->Weights = new double[size];
    }

    int index = 0;
    //The data layout is simple row after row, in one single long row...
    for(int row = 0; row < rrCData->RSize; row++)
    {
        for(int col = 0; col < rrCData->CSize; col++)
        {
            rrCData->Data[index] = result(row, col);
            if(result.hasWeights())
            {
            	rrCData->Weights[index] = result.weight(row, col);
            }
            ++index;
        }
    }
	return rrCData;
}
bool RoadRunnerData::append(const RoadRunnerData& data)
{
    //When appending data, the number of rows have to match with current data
    if(mTheData.RSize() > 0)
    {
        if(data.rSize() != rSize())
        {
            return false;
        }
    }
    else
    {
        (*this) = data;
        return true;
    }

    int currColSize = cSize();

    RoadRunnerData temp(mColumnNames, mTheData);

    int newCSize = cSize() + data.cSize();
    mTheData.resize(data.rSize(), newCSize );

    for(int row = 0; row < temp.rSize(); row++)
    {
        for( int col = 0; col < temp.cSize(); col++)
        {
            mTheData(row, col) = temp(row, col);
        }
    }

    for(int row = 0; row < mTheData.RSize(); row++)
    {
        for(int col = 0; col < data.cSize(); col++)
        {
            mTheData(row, col + currColSize) = data(row, col);
        }
    }

    for(int col = 0; col < data.cSize(); col++)
    {
        mColumnNames.push_back(data.getColumnName(col));
    }
    return true;
}