Changes between Initial Version and Version 1 of analytics-and-statistics


Ignore:
Timestamp:
02/12/25 15:25:09 (10 days ago)
Author:
181557
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • analytics-and-statistics

    v1 v1  
     1= Advanced Database Reports (SQL Queries and Stored Procedures) =
     2
     3This page includes advanced SQL queries and stored procedures for generating reports from the *Legends of the Balkans* game database. The queries are based on the following tables:
     4
     5== 1. Player Progress Report ==
     6This query provides a summary of each player's progress—including their character details and any associated faction reputation.
     7
     8{{{
     9SELECT p.PlayerID,
     10       p.Username,
     11       c.Name AS CharacterName,
     12       c.Health,
     13       c.EXP,
     14       c.Gold,
     15       f.Name AS FactionName,
     16       r.ReputationPoints,
     17       r.Rank
     18FROM Player p
     19JOIN Character c ON p.PlayerID = c.PlayerID
     20LEFT JOIN Reputation r ON c.CharacterID = r.CharacterID
     21LEFT JOIN Faction f ON r.FactionID = f.FactionID;
     22}}}
     23
     24== 2. Faction Reputation Update After Quest Completion ==
     25The following stored procedure updates a character’s reputation for a given faction based on the EXP reward from a completed quest.
     26
     27{{{
     28CREATE OR REPLACE FUNCTION UpdateFactionReputation(
     29    char_id INT,
     30    quest_id INT,
     31    faction_id INT
     32)
     33RETURNS VOID AS
     34$$
     35DECLARE
     36    reputation_change INT;
     37BEGIN
     38    -- Get the EXP reward from the quest
     39    SELECT EXP_Reward INTO reputation_change
     40    FROM Quest
     41    WHERE QuestID = quest_id;
     42
     43    -- Update the Reputation record for the character and faction
     44    UPDATE Reputation
     45    SET ReputationPoints = ReputationPoints + reputation_change
     46    WHERE CharacterID = char_id AND FactionID = faction_id;
     47END;
     48$$ LANGUAGE plpgsql;
     49}}}
     50
     51== 3. Completed Quests Report for a Specific Player ==
     52This query retrieves the list of quests completed by a specific player. (Note: The join table *Character_Quest* contains only the CharacterID and QuestID.)
     53
     54{{{
     55SELECT p.Username,
     56       q.Name AS QuestName
     57FROM Player p
     58JOIN Character c ON p.PlayerID = c.PlayerID
     59JOIN Character_Quest cq ON c.CharacterID = cq.CharacterID
     60JOIN Quest q ON cq.QuestID = q.QuestID
     61WHERE p.PlayerID = ?;  -- Replace ? with the specific PlayerID
     62}}}
     63
     64== 4. List of Players in a Specific Faction ==
     65This query lists all players whose characters have a reputation record with a specific faction. Replace the faction name as needed.
     66
     67{{{
     68SELECT DISTINCT p.PlayerID,
     69       p.Username,
     70       c.Name AS CharacterName
     71FROM Player p
     72JOIN Character c ON p.PlayerID = c.PlayerID
     73JOIN Reputation r ON c.CharacterID = r.CharacterID
     74JOIN Faction f ON r.FactionID = f.FactionID
     75WHERE f.Name = 'Kingdom of Zeta';  -- Replace with the desired faction name
     76}}}
     77
     78== 5. Market Listings for a Specific Player ==
     79This query retrieves all items listed on the market by a specific player.
     80
     81{{{
     82SELECT m.MarketID,
     83       i.Name AS ItemName,
     84       m.Price
     85FROM Market m
     86JOIN Item i ON m.ItemID = i.ItemID
     87WHERE m.SellerID = ?;  -- Replace ? with the specific Seller's PlayerID
     88}}}
     89
     90== 6. Top Players by Total Experience and Completed Quests ==
     91This query provides a list of top players, ordered by the total EXP of all their characters and the number of quests they have completed.
     92
     93{{{
     94SELECT p.PlayerID,
     95       p.Username,
     96       SUM(c.EXP) AS TotalEXP,
     97       COUNT(cq.QuestID) AS CompletedQuests
     98FROM Player p
     99JOIN Character c ON p.PlayerID = c.PlayerID
     100LEFT JOIN Character_Quest cq ON c.CharacterID = cq.CharacterID
     101GROUP BY p.PlayerID, p.Username
     102ORDER BY TotalEXP DESC, CompletedQuests DESC;
     103}}}
     104
     105== 7. Items Owned by a Specific Player ==
     106This query lists the items owned by a specific player's characters.
     107
     108{{{
     109SELECT p.Username,
     110       i.Name AS ItemName
     111FROM Player p
     112JOIN Character c ON p.PlayerID = c.PlayerID
     113JOIN Character_Item ci ON c.CharacterID = ci.CharacterID
     114JOIN Item i ON ci.ItemID = i.ItemID
     115WHERE p.PlayerID = ?;  -- Replace ? with the specific PlayerID
     116}}}
     117
     118== 8. Items Listed in the Market ==
     119This query retrieves all items currently listed on the market along with seller information.
     120
     121{{{
     122SELECT m.MarketID,
     123       i.Name AS ItemName,
     124       m.Price,
     125       p.Username AS Seller
     126FROM Market m
     127JOIN Item i ON m.ItemID = i.ItemID
     128JOIN Player p ON m.SellerID = p.PlayerID;
     129}}}
     130
     131== 9. List of Guilds and Their Leaders ==
     132This query lists all guilds along with the username of their leader.
     133
     134{{{
     135SELECT g.GuildID,
     136       g.Name AS GuildName,
     137       p.Username AS LeaderName
     138FROM Guild g
     139JOIN Player p ON g.LeaderID = p.PlayerID;
     140}}}
     141
     142== 10. Characters in Guilds ==
     143This query retrieves characters that belong to guilds, along with their guild name.
     144
     145{{{
     146SELECT p.Username,
     147       c.Name AS CharacterName,
     148       g.Name AS GuildName
     149FROM Character_Guild cg
     150JOIN Character c ON cg.CharacterID = c.CharacterID
     151JOIN Player p ON c.PlayerID = p.PlayerID
     152JOIN Guild g ON cg.GuildID = g.GuildID;
     153}}}