Calculate netspeed points, too
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.19.0
|
||||
// sqlc v1.19.1
|
||||
|
||||
package ntpdb
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.19.0
|
||||
// sqlc v1.19.1
|
||||
|
||||
package ntpdb
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.19.0
|
||||
// sqlc v1.19.1
|
||||
// source: query.sql
|
||||
|
||||
package ntpdb
|
||||
@@ -10,6 +10,17 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const getServerNetspeed = `-- name: GetServerNetspeed :one
|
||||
select netspeed from servers where ip = ?
|
||||
`
|
||||
|
||||
func (q *Queries) GetServerNetspeed(ctx context.Context, ip string) (uint32, error) {
|
||||
row := q.db.QueryRowContext(ctx, getServerNetspeed, ip)
|
||||
var netspeed uint32
|
||||
err := row.Scan(&netspeed)
|
||||
return netspeed, err
|
||||
}
|
||||
|
||||
const getZoneStatsData = `-- name: GetZoneStatsData :many
|
||||
SELECT zc.date, z.name, zc.ip_version, count_active, count_registered, netspeed_active
|
||||
FROM zone_server_counts zc USE INDEX (date_idx)
|
||||
@@ -20,12 +31,12 @@ ORDER BY name
|
||||
`
|
||||
|
||||
type GetZoneStatsDataRow struct {
|
||||
Date time.Time `json:"date"`
|
||||
Name string `json:"name"`
|
||||
IpVersion ZoneServerCountsIpVersion `json:"ip_version"`
|
||||
CountActive uint32 `json:"count_active"`
|
||||
CountRegistered uint32 `json:"count_registered"`
|
||||
NetspeedActive uint32 `json:"netspeed_active"`
|
||||
Date time.Time `db:"date" json:"date"`
|
||||
Name string `db:"name" json:"name"`
|
||||
IpVersion ZoneServerCountsIpVersion `db:"ip_version" json:"ip_version"`
|
||||
CountActive uint32 `db:"count_active" json:"count_active"`
|
||||
CountRegistered uint32 `db:"count_registered" json:"count_registered"`
|
||||
NetspeedActive uint32 `db:"netspeed_active" json:"netspeed_active"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetZoneStatsData(ctx context.Context) ([]GetZoneStatsDataRow, error) {
|
||||
@@ -57,3 +68,59 @@ func (q *Queries) GetZoneStatsData(ctx context.Context) ([]GetZoneStatsDataRow,
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getZoneStatsV2 = `-- name: GetZoneStatsV2 :many
|
||||
select zone_name, netspeed_active+0 as netspeed_active FROM (
|
||||
SELECT
|
||||
z.name as zone_name,
|
||||
SUM(
|
||||
IF (deletion_on IS NULL AND score_raw > 10,
|
||||
netspeed,
|
||||
0
|
||||
)
|
||||
) AS netspeed_active
|
||||
FROM
|
||||
servers s
|
||||
INNER JOIN server_zones sz ON (sz.server_id = s.id)
|
||||
INNER JOIN zones z ON (z.id = sz.zone_id)
|
||||
INNER JOIN (
|
||||
select zone_id, s.ip_version
|
||||
from server_zones sz
|
||||
inner join servers s on (s.id=sz.server_id)
|
||||
where s.ip=?
|
||||
) as srvz on (srvz.zone_id=z.id AND srvz.ip_version=s.ip_version)
|
||||
WHERE
|
||||
(deletion_on IS NULL OR deletion_on > NOW())
|
||||
AND in_pool = 1
|
||||
AND netspeed > 0
|
||||
GROUP BY z.name)
|
||||
AS server_netspeed
|
||||
`
|
||||
|
||||
type GetZoneStatsV2Row struct {
|
||||
ZoneName string `db:"zone_name" json:"zone_name"`
|
||||
NetspeedActive int32 `db:"netspeed_active" json:"netspeed_active"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetZoneStatsV2(ctx context.Context, ip string) ([]GetZoneStatsV2Row, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getZoneStatsV2, ip)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []GetZoneStatsV2Row
|
||||
for rows.Next() {
|
||||
var i GetZoneStatsV2Row
|
||||
if err := rows.Scan(&i.ZoneName, &i.NetspeedActive); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user