comparison data/fileio/CSVFormat.cpp @ 1512:c9c2aa17439a import-audio-data

Add small, signed
author Chris Cannam
date Thu, 06 Sep 2018 16:26:19 +0100
parents 5f1b2a117a4f
children ffec849858a7
comparison
equal deleted inserted replaced
1511:12b7a9613eb5 1512:c9c2aa17439a
69 QStringList lines = chunk.split('\r', QString::SkipEmptyParts); 69 QStringList lines = chunk.split('\r', QString::SkipEmptyParts);
70 70
71 for (int li = 0; li < lines.size(); ++li) { 71 for (int li = 0; li < lines.size(); ++li) {
72 72
73 QString line = lines[li]; 73 QString line = lines[li];
74 if (line.startsWith("#") || line == "") continue; 74 if (line.startsWith("#") || line == "") {
75 continue;
76 }
75 77
76 guessQualities(line, lineno); 78 guessQualities(line, lineno);
77 79
78 ++lineno; 80 ++lineno;
79 } 81 }
80 82
81 if (lineno >= 50) break; 83 if (lineno >= 150) break;
82 } 84 }
83 85
84 guessPurposes(); 86 guessPurposes();
85 } 87 }
86 88
111 113
112 // All columns are regarded as having these qualities until we see 114 // All columns are regarded as having these qualities until we see
113 // something that indicates otherwise: 115 // something that indicates otherwise:
114 116
115 ColumnQualities defaultQualities = 117 ColumnQualities defaultQualities =
116 ColumnNumeric | ColumnIntegral | ColumnIncreasing | ColumnNearEmpty; 118 ColumnNumeric | ColumnIntegral | ColumnSmall |
119 ColumnIncreasing | ColumnNearEmpty;
117 120
118 for (int i = 0; i < cols; ++i) { 121 for (int i = 0; i < cols; ++i) {
119 122
120 while (m_columnQualities.size() <= i) { 123 while (m_columnQualities.size() <= i) {
121 m_columnQualities.push_back(defaultQualities); 124 m_columnQualities.push_back(defaultQualities);
128 ColumnQualities qualities = m_columnQualities[i]; 131 ColumnQualities qualities = m_columnQualities[i];
129 132
130 bool numeric = (qualities & ColumnNumeric); 133 bool numeric = (qualities & ColumnNumeric);
131 bool integral = (qualities & ColumnIntegral); 134 bool integral = (qualities & ColumnIntegral);
132 bool increasing = (qualities & ColumnIncreasing); 135 bool increasing = (qualities & ColumnIncreasing);
136 bool small = (qualities & ColumnSmall);
133 bool large = (qualities & ColumnLarge); // this one defaults to off 137 bool large = (qualities & ColumnLarge); // this one defaults to off
138 bool signd = (qualities & ColumnSigned); // also defaults to off
134 bool emptyish = (qualities & ColumnNearEmpty); 139 bool emptyish = (qualities & ColumnNearEmpty);
135 140
136 if (lineno > 1 && s.trimmed() != "") { 141 if (lineno > 1 && s.trimmed() != "") {
137 emptyish = false; 142 emptyish = false;
138 } 143 }
145 value = s.toFloat(&ok); 150 value = s.toFloat(&ok);
146 if (!ok) { 151 if (!ok) {
147 value = (float)StringBits::stringToDoubleLocaleFree(s, &ok); 152 value = (float)StringBits::stringToDoubleLocaleFree(s, &ok);
148 } 153 }
149 if (ok) { 154 if (ok) {
150 if (lineno < 2 && value > 1000.f) large = true; 155 if (lineno < 2 && value > 1000.f) {
156 large = true;
157 }
158 if (value < 0.f) {
159 signd = true;
160 }
161 if (value < -1.f || value > 1.f) {
162 small = false;
163 }
151 } else { 164 } else {
152 numeric = false; 165 numeric = false;
153 } 166 }
154 } 167 }
155 168
172 185
173 m_columnQualities[i] = 186 m_columnQualities[i] =
174 (numeric ? ColumnNumeric : 0) | 187 (numeric ? ColumnNumeric : 0) |
175 (integral ? ColumnIntegral : 0) | 188 (integral ? ColumnIntegral : 0) |
176 (increasing ? ColumnIncreasing : 0) | 189 (increasing ? ColumnIncreasing : 0) |
190 (small ? ColumnSmall : 0) |
177 (large ? ColumnLarge : 0) | 191 (large ? ColumnLarge : 0) |
192 (signd ? ColumnSigned : 0) |
178 (emptyish ? ColumnNearEmpty : 0); 193 (emptyish ? ColumnNearEmpty : 0);
179 } 194 }
180 195
181 if (lineno < 10) { 196 if (lineno < 10) {
182 m_example.push_back(list); 197 m_example.push_back(list);