comparison data/fileio/CSVFormat.cpp @ 631:3a5ee4b6c9ad

* Complete the overhaul of CSV file import; now you can pick the purpose for each column in the file, and SV should do the rest. The most significant practical improvement here is that we can now handle files in which time and duration do not necessarily appear in known columns.
author Chris Cannam
date Mon, 19 Jul 2010 17:08:56 +0000
parents 11a664058dd8
children ad7c96620886
comparison
equal deleted inserted replaced
630:11a664058dd8 631:3a5ee4b6c9ad
37 void 37 void
38 CSVFormat::guessFormatFor(QString path) 38 CSVFormat::guessFormatFor(QString path)
39 { 39 {
40 m_modelType = TwoDimensionalModel; 40 m_modelType = TwoDimensionalModel;
41 m_timingType = ExplicitTiming; 41 m_timingType = ExplicitTiming;
42 m_durationType = Durations;
43 m_timeUnits = TimeSeconds; 42 m_timeUnits = TimeSeconds;
44 m_behaviour = QString::KeepEmptyParts;
45 43
46 m_maxExampleCols = 0; 44 m_maxExampleCols = 0;
47 m_columnCount = 0; 45 m_columnCount = 0;
48 m_variableColumnCount = false; 46 m_variableColumnCount = false;
49 47
184 } 182 }
185 183
186 void 184 void
187 CSVFormat::guessPurposes() 185 CSVFormat::guessPurposes()
188 { 186 {
189 while (m_columnPurposes.size() <= m_columnCount) {
190 m_columnPurposes.push_back(ColumnUnknown);
191 }
192
193 m_timingType = CSVFormat::ImplicitTiming; 187 m_timingType = CSVFormat::ImplicitTiming;
194 m_timeUnits = CSVFormat::TimeWindows; 188 m_timeUnits = CSVFormat::TimeWindows;
195 189
196 int timingColumnCount = 0; 190 int timingColumnCount = 0;
197 191
227 221
228 } else { 222 } else {
229 223
230 if (timingColumnCount == 2 && m_timingType == ExplicitTiming) { 224 if (timingColumnCount == 2 && m_timingType == ExplicitTiming) {
231 purpose = ColumnEndTime; 225 purpose = ColumnEndTime;
232 m_durationType = EndTimes;
233 } 226 }
234 } 227 }
235 } 228 }
236 229
237 if (purpose == ColumnUnknown) { 230 if (purpose == ColumnUnknown) {
240 } else { 233 } else {
241 purpose = ColumnLabel; 234 purpose = ColumnLabel;
242 } 235 }
243 } 236 }
244 237
245 m_columnPurposes[i] = purpose; 238 setColumnPurpose(i, purpose);
246 } 239 }
247 240
248 int valueCount = 0; 241 int valueCount = 0;
249 for (int i = 0; i < m_columnCount; ++i) { 242 for (int i = 0; i < m_columnCount; ++i) {
250 if (m_columnPurposes[i] == ColumnValue) ++valueCount; 243 if (m_columnPurposes[i] == ColumnValue) ++valueCount;
279 --valueCount; 272 --valueCount;
280 } 273 }
281 } 274 }
282 } 275 }
283 276
284 if (valueCount == 0) { 277 if (timingColumnCount > 1) {
285 m_modelType = OneDimensionalModel; 278 m_modelType = TwoDimensionalModelWithDuration;
286 } else if (valueCount == 1) {
287 m_modelType = TwoDimensionalModel;
288 } else { 279 } else {
289 m_modelType = ThreeDimensionalModel; 280 if (valueCount == 0) {
281 m_modelType = OneDimensionalModel;
282 } else if (valueCount == 1) {
283 m_modelType = TwoDimensionalModel;
284 } else {
285 m_modelType = ThreeDimensionalModel;
286 }
290 } 287 }
291 288
292 std::cerr << "Estimated column purposes: "; 289 std::cerr << "Estimated column purposes: ";
293 for (int i = 0; i < m_columnCount; ++i) { 290 for (int i = 0; i < m_columnCount; ++i) {
294 std::cerr << int(m_columnPurposes[i]) << " "; 291 std::cerr << int(m_columnPurposes[i]) << " ";
295 } 292 }
296 std::cerr << std::endl; 293 std::cerr << std::endl;
297 294
298 std::cerr << "Estimated model type: " << m_modelType << std::endl; 295 std::cerr << "Estimated model type: " << m_modelType << std::endl;
299 std::cerr << "Estimated timing type: " << m_timingType << std::endl; 296 std::cerr << "Estimated timing type: " << m_timingType << std::endl;
300 std::cerr << "Estimated duration type: " << m_durationType << std::endl;
301 std::cerr << "Estimated units: " << m_timeUnits << std::endl; 297 std::cerr << "Estimated units: " << m_timeUnits << std::endl;
302 } 298 }
303 299
304 300 CSVFormat::ColumnPurpose
301 CSVFormat::getColumnPurpose(int i)
302 {
303 while (m_columnPurposes.size() <= i) {
304 m_columnPurposes.push_back(ColumnUnknown);
305 }
306 return m_columnPurposes[i];
307 }
308
309 CSVFormat::ColumnPurpose
310 CSVFormat::getColumnPurpose(int i) const
311 {
312 return m_columnPurposes[i];
313 }
314
315 void
316 CSVFormat::setColumnPurpose(int i, ColumnPurpose p)
317 {
318 while (m_columnPurposes.size() <= i) {
319 m_columnPurposes.push_back(ColumnUnknown);
320 }
321 m_columnPurposes[i] = p;
322 }
323
324
325
326