Skip to content

Commit

Permalink
Make ingestDays available to evaluation discoverers #3234
Browse files Browse the repository at this point in the history
  • Loading branch information
giorgiosironi committed May 13, 2024
1 parent ba6eb64 commit 718397f
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ const toHumanFriendlyErrorMessage = (
(formattedErrors) => `acmi: could not decode crossref response ${formattedErrors.join(', ')}`,
);

export const discoverEvaluationsForAccessMicrobiologyViaCrossref: DiscoverPublishedEvaluations = (dependencies) => pipe(
export const discoverEvaluationsForAccessMicrobiologyViaCrossref: DiscoverPublishedEvaluations = () => (
dependencies,
) => pipe(
'https://api.crossref.org/works?filter=prefix:10.1099,type:peer-review,relation.type:is-review-of&sort=published&order=asc',
dependencies.fetchData,
TE.chainEitherK(flow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const identifyCandidates = (doiPrefix: string, reviewDoiPrefix: string) => {
export const discoverEvaluationsFromCrossrefViaBiorxiv = (
doiPrefix: string,
reviewDoiPrefix: string,
): DiscoverPublishedEvaluations => () => pipe(
): DiscoverPublishedEvaluations => () => () => pipe(
identifyCandidates(doiPrefix, reviewDoiPrefix),
TE.map(RA.map(toEvaluation)),
TE.map((evaluations) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const calculateEarliestPublicationDateToConsider = (earliestPublicationDateToCon
export const discoverEvaluationsFromHypothesisGroup = (
publisherGroupId: string,
avoidWhenPublishedBefore?: Date,
): DiscoverPublishedEvaluations => (ports: Ports) => pipe(
): DiscoverPublishedEvaluations => () => (ports: Ports) => pipe(
publisherGroupId,
Hyp.fetchEvaluationsByGroupSince(
calculateEarliestPublicationDateToConsider(avoidWhenPublishedBefore),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Ports = {
export const discoverEvaluationsFromHypothesisUser = (
publisherUserId: string,
daysToLookBackForAcceptablePerformance = 5,
): DiscoverPublishedEvaluations => (ports: Ports) => pipe(
): DiscoverPublishedEvaluations => () => (ports: Ports) => pipe(
publisherUserId,
Hyp.fetchEvaluationsByUserSince(ingestionWindowStartDate(daysToLookBackForAcceptablePerformance), ports.fetchData),
TE.map(RA.map(convertHypothesisAnnotationToEvaluation(tagToEvaluationTypeMap))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type Ports = {
fetchData: FetchData,
};

export const discoverPciEvaluations = (url: string): DiscoverPublishedEvaluations => (ports: Ports) => pipe(
export const discoverPciEvaluations = (url: string): DiscoverPublishedEvaluations => () => (ports: Ports) => pipe(
ports.fetchData<string>(url),
TE.map(identifyCandidates),
TE.map(RA.map(toEvaluationOrSkip)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const identifyCandidates = (fetchData: FetchData) => pipe(
)),
);

export const discoverPrereviewEvaluations = (): DiscoverPublishedEvaluations => (ports: Ports) => pipe(
export const discoverPrereviewEvaluations = (): DiscoverPublishedEvaluations => () => (ports: Ports) => pipe(
identifyCandidates(ports.fetchData),
TE.map(RA.map(toEvaluationOrSkip)),
TE.map((parts) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const toEvaluationOrSkip = (candidate: CR.CrossrefReview) => pipe(
})),
);

export const discoverRapidReviewsEvaluations = (): DiscoverPublishedEvaluations => (ports: Ports) => pipe(
export const discoverRapidReviewsEvaluations = (): DiscoverPublishedEvaluations => () => (ports: Ports) => pipe(
identifyCandidates(ports.fetchData),
TE.map(RA.map(toEvaluationOrSkip)),
TE.map((parts) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Dependencies = {
fetchData: FetchData,
};

export const fetchPrelightsEvaluations = (): DiscoverPublishedEvaluations => (dependencies: Dependencies) => pipe(
export const fetchPrelightsEvaluations = (): DiscoverPublishedEvaluations => () => (dependencies: Dependencies) => pipe(
keyFromEnv,
TE.fromEither,
TE.map((key) => `https://prelights.biologists.com/feed/sciety/?key=${key}&hours=120`),
Expand Down
5 changes: 4 additions & 1 deletion src/ingest/update-all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { DiscoveredPublishedEvaluations } from './types/discovered-published-eva
type Adapters = { fetchData: FetchData };

export type DiscoverPublishedEvaluations = (
ingestDays: number,
) => (
adapters: Adapters
) => TE.TaskEither<string, DiscoveredPublishedEvaluations>;

Expand Down Expand Up @@ -144,7 +146,8 @@ const sendRecordEvaluationCommands = (
);

const updateGroup = (config: Config) => (group: GroupIngestionConfiguration): TE.TaskEither<unknown, void> => pipe(
group.discoverPublishedEvaluations({ fetchData }),
{ fetchData },
group.discoverPublishedEvaluations(config.ingestDays),
TE.bimap(
(error) => ({
groupName: group.name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as E from 'fp-ts/Either';
import * as TE from 'fp-ts/TaskEither';
import { pipe } from 'fp-ts/function';
import { arbitraryIngestDays } from './ingest-days.helper';
import { discoverPciEvaluations } from '../../../src/ingest/evaluation-discovery/discover-pci-evaluations';
import { ingestionWindowStartDate } from '../../../src/ingest/time';
import { constructPublishedEvaluation } from '../../../src/ingest/types/published-evaluation';
Expand All @@ -13,7 +14,7 @@ const discover = (xml: string) => pipe(
fetchData: <D>() => TE.right(xml as unknown as D),
fetchGoogleSheet: shouldNotBeCalled,
},
discoverPciEvaluations(arbitraryUri()),
discoverPciEvaluations(arbitraryUri())(arbitraryIngestDays()),
);

describe('discover-pci-evaluations', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as TE from 'fp-ts/TaskEither';
import { pipe } from 'fp-ts/function';
import { arbitraryIngestDays } from './ingest-days.helper';
import { discoverPrereviewEvaluations } from '../../../src/ingest/evaluation-discovery/discover-prereview-evaluations';
import { DiscoveredPublishedEvaluations } from '../../../src/ingest/types/discovered-published-evaluations';
import { constructPublishedEvaluation } from '../../../src/ingest/types/published-evaluation';
Expand All @@ -10,7 +11,7 @@ import { arbitraryArticleId } from '../../types/article-id.helper';

const runDiscovery = (stubbedResponse: unknown) => pipe(
({ fetchData: <D>() => TE.right({ data: stubbedResponse } as unknown as D) }),
discoverPrereviewEvaluations(),
discoverPrereviewEvaluations()(arbitraryIngestDays()),
);

describe('discover-prereview-evaluations', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as E from 'fp-ts/Either';
import * as T from 'fp-ts/Task';
import * as TE from 'fp-ts/TaskEither';
import { pipe } from 'fp-ts/function';
import { arbitraryIngestDays } from './ingest-days.helper';
import { discoverRapidReviewsEvaluations } from '../../../src/ingest/evaluation-discovery/discover-rapid-reviews-evaluations';
import { DiscoveredPublishedEvaluations } from '../../../src/ingest/types/discovered-published-evaluations';
import { constructPublishedEvaluation } from '../../../src/ingest/types/published-evaluation';
Expand All @@ -14,7 +15,7 @@ const ingest = (crossrefResponseItems: ReadonlyArray<unknown>) => pipe(
fetchData: <D>() => TE.right({ message: { items: crossrefResponseItems } } as unknown as D),
fetchGoogleSheet: shouldNotBeCalled,
},
discoverRapidReviewsEvaluations(),
discoverRapidReviewsEvaluations()(arbitraryIngestDays()),
);

describe('discover-rapid-reviews-evaluations', () => {
Expand Down
1 change: 1 addition & 0 deletions test/ingest/evaluation-discovery/ingest-days.helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const arbitraryIngestDays = (): number => 5;

0 comments on commit 718397f

Please sign in to comment.