Skip to content
Merged
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
1 change: 1 addition & 0 deletions lambda/aggregator/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def process_quest(event_id: str, quest: dict, event_items: set[str]) -> None:
{
"id": report.get("id", report.get("report_id", "")),
"reporter": report.get("reporter", ""),
"reporterId": report.get("reporter_id", ""),
"reporterName": report.get("reporter_name", ""),
"runcount": report.get("runcount", 0),
"timestamp": report.get("timestamp", ""),
Expand Down
4 changes: 1 addition & 3 deletions lambda/aggregator/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

import os
import sys
from unittest.mock import MagicMock
from unittest.mock import MagicMock, patch

# boto3 はテスト環境に存在しないため、インポート前にモック化する
os.environ.setdefault("S3_BUCKET_NAME", "test-bucket")
sys.modules["boto3"] = MagicMock()
sys.modules["botocore"] = MagicMock()
sys.modules["botocore.exceptions"] = MagicMock()

from unittest.mock import patch

from handler import detect_event_items, is_raw_count_report, process_quest, transform_report # noqa: E402


Expand Down
1 change: 1 addition & 0 deletions viewer/src/aggregate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function makeReport(id: string, runcount: number, items: Record<string, number |
return {
id,
reporter: "user1",
reporterId: "",
reporterName: "User 1",
runcount,
timestamp: "2026-01-01T00:00:00Z",
Expand Down
20 changes: 10 additions & 10 deletions viewer/src/components/ReporterSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ interface Props {
exclusions: ExclusionsMap;
}

function XIdLink({
xId,
function ConditionalLink({
id,
href,
children,
}: {
xId: string;
id: string;
href: string;
children: React.ReactNode;
}) {
if (!xId || xId === "anonymous") return <>{children}</>;
if (!id || id === "anonymous") return <>{children}</>;
return (
<a href={href} target="_blank" rel="noopener noreferrer">
{children}
Expand Down Expand Up @@ -172,17 +172,17 @@ export function ReporterSummary({ eventId, quests, exclusions }: Props) {
</td>
<td style={tdStyleRight}>{i + 1}</td>
<td style={tdStyle}>
<XIdLink
xId={r.xId}
href={`https://fgodrop.max747.org/owners/${r.xId}/reports`}
<ConditionalLink
id={r.reporterId}
href={`https://fgodrop.max747.org/owners/${r.reporterId}/reports`}
>
{r.reporter}
</XIdLink>
</ConditionalLink>
</td>
<td style={tdStyle}>
<XIdLink xId={r.xId} href={`https://x.com/${r.xId}`}>
<ConditionalLink id={r.xId} href={`https://x.com/${r.xId}`}>
{r.xId}
</XIdLink>
</ConditionalLink>
</td>
<td style={tdStyleRight}>{r.reportCount.toLocaleString()}</td>
<td style={tdStyleRight}>{r.totalRuns.toLocaleString()}</td>
Expand Down
1 change: 1 addition & 0 deletions viewer/src/reportTableUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function makeReport(overrides: Partial<Report> = {}): Report {
return {
id: "r1",
reporter: "user1",
reporterId: "",
reporterName: "User 1",
runcount: 100,
timestamp: "2026-01-01T00:00:00Z",
Expand Down
41 changes: 38 additions & 3 deletions viewer/src/reporterSummaryUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ function makeQuestData(
reporter: string;
reporterName: string;
runcount: number;
reporterId?: string;
}>,
): QuestData {
return {
quest: { questId, name: questName, level: "90", ap: 40 },
lastUpdated: "2026-01-01T00:00:00Z",
reports: reports.map((r) => ({
...r,
reporterId: r.reporterId ?? "",
timestamp: "2026-01-01T00:00:00Z",
note: "",
Comment on lines 18 to 24
items: {},
Expand Down Expand Up @@ -118,13 +120,46 @@ describe("aggregateReporters", () => {
expect(rows[0].details[0].runcount).toBe(50);
expect(rows[0].details[0].reportId).toBe("r1");
});

test("reporterId を ReporterRow に伝える", () => {
const data = [
makeQuestData("q1", "Quest 1", [
{
id: "r1",
reporter: "user1",
reporterName: "User 1",
runcount: 100,
reporterId: "owner-abc",
},
]),
];
const rows = aggregateReporters(data, {});
expect(rows[0].reporterId).toBe("owner-abc");
});

test("最初の報告の reporterId が空でも後続報告の値で補完する", () => {
const data = [
makeQuestData("q1", "Quest 1", [
{ id: "r1", reporter: "user1", reporterName: "User 1", runcount: 100, reporterId: "" },
{
id: "r2",
reporter: "user1",
reporterName: "User 1",
runcount: 50,
reporterId: "owner-abc",
},
]),
];
const rows = aggregateReporters(data, {});
expect(rows[0].reporterId).toBe("owner-abc");
});
});

describe("sortRows", () => {
const rows: ReporterRow[] = [
{ reporter: "A", xId: "a", reportCount: 3, totalRuns: 100, details: [] },
{ reporter: "B", xId: "b", reportCount: 1, totalRuns: 300, details: [] },
{ reporter: "C", xId: "c", reportCount: 2, totalRuns: 200, details: [] },
{ reporter: "A", reporterId: "", xId: "a", reportCount: 3, totalRuns: 100, details: [] },
{ reporter: "B", reporterId: "", xId: "b", reportCount: 1, totalRuns: 300, details: [] },
{ reporter: "C", reporterId: "", xId: "c", reportCount: 2, totalRuns: 200, details: [] },
];

test("totalRuns 昇順", () => {
Expand Down
4 changes: 4 additions & 0 deletions viewer/src/reporterSummaryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface ReportDetail {

export interface ReporterRow {
reporter: string;
reporterId: string;
xId: string;
reportCount: number;
totalRuns: number;
Expand Down Expand Up @@ -46,11 +47,14 @@ export function aggregateReporters(
const name = getReporterName(r);
const entry = map.get(name) ?? {
reporter: name,
reporterId: r.reporterId || "",
xId: r.reporter || "",
reportCount: 0,
totalRuns: 0,
details: [],
};
if (!entry.reporterId && r.reporterId) entry.reporterId = r.reporterId;
if (!entry.xId && r.reporter) entry.xId = r.reporter;
entry.reportCount += 1;
entry.totalRuns += r.runcount;
entry.details.push({
Expand Down
1 change: 1 addition & 0 deletions viewer/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface EventsResponse {
export interface Report {
id: string;
reporter: string;
reporterId: string;
reporterName: string;
runcount: number;
timestamp: string;
Expand Down
Loading