mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-11-16 19:25:33 -06:00
Feed fixes
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
import * as R from "remeda";
|
||||
import type { BusyBlock, TimeRange } from "../availability-types";
|
||||
import { AVAILABILITY } from "../availability-constants";
|
||||
import type {
|
||||
BusyBlock,
|
||||
PlayableWindowTier,
|
||||
TimeRange,
|
||||
} from "../availability-types";
|
||||
import * as Availability from "./Availability";
|
||||
|
||||
const DAY_SECONDS = 24 * 60 * 60;
|
||||
@@ -134,3 +139,64 @@ export function memberRow({
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The players' free time in the week with commitments cut out and the playable windows it leaves,
|
||||
* needing `AVAILABILITY.DEFAULT_MIN_PLAYERS` or every player of a smaller roster.
|
||||
*/
|
||||
export function teamWindows({
|
||||
range,
|
||||
playerIds,
|
||||
reportedWeeks,
|
||||
busyByUserId,
|
||||
}: {
|
||||
range: TimeRange;
|
||||
playerIds: Array<number>;
|
||||
reportedWeeks: Array<ReportedWeek>;
|
||||
busyByUserId: Map<number, Array<BusyBlock>>;
|
||||
}) {
|
||||
const minPlayers = Math.min(
|
||||
AVAILABILITY.DEFAULT_MIN_PLAYERS,
|
||||
playerIds.length,
|
||||
);
|
||||
const members = playerIds.map((userId) => ({
|
||||
userId,
|
||||
ranges: Availability.subtract(
|
||||
Availability.clip(
|
||||
reportedWeeks
|
||||
.filter((week) => week.userId === userId)
|
||||
.flatMap((week) => week.slots),
|
||||
range,
|
||||
),
|
||||
busyByUserId.get(userId) ?? [],
|
||||
),
|
||||
}));
|
||||
|
||||
return {
|
||||
members,
|
||||
minPlayers,
|
||||
windows: Availability.playableWindows({ members, minPlayers }),
|
||||
};
|
||||
}
|
||||
|
||||
/** Tier of the best playable window starting on the viewer-local day (the day it renders its grid ranges on). */
|
||||
export function bestWindowTierOfDay({
|
||||
date,
|
||||
windows,
|
||||
timezone,
|
||||
}: {
|
||||
date: string;
|
||||
windows: Array<TimeRange & { tier: PlayableWindowTier }>;
|
||||
timezone: string;
|
||||
}): PlayableWindowTier | null {
|
||||
const tiers = windows
|
||||
.filter(
|
||||
(window) =>
|
||||
Availability.dateInTimezone(window.startsAt, timezone) === date,
|
||||
)
|
||||
.map((window) => window.tier);
|
||||
|
||||
if (tiers.includes("FULL")) return "FULL";
|
||||
if (tiers.includes("ONE_SHORT")) return "ONE_SHORT";
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -11,11 +11,7 @@ import type { SerializeFrom } from "~/utils/remix";
|
||||
import { notFoundIfNullish, parseParams } from "~/utils/remix.server";
|
||||
import * as AvailabilityRepository from "../AvailabilityRepository.server";
|
||||
import { AVAILABILITY } from "../availability-constants";
|
||||
import type {
|
||||
BusyBlock,
|
||||
PlayableWindowTier,
|
||||
TimeRange,
|
||||
} from "../availability-types";
|
||||
import type { BusyBlock, TimeRange } from "../availability-types";
|
||||
import * as Availability from "../core/Availability";
|
||||
import * as ScheduleWeek from "../core/ScheduleWeek";
|
||||
import * as VisibleSchedules from "../core/VisibleSchedules.server";
|
||||
@@ -104,26 +100,12 @@ function weekView({
|
||||
busyByUserId: Map<number, Array<BusyBlock>>;
|
||||
teamEvents: Array<TeamEventRow>;
|
||||
}) {
|
||||
const minPlayers = Math.min(
|
||||
AVAILABILITY.DEFAULT_MIN_PLAYERS,
|
||||
playerIds.length,
|
||||
);
|
||||
|
||||
const windows = Availability.playableWindows({
|
||||
members: playerIds.map((userId) => ({
|
||||
userId,
|
||||
ranges: Availability.subtract(
|
||||
Availability.clip(
|
||||
reportedWeeks
|
||||
.filter((week) => week.userId === userId)
|
||||
.flatMap((week) => week.slots),
|
||||
range,
|
||||
),
|
||||
busyByUserId.get(userId) ?? [],
|
||||
),
|
||||
})),
|
||||
minPlayers,
|
||||
}).map((window) => R.omit(window, ["userIds"]));
|
||||
const { minPlayers, windows } = ScheduleWeek.teamWindows({
|
||||
range,
|
||||
playerIds,
|
||||
reportedWeeks,
|
||||
busyByUserId,
|
||||
});
|
||||
|
||||
const days = ScheduleWeek.days(range, timezone).map((day) => ({
|
||||
...day,
|
||||
@@ -133,7 +115,11 @@ function weekView({
|
||||
time: "00:00",
|
||||
timezone,
|
||||
}),
|
||||
windowTier: bestWindowTierOfDay({ date: day.date, windows, timezone }),
|
||||
windowTier: ScheduleWeek.bestWindowTierOfDay({
|
||||
date: day.date,
|
||||
windows,
|
||||
timezone,
|
||||
}),
|
||||
}));
|
||||
|
||||
const members = memberIds.map((userId) =>
|
||||
@@ -154,7 +140,7 @@ function weekView({
|
||||
timezone,
|
||||
days,
|
||||
members,
|
||||
windows,
|
||||
windows: windows.map((window) => R.omit(window, ["userIds"])),
|
||||
minPlayers,
|
||||
teamEvents: teamEvents.filter(
|
||||
(event) =>
|
||||
@@ -162,25 +148,3 @@ function weekView({
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
/** Tier of the best playable window starting on the viewer-local day (the day it renders its grid ranges on). */
|
||||
function bestWindowTierOfDay({
|
||||
date,
|
||||
windows,
|
||||
timezone,
|
||||
}: {
|
||||
date: string;
|
||||
windows: Array<TimeRange & { tier: PlayableWindowTier }>;
|
||||
timezone: string;
|
||||
}): PlayableWindowTier | null {
|
||||
const tiers = windows
|
||||
.filter(
|
||||
(window) =>
|
||||
Availability.dateInTimezone(window.startsAt, timezone) === date,
|
||||
)
|
||||
.map((window) => window.tier);
|
||||
|
||||
if (tiers.includes("FULL")) return "FULL";
|
||||
if (tiers.includes("ONE_SHORT")) return "ONE_SHORT";
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -133,6 +133,15 @@ export function findAllSqPlaysByUserId(userId: number) {
|
||||
"GroupMatch.createdAt as at",
|
||||
"Skill.season",
|
||||
"Skill.ordinal",
|
||||
eb
|
||||
.selectFrom("Skill as PreviousSkill")
|
||||
.select("PreviousSkill.ordinal")
|
||||
.whereRef("PreviousSkill.userId", "=", "Skill.userId")
|
||||
.whereRef("PreviousSkill.season", "=", "Skill.season")
|
||||
.whereRef("PreviousSkill.id", "<", "Skill.id")
|
||||
.orderBy("PreviousSkill.id", "desc")
|
||||
.limit(1)
|
||||
.as("previousOrdinal"),
|
||||
"OwnGroup.tierName as ownTierName",
|
||||
"OwnGroup.tierIsPlus as ownTierIsPlus",
|
||||
"OpponentGroup.tierName as opponentTierName",
|
||||
|
||||
@@ -299,7 +299,8 @@ export function findTopTeammatesByUserId(userId: number) {
|
||||
.execute();
|
||||
}
|
||||
|
||||
export function findWeaponUsageCounts({
|
||||
/** How many maps each player played on each weapon in SendouQ matches created in `[from, to)` */
|
||||
export function findWeaponPicksByUser({
|
||||
from,
|
||||
to,
|
||||
}: {
|
||||
@@ -310,12 +311,13 @@ export function findWeaponUsageCounts({
|
||||
.selectFrom("ReportedWeapon")
|
||||
.innerJoin("GroupMatch", "GroupMatch.id", "ReportedWeapon.groupMatchId")
|
||||
.select(({ fn }) => [
|
||||
"ReportedWeapon.userId",
|
||||
"ReportedWeapon.weaponSplId",
|
||||
fn.countAll<number>().as("count"),
|
||||
])
|
||||
.where("GroupMatch.createdAt", ">", from)
|
||||
.where("GroupMatch.createdAt", ">=", from)
|
||||
.where("GroupMatch.createdAt", "<", to)
|
||||
.groupBy("ReportedWeapon.weaponSplId")
|
||||
.groupBy(["ReportedWeapon.userId", "ReportedWeapon.weaponSplId"])
|
||||
.execute();
|
||||
}
|
||||
|
||||
@@ -1248,36 +1250,6 @@ export function findLatestAddedUpcomingTeamEvent({
|
||||
.executeTakeFirst();
|
||||
}
|
||||
|
||||
export function findAvailabilitySlotsOfTeamWeek({
|
||||
teamId,
|
||||
weekStartsAt,
|
||||
}: {
|
||||
teamId: number;
|
||||
weekStartsAt: number;
|
||||
}) {
|
||||
return db
|
||||
.selectFrom("AvailabilitySlot")
|
||||
.innerJoin(
|
||||
"AvailabilityWeek",
|
||||
"AvailabilityWeek.id",
|
||||
"AvailabilitySlot.availabilityWeekId",
|
||||
)
|
||||
.innerJoin(
|
||||
"AllTeamMember",
|
||||
"AllTeamMember.userId",
|
||||
"AvailabilityWeek.userId",
|
||||
)
|
||||
.select([
|
||||
"AvailabilityWeek.userId",
|
||||
"AvailabilitySlot.startsAt",
|
||||
"AvailabilitySlot.endsAt",
|
||||
])
|
||||
.where("AllTeamMember.teamId", "=", teamId)
|
||||
.where("AllTeamMember.leftAt", "is", null)
|
||||
.where("AvailabilityWeek.weekStartsAt", "=", weekStartsAt)
|
||||
.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Team scrim posts still open for requests at `now` that the viewer can see or has requested: not
|
||||
* canceled, nothing accepted, not started yet ("looking now" posts until `lookingNowFrom`). Posts the
|
||||
|
||||
@@ -32,6 +32,10 @@
|
||||
aspect-ratio: 16 / 9;
|
||||
object-fit: cover;
|
||||
border-radius: max(2px, calc(var(--radius-box) - var(--s-2)));
|
||||
|
||||
@container (width < 400px) {
|
||||
width: 72px;
|
||||
}
|
||||
}
|
||||
|
||||
.rotationStageOff {
|
||||
|
||||
@@ -164,6 +164,7 @@ export function communityItemContent(
|
||||
) : null}
|
||||
</>
|
||||
),
|
||||
href: plusSuggestionPage({ tier: data.tier }),
|
||||
};
|
||||
}
|
||||
case "ARTICLE_NEW": {
|
||||
@@ -247,7 +248,7 @@ export function communityItemContent(
|
||||
key={`${rotation.type}-${rotation.startsAt}`}
|
||||
className={styles.rotationRow}
|
||||
>
|
||||
<div>
|
||||
<div className="whitespace-nowrap">
|
||||
<div className="text-sm font-semi-bold">
|
||||
<LocaleTime
|
||||
inline
|
||||
@@ -265,7 +266,11 @@ export function communityItemContent(
|
||||
"text-xs text-lighter",
|
||||
)}
|
||||
>
|
||||
<ModeImage mode={rotation.mode} size={16} />
|
||||
<ModeImage
|
||||
mode={rotation.mode}
|
||||
size={16}
|
||||
containerClassName={partsStyles.noShrink}
|
||||
/>
|
||||
{rotationTypeLabel(rotation.type)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -11,7 +11,7 @@ import { smallImageFileName, vodVideoPage } from "~/utils/urls";
|
||||
import type { FeedItem } from "../core/FeedItems.server";
|
||||
import styles from "./CreatorItems.module.css";
|
||||
import type { FeedItemContent } from "./FeedItemCard";
|
||||
import { countText, LogoAvatar, UserName } from "./FeedParts";
|
||||
import { countText, UnknownWeaponImage, UserName } from "./FeedParts";
|
||||
import partsStyles from "./FeedParts.module.css";
|
||||
|
||||
export function creatorItemContent(item: FeedItem): FeedItemContent | null {
|
||||
@@ -108,7 +108,7 @@ export function creatorItemContent(item: FeedItem): FeedItemContent | null {
|
||||
case "VOD_NEW": {
|
||||
const { data } = item;
|
||||
return {
|
||||
avatar: <LogoAvatar url={null} name={data.title} />,
|
||||
avatar: <Avatar user={data.submitter} size="xs" />,
|
||||
line: (
|
||||
<>
|
||||
New {data.type.toLowerCase()} VoD:{" "}
|
||||
@@ -158,6 +158,7 @@ export function creatorItemContent(item: FeedItem): FeedItemContent | null {
|
||||
</div>
|
||||
</>
|
||||
),
|
||||
href: vodVideoPage(data.videoId),
|
||||
};
|
||||
}
|
||||
case "XRANK_TOP_500": {
|
||||
@@ -258,9 +259,16 @@ export function creatorItemContent(item: FeedItem): FeedItemContent | null {
|
||||
variant="build"
|
||||
size={22}
|
||||
/>
|
||||
) : null}
|
||||
) : (
|
||||
<UnknownWeaponImage size={22} />
|
||||
)}
|
||||
</td>
|
||||
<td className={partsStyles.ellipsis}>
|
||||
<td
|
||||
className={clsx(
|
||||
partsStyles.ellipsis,
|
||||
partsStyles.fillCell,
|
||||
)}
|
||||
>
|
||||
{player.name ?? "?"}
|
||||
</td>
|
||||
<td className={partsStyles.numeric}>
|
||||
|
||||
@@ -27,15 +27,12 @@ export function Feed({
|
||||
canViewAs = false,
|
||||
headerEnd,
|
||||
footer,
|
||||
scoreShown = false,
|
||||
}: {
|
||||
data: FeedPageData;
|
||||
/** Dev only: lets the feed of any user be picked */
|
||||
canViewAs?: boolean;
|
||||
headerEnd?: React.ReactNode;
|
||||
footer?: React.ReactNode;
|
||||
/** Shows how each post's ranking score was calculated */
|
||||
scoreShown?: boolean;
|
||||
}) {
|
||||
const [tabParam, setTabParam] = useSearchParam(feedSearchParams, "tab");
|
||||
const [viewAs] = useSearchParam(feedSearchParams, "viewAs");
|
||||
@@ -54,7 +51,7 @@ export function Feed({
|
||||
return definition.category === filter;
|
||||
});
|
||||
|
||||
const card = (item: FeedItem, score?: ScoreBreakdown) => (
|
||||
const card = (item: FeedItem, score?: ScoreBreakdown | null) => (
|
||||
<FeedItemCard
|
||||
key={item.id}
|
||||
item={item}
|
||||
@@ -107,9 +104,7 @@ export function Feed({
|
||||
))}
|
||||
</nav>
|
||||
{filter === "ALL" ? data.pinned.map((item) => card(item)) : null}
|
||||
{activity.map((item) =>
|
||||
card(item, scoreShown ? item.score : undefined),
|
||||
)}
|
||||
{activity.map((item) => card(item, item.score))}
|
||||
<div className={styles.caughtUp}>
|
||||
<CircleCheck size={32} className={styles.caughtUpIcon} />
|
||||
All caught up!
|
||||
|
||||
@@ -78,6 +78,7 @@
|
||||
display: grid;
|
||||
gap: var(--s-1-5);
|
||||
min-width: 0;
|
||||
container-type: inline-size;
|
||||
}
|
||||
|
||||
.meta {
|
||||
@@ -140,6 +141,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
@container (width < 400px) {
|
||||
.feedbackLabel {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.text {
|
||||
margin: 0;
|
||||
font-size: 0.95rem;
|
||||
@@ -161,6 +168,7 @@
|
||||
|
||||
.postAction {
|
||||
justify-self: start;
|
||||
margin-top: var(--s-1);
|
||||
}
|
||||
|
||||
.actions {
|
||||
@@ -207,15 +215,21 @@
|
||||
}
|
||||
|
||||
.math {
|
||||
margin-bottom: var(--s-2);
|
||||
padding: var(--s-1-5) var(--s-2);
|
||||
display: grid;
|
||||
gap: var(--s-1-5);
|
||||
font-family: monospace;
|
||||
font-size: var(--font-2xs);
|
||||
color: var(--color-text-high);
|
||||
background-color: var(--color-bg-high);
|
||||
border-radius: var(--radius-field);
|
||||
font-size: var(--font-xs);
|
||||
|
||||
& b {
|
||||
color: var(--color-fg-accent);
|
||||
}
|
||||
}
|
||||
|
||||
.mathTable {
|
||||
border-collapse: collapse;
|
||||
|
||||
& td {
|
||||
padding: var(--s-0-5) var(--s-1);
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import clsx from "clsx";
|
||||
import {
|
||||
Calculator,
|
||||
EyeOff,
|
||||
Heart,
|
||||
MessageCircle,
|
||||
@@ -13,6 +14,7 @@ import * as React from "react";
|
||||
import { Link, useNavigate } from "react-router";
|
||||
import { SendouButton } from "~/components/elements/Button";
|
||||
import { SendouMenu, SendouMenuItem } from "~/components/elements/Menu";
|
||||
import { SendouPopover } from "~/components/elements/Popover";
|
||||
import { toastQueue } from "~/components/elements/Toast";
|
||||
import { Image } from "~/components/Image";
|
||||
import { useUser } from "~/features/auth/core/user";
|
||||
@@ -92,7 +94,8 @@ const FEED_FEEDBACK_OPTIONS: Record<
|
||||
|
||||
const FROM_FEED_STATE: FeedItemPageState = { fromFeed: true };
|
||||
|
||||
const INTERACTIVE_SELECTOR = "a, button, input, label, [role='menuitem']";
|
||||
const INTERACTIVE_SELECTOR =
|
||||
"a, button, input, label, [role='menuitem'], [role='dialog']";
|
||||
|
||||
export function FeedItemCard({
|
||||
item,
|
||||
@@ -112,7 +115,8 @@ export function FeedItemCard({
|
||||
href?: string;
|
||||
/** Shown at the end of the header line, e.g. a back link on the post page */
|
||||
headerAction?: React.ReactNode;
|
||||
score?: ScoreBreakdown;
|
||||
/** Ranking score breakdown, shown in a popover */
|
||||
score?: ScoreBreakdown | null;
|
||||
}) {
|
||||
const navigate = useNavigate();
|
||||
const definition: FeedItemTypeDefinition = FEED_ITEM_TYPES[item.type];
|
||||
@@ -192,6 +196,13 @@ export function FeedItemCard({
|
||||
<span>{relativeTime(item.at, now)}</span>
|
||||
)}
|
||||
<div className={styles.metaEnd}>
|
||||
{score ? (
|
||||
<ScorePopover
|
||||
score={score}
|
||||
definition={definition}
|
||||
relation={item.relation}
|
||||
/>
|
||||
) : null}
|
||||
<FeedbackMenu onFeedback={(kind) => sendFeedback(kind, null)} />
|
||||
{headerAction ? (
|
||||
<div className={styles.headerAction}>{headerAction}</div>
|
||||
@@ -211,13 +222,6 @@ export function FeedItemCard({
|
||||
href={href}
|
||||
/>
|
||||
)}
|
||||
{score ? (
|
||||
<RankingMath
|
||||
score={score}
|
||||
definition={definition}
|
||||
relation={item.relation}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
</article>
|
||||
);
|
||||
@@ -352,9 +356,13 @@ function FeedbackMenu({
|
||||
<SendouMenu
|
||||
placement="bottom end"
|
||||
trigger={
|
||||
<button type="button" className={styles.feedbackTrigger}>
|
||||
<button
|
||||
type="button"
|
||||
className={styles.feedbackTrigger}
|
||||
aria-label="Feedback"
|
||||
>
|
||||
<MessageSquareHeart size={14} />
|
||||
Feedback
|
||||
<span className={styles.feedbackLabel}>Feedback</span>
|
||||
</button>
|
||||
}
|
||||
>
|
||||
@@ -431,7 +439,7 @@ function FeedbackPanel({
|
||||
);
|
||||
}
|
||||
|
||||
function RankingMath({
|
||||
function ScorePopover({
|
||||
score,
|
||||
definition,
|
||||
relation,
|
||||
@@ -440,21 +448,59 @@ function RankingMath({
|
||||
definition: FeedItemTypeDefinition;
|
||||
relation: FeedRelation | null;
|
||||
}) {
|
||||
const rows = [
|
||||
{ label: "base", value: score.base, note: null },
|
||||
{ label: "weight", value: score.weight.toFixed(2), note: null },
|
||||
{
|
||||
label: "affinity",
|
||||
value: score.affinity,
|
||||
note: relation ? relation.toLowerCase() : "no relation",
|
||||
},
|
||||
{ label: "weapon", value: score.weaponAffinity, note: null },
|
||||
{
|
||||
label: "recency",
|
||||
value: score.recency.toFixed(2),
|
||||
note: `${durationText(score.ageHours * 3600)} old, half-life ${definition.halfLifeHours}h`,
|
||||
},
|
||||
{ label: "diversity", value: score.diversity.toFixed(2), note: null },
|
||||
];
|
||||
|
||||
return (
|
||||
<div className={styles.math}>
|
||||
<b>{definition.name}</b>: base <b>{score.base}</b>
|
||||
{score.weight !== 1 ? (
|
||||
<>
|
||||
{" "}
|
||||
× weight <b>{score.weight.toFixed(2)}</b>
|
||||
</>
|
||||
) : null}{" "}
|
||||
× affinity <b>{score.affinity}</b>
|
||||
{relation ? ` (${relation.toLowerCase()})` : null} × recency{" "}
|
||||
<b>{score.recency.toFixed(2)}</b> ({durationText(score.ageHours * 3600)}{" "}
|
||||
old, half-life {definition.halfLifeHours}h) × diversity{" "}
|
||||
<b>{score.diversity.toFixed(2)}</b> = <b>{score.total.toFixed(3)}</b>
|
||||
</div>
|
||||
<SendouPopover
|
||||
placement="bottom end"
|
||||
trigger={
|
||||
<button type="button" className={styles.feedbackTrigger}>
|
||||
<Calculator size={14} />
|
||||
{score.total.toFixed(3)}
|
||||
</button>
|
||||
}
|
||||
>
|
||||
<div className={styles.math}>
|
||||
<b>{definition.name}</b>
|
||||
<table className={styles.mathTable}>
|
||||
<tbody>
|
||||
{rows.map((row, i) => (
|
||||
<tr key={row.label}>
|
||||
<td>{i === 0 ? null : "×"}</td>
|
||||
<td>{row.label}</td>
|
||||
<td>
|
||||
<b>{row.value}</b>
|
||||
</td>
|
||||
<td className="text-lighter">{row.note}</td>
|
||||
</tr>
|
||||
))}
|
||||
<tr>
|
||||
<td>=</td>
|
||||
<td>total</td>
|
||||
<td>
|
||||
<b>{score.total.toFixed(3)}</b>
|
||||
</td>
|
||||
<td />
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</SendouPopover>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -216,6 +216,10 @@
|
||||
color-mix(in oklch, var(--hero-tint) 14%, var(--color-bg-high)),
|
||||
var(--color-bg-high) 65%
|
||||
);
|
||||
|
||||
@container (width < 400px) {
|
||||
padding: var(--s-3);
|
||||
}
|
||||
}
|
||||
|
||||
.heroAccent {
|
||||
@@ -272,11 +276,28 @@
|
||||
& tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
@container (width < 400px) {
|
||||
& td,
|
||||
& th {
|
||||
padding-inline: var(--s-1-5);
|
||||
}
|
||||
|
||||
& .rowNoWrap {
|
||||
gap: var(--s-1-5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.numeric {
|
||||
text-align: right;
|
||||
font-variant-numeric: tabular-nums;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.fillCell {
|
||||
width: 100%;
|
||||
max-width: 0;
|
||||
}
|
||||
|
||||
.rankCell {
|
||||
@@ -364,6 +385,12 @@
|
||||
align-items: center;
|
||||
gap: var(--s-3);
|
||||
text-align: center;
|
||||
|
||||
@container (width < 400px) {
|
||||
grid-template-columns: minmax(0, 1fr) fit-content(5.5rem) minmax(0, 1fr);
|
||||
gap: var(--s-1-5);
|
||||
padding-inline: var(--s-2);
|
||||
}
|
||||
}
|
||||
|
||||
.vsSide {
|
||||
@@ -373,6 +400,14 @@
|
||||
min-width: 0;
|
||||
font-size: var(--font-sm);
|
||||
font-weight: var(--weight-semi);
|
||||
|
||||
& > .ellipsis {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
@container (width < 400px) {
|
||||
font-size: var(--font-xs);
|
||||
}
|
||||
}
|
||||
|
||||
.list {
|
||||
|
||||
@@ -2,7 +2,13 @@ import clsx from "clsx";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Link } from "react-router";
|
||||
import { Avatar } from "~/components/Avatar";
|
||||
import { Image, ModeImage, StageImage, WeaponImage } from "~/components/Image";
|
||||
import {
|
||||
Image,
|
||||
ModeImage,
|
||||
OutlinedImage,
|
||||
StageImage,
|
||||
WeaponImage,
|
||||
} from "~/components/Image";
|
||||
import { LocaleTime } from "~/components/LocaleTime";
|
||||
import { SiteLogoMark } from "~/components/SiteLogoMark";
|
||||
import type {
|
||||
@@ -13,6 +19,7 @@ import type {
|
||||
import { truncateWithOverflow } from "~/utils/arrays";
|
||||
import type { CommonUser } from "~/utils/kysely.server";
|
||||
import {
|
||||
abilityImageUrl,
|
||||
type NavIcon,
|
||||
navIconUrl,
|
||||
tournamentPage,
|
||||
@@ -147,12 +154,22 @@ export function WeaponSlot({
|
||||
{weaponSplId !== null ? (
|
||||
<WeaponImage weaponSplId={weaponSplId} variant="build" size={24} />
|
||||
) : (
|
||||
"?"
|
||||
<UnknownWeaponImage size={24} />
|
||||
)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
export function UnknownWeaponImage({ size }: { size: number }) {
|
||||
return (
|
||||
<OutlinedImage
|
||||
path={abilityImageUrl("UNKNOWN")}
|
||||
alt="Unknown weapon"
|
||||
size={size}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export function WeaponName({ weaponSplId }: { weaponSplId: MainWeaponId }) {
|
||||
const { t } = useTranslation(["weapons"]);
|
||||
|
||||
@@ -189,15 +206,17 @@ export function TournamentRow({
|
||||
{tournament.name}
|
||||
</Link>
|
||||
<div className="text-xs text-lighter">
|
||||
{tournament.organizationName
|
||||
? `${tournament.organizationName} · `
|
||||
: null}
|
||||
{tournament.organizationName && tournament.startsAt
|
||||
? `${tournament.organizationName}\u00a0· `
|
||||
: tournament.organizationName}
|
||||
{tournament.startsAt ? (
|
||||
<LocaleTime
|
||||
inline
|
||||
date={tournament.startsAt}
|
||||
options={{ weekday: "short", month: "short", day: "numeric" }}
|
||||
/>
|
||||
<span className="whitespace-nowrap">
|
||||
<LocaleTime
|
||||
inline
|
||||
date={tournament.startsAt}
|
||||
options={{ weekday: "short", month: "short", day: "numeric" }}
|
||||
/>
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
padding: var(--s-3);
|
||||
|
||||
& + & {
|
||||
border-top: 1px solid var(--color-border);
|
||||
border-top: var(--border-style);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,19 +60,27 @@
|
||||
align-items: center;
|
||||
gap: var(--s-1-5);
|
||||
min-width: 0;
|
||||
font-size: var(--font-xs);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.rotationType {
|
||||
.rotationMode {
|
||||
overflow: hidden;
|
||||
font-size: var(--font-sm);
|
||||
font-weight: var(--weight-bold);
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.rotationMode {
|
||||
.rotationType {
|
||||
flex-shrink: 0;
|
||||
margin-left: auto;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
padding: var(--s-0-5) var(--s-2);
|
||||
font-size: var(--font-3xs);
|
||||
font-weight: var(--weight-semi);
|
||||
color: var(--color-text-high);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
background-color: var(--color-bg-higher);
|
||||
border-radius: var(--radius-full);
|
||||
}
|
||||
|
||||
.stages {
|
||||
@@ -85,8 +93,17 @@
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
aspect-ratio: 16 / 9;
|
||||
border-radius: max(2px, calc(var(--radius-box) - var(--s-3)));
|
||||
border-radius: var(--radius-field);
|
||||
background-color: var(--color-bg-higher);
|
||||
|
||||
&::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
border-radius: inherit;
|
||||
box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.08);
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
.stageImageContainer {
|
||||
@@ -104,30 +121,35 @@
|
||||
.stageName {
|
||||
position: absolute;
|
||||
inset: auto 0 0;
|
||||
padding: var(--s-3) var(--s-1-5) var(--s-1);
|
||||
overflow: hidden;
|
||||
padding: var(--s-5) var(--s-2) var(--s-1-5);
|
||||
font-size: var(--font-2xs);
|
||||
font-weight: var(--weight-semi);
|
||||
font-weight: var(--weight-bold);
|
||||
line-height: 1.2;
|
||||
color: white;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
background: linear-gradient(transparent, rgb(0 0 0 / 0.75));
|
||||
text-wrap: balance;
|
||||
text-shadow: 0 1px 2px rgb(0 0 0 / 0.6);
|
||||
background: linear-gradient(
|
||||
transparent,
|
||||
rgb(0 0 0 / 0.45) 45%,
|
||||
rgb(0 0 0 / 0.8)
|
||||
);
|
||||
}
|
||||
|
||||
.next {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--s-1);
|
||||
gap: var(--s-1-5);
|
||||
min-width: 0;
|
||||
font-size: var(--font-2xs);
|
||||
color: var(--color-text-high);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.nextLabel {
|
||||
font-weight: var(--weight-semi);
|
||||
font-size: var(--font-3xs);
|
||||
font-weight: var(--weight-bold);
|
||||
color: var(--color-text-high);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
letter-spacing: 0.06em;
|
||||
}
|
||||
|
||||
.nextStages {
|
||||
@@ -136,12 +158,14 @@
|
||||
}
|
||||
|
||||
.credit {
|
||||
display: block;
|
||||
padding: var(--s-2) var(--s-3);
|
||||
font-size: var(--font-3xs);
|
||||
color: var(--color-text-high);
|
||||
text-align: right;
|
||||
border-top: 1px solid var(--color-border);
|
||||
border-top: var(--border-style);
|
||||
|
||||
& a {
|
||||
color: var(--color-text-high);
|
||||
}
|
||||
}
|
||||
|
||||
.streams {
|
||||
|
||||
@@ -117,13 +117,13 @@ function RotationsPanel({
|
||||
{rows.map(({ type, current, next }) => (
|
||||
<li key={type} className={styles.rotation}>
|
||||
<div className={styles.rotationHeader}>
|
||||
<ModeImage mode={current.mode as ModeShort} width={18} />
|
||||
<span className={styles.rotationType}>
|
||||
{t(ROTATION_TYPE_LABELS[type])}
|
||||
</span>
|
||||
<ModeImage mode={current.mode as ModeShort} width={22} />
|
||||
<span className={styles.rotationMode}>
|
||||
{t(`game-misc:MODE_LONG_${current.mode as ModeShort}`)}
|
||||
</span>
|
||||
<span className={styles.rotationType}>
|
||||
{t(ROTATION_TYPE_LABELS[type])}
|
||||
</span>
|
||||
</div>
|
||||
<div className={styles.stages}>
|
||||
{[current.stageId1, current.stageId2].map((stageId) => (
|
||||
@@ -135,7 +135,7 @@ function RotationsPanel({
|
||||
containerClassName={styles.stageImageContainer}
|
||||
/>
|
||||
<span className={styles.stageName}>
|
||||
{shortStageName(t(`game-misc:STAGE_${stageId as StageId}`))}
|
||||
{t(`game-misc:STAGE_${stageId as StageId}`)}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
@@ -160,14 +160,11 @@ function RotationsPanel({
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<a
|
||||
href={SPLATOON_3_INK}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className={styles.credit}
|
||||
>
|
||||
{t("front:rotations.credit")}
|
||||
</a>
|
||||
<div className={styles.credit}>
|
||||
<a href={SPLATOON_3_INK} target="_blank" rel="noopener noreferrer">
|
||||
{t("front:rotations.credit")}
|
||||
</a>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -64,6 +64,23 @@
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: var(--s-6);
|
||||
|
||||
@container (width < 400px) {
|
||||
gap: var(--s-3);
|
||||
}
|
||||
}
|
||||
|
||||
.columnsStackNarrow {
|
||||
@container (width < 400px) {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
gap: var(--s-4);
|
||||
}
|
||||
}
|
||||
|
||||
.promotionFrom {
|
||||
@container (width < 400px) {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.column {
|
||||
|
||||
@@ -33,6 +33,7 @@ import {
|
||||
NavIconAvatar,
|
||||
StageName,
|
||||
tierLabel,
|
||||
UnknownWeaponImage,
|
||||
UserName,
|
||||
UserStack,
|
||||
WeaponName,
|
||||
@@ -72,12 +73,14 @@ export function playItemContent(item: FeedItem): FeedItemContent | null {
|
||||
<TierImage tier={data.promotion.to} width={56} />
|
||||
<div className={clsx("ml-auto", styles.alignEnd)}>
|
||||
<div className="font-bold">
|
||||
{tierLabel(data.promotion.from)} →{" "}
|
||||
<span className={styles.promotionFrom}>
|
||||
{tierLabel(data.promotion.from)} →{" "}
|
||||
</span>
|
||||
{tierLabel(data.promotion.to)}
|
||||
</div>
|
||||
{data.newSp !== null ? (
|
||||
<div className="text-xs text-lighter">
|
||||
{data.newSp} SP
|
||||
{`${data.newSp}\u00a0SP`}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
@@ -135,7 +138,7 @@ export function playItemContent(item: FeedItem): FeedItemContent | null {
|
||||
</span>
|
||||
<br />
|
||||
<span className="text-xs text-lighter">
|
||||
{data.newSp} SP
|
||||
{`${data.newSp}\u00a0SP`}
|
||||
</span>
|
||||
</span>
|
||||
) : null}
|
||||
@@ -189,7 +192,7 @@ export function playItemContent(item: FeedItem): FeedItemContent | null {
|
||||
</div>
|
||||
{data.tier ? (
|
||||
<span className="text-xs text-lighter">
|
||||
{tierLabel(data.tier)} · {data.sp} SP
|
||||
{tierLabel(data.tier)} · {`${data.sp}\u00a0SP`}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
@@ -227,10 +230,13 @@ export function playItemContent(item: FeedItem): FeedItemContent | null {
|
||||
<td className={partsStyles.rankCell}>
|
||||
#{neighbor.placement}
|
||||
</td>
|
||||
<td>
|
||||
<td className={partsStyles.fillCell}>
|
||||
<div className={partsStyles.rowNoWrap}>
|
||||
<Avatar user={neighbor.user} size="xxxsm" />
|
||||
<Link to={userPage(neighbor.user)}>
|
||||
<Link
|
||||
to={userPage(neighbor.user)}
|
||||
className={partsStyles.ellipsis}
|
||||
>
|
||||
{neighbor.user.username}
|
||||
</Link>
|
||||
</div>
|
||||
@@ -304,7 +310,7 @@ export function playItemContent(item: FeedItem): FeedItemContent | null {
|
||||
"–"
|
||||
)}
|
||||
</span>
|
||||
<span className="text-xs text-lighter">{data.sp} SP</span>
|
||||
<span className="text-xs text-lighter">{`${data.sp}\u00a0SP`}</span>
|
||||
</div>
|
||||
<div className={styles.stat}>
|
||||
<span className={styles.label}>Maps</span>
|
||||
@@ -330,7 +336,7 @@ export function playItemContent(item: FeedItem): FeedItemContent | null {
|
||||
size={28}
|
||||
/>
|
||||
) : (
|
||||
"–"
|
||||
<UnknownWeaponImage size={28} />
|
||||
)}
|
||||
</span>
|
||||
<span
|
||||
@@ -456,7 +462,7 @@ export function playItemContent(item: FeedItem): FeedItemContent | null {
|
||||
<div className={partsStyles.grow}>
|
||||
<div className="font-semi-bold">
|
||||
{rank
|
||||
? `${tierLabel(rank.tier)} · ${rank.sp} SP`
|
||||
? `${tierLabel(rank.tier)} · ${rank.sp}\u00a0SP`
|
||||
: `${data.setCount} ${data.setCount === 1 ? "set" : "sets"} played`}
|
||||
</div>
|
||||
{rank ? (
|
||||
@@ -500,7 +506,7 @@ export function playItemContent(item: FeedItem): FeedItemContent | null {
|
||||
),
|
||||
body: (
|
||||
<>
|
||||
<div className={styles.columns}>
|
||||
<div className={clsx(styles.columns, styles.columnsStackNarrow)}>
|
||||
<div className={styles.column}>
|
||||
<span className={styles.label}>Players</span>
|
||||
{data.players.map((player) => (
|
||||
@@ -515,7 +521,9 @@ export function playItemContent(item: FeedItem): FeedItemContent | null {
|
||||
previousPlacement={player.previousPlacement}
|
||||
/>
|
||||
</span>
|
||||
<span className={styles.alignEnd}>
|
||||
<span
|
||||
className={clsx(styles.alignEnd, "whitespace-nowrap")}
|
||||
>
|
||||
{player.sp.toFixed(1)}
|
||||
{player.weeklyChange ? (
|
||||
<span
|
||||
@@ -574,7 +582,7 @@ export function playItemContent(item: FeedItem): FeedItemContent | null {
|
||||
case "SQ_META": {
|
||||
const { data } = item;
|
||||
return {
|
||||
avatar: <LogoAvatar url={null} name="SendouQ" />,
|
||||
avatar: <NavIconAvatar navIcon="sendouq" />,
|
||||
line: (
|
||||
<>
|
||||
<b>Weapon trends</b> in SendouQ this week
|
||||
@@ -603,13 +611,15 @@ export function playItemContent(item: FeedItem): FeedItemContent | null {
|
||||
<span
|
||||
className={clsx(
|
||||
"ml-auto text-xs",
|
||||
row.changePercentage >= 0
|
||||
row.changePercentage === null ||
|
||||
row.changePercentage > 0
|
||||
? styles.plusDelta
|
||||
: styles.minusDelta,
|
||||
)}
|
||||
>
|
||||
{row.changePercentage > 0 ? "+" : ""}
|
||||
{row.changePercentage}%
|
||||
{row.changePercentage === null
|
||||
? "New"
|
||||
: `${row.changePercentage > 0 ? "+" : ""}${row.changePercentage}%`}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
@@ -617,8 +627,8 @@ export function playItemContent(item: FeedItem): FeedItemContent | null {
|
||||
))}
|
||||
</div>
|
||||
<div className="text-xs text-lighter">
|
||||
Change in share of picks vs last week · {data.reportCount} weapon
|
||||
reports
|
||||
Change in share of play vs last week, weighted towards higher
|
||||
ranked players · {data.playerCount} players
|
||||
</div>
|
||||
</>
|
||||
),
|
||||
@@ -643,10 +653,12 @@ export function playItemContent(item: FeedItem): FeedItemContent | null {
|
||||
{data.top.map((player) => (
|
||||
<tr key={player.id}>
|
||||
<td className={partsStyles.rankCell}>#{player.placement}</td>
|
||||
<td>
|
||||
<td className={partsStyles.fillCell}>
|
||||
<div className={partsStyles.rowNoWrap}>
|
||||
<Avatar user={player} size="xxxsm" />
|
||||
<UserName user={player} />
|
||||
<span className={partsStyles.ellipsis}>
|
||||
<UserName user={player} />
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td className={partsStyles.numeric}>
|
||||
|
||||
@@ -42,6 +42,24 @@
|
||||
}
|
||||
}
|
||||
|
||||
.heatBest i {
|
||||
.heatFull i {
|
||||
background-color: var(--color-success);
|
||||
}
|
||||
|
||||
.heatOneShort i {
|
||||
border-radius: 0 0 var(--radius-selector) var(--radius-selector);
|
||||
background-color: var(--color-success-low);
|
||||
box-shadow: inset 0 0 0 1px var(--color-success);
|
||||
}
|
||||
|
||||
.tierCounts {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--s-1) var(--s-3);
|
||||
}
|
||||
|
||||
.tierCount {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: var(--s-1-5);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ import { Link } from "react-router";
|
||||
import { Avatar } from "~/components/Avatar";
|
||||
import { WeaponImage } from "~/components/Image";
|
||||
import { LocaleTime } from "~/components/LocaleTime";
|
||||
import type { PlayableWindowTier } from "~/features/availability/availability-types";
|
||||
import { TierDot } from "~/features/availability/components/PlayableWindowsSummary";
|
||||
import { lfgSearchParams } from "~/features/lfg/lfg-search-params";
|
||||
import { LFG_PAGE, scrimsPage, teamPage, teamSchedulePage } from "~/utils/urls";
|
||||
import type { FeedItem } from "../core/FeedItems.server";
|
||||
@@ -27,6 +29,11 @@ const SCRIM_POST_REASON_TEXTS: Record<ScrimPostReason, string | null> = {
|
||||
FIT: null,
|
||||
};
|
||||
|
||||
const HEAT_TIER_CLASSES: Record<PlayableWindowTier, string> = {
|
||||
FULL: styles.heatFull,
|
||||
ONE_SHORT: styles.heatOneShort,
|
||||
};
|
||||
|
||||
export function teamItemContent(item: FeedItem): FeedItemContent | null {
|
||||
switch (item.type) {
|
||||
case "TEAM_JOIN": {
|
||||
@@ -117,9 +124,12 @@ export function teamItemContent(item: FeedItem): FeedItemContent | null {
|
||||
}
|
||||
case "TEAM_AVAILABILITY": {
|
||||
const { data } = item;
|
||||
const bestDayIndex = Math.floor(
|
||||
(data.bestStartsAt - data.days[0].startsAt) / 86400,
|
||||
);
|
||||
const fullDayCount = data.days.filter(
|
||||
(day) => day.tier === "FULL",
|
||||
).length;
|
||||
const oneShortDayCount = data.days.filter(
|
||||
(day) => day.tier === "ONE_SHORT",
|
||||
).length;
|
||||
return {
|
||||
avatar: <LogoAvatar url={data.team.avatarUrl} name={data.team.name} />,
|
||||
line: (
|
||||
@@ -133,12 +143,13 @@ export function teamItemContent(item: FeedItem): FeedItemContent | null {
|
||||
body: (
|
||||
<>
|
||||
<div className={styles.heat}>
|
||||
{data.days.map((day, i) => (
|
||||
{data.days.map((day) => (
|
||||
<div
|
||||
key={day.startsAt}
|
||||
className={clsx(styles.heatDay, {
|
||||
[styles.heatBest]: i === bestDayIndex,
|
||||
})}
|
||||
className={clsx(
|
||||
styles.heatDay,
|
||||
day.tier ? HEAT_TIER_CLASSES[day.tier] : undefined,
|
||||
)}
|
||||
>
|
||||
<div className={styles.heatBar}>
|
||||
<i
|
||||
@@ -156,17 +167,23 @@ export function teamItemContent(item: FeedItem): FeedItemContent | null {
|
||||
))}
|
||||
</div>
|
||||
<div className={partsStyles.rowNoWrap}>
|
||||
<span className="text-xs">
|
||||
Best window{" "}
|
||||
<b>
|
||||
<DayTime at={data.bestStartsAt} />
|
||||
</b>{" "}
|
||||
–{" "}
|
||||
<LocaleTime
|
||||
inline
|
||||
date={data.bestEndsAt}
|
||||
options={{ hour: "numeric", minute: "2-digit" }}
|
||||
/>
|
||||
<span className={clsx("text-xs", styles.tierCounts)}>
|
||||
<span className={styles.tierCount}>
|
||||
<TierDot full />
|
||||
<span>
|
||||
<b>{countText(fullDayCount, "day")}</b> with{" "}
|
||||
{data.minPlayers}+
|
||||
</span>
|
||||
</span>
|
||||
{oneShortDayCount > 0 ? (
|
||||
<span className={styles.tierCount}>
|
||||
<TierDot full={false} />
|
||||
<span>
|
||||
<b>{countText(oneShortDayCount, "day")}</b> with{" "}
|
||||
{data.minPlayers - 1}
|
||||
</span>
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
<span className="ml-auto">
|
||||
<UserStack users={data.freeUsers} />
|
||||
@@ -174,6 +191,7 @@ export function teamItemContent(item: FeedItem): FeedItemContent | null {
|
||||
</div>
|
||||
</>
|
||||
),
|
||||
href: teamSchedulePage(data.team.customUrl),
|
||||
};
|
||||
}
|
||||
case "TEAM_EVENT_ADDED": {
|
||||
|
||||
@@ -16,9 +16,72 @@
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: var(--s-0-5);
|
||||
|
||||
& img {
|
||||
flex: none;
|
||||
}
|
||||
}
|
||||
|
||||
@container (width < 260px) {
|
||||
.placementsCell {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
@container (width < 400px) {
|
||||
.medalCounts {
|
||||
gap: var(--s-1-5);
|
||||
}
|
||||
|
||||
.medalTimes {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.podiumStack,
|
||||
.standingsAvatar {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.showcaseList {
|
||||
display: grid;
|
||||
grid-template-columns: auto minmax(0, 1fr) auto auto;
|
||||
|
||||
@container (width < 400px) {
|
||||
grid-template-columns: auto minmax(0, 1fr) auto;
|
||||
}
|
||||
|
||||
& .showcaseRow {
|
||||
grid-column: 1 / -1;
|
||||
grid-template-columns: subgrid;
|
||||
}
|
||||
}
|
||||
|
||||
.showcaseEnd {
|
||||
display: contents;
|
||||
|
||||
& > :last-child {
|
||||
justify-self: end;
|
||||
}
|
||||
|
||||
@container (width < 400px) {
|
||||
display: grid;
|
||||
justify-items: center;
|
||||
gap: var(--s-1);
|
||||
|
||||
& > :last-child {
|
||||
justify-self: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.showcaseTier {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.emptySlot {
|
||||
flex: none;
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border-radius: 50%;
|
||||
|
||||
@@ -129,7 +129,9 @@ export function tournamentItemContent(
|
||||
<div className={clsx(partsStyles.inset, partsStyles.rowNoWrap)}>
|
||||
<Placement placement={data.placement} size={36} />
|
||||
<div className={partsStyles.grow}>
|
||||
<div className="font-bold">{data.team.name}</div>
|
||||
<div className={clsx(partsStyles.ellipsis, "font-bold")}>
|
||||
{data.team.name}
|
||||
</div>
|
||||
<div className="text-xs text-lighter">
|
||||
{ordinalPlacement(data.placement)} of {data.participantCount} ·{" "}
|
||||
{data.setWins}–{data.setLosses} in sets
|
||||
@@ -138,7 +140,9 @@ export function tournamentItemContent(
|
||||
: ""}
|
||||
</div>
|
||||
</div>
|
||||
<UserStack users={data.team.members} max={4} />
|
||||
<span className={styles.podiumStack}>
|
||||
<UserStack users={data.team.members} max={4} />
|
||||
</span>
|
||||
</div>
|
||||
),
|
||||
};
|
||||
@@ -220,17 +224,11 @@ export function tournamentItemContent(
|
||||
const { data } = item;
|
||||
return {
|
||||
avatar: <Avatar user={data.actor} size="xs" />,
|
||||
line: data.isActorWinner ? (
|
||||
line: (
|
||||
<>
|
||||
<UserName user={data.actor} />
|
||||
's team, seeded {data.winnerSeed}, knocked out seed {data.loserSeed}{" "}
|
||||
at <TournamentLink tournament={data.tournament} />
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<UserName user={data.actor} />
|
||||
's team, seeded {data.loserSeed}, was knocked out by seed{" "}
|
||||
{data.winnerSeed} at <TournamentLink tournament={data.tournament} />
|
||||
's team (seed {data.winnerSeed}) upset seed {data.loserSeed} at{" "}
|
||||
<TournamentLink tournament={data.tournament} />
|
||||
</>
|
||||
),
|
||||
body: (
|
||||
@@ -275,13 +273,13 @@ export function tournamentItemContent(
|
||||
{data.note ? (
|
||||
<div className={partsStyles.quote}>{data.note}</div>
|
||||
) : null}
|
||||
<div className={partsStyles.rowNoWrap}>
|
||||
<div className={partsStyles.row}>
|
||||
<UserStack users={data.team.members} />
|
||||
{Array.from({ length: data.openSpots }, (_, i) => (
|
||||
<span key={i} className={styles.emptySlot} />
|
||||
))}
|
||||
{data.tournament?.startsAt ? (
|
||||
<span className="text-xs text-lighter">
|
||||
<span className="text-xs text-lighter whitespace-nowrap">
|
||||
<DayTime at={data.tournament.startsAt} />
|
||||
</span>
|
||||
) : null}
|
||||
@@ -368,7 +366,11 @@ export function tournamentItemContent(
|
||||
<tr>
|
||||
<th className={partsStyles.rankCell}>#</th>
|
||||
<th>Player</th>
|
||||
<th className={partsStyles.numeric}>Placements</th>
|
||||
<th
|
||||
className={clsx(partsStyles.numeric, styles.placementsCell)}
|
||||
>
|
||||
Placements
|
||||
</th>
|
||||
<th className={partsStyles.numeric}>Points</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -381,13 +383,22 @@ export function tournamentItemContent(
|
||||
})}
|
||||
>
|
||||
<td className={partsStyles.rankCell}>{row.placement}</td>
|
||||
<td>
|
||||
<td className={partsStyles.fillCell}>
|
||||
<div className={partsStyles.rowNoWrap}>
|
||||
<Avatar user={row.user} size="xxxsm" />
|
||||
<Link to={userPage(row.user)}>{row.user.username}</Link>
|
||||
<Avatar
|
||||
user={row.user}
|
||||
size="xxxsm"
|
||||
className={styles.standingsAvatar}
|
||||
/>
|
||||
<Link
|
||||
to={userPage(row.user)}
|
||||
className={partsStyles.ellipsis}
|
||||
>
|
||||
{row.user.username}
|
||||
</Link>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<td className={styles.placementsCell}>
|
||||
<MedalCounts placements={row.placements} />
|
||||
</td>
|
||||
<td className={partsStyles.numeric}>
|
||||
@@ -399,6 +410,12 @@ export function tournamentItemContent(
|
||||
</table>
|
||||
</>
|
||||
),
|
||||
href: data.organization
|
||||
? tournamentOrganizationPage({
|
||||
organizationSlug: data.organization.slug,
|
||||
seriesId: data.seriesId,
|
||||
})
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
case "TO_VOD": {
|
||||
@@ -493,7 +510,7 @@ export function tournamentItemContent(
|
||||
<React.Suspense fallback={<div className={styles.trophySlot} />}>
|
||||
<FeedTrophy trophy={data.trophy} tier={data.tier} />
|
||||
</React.Suspense>
|
||||
<div>
|
||||
<div className={partsStyles.grow}>
|
||||
<div className="font-bold">{data.trophy.name}</div>
|
||||
<div className="text-xs text-lighter">
|
||||
{data.tournament?.name}
|
||||
@@ -521,7 +538,7 @@ export function tournamentItemContent(
|
||||
<React.Suspense fallback={<div className={styles.trophySlot} />}>
|
||||
<FeedTrophy trophy={data.trophy} tier={null} />
|
||||
</React.Suspense>
|
||||
<div>
|
||||
<div className={partsStyles.grow}>
|
||||
<div className="font-bold">{data.trophy.name}</div>
|
||||
{data.organizationName ? (
|
||||
<div className="text-xs text-lighter">
|
||||
@@ -592,9 +609,12 @@ export function tournamentItemContent(
|
||||
),
|
||||
body: (
|
||||
<>
|
||||
<div className={partsStyles.list}>
|
||||
<div className={clsx(partsStyles.list, styles.showcaseList)}>
|
||||
{data.tournaments.map((tournament) => (
|
||||
<div key={tournament.id} className={partsStyles.digestRow}>
|
||||
<div
|
||||
key={tournament.id}
|
||||
className={clsx(partsStyles.digestRow, styles.showcaseRow)}
|
||||
>
|
||||
<LogoAvatar
|
||||
url={tournament.logoUrl}
|
||||
name={tournament.name}
|
||||
@@ -609,22 +629,29 @@ export function tournamentItemContent(
|
||||
{tournament.name}
|
||||
</Link>
|
||||
</div>
|
||||
<div className="text-xs text-lighter">
|
||||
<div
|
||||
className={clsx(
|
||||
partsStyles.ellipsis,
|
||||
"text-xs text-lighter",
|
||||
)}
|
||||
>
|
||||
<DayTime at={tournament.startsAt} />
|
||||
{tournament.organization
|
||||
? ` · ${tournament.organization.name}`
|
||||
: ""}
|
||||
</div>
|
||||
</div>
|
||||
<div className={partsStyles.rowNoWrap}>
|
||||
{tournament.tier !== null ||
|
||||
tournament.tentativeTier !== null ? (
|
||||
<TierPill
|
||||
tier={(tournament.tier ?? tournament.tentativeTier)!}
|
||||
isTentative={tournament.tier === null}
|
||||
withoutAnimation
|
||||
/>
|
||||
) : null}
|
||||
<div className={styles.showcaseEnd}>
|
||||
<span className={styles.showcaseTier}>
|
||||
{tournament.tier !== null ||
|
||||
tournament.tentativeTier !== null ? (
|
||||
<TierPill
|
||||
tier={(tournament.tier ?? tournament.tentativeTier)!}
|
||||
isTentative={tournament.tier === null}
|
||||
withoutAnimation
|
||||
/>
|
||||
) : null}
|
||||
</span>
|
||||
<span className="text-xs text-lighter">
|
||||
{countText(tournament.teamsCount, "team")}
|
||||
</span>
|
||||
@@ -716,7 +743,7 @@ export function tournamentItemContent(
|
||||
<td className={partsStyles.rankCell}>
|
||||
#{row.projectedSeed}
|
||||
</td>
|
||||
<td>
|
||||
<td className={partsStyles.fillCell}>
|
||||
<div className={partsStyles.rowNoWrap}>
|
||||
<UserStack users={row.team.members} max={4} />
|
||||
<span className={partsStyles.ellipsis}>
|
||||
@@ -725,7 +752,12 @@ export function tournamentItemContent(
|
||||
{row.isOwn ? (
|
||||
<span className={partsStyles.pill}>You</span>
|
||||
) : row.known.length > 0 ? (
|
||||
<span className={partsStyles.pill}>
|
||||
<span
|
||||
className={clsx(
|
||||
partsStyles.pill,
|
||||
partsStyles.ellipsis,
|
||||
)}
|
||||
>
|
||||
{row.known
|
||||
.map((member) => member.username)
|
||||
.join(", ")}
|
||||
@@ -805,7 +837,9 @@ function PodiumBody({
|
||||
{team.members.map((member) => member.username).join(", ")}
|
||||
</div>
|
||||
</div>
|
||||
<UserStack users={team.members} max={4} />
|
||||
<span className={styles.podiumStack}>
|
||||
<UserStack users={team.members} max={4} />
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
@@ -826,7 +860,9 @@ function MedalCounts({
|
||||
{[placements.first, placements.second, placements.third].map(
|
||||
(count, i) => (
|
||||
<span key={i} className={styles.medalCount}>
|
||||
<Placement placement={i + 1} size={16} />×{count}
|
||||
<Placement placement={i + 1} size={16} />
|
||||
<span className={styles.medalTimes}>×</span>
|
||||
{count}
|
||||
</span>
|
||||
),
|
||||
)}
|
||||
|
||||
@@ -113,8 +113,8 @@ describe("FeedEvents.derive", () => {
|
||||
const events = derive(
|
||||
[
|
||||
sqPlay({ at: NOW - 2, ordinal: 15 }),
|
||||
sqPlay({ at: NOW - 1, ordinal: 25, matchId: 2 }),
|
||||
sqPlay({ at: NOW, ordinal: 35, matchId: 3 }),
|
||||
sqPlay({ at: NOW - 1, previousOrdinal: 15, ordinal: 25, matchId: 2 }),
|
||||
sqPlay({ at: NOW, previousOrdinal: 25, ordinal: 35, matchId: 3 }),
|
||||
],
|
||||
{ name: "DIAMOND", isPlus: false },
|
||||
);
|
||||
@@ -129,6 +129,23 @@ describe("FeedEvents.derive", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
test("emits no promotion for a tier crossed outside the set", () => {
|
||||
const events = derive([
|
||||
sqPlay({ at: NOW - 1, ordinal: 25 }),
|
||||
sqPlay({ at: NOW, previousOrdinal: 31, ordinal: 35 }),
|
||||
]);
|
||||
|
||||
expect(ofType(events, "SQ_PROMOTION")).toEqual([]);
|
||||
});
|
||||
|
||||
test("emits no promotion for a lost set", () => {
|
||||
const events = derive([
|
||||
sqPlay({ at: NOW, previousOrdinal: 25, ordinal: 35, isWin: false }),
|
||||
]);
|
||||
|
||||
expect(ofType(events, "SQ_PROMOTION")).toEqual([]);
|
||||
});
|
||||
|
||||
test("emits an upset when beating a group enough tiers higher", () => {
|
||||
const events = derive([
|
||||
sqPlay({
|
||||
@@ -183,6 +200,7 @@ function sqPlay(play: Partial<FeedEvents.SqPlay>): FeedEvents.SqPlay {
|
||||
matchId: 1,
|
||||
season: 1,
|
||||
ordinal: 0,
|
||||
previousOrdinal: null,
|
||||
isWin: true,
|
||||
ownTier: null,
|
||||
opponentTier: null,
|
||||
|
||||
@@ -31,6 +31,8 @@ export interface SqPlay {
|
||||
matchId: number;
|
||||
season: number;
|
||||
ordinal: number;
|
||||
/** Before this set, also counting tournaments of the season. `null` when this set was the first. */
|
||||
previousOrdinal: number | null;
|
||||
isWin: boolean;
|
||||
ownTier: FeedTier | null;
|
||||
opponentTier: FeedTier | null;
|
||||
@@ -146,11 +148,7 @@ export function derive({
|
||||
}
|
||||
}
|
||||
|
||||
let previousOfSeason: SqPlay | undefined;
|
||||
for (const [index, play] of sqPlays.entries()) {
|
||||
const previous =
|
||||
previousOfSeason?.season === play.season ? previousOfSeason : undefined;
|
||||
previousOfSeason = play;
|
||||
if (play.at < since) continue;
|
||||
|
||||
const milestone = SQ_SET_MILESTONES.find((m) => m === index + 1);
|
||||
@@ -163,8 +161,8 @@ export function derive({
|
||||
}
|
||||
|
||||
const tiers = tiersOfSeason(play.season);
|
||||
if (previous && tiers) {
|
||||
const from = tierOf(tiers.intervals, previous.ordinal);
|
||||
if (play.isWin && play.previousOrdinal !== null && tiers) {
|
||||
const from = tierOf(tiers.intervals, play.previousOrdinal);
|
||||
const to = tierOf(tiers.intervals, play.ordinal);
|
||||
const isNotable =
|
||||
!tiers.previousSeasonTier ||
|
||||
|
||||
@@ -85,6 +85,7 @@ async function reindexUser({ userId, now }: { userId: number; now: number }) {
|
||||
matchId: row.matchId,
|
||||
season: row.season,
|
||||
ordinal: row.ordinal,
|
||||
previousOrdinal: row.previousOrdinal,
|
||||
isWin: row.mapWins > row.mapsPlayed - row.mapWins,
|
||||
ownTier: row.ownTierName
|
||||
? { name: row.ownTierName, isPlus: Boolean(row.ownTierIsPlus) }
|
||||
|
||||
@@ -3,6 +3,9 @@ import { hoursToMilliseconds, subDays } from "date-fns";
|
||||
import * as R from "remeda";
|
||||
import { Config } from "~/config";
|
||||
import { mostRecentArticles } from "~/features/articles/core/list.server";
|
||||
import * as Availability from "~/features/availability/core/Availability";
|
||||
import * as ScheduleWeek from "~/features/availability/core/ScheduleWeek";
|
||||
import * as VisibleSchedules from "~/features/availability/core/VisibleSchedules.server";
|
||||
import { allEntries as allChangelogEntries } from "~/features/changelog/core/entries.server";
|
||||
import * as FriendRepository from "~/features/friends/FriendRepository.server";
|
||||
import * as ShowcaseTournaments from "~/features/front-page/core/ShowcaseTournaments.server";
|
||||
@@ -28,6 +31,7 @@ import { parseLutiDiv, serializeLutiDiv } from "~/features/scrims/scrims-utils";
|
||||
import * as ReportedWeaponRepository from "~/features/sendouq-match/ReportedWeaponRepository.server";
|
||||
import * as SQMatchRepository from "~/features/sendouq-match/SQMatchRepository.server";
|
||||
import * as SplatoonRotationRepository from "~/features/splatoon-rotations/SplatoonRotationRepository.server";
|
||||
import { getViewerTimezone } from "~/features/timezone/timezone-context.server";
|
||||
import { eventLeaderboards } from "~/features/tournament-organization/core/leaderboards.server";
|
||||
import type {
|
||||
BuildAbilitiesTuple,
|
||||
@@ -87,6 +91,7 @@ import * as FeedRotations from "./FeedRotations";
|
||||
import * as FeedSchedule from "./FeedSchedule";
|
||||
import * as FeedScrimMatch from "./FeedScrimMatch";
|
||||
import * as FeedSeasonGoal from "./FeedSeasonGoal";
|
||||
import * as FeedWeaponTrends from "./FeedWeaponTrends";
|
||||
|
||||
const HOUR = 3600;
|
||||
const DAY = 24 * HOUR;
|
||||
@@ -144,6 +149,8 @@ export interface FeedContext {
|
||||
/** Users sharing a current team with the viewer who aren't their friends */
|
||||
teammateIds: number[];
|
||||
teammateIdSet: Set<number>;
|
||||
/** Weapons of the viewer's weapon pool, see `RankableItem.weaponSplIds` */
|
||||
weaponPool: MainWeaponId[];
|
||||
/** Database timestamp everything is relative to */
|
||||
now: number;
|
||||
season: number | null;
|
||||
@@ -166,6 +173,8 @@ interface BuiltItem<D> {
|
||||
relation?: FeedRelation | null;
|
||||
/** See `RankableItem.weight` */
|
||||
weight?: number;
|
||||
/** See `RankableItem.weaponSplIds` */
|
||||
weaponSplIds?: MainWeaponId[];
|
||||
data: D;
|
||||
}
|
||||
|
||||
@@ -256,6 +265,7 @@ export type FeedItem = {
|
||||
actorKey: string;
|
||||
relation: FeedRelation | null;
|
||||
weight: number;
|
||||
weaponSplIds: MainWeaponId[];
|
||||
data: FeedItemData<T>;
|
||||
};
|
||||
}[FeedItemType];
|
||||
@@ -271,6 +281,7 @@ export async function contextFor({
|
||||
const friendIds = await FriendRepository.findFriendIds(viewerId);
|
||||
const friendIdSet = new Set(friendIds);
|
||||
const teammateIds = await teammateIdsOf({ viewerId, friendIdSet });
|
||||
const weaponPool = await FeedRepository.findWeaponPoolByUserId(viewerId);
|
||||
const now = mode === "TEST" ? await testNow() : databaseTimestampNow();
|
||||
const nowDate = databaseTimestampToDate(now);
|
||||
|
||||
@@ -281,6 +292,7 @@ export async function contextFor({
|
||||
friendIdSet,
|
||||
teammateIds,
|
||||
teammateIdSet: new Set(teammateIds),
|
||||
weaponPool: weaponPool.map((weapon) => weapon.weaponSplId),
|
||||
now,
|
||||
season: Seasons.currentOrPrevious(nowDate)?.nth ?? null,
|
||||
previousSeason: Seasons.previous(nowDate)?.nth ?? null,
|
||||
@@ -316,6 +328,7 @@ async function buildItemsOfType(
|
||||
at: Math.min(item.at, ctx.now),
|
||||
relation: item.relation ?? null,
|
||||
weight: item.weight ?? 1,
|
||||
weaponSplIds: item.weaponSplIds ?? [],
|
||||
} as FeedItem;
|
||||
},
|
||||
);
|
||||
@@ -859,48 +872,36 @@ async function buildSqMeta(ctx: SharedFeedContext) {
|
||||
weekday: FeedSchedule.WEEKDAY.MONDAY,
|
||||
}),
|
||||
);
|
||||
const thisWeek = await FeedRepository.findWeaponUsageCounts({
|
||||
const thisWeek = await FeedRepository.findWeaponPicksByUser({
|
||||
from: publishedAt - 7 * DAY,
|
||||
to: publishedAt,
|
||||
});
|
||||
const lastWeek = await FeedRepository.findWeaponUsageCounts({
|
||||
const lastWeek = await FeedRepository.findWeaponPicksByUser({
|
||||
from: publishedAt - 14 * DAY,
|
||||
to: publishedAt - 7 * DAY,
|
||||
});
|
||||
const totalThisWeek = R.sumBy(thisWeek, (row) => row.count);
|
||||
const totalLastWeek = R.sumBy(lastWeek, (row) => row.count);
|
||||
if (totalThisWeek < 100 || totalLastWeek < 100) return null;
|
||||
|
||||
const changes = R.sortBy(
|
||||
thisWeek
|
||||
.filter((row) => row.count >= totalThisWeek / 50)
|
||||
.map((row) => {
|
||||
const share = row.count / totalThisWeek;
|
||||
const previousCount =
|
||||
lastWeek.find((previous) => previous.weaponSplId === row.weaponSplId)
|
||||
?.count ?? 0;
|
||||
const previousShare = previousCount / totalLastWeek;
|
||||
const ordinals = new Map<number, number>();
|
||||
for (const season of [ctx.previousSeason, ctx.season]) {
|
||||
if (season === null) continue;
|
||||
for (const [userId, skill] of Object.entries(
|
||||
(await userSkills(season)).userSkills,
|
||||
)) {
|
||||
ordinals.set(Number(userId), skill.ordinal);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
weaponSplId: row.weaponSplId,
|
||||
sharePercentage: Math.round(share * 1000) / 10,
|
||||
changePercentage: previousShare
|
||||
? Math.round((share / previousShare - 1) * 100)
|
||||
: 100,
|
||||
};
|
||||
}),
|
||||
[(change) => change.changePercentage, "desc"],
|
||||
);
|
||||
if (changes.length < 5) return null;
|
||||
const trends = FeedWeaponTrends.risersAndFallers({
|
||||
thisWeek,
|
||||
lastWeek,
|
||||
ordinals,
|
||||
});
|
||||
if (!trends) return null;
|
||||
|
||||
return {
|
||||
at: publishedAt,
|
||||
actorKey: "SQ_META",
|
||||
data: {
|
||||
rising: changes.slice(0, 3),
|
||||
falling: changes.slice(-2).reverse(),
|
||||
reportCount: totalThisWeek,
|
||||
},
|
||||
data: trends,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1232,15 +1233,13 @@ async function buildTournamentUpset(ctx: FeedContext) {
|
||||
| (TournamentUpset & {
|
||||
tournamentId: number;
|
||||
userId: number;
|
||||
isUserWinner: boolean;
|
||||
})
|
||||
| null = null;
|
||||
for (const tournamentId of R.unique(
|
||||
results.map((result) => result.tournamentId),
|
||||
)) {
|
||||
for (const upset of await tournamentUpsets(tournamentId)) {
|
||||
const winnerUserId = userIdByTeamId.get(upset.winnerId);
|
||||
const userId = winnerUserId ?? userIdByTeamId.get(upset.loserId);
|
||||
const userId = userIdByTeamId.get(upset.winnerId);
|
||||
if (userId === undefined) continue;
|
||||
if (
|
||||
best &&
|
||||
@@ -1253,7 +1252,6 @@ async function buildTournamentUpset(ctx: FeedContext) {
|
||||
...upset,
|
||||
tournamentId,
|
||||
userId,
|
||||
isUserWinner: winnerUserId !== undefined,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1270,7 +1268,6 @@ async function buildTournamentUpset(ctx: FeedContext) {
|
||||
data: {
|
||||
tournament,
|
||||
actor: users.get(best.userId)!,
|
||||
isActorWinner: best.isUserWinner,
|
||||
winner: teams.get(best.winnerId)!,
|
||||
loser: teams.get(best.loserId)!,
|
||||
winnerSeed: best.winnerSeed,
|
||||
@@ -2150,39 +2147,56 @@ async function buildTeamAvailability(ctx: FeedContext) {
|
||||
: undefined);
|
||||
if (!week) return null;
|
||||
|
||||
const slots = await FeedRepository.findAvailabilitySlotsOfTeamWeek({
|
||||
teamId: week.teamId,
|
||||
weekStartsAt: week.weekStartsAt,
|
||||
const [team] = await FeedRepository.findTeamsByIds([week.teamId]);
|
||||
const timezone = getViewerTimezone() ?? "UTC";
|
||||
// midweek so a week started in another timezone still lands on the same viewer week
|
||||
const range = Availability.weekRange(
|
||||
databaseTimestampToDate(week.weekStartsAt + 3.5 * DAY),
|
||||
timezone,
|
||||
);
|
||||
const memberIds = team.members.map((member) => member.id);
|
||||
const { reportedWeeks, busyByUserId } = await VisibleSchedules.findByUserIds({
|
||||
userIds: memberIds,
|
||||
viewerId: ctx.viewerId,
|
||||
bypassVisibility: ctx.mode === "TEST",
|
||||
...range,
|
||||
});
|
||||
const { members, minPlayers, windows } = ScheduleWeek.teamWindows({
|
||||
range,
|
||||
playerIds: memberIds,
|
||||
reportedWeeks,
|
||||
busyByUserId,
|
||||
});
|
||||
const freeUsersByHour = new Map<number, Set<number>>();
|
||||
for (const slot of slots) {
|
||||
for (let hour = slot.startsAt; hour < slot.endsAt; hour += HOUR) {
|
||||
const users = freeUsersByHour.get(hour) ?? new Set();
|
||||
users.add(slot.userId);
|
||||
freeUsersByHour.set(hour, users);
|
||||
}
|
||||
}
|
||||
const best = R.firstBy(
|
||||
[...freeUsersByHour.entries()],
|
||||
[([, users]) => users.size, "desc"],
|
||||
[([hour]) => hour, "asc"],
|
||||
windows,
|
||||
[(window) => window.userIds.length, "desc"],
|
||||
[(window) => window.startsAt, "asc"],
|
||||
);
|
||||
if (!best) return null;
|
||||
|
||||
let bestEndsAt = best[0] + HOUR;
|
||||
while (freeUsersByHour.get(bestEndsAt)?.size === best[1].size)
|
||||
bestEndsAt += HOUR;
|
||||
const segments = Availability.availabilitySegments(members);
|
||||
const weekDays = ScheduleWeek.days(range, timezone);
|
||||
const dayStarts = weekDays.map((day) =>
|
||||
Availability.localToTimestamp({ date: day.date, time: "00:00", timezone }),
|
||||
);
|
||||
const days = weekDays.map((day, dayIndex) => {
|
||||
const startsAt = dayStarts[dayIndex];
|
||||
const endsAt = dayStarts[dayIndex + 1] ?? range.endsAt;
|
||||
|
||||
const [team] = await FeedRepository.findTeamsByIds([week.teamId]);
|
||||
const days = R.range(0, 7).map((dayIndex) => {
|
||||
const dayStartsAt = week.weekStartsAt + dayIndex * DAY;
|
||||
return {
|
||||
startsAt: dayStartsAt,
|
||||
startsAt,
|
||||
tier: ScheduleWeek.bestWindowTierOfDay({
|
||||
date: day.date,
|
||||
windows,
|
||||
timezone,
|
||||
}),
|
||||
maxFree: Math.max(
|
||||
0,
|
||||
...R.range(0, 24).map(
|
||||
(hour) => freeUsersByHour.get(dayStartsAt + hour * HOUR)?.size ?? 0,
|
||||
),
|
||||
...segments
|
||||
.filter(
|
||||
(segment) => segment.startsAt < endsAt && segment.endsAt > startsAt,
|
||||
)
|
||||
.map((segment) => segment.userIds.length),
|
||||
),
|
||||
};
|
||||
});
|
||||
@@ -2192,10 +2206,11 @@ async function buildTeamAvailability(ctx: FeedContext) {
|
||||
actorKey: `team-${week.teamId}`,
|
||||
data: {
|
||||
team,
|
||||
freeCount: best[1].size,
|
||||
bestStartsAt: best[0],
|
||||
bestEndsAt,
|
||||
freeUsers: team.members.filter((member) => best[1].has(member.id)),
|
||||
freeCount: best.userIds.length,
|
||||
freeUsers: team.members.filter((member) =>
|
||||
best.userIds.includes(member.id),
|
||||
),
|
||||
minPlayers,
|
||||
days,
|
||||
},
|
||||
};
|
||||
@@ -2712,6 +2727,7 @@ async function buildBuildNew(ctx: FeedContext) {
|
||||
at: card.at,
|
||||
actorKey: String(card.ownerId),
|
||||
relation: relationOf(ctx, card.ownerId),
|
||||
weaponSplIds: card.card.build.weapons.map((weapon) => weapon.weaponSplId),
|
||||
data: card.card,
|
||||
};
|
||||
});
|
||||
@@ -2754,16 +2770,23 @@ async function buildVodNew(ctx: SharedFeedContext) {
|
||||
video.matches.flatMap((match) => match.players),
|
||||
(player) => player.playerUserId ?? player.playerName,
|
||||
).slice(0, 4);
|
||||
const users = await usersById(
|
||||
players.flatMap((player) =>
|
||||
const users = await usersById([
|
||||
video.submitterUserId,
|
||||
...players.flatMap((player) =>
|
||||
player.playerUserId ? [player.playerUserId] : [],
|
||||
),
|
||||
);
|
||||
]);
|
||||
|
||||
return {
|
||||
at: video.youtubePublishedAt,
|
||||
actorKey: `video-${video.id}`,
|
||||
weaponSplIds: R.unique(
|
||||
video.matches.flatMap((match) =>
|
||||
match.players.map((player) => player.weaponSplId as MainWeaponId),
|
||||
),
|
||||
),
|
||||
data: {
|
||||
submitter: users.get(video.submitterUserId)!,
|
||||
videoId: video.id,
|
||||
title: video.title,
|
||||
type: video.type,
|
||||
|
||||
@@ -18,11 +18,14 @@ export async function load({
|
||||
viewerId,
|
||||
userId,
|
||||
mode,
|
||||
isScoreShown,
|
||||
}: {
|
||||
viewerId: number;
|
||||
/** The logged in user, differs from `viewerId` when a dev views someone else's feed */
|
||||
userId: number;
|
||||
mode: FeedItems.FeedMode;
|
||||
/** Whether each post's ranking score breakdown is included */
|
||||
isScoreShown: boolean;
|
||||
}) {
|
||||
const ctx = await FeedItems.contextFor({ viewerId, mode });
|
||||
const items = (await FeedItems.buildAll(ctx)).filter(
|
||||
@@ -50,7 +53,8 @@ export async function load({
|
||||
activity: FeedRanking.rank(
|
||||
items.filter((item) => !definitionOf(item).isPinned),
|
||||
ctx.now,
|
||||
),
|
||||
ctx.weaponPool,
|
||||
).map((item) => ({ ...item, score: isScoreShown ? item.score : null })),
|
||||
rotations: await FeedItems.allRotations(),
|
||||
rotationsNow: databaseTimestampNow(),
|
||||
interactions: Object.fromEntries(
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { FEED_AUDIENCE_AFFINITY } from "../feed-constants";
|
||||
import {
|
||||
FEED_AUDIENCE_AFFINITY,
|
||||
FEED_WEAPON_AFFINITY,
|
||||
} from "../feed-constants";
|
||||
import * as FeedRanking from "./FeedRanking";
|
||||
|
||||
const NOW = 1_800_000_000;
|
||||
@@ -52,9 +55,9 @@ describe("FeedRanking.score", () => {
|
||||
|
||||
test.each([
|
||||
{
|
||||
why: "no relation: the closest audience of the type",
|
||||
why: "no relation: the widest audience of the type",
|
||||
relation: null,
|
||||
expected: FEED_AUDIENCE_AFFINITY.FOLLOWING,
|
||||
expected: FEED_AUDIENCE_AFFINITY.EVERYONE,
|
||||
},
|
||||
{ why: "self", relation: "SELF", expected: FEED_AUDIENCE_AFFINITY.SELF },
|
||||
{
|
||||
@@ -77,6 +80,101 @@ describe("FeedRanking.score", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("FeedRanking.score", () => {
|
||||
const SPLATTERSHOT = 40;
|
||||
const TENTATEK_SPLATTERSHOT = 41;
|
||||
const HERO_SHOT_REPLICA = 45;
|
||||
const SPLASH_O_MATIC = 20;
|
||||
const SPLAT_CHARGER = 2010;
|
||||
|
||||
test.each([
|
||||
{
|
||||
why: "same weapon",
|
||||
weaponSplIds: [SPLATTERSHOT],
|
||||
expected: FEED_WEAPON_AFFINITY.SAME_WEAPON,
|
||||
},
|
||||
{
|
||||
why: "kit of the same base weapon",
|
||||
weaponSplIds: [TENTATEK_SPLATTERSHOT],
|
||||
expected: FEED_WEAPON_AFFINITY.SAME_WEAPON,
|
||||
},
|
||||
{
|
||||
why: "skin of the same base weapon",
|
||||
weaponSplIds: [HERO_SHOT_REPLICA],
|
||||
expected: FEED_WEAPON_AFFINITY.SAME_WEAPON,
|
||||
},
|
||||
{
|
||||
why: "same weapon among others",
|
||||
weaponSplIds: [SPLASH_O_MATIC, SPLAT_CHARGER, SPLATTERSHOT],
|
||||
expected: FEED_WEAPON_AFFINITY.SAME_WEAPON,
|
||||
},
|
||||
{
|
||||
why: "same category",
|
||||
weaponSplIds: [SPLASH_O_MATIC],
|
||||
expected: FEED_WEAPON_AFFINITY.SAME_CATEGORY,
|
||||
},
|
||||
{
|
||||
why: "other category",
|
||||
weaponSplIds: [SPLAT_CHARGER],
|
||||
expected: FEED_WEAPON_AFFINITY.NONE,
|
||||
},
|
||||
{
|
||||
why: "no weapons",
|
||||
weaponSplIds: [],
|
||||
expected: FEED_WEAPON_AFFINITY.NONE,
|
||||
},
|
||||
] as const)("$why", ({ weaponSplIds, expected }) => {
|
||||
const result = FeedRanking.score(
|
||||
{
|
||||
type: "VOD_NEW",
|
||||
at: NOW,
|
||||
relation: null,
|
||||
weaponSplIds: [...weaponSplIds],
|
||||
},
|
||||
NOW,
|
||||
[TENTATEK_SPLATTERSHOT],
|
||||
);
|
||||
|
||||
expect(result.weaponAffinity).toBe(expected);
|
||||
});
|
||||
|
||||
test("is none without a weapon pool", () => {
|
||||
const result = FeedRanking.score(
|
||||
{
|
||||
type: "VOD_NEW",
|
||||
at: NOW,
|
||||
relation: null,
|
||||
weaponSplIds: [SPLATTERSHOT],
|
||||
},
|
||||
NOW,
|
||||
);
|
||||
|
||||
expect(result.weaponAffinity).toBe(FEED_WEAPON_AFFINITY.NONE);
|
||||
});
|
||||
|
||||
test("scales the score by the weapon affinity", () => {
|
||||
const plain = FeedRanking.score(
|
||||
{ type: "BUILD_NEW", at: NOW, relation: null },
|
||||
NOW,
|
||||
[SPLATTERSHOT],
|
||||
);
|
||||
const matching = FeedRanking.score(
|
||||
{
|
||||
type: "BUILD_NEW",
|
||||
at: NOW,
|
||||
relation: null,
|
||||
weaponSplIds: [SPLATTERSHOT],
|
||||
},
|
||||
NOW,
|
||||
[SPLATTERSHOT],
|
||||
);
|
||||
|
||||
expect(matching.total).toBeCloseTo(
|
||||
plain.total * FEED_WEAPON_AFFINITY.SAME_WEAPON,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("FeedRanking.rank", () => {
|
||||
test("orders by score", () => {
|
||||
const ranked = FeedRanking.rank(
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
import type { MainWeaponId } from "~/modules/in-game-lists/types";
|
||||
import {
|
||||
weaponIdToBaseWeaponId,
|
||||
weaponIdToCategory,
|
||||
} from "~/modules/in-game-lists/weapon-ids";
|
||||
import {
|
||||
FEED_AUDIENCE_AFFINITY,
|
||||
FEED_ITEM_TYPES,
|
||||
@@ -6,6 +11,7 @@ import {
|
||||
FEED_SAME_ACTOR_PENALTY,
|
||||
FEED_SAME_CATEGORY_PENALTY,
|
||||
FEED_SAME_TYPE_REPEAT_PENALTY,
|
||||
FEED_WEAPON_AFFINITY,
|
||||
type FeedItemType,
|
||||
type FeedItemTypeDefinition,
|
||||
type FeedRelation,
|
||||
@@ -21,12 +27,15 @@ export interface RankableItem {
|
||||
relation: FeedRelation | null;
|
||||
/** How strong the item is among those of its type, 0–1, 1 when left out */
|
||||
weight?: number;
|
||||
/** Weapons the item is about, matched against the viewer's weapon pool */
|
||||
weaponSplIds?: MainWeaponId[];
|
||||
}
|
||||
|
||||
export interface ScoreBreakdown {
|
||||
base: number;
|
||||
weight: number;
|
||||
affinity: number;
|
||||
weaponAffinity: number;
|
||||
recency: number;
|
||||
ageHours: number;
|
||||
diversity: number;
|
||||
@@ -35,17 +44,21 @@ export interface ScoreBreakdown {
|
||||
|
||||
/**
|
||||
* Score of an item before the diversity pass: base score of its type × the item's weight × affinity ×
|
||||
* exponential recency decay by the type's half-life. Affinity is that of the item's relation, or without
|
||||
* one the closest audience of its type.
|
||||
* weapon affinity × exponential recency decay by the type's half-life. Affinity is that of the item's
|
||||
* relation, or without one the widest audience of its type.
|
||||
*/
|
||||
export function score(
|
||||
item: Pick<RankableItem, "type" | "at" | "relation" | "weight">,
|
||||
item: Pick<
|
||||
RankableItem,
|
||||
"type" | "at" | "relation" | "weight" | "weaponSplIds"
|
||||
>,
|
||||
now: number,
|
||||
weaponPool: MainWeaponId[] = [],
|
||||
): Omit<ScoreBreakdown, "diversity"> {
|
||||
const definition: FeedItemTypeDefinition = FEED_ITEM_TYPES[item.type];
|
||||
const affinity = item.relation
|
||||
? FEED_AUDIENCE_AFFINITY[FEED_RELATION_AUDIENCE[item.relation]]
|
||||
: Math.max(
|
||||
: Math.min(
|
||||
...definition.audience.map(
|
||||
(audience) => FEED_AUDIENCE_AFFINITY[audience],
|
||||
),
|
||||
@@ -53,14 +66,16 @@ export function score(
|
||||
const ageHours = Math.max(0, (now - item.at) / 3600);
|
||||
const recency = 0.5 ** (ageHours / definition.halfLifeHours);
|
||||
const weight = item.weight ?? 1;
|
||||
const weaponAffinity = weaponAffinityOf(item.weaponSplIds ?? [], weaponPool);
|
||||
|
||||
return {
|
||||
base: definition.baseScore,
|
||||
weight,
|
||||
affinity,
|
||||
weaponAffinity,
|
||||
recency,
|
||||
ageHours,
|
||||
total: definition.baseScore * weight * affinity * recency,
|
||||
total: definition.baseScore * weight * affinity * weaponAffinity * recency,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -82,8 +97,12 @@ export function isStale(item: Pick<RankableItem, "type" | "at">, now: number) {
|
||||
export function rank<T extends RankableItem>(
|
||||
items: T[],
|
||||
now: number,
|
||||
weaponPool: MainWeaponId[] = [],
|
||||
): Array<T & { score: ScoreBreakdown }> {
|
||||
const pool = items.map((item) => ({ item, ...score(item, now) }));
|
||||
const pool = items.map((item) => ({
|
||||
item,
|
||||
...score(item, now, weaponPool),
|
||||
}));
|
||||
const result: Array<T & { score: ScoreBreakdown }> = [];
|
||||
const pickedCountByType = new Map<FeedItemType, number>();
|
||||
|
||||
@@ -127,6 +146,7 @@ export function rank<T extends RankableItem>(
|
||||
base: best.base,
|
||||
weight: best.weight,
|
||||
affinity: best.affinity,
|
||||
weaponAffinity: best.weaponAffinity,
|
||||
recency: best.recency,
|
||||
ageHours: best.ageHours,
|
||||
diversity: bestDiversity,
|
||||
@@ -137,3 +157,20 @@ export function rank<T extends RankableItem>(
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function weaponAffinityOf(
|
||||
weaponSplIds: MainWeaponId[],
|
||||
weaponPool: MainWeaponId[],
|
||||
) {
|
||||
const poolBaseIds = new Set(weaponPool.map(weaponIdToBaseWeaponId));
|
||||
if (weaponSplIds.some((id) => poolBaseIds.has(weaponIdToBaseWeaponId(id)))) {
|
||||
return FEED_WEAPON_AFFINITY.SAME_WEAPON;
|
||||
}
|
||||
|
||||
const poolCategories = new Set(weaponPool.map(weaponIdToCategory));
|
||||
if (weaponSplIds.some((id) => poolCategories.has(weaponIdToCategory(id)))) {
|
||||
return FEED_WEAPON_AFFINITY.SAME_CATEGORY;
|
||||
}
|
||||
|
||||
return FEED_WEAPON_AFFINITY.NONE;
|
||||
}
|
||||
|
||||
118
app/features/feed/core/FeedWeaponTrends.test.ts
Normal file
118
app/features/feed/core/FeedWeaponTrends.test.ts
Normal file
@@ -0,0 +1,118 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import type { MainWeaponId } from "~/modules/in-game-lists/types";
|
||||
import * as FeedWeaponTrends from "./FeedWeaponTrends";
|
||||
|
||||
const PLAYER_COUNT = 100;
|
||||
|
||||
describe("FeedWeaponTrends.risersAndFallers", () => {
|
||||
test("returns null when a week has too few players", () => {
|
||||
const week = players({ count: 10, weaponSplId: 0 });
|
||||
|
||||
expect(
|
||||
FeedWeaponTrends.risersAndFallers({
|
||||
thisWeek: week,
|
||||
lastWeek: week,
|
||||
ordinals: new Map(),
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
test("counts each player once no matter how many maps they played", () => {
|
||||
const lastWeek = players({ count: PLAYER_COUNT, weaponSplId: 0 });
|
||||
const thisWeek = players({ count: PLAYER_COUNT, weaponSplId: 0 });
|
||||
thisWeek[0] = { userId: 0, weaponSplId: 10, count: 1000 };
|
||||
thisWeek[1] = { userId: 1, weaponSplId: 10, count: 1 };
|
||||
thisWeek[2] = { userId: 2, weaponSplId: 10, count: 1 };
|
||||
|
||||
expect(
|
||||
FeedWeaponTrends.risersAndFallers({
|
||||
thisWeek,
|
||||
lastWeek,
|
||||
ordinals: new Map(),
|
||||
})?.rising,
|
||||
).toEqual([
|
||||
{ weaponSplId: 10, sharePercentage: 3, changePercentage: null },
|
||||
]);
|
||||
});
|
||||
|
||||
test("weighs higher ranked players more", () => {
|
||||
const lastWeek = players({ count: PLAYER_COUNT, weaponSplId: 0 });
|
||||
const thisWeek = players({ count: PLAYER_COUNT, weaponSplId: 0 });
|
||||
for (const userId of [0, 1, 2, 3, 4]) {
|
||||
thisWeek[userId] = { userId, weaponSplId: 10, count: 1 };
|
||||
}
|
||||
const ordinals = new Map(
|
||||
Array.from({ length: PLAYER_COUNT }, (_, userId) => [userId, userId]),
|
||||
);
|
||||
const reversedOrdinals = new Map(
|
||||
Array.from({ length: PLAYER_COUNT }, (_, userId) => [userId, -userId]),
|
||||
);
|
||||
|
||||
const highRankedShare = FeedWeaponTrends.risersAndFallers({
|
||||
thisWeek,
|
||||
lastWeek,
|
||||
ordinals: reversedOrdinals,
|
||||
})?.rising[0].sharePercentage;
|
||||
const lowRankedShare = FeedWeaponTrends.risersAndFallers({
|
||||
thisWeek,
|
||||
lastWeek,
|
||||
ordinals,
|
||||
})?.rising[0].sharePercentage;
|
||||
|
||||
expect(highRankedShare).toBeGreaterThan(lowRankedShare!);
|
||||
});
|
||||
|
||||
test("finds a weapon that fell below the minimum share", () => {
|
||||
const lastWeek = [
|
||||
...players({ count: 90, weaponSplId: 0 }),
|
||||
...players({ count: 10, weaponSplId: 10, firstUserId: 90 }),
|
||||
];
|
||||
const thisWeek = [
|
||||
...players({ count: 90, weaponSplId: 20 }),
|
||||
...players({ count: 10, weaponSplId: 0, firstUserId: 90 }),
|
||||
];
|
||||
|
||||
expect(
|
||||
FeedWeaponTrends.risersAndFallers({
|
||||
thisWeek,
|
||||
lastWeek,
|
||||
ordinals: new Map(),
|
||||
})?.falling.map((trend) => trend.weaponSplId),
|
||||
).toEqual([10, 0]);
|
||||
});
|
||||
|
||||
test("leaves out moves smaller than a percentage point", () => {
|
||||
const lastWeek = [
|
||||
...players({ count: 196, weaponSplId: 0 }),
|
||||
...players({ count: 4, weaponSplId: 10, firstUserId: 196 }),
|
||||
];
|
||||
const thisWeek = [
|
||||
...players({ count: 195, weaponSplId: 0 }),
|
||||
...players({ count: 5, weaponSplId: 10, firstUserId: 195 }),
|
||||
];
|
||||
|
||||
expect(
|
||||
FeedWeaponTrends.risersAndFallers({
|
||||
thisWeek,
|
||||
lastWeek,
|
||||
ordinals: new Map(),
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
function players({
|
||||
count,
|
||||
weaponSplId,
|
||||
firstUserId = 0,
|
||||
}: {
|
||||
count: number;
|
||||
weaponSplId: MainWeaponId;
|
||||
firstUserId?: number;
|
||||
}): FeedWeaponTrends.WeaponPicks[] {
|
||||
return Array.from({ length: count }, (_, index) => ({
|
||||
userId: firstUserId + index,
|
||||
weaponSplId,
|
||||
count: 3,
|
||||
}));
|
||||
}
|
||||
140
app/features/feed/core/FeedWeaponTrends.ts
Normal file
140
app/features/feed/core/FeedWeaponTrends.ts
Normal file
@@ -0,0 +1,140 @@
|
||||
import * as R from "remeda";
|
||||
import type { MainWeaponId } from "~/modules/in-game-lists/types";
|
||||
|
||||
/** How much the week's highest ranked player counts compared to its lowest ranked one */
|
||||
const TOP_PLAYER_WEIGHT = 3;
|
||||
const MIN_PLAYERS = 50;
|
||||
/** Weapons below this share in both weeks are left out */
|
||||
const MIN_SHARE = 0.02;
|
||||
/** Smaller week-to-week moves are treated as noise */
|
||||
const MIN_SHARE_CHANGE = 0.01;
|
||||
const RISING_COUNT = 3;
|
||||
const FALLING_COUNT = 2;
|
||||
|
||||
export interface WeaponPicks {
|
||||
userId: number;
|
||||
weaponSplId: MainWeaponId;
|
||||
count: number;
|
||||
}
|
||||
|
||||
interface WeaponTrend {
|
||||
weaponSplId: MainWeaponId;
|
||||
sharePercentage: number;
|
||||
/** `null` when the weapon wasn't played at all last week */
|
||||
changePercentage: number | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Weapons whose share of play rose and fell the most from last week to this week. Every player's weapon mix
|
||||
* counts once, weighted from 1 (lowest ranked or unranked) to `TOP_PLAYER_WEIGHT` (highest ranked) by their
|
||||
* ordinal among the week's players. `null` when either week has too few players or there is no clear riser and faller.
|
||||
*/
|
||||
export function risersAndFallers({
|
||||
thisWeek,
|
||||
lastWeek,
|
||||
ordinals,
|
||||
}: {
|
||||
thisWeek: WeaponPicks[];
|
||||
lastWeek: WeaponPicks[];
|
||||
/** Skill ordinal by user id */
|
||||
ordinals: Map<number, number>;
|
||||
}) {
|
||||
const playerCount = R.unique(thisWeek.map((picks) => picks.userId)).length;
|
||||
const previousPlayerCount = R.unique(
|
||||
lastWeek.map((picks) => picks.userId),
|
||||
).length;
|
||||
if (playerCount < MIN_PLAYERS || previousPlayerCount < MIN_PLAYERS) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const shares = weightedShares(thisWeek, ordinals);
|
||||
const previousShares = weightedShares(lastWeek, ordinals);
|
||||
|
||||
const trends = R.unique([...shares.keys(), ...previousShares.keys()])
|
||||
.map((weaponSplId) => ({
|
||||
weaponSplId,
|
||||
share: shares.get(weaponSplId) ?? 0,
|
||||
previousShare: previousShares.get(weaponSplId) ?? 0,
|
||||
}))
|
||||
.filter(
|
||||
({ share, previousShare }) =>
|
||||
Math.max(share, previousShare) >= MIN_SHARE &&
|
||||
Math.abs(share - previousShare) >= MIN_SHARE_CHANGE,
|
||||
);
|
||||
|
||||
const rising = R.sortBy(
|
||||
trends.filter(({ share, previousShare }) => share > previousShare),
|
||||
[
|
||||
({ share, previousShare }) =>
|
||||
previousShare === 0 ? Number.POSITIVE_INFINITY : share / previousShare,
|
||||
"desc",
|
||||
],
|
||||
).slice(0, RISING_COUNT);
|
||||
const falling = R.sortBy(
|
||||
trends.filter(({ share, previousShare }) => share < previousShare),
|
||||
({ share, previousShare }) => share / previousShare,
|
||||
).slice(0, FALLING_COUNT);
|
||||
if (rising.length === 0 || falling.length === 0) return null;
|
||||
|
||||
return {
|
||||
rising: rising.map(toWeaponTrend),
|
||||
falling: falling.map(toWeaponTrend),
|
||||
playerCount,
|
||||
};
|
||||
}
|
||||
|
||||
function weightedShares(picks: WeaponPicks[], ordinals: Map<number, number>) {
|
||||
const picksByUserId = Map.groupBy(picks, (pick) => pick.userId);
|
||||
const weights = rankWeights([...picksByUserId.keys()], ordinals);
|
||||
const totalWeight = R.sum([...weights.values()]);
|
||||
|
||||
const result = new Map<MainWeaponId, number>();
|
||||
for (const [userId, userPicks] of picksByUserId) {
|
||||
const userPickCount = R.sumBy(userPicks, (pick) => pick.count);
|
||||
const userShare = weights.get(userId)! / totalWeight;
|
||||
|
||||
for (const pick of userPicks) {
|
||||
result.set(
|
||||
pick.weaponSplId,
|
||||
(result.get(pick.weaponSplId) ?? 0) +
|
||||
(userShare * pick.count) / userPickCount,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function rankWeights(userIds: number[], ordinals: Map<number, number>) {
|
||||
const rankedLowestFirst = R.sortBy(
|
||||
userIds.filter((userId) => ordinals.has(userId)),
|
||||
(userId) => ordinals.get(userId)!,
|
||||
);
|
||||
const lastIndex = Math.max(rankedLowestFirst.length - 1, 1);
|
||||
|
||||
const result = new Map(userIds.map((userId) => [userId, 1]));
|
||||
for (const [index, userId] of rankedLowestFirst.entries()) {
|
||||
result.set(userId, 1 + ((TOP_PLAYER_WEIGHT - 1) * index) / lastIndex);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function toWeaponTrend({
|
||||
weaponSplId,
|
||||
share,
|
||||
previousShare,
|
||||
}: {
|
||||
weaponSplId: MainWeaponId;
|
||||
share: number;
|
||||
previousShare: number;
|
||||
}): WeaponTrend {
|
||||
return {
|
||||
weaponSplId,
|
||||
sharePercentage: Math.round(share * 1000) / 10,
|
||||
changePercentage:
|
||||
previousShare === 0
|
||||
? null
|
||||
: Math.round((share / previousShare - 1) * 100),
|
||||
};
|
||||
}
|
||||
@@ -214,6 +214,7 @@ export const FEED_ITEM_TYPES = {
|
||||
audience: ["SELF"],
|
||||
baseScore: 0.35,
|
||||
halfLifeHours: 96,
|
||||
isNotice: true,
|
||||
},
|
||||
TO_VOD: {
|
||||
name: "Tournament VoD",
|
||||
@@ -323,6 +324,7 @@ export const FEED_ITEM_TYPES = {
|
||||
audience: ["TEAM"],
|
||||
baseScore: 0.6,
|
||||
halfLifeHours: 48,
|
||||
isNotice: true,
|
||||
},
|
||||
TEAM_EVENT_ADDED: {
|
||||
name: "Team event added",
|
||||
@@ -404,6 +406,7 @@ export const FEED_ITEM_TYPES = {
|
||||
audience: ["FOLLOWING", "EVERYONE"],
|
||||
baseScore: 0.35,
|
||||
halfLifeHours: 72,
|
||||
isNotice: true,
|
||||
},
|
||||
XRANK_TOP_500: {
|
||||
name: "X Rank Top 500",
|
||||
@@ -434,6 +437,7 @@ export const FEED_ITEM_TYPES = {
|
||||
audience: ["SELF"],
|
||||
baseScore: 0.4,
|
||||
halfLifeHours: 168,
|
||||
isNotice: true,
|
||||
},
|
||||
|
||||
COMEBACK: {
|
||||
@@ -467,6 +471,7 @@ export const FEED_ITEM_TYPES = {
|
||||
audience: ["SELF"],
|
||||
baseScore: 0.4,
|
||||
halfLifeHours: 48,
|
||||
isNotice: true,
|
||||
},
|
||||
ARTICLE_NEW: {
|
||||
name: "New article",
|
||||
@@ -564,6 +569,15 @@ export const FEED_SAME_ACTOR_PENALTY = 0.6;
|
||||
/** Diversity pass: penalty for each item of the same type already picked */
|
||||
export const FEED_SAME_TYPE_REPEAT_PENALTY = 0.75;
|
||||
|
||||
/** Bonus for an item about a weapon the viewer plays, the `weaponAffinity` term of the ranking score */
|
||||
export const FEED_WEAPON_AFFINITY = {
|
||||
/** Same base weapon as one in the viewer's weapon pool */
|
||||
SAME_WEAPON: 2,
|
||||
/** Same category as a weapon in the viewer's weapon pool */
|
||||
SAME_CATEGORY: 1.3,
|
||||
NONE: 1,
|
||||
} as const;
|
||||
|
||||
/** Weeks of match history used to find the hours a user usually plays */
|
||||
export const FEED_ROTATION_LOOKBACK_WEEKS = 8;
|
||||
/** An hour of the week is a usual play hour once it has matches on this many different weeks */
|
||||
|
||||
@@ -193,10 +193,10 @@ export const FEED_SOURCE_FEATURES: FeedSourceFeature[] = [
|
||||
},
|
||||
{
|
||||
item: "TO_UPSET",
|
||||
when: "A friend's team is in an upset: it beats a team seeded at least 5 places higher, or a team seeded at least 5 places lower beats it. The post says which friend, so it's clear why it's in your feed.",
|
||||
when: "A friend's team pulls off an upset: it beats a team seeded at least 5 places higher. Only wins, never a friend's team being upset. The post says which friend, so it's clear why it's in your feed.",
|
||||
example: {
|
||||
actor: "Callie",
|
||||
text: "**Callie**'s team, seeded 10, knocked out seed 1 at **In The Zone 55**",
|
||||
text: "**Callie**'s team (seed 10) upset seed 1 at **In The Zone 55**",
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -479,7 +479,7 @@ export const FEED_SOURCE_FEATURES: FeedSourceFeature[] = [
|
||||
when: "Enough of your team has filled in availability for the week to find a shared window.",
|
||||
example: {
|
||||
actor: "Kraken",
|
||||
text: "**4 of 5** on Kraken Kids are free together · Fri 21:00",
|
||||
text: "**4 of 5** on Kraken Kids are free together · **3 days** with 4+",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -33,6 +33,8 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
|
||||
viewerId: viewAs ?? user.id,
|
||||
userId: user.id,
|
||||
mode: test ? "TEST" : "REAL",
|
||||
isScoreShown:
|
||||
user.roles.includes("ADMIN") || user.roles.includes("DEV"),
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -73,33 +73,22 @@ export default function FrontPage() {
|
||||
|
||||
function FeedFrontPage({ data }: { data: FeedPageData }) {
|
||||
const [test, setTest] = useSearchParam(feedSearchParams, "test");
|
||||
const [showRankingMath, setShowRankingMath] = React.useState(false);
|
||||
|
||||
return (
|
||||
<Main bigger>
|
||||
<Feed
|
||||
data={data}
|
||||
canViewAs
|
||||
scoreShown={showRankingMath}
|
||||
headerEnd={
|
||||
<div className="stack horizontal md">
|
||||
<SendouSwitch
|
||||
isSelected={test}
|
||||
onChange={(isSelected) =>
|
||||
setTest(isSelected, { preventScrollReset: true })
|
||||
}
|
||||
size="small"
|
||||
>
|
||||
Test items
|
||||
</SendouSwitch>
|
||||
<SendouSwitch
|
||||
isSelected={showRankingMath}
|
||||
onChange={setShowRankingMath}
|
||||
size="small"
|
||||
>
|
||||
Show ranking math
|
||||
</SendouSwitch>
|
||||
</div>
|
||||
<SendouSwitch
|
||||
isSelected={test}
|
||||
onChange={(isSelected) =>
|
||||
setTest(isSelected, { preventScrollReset: true })
|
||||
}
|
||||
size="small"
|
||||
>
|
||||
Test items
|
||||
</SendouSwitch>
|
||||
}
|
||||
footer={
|
||||
test ? (
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export const SPLATOON_ROTATION_TYPES = ["SERIES", "OPEN", "X"] as const;
|
||||
export const SPLATOON_ROTATION_TYPES = ["X", "SERIES", "OPEN"] as const;
|
||||
|
||||
export type SplatoonRotationType = (typeof SPLATOON_ROTATION_TYPES)[number];
|
||||
|
||||
@@ -555,8 +555,8 @@ export function buildCases(fx: Fixtures): {
|
||||
fx.topTeammatesUserId,
|
||||
(userId) => FeedRepository.findTopTeammatesByUserId(userId),
|
||||
);
|
||||
add("FeedRepository.findWeaponUsageCounts", fx.feedNow, (now) =>
|
||||
FeedRepository.findWeaponUsageCounts({ from: now - 7 * DAY, to: now }),
|
||||
add("FeedRepository.findWeaponPicksByUser", fx.feedNow, (now) =>
|
||||
FeedRepository.findWeaponPicksByUser({ from: now - 7 * DAY, to: now }),
|
||||
);
|
||||
add("FeedRepository.findAllLobbiesEndedAfter", fx.feedNow, (now) =>
|
||||
FeedRepository.findAllLobbiesEndedAfter(
|
||||
@@ -771,11 +771,6 @@ export function buildCases(fx: Fixtures): {
|
||||
teamIds,
|
||||
}),
|
||||
);
|
||||
add(
|
||||
"FeedRepository.findAvailabilitySlotsOfTeamWeek",
|
||||
fx.heavyTeamAvailabilityWeek,
|
||||
(week) => FeedRepository.findAvailabilitySlotsOfTeamWeek(week),
|
||||
);
|
||||
add(
|
||||
"FeedRepository.findOpenScrimPostsForViewer",
|
||||
both(fx.heavyTeam, fx.feedNow),
|
||||
|
||||
@@ -169,8 +169,6 @@ export interface Fixtures {
|
||||
manyTeamIds: number[] | null;
|
||||
/** Leaderboard series of the organization with the most events. */
|
||||
heavySeries: { organizationId: number; substringMatches: string[] } | null;
|
||||
/** Team week with the most availability slots filled. */
|
||||
heavyTeamAvailabilityWeek: { teamId: number; weekStartsAt: number } | null;
|
||||
scannedMatchId: number | null;
|
||||
siteTotalCounts: Record<FeedRepository.SiteTotal, number> | null;
|
||||
/** Posts with the most comments, the heaviest first. Null until users have commented. */
|
||||
@@ -275,7 +273,6 @@ export async function resolveFixtures(): Promise<Fixtures> {
|
||||
await resolveFeedIndexerTournamentResultRowId(feedNow),
|
||||
manyTeamIds: await resolveManyTeamIds(),
|
||||
heavySeries: await resolveHeavySeries(),
|
||||
heavyTeamAvailabilityWeek: await resolveHeavyTeamAvailabilityWeek(),
|
||||
scannedMatchId: await resolveScannedMatchId(),
|
||||
siteTotalCounts: await resolveSiteTotalCounts(),
|
||||
feedCommentItemIds: await resolveFeedCommentItemIds(),
|
||||
@@ -1757,34 +1754,6 @@ async function resolveHeavySeries() {
|
||||
};
|
||||
}
|
||||
|
||||
async function resolveHeavyTeamAvailabilityWeek() {
|
||||
const row = await db
|
||||
.selectFrom("AvailabilitySlot")
|
||||
.innerJoin(
|
||||
"AvailabilityWeek",
|
||||
"AvailabilityWeek.id",
|
||||
"AvailabilitySlot.availabilityWeekId",
|
||||
)
|
||||
.innerJoin(
|
||||
"AllTeamMember",
|
||||
"AllTeamMember.userId",
|
||||
"AvailabilityWeek.userId",
|
||||
)
|
||||
.select(({ fn }) => [
|
||||
"AllTeamMember.teamId",
|
||||
"AvailabilityWeek.weekStartsAt",
|
||||
fn.countAll<number>().as("count"),
|
||||
])
|
||||
.where("AllTeamMember.leftAt", "is", null)
|
||||
.groupBy(["AllTeamMember.teamId", "AvailabilityWeek.weekStartsAt"])
|
||||
.orderBy("count", "desc")
|
||||
.limit(1)
|
||||
.executeTakeFirst();
|
||||
if (!row) return null;
|
||||
|
||||
return { teamId: row.teamId, weekStartsAt: row.weekStartsAt };
|
||||
}
|
||||
|
||||
async function resolveScannedMatchId() {
|
||||
const row = await db
|
||||
.selectFrom("IngestedMatch")
|
||||
|
||||
Reference in New Issue
Block a user