Commit ff04e847e495955fb753da95b385505e918e8004
1 parent
02ead89d
Check if detection eval files contain only one ROC point
Showing
1 changed file
with
33 additions
and
1 deletions
openbr/core/plot.cpp
| ... | ... | @@ -271,6 +271,34 @@ bool Plot(const QStringList &files, const File &destination, bool show) |
| 271 | 271 | return p.finalize(show); |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | +//Check if only one ROC point is in the file | |
| 275 | +bool fileHasSinglePoint(const QString &evalFile) { | |
| 276 | + QFile file(evalFile); | |
| 277 | + bool success = file.open(QFile::ReadOnly); | |
| 278 | + if (!success) qFatal("Failed to open %s for reading.", qPrintable(evalFile)); | |
| 279 | + QStringList lines = QString(file.readAll()).split("\n"); | |
| 280 | + file.close(); | |
| 281 | + | |
| 282 | + int rocCnt = 0; | |
| 283 | + foreach (const QString &line, lines) { | |
| 284 | + if (line.contains("DiscreteROC")) { | |
| 285 | + rocCnt++; | |
| 286 | + } | |
| 287 | + if (rocCnt > 1) | |
| 288 | + return false; | |
| 289 | + } | |
| 290 | + | |
| 291 | + return true; | |
| 292 | +} | |
| 293 | + | |
| 294 | +//Check all files to see if any single file has only have one ROC point | |
| 295 | +bool filesHaveSinglePoint(const QStringList &files) { | |
| 296 | + foreach (const File &file, files) | |
| 297 | + if (fileHasSinglePoint(file)) | |
| 298 | + return true; | |
| 299 | + return false; | |
| 300 | +} | |
| 301 | + | |
| 274 | 302 | bool PlotDetection(const QStringList &files, const File &destination, bool show) |
| 275 | 303 | { |
| 276 | 304 | qDebug("Plotting %d detection file(s) to %s", files.size(), qPrintable(destination)); |
| ... | ... | @@ -287,8 +315,12 @@ bool PlotDetection(const QStringList &files, const File &destination, bool show) |
| 287 | 315 | "rm(data)\n" |
| 288 | 316 | "\n"); |
| 289 | 317 | |
| 318 | + QString plotType("line"); | |
| 319 | + if (filesHaveSinglePoint(files)) | |
| 320 | + plotType = QString("point"); | |
| 321 | + | |
| 290 | 322 | foreach (const QString &type, QStringList() << "Discrete" << "Continuous") |
| 291 | - p.file.write(qPrintable(QString("qplot(X, Y, data=%1ROC%2").arg(type, (p.major.smooth || p.minor.smooth) ? ", geom=\"smooth\", method=loess, level=0.99" : ", geom=\"line\"") + | |
| 323 | + p.file.write(qPrintable(QString("qplot(X, Y, data=%1ROC%2").arg(type, (p.major.smooth || p.minor.smooth) ? ", geom=\"smooth\", method=loess, level=0.99" : QString(", geom=\"%1\"").arg(plotType)) + | |
| 292 | 324 | (p.major.size > 1 ? QString(", colour=factor(%1)").arg(p.major.header) : QString()) + |
| 293 | 325 | (p.minor.size > 1 ? QString(", linetype=factor(%1)").arg(p.minor.header) : QString()) + |
| 294 | 326 | QString(", xlab=\"False Accepts\", ylab=\"True Accept Rate\") + theme_minimal()") + | ... | ... |