feat : update analis page
This commit is contained in:
@@ -28,8 +28,8 @@ describe("analytics source selection", () => {
|
||||
const entries = [item("shared", 2, 1), item("stygian", 0, 1)];
|
||||
const data: PublicAnalytics = {
|
||||
guides: [
|
||||
...Array.from({ length: 5 }, (_, index) => ({ id: `g${index}`, source: "guide" as const, name: `Guide ${index}` })),
|
||||
...Array.from({ length: 3 }, (_, index) => ({ id: `s${index}`, source: "stygian" as const, name: `Stygian ${index}` })),
|
||||
...Array.from({ length: 5 }, (_, index) => ({ id: `g${index}`, source: "guide" as const, name: `Guide ${index}`, character: null })),
|
||||
...Array.from({ length: 3 }, (_, index) => ({ id: `s${index}`, source: "stygian" as const, name: `Stygian ${index}`, character: null })),
|
||||
],
|
||||
teamGroups: [{ guideId: "g0", signature: "guide-team", count: 6 }, { guideId: "s0", signature: "stygian-team", count: 9 }],
|
||||
guideCount: 5, stygianScheduleCount: 3, guideTeamCount: 6, stygianTeamCount: 9,
|
||||
@@ -61,7 +61,7 @@ describe("analytics source selection", () => {
|
||||
};
|
||||
const recommendation = { ...entry, contributions: [{ guideId: "g1", teamSignature: null, count: 3 }, { guideId: "g2", teamSignature: null, count: 4 }] };
|
||||
const data: PublicAnalytics = {
|
||||
guides: [{ id: "g1", source: "guide", name: "One" }, { id: "g2", source: "guide", name: "Two" }, { id: "s1", source: "stygian", name: "Stygian" }],
|
||||
guides: [{ id: "g1", source: "guide", name: "One", character: null }, { id: "g2", source: "guide", name: "Two", character: null }, { id: "s1", source: "stygian", name: "Stygian", character: null }],
|
||||
teamGroups: [{ guideId: "g1", signature: "shared", count: 2 }, { guideId: "g2", signature: "shared", count: 1 }, { guideId: "g2", signature: "different-build", count: 1 }, { guideId: "s1", signature: "shared", count: 1 }],
|
||||
guideCount: 2, stygianScheduleCount: 1, guideTeamCount: 4, stygianTeamCount: 1,
|
||||
team: { character: [], weapon: [entry], artifact: [] }, recommendation: { weapon: [recommendation], artifact: [] },
|
||||
|
||||
@@ -15,6 +15,7 @@ export interface AnalyticsGuide {
|
||||
id: string;
|
||||
source: "guide" | "stygian";
|
||||
name: string;
|
||||
character: { key: string; imageUrl: string | null; rarity: number | null } | null;
|
||||
}
|
||||
|
||||
export interface AnalyticsTeamGroup {
|
||||
|
||||
@@ -21,6 +21,7 @@ type AggregateRow = {
|
||||
name: string | null;
|
||||
imageKey: string | null;
|
||||
rarity: number | null;
|
||||
characterKey: string | null;
|
||||
guideId: string;
|
||||
teamSignature: string | null;
|
||||
};
|
||||
@@ -30,7 +31,9 @@ type AggregateRow = {
|
||||
export async function getPublicAnalytics(): Promise<PublicAnalytics> {
|
||||
const rows = await getDb().execute<AggregateRow>(sql`
|
||||
with public_guides as (
|
||||
select g.id, g.name from ${guides} g where g.is_public = true and g.trashed_at is null
|
||||
select g.id, g.name, g.character_key as "characterKey", c.image_key, c.rarity from ${guides} g
|
||||
left join ${catalogCharacters} c on c.key = g.character_key
|
||||
where g.is_public = true and g.trashed_at is null
|
||||
), public_sections as (
|
||||
select s.guide_id, s.kind from ${guideSections} s
|
||||
join public_guides g on g.id = s.guide_id where s.enabled = true
|
||||
@@ -99,11 +102,11 @@ export async function getPublicAnalytics(): Promise<PublicAnalytics> {
|
||||
union all select 'artifact', key, name, image_key, rarity from ${catalogArtifacts}
|
||||
)
|
||||
select c.source, c.category, c.kind, c.key, c.count, i.name, i.image_key as "imageKey",
|
||||
c.guide_id as "guideId", c.signature as "teamSignature", i.rarity
|
||||
c.guide_id as "guideId", c.signature as "teamSignature", i.rarity, null::text as "characterKey"
|
||||
from counts c left join catalog i on i.kind = c.kind and i.key = c.key
|
||||
union all select 'guide', 'summary', 'guide', '', 1, name, null, 'guide:' || id, null, null from public_guides
|
||||
union all select 'stygian', 'summary', 'schedule', '', 1, challenge_name, null, 'stygian:' || schedule_id, null, null from ${stygianSchedules}
|
||||
union all select source, 'summary', 'team', '', count, null, null, guide_id, signature, null from team_groups
|
||||
union all select 'guide', 'summary', 'guide', '', 1, name, image_key, 'guide:' || id, null, rarity, "characterKey" from public_guides
|
||||
union all select 'stygian', 'summary', 'schedule', '', 1, challenge_name, null, 'stygian:' || schedule_id, null, null, null::text from ${stygianSchedules}
|
||||
union all select source, 'summary', 'team', '', count, null, null, guide_id, signature, null, null::text from team_groups
|
||||
`);
|
||||
|
||||
const data: PublicAnalytics = {
|
||||
@@ -116,7 +119,16 @@ export async function getPublicAnalytics(): Promise<PublicAnalytics> {
|
||||
for (const row of rows) {
|
||||
if (row.category === "summary") {
|
||||
if (row.kind === "guide" || row.kind === "schedule") {
|
||||
data.guides.push({ id: row.guideId, source: row.source, name: row.name ?? row.guideId });
|
||||
data.guides.push({
|
||||
id: row.guideId,
|
||||
source: row.source,
|
||||
name: row.name ?? row.guideId,
|
||||
character: row.characterKey ? {
|
||||
key: row.characterKey,
|
||||
imageUrl: row.imageKey ? publicMediaUrl(row.imageKey) : null,
|
||||
rarity: row.rarity,
|
||||
} : null,
|
||||
});
|
||||
if (row.kind === "guide") data.guideCount += row.count;
|
||||
else data.stygianScheduleCount += row.count;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user