pool-stats/models/models.go
2025-06-23 21:35:16 +03:00

62 lines
2.8 KiB
Go

package models
import (
"fmt"
"time"
)
type ShareLog struct {
WorkInfoID uint64 `json:"workinfoid"` // ID of the associated work unit
ClientID int `json:"clientid"` // ID of the client/miner connection
Enonce1 string `json:"enonce1"` // Extra nonce 1 (assigned by pool)
Nonce2 string `json:"nonce2"` // Extra nonce 2 (sent by miner)
Nonce string `json:"nonce"` // Nonce used to generate the solution
NTime string `json:"ntime"` // Network time used in the block
Diff float64 `json:"diff"` // Target difficulty for the share
SDiff float64 `json:"sdiff"` // Share difficulty achieved
Hash string `json:"hash"` // Resulting hash from the share
Result bool `json:"result"` // Was this share a valid result
Errn int `json:"errn"` // Error code (0 = no error)
CreateDate string `json:"createdate"` // Timestamp: "seconds,nanoseconds"
CreateBy string `json:"createby"` // Origin of share creation ("code")
CreateCode string `json:"createcode"` // Component that created this entry
CreateInet string `json:"createinet"` // IP + port of submit origin
WorkerName string `json:"workername"` // Full worker name (username.worker)
Username string `json:"username"` // User's Bitcoin address
Address string `json:"address"` // IP address of the worker
Agent string `json:"agent"` // Miner agent string (e.g., bitaxe/BM1370)
}
type TimeWindowHighShare struct {
TimeWindowID string `json:"time_window_id"` // Unique ID for the time window
TimeWindowName string `json:"time_window_name"` // Name of the time window (e.g., "Past Hour")
SDiff float64 `json:"share_diff"` // Difficulty of the highest share
Time string `json:"share_time"` // Time of the highest share
}
type DailyStats struct {
Date string `json:"date"` // Format: "2006-01-02" in UTC
ShareCount int `json:"sharecount"` // Total shares submitted that day
TopShare ShareLog `json:"topshare"` // Highest share (by SDiff)
PoolHashrate float64 `json:"poolhashrate"` // In H/s (averaged)
Workers map[string]WorkerDailyStats `json:"workers"` // key = workername
}
type WorkerDailyStats struct {
TopShare ShareLog `json:"topshare"` // Highest share by this worker
Hashrate float64 `json:"hashrate"` // avg hashrate in H/s
Shares int `json:"shares"` // shares submitted
}
// ParseCreateDate can be used to convert ShareLog.CreateDate to time.Time
func (s *ShareLog) ParseCreateDate() (time.Time, error) {
var sec, nsec int64
_, err := fmt.Sscanf(s.CreateDate, "%d,%d", &sec, &nsec)
if err != nil {
return time.Time{}, err
}
return time.Unix(sec, nsec), nil
}