Skip to content

Commit

Permalink
export to file path WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Aidan-Zamfir committed Jun 7, 2024
1 parent 2975074 commit b30eefa
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 18 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
## CLI tool for quick data normalization
## CLI tool for quick data normalization

*Currently WIP*

This simple CLI tool allows you to quickly normalize and/or standardise csv data for ML applications and save it to your device.

### Use:


In Progress...

Expand All @@ -9,3 +16,5 @@ In Progress...
- [x] Re-insert column names
- [ ] Easy UI
- [ ] CLI Specify save file path
- [ ] MAKEFILE

24 changes: 24 additions & 0 deletions cli/expoFile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cli

import (
"log"
"os"
)

func ExportToFile(result, filePath string) {

if filePath != "" {
file, err := os.OpenFile(filePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Println("Error opening file:", err)
return
}
defer file.Close()
if _, err := file.WriteString(result); err != nil {
log.Println("Error writing to file:", err)
} else {
log.Println("Saved to:", filePath)
}
}

}
10 changes: 6 additions & 4 deletions cli/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (

var normalizeCmd = &cobra.Command{
Use: "nm",
Short: "Will return normalized values as X file form", //decide
Short: "Will return normalized values as .csv file", //decide
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {

da, head, err := csvData.GetCSVData(args[0])
if err != nil {
log.Fatal(err)
Expand All @@ -29,12 +30,13 @@ var normalizeCmd = &cobra.Command{
if err != nil {
log.Fatal(err)
}

//res := "dataNM.csv"
//ExportToFile(res, exportFilePath)
},
}

func init() {
rootCmd.AddCommand(normalizeCmd)

//need to add file path functionality
// normalizeCmd.Flags().StringVarP(&exportFilePath, "export", "e", "Export to file ->")
//normalizeCmd.Flags().StringVarP(&exportFilePath, "export", "e", "", "Export to filepath -> (provide path)")
}
9 changes: 5 additions & 4 deletions cli/standardise.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

var standardiseCmd = &cobra.Command{
Use: "stand",
Short: "Will return standardised values as X file form", //decide
Short: "Will return standardised values as .csv file", //decide
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
da, head, err := csvData.GetCSVData(args[0])
Expand All @@ -29,12 +29,13 @@ var standardiseCmd = &cobra.Command{
if err != nil {
log.Fatal(err)
}

//res := "dataST.csv"
//ExportToFile(res, exportFilePath)
},
}

func init() {
rootCmd.AddCommand(standardiseCmd)

//need to add file path functionality
// normalizeCmd.Flags().StringVarP(&exportFilePath, "export", "e", "Export to file ->")
//standardiseCmd.Flags().StringVarP(&exportFilePath, "export", "e", "", "Export to filepath -> (provide path)")
}
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ go 1.22.2

require (
github.com/spf13/cobra v1.8.0
github.com/tobgu/qframe v0.4.0
)

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mauricelam/genny v0.0.0-20190320071652-0800202903e5 // indirect
github.com/spf13/pflag v1.0.5 // indirect
)
14 changes: 7 additions & 7 deletions testdata.csv
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
First,Second,Third,Fourth
11,22,31,44
19,25,32,46
33,29,3,43
92,21,54,3
1,22,3,6
32,3,1,66
First,Second,Third,Fourth,Fifth,Sixth
11,22,31,44,2,60
19,25,32,46,1002,34
33,29,3,43,20,40
92,21,54,3,27,54
1,22,3,6,10,74
32,3,1,66,2,7

0 comments on commit b30eefa

Please sign in to comment.