From b070bc29c62bebb77505b3e4ea3c52aeb9519a08 Mon Sep 17 00:00:00 2001 From: Jim deVos Date: Tue, 23 Jul 2024 14:47:30 -0700 Subject: [PATCH 1/9] breaking out event-codes-by-year into -count-non-stricken-event-codes-by-year --- .../count-non-stricken-event-codes-by-year.ts | 134 ++++++++++++++++++ scripts/reports/event-codes-by-year.ts | 23 +-- 2 files changed, 147 insertions(+), 10 deletions(-) create mode 100644 scripts/reports/count-non-stricken-event-codes-by-year.ts diff --git a/scripts/reports/count-non-stricken-event-codes-by-year.ts b/scripts/reports/count-non-stricken-event-codes-by-year.ts new file mode 100644 index 00000000000..f312bb5644f --- /dev/null +++ b/scripts/reports/count-non-stricken-event-codes-by-year.ts @@ -0,0 +1,134 @@ +// usage: npx ts-node --transpile-only scripts/reports/count-non-stricken-event-codes-by-year.ts M071,M074 2021-2022 [includeStricken] > ~/Desktop/m071s-and-m074s-filed-2021-2022.csv + +import { count } from '@web-api/persistence/elasticsearch/searchClient'; +import { createApplicationContext } from '@web-api/applicationContext'; +import { requireEnvVars } from '../../shared/admin-tools/util'; +import { validateDateAndCreateISO } from '@shared/business/utilities/DateHandler'; + +requireEnvVars(['ENV', 'REGION']); + +const includeStricken = !!(process.argv.length > 4); +if (includeStricken) { + console.log('including stricken docket entries'); +} + +const getCountDocketEntriesByEventCodesAndYears = async ({ + applicationContext, + eventCodes, + onlyNonStricken, + years, +}: { + applicationContext: IApplicationContext; + eventCodes: string[]; + onlyNonStricken: boolean; + years?: number[]; +}): Promise => { + const must: {}[] = [ + { + bool: { + should: eventCodes.map(eventCode => { + return { + term: { + 'eventCode.S': eventCode, + }, + }; + }), + }, + }, + ]; + if (onlyNonStricken) { + must.push({ + term: { + 'isStricken.BOOL': false, + }, + }); + } + if (years && years.length) { + if (years.length === 1) { + must.push({ + range: { + 'receivedAt.S': { + gte: validateDateAndCreateISO({ + day: '1', + month: '1', + year: String(years[0]), + }), + lt: validateDateAndCreateISO({ + day: '1', + month: '1', + year: String(years[0] + 1), + }), + }, + }, + }); + } else { + must.push({ + bool: { + should: years.map(year => { + return { + range: { + 'receivedAt.S': { + gte: validateDateAndCreateISO({ + day: '1', + month: '1', + year: String(year), + }), + lt: validateDateAndCreateISO({ + day: '1', + month: '1', + year: String(year + 1), + }), + }, + }, + }; + }), + }, + }); + } + } + const searchParameters = { + body: { + query: { + bool: { + must, + }, + }, + }, + index: 'efcms-docket-entry', + }; + // console.log('Effective Query:', JSON.stringify(searchParameters, null, 4)); + + const results = await count({ + applicationContext, + searchParameters, + }); + return results; +}; + +// eslint-disable-next-line @typescript-eslint/no-floating-promises +(async () => { + const applicationContext = createApplicationContext({}); + + const eventCodes = process.argv[2].split(','); + const years: number[] = []; + const yearArg = process.argv[3]; + if (yearArg.includes('-')) { + const [lower, upper] = yearArg.split('-'); + for (let i = Number(lower); i <= Number(upper); i++) { + years.push(Number(i)); + } + } else { + const yearStrings = yearArg.split(','); + for (const year of yearStrings) { + years.push(Number(year)); + } + } + + const ret = await getCountDocketEntriesByEventCodesAndYears({ + applicationContext, + eventCodes, + onlyNonStricken: !includeStricken, + years, + }); + console.log(ret); +})(); diff --git a/scripts/reports/event-codes-by-year.ts b/scripts/reports/event-codes-by-year.ts index 426915dbcf7..23a9a53cce7 100644 --- a/scripts/reports/event-codes-by-year.ts +++ b/scripts/reports/event-codes-by-year.ts @@ -113,19 +113,22 @@ const getDocketEntriesByEventCodesAndYears = async ({ }); } } - const { results } = await searchAll({ - applicationContext, - searchParameters: { - body: { - query: { - bool: { - must, - }, + const searchParameters = { + body: { + query: { + bool: { + must, }, - sort: [{ 'receivedAt.S': 'asc' }], }, - index: 'efcms-docket-entry', + sort: [{ 'receivedAt.S': 'asc' }], }, + index: 'efcms-docket-entry', + }; + console.log('Effective Query:', JSON.stringify(searchParameters, null, 4)); + + const { results } = await searchAll({ + applicationContext, + searchParameters, }); return results; }; From 320d78c44efd2cd4972289e034c6803c8b9d41ce Mon Sep 17 00:00:00 2001 From: Jim deVos Date: Wed, 24 Jul 2024 10:11:00 -0700 Subject: [PATCH 2/9] reverting temporary changes I did not mean to commit --- scripts/reports/event-codes-by-year.ts | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/scripts/reports/event-codes-by-year.ts b/scripts/reports/event-codes-by-year.ts index 23a9a53cce7..426915dbcf7 100644 --- a/scripts/reports/event-codes-by-year.ts +++ b/scripts/reports/event-codes-by-year.ts @@ -113,22 +113,19 @@ const getDocketEntriesByEventCodesAndYears = async ({ }); } } - const searchParameters = { - body: { - query: { - bool: { - must, + const { results } = await searchAll({ + applicationContext, + searchParameters: { + body: { + query: { + bool: { + must, + }, }, + sort: [{ 'receivedAt.S': 'asc' }], }, - sort: [{ 'receivedAt.S': 'asc' }], + index: 'efcms-docket-entry', }, - index: 'efcms-docket-entry', - }; - console.log('Effective Query:', JSON.stringify(searchParameters, null, 4)); - - const { results } = await searchAll({ - applicationContext, - searchParameters, }); return results; }; From 52e5c93fb0d95dba3ec6a83d16aef739e9cd5712 Mon Sep 17 00:00:00 2001 From: Jim deVos Date: Wed, 24 Jul 2024 11:35:16 -0700 Subject: [PATCH 3/9] adding requested changes (wip) --- .../count-non-stricken-event-codes-by-year.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/reports/count-non-stricken-event-codes-by-year.ts b/scripts/reports/count-non-stricken-event-codes-by-year.ts index f312bb5644f..0483615dd67 100644 --- a/scripts/reports/count-non-stricken-event-codes-by-year.ts +++ b/scripts/reports/count-non-stricken-event-codes-by-year.ts @@ -1,16 +1,16 @@ -// usage: npx ts-node --transpile-only scripts/reports/count-non-stricken-event-codes-by-year.ts M071,M074 2021-2022 [includeStricken] > ~/Desktop/m071s-and-m074s-filed-2021-2022.csv +// usage: npx ts-node --transpile-only scripts/reports/count-non-stricken-event-codes-by-year.ts M071,M074 2021-2022 [includeStricken] +import { + ServerApplicationContext, + createApplicationContext, +} from '@web-api/applicationContext'; import { count } from '@web-api/persistence/elasticsearch/searchClient'; -import { createApplicationContext } from '@web-api/applicationContext'; import { requireEnvVars } from '../../shared/admin-tools/util'; import { validateDateAndCreateISO } from '@shared/business/utilities/DateHandler'; requireEnvVars(['ENV', 'REGION']); const includeStricken = !!(process.argv.length > 4); -if (includeStricken) { - console.log('including stricken docket entries'); -} const getCountDocketEntriesByEventCodesAndYears = async ({ applicationContext, @@ -18,7 +18,7 @@ const getCountDocketEntriesByEventCodesAndYears = async ({ onlyNonStricken, years, }: { - applicationContext: IApplicationContext; + applicationContext: ServerApplicationContext; eventCodes: string[]; onlyNonStricken: boolean; years?: number[]; From cee58f7d82150bae03711a43b9be76da03cb4649 Mon Sep 17 00:00:00 2001 From: Jim deVos Date: Wed, 31 Jul 2024 19:48:32 -0700 Subject: [PATCH 4/9] incomplete work on extracting arg utils from eventcode reports (wip) --- ...y-year.ts => count-event-codes-by-year.ts} | 66 ++++++++++++++----- scripts/reports/reportUtils.ts | 28 ++++++++ 2 files changed, 76 insertions(+), 18 deletions(-) rename scripts/reports/{count-non-stricken-event-codes-by-year.ts => count-event-codes-by-year.ts} (67%) create mode 100644 scripts/reports/reportUtils.ts diff --git a/scripts/reports/count-non-stricken-event-codes-by-year.ts b/scripts/reports/count-event-codes-by-year.ts similarity index 67% rename from scripts/reports/count-non-stricken-event-codes-by-year.ts rename to scripts/reports/count-event-codes-by-year.ts index 0483615dd67..aad2ad48308 100644 --- a/scripts/reports/count-non-stricken-event-codes-by-year.ts +++ b/scripts/reports/count-event-codes-by-year.ts @@ -1,16 +1,53 @@ -// usage: npx ts-node --transpile-only scripts/reports/count-non-stricken-event-codes-by-year.ts M071,M074 2021-2022 [includeStricken] +#!/usr/bin/env npx ts-node --transpile-only +import { DateTime } from 'luxon'; import { ServerApplicationContext, createApplicationContext, } from '@web-api/applicationContext'; import { count } from '@web-api/persistence/elasticsearch/searchClient'; +import { parseArgs } from 'node:util'; +import { parseIntsArg } from './reportUtils'; import { requireEnvVars } from '../../shared/admin-tools/util'; import { validateDateAndCreateISO } from '@shared/business/utilities/DateHandler'; requireEnvVars(['ENV', 'REGION']); -const includeStricken = !!(process.argv.length > 4); +let positionals, values; + +function usage(warning: string | undefined) { + if (warning) { + console.log(warning); + } + console.log( + `npx ts-node --transpile-only ${process.argv[1]} M071,M074 2021-2022 [includeStricken]`, + ); +} + +const config = { + allowPositionals: true, + args: process.argv, + options: { + stricken: { + default: false, + description: 'include stricken docket entries when computing the results', + short: 's', + type: 'boolean', + }, + verbose: { + default: false, + short: 'v', + type: 'boolean', + }, + years: { + default: `${DateTime.now().toObject().year}`, + description: + 'comma-delimited list of years, or a hyphen-separated range of years', + type: 'string', + }, + }, + strict: true, +} as const; const getCountDocketEntriesByEventCodesAndYears = async ({ applicationContext, @@ -107,25 +144,18 @@ const getCountDocketEntriesByEventCodesAndYears = async ({ // eslint-disable-next-line @typescript-eslint/no-floating-promises (async () => { - const applicationContext = createApplicationContext({}); - - const eventCodes = process.argv[2].split(','); - const years: number[] = []; - const yearArg = process.argv[3]; - if (yearArg.includes('-')) { - const [lower, upper] = yearArg.split('-'); - for (let i = Number(lower); i <= Number(upper); i++) { - years.push(Number(i)); - } - } else { - const yearStrings = yearArg.split(','); - for (const year of yearStrings) { - years.push(Number(year)); - } + try { + ({ positionals, values } = parseArgs(config)); + } catch (ex) { + usage(`Error: ${ex}`); + process.exit(1); } + const eventCodes = positionals.map(s => s.toUpperCase()); + const years: number[] = parseIntsArg(values.years); + const includeStricken = values.stricken; const ret = await getCountDocketEntriesByEventCodesAndYears({ - applicationContext, + applicationContext: createApplicationContext({}), eventCodes, onlyNonStricken: !includeStricken, years, diff --git a/scripts/reports/reportUtils.ts b/scripts/reports/reportUtils.ts new file mode 100644 index 00000000000..18f00029c03 --- /dev/null +++ b/scripts/reports/reportUtils.ts @@ -0,0 +1,28 @@ +export function parseInts(ints: string, delimiter = ','): number[] { + let nums = ints.split(delimiter).map(parseInt); + return nums; +} + +export function parseIntRange(intRange: string): number[] { + const ints = intRange.split('-').map(parseInt); + const min = Math.min(...ints); + const max = Math.max(...ints); + let rangeNums: number[] = []; + for (let i = min; i <= max; i++) { + rangeNums.push(i); + } + return rangeNums; +} +// eslint-disable-next-line spellcheck/spell-checker +/** + * + * @param intstr a string containing an int (e.g. '1'), list of ints(e.g. '1,2,3'), or inclusive int range (e.g. '1-3') + * @returns an array of one or more integers + */ +export function parseIntsArg(intstr: string): number[] { + if (intstr.indexOf('-')) { + return parseIntRange(intstr); + } else { + return parseInts(intstr); + } +} From 7d54b280e96729ce0c30221d8666fe0ab40b4771 Mon Sep 17 00:00:00 2001 From: Jim deVos Date: Wed, 31 Jul 2024 19:55:11 -0700 Subject: [PATCH 5/9] cleanup args, usage (still WIP) --- scripts/reports/count-event-codes-by-year.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/reports/count-event-codes-by-year.ts b/scripts/reports/count-event-codes-by-year.ts index aad2ad48308..b1d2ebe9d21 100644 --- a/scripts/reports/count-event-codes-by-year.ts +++ b/scripts/reports/count-event-codes-by-year.ts @@ -19,9 +19,7 @@ function usage(warning: string | undefined) { if (warning) { console.log(warning); } - console.log( - `npx ts-node --transpile-only ${process.argv[1]} M071,M074 2021-2022 [includeStricken]`, - ); + console.log(`npx ts-node --transpile-only ${process.argv[1]} M071,m074`); } const config = { @@ -43,6 +41,7 @@ const config = { default: `${DateTime.now().toObject().year}`, description: 'comma-delimited list of years, or a hyphen-separated range of years', + short: 'y', type: 'string', }, }, @@ -160,5 +159,8 @@ const getCountDocketEntriesByEventCodesAndYears = async ({ onlyNonStricken: !includeStricken, years, }); + if (values.verbose) { + console.log(JSON.stringify(config, null, 4)); + } console.log(ret); })(); From 7e4abfb963e8e57ff107c1452edb0a2d043abc58 Mon Sep 17 00:00:00 2001 From: Jim deVos Date: Thu, 1 Aug 2024 13:05:05 -0700 Subject: [PATCH 6/9] more refactoring; added tests; report now executable (see notes) - now using node:util:parseArgs instead of doing it manual - pulled out parsing numbers, ranges from count-event-codes-by-year into a reportUtils file - added exec shebang so count-event-codes can be run directly - todo: similarly refactor event-codes-by-year --- scripts/reports/count-event-codes-by-year.ts | 17 +++--- scripts/reports/reportUtils.test.ts | 55 ++++++++++++++++++++ scripts/reports/reportUtils.ts | 13 +++-- 3 files changed, 74 insertions(+), 11 deletions(-) mode change 100644 => 100755 scripts/reports/count-event-codes-by-year.ts create mode 100644 scripts/reports/reportUtils.test.ts diff --git a/scripts/reports/count-event-codes-by-year.ts b/scripts/reports/count-event-codes-by-year.ts old mode 100644 new mode 100755 index b1d2ebe9d21..85727129c7b --- a/scripts/reports/count-event-codes-by-year.ts +++ b/scripts/reports/count-event-codes-by-year.ts @@ -1,5 +1,7 @@ #!/usr/bin/env npx ts-node --transpile-only +//usage: count-event-codes-by-year m01 m02 feew -y 2000-2020 + import { DateTime } from 'luxon'; import { ServerApplicationContext, @@ -19,16 +21,13 @@ function usage(warning: string | undefined) { if (warning) { console.log(warning); } - console.log(`npx ts-node --transpile-only ${process.argv[1]} M071,m074`); + console.log(`npx ts-node --transpile-only ${process.argv[1]} M071,m074 `); } - const config = { allowPositionals: true, - args: process.argv, options: { stricken: { default: false, - description: 'include stricken docket entries when computing the results', short: 's', type: 'boolean', }, @@ -39,8 +38,6 @@ const config = { }, years: { default: `${DateTime.now().toObject().year}`, - description: - 'comma-delimited list of years, or a hyphen-separated range of years', short: 'y', type: 'string', }, @@ -149,8 +146,12 @@ const getCountDocketEntriesByEventCodesAndYears = async ({ usage(`Error: ${ex}`); process.exit(1); } - - const eventCodes = positionals.map(s => s.toUpperCase()); + if (positionals.length === 0) { + usage('invalid input: expected event codes'); + process.exit(1); + } + console.log('positionals', positionals); + const eventCodes = positionals[0].split(',').map(s => s.toUpperCase()); const years: number[] = parseIntsArg(values.years); const includeStricken = values.stricken; const ret = await getCountDocketEntriesByEventCodesAndYears({ diff --git a/scripts/reports/reportUtils.test.ts b/scripts/reports/reportUtils.test.ts new file mode 100644 index 00000000000..3ae6473f068 --- /dev/null +++ b/scripts/reports/reportUtils.test.ts @@ -0,0 +1,55 @@ +import { parseIntRange, parseInts, parseIntsArg } from './reportUtils'; + +describe('parseIntsRange', () => { + it('returns array when given valid ranges', () => { + expect(parseIntRange('1-2')).toEqual([1, 2]); + expect(parseIntRange('3-1')).toEqual([1, 2, 3]); + expect(parseIntRange('1-3')).toEqual([1, 2, 3]); + expect(parseIntRange('0-0')).toEqual([0]); // hoot! + expect(parseIntRange('')).toEqual([]); + }); + + it('returns single item array when given single number', () => { + expect(parseIntRange('1')).toEqual([1]); + }); + + it('returns empty array when given no valid input', () => { + expect(parseIntRange('')).toEqual([]); + }); +}); + +describe('parseInts', () => { + it('should return empty array when given empty input', () => { + expect(parseInts('')).toEqual([]); + }); + it('should ignore trailing comma', () => { + expect(parseInts('1,')).toEqual([1]); + }); + it('should return an array when given comma-delimited list', () => { + expect(parseInts('1,2,3')).toEqual([1, 2, 3]); + }); + it('should return an array when given tab-delimited list', () => { + expect(parseInts('1\t2\t3', '\t')).toEqual([1, 2, 3]); + }); + + it('should return array of ints', () => { + let ints = parseInts('1,2,3'); + expect(ints).toEqual([1, 2, 3]); + ints.forEach(n => { + expect(typeof n).toBe('number'); + }); + }); +}); + +describe('parseIntsArg', () => { + it('returns empty array when given empty input', () => { + expect(parseIntsArg('')).toEqual([]); + }); + it('handles int ranges', () => { + expect(parseIntsArg('1-3')).toEqual([1, 2, 3]); + }); + + it('handles int lists', () => { + expect(parseIntsArg('1,2,3')).toEqual([1, 2, 3]); + }); +}); diff --git a/scripts/reports/reportUtils.ts b/scripts/reports/reportUtils.ts index 18f00029c03..0642abe4d11 100644 --- a/scripts/reports/reportUtils.ts +++ b/scripts/reports/reportUtils.ts @@ -1,10 +1,16 @@ export function parseInts(ints: string, delimiter = ','): number[] { - let nums = ints.split(delimiter).map(parseInt); + let nums = ints + .split(delimiter) + .filter(s => s.length) + .map(s => parseInt(s)); return nums; } export function parseIntRange(intRange: string): number[] { - const ints = intRange.split('-').map(parseInt); + const ints = intRange + .split('-') + .filter(s => s.length) + .map(s => parseInt(s)); const min = Math.min(...ints); const max = Math.max(...ints); let rangeNums: number[] = []; @@ -13,6 +19,7 @@ export function parseIntRange(intRange: string): number[] { } return rangeNums; } + // eslint-disable-next-line spellcheck/spell-checker /** * @@ -20,7 +27,7 @@ export function parseIntRange(intRange: string): number[] { * @returns an array of one or more integers */ export function parseIntsArg(intstr: string): number[] { - if (intstr.indexOf('-')) { + if (intstr.indexOf('-') > 0) { return parseIntRange(intstr); } else { return parseInts(intstr); From 4c41237bcb847255345a9efbede21036ee43310f Mon Sep 17 00:00:00 2001 From: Jim deVos Date: Thu, 8 Aug 2024 14:54:36 -0700 Subject: [PATCH 7/9] refactor event-codes-by-year to use parseArgs; updated usage --- scripts/reports/count-event-codes-by-year.ts | 21 +++++--- scripts/reports/event-codes-by-year.ts | 55 ++++++++++++++------ 2 files changed, 53 insertions(+), 23 deletions(-) mode change 100644 => 100755 scripts/reports/event-codes-by-year.ts diff --git a/scripts/reports/count-event-codes-by-year.ts b/scripts/reports/count-event-codes-by-year.ts index 85727129c7b..8af530768f2 100755 --- a/scripts/reports/count-event-codes-by-year.ts +++ b/scripts/reports/count-event-codes-by-year.ts @@ -17,12 +17,6 @@ requireEnvVars(['ENV', 'REGION']); let positionals, values; -function usage(warning: string | undefined) { - if (warning) { - console.log(warning); - } - console.log(`npx ts-node --transpile-only ${process.argv[1]} M071,m074 `); -} const config = { allowPositionals: true, options: { @@ -45,6 +39,16 @@ const config = { strict: true, } as const; +function usage(warning: string | undefined) { + if (warning) { + console.log(warning); + } + console.log( + `Usage: npx ts-node --transpile-only ${process.argv[1]} M071,m074 `, + ); + console.log('Options:', JSON.stringify(config, null, 4)); +} + const getCountDocketEntriesByEventCodesAndYears = async ({ applicationContext, eventCodes, @@ -150,7 +154,6 @@ const getCountDocketEntriesByEventCodesAndYears = async ({ usage('invalid input: expected event codes'); process.exit(1); } - console.log('positionals', positionals); const eventCodes = positionals[0].split(',').map(s => s.toUpperCase()); const years: number[] = parseIntsArg(values.years); const includeStricken = values.stricken; @@ -161,7 +164,9 @@ const getCountDocketEntriesByEventCodesAndYears = async ({ years, }); if (values.verbose) { - console.log(JSON.stringify(config, null, 4)); + usage('Verbose output enabled'); + console.log(`positionals: ${positionals}`); + console.log(`option values: ${values}`); } console.log(ret); })(); diff --git a/scripts/reports/event-codes-by-year.ts b/scripts/reports/event-codes-by-year.ts old mode 100644 new mode 100755 index 426915dbcf7..71e95f42511 --- a/scripts/reports/event-codes-by-year.ts +++ b/scripts/reports/event-codes-by-year.ts @@ -1,6 +1,11 @@ +#!/usr/bin/env npx ts-node --transpile-only + // usage: npx ts-node --transpile-only scripts/reports/event-codes-by-year.ts M071,M074 2021-2022 > ~/Desktop/m071s-and-m074s-filed-2021-2022.csv +import { DateTime } from 'luxon'; import { createApplicationContext } from '@web-api/applicationContext'; +import { parseArgs } from 'node:util'; +import { parseIntsArg } from './reportUtils'; import { requireEnvVars } from '../../shared/admin-tools/util'; import { search, @@ -9,6 +14,29 @@ import { import { validateDateAndCreateISO } from '@shared/business/utilities/DateHandler'; requireEnvVars(['ENV', 'REGION']); +let positionals, values; + +const config = { + allowPositionals: true, + options: { + years: { + default: `${DateTime.now().toObject().year}`, + short: 'y', + type: 'string', + }, + }, + strict: true, +} as const; + +function usage(warning: string | undefined) { + if (warning) { + console.log(warning); + } + console.log( + `Usage: npx ts-node --transpile-only ${process.argv[1]} M071,m074 [-y 2023,2024]`, + ); + console.log('Options:', JSON.stringify(config, null, 4)); +} const cachedCases: { [key: string]: RawCase } = {}; @@ -132,22 +160,19 @@ const getDocketEntriesByEventCodesAndYears = async ({ // eslint-disable-next-line @typescript-eslint/no-floating-promises (async () => { - const applicationContext = createApplicationContext({}); - - const eventCodes = process.argv[2].split(','); - const years: number[] = []; - const yearArg = process.argv[3]; - if (yearArg.includes('-')) { - const [lower, upper] = yearArg.split('-'); - for (let i = Number(lower); i <= Number(upper); i++) { - years.push(Number(i)); - } - } else { - const yearStrings = yearArg.split(','); - for (const year of yearStrings) { - years.push(Number(year)); - } + try { + ({ positionals, values } = parseArgs(config)); + } catch (ex) { + usage(`Error: ${ex}`); + process.exit(1); + } + if (positionals.length === 0) { + usage('invalid input: expected event codes'); + process.exit(1); } + const eventCodes = positionals[0].split(',').map(s => s.toUpperCase()); + const years: number[] = parseIntsArg(values.years); + const applicationContext = createApplicationContext({}); const docketEntries = await getDocketEntriesByEventCodesAndYears({ applicationContext, From c2f0c52dce6c16cc45e227680a757c0d508a5179 Mon Sep 17 00:00:00 2001 From: Jim deVos Date: Tue, 20 Aug 2024 09:59:29 -0700 Subject: [PATCH 8/9] cleanup usage, set executable flag --- scripts/reports/count-event-codes-by-year.ts | 2 +- scripts/reports/event-codes-by-year.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/reports/count-event-codes-by-year.ts b/scripts/reports/count-event-codes-by-year.ts index 8af530768f2..651db8ba124 100755 --- a/scripts/reports/count-event-codes-by-year.ts +++ b/scripts/reports/count-event-codes-by-year.ts @@ -1,6 +1,6 @@ #!/usr/bin/env npx ts-node --transpile-only -//usage: count-event-codes-by-year m01 m02 feew -y 2000-2020 +// usage: scripts/reports/count-event-codes-by-year.ts m01,m02 feew [-y 2000-2020] import { DateTime } from 'luxon'; import { diff --git a/scripts/reports/event-codes-by-year.ts b/scripts/reports/event-codes-by-year.ts index 71e95f42511..cf4bc1b265d 100755 --- a/scripts/reports/event-codes-by-year.ts +++ b/scripts/reports/event-codes-by-year.ts @@ -1,6 +1,6 @@ #!/usr/bin/env npx ts-node --transpile-only -// usage: npx ts-node --transpile-only scripts/reports/event-codes-by-year.ts M071,M074 2021-2022 > ~/Desktop/m071s-and-m074s-filed-2021-2022.csv +// usage: scripts/reports/event-codes-by-year.ts M071,M074 [-y 2021-2022] > ~/Desktop/m071s-and-m074s-filed-2021-2022.csv import { DateTime } from 'luxon'; import { createApplicationContext } from '@web-api/applicationContext'; From ff2f117913f6ba787e670e264e7d916d43f2cd29 Mon Sep 17 00:00:00 2001 From: Jim deVos Date: Tue, 20 Aug 2024 10:25:33 -0700 Subject: [PATCH 9/9] more usage cleanup --- scripts/reports/count-event-codes-by-year.ts | 4 +--- scripts/reports/event-codes-by-year.ts | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/scripts/reports/count-event-codes-by-year.ts b/scripts/reports/count-event-codes-by-year.ts index 651db8ba124..18aadd8fd94 100755 --- a/scripts/reports/count-event-codes-by-year.ts +++ b/scripts/reports/count-event-codes-by-year.ts @@ -43,9 +43,7 @@ function usage(warning: string | undefined) { if (warning) { console.log(warning); } - console.log( - `Usage: npx ts-node --transpile-only ${process.argv[1]} M071,m074 `, - ); + console.log(`Usage: ${process.argv[1]} M071,m074 `); console.log('Options:', JSON.stringify(config, null, 4)); } diff --git a/scripts/reports/event-codes-by-year.ts b/scripts/reports/event-codes-by-year.ts index cf4bc1b265d..66a707a71ed 100755 --- a/scripts/reports/event-codes-by-year.ts +++ b/scripts/reports/event-codes-by-year.ts @@ -32,9 +32,7 @@ function usage(warning: string | undefined) { if (warning) { console.log(warning); } - console.log( - `Usage: npx ts-node --transpile-only ${process.argv[1]} M071,m074 [-y 2023,2024]`, - ); + console.log(`Usage: ${process.argv[1]} M071,m074 [-y 2023,2024]`); console.log('Options:', JSON.stringify(config, null, 4)); }