MCPcopy Index your code
hub / github.com/codechenx/FastTableViewer / autoDetectColumnType

Method autoDetectColumnType

buffer.go:478–560  ·  view source on GitHub ↗

autoDetectColumnType intelligently detects if a column contains numeric, date, or string data Returns colTypeDate for dates, colTypeFloat for numbers, colTypeStr for strings

(colIndex int)

Source from the content-addressed store, hash-verified

476// autoDetectColumnType intelligently detects if a column contains numeric, date, or string data
477// Returns colTypeDate for dates, colTypeFloat for numbers, colTypeStr for strings
478func (b *Buffer) autoDetectColumnType(colIndex int) int {
479 b.mu.RLock()
480 defer b.mu.RUnlock()
481
482 if colIndex < 0 || colIndex >= b.colLen {
483 return colTypeStr
484 }
485
486 // Sample size for type detection
487 startRow := b.rowFreeze
488 endRow := b.rowLen
489
490 // For large datasets, sample smartly (first N rows + some middle + last N)
491 sampleSize := 100
492 sampleRows := []int{}
493
494 if endRow-startRow > sampleSize {
495 // Sample first 50 rows
496 for i := startRow; i < startRow+50 && i < endRow; i++ {
497 sampleRows = append(sampleRows, i)
498 }
499 // Sample middle 25 rows
500 midPoint := (startRow + endRow) / 2
501 for i := midPoint; i < midPoint+25 && i < endRow; i++ {
502 sampleRows = append(sampleRows, i)
503 }
504 // Sample last 25 rows
505 for i := endRow - 25; i < endRow; i++ {
506 if i > startRow {
507 sampleRows = append(sampleRows, i)
508 }
509 }
510 } else {
511 // For small datasets, check all rows
512 for i := startRow; i < endRow; i++ {
513 sampleRows = append(sampleRows, i)
514 }
515 }
516
517 // Analyze samples
518 dateCount := 0
519 numericCount := 0
520 totalCount := 0
521
522 for _, rowIdx := range sampleRows {
523 if rowIdx >= b.rowLen || colIndex >= len(b.cont[rowIdx]) {
524 continue
525 }
526
527 value := strings.TrimSpace(b.cont[rowIdx][colIndex])
528
529 // Skip empty/null cells
530 if value == "" || value == "NA" || value == "N/A" || value == "NaN" || value == "null" {
531 continue
532 }
533
534 totalCount++
535

Callers 2

detectAllColumnTypesMethod · 0.95
TestAutoDetectColumnTypeFunction · 0.80

Calls 2

isDateValueFunction · 0.85
isNumericValueFunction · 0.85

Tested by 1

TestAutoDetectColumnTypeFunction · 0.64