comparison transform/CSVFeatureWriter.cpp @ 1206:659372323b45 tony-2.0-integration

Merge latest SV 3.0 branch code
author Chris Cannam
date Fri, 19 Aug 2016 15:58:57 +0100
parents d094598f84bd
children 4a2bc07ec0fb
comparison
equal deleted inserted replaced
1136:e94719f941ba 1206:659372323b45
35 "csv"), 35 "csv"),
36 m_separator(","), 36 m_separator(","),
37 m_sampleTiming(false), 37 m_sampleTiming(false),
38 m_endTimes(false), 38 m_endTimes(false),
39 m_forceEnd(false), 39 m_forceEnd(false),
40 m_omitFilename(false) 40 m_omitFilename(false),
41 m_digits(6)
41 { 42 {
42 } 43 }
43 44
44 CSVFeatureWriter::~CSVFeatureWriter() 45 CSVFeatureWriter::~CSVFeatureWriter()
45 { 46 {
80 p.name = "fill-ends"; 81 p.name = "fill-ends";
81 p.description = "Include durations (or end times) even for features without duration, by using the gap to the next feature instead."; 82 p.description = "Include durations (or end times) even for features without duration, by using the gap to the next feature instead.";
82 p.hasArg = false; 83 p.hasArg = false;
83 pl.push_back(p); 84 pl.push_back(p);
84 85
86 p.name = "digits";
87 p.description = "Specify the number of significant digits to use when printing transform outputs. Outputs are represented internally using single-precision floating-point, so digits beyond the 8th or 9th place are usually meaningless. The default is 6.";
88 p.hasArg = true;
89 pl.push_back(p);
90
85 return pl; 91 return pl;
86 } 92 }
87 93
88 void 94 void
89 CSVFeatureWriter::setParameters(map<string, string> &params) 95 CSVFeatureWriter::setParameters(map<string, string> &params)
91 FileFeatureWriter::setParameters(params); 97 FileFeatureWriter::setParameters(params);
92 98
93 SVDEBUG << "CSVFeatureWriter::setParameters" << endl; 99 SVDEBUG << "CSVFeatureWriter::setParameters" << endl;
94 for (map<string, string>::iterator i = params.begin(); 100 for (map<string, string>::iterator i = params.begin();
95 i != params.end(); ++i) { 101 i != params.end(); ++i) {
96 cerr << i->first << " -> " << i->second << endl; 102 SVDEBUG << i->first << " -> " << i->second << endl;
97 if (i->first == "separator") { 103 if (i->first == "separator") {
98 m_separator = i->second.c_str(); 104 m_separator = i->second.c_str();
99 cerr << "m_separator = " << m_separator << endl; 105 SVDEBUG << "m_separator = " << m_separator << endl;
100 if (m_separator == "\\t") { 106 if (m_separator == "\\t") {
101 m_separator = QChar::Tabulation; 107 m_separator = QChar::Tabulation;
102 } 108 }
103 } else if (i->first == "sample-timing") { 109 } else if (i->first == "sample-timing") {
104 m_sampleTiming = true; 110 m_sampleTiming = true;
106 m_endTimes = true; 112 m_endTimes = true;
107 } else if (i->first == "fill-ends") { 113 } else if (i->first == "fill-ends") {
108 m_forceEnd = true; 114 m_forceEnd = true;
109 } else if (i->first == "omit-filename") { 115 } else if (i->first == "omit-filename") {
110 m_omitFilename = true; 116 m_omitFilename = true;
117 } else if (i->first == "digits") {
118 int digits = atoi(i->second.c_str());
119 if (digits <= 0 || digits > 100) {
120 cerr << "CSVFeatureWriter: ERROR: Invalid or out-of-range value for number of significant digits: " << i->second << endl;
121 cerr << "CSVFeatureWriter: NOTE: Continuing with default settings" << endl;
122 } else {
123 m_digits = digits;
124 }
111 } 125 }
112 } 126 }
113 } 127 }
114 128
115 void 129 void
260 if (summaryType != "") { 274 if (summaryType != "") {
261 stream << m_separator << summaryType.c_str(); 275 stream << m_separator << summaryType.c_str();
262 } 276 }
263 277
264 for (unsigned int j = 0; j < f.values.size(); ++j) { 278 for (unsigned int j = 0; j < f.values.size(); ++j) {
265 stream << m_separator << f.values[j]; 279 stream << m_separator << QString("%1").arg(f.values[j], 0, 'g', m_digits);
266 } 280 }
267 281
268 if (f.label != "") { 282 if (f.label != "") {
269 stream << m_separator << "\"" << f.label.c_str() << "\""; 283 stream << m_separator << "\"" << f.label.c_str() << "\"";
270 } 284 }