add prompt dir
This commit is contained in:
61
digits-work-sample-go.d/transaction.go
Normal file
61
digits-work-sample-go.d/transaction.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package analyzer
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Transaction represents a transaction from our upstream source.
|
||||
// URL: https://catalog.data.gov/dataset/purchase-card-pcard-fiscal-year-2014
|
||||
type Transaction struct {
|
||||
Category string `json:"MerchantCategory"`
|
||||
Vendor string
|
||||
Description string
|
||||
AgencyName string
|
||||
CardholderLastName string
|
||||
TransactionDate string
|
||||
Amount Amount `json:",string"`
|
||||
YearMonth string
|
||||
CardholderFirstInitial string
|
||||
AgencyNumber string
|
||||
PostedDate string
|
||||
}
|
||||
|
||||
func (trn Transaction) String() string {
|
||||
// TODO: Not implemented.
|
||||
return ""
|
||||
}
|
||||
|
||||
// Transactions represents a list of Transaction
|
||||
type Transactions []Transaction
|
||||
|
||||
// Sum adds all transactions together.
|
||||
func (trns Transactions) Sum() Amount {
|
||||
// TODO: Not implemented.
|
||||
return 0.0
|
||||
}
|
||||
|
||||
// Count is the number of unique Transactions.
|
||||
func (trns Transactions) Count() int {
|
||||
return len(trns)
|
||||
}
|
||||
|
||||
func TransactionsFromFile(path string) (Transactions, error) {
|
||||
jsonFile, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer jsonFile.Close()
|
||||
|
||||
var transactions Transactions
|
||||
if err := json.NewDecoder(jsonFile).Decode(&transactions); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return transactions, nil
|
||||
}
|
||||
|
||||
func TransactionsFromURLs(url ...string) (Transactions, error) {
|
||||
return nil, errors.New("not implemented")
|
||||
}
|
||||
Reference in New Issue
Block a user