145 lines
3.4 KiB
Go
145 lines
3.4 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"gullion/currency_convert_ssheets/configs"
|
||
|
"gullion/currency_convert_ssheets/etl"
|
||
|
etlForex "gullion/currency_convert_ssheets/extractionCleansing"
|
||
|
"gullion/currency_convert_ssheets/extrapolation"
|
||
|
"gullion/currency_convert_ssheets/reportgen"
|
||
|
utils "gullion/currency_convert_ssheets/utility"
|
||
|
"log"
|
||
|
"os"
|
||
|
"sort"
|
||
|
|
||
|
"github.com/urfave/cli/v2"
|
||
|
)
|
||
|
|
||
|
type appCommand int
|
||
|
|
||
|
const (
|
||
|
processForexHistoricalData appCommand = iota
|
||
|
processBkmHistoricalData
|
||
|
generateUsdSheet
|
||
|
extrapolateForexData
|
||
|
none
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
var inputfile string
|
||
|
var sheetName string
|
||
|
exists := true
|
||
|
appCommand := none
|
||
|
|
||
|
app := &cli.App{
|
||
|
Flags: []cli.Flag{
|
||
|
|
||
|
&cli.StringFlag{
|
||
|
Name: "inputfile",
|
||
|
Usage: "Configuration file path",
|
||
|
Aliases: []string{"i"},
|
||
|
Destination: &inputfile,
|
||
|
},
|
||
|
&cli.StringFlag{
|
||
|
Name: "sheet",
|
||
|
Usage: "sheet name of excel file",
|
||
|
Aliases: []string{"s"},
|
||
|
Destination: &sheetName,
|
||
|
},
|
||
|
},
|
||
|
|
||
|
Action: func(c *cli.Context) error {
|
||
|
if !utils.FileExists(inputfile) {
|
||
|
exists = false
|
||
|
fmt.Printf("Input file `%s` does NOT exist\n", inputfile)
|
||
|
}
|
||
|
return nil
|
||
|
},
|
||
|
|
||
|
Commands: []*cli.Command{
|
||
|
{
|
||
|
Name: "process_forex_historical_data",
|
||
|
Aliases: []string{"pro_forex_his"},
|
||
|
Usage: "Read Forex historical data and write on DB",
|
||
|
Action: func(c *cli.Context) error {
|
||
|
appCommand = processForexHistoricalData
|
||
|
return nil
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
Name: "process_bkm_historical_data",
|
||
|
Aliases: []string{"pro_bkm_his"},
|
||
|
Usage: "Read bkm historical data and write on DB",
|
||
|
Action: func(c *cli.Context) error {
|
||
|
appCommand = processBkmHistoricalData
|
||
|
return nil
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
Name: "extrapolate_forex-data",
|
||
|
Aliases: []string{"extra-forex-data"},
|
||
|
Usage: "extrapolate forex data",
|
||
|
Action: func(c *cli.Context) error {
|
||
|
appCommand = extrapolateForexData
|
||
|
return nil
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
Name: "generate_transformed_sheet",
|
||
|
Aliases: []string{"gen_trans"},
|
||
|
Usage: "Read historical data from DB and generate xlsx sheet",
|
||
|
Action: func(c *cli.Context) error {
|
||
|
appCommand = generateUsdSheet
|
||
|
return nil
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
|
||
|
sort.Sort(cli.FlagsByName(app.Flags))
|
||
|
sort.Sort(cli.CommandsByName(app.Commands))
|
||
|
|
||
|
err := app.Run(os.Args)
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
|
||
|
if exists {
|
||
|
switch appCommand {
|
||
|
case processForexHistoricalData:
|
||
|
config := configs.ReadConfigs(inputfile)
|
||
|
|
||
|
for _, inputFileRecord := range config.InputFile {
|
||
|
xlsxFile := &etlForex.FileXLXS{
|
||
|
Path: inputFileRecord.FileName,
|
||
|
Sheet: inputFileRecord.SheetName,
|
||
|
}
|
||
|
etl.ExtractForexDataFromFile(xlsxFile)
|
||
|
}
|
||
|
case processBkmHistoricalData:
|
||
|
config := configs.ReadConfigs(inputfile)
|
||
|
|
||
|
for _, inputFileRecord := range config.InputFile {
|
||
|
|
||
|
fmt.Println(inputFileRecord.FileName)
|
||
|
xlsxFile := &etlForex.FileXLXS{
|
||
|
Path: inputFileRecord.FileName,
|
||
|
Sheet: inputFileRecord.SheetName,
|
||
|
Measurement: inputFileRecord.Measurement,
|
||
|
}
|
||
|
etl.ExtractBkmDataFromFile(xlsxFile)
|
||
|
}
|
||
|
case extrapolateForexData:
|
||
|
extrapolation.ExtrapolateXauToTLForexRates()
|
||
|
case generateUsdSheet:
|
||
|
config := configs.ReadConfigs(inputfile)
|
||
|
|
||
|
for _, inputFileRecord := range config.InputFile {
|
||
|
reportgen.GenerateReport(inputFileRecord, config)
|
||
|
}
|
||
|
default:
|
||
|
fmt.Println("invalid/missing command, Please try help command")
|
||
|
}
|
||
|
}
|
||
|
}
|