comparison transform/Transform.cpp @ 508:1b8c748fd7ea

* Support recording the summary type in transform
author Chris Cannam
date Fri, 05 Dec 2008 16:18:04 +0000
parents 3012af787e4a
children ecbd99d5d2c4
comparison
equal deleted inserted replaced
507:0944d13689b2 508:1b8c748fd7ea
29 #include <QTextStream> 29 #include <QTextStream>
30 30
31 #include <iostream> 31 #include <iostream>
32 32
33 Transform::Transform() : 33 Transform::Transform() :
34 m_summaryType(NoSummary),
34 m_stepSize(0), 35 m_stepSize(0),
35 m_blockSize(0), 36 m_blockSize(0),
36 m_windowType(HanningWindow), 37 m_windowType(HanningWindow),
37 m_sampleRate(0) 38 m_sampleRate(0)
38 { 39 {
39 } 40 }
40 41
41 Transform::Transform(QString xml) : 42 Transform::Transform(QString xml) :
43 m_summaryType(NoSummary),
42 m_stepSize(0), 44 m_stepSize(0),
43 m_blockSize(0), 45 m_blockSize(0),
44 m_windowType(HanningWindow), 46 m_windowType(HanningWindow),
45 m_sampleRate(0) 47 m_sampleRate(0)
46 { 48 {
112 return 114 return
113 m_id == t.m_id && 115 m_id == t.m_id &&
114 m_parameters == t.m_parameters && 116 m_parameters == t.m_parameters &&
115 m_configuration == t.m_configuration && 117 m_configuration == t.m_configuration &&
116 m_program == t.m_program && 118 m_program == t.m_program &&
119 m_summaryType == t.m_summaryType &&
117 m_stepSize == t.m_stepSize && 120 m_stepSize == t.m_stepSize &&
118 m_blockSize == t.m_blockSize && 121 m_blockSize == t.m_blockSize &&
119 m_windowType == t.m_windowType && 122 m_windowType == t.m_windowType &&
120 m_startTime == t.m_startTime && 123 m_startTime == t.m_startTime &&
121 m_duration == t.m_duration && 124 m_duration == t.m_duration &&
135 return mapLessThan<QString, QString>(m_configuration, t.m_configuration); 138 return mapLessThan<QString, QString>(m_configuration, t.m_configuration);
136 } 139 }
137 if (m_program != t.m_program) { 140 if (m_program != t.m_program) {
138 return m_program < t.m_program; 141 return m_program < t.m_program;
139 } 142 }
143 if (m_summaryType != t.m_summaryType) {
144 return int(m_summaryType) < int(t.m_summaryType);
145 }
140 if (m_stepSize != t.m_stepSize) { 146 if (m_stepSize != t.m_stepSize) {
141 return m_stepSize < t.m_stepSize; 147 return m_stepSize < t.m_stepSize;
142 } 148 }
143 if (m_blockSize != t.m_blockSize) { 149 if (m_blockSize != t.m_blockSize) {
144 return m_blockSize < t.m_blockSize; 150 return m_blockSize < t.m_blockSize;
293 Transform::setProgram(QString program) 299 Transform::setProgram(QString program)
294 { 300 {
295 m_program = program; 301 m_program = program;
296 } 302 }
297 303
304 Transform::SummaryType
305 Transform::getSummaryType() const
306 {
307 return m_summaryType;
308 }
309
310 void
311 Transform::setSummaryType(SummaryType type)
312 {
313 m_summaryType = type;
314 }
298 315
299 size_t 316 size_t
300 Transform::getStepSize() const 317 Transform::getStepSize() const
301 { 318 {
302 return m_stepSize; 319 return m_stepSize;
384 .arg(m_blockSize) 401 .arg(m_blockSize)
385 .arg(encodeEntities(Window<float>::getNameForType(m_windowType).c_str())) 402 .arg(encodeEntities(Window<float>::getNameForType(m_windowType).c_str()))
386 .arg(encodeEntities(m_startTime.toString().c_str())) 403 .arg(encodeEntities(m_startTime.toString().c_str()))
387 .arg(encodeEntities(m_duration.toString().c_str())) 404 .arg(encodeEntities(m_duration.toString().c_str()))
388 .arg(m_sampleRate); 405 .arg(m_sampleRate);
406
407 if (m_summaryType != NoSummary) {
408 out << QString("\n summaryType=\"%1\"").arg(summaryTypeToString(m_summaryType));
409 }
389 410
390 if (extraAttributes != "") { 411 if (extraAttributes != "") {
391 out << " " << extraAttributes; 412 out << " " << extraAttributes;
392 } 413 }
393 414
417 438
418 out << "/>\n"; 439 out << "/>\n";
419 } 440 }
420 } 441 }
421 442
443 Transform::SummaryType
444 Transform::stringToSummaryType(QString str)
445 {
446 str = str.toLower();
447 if (str == "minimum" || str == "min") return Minimum;
448 if (str == "maximum" || str == "max") return Maximum;
449 if (str == "mean") return Mean;
450 if (str == "median") return Median;
451 if (str == "mode") return Mode;
452 if (str == "sum") return Sum;
453 if (str == "variance") return Variance;
454 if (str == "standard-deviation" || str == "standardDeviation" ||
455 str == "standard deviation" || str == "sd") return StandardDeviation;
456 if (str == "count") return Count;
457 if (str == "") return NoSummary;
458 std::cerr << "Transform::stringToSummaryType: unknown summary type \""
459 << str.toStdString() << "\"" << std::endl;
460 return NoSummary;
461 }
462
463 QString
464 Transform::summaryTypeToString(SummaryType type)
465 {
466 switch (type) {
467 case Minimum: return "min";
468 case Maximum: return "max";
469 case Mean: return "mean";
470 case Median: return "median";
471 case Mode: return "mode";
472 case Sum: return "sum";
473 case Variance: return "variance";
474 case StandardDeviation: return "sd";
475 case Count: return "count";
476 case NoSummary: return "";
477 default:
478 std::cerr << "Transform::summaryTypeToString: unexpected summary type "
479 << int(type) << std::endl;
480 return "";
481 }
482 }
483
422 void 484 void
423 Transform::setFromXmlAttributes(const QXmlAttributes &attrs) 485 Transform::setFromXmlAttributes(const QXmlAttributes &attrs)
424 { 486 {
425 if (attrs.value("id") != "") { 487 if (attrs.value("id") != "") {
426 setIdentifier(attrs.value("id")); 488 setIdentifier(attrs.value("id"));
456 } 518 }
457 519
458 if (attrs.value("sampleRate") != "") { 520 if (attrs.value("sampleRate") != "") {
459 setSampleRate(attrs.value("sampleRate").toFloat()); 521 setSampleRate(attrs.value("sampleRate").toFloat());
460 } 522 }
461 } 523
462 524 if (attrs.value("summaryType") != "") {
525 setSummaryType(stringToSummaryType(attrs.value("summaryType")));
526 }
527 }
528