Skip to content

Commit

Permalink
Maintain date type for snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcgary committed Oct 29, 2024
1 parent c9ceb78 commit 960601e
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pkg/rewards/operatorAvsRegistrationSnaphots.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ cleaned_records AS (
SELECT
operator,
avs,
to_char(d, 'YYYY-MM-DD') AS snapshot
d AS snapshot
FROM cleaned_records
CROSS JOIN generate_series(DATE(start_time), DATE(end_time) - interval '1' day, interval '1' day) AS d
`
Expand Down
3 changes: 2 additions & 1 deletion pkg/rewards/operatorAvsRegistrationSnaphots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"gorm.io/gorm"
"slices"
"testing"
"time"
)

func setupOperatorAvsRegistrationSnapshot() (
Expand Down Expand Up @@ -163,7 +164,7 @@ func Test_OperatorAvsRegistrationSnapshots(t *testing.T) {
t.Logf("Operator/AVS not found in results: %+v\n", window)
lacksExpectedResult = append(lacksExpectedResult, window)
} else {
if !slices.Contains(found, window.Snapshot) {
if !slices.Contains(found, window.Snapshot.Format(time.DateOnly)) {
t.Logf("Found operator/AVS, but no snapshot: %+v - %+v\n", window, found)
lacksExpectedResult = append(lacksExpectedResult, window)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/rewards/operatorAvsStrategySnapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ final_results as (
operator,
avs,
strategy,
to_char(d, 'YYYY-MM-DD') AS snapshot
d AS snapshot
FROM cleaned_records
CROSS JOIN generate_series(DATE(start_time), DATE(end_time) - interval '1' day, interval '1' day) AS d
)
Expand Down
3 changes: 2 additions & 1 deletion pkg/rewards/operatorAvsStrategySnapshots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"slices"
"strings"
"testing"
"time"
)

func setupOperatorAvsStrategyWindows() (
Expand Down Expand Up @@ -158,7 +159,7 @@ func Test_OperatorAvsStrategySnapshots(t *testing.T) {
t.Logf("Could not find expected result for %+v", window)
continue
}
if !slices.Contains(found, window.Snapshot) {
if !slices.Contains(found, window.Snapshot.Format(time.DateOnly)) {
t.Logf("Found result, but snapshot doesnt match: %+v - %v", window, found)
lacksExpectedResult = append(lacksExpectedResult, window)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/rewards/operatorShareSnapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ final_results as (
operator,
strategy,
shares,
cast(day AS DATE) AS snapshot
d AS snapshot
FROM
cleaned_records
CROSS JOIN
generate_series(DATE(start_time), DATE(end_time) - interval '1' day, interval '1' day) AS day
generate_series(DATE(start_time), DATE(end_time) - interval '1' day, interval '1' day) AS d
)
select * from final_results
`
Expand Down
3 changes: 2 additions & 1 deletion pkg/rewards/operatorShareSnapshots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"go.uber.org/zap"
"gorm.io/gorm"
"testing"
"time"
)

func setupOperatorShareSnapshot() (
Expand Down Expand Up @@ -129,7 +130,7 @@ func Test_OperatorShareSnapshots(t *testing.T) {
// Go line-by-line in the snapshot results and find the corresponding line in the expected results.
// If one doesnt exist, add it to the missing list.
for _, snapshot := range snapshots {
snapshotStr := snapshot.Snapshot
snapshotStr := snapshot.Snapshot.Format(time.DateOnly)

slotId := fmt.Sprintf("%s_%s_%s", snapshot.Operator, snapshot.Strategy, snapshotStr)

Expand Down
4 changes: 2 additions & 2 deletions pkg/rewards/stakerDelegationSnapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ final_results as (
SELECT
staker,
operator,
cast(day AS DATE) AS snapshot
d AS snapshot
FROM
cleaned_records
CROSS JOIN
generate_series(DATE(start_time), DATE(end_time) - interval '1' day, interval '1' day) AS day
generate_series(DATE(start_time), DATE(end_time) - interval '1' day, interval '1' day) AS d
)
select * from final_results
`
Expand Down
3 changes: 2 additions & 1 deletion pkg/rewards/stakerDelegationSnapshots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"gorm.io/gorm"
"slices"
"testing"
"time"
)

func setupStakerDelegationSnapshot() (
Expand Down Expand Up @@ -138,7 +139,7 @@ func Test_StakerDelegationSnapshots(t *testing.T) {
t.Logf("Staker/operator not found in results: %+v\n", snapshot)
lacksExpectedResult = append(lacksExpectedResult, snapshot)
} else {
if !slices.Contains(found, snapshot.Snapshot) {
if !slices.Contains(found, snapshot.Snapshot.Format(time.DateOnly)) {
t.Logf("Found staker operator, but no snapshot: %+v - %+v\n", snapshot, found)
lacksExpectedResult = append(lacksExpectedResult, snapshot)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/rewards/stakerShareSnapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ final_results as (
staker,
strategy,
shares,
cast(day AS DATE) AS snapshot
d AS snapshot
FROM
cleaned_records
CROSS JOIN
generate_series(DATE(start_time), DATE(end_time) - interval '1' day, interval '1' day) AS day
generate_series(DATE(start_time), DATE(end_time) - interval '1' day, interval '1' day) AS d
)
select * from final_results
`
Expand Down
3 changes: 2 additions & 1 deletion pkg/rewards/stakerShareSnapshots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"go.uber.org/zap"
"gorm.io/gorm"
"testing"
"time"
)

func setupStakerShareSnapshot() (
Expand Down Expand Up @@ -126,7 +127,7 @@ func Test_StakerShareSnapshots(t *testing.T) {
// Go line-by-line in the snapshot results and find the corresponding line in the expected results.
// If one doesnt exist, add it to the missing list.
for _, snapshot := range snapshots {
slotId := fmt.Sprintf("%s_%s_%s", snapshot.Staker, snapshot.Strategy, snapshot.Snapshot)
slotId := fmt.Sprintf("%s_%s_%s", snapshot.Staker, snapshot.Strategy, snapshot.Snapshot.Format(time.DateOnly))

found, ok := mappedExpectedResults[slotId]
if !ok {
Expand Down
10 changes: 5 additions & 5 deletions pkg/rewards/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,32 @@ type CombinedRewards struct {
type OperatorAvsRegistrationSnapshots struct {
Avs string
Operator string
Snapshot string
Snapshot time.Time
}

type OperatorAvsStrategySnapshot struct {
Operator string
Avs string
Strategy string
Snapshot string
Snapshot time.Time
}

type OperatorShareSnapshots struct {
Operator string
Strategy string
Shares string
Snapshot string
Snapshot time.Time
}

type StakerDelegationSnapshot struct {
Staker string
Operator string
Snapshot string
Snapshot time.Time
}

type StakerShareSnapshot struct {
Staker string
Strategy string
Snapshot string
Snapshot time.Time
Shares string
}

0 comments on commit 960601e

Please sign in to comment.