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
6 changes: 5 additions & 1 deletion convex/screening/cards.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ it("counts a source's papers and a reviewer's by where they stand, follows a pap
const { jobId, papers } = await started(made, ["ann", "ben"], 3);
const source = papers[0]!.sourceId!;
const vote = (name: string, paperId: Id<"screeningResults">, decision: "include" | "exclude") => made.as[name]!.mutation(api.screening.voting.vote, { workspaceId, jobId, paperId, decision, ...(decision === "exclude" ? { reason: "other" } : {}) });
const counts = (name: string, narrowed: object = {}) => made.as[name]!.query(api.screening.paperViews.counts, { workspaceId, jobId, ...narrowed });
// Counts are kept by a worker a moment after each change (./facets.ts): it runs before each is read.
const counts = async (name: string, narrowed: object = {}) => {
await made.t.finishAllScheduledFunctions(vi.runAllTimers);
return await made.as[name]!.query(api.screening.paperViews.counts, { workspaceId, jobId, ...narrowed });
};
expect(await counts("ann", { source })).toEqual({ include: 0, maybe: 0, exclude: 0, conflict: 0, waiting: 3 });

// The first is included by both, the second splits them, the third waits for Ben.
Expand Down
22 changes: 16 additions & 6 deletions convex/screening/paperViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { placeOf } from "./settling";
import { decisionValidator, paperResultValidator, paperViewValidator, voteViewValidator } from "./validators";
import { progressRow } from "./bookkeeping";
import { keepsVotes } from "./view";
import { tallyForReason, tallyOfReviewer, tallyUnder } from "./facets";

type Paper = Doc<"screeningResults">;
type Vote = Doc<"screeningVotes">;
Expand Down Expand Up @@ -186,19 +187,28 @@ export const counts = workspaceQuery({
if (!looking) return null;
const check = asked === "start" ? looking.first : asked;
if (asked === "start" && !check) return null;
const row = reviewer ? [...looking.reviewers.values()].find((one) => viewId(one) === reviewer || one._id === reviewer) : undefined;
if (reviewer && !row) return null;
// Which way someone else voted is kept from a reviewer who still has papers to vote on (./view.ts `keepsVotes`): so is how many they voted each way.
const others = row && voted && voted !== "none" && voted !== "failed" && row._id !== looking.reviewer?._id;
if (others && !showsEarly(looking.job.rule!, row.kind) && keepsVotes(looking.job, looking.reviewer, (await progressRow(ctx as QueryCtx, jobId))?.reviewers, looking.reviewers.values(), (await invitationsTo(ctx, jobId)).length)) return null;
// Narrowed one way, the counts are kept already (./facets.ts): a few counted reads, whatever the screening's size.
const narrowed = [source, check, reason, row].filter(Boolean).length;
if (narrowed === 1) {
if (row) return await tallyOfReviewer(ctx, row._id, voted === "none" ? ["waiting"] : voted === "failed" ? ["failed"] : voted ? [voted] : ["include", "maybe", "exclude", "cast"]);
if (source) return await tallyUnder(ctx, jobId, { source });
if (check) return await tallyUnder(ctx, jobId, { check });
return await tallyForReason(ctx, jobId, reason!);
}
// Narrowed two ways at once, the papers' cards are counted one by one. ponytail: a namespace per pair of narrowings would count those too, if they come to be used on large screenings.
const keeps = (card: Doc<"screeningCards">) => !card.withdrawn && (!source || card.sourceId === source) && (!check || card.checkId === check) && (!reason || (card.result === "exclude" && (card.reason ?? NO_REASON) === reason));
const tally = { include: 0, maybe: 0, exclude: 0, conflict: 0, waiting: 0 };
const cards = await ctx.db.query("screeningCards").withIndex("by_job", (q) => q.eq("jobId", jobId)).take(COUNTED + 1);
if (cards.length > COUNTED) return null;
if (!reviewer) {
if (!row) {
for (const card of cards) if (keeps(card)) tally[card.result]++;
return tally;
}
const row = [...looking.reviewers.values()].find((one) => viewId(one) === reviewer || one._id === reviewer);
if (!row) return null;
// Which way someone else voted is kept from a reviewer who still has papers to vote on (./view.ts `keepsVotes`): so is how many they voted each way.
const others = voted && voted !== "none" && voted !== "failed" && row._id !== looking.reviewer?._id;
if (others && !showsEarly(looking.job.rule!, row.kind) && keepsVotes(looking.job, looking.reviewer, (await progressRow(ctx as QueryCtx, jobId))?.reviewers, looking.reviewers.values(), (await invitationsTo(ctx, jobId)).length)) return null;
const votes = ctx.db.query("screeningVotes");
const theirs = await (voted === "none" || voted === "failed"
? votes.withIndex("by_reviewer_and_status_and_place", (q) => q.eq("reviewerId", row._id).eq("status", voted === "none" ? "waiting" : "failed"))
Expand Down
4 changes: 2 additions & 2 deletions convex/screening/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { dealable, firstCheck, inWhole, invitationsTo, laterChecks, modelName, m
import { noticeOf } from "./notices";
import { NO_RESULTS } from "./settling";
import { askedWhereValidator, ruleValidator, invitedViewValidator, libraryWriteProblemValidator, retiredCriteriaValidator, unreadSourcesValidator, modelVotesValidator, checkSourcesValidator, criteriaValidator, ELSEWHERE_MAX, elsewhereValidator, everyValidator, figuresValidator, leftOutWhyValidator, PAIRS_MAX, reviewerViewsValidator, reviewerViewValidator, sourceViewsValidator, starsValidator } from "./validators";
import { castSince } from "./facets";


const personValidator = v.object({ id: v.id("users"), name: v.string(), imageUrl: v.optional(v.string()) });
Expand Down Expand Up @@ -497,7 +498,6 @@ const CHANGED = new Set(["settings", "reviewerAdded", "reviewerRemoved", "madeVi
/** Checks counted for a methods paragraph, saves of its settings counted, and votes counted for a person's pace. */
const CHECKS_COUNTED = 400;
const CHANGES_COUNTED = 200;
const RECENT_VOTES = 500;

export const figuresAction = defineUserQuery({
path: "screening/view:figures",
Expand All @@ -518,7 +518,7 @@ export const figuresAction = defineUserQuery({
]);
const idOf = new Map(reviewers.map((one) => [one._id, viewId(one)]));
const people = reviewers.filter((one) => one.kind === "person" && one.left === undefined && one.userId);
const recent = await Promise.all(people.map(async (one) => [viewId(one), (await ctx.db.query("screeningVotes").withIndex("by_reviewer_and_status_and_at", (q) => q.eq("reviewerId", one._id).eq("status", "cast").gte("at", since)).take(RECENT_VOTES)).length] as const));
const recent = await Promise.all(people.map(async (one) => [viewId(one), await castSince(ctx as QueryCtx, one._id, since)] as const));
// The searches for papers its sources gained. A save that read a source it added or widened searched nothing again.
const later = checks.filter((check) => check.search && check.state === "done");
return {
Expand Down
1 change: 0 additions & 1 deletion scripts/convex-rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@
"PAIRS_MAX": "the pairs of reviewers a screening's overview draws agreement for; a screening with more reviewers than that many pairs shows the first",
"CHECKS_COUNTED": "a screening's checks for new papers counted for its methods paragraph: the first of them",
"CHANGES_COUNTED": "a screening's latest activity, looked through for how often its settings were changed",
"RECENT_VOTES": "one person's votes of the last days, counted for their pace",
"CHECK_COUNTED": "the papers one check added, looked at for where they stand; a check that added more shows no such count",
"READING_LOOKED": "The rail looks at a workspace's newest open screenings for one whose models are reading: the first few, since the ring shows one."
},
Expand Down