Skip to content

Commit

Permalink
remove mongodb
Browse files Browse the repository at this point in the history
  • Loading branch information
crhntr committed Dec 27, 2024
1 parent d9d78b6 commit 840316d
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 49 deletions.
8 changes: 1 addition & 7 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"os"
"strings"

"go.mongodb.org/mongo-driver/bson/primitive"

"github.com/portfoliotree/portfolio/returns"
)

Expand Down Expand Up @@ -66,11 +64,7 @@ func ParseComponentsFromURL(values url.Values, prefix string) ([]Component, erro
}
components := make([]Component, 0, len(assetValues))
for _, v := range assetValues {
if _, err := primitive.ObjectIDFromHex(v); err == nil {
components = append(components, Component{Type: "Portfolio", ID: v})
continue
}
components = append(components, Component{Type: "Security", ID: v})
components = append(components, Component{ID: v})
}
return components, nil
}
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ toolchain go1.23.3
require (
github.com/portfoliotree/round v0.1.0
github.com/stretchr/testify v1.10.0
go.mongodb.org/mongo-driver v1.17.1
gonum.org/v1/gonum v0.15.1
gopkg.in/yaml.v3 v3.0.1
)
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand All @@ -15,8 +13,6 @@ github.com/portfoliotree/round v0.1.0 h1:cgwCj64CUk262Cga+kQLFJEEnplebSeCwnlDtA3
github.com/portfoliotree/round v0.1.0/go.mod h1:sm64uU9te4vt/uRZi5Ag3LFVQtc7isrrYr2ZKWi147M=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.mongodb.org/mongo-driver v1.17.1 h1:Wic5cJIwJgSpBhe3lx3+/RybR5PiYRMpVFgO7cOHyIM=
go.mongodb.org/mongo-driver v1.17.1/go.mod h1:wwWm/+BuOddhcq3n68LKRmgk2wXzmF6s0SFOa0GINL4=
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 h1:1UoZQm6f0P/ZO0w1Ri+f+ifG/gXhegadRdwBIXEFWDo=
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c=
golang.org/x/tools v0.28.0 h1:WuB6qZ4RPCQo5aP3WdKZS7i595EdWqWR8vqJTlwTVK8=
Expand Down
3 changes: 1 addition & 2 deletions portfolio.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strings"
"time"

"go.mongodb.org/mongo-driver/bson/primitive"
"gopkg.in/yaml.v3"

"github.com/portfoliotree/portfolio/allocation"
Expand All @@ -18,7 +17,7 @@ import (
"github.com/portfoliotree/portfolio/returns"
)

type Identifier = primitive.ObjectID
type Identifier = string

type Document struct {
ID Identifier `json:"_id" yaml:"_id" bson:"_id"`
Expand Down
4 changes: 2 additions & 2 deletions returns/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ func indexOfClosest[T any](list []T, time func(T) time.Time, t time.Time) int {
if len(list) == 1 {
return 1
}
return index + indexOfClosest(list[index:], time, t)
return index + indexOfClosest[T](list[index:], time, t)
}
return indexOfClosest(list[:index], time, t)
return indexOfClosest[T](list[:index], time, t)
}

func inBounds[T any](list []T, index int) bool {
Expand Down
37 changes: 4 additions & 33 deletions returns/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"strconv"
"time"

"go.mongodb.org/mongo-driver/bson"

"github.com/portfoliotree/round"

"github.com/portfoliotree/portfolio/calculate"
Expand All @@ -38,21 +36,9 @@ func NewTable(list []List) Table {
return table
}

func (table *Table) UnmarshalBSON(buf []byte) error {
var enc encodedTable
err := bson.Unmarshal(buf, &enc)
table.times = enc.Times
table.values = enc.Values
return err
}

func (table Table) MarshalBSON() ([]byte, error) {
return bson.Marshal(newEncodedTable(table.times, table.values))
}

type encodedTable struct {
Times []time.Time `json:"times" bson:"times"`
Values [][]float64 `json:"values" bson:"values"`
Times []time.Time `json:"times"`
Values [][]float64 `json:"values"`
}

func newEncodedTable(times []time.Time, values [][]float64) encodedTable {
Expand Down Expand Up @@ -478,23 +464,8 @@ func (table Table) RangeIndexes(last, first time.Time) (end int, start int) {
}

type encodedColumnGroup struct {
Index int `json:"index" bson:"index"`
Length int `json:"length" bson:"length"`
}

func (group *ColumnGroup) UnmarshalBSON(buf []byte) error {
var ecg encodedColumnGroup
err := bson.Unmarshal(buf, &ecg)
group.index = ecg.Index
group.length = ecg.Length
return err
}

func (group ColumnGroup) MarshalBSON() ([]byte, error) {
return bson.Marshal(encodedColumnGroup{
Index: group.index,
Length: group.length,
})
Index int `json:"index"`
Length int `json:"length"`
}

func (group *ColumnGroup) UnmarshalJSON(buf []byte) error {
Expand Down

0 comments on commit 840316d

Please sign in to comment.