Skip to content

[WIP] Leaderboard queries #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/Database/game/Procedures/API.LeaderboardIndy.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
----------------------------------------------------
--Production leaderboard - who produced the most type of item for some time range
--Good general CategoryFlag Names:
--cf_robots, cf_robot_equipment, cf_ammo
--Others work and allow for more specificity, curate as necessary.
--Last updated: 2019/07/02
----------------------------------------------------

IF OBJECT_ID('API.LeaderboardIndy', 'P') IS NOT NULL
DROP PROCEDURE API.LeaderboardIndy;
GO

CREATE procedure API.LeaderboardIndy
@startTime DATETIME,
@endTime DATETIME,
@cfName varchar(50),
@pageNum INT,
@pageSize INT
as

DECLARE @cfFlag BIGINT;
SET @cfFlag = (SELECT TOP 1 value FROM [perpetuumsa].[dbo].[categoryFlags] WHERE name = @cfName);

SELECT prod.characterid, c.nick, SUM(amount) as total
FROM [perpetuumsa].[dbo].[productionlog] prod
JOIN characters c on prod.characterid = c.characterID
WHERE productiontime BETWEEN @startTime AND @endTime
AND definition in (SELECT definition from entitydefaults where (categoryflags & CAST(dbo.GetCFMask(@cfFlag)as BIGINT) = @cfFlag))
GROUP BY prod.characterid, nick
ORDER BY total DESC
OFFSET @pageSize * (@pageNum - 1) ROWS
FETCH NEXT @pageSize ROWS ONLY;

GO

31 changes: 31 additions & 0 deletions src/Database/game/Procedures/API.LeaderboardPVPKill.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
----------------------------------------------------
--Most Dangerous Agents - PVP leaderboard - simple killcounts
--Last updated: 2019/07/02
----------------------------------------------------

IF OBJECT_ID('API.LeaderboardPVPKill', 'P') IS NOT NULL
DROP PROCEDURE API.LeaderboardPVPKill;
GO

CREATE procedure API.LeaderboardPVPKill
@startTime DATETIME,
@endTime DATETIME,
@pageNum INT,
@pageSize INT
as

DECLARE @accLevel INT;
SET @accLevel = 2; --normal

SELECT highscore.characterid, c.nick, SUM(playerskilled) as total
FROM [perpetuumsa].[dbo].[characterhighscore] highscore
JOIN characters c on highscore.characterid = c.characterID
WHERE DATE BETWEEN @startTime AND @endTime
AND (SELECT acclevel FROM accounts WHERE accountid=c.accountid)=@accLevel
GROUP BY highscore.characterid, nick
ORDER BY total DESC
OFFSET @pageSize * (@pageNum - 1) ROWS
FETCH NEXT @pageSize ROWS ONLY;

GO

27 changes: 27 additions & 0 deletions src/Database/game/Procedures/API.LeaderboardRawEP.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
----------------------------------------------------
--Query for Top EP earners by some time period
--Last updated: 2019/07/02
----------------------------------------------------


IF OBJECT_ID('API.LeaderboardRawEP', 'P') IS NOT NULL
DROP PROCEDURE API.LeaderboardRawEP;
GO

CREATE procedure API.LeaderboardRawEP
@startTime DATETIME,
@endTime DATETIME,
@pageNum INT,
@pageSize INT
as

SELECT el.characterid, c.nick, SUM(rawpoints) as total
FROM [perpetuumsa].[dbo].[epforactivitylog] el
JOIN characters c on el.characterid = c.characterID
WHERE eventtime > @startTime AND eventtime < @endTime
GROUP BY el.characterid, nick
ORDER BY total DESC
OFFSET @pageSize * (@pageNum - 1) ROWS
FETCH NEXT @pageSize ROWS ONLY;

GO
36 changes: 36 additions & 0 deletions src/Database/game/Procedures/API.LeaderboardRawEPByType.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
----------------------------------------------------
--Query for Top EP earners by some time period and Activity Type
--Activity Type Enum: https://github.com/OpenPerpetuum/PerpetuumServer/blob/Development/src/Perpetuum/EpForActivityType.cs
--Undefined = 0
--Gathering = 1
--Mission = 2
--Production = 3
--Artifact = 4
--Intrusion = 5
--Npc = 6
--Last updated: 2019/07/02
----------------------------------------------------

IF OBJECT_ID('API.LeaderboardEPByType', 'P') IS NOT NULL
DROP PROCEDURE API.LeaderboardEPByType;
GO

CREATE procedure API.LeaderboardEPByType
@startTime DATETIME,
@endTime DATETIME,
@activityType INT,
@pageNum INT,
@pageSize INT
as

SELECT el.characterid, c.nick, SUM(rawpoints) as total
FROM [perpetuumsa].[dbo].[epforactivitylog] el
JOIN characters c on el.characterid = c.characterID
WHERE eventtime > @startTime AND eventtime < @endTime
AND @activityType = el.epforactivitytype
GROUP BY el.characterid, nick
ORDER BY total DESC
OFFSET @pageSize * (@pageNum - 1) ROWS
FETCH NEXT @pageSize ROWS ONLY;

GO
27 changes: 27 additions & 0 deletions src/Database/game/Procedures/API.ServerStatMining.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
----------------------------------------------------
--Server Statistics: Mining
--Displays ores gathered as aggregate statistics grouped by ore definition
--Last updated: 2019/07/02
----------------------------------------------------

IF OBJECT_ID('API.ServerStatMining', 'P') IS NOT NULL
DROP PROCEDURE API.ServerStatMining;
GO

CREATE procedure API.ServerStatMining
@startTime DATETIME,
@endTime DATETIME,
@pageNum INT,
@pageSize INT
as

SELECT mine.definition, e.definitionname, SUM(amount) AS total
FROM [perpetuumsa].[dbo].[mininglog] mine
JOIN entitydefaults e ON e.definition = mine.definition
WHERE eventtime BETWEEN @startTime AND @endTime
GROUP BY mine.definition, e.definitionname
ORDER BY total DESC
OFFSET @pageSize * (@pageNum - 1) ROWS
FETCH NEXT @pageSize ROWS ONLY;

GO