-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
85 lines (73 loc) · 2.17 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"flag"
"fmt"
"log"
"github.com/guptarohit/asciigraph"
"github.com/charmbracelet/lipgloss"
explore "github.com/tmickleydoyle/shallow-explore/utils"
)
var (
file string
path string
style string
)
var styleDark = lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("#FAFAFA")).
Background(lipgloss.Color("#808080")).
PaddingTop(1).
PaddingBottom(1).
PaddingLeft(2).
PaddingRight(2).
BorderStyle(lipgloss.NormalBorder()).
BorderForeground(lipgloss.Color("#FAFAFA"))
var styleLight = lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("#808080")).
Background(lipgloss.Color("#FAFAFA")).
PaddingTop(1).
PaddingBottom(1).
PaddingLeft(2).
PaddingRight(2).
BorderStyle(lipgloss.NormalBorder()).
BorderForeground(lipgloss.Color("#808080"))
func main() {
flag.StringVar(&file, "csv", "", "starting point")
flag.StringVar(&style, "style", "", "output style (dark or light)")
flag.Parse()
if file != "" {
path = file
} else {
log.Fatal("Could not find the path to the CSV file")
}
records := explore.ReadCSVFile(path)
for column := range records[0] {
colValues := []string{}
for i := 1; i < len(records); i++ {
colValues = append(colValues, records[i][column])
}
transformedArray, _ := explore.ConvertStringToInt(colValues)
plotArray, stringValues := explore.ConvertStringToInt(colValues)
column := fmt.Sprintf("Column: %s\n\n", records[0][column])
var selectedStyle lipgloss.Style
if style == "dark" {
selectedStyle = styleDark
} else {
selectedStyle = styleLight
}
if len(transformedArray) > 0 {
min, max := explore.MinMaxValues(transformedArray)
mean := explore.MeanValue(transformedArray)
median := explore.MedianValue(transformedArray)
statsOutput := explore.FloatOutput(min, max, mean, median)
graph := asciigraph.Plot(plotArray, asciigraph.Height(20), asciigraph.Width(90), asciigraph.Caption(statsOutput))
fmt.Println(selectedStyle.Render(column + graph))
} else {
valuesMap := explore.CountValues(stringValues)
sortedMap := explore.SortMapByValue(valuesMap)
histogram := explore.HistTopTen(sortedMap, column)
fmt.Println(selectedStyle.Render(column + histogram))
}
}
}