From 0614e303fc4085e871be885952fb3743a92b84ed Mon Sep 17 00:00:00 2001 From: Moses Narrow Date: Wed, 16 Oct 2024 14:12:50 -0500 Subject: [PATCH] updates to reward UI for second pool --- cmd/skywire-cli/commands/rewards/ui.go | 69 +++++++++++++++++--------- 1 file changed, 46 insertions(+), 23 deletions(-) diff --git a/cmd/skywire-cli/commands/rewards/ui.go b/cmd/skywire-cli/commands/rewards/ui.go index 190dd7cf38..b1aef2afec 100644 --- a/cmd/skywire-cli/commands/rewards/ui.go +++ b/cmd/skywire-cli/commands/rewards/ui.go @@ -626,10 +626,8 @@ func server() { l := fmt.Sprintf("
%s
", func() string { yearlyTotal := 408000.0 result := fmt.Sprintf("%g annual reward distribution\nReward total per month:\n", yearlyTotal) - currentMonth := time.Now().Month() currentYear := time.Now().Year() - for month := time.January; month <= time.December; month++ { daysInMonth := time.Date(currentYear, month+1, 0, 0, 0, 0, 0, time.UTC).Day() monthlyRewards := (yearlyTotal / 365) * float64(daysInMonth) @@ -639,45 +637,70 @@ func server() { } result += fmt.Sprintf(format, monthlyRewards, currentYear, month) } - firstDayOfNextYear := time.Date(currentYear+1, time.January, 1, 0, 0, 0, 0, time.UTC) lastDayOfYear := firstDayOfNextYear.Add(-time.Second) totalDaysInYear := int(lastDayOfYear.YearDay()) - skycoinPerDay := yearlyTotal / float64(totalDaysInYear) result += fmt.Sprintf("%g Skycoin per day\n

", skycoinPerDay) utstats, _ := script.Exec(`skywire cli ut -t`).String() //nolint - result += fmt.Sprintf("Uptime tracker version statistics:\n%s", utstats) + result += fmt.Sprintf("Uptime tracker version statistics:\n%s\n", utstats) return result + }()) l += fmt.Sprintf("There are %d days in the month of %s.\n", time.Date(time.Now().Year(), time.Now().Month()+1, 0, 0, 0, 0, 0, time.UTC).Day(), time.Now().Month()) - l += fmt.Sprintf("Today is %s %d.\n", time.Now().Month(), time.Now().Day()) - l += fmt.Sprintf("There are %d days left in the month of %s.\n", time.Date(time.Now().Year(), time.Now().Month()+1, 0, 0, 0, 0, 0, time.UTC).Day()-time.Now().Day(), time.Now().Month()) - l += fmt.Sprintf("%d days in the year %d.\n", time.Date(time.Now().Year(), time.December, 31, 0, 0, 0, 0, time.UTC).YearDay(), time.Now().Year()) - l += fmt.Sprintf("Today is day %d.\n", time.Now().YearDay()) - l += fmt.Sprintf("There are %d days remaining in %d\n", time.Date(time.Now().Year(), time.December, 31, 0, 0, 0, 0, time.UTC).YearDay()-time.Now().YearDay(), time.Now().Year()) - calendar, err := script.Exec(`bash -c 'set -o pipefail ; unbuffer cal --color | lolcat -f -F 0.5'`).String() if err != nil { calendar = cal() } l += "\n" + string(ansihtml.ConvertToHTML([]byte(calendar))) - l += "\n\nRewardDate SKY/VISOR [/]distributed\n" + l += "\n\n\n" + l += "\n\n
\n" + l += "\n" + l += "\n" + l += "\n" + l += "\n" + l += "\n" + l += "\n" rewardtxncsvs, _ := script.FindFiles(`rewards/hist`).MatchRegexp(regexp.MustCompile(".?.?.?.?-.?.?-.?.?_rewardtxn0.csv")).Replace("rewards/hist/", "").Replace("_rewardtxn0.csv", "").Slice() //nolint for i := len(rewardtxncsvs) - 1; i >= 0; i-- { - skycoinpershare, _ := script.File("rewards/hist/"+rewardtxncsvs[i]+"_stats.txt").Match("Skycoin Per Share: ").Replace("Skycoin Per Share: ", "").String() //nolint - if _, err := os.Stat("rewards/hist/" + rewardtxncsvs[i] + ".txt"); err == nil { - l += "" + rewardtxncsvs[i] + " " + strings.ReplaceAll(skycoinpershare, "\n", "") + " \n" - } else { - l += "" + rewardtxncsvs[i] + " " + strings.ReplaceAll(skycoinpershare, "\n", "") + " \n" - } - } + skycoinpershare, _ := script.File("rewards/hist/"+rewardtxncsvs[i]+"_stats.txt").Match("Skycoin Per Share: ").Replace("Skycoin Per Share: ", "").String() //nolint + skycoinpershare1 := "" + skycoinpershare2 := "" + if strings.TrimSpace(skycoinpershare) == "" { + skycoinpershare1, _ = script.File("rewards/hist/"+rewardtxncsvs[i]+"_stats.txt").Match("Skycoin Per Share (Pool 1): ").Replace("Skycoin Per Share (Pool 1): ", "").String() //nolint + skycoinpershare2, _ = script.File("rewards/hist/"+rewardtxncsvs[i]+"_stats.txt").Match("Skycoin Per Share (Pool 2): ").Replace("Skycoin Per Share (Pool 2): ", "").String() //nolint + skycoinpershare1 = strings.TrimSpace(skycoinpershare1) + skycoinpershare2 = strings.TrimSpace(skycoinpershare2) + } else { + skycoinpershare1 = strings.TrimSpace(skycoinpershare) + skycoinpershare2 = "" + } + + var distributedIcon string + if _, err := os.Stat("rewards/hist/" + rewardtxncsvs[i] + ".txt"); err == nil { + distributedIcon = "" + } else { + distributedIcon = "" + } + l += "\n" + l += "\n" + l += "\n" + if skycoinpershare2 != "" { + l += "\n" + } else { + l += "\n" + } + l += "\n" + l += "\n" + } + l += "\n

RewardDate
Pool 1
SKY/VISOR
Pool 2
SKY/VISOR
Distributed
[/]
" + rewardtxncsvs[i] + "" + skycoinpershare1 + "" + skycoinpershare2 + "" + distributedIcon + "
\n" l += "
" + htmltoplink + tmpl0, err1 := tmpl.Clone() if err1 != nil { fmt.Println("Error cloning template:", err1) @@ -691,7 +714,6 @@ func server() { Title: "Skycoin Reward Calculation and Distribution", Content: htmpl.HTML(l), //nolint } - // htmlPageTemplateData1.Content = tmplData := map[string]interface{}{ "Page": htmlPageTemplateData1, } @@ -812,9 +834,9 @@ func server() { }) r1.GET("/health", func(c *gin.Context) { runTime = time.Since(startTime) - nextrun, _ := script.Exec(`bash -c "systemctl status skywire-reward.timer --lines=0 | head -n4 | tail -n1 | sed 's/ Trigger: //g'"`).String() //nolint - prevDuration, _ := script.Exec(`bash -c "systemctl status skywire-reward.service --lines=0 | grep -m1 'Duration' | sed 's/ Duration: //g'"`).String() //nolint - active, _ := script.Exec(`systemctl is-active skywire-reward.service`).String() //nolint + nextrun, _ := script.Exec(`systemctl status skywire-reward.timer --lines=0`).First(5).Last(1).Replace(" Trigger: ", "").String() //nolint + prevDuration, _ := script.Exec(`systemctl status skywire-reward.service --lines=0`).Match("Duration").First(1).String() //nolint + active, _ := script.Exec(`systemctl is-active skywire-reward.service`).String() //nolint c.JSON(http.StatusOK, gin.H{ "frontend_start_time": startTime, "frontend_run_time": runTime.String(), @@ -1621,6 +1643,7 @@ var htmlMainPageTemplate = `