void MapStatsWriter::writeStats(const QString& mapInputPath, const QString& statsOutputFilePath, QString sep) { LOG_INFO("Writing stats for map in file: " << mapInputPath << " to file: " << statsOutputFilePath); // read the conflation status from the file. conf().set(ConfigOptions().getReaderUseFileStatusKey(), true); shared_ptr<OsmMap> map(new OsmMap()); OsmUtils::loadMap(map, mapInputPath, true, Status::Invalid); MapReprojector::reprojectToPlanar(map); QList< QList<SingleStat> > allStats; shared_ptr<CalculateStatsOp> cso(new CalculateStatsOp()); cso->apply(map); allStats.append(cso->getStats()); QFile outputFile(statsOutputFilePath); if (outputFile.exists()) { outputFile.remove(); } if (outputFile.open(QFile::WriteOnly | QFile::Text)) { QTextStream out(&outputFile); //out << "Stat Name\t" << args.join(sep) << endl; out << statsToString(allStats, sep); outputFile.close(); } else { LOG_ERROR("Unable to write to output file."); } }
/* ******************************************************** * Gives a printable string of tree structure. If the number of nodes is more than 30, only statistics are returned in the string. */ string DTree::toString() { string out = ""; if(!stats.bLevels || !stats.bLeaves || !stats.bNodes) computeStats(root); if(stats.nbNodes < 30) out += (*root).toString(); out += statsToString(); return out; }
void MapStatsWriter::writeStatsToJson(QList< QList<SingleStat> >& stats, const QString& statsOutputFilePath) { try { pt::ptree pt; QStringList allStats = statsToString(stats, "\t").split("\n"); for (int i = 0; i < allStats.size(); i++) { QStringList statrow = allStats.at(i).split("\t"); if (statrow.size() > 0 && !statrow[0].isEmpty()) { QStringList tmpValues; //filter out empty values, first one in array is key, so the loop starts with 1 for (int j = 1; j < statrow.size(); j++) { if (!statrow.at(j).trimmed().isEmpty()) { tmpValues << statrow.at(j).trimmed(); } } //if only one value in the array, do not use array in json file if (tmpValues.size() == 1) { pt::ptree child; child.put("", tmpValues.at(0).toStdString()); pt.add_child(statrow.at(0).toStdString(), child); } else { pt::ptree children; for (int j = 0; j < tmpValues.size(); j++) { pt::ptree child; child.put("", tmpValues.at(j).toStdString()); children.push_back(std::make_pair("", child)); } pt.add_child(statrow.at(0).toStdString(), children); } } } pt::write_json(statsOutputFilePath.toStdString(), pt); } catch (std::exception e) { QString reason = e.what(); LOG_ERROR("Error writing JSON " + reason); } }
void MapStatsWriter::writeStatsToText(QList<QList<SingleStat> > &stats, const QString &statsOutputFilePath) { LOG_INFO("Writing stats to file: " << statsOutputFilePath); // Write to the text file QFile outputFile(statsOutputFilePath); if (outputFile.exists()) { outputFile.remove(); } if (outputFile.open(QFile::WriteOnly | QFile::Text)) { QTextStream out(&outputFile); out << statsToString(stats, "\t"); outputFile.close(); } else { LOG_ERROR("Unable to write to output file."); } }
char *timingsToString(Timings *t, int totalTime){ char *answer; int cursor, i, leaderSize, length, n, size_n; if (t->iterations > 1) { char *stats = statsToString(t); answer = calloc(4000+strlen(stats), sizeof(char)); sprintf(answer, "There were %d iterations, which took %d milliseconds in all.\r\n\r\n", t->iterations, totalTime); strcat(answer, stats); //free(stats); strcat(answer, "\r\nIndividual timings:\r\n\r\n"); } else { answer = calloc(4000, sizeof(char)); } leaderSize = 0; for(n = 0; n<t->phases; n++) { length = strlen(t->phaseDescriptions[n]); if (length>leaderSize) leaderSize = length; } leaderSize += leaderSize%4 != 0 ? 4-leaderSize%4 : 0; for(i=0; i<t->iterations; i+=4) { for(n = 0; n<t->phases; n++) { strcat(answer, t->phaseDescriptions[n]); size_n = strlen(t->phaseDescriptions[n]); cursor = strlen(answer); while(size_n++<leaderSize) answer[cursor++] = ' '; catPaddedInt(answer, (t->data[n+i*t->phases])); if(i+1<t->iterations) catPaddedInt(answer, (t->data[n+ t->phases*(i+1)])); if(i+2<t->iterations) catPaddedInt(answer, (t->data[n+ t->phases*(i+2)])); if(i+3<t->iterations) catPaddedInt(answer, (t->data[n+ t->phases*(i+3)])); strcat(answer, "\r\n"); } strcat(answer, "\r\n"); } return answer; }