package main
import "encoding/csv"
import "fmt"
import "io"
import "log"
import "os"
import "strconv"
var COLUMNS []string
type FinancialData struct {
Date string
Open, High, Low, Close, Adj_Close, Volume float64
}
func printHTML(data []FinancialData, out io.Writer) {
io.WriteString(out, `
Financial
`)
for _, col := range COLUMNS {
io.WriteString(out, " ")
io.WriteString(out, col)
io.WriteString(out, " | \n")
}
io.WriteString(out, "
\n")
// data
for _, row := range data {
row.printHTMLRow(out)
}
io.WriteString(out, `
`)
}
func getDataOpen(data []FinancialData) string {
str := ""
for i, v := range data {
str += fmt.Sprintf("%.4f", v.Open)
if i < len(data)-1 {
str += ","
}
}
return str
}
func getDataClose(data []FinancialData) string {
str := ""
for i, v := range data {
str += fmt.Sprintf("%.4f", v.Close)
if i < len(data)-1 {
str += ","
}
}
return str
}
func (data FinancialData) printHTMLRow(out io.Writer) {
io.WriteString(out, " ")
printCellString(data.Date, out)
printCellFloat(data.Open, out)
printCellFloat(data.High, out)
printCellFloat(data.Low, out)
printCellFloat(data.Close, out)
printCellFloat(data.Adj_Close, out)
printCellFloatFmt(data.Volume, "%f", out)
io.WriteString(out, "
\n")
}
func printCellString(val string, out io.Writer) {
io.WriteString(out, ""+val+" | ")
}
func printCellFloatFmt(val float64, format string, out io.Writer) {
io.WriteString(out, fmt.Sprintf(""+format+" | ", val))
}
func printCellFloat(val float64, out io.Writer) {
printCellFloatFmt(val, "%.2f", out)
}
func printFooter() {
fmt.Println(`