Skip to content

Commit

Permalink
Add juritj (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLibeau authored Aug 7, 2023
1 parent f718a09 commit 824712b
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 12 deletions.
5 changes: 5 additions & 0 deletions docs/scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ Import from the SDER database JuriCA decisions to pseudonymise chained with Juri

Import from the SDER database recent JuriCA decisions to pseudonymise.

## importJuritjDocuments

Import from the SDER database recent JuriTJ decisions to pseudonymise.


## importNewDocumentsFromSder

Same as `autoImportDocumentsFromSder`, but without the `threshold` option.
Expand Down
4 changes: 2 additions & 2 deletions packages/courDeCassation/src/connector/fetcher/sderFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const sderFetcher = {
}: {
startDate: Date;
endDate: Date;
source: 'jurinet' | 'jurica';
source: 'jurinet' | 'jurica' | 'juritj';
}) {
const courtDecisions = await sderApi.fetchDecisionsToPseudonymiseBetween({
startDate,
Expand Down Expand Up @@ -54,7 +54,7 @@ const sderFetcher = {
}: {
startDate: Date;
endDate: Date;
source: 'jurinet' | 'jurica';
source: 'jurinet' | 'jurica' | 'juritj';
}) {
const courtDecisions = await sderApi.fetchDecisionsToPseudonymiseBetweenDateCreation(
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
import { extractRoute } from '.';

describe('extractRoute', () => {
it('should return exhaustive because it is juritj', async () => {
const route = extractRoute(
{
additionalTermsToAnnotate: '',
solution: '',
publicationCategory: ['W'],
chamberId: 'CR',
civilCaseCode: '',
civilMatterCode: '',
criminalCaseCode: '',
session: '',
NACCode: '',
endCaseCode: '',
},
'juritj',
);

expect(route).toBe('exhaustive');
});

it('should return exhaustive if no endCaseCode & no NACCode', async () => {
const route = extractRoute(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { logger } from '@label/backend';
import { documentType } from '@label/core';
import { extractRouteForJurica } from './extractRouteForJurica';
import { extractRouteForJurinet } from './extractRouteForJurinet';
import { extractRouteForJuritj } from './extractRouteForJuritj';

export { extractRoute };

Expand Down Expand Up @@ -39,6 +40,14 @@ function extractRoute(
route = 'exhaustive';
}
break;
case 'juritj':
try {
route = extractRouteForJuritj({ ...routeInfos });
} catch (e) {
logger.log(e);
route = 'exhaustive';
}
break;
}

if (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { documentType } from '@label/core';

export { extractRouteForJuritj };

function extractRouteForJuritj({}: {
session: documentType['decisionMetadata']['session'];
solution: documentType['decisionMetadata']['solution'];
publicationCategory: documentType['publicationCategory'];
chamberId: string;
civilMatterCode: documentType['decisionMetadata']['civilMatterCode'];
civilCaseCode: documentType['decisionMetadata']['civilCaseCode'];
criminalCaseCode: documentType['decisionMetadata']['criminalCaseCode'];
NACCode: documentType['decisionMetadata']['NACCode'];
endCaseCode: documentType['decisionMetadata']['endCaseCode'];
}): documentType['route'] {
return 'exhaustive';
}
31 changes: 31 additions & 0 deletions packages/courDeCassation/src/scripts/importJuritjDocuments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import yargs from 'yargs';
import { buildBackend } from '@label/backend';
import { sderConnector } from '../connector';
import { parametersHandler } from '../lib/parametersHandler';

(async () => {
const { environment, settings } = await parametersHandler.getParameters();
const { count } = parseArgv();
const backend = buildBackend(environment, settings);

backend.runScript(() => sderConnector.importJuritjDocuments(count), {
shouldLoadDb: true,
});
})();

function parseArgv() {
const argv = yargs
.options({
count: {
demandOption: true,
description: 'number of documents you want to import',
type: 'number',
},
})
.help()
.alias('help', 'h').argv;

return {
count: argv.count as number,
};
}
4 changes: 2 additions & 2 deletions packages/courDeCassation/src/sderApi/sderApiType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ type sderApiType = {
fetchDecisionsToPseudonymiseBetween: (params: {
startDate: Date;
endDate: Date;
source: 'jurinet' | 'jurica';
source: 'jurinet' | 'jurica' | 'juritj';
}) => Promise<Array<decisionType>>;
fetchDecisionsToPseudonymiseBetweenDateCreation: (params: {
startDate: Date;
endDate: Date;
source: 'jurinet' | 'jurica';
source: 'jurinet' | 'jurica' | 'juritj';
}) => Promise<Array<decisionType>>;
fetchCourtDecisionBySourceIdAndSourceName: (
sourceId: decisionType['sourceId'],
Expand Down
103 changes: 101 additions & 2 deletions packages/generic/backend/src/lib/connector/buildConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function buildConnector(connectorConfig: connectorConfigType) {
importSpecificDocument,
importNewDocuments,
importJuricaDocuments,
importJuritjDocuments,
importDocumentsByJurisdictionBetween,
importDocumentsSince,
importDocumentsSinceDateCreation,
Expand Down Expand Up @@ -119,6 +120,58 @@ function buildConnector(connectorConfig: connectorConfigType) {
logger.log(`DONE`);
}

async function importJuritjDocuments(documentsCount: number) {
logger.log(`importJuritjDocuments: ${documentsCount}`);

logger.log(`Fetching ${connectorConfig.name} documents...`);
let daysAgo = 0;
let step = 0;
const daysStep = 10;
const MAX_STEP = 120;

const newDocuments: documentType[] = [];
while (newDocuments.length < documentsCount && step < MAX_STEP) {
const startDate = new Date(dateBuilder.daysAgo(daysAgo + daysStep));
const endDate = new Date(dateBuilder.daysAgo(daysAgo));
const newCourtDecisions = await connectorConfig.fetchDecisionsToPseudonymiseBetween(
{
source: 'juritj',
startDate,
endDate,
},
);
logger.log(
`${newCourtDecisions.length} ${
connectorConfig.name
} court decisions fetched between ${timeOperator.convertTimestampToReadableDate(
startDate.getTime(),
)} and ${timeOperator.convertTimestampToReadableDate(
endDate.getTime(),
)}!`,
);
for (const courtDecision of newCourtDecisions) {
newDocuments.push(
await connectorConfig.mapCourtDecisionToDocument(
courtDecision,
'recent',
),
);
}
daysAgo += daysStep;
step++;
}

logger.log(
`Insertion ${newDocuments.length} documents into the database...`,
);
await insertDocuments(newDocuments);
logger.log(`Insertion done!`);

logger.log(`Send documents have been loaded...`);
await connectorConfig.updateDocumentsLoadedStatus(newDocuments);
logger.log(`DONE`);
}

async function importSpecificDocument({
documentNumber,
source,
Expand Down Expand Up @@ -198,7 +251,18 @@ function buildConnector(connectorConfig: connectorConfigType) {
source: 'jurica',
},
);
const newCourtDecisions = [...newJurinetDecisions, ...newJuricaDecisions];
const newJuritjDecisions = await connectorConfig.fetchDecisionsToPseudonymiseBetween(
{
startDate,
endDate,
source: 'juritj',
},
);
const newCourtDecisions = [
...newJurinetDecisions,
...newJuricaDecisions,
...newJuritjDecisions,
];

logger.log(
`${newCourtDecisions.length} ${
Expand Down Expand Up @@ -324,11 +388,22 @@ function buildConnector(connectorConfig: connectorConfigType) {
},
);
logger.log(
`${newJuricaCourtDecisions.length} ${connectorConfig.name} court decisions fetched from jurica!`,
`${newJuricaCourtDecisions.length} ${connectorConfig.name} court decisions fetched from juritj!`,
);
const newJuritjCourtDecisions = await connectorConfig.fetchDecisionsToPseudonymiseBetween(
{
startDate: new Date(dateBuilder.daysAgo(days)),
endDate: new Date(),
source: 'juritj',
},
);
logger.log(
`${newJuritjCourtDecisions.length} ${connectorConfig.name} court decisions fetched from juritj!`,
);
const newCourtDecisions = [
...newJurinetCourtDecisions,
...newJuricaCourtDecisions,
...newJuritjCourtDecisions,
];
const documents = [] as documentType[];
for (const courtDecision of newCourtDecisions) {
Expand Down Expand Up @@ -373,9 +448,20 @@ function buildConnector(connectorConfig: connectorConfigType) {
logger.log(
`${newJuricaCourtDecisions.length} ${connectorConfig.name} court decisions fetched from jurica!`,
);
const newJuritjCourtDecisions = await connectorConfig.fetchDecisionsToPseudonymiseBetweenDateCreation(
{
startDate: new Date(dateBuilder.daysAgo(days)),
endDate: new Date(),
source: 'juritj',
},
);
logger.log(
`${newJuritjCourtDecisions.length} ${connectorConfig.name} court decisions fetched from juritj!`,
);
const newCourtDecisions = [
...newJurinetCourtDecisions,
...newJuricaCourtDecisions,
...newJuritjCourtDecisions,
];
const documents = [] as documentType[];
for (const courtDecision of newCourtDecisions) {
Expand Down Expand Up @@ -434,9 +520,22 @@ function buildConnector(connectorConfig: connectorConfigType) {
logger.log(
`${newJuricaCourtDecisions.length} ${connectorConfig.name} court decisions fetched from jurica!`,
);
const newJuritjCourtDecisions = await connectorConfig.fetchAllDecisionsBySourceAndJurisdictionsAndChambersBetween(
{
startDate: from,
endDate: to,
source: 'juritj',
jurisdictions,
chambers,
},
);
logger.log(
`${newJuritjCourtDecisions.length} ${connectorConfig.name} court decisions fetched from juritj!`,
);
const newCourtDecisions = [
...newJurinetCourtDecisions,
...newJuricaCourtDecisions,
...newJuritjCourtDecisions,
];
const documents = [] as documentType[];
for (const courtDecision of newCourtDecisions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async function buildFakeConnectorWithNDecisions(
}: {
startDate: Date;
endDate: Date;
source: 'jurinet' | 'jurica';
source: 'jurinet' | 'jurica' | 'juritj';
}) {
return courtDecisions.filter((courtDecision) => {
if (!courtDecision.dateDecision) {
Expand All @@ -147,7 +147,7 @@ async function buildFakeConnectorWithNDecisions(
}: {
startDate: Date;
endDate: Date;
source: 'jurinet' | 'jurica';
source: 'jurinet' | 'jurica' | 'juritj';
}) {
return courtDecisions.filter((courtDecision) => {
if (!courtDecision.dateCreation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type connectorConfigType = {
fetchAllDecisionsBySourceAndJurisdictionsAndChambersBetween: (param: {
startDate: Date;
endDate: Date;
source: 'jurinet' | 'jurica';
source: 'jurinet' | 'jurica' | 'juritj';
jurisdictions: string[];
chambers: string[];
}) => Promise<decisionType[]>;
Expand All @@ -30,12 +30,12 @@ type connectorConfigType = {
fetchDecisionsToPseudonymiseBetween(params: {
startDate: Date;
endDate: Date;
source: 'jurinet' | 'jurica';
source: 'jurinet' | 'jurica' | 'juritj';
}): Promise<decisionType[]>;
fetchDecisionsToPseudonymiseBetweenDateCreation(params: {
startDate: Date;
endDate: Date;
source: 'jurinet' | 'jurica';
source: 'jurinet' | 'jurica' | 'juritj';
}): Promise<decisionType[]>;
updateDocumentsLoadedStatus: (documents: documentType[]) => Promise<void>;
updateDocumentsToBeTreatedStatus: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async function fetchExtremumDates() {
const treatmentRepository = buildTreatmentRepository();

const extremumDatesInStatistics = await statisticRepository.findExtremumTreatmentDateBySources(
['jurinet', 'jurica'],
['jurinet', 'jurica', 'juritj'],
);

const extremumDatesInTreatments = await treatmentRepository.findExtremumLastUpdateDateBySources(
Expand Down

0 comments on commit 824712b

Please sign in to comment.