|
|
|
@ -316,43 +316,53 @@ func convertPoolChartsResults(raw *redis.ZSliceCmd) []*PoolCharts { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (r *RedisClient) GetNetCharts(netHashLen int64) (stats []*NetCharts, err error) { |
|
|
|
func (r *RedisClient) GetNetCharts(netHashLen int64) (stats []*NetCharts, err error) { |
|
|
|
|
|
|
|
tx := r.client.Multi() |
|
|
|
tx := r.client.Multi() |
|
|
|
defer tx.Close() |
|
|
|
defer tx.Close() |
|
|
|
|
|
|
|
|
|
|
|
now := util.MakeTimestamp() / 1000 |
|
|
|
now := util.MakeTimestamp() / 1000 |
|
|
|
|
|
|
|
|
|
|
|
cmds, err := tx.Exec(func() error { |
|
|
|
cmds, err := tx.Exec(func() error { |
|
|
|
if err := tx.ZRemRangeByScore(r.formatKey("charts", "difficulty"), "-inf", fmt.Sprint("(", now-172800)).Err(); err != nil { |
|
|
|
tx.ZRemRangeByScore(r.formatKey("charts", "difficulty"), "-inf", fmt.Sprint("(", now-172800)) |
|
|
|
return err |
|
|
|
tx.ZRevRangeWithScores(r.formatKey("charts", "difficulty"), 0, netHashLen) |
|
|
|
} |
|
|
|
return nil |
|
|
|
zRangeCmd := tx.ZRevRangeWithScores(r.formatKey("charts", "difficulty"), 0, netHashLen) |
|
|
|
}) |
|
|
|
if zRangeCmd.Err() != nil { |
|
|
|
|
|
|
|
return zRangeCmd.Err() |
|
|
|
if err != nil { |
|
|
|
} |
|
|
|
return nil, err |
|
|
|
return nil |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
stats = convertNetChartsResults(cmds[1].(*redis.ZSliceCmd)) |
|
|
|
return nil, err |
|
|
|
return stats, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
zSliceCmd, ok := cmds[1].(*redis.ZSliceCmd) |
|
|
|
func convertNetChartsResults(raw *redis.ZSliceCmd) []*NetCharts { |
|
|
|
if !ok { |
|
|
|
var result []*NetCharts |
|
|
|
return nil, fmt.Errorf("invalid command result type: %T", cmds[1]) |
|
|
|
for _, v := range raw.Val() { |
|
|
|
} |
|
|
|
// "Timestamp:TimeFormat:Hash"
|
|
|
|
stats, err = convertNetChartsResults(zSliceCmd) |
|
|
|
pc := NetCharts{} |
|
|
|
if err != nil { |
|
|
|
pc.Timestamp = int64(v.Score) |
|
|
|
return nil, err |
|
|
|
str := v.Member.(string) |
|
|
|
} |
|
|
|
pc.TimeFormat = str[strings.Index(str, ":")+1 : strings.LastIndex(str, ":")] |
|
|
|
return stats, nil |
|
|
|
pc.NetHash, _ = strconv.ParseInt(str[strings.LastIndex(str, ":")+1:], 10, 64) |
|
|
|
} |
|
|
|
result = append(result, &pc) |
|
|
|
|
|
|
|
} |
|
|
|
func convertNetChartsResults(raw *redis.ZSliceCmd) ([]*NetCharts, error) { |
|
|
|
|
|
|
|
var result []*NetCharts |
|
|
|
var reverse []*NetCharts |
|
|
|
for _, v := range raw.Val() { |
|
|
|
for i := len(result) - 1; i >= 0; i-- { |
|
|
|
// "Timestamp:TimeFormat:Hash"
|
|
|
|
reverse = append(reverse, result[i]) |
|
|
|
pc := NetCharts{} |
|
|
|
} |
|
|
|
pc.Timestamp = int64(v.Score) |
|
|
|
return reverse |
|
|
|
str := v.Member.(string) |
|
|
|
|
|
|
|
pc.TimeFormat = str[strings.Index(str, ":")+1 : strings.LastIndex(str, ":")] |
|
|
|
|
|
|
|
pc.NetHash, _ = strconv.ParseInt(str[strings.LastIndex(str, ":")+1:], 10, 64) |
|
|
|
|
|
|
|
result = append(result, &pc) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var reverse []*NetCharts |
|
|
|
|
|
|
|
for i := len(result) - 1; i >= 0; i-- { |
|
|
|
|
|
|
|
reverse = append(reverse, result[i]) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return reverse, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func convertMinerChartsResults(raw *redis.ZSliceCmd) []*MinerCharts { |
|
|
|
func convertMinerChartsResults(raw *redis.ZSliceCmd) []*MinerCharts { |
|
|
|
|