Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
admin-backend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Odysseus
admin-backend
Commits
572ac87f
Commit
572ac87f
authored
May 10, 2024
by
brent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
midify client api
parent
7c694525
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
417 additions
and
108 deletions
+417
-108
.DS_Store
.DS_Store
+0
-0
app.conf
conf/app.conf
+1
-0
client.go
controllers/client.go
+280
-57
explorer.go
controllers/explorer.go
+19
-15
task.go
controllers/task.go
+31
-7
cronjob.go
libs/cronjob/cronjob.go
+2
-4
client.go
models/client.go
+65
-9
task.go
models/task.go
+19
-16
No files found.
.DS_Store
View file @
572ac87f
No preview for this file type
conf/app.conf
View file @
572ac87f
...
@@ -7,6 +7,7 @@ sessiongcmaxlifetime = 127800
...
@@ -7,6 +7,7 @@ sessiongcmaxlifetime = 127800
logLevel
=
7
logLevel
=
7
logfile
=
"admin_backend.log"
logfile
=
"admin_backend.log"
debitTime
=
"0 46 15 * * ?"
debitTime
=
"0 46 15 * * ?"
rewardUrl
=
"http://18.167.203.17:20012"
;
01
01
00
* * ?
;
01
01
00
* * ?
;
SessionProvider
=
"redis"
;
SessionProvider
=
"redis"
;
SessionProviderConfig
=
"192.168.1.10:6379,1000"
;
SessionProviderConfig
=
"192.168.1.10:6379,1000"
...
...
controllers/client.go
View file @
572ac87f
...
@@ -6,10 +6,14 @@ import (
...
@@ -6,10 +6,14 @@ import (
"ai_developer_admin/libs/postgres"
"ai_developer_admin/libs/postgres"
"ai_developer_admin/libs/registry"
"ai_developer_admin/libs/registry"
"ai_developer_admin/models"
"ai_developer_admin/models"
"bytes"
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"github.com/beego/beego/orm"
"github.com/beego/beego/orm"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/core/logs"
beego
"github.com/beego/beego/v2/server/web"
"io"
"math/big"
"net/http"
"net/http"
"strconv"
"strconv"
"time"
"time"
...
@@ -47,8 +51,8 @@ func (server *ClientController) GlobalStatistics() {
...
@@ -47,8 +51,8 @@ func (server *ClientController) GlobalStatistics() {
workload
:=
int64
(
0
)
workload
:=
int64
(
0
)
if
len
(
taskCount
)
>
0
{
if
len
(
taskCount
)
>
0
{
task
:=
taskCount
[
0
]
task
:=
taskCount
[
0
]
count
,
_
=
strconv
.
ParseInt
(
task
.
Count
,
10
,
64
)
count
=
task
.
Count
workload
,
_
=
strconv
.
ParseInt
(
task
.
Workload
,
10
,
64
)
workload
=
task
.
Workload
}
}
_
,
total
,
_
:=
registry
.
NodeManagersByPage
(
0
,
10
)
_
,
total
,
_
:=
registry
.
NodeManagersByPage
(
0
,
10
)
...
@@ -165,7 +169,7 @@ func (server *ClientController) TasksPerDay() {
...
@@ -165,7 +169,7 @@ func (server *ClientController) TasksPerDay() {
From
(
"bills"
)
From
(
"bills"
)
queryQB
,
_
:=
orm
.
NewQueryBuilder
(
"mysql"
)
queryQB
,
_
:=
orm
.
NewQueryBuilder
(
"mysql"
)
queryQB
.
Select
(
"count(*)
,sum(workload) AS
workload"
,
"sum(exec_duration) AS exec_duration"
,
"time"
)
.
queryQB
.
Select
(
"count(*)
AS total_tasks"
,
"sum(workload) AS total_
workload"
,
"sum(exec_duration) AS exec_duration"
,
"time"
)
.
From
(
"bills"
)
From
(
"bills"
)
if
appRequest
.
WorkerAcc
!=
""
{
if
appRequest
.
WorkerAcc
!=
""
{
...
@@ -255,7 +259,7 @@ func (server *ClientController) GlobalTasksPerDay() {
...
@@ -255,7 +259,7 @@ func (server *ClientController) GlobalTasksPerDay() {
From
(
"bills"
)
From
(
"bills"
)
queryQB
,
_
:=
orm
.
NewQueryBuilder
(
"mysql"
)
queryQB
,
_
:=
orm
.
NewQueryBuilder
(
"mysql"
)
queryQB
.
Select
(
"count(*)
,sum(workload) AS
workload"
,
"sum(exec_duration) AS exec_duration"
,
"time"
)
.
queryQB
.
Select
(
"count(*)
AS total_tasks,sum(workload) AS total_
workload"
,
"sum(exec_duration) AS exec_duration"
,
"time"
)
.
From
(
"bills"
)
From
(
"bills"
)
//if appRequest.WorkerAcc != "" {
//if appRequest.WorkerAcc != "" {
...
@@ -319,7 +323,50 @@ func (server *ClientController) GlobalTasksPerDay() {
...
@@ -319,7 +323,50 @@ func (server *ClientController) GlobalTasksPerDay() {
server
.
respond
(
http
.
StatusOK
,
""
,
responseData
)
server
.
respond
(
http
.
StatusOK
,
""
,
responseData
)
}
}
func
(
server
*
ClientController
)
TaskRevenue
()
{
func
getWeiPerWorkload
(
dates
[]
string
)
([]
models
.
WeiPerWorkloadStruct
,
error
)
{
host
,
_
:=
beego
.
AppConfig
.
String
(
"rewardUrl"
)
url
:=
host
+
"/api/v1/workload"
payload
:=
new
(
bytes
.
Buffer
)
json
.
NewEncoder
(
payload
)
.
Encode
(
dates
)
resp
,
err
:=
http
.
Post
(
url
,
"application/json;charset=UTF-8"
,
payload
)
if
err
!=
nil
{
logs
.
Info
(
"Error sending request:"
,
err
)
return
nil
,
err
}
defer
resp
.
Body
.
Close
()
logs
.
Info
(
"getWeiPerWorkload resp code"
,
resp
.
StatusCode
)
body
,
err
:=
io
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
logs
.
Info
(
"Error reading response:"
,
err
)
return
nil
,
err
}
var
response
models
.
WeiPerWorkloadResponse
if
err
:=
json
.
Unmarshal
(
body
,
&
response
);
err
!=
nil
{
logs
.
Info
(
"Error Unmarshal response:"
,
err
)
return
nil
,
err
}
return
response
.
Data
,
nil
}
func
contains
(
arr
[]
string
,
target
string
)
bool
{
for
_
,
item
:=
range
arr
{
if
item
==
target
{
return
true
}
}
return
false
}
func
weiToAGI
(
wei
*
big
.
Int
)
*
big
.
Float
{
weiInAGI
:=
new
(
big
.
Float
)
.
SetInt
(
big
.
NewInt
(
1000000000000000000
))
// 10^18
// 将 Wei 转换为 ETH,除以 10^18
agi
:=
new
(
big
.
Float
)
.
Quo
(
new
(
big
.
Float
)
.
SetInt
(
wei
),
weiInAGI
)
return
agi
}
func
(
server
*
ClientController
)
TaskReward
()
{
body
:=
server
.
Ctx
.
Input
.
RequestBody
body
:=
server
.
Ctx
.
Input
.
RequestBody
appRequest
:=
models
.
AppRequest
{}
appRequest
:=
models
.
AppRequest
{}
err
:=
json
.
Unmarshal
(
body
,
&
appRequest
)
//解析body中数据
err
:=
json
.
Unmarshal
(
body
,
&
appRequest
)
//解析body中数据
...
@@ -334,8 +381,8 @@ func (server *ClientController) TaskRevenue() {
...
@@ -334,8 +381,8 @@ func (server *ClientController) TaskRevenue() {
offset
:=
(
appRequest
.
Page
-
1
)
*
appRequest
.
Size
offset
:=
(
appRequest
.
Page
-
1
)
*
appRequest
.
Size
size
:=
appRequest
.
Page
*
appRequest
.
Size
size
:=
appRequest
.
Page
*
appRequest
.
Size
if
appRequest
.
WorkerAcc
==
""
&&
appRequest
.
ProfitAcc
==
""
{
if
appRequest
.
ProfitAcc
==
""
{
server
.
respond
(
models
.
MissingParameter
,
"
At least one of worker_acc or profit_acc needs to be passed
."
)
server
.
respond
(
models
.
MissingParameter
,
"
Missing profit_acc
."
)
return
return
}
}
...
@@ -347,18 +394,10 @@ func (server *ClientController) TaskRevenue() {
...
@@ -347,18 +394,10 @@ func (server *ClientController) TaskRevenue() {
queryQB
.
Select
(
"id"
,
"type"
,
"time"
,
"workload"
,
"profit_acc"
,
"worker_acc"
)
.
queryQB
.
Select
(
"id"
,
"type"
,
"time"
,
"workload"
,
"profit_acc"
,
"worker_acc"
)
.
From
(
"bills"
)
From
(
"bills"
)
if
appRequest
.
WorkerAcc
!=
""
{
if
appRequest
.
ProfitAcc
!=
""
{
countQB
.
Where
(
fmt
.
Sprintf
(
"worker_acc = '%s'"
,
appRequest
.
WorkerAcc
))
queryQB
.
Where
(
fmt
.
Sprintf
(
"worker_acc = '%s'"
,
appRequest
.
WorkerAcc
))
}
if
appRequest
.
ProfitAcc
!=
""
&&
appRequest
.
WorkerAcc
==
""
{
countQB
.
Where
(
fmt
.
Sprintf
(
"profit_acc = '%s'"
,
appRequest
.
ProfitAcc
))
countQB
.
Where
(
fmt
.
Sprintf
(
"profit_acc = '%s'"
,
appRequest
.
ProfitAcc
))
queryQB
.
Where
(
fmt
.
Sprintf
(
"profit_acc = '%s'"
,
appRequest
.
ProfitAcc
))
queryQB
.
Where
(
fmt
.
Sprintf
(
"profit_acc = '%s'"
,
appRequest
.
ProfitAcc
))
}
}
if
appRequest
.
ProfitAcc
!=
""
&&
appRequest
.
WorkerAcc
!=
""
{
countQB
.
And
(
fmt
.
Sprintf
(
"profit_acc = '%s'"
,
appRequest
.
ProfitAcc
))
queryQB
.
And
(
fmt
.
Sprintf
(
"profit_acc = '%s'"
,
appRequest
.
ProfitAcc
))
}
if
appRequest
.
StartTime
!=
""
&&
appRequest
.
EndTime
!=
""
{
if
appRequest
.
StartTime
!=
""
&&
appRequest
.
EndTime
!=
""
{
temp
,
_
:=
time
.
Parse
(
layout
,
appRequest
.
StartTime
)
temp
,
_
:=
time
.
Parse
(
layout
,
appRequest
.
StartTime
)
...
@@ -376,7 +415,7 @@ func (server *ClientController) TaskRevenue() {
...
@@ -376,7 +415,7 @@ func (server *ClientController) TaskRevenue() {
return
return
}
}
logs
.
Debug
(
"total = %d"
,
total
)
logs
.
Debug
(
"total = %d"
,
total
)
var
responseTasks
[]
models
.
Bill
s
var
responseTasks
[]
*
models
.
Revenue
s
if
total
==
0
{
if
total
==
0
{
responseData
:=
struct
{
responseData
:=
struct
{
Total
int64
`json:"total"`
Total
int64
`json:"total"`
...
@@ -397,40 +436,96 @@ func (server *ClientController) TaskRevenue() {
...
@@ -397,40 +436,96 @@ func (server *ClientController) TaskRevenue() {
return
return
}
}
for
_
,
task
:=
range
data
{
groupedItems
:=
make
(
map
[
string
][]
*
models
.
Revenues
)
//apiPath := ""
//model := ""
// 遍历对象数组,按照日期进行分组
var
dates
[]
string
for
_
,
item
:=
range
data
{
// 将日期转换为当天的 0 点
date
:=
time
.
Date
(
item
.
Time
.
Year
(),
item
.
Time
.
Month
(),
item
.
Time
.
Day
(),
0
,
0
,
0
,
0
,
time
.
UTC
)
// 将 item 添加到对应日期的分组中
key
:=
date
.
Format
(
"2006-01-02"
)
if
!
contains
(
dates
,
key
)
{
dates
=
append
(
dates
,
key
)
}
baseModel
:=
""
baseModel
:=
""
//kind := 1
typeDe
:=
1
typeDe
:=
1
taskId
,
err
:=
strconv
.
Atoi
(
task
.
Type
)
taskId
:=
item
.
Type
if
err
==
nil
{
if
err
==
nil
{
taskType
,
_
:=
odysseus
.
GetTaskType
(
int64
(
taskId
))
taskType
,
_
:=
odysseus
.
GetTaskType
(
int64
(
taskId
))
if
taskType
!=
nil
{
if
taskType
!=
nil
{
//apiPath = taskType.ApiPath
//model = taskType.Model
baseModel
=
taskType
.
BaseModel
baseModel
=
taskType
.
BaseModel
//kind = taskType.Kind
typeDe
=
taskType
.
Type
typeDe
=
taskType
.
Type
}
}
}
}
reTask
:=
&
models
.
Revenues
{
reTask
:=
models
.
Bills
{
Id
:
item
.
Id
,
Id
:
task
.
Id
,
Type
:
models
.
ModelType
(
typeDe
)
.
String
(),
Type
:
models
.
ModelType
(
typeDe
)
.
String
(),
Time
:
item
.
Time
,
Time
:
task
.
Time
,
//Result: task.Result,
//ApiPath: apiPath,
//Model: model,
BaseModel
:
baseModel
,
BaseModel
:
baseModel
,
//Kind: models.TaskKind(kind).EnString(),
Workload
:
item
.
Workload
,
//Desc: desc,
ProfitAcc
:
item
.
ProfitAcc
,
Workload
:
task
.
Workload
,
ProfitAcc
:
task
.
ProfitAcc
,
//WorkerAcc: task.WorkerAcc,
}
}
responseTasks
=
append
(
responseTasks
,
reTask
)
responseTasks
=
append
(
responseTasks
,
reTask
)
groupedItems
[
key
]
=
append
(
groupedItems
[
key
],
reTask
)
}
wei
,
err
:=
getWeiPerWorkload
(
dates
)
//wei := []models.WeiPerWorkloadStruct{
// {
// Date: "2024-05-08",
// WeiPerWorkload: "1000000000000",
// Workload: "1000",
// Reward: "10000",
// },
//}
for
_
,
value
:=
range
wei
{
bills
:=
groupedItems
[
value
.
Date
]
for
_
,
item
:=
range
bills
{
workload
:=
big
.
NewInt
(
item
.
Workload
)
weiPerWorkload
,
_
:=
strconv
.
Atoi
(
value
.
WeiPerWorkload
)
weiPerWorkloadBig
:=
big
.
NewInt
(
int64
(
weiPerWorkload
))
incomeWei
:=
new
(
big
.
Int
)
.
Mul
(
workload
,
weiPerWorkloadBig
)
income
:=
weiToAGI
(
incomeWei
)
item
.
Income
=
income
}
}
}
//for _, task := range data {
// //apiPath := ""
// //model := ""
// baseModel := ""
// //kind := 1
// typeDe := 1
// taskId, err := strconv.Atoi(task.Type)
// if err == nil {
// taskType, _ := odysseus.GetTaskType(int64(taskId))
// if taskType != nil {
// //apiPath = taskType.ApiPath
// //model = taskType.Model
// baseModel = taskType.BaseModel
// //kind = taskType.Kind
// typeDe = taskType.Type
// }
// }
//
// reTask := models.Bills{
// Id: task.Id,
// Type: models.ModelType(typeDe).String(),
// Time: task.Time,
// //Result: task.Result,
// //ApiPath: apiPath,
// //Model: model,
// BaseModel: baseModel,
// //Kind: models.TaskKind(kind).EnString(),
// //Desc: desc,
// Workload: task.Workload,
// ProfitAcc: task.ProfitAcc,
// //WorkerAcc: task.WorkerAcc,
// }
// responseTasks = append(responseTasks, reTask)
//}
responseData
:=
struct
{
responseData
:=
struct
{
Total
int64
`json:"total"`
Total
int64
`json:"total"`
Data
interface
{}
`json:"data,omitempty"`
Data
interface
{}
`json:"data,omitempty"`
...
@@ -484,7 +579,7 @@ func (server *ClientController) AddressByIP() {
...
@@ -484,7 +579,7 @@ func (server *ClientController) AddressByIP() {
server
.
respond
(
http
.
StatusOK
,
""
,
address
)
server
.
respond
(
http
.
StatusOK
,
""
,
address
)
}
}
func
(
server
*
ClientController
)
RevenuePerDay
()
{
func
(
server
*
ClientController
)
IncomeRecord
()
{
body
:=
server
.
Ctx
.
Input
.
RequestBody
body
:=
server
.
Ctx
.
Input
.
RequestBody
appRequest
:=
models
.
AppRequest
{}
appRequest
:=
models
.
AppRequest
{}
...
@@ -500,39 +595,35 @@ func (server *ClientController) RevenuePerDay() {
...
@@ -500,39 +595,35 @@ func (server *ClientController) RevenuePerDay() {
offset
:=
(
appRequest
.
Page
-
1
)
*
appRequest
.
Size
offset
:=
(
appRequest
.
Page
-
1
)
*
appRequest
.
Size
size
:=
appRequest
.
Page
*
appRequest
.
Size
size
:=
appRequest
.
Page
*
appRequest
.
Size
if
appRequest
.
WorkerAcc
==
""
&&
appRequest
.
ProfitAcc
==
""
{
if
appRequest
.
ProfitAcc
==
""
{
server
.
respond
(
models
.
MissingParameter
,
"
At least one of worker_acc or profit_acc needs to be passed
."
)
server
.
respond
(
models
.
MissingParameter
,
"
Missing profit_acc
."
)
return
return
}
}
countQB
,
_
:=
orm
.
NewQueryBuilder
(
"mysql"
)
countQB
,
_
:=
orm
.
NewQueryBuilder
(
"mysql"
)
countQB
.
Select
(
"count(*)"
)
.
countQB
.
Select
(
"count(*)"
)
.
From
(
"
revenue
s"
)
From
(
"
bill
s"
)
queryQB
,
_
:=
orm
.
NewQueryBuilder
(
"mysql"
)
queryQB
,
_
:=
orm
.
NewQueryBuilder
(
"mysql"
)
queryQB
.
Select
(
"
*
"
)
.
queryQB
.
Select
(
"
sum(workload) AS workload"
,
"time
"
)
.
From
(
"
revenue
s"
)
From
(
"
bill
s"
)
if
appRequest
.
WorkerAcc
!=
""
{
countQB
.
Where
(
fmt
.
Sprintf
(
"worker_acc = '%s'"
,
appRequest
.
WorkerAcc
))
queryQB
.
Where
(
fmt
.
Sprintf
(
"worker_acc = '%s'"
,
appRequest
.
WorkerAcc
))
}
if
appRequest
.
ProfitAcc
!=
""
{
if
appRequest
.
ProfitAcc
!=
""
{
countQB
.
Where
(
fmt
.
Sprintf
(
"profit_acc = '%s'"
,
appRequest
.
ProfitAcc
))
countQB
.
Where
(
fmt
.
Sprintf
(
"profit_acc = '%s'"
,
appRequest
.
ProfitAcc
))
queryQB
.
Where
(
fmt
.
Sprintf
(
"profit_acc = '%s'"
,
appRequest
.
ProfitAcc
))
queryQB
.
Where
(
fmt
.
Sprintf
(
"profit_acc = '%s'"
,
appRequest
.
ProfitAcc
))
}
}
//sql := fmt.Sprintf("%s SAMPLE BY 1M
ALIGN TO CALENDAR", countQB.String())
sql
:=
fmt
.
Sprintf
(
"%s SAMPLE BY 1d
ALIGN TO CALENDAR"
,
countQB
.
String
())
//
sql = fmt.Sprintf("SELECT count(*) FROM (%s);", sql)
sql
=
fmt
.
Sprintf
(
"SELECT count(*) FROM (%s);"
,
sql
)
sql
:=
countQB
.
String
()
//
sql := countQB.String()
total
,
err
:=
postgres
.
QueryTotal
(
sql
)
total
,
err
:=
postgres
.
QueryTotal
(
sql
)
if
err
!=
nil
{
if
err
!=
nil
{
server
.
respond
(
models
.
BusinessFailed
,
err
.
Error
())
server
.
respond
(
models
.
BusinessFailed
,
err
.
Error
())
return
return
}
}
logs
.
Debug
(
"total = %d"
,
total
)
logs
.
Debug
(
"total = %d"
,
total
)
var
responseTasks
[]
interface
{}
var
responseTasks
[]
*
models
.
Revenues
if
total
==
0
{
if
total
==
0
{
responseData
:=
struct
{
responseData
:=
struct
{
Total
int64
`json:"total"`
Total
int64
`json:"total"`
...
@@ -545,20 +636,152 @@ func (server *ClientController) RevenuePerDay() {
...
@@ -545,20 +636,152 @@ func (server *ClientController) RevenuePerDay() {
return
return
}
}
queryQB
.
OrderBy
(
"time"
)
.
Desc
()
//
queryQB.OrderBy("time").Desc()
//sql = fmt.Sprintf("%s SAMPLE BY 1M ALIGN TO CALENDAR
LIMIT %d,%d;", queryQB.String(), offset, size)
sql
=
fmt
.
Sprintf
(
"%s SAMPLE BY 1d ALIGN TO CALENDAR ORDER BY time DESC
LIMIT %d,%d;"
,
queryQB
.
String
(),
offset
,
size
)
sql
=
fmt
.
Sprintf
(
"%s LIMIT %d,%d;"
,
queryQB
.
String
(),
offset
,
size
)
//
sql = fmt.Sprintf("%s LIMIT %d,%d;", queryQB.String(), offset, size)
revenues
,
err
:=
postgres
.
Query
Revenue
s
(
sql
)
revenues
,
err
:=
postgres
.
Query
Bill
s
(
sql
)
if
err
!=
nil
{
if
err
!=
nil
{
server
.
respond
(
models
.
BusinessFailed
,
err
.
Error
())
server
.
respond
(
models
.
BusinessFailed
,
err
.
Error
())
return
return
}
}
groupedItems
:=
make
(
map
[
string
][]
*
models
.
Revenues
)
// 遍历对象数组,按照日期进行分组
var
dates
[]
string
for
_
,
item
:=
range
revenues
{
// 将日期转换为当天的 0 点
date
:=
time
.
Date
(
item
.
Time
.
Year
(),
item
.
Time
.
Month
(),
item
.
Time
.
Day
(),
0
,
0
,
0
,
0
,
time
.
UTC
)
// 将 item 添加到对应日期的分组中
key
:=
date
.
Format
(
"2006-01-02"
)
if
!
contains
(
dates
,
key
)
{
dates
=
append
(
dates
,
key
)
}
reTask
:=
&
models
.
Revenues
{
Id
:
item
.
Id
,
Type
:
"Work income"
,
Time
:
item
.
Time
,
Workload
:
item
.
Workload
,
}
responseTasks
=
append
(
responseTasks
,
reTask
)
groupedItems
[
key
]
=
append
(
groupedItems
[
key
],
reTask
)
}
wei
,
err
:=
getWeiPerWorkload
(
dates
)
//wei := []models.WeiPerWorkloadStruct{
// {
// Date: "2024-05-08",
// WeiPerWorkload: "1000000000000",
// Workload: "1000",
// Reward: "10000",
// },
//}
for
_
,
value
:=
range
wei
{
bills
:=
groupedItems
[
value
.
Date
]
for
_
,
item
:=
range
bills
{
workload
:=
big
.
NewInt
(
item
.
Workload
)
weiPerWorkload
,
_
:=
strconv
.
Atoi
(
value
.
WeiPerWorkload
)
weiPerWorkloadBig
:=
big
.
NewInt
(
int64
(
weiPerWorkload
))
incomeWei
:=
new
(
big
.
Int
)
.
Mul
(
workload
,
weiPerWorkloadBig
)
income
:=
weiToAGI
(
incomeWei
)
item
.
Income
=
income
}
}
responseData
:=
struct
{
responseData
:=
struct
{
Total
int64
`json:"total"`
Total
int64
`json:"total"`
Data
interface
{}
`json:"data,omitempty"`
Data
interface
{}
`json:"data,omitempty"`
}{
}{
Total
:
total
,
Total
:
total
,
Data
:
re
venue
s
,
Data
:
re
sponseTask
s
,
}
}
server
.
respond
(
http
.
StatusOK
,
""
,
responseData
)
server
.
respond
(
http
.
StatusOK
,
""
,
responseData
)
}
}
func
(
server
*
ClientController
)
TotalReward
()
{
requestBody
:=
server
.
Ctx
.
Input
.
RequestBody
appRequest
:=
models
.
AppRequest
{}
err
:=
json
.
Unmarshal
(
requestBody
,
&
appRequest
)
//解析body中数据
logs
.
Debug
(
"appRequest"
,
appRequest
)
if
appRequest
.
ProfitAcc
==
""
{
server
.
respond
(
models
.
MissingParameter
,
"Missing profit_acc."
)
return
}
host
,
_
:=
beego
.
AppConfig
.
String
(
"rewardUrl"
)
url
:=
host
+
"/api/v1/reward"
requestJaon
:=
models
.
TotalRevenuesRequest
{
Address
:
appRequest
.
ProfitAcc
,
}
payload
:=
new
(
bytes
.
Buffer
)
json
.
NewEncoder
(
payload
)
.
Encode
(
requestJaon
)
resp
,
err
:=
http
.
Post
(
url
,
"application/json;charset=UTF-8"
,
payload
)
if
err
!=
nil
{
logs
.
Info
(
"Error sending request:"
,
err
)
server
.
respond
(
models
.
BusinessFailed
,
err
.
Error
())
return
}
defer
resp
.
Body
.
Close
()
logs
.
Info
(
"TotalReward resp code"
,
resp
.
StatusCode
)
body
,
err
:=
io
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
logs
.
Info
(
"Error reading response:"
,
err
)
server
.
respond
(
models
.
BusinessFailed
,
err
.
Error
())
return
}
var
response
models
.
TotalRevenuesResponse
if
err
:=
json
.
Unmarshal
(
body
,
&
response
);
err
!=
nil
{
server
.
respond
(
models
.
BusinessFailed
,
err
.
Error
())
return
}
server
.
respond
(
http
.
StatusOK
,
""
,
response
.
Data
)
}
func
(
server
*
ClientController
)
WithdrawalRecord
()
{
requestBody
:=
server
.
Ctx
.
Input
.
RequestBody
appRequest
:=
models
.
AppRequest
{}
err
:=
json
.
Unmarshal
(
requestBody
,
&
appRequest
)
//解析body中数据
logs
.
Debug
(
"appRequest"
,
appRequest
)
if
appRequest
.
Page
==
0
{
appRequest
.
Page
=
1
}
if
appRequest
.
Size
==
0
{
appRequest
.
Size
=
10
}
if
appRequest
.
ProfitAcc
==
""
{
server
.
respond
(
models
.
MissingParameter
,
"Missing profit_acc."
)
return
}
host
,
_
:=
beego
.
AppConfig
.
String
(
"rewardUrl"
)
url
:=
host
+
"/api/v1/record"
payload
:=
new
(
bytes
.
Buffer
)
requestJson
:=
models
.
WithdrawalRecordRequest
{
Address
:
appRequest
.
ProfitAcc
,
Page
:
int
(
appRequest
.
Page
),
PageSize
:
int
(
appRequest
.
Size
),
}
json
.
NewEncoder
(
payload
)
.
Encode
(
requestJson
)
resp
,
err
:=
http
.
Post
(
url
,
"application/json;charset=UTF-8"
,
payload
)
if
err
!=
nil
{
logs
.
Info
(
"Error sending request:"
,
err
)
server
.
respond
(
models
.
BusinessFailed
,
err
.
Error
())
return
}
defer
resp
.
Body
.
Close
()
logs
.
Info
(
"getWeiPerWorkload resp code"
,
resp
.
StatusCode
)
body
,
err
:=
io
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
logs
.
Info
(
"Error reading response:"
,
err
)
server
.
respond
(
models
.
BusinessFailed
,
err
.
Error
())
return
}
var
response
models
.
WithdrawalRecordResponse
if
err
:=
json
.
Unmarshal
(
body
,
&
response
);
err
!=
nil
{
server
.
respond
(
models
.
BusinessFailed
,
err
.
Error
())
return
}
server
.
respond
(
http
.
StatusOK
,
""
,
response
.
Data
)
}
controllers/explorer.go
View file @
572ac87f
...
@@ -11,7 +11,7 @@ import (
...
@@ -11,7 +11,7 @@ import (
"github.com/beego/beego/orm"
"github.com/beego/beego/orm"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/core/logs"
"net/http"
"net/http"
"
strconv
"
"
time
"
)
)
type
ExplorerController
struct
{
type
ExplorerController
struct
{
...
@@ -46,8 +46,8 @@ func (server *ExplorerController) Statistics() {
...
@@ -46,8 +46,8 @@ func (server *ExplorerController) Statistics() {
workload
:=
int64
(
0
)
workload
:=
int64
(
0
)
if
len
(
taskCount
)
>
0
{
if
len
(
taskCount
)
>
0
{
task
:=
taskCount
[
0
]
task
:=
taskCount
[
0
]
count
,
_
=
strconv
.
ParseInt
(
task
.
Count
,
10
,
64
)
count
=
task
.
Count
workload
,
_
=
strconv
.
ParseInt
(
task
.
Workload
,
10
,
64
)
workload
=
task
.
Workload
}
}
_
,
total
,
_
:=
registry
.
NodeManagersByPage
(
0
,
10
)
_
,
total
,
_
:=
registry
.
NodeManagersByPage
(
0
,
10
)
...
@@ -162,7 +162,16 @@ func (server *ExplorerController) Tasks() {
...
@@ -162,7 +162,16 @@ func (server *ExplorerController) Tasks() {
return
return
}
}
logs
.
Debug
(
"total = %d"
,
total
)
logs
.
Debug
(
"total = %d"
,
total
)
var
responseTasks
[]
models
.
Bills
type
ResponseBills
struct
{
Id
string
`json:"id,omitempty"`
Type
string
`json:"type,omitempty"`
ProfitAcc
string
`json:"profit_acc,omitempty"`
Result
string
`json:"result,omitempty"`
Workload
int64
`json:"workload,omitempty"`
Time
time
.
Time
`json:"time,omitempty"`
BaseModel
string
`json:"base_model,omitempty"`
}
var
responseTasks
[]
ResponseBills
if
total
==
0
{
if
total
==
0
{
responseData
:=
struct
{
responseData
:=
struct
{
Total
int64
`json:"total"`
Total
int64
`json:"total"`
...
@@ -189,7 +198,7 @@ func (server *ExplorerController) Tasks() {
...
@@ -189,7 +198,7 @@ func (server *ExplorerController) Tasks() {
baseModel
:=
""
baseModel
:=
""
//kind := 1
//kind := 1
typeDe
:=
1
typeDe
:=
1
taskId
,
err
:=
strconv
.
Atoi
(
task
.
Type
)
taskId
:=
task
.
Type
if
err
==
nil
{
if
err
==
nil
{
taskType
,
_
:=
odysseus
.
GetTaskType
(
int64
(
taskId
))
taskType
,
_
:=
odysseus
.
GetTaskType
(
int64
(
taskId
))
if
taskType
!=
nil
{
if
taskType
!=
nil
{
...
@@ -201,19 +210,14 @@ func (server *ExplorerController) Tasks() {
...
@@ -201,19 +210,14 @@ func (server *ExplorerController) Tasks() {
}
}
}
}
reTask
:=
models
.
Bills
{
reTask
:=
ResponseBills
{
Id
:
task
.
Id
,
Id
:
task
.
Id
,
Type
:
models
.
ModelType
(
typeDe
)
.
String
(),
Type
:
models
.
ModelType
(
typeDe
)
.
String
(),
Time
:
task
.
Time
,
Time
:
task
.
Time
,
Result
:
task
.
Result
,
Result
:
task
.
Result
,
//ApiPath: apiPath,
//Model: model,
BaseModel
:
baseModel
,
BaseModel
:
baseModel
,
//Kind: models.TaskKind(kind).EnString(),
//Desc: desc,
Workload
:
task
.
Workload
,
Workload
:
task
.
Workload
,
ProfitAcc
:
task
.
ProfitAcc
,
ProfitAcc
:
task
.
ProfitAcc
,
//WorkerAcc: task.WorkerAcc,
}
}
responseTasks
=
append
(
responseTasks
,
reTask
)
responseTasks
=
append
(
responseTasks
,
reTask
)
}
}
...
...
controllers/task.go
View file @
572ac87f
...
@@ -183,7 +183,16 @@ func (server *TaskController) BillDetails() {
...
@@ -183,7 +183,16 @@ func (server *TaskController) BillDetails() {
return
return
}
}
logs
.
Debug
(
"total = %d"
,
total
)
logs
.
Debug
(
"total = %d"
,
total
)
var
responseTasks
[]
models
.
Bills
type
ResponseBills
struct
{
Id
string
`json:"id,omitempty"`
Type
string
`json:"type,omitempty"`
Fee
string
`json:"fee,omitempty"`
Result
string
`json:"result,omitempty"`
Time
time
.
Time
`json:"time,omitempty"`
ApiPath
string
`json:"api_path,omitempty"`
Desc
string
`json:"desc,omitempty"`
}
var
responseTasks
[]
ResponseBills
if
total
==
0
{
if
total
==
0
{
responseData
:=
struct
{
responseData
:=
struct
{
Total
int64
`json:"total"`
Total
int64
`json:"total"`
...
@@ -208,7 +217,7 @@ func (server *TaskController) BillDetails() {
...
@@ -208,7 +217,7 @@ func (server *TaskController) BillDetails() {
apiPath
:=
""
apiPath
:=
""
desc
:=
""
desc
:=
""
typeDesc
:=
""
typeDesc
:=
""
taskId
,
err
:=
strconv
.
Atoi
(
task
.
Type
)
taskId
:=
task
.
Type
if
err
==
nil
{
if
err
==
nil
{
taskType
,
err1
:=
odysseus
.
GetTaskType
(
int64
(
taskId
))
taskType
,
err1
:=
odysseus
.
GetTaskType
(
int64
(
taskId
))
if
err1
==
nil
{
if
err1
==
nil
{
...
@@ -220,7 +229,7 @@ func (server *TaskController) BillDetails() {
...
@@ -220,7 +229,7 @@ func (server *TaskController) BillDetails() {
//balance, _ := odysseus.GetUserBalance(int64(token.UserID))
//balance, _ := odysseus.GetUserBalance(int64(token.UserID))
reTask
:=
models
.
Bills
{
reTask
:=
Response
Bills
{
Id
:
task
.
Id
,
Id
:
task
.
Id
,
Type
:
typeDesc
,
Type
:
typeDesc
,
Fee
:
task
.
Fee
,
Fee
:
task
.
Fee
,
...
@@ -306,7 +315,22 @@ func (server *TaskController) Tasks() {
...
@@ -306,7 +315,22 @@ func (server *TaskController) Tasks() {
return
return
}
}
logs
.
Debug
(
"total = %d"
,
total
)
logs
.
Debug
(
"total = %d"
,
total
)
var
responseTasks
[]
models
.
Bills
type
ResponseBills
struct
{
Id
string
`json:"id,omitempty"`
Type
string
`json:"type,omitempty"`
Fee
string
`json:"fee,omitempty"`
Result
string
`json:"result,omitempty"`
Time
time
.
Time
`json:"time,omitempty"`
ApiPath
string
`json:"api_path,omitempty"`
Desc
string
`json:"desc,omitempty"`
BaseModel
string
`json:"base_model,omitempty"`
Model
string
`json:"model,omitempty"`
ProfitAcc
string
`json:"profit_acc,omitempty"`
WorkerAcc
string
`json:"worker_acc,omitempty"`
Workload
int64
`json:"workload,omitempty"`
Kind
string
`json:"kind,omitempty"`
}
var
responseTasks
[]
ResponseBills
if
total
==
0
{
if
total
==
0
{
responseData
:=
struct
{
responseData
:=
struct
{
Total
int64
`json:"total"`
Total
int64
`json:"total"`
...
@@ -333,7 +357,7 @@ func (server *TaskController) Tasks() {
...
@@ -333,7 +357,7 @@ func (server *TaskController) Tasks() {
baseModel
:=
""
baseModel
:=
""
kind
:=
1
kind
:=
1
typeDe
:=
1
typeDe
:=
1
taskId
,
err
:=
strconv
.
Atoi
(
task
.
Type
)
taskId
:=
task
.
Type
if
err
==
nil
{
if
err
==
nil
{
taskType
,
_
:=
odysseus
.
GetTaskType
(
int64
(
taskId
))
taskType
,
_
:=
odysseus
.
GetTaskType
(
int64
(
taskId
))
if
taskType
!=
nil
{
if
taskType
!=
nil
{
...
@@ -345,7 +369,7 @@ func (server *TaskController) Tasks() {
...
@@ -345,7 +369,7 @@ func (server *TaskController) Tasks() {
}
}
}
}
reTask
:=
models
.
Bills
{
reTask
:=
Response
Bills
{
Id
:
task
.
Id
,
Id
:
task
.
Id
,
Type
:
models
.
ModelType
(
typeDe
)
.
String
(),
Type
:
models
.
ModelType
(
typeDe
)
.
String
(),
Time
:
task
.
Time
,
Time
:
task
.
Time
,
...
@@ -581,7 +605,7 @@ func (server *TaskController) UserTasks() {
...
@@ -581,7 +605,7 @@ func (server *TaskController) UserTasks() {
for
_
,
task
:=
range
tasks
{
for
_
,
task
:=
range
tasks
{
apiPath
:=
""
apiPath
:=
""
desc
:=
""
desc
:=
""
taskId
,
err
:=
strconv
.
Atoi
(
task
.
Type
)
taskId
:=
task
.
Type
if
err
==
nil
{
if
err
==
nil
{
taskType
,
err1
:=
odysseus
.
GetTaskType
(
int64
(
taskId
))
taskType
,
err1
:=
odysseus
.
GetTaskType
(
int64
(
taskId
))
if
err1
==
nil
{
if
err1
==
nil
{
...
...
libs/cronjob/cronjob.go
View file @
572ac87f
...
@@ -305,12 +305,10 @@ func startRevenue() {
...
@@ -305,12 +305,10 @@ func startRevenue() {
for
_
,
bill
:=
range
data
{
for
_
,
bill
:=
range
data
{
workload
,
_
:=
strconv
.
Atoi
(
bill
.
Workload
)
//nanoseconds := int64(uint64(dayTime.UnixNano()))
//nanoseconds := int64(uint64(dayTime.UnixNano()))
//seconds := nanoseconds / 1e9
//seconds := nanoseconds / 1e9
taskId
,
err
:=
strconv
.
Atoi
(
bill
.
Type
)
taskId
:=
bill
.
Type
typeDesc
:=
""
typeDesc
:=
""
baseModel
:=
""
baseModel
:=
""
if
err
==
nil
{
if
err
==
nil
{
...
@@ -327,7 +325,7 @@ func startRevenue() {
...
@@ -327,7 +325,7 @@ func startRevenue() {
Symbol
(
"base_model"
,
baseModel
)
.
Symbol
(
"base_model"
,
baseModel
)
.
Symbol
(
"profit_acc"
,
bill
.
ProfitAcc
)
.
Symbol
(
"profit_acc"
,
bill
.
ProfitAcc
)
.
Symbol
(
"worker_acc"
,
bill
.
WorkerAcc
)
.
Symbol
(
"worker_acc"
,
bill
.
WorkerAcc
)
.
Int64Column
(
"workload"
,
int64
(
workload
)
)
.
Int64Column
(
"workload"
,
bill
.
Workload
)
.
Int64Column
(
"income"
,
int64
(
0
))
.
Int64Column
(
"income"
,
int64
(
0
))
.
TimestampColumn
(
"time"
,
bill
.
Time
)
.
TimestampColumn
(
"time"
,
bill
.
Time
)
.
AtNow
(
ctx
)
AtNow
(
ctx
)
...
...
models/client.go
View file @
572ac87f
package
models
package
models
import
"time"
import
(
"math/big"
"time"
)
type
Revenues
struct
{
type
Revenues
struct
{
Id
string
`json:"id";orm:"column(id)"`
Id
string
`json:"id,omitempty";orm:"column(id)"`
Time
time
.
Time
`json:"time";orm:"column(time);type(datetime)"`
Time
time
.
Time
`json:"time,omitempty";orm:"column(time);type(datetime)"`
Type
string
`json:"type";orm:"column(type)"`
Type
string
`json:"type,omitempty";orm:"column(type)"`
BaseModel
string
`json:"base_model";orm:"column(base_model)"`
BaseModel
string
`json:"base_model,omitempty";orm:"column(base_model)"`
ProfitAcc
string
`json:"profit_acc";orm:"column(profit_acc)"`
ProfitAcc
string
`json:"profit_acc,omitempty";orm:"column(profit_acc)"`
WorkerAcc
string
`json:"worker_acc";orm:"column(worker_acc)"`
WorkerAcc
string
`json:"worker_acc,omitempty";orm:"column(worker_acc)"`
Workload
int
`json:"workload";orm:"column(workload)"`
Workload
int64
`json:"workload,omitempty";orm:"column(workload)"`
Income
int64
`json:"income";orm:"column(income)"`
Income
*
big
.
Float
`json:"income,omitempty";orm:"column(income)"`
}
type
WeiPerWorkloadStruct
struct
{
Date
string
`json:"date,omitempty"`
WeiPerWorkload
string
`json:"weiPerWorkload,omitempty"`
Workload
string
`json:"workload,omitempty"`
Reward
string
`json:"reward,omitempty"`
}
type
WeiPerWorkloadResponse
struct
{
Code
int
`json:"code,omitempty"`
Msg
string
`json:"msg,omitempty"`
Data
[]
WeiPerWorkloadStruct
`json:"data,omitempty"`
}
type
TotalRevenuesRequest
struct
{
Address
string
`json:"address,omitempty"`
}
type
TotalRevenuesStruct
struct
{
Total
string
`json:"total"`
Claimed
string
`json:"claimed"`
Unclaimed
string
`json:"unclaimed"`
}
type
TotalRevenuesResponse
struct
{
Code
int
`json:"code"`
Msg
string
`json:"msg"`
Data
TotalRevenuesStruct
`json:"data"`
}
type
WithdrawalRecordRequest
struct
{
Address
string
`json:"address,omitempty"`
Page
int
`json:"page,omitempty"`
PageSize
int
`json:"pageSize,omitempty"`
}
type
WithdrawalRecordStruct
struct
{
TxHash
string
`json:"txHash"`
Date
string
`json:"date"`
Timestamp
int
`json:"timestamp"`
Amount
string
`json:"amount"`
}
type
WithdrawalRecordData
struct
{
TotalCount
int
`json:"totalCount"`
Records
[]
WithdrawalRecordStruct
`json:"records"`
}
type
WithdrawalRecordResponse
struct
{
Code
int
`json:"code"`
Msg
string
`json:"msg"`
Data
WithdrawalRecordData
`json:"data"`
}
}
models/task.go
View file @
572ac87f
...
@@ -217,27 +217,30 @@ type ResonseModel struct {
...
@@ -217,27 +217,30 @@ type ResonseModel struct {
type
Bills
struct
{
type
Bills
struct
{
//Key int `orm:"column(key);auto"`
//Key int `orm:"column(key);auto"`
Id
string
`json:"id,omitempty";orm:"column(id)"`
Id
string
`json:"id,omitempty";orm:"column(id)"`
Type
string
`json:"type,omitempty";orm:"column(type)"`
Type
int
`json:"type,omitempty";orm:"column(type)"`
Kind
string
`json:"kind,omitempty"`
Kind
int
`json:"kind,omitempty"`
Uid
string
`json:"uid,omitempty";orm:"column(uid)"`
Uid
int
`json:"uid,omitempty";orm:"column(uid)"`
ProfitAcc
string
`json:"profit_acc,omitempty";orm:"column(profit_acc)"`
ProfitAcc
string
`json:"profit_acc,omitempty";orm:"column(profit_acc)"`
Fee
string
`json:"fee,omitempty";orm:"column(fee)"`
Fee
string
`json:"fee,omitempty";orm:"column(fee)"`
WorkerAcc
string
`json:"worker_acc,omitempty";orm:"column(worker_acc)"`
WorkerAcc
string
`json:"worker_acc,omitempty";orm:"column(worker_acc)"`
Result
string
`json:"result,omitempty";orm:"column(result)"`
Result
string
`json:"result,omitempty";orm:"column(result)"`
Workload
string
`json:"workload,omitempty";orm:"column(workload)"`
Workload
int64
`json:"workload,omitempty";orm:"column(workload)"`
//ApiPath string `json:"api_path";orm:"column(api_path)"`
//ApiPath string `json:"api_path";orm:"column(api_path)"`
Time
time
.
Time
`json:"time,omitempty";orm:"column(time);type(datetime)"`
Time
time
.
Time
`json:"time,omitempty";orm:"column(time);type(datetime)"`
TaskDuration
string
`json:"task_duration,omitempty";orm:"column(task_duration)"`
TaskDuration
string
`json:"task_duration,omitempty";orm:"column(task_duration)"`
ExecDuration
string
`json:"exec_duration,omitempty";orm:"column(exec_duration)"`
ExecDuration
string
`json:"exec_duration,omitempty";orm:"column(exec_duration)"`
OutLen
string
`json:"out_len,omitempty";orm:"column(out_len)"`
OutLen
string
`json:"out_len,omitempty";orm:"column(out_len)"`
InLen
string
`json:"in_len,omitempty";orm:"column(in_len)"`
InLen
string
`json:"in_len,omitempty";orm:"column(in_len)"`
ApiPath
string
`json:"api_path,omitempty"`
ApiPath
string
`json:"api_path,omitempty"`
Desc
string
`json:"desc,omitempty"`
Desc
string
`json:"desc,omitempty"`
TaskType
string
`json:"task_type,omitempty"`
TaskType
string
`json:"task_type,omitempty"`
Balance
int64
`json:"balance,omitempty"`
Balance
int64
`json:"balance,omitempty"`
BaseModel
string
`json:"base_model,omitempty"`
BaseModel
string
`json:"base_model,omitempty"`
Model
string
`json:"model,omitempty"`
Model
string
`json:"model,omitempty"`
Count
string
`json:"count,omitempty"`
Count
int64
`json:"count,omitempty"`
Income
float64
`json:"income,omitempty"`
TotalTasks
int64
`json:"total_tasks,omitempty"`
TotalWorkload
int64
`json:"total_workload,omitempty"`
}
}
type
TotalType
struct
{
type
TotalType
struct
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment