From 48420b2e18804e264715ce01d081a5c17b8d835c Mon Sep 17 00:00:00 2001 From: chaos Date: Sat, 9 Nov 2024 00:57:22 +0000 Subject: [PATCH] update --- runTests.sh | 4 +++- tool/journalUtils.jq | 5 ++--- tool/{ => lib}/journalLib.jq | 14 +++++++------- tool/{utils.jq => lib/utilsLib.jq} | 0 tool/main.jq | 7 +++---- tool/tests.jq | 5 +++-- 6 files changed, 18 insertions(+), 17 deletions(-) rename tool/{ => lib}/journalLib.jq (93%) rename tool/{utils.jq => lib/utilsLib.jq} (100%) diff --git a/runTests.sh b/runTests.sh index 83a7068..ca2be32 100755 --- a/runTests.sh +++ b/runTests.sh @@ -9,7 +9,9 @@ runTests() { JQ=${JQ:-jq} export JQ_FLAVOR=${JQ_FLAVOR:-jq} echo "Running Tests with JQ=${JQ}" - ${JQ} -n -r -L . -L "dropins/${JQ_FLAVOR}" "include \"tests\"; testsMain" + ${JQ} -nr \ + -L "$(realpath .)" -L "$(realpath ./lib)" -L "$(realpath ./dropins)/${JQ_FLAVOR}" \ + "include \"tests\"; testsMain" } runTests diff --git a/tool/journalUtils.jq b/tool/journalUtils.jq index 02c8ceb..6d3b20d 100644 --- a/tool/journalUtils.jq +++ b/tool/journalUtils.jq @@ -1,9 +1,8 @@ include "dropins"; -include "utils"; +import "lib/utilsLib" as utilsLib; import "lib/stringLib" as stringLib; - -import "journalLib" as journalLib; +import "lib/journalLib" as journalLib; def formatExperienceTitle: . as $experience | diff --git a/tool/journalLib.jq b/tool/lib/journalLib.jq similarity index 93% rename from tool/journalLib.jq rename to tool/lib/journalLib.jq index e893fc8..316e25a 100644 --- a/tool/journalLib.jq +++ b/tool/lib/journalLib.jq @@ -1,4 +1,4 @@ -import "utils" as utils; +import "utilsLib" as utilsLib; def calculateIngestionDose($customUnits): . as $ingestion | @@ -39,11 +39,11 @@ def filterIngestions($substanceFilter; $consumerFilter): def ingestionsSubstanceNames: . as $ingestions | - [$ingestions[].substanceName] | utils::orderedUnique; + [$ingestions[].substanceName] | utilsLib::orderedUnique; def ingestionsConsumerNames: . as $ingestions | - [$ingestions[] | ingestionConsumerName] | utils::orderedUnique; + [$ingestions[] | ingestionConsumerName] | utilsLib::orderedUnique; def ingestionsByConsumer: . as $ingestions | @@ -131,7 +131,7 @@ def filterSortExperiences($customUnits; $substanceFilter; $consumerFilter; $sort any(index($ingestion.substanceName)) ) ) then $experienceData else null end - ] | map(select(. != null)); + ] | objects; def filterByConsumerFilter: . as $experiencesData | @@ -181,14 +181,14 @@ def filterSortExperiences($customUnits; $substanceFilter; $consumerFilter; $sort elif $sortMethod == "highest-combined-dose" then - utils::assert($sortOptions.substanceName != null; "substanceName not provided as sortOption") | + utilsLib::assert($sortOptions.substanceName != null; "substanceName not provided as sortOption") | filterBySubstanceAndConsumer | sort_by(highestCombinedDoseSort, oldToNewSort) | reverse elif $sortMethod == "highest-dose-for-method" then - utils::assert($sortOptions.substanceName != null; "substanceName not provided as sortOption") | + utilsLib::assert($sortOptions.substanceName != null; "substanceName not provided as sortOption") | filterByIngestionMethodForSubstance | sort_by(highestMethodDoseSort, oldToNewSort) | reverse @@ -199,5 +199,5 @@ def filterSortExperiences($customUnits; $substanceFilter; $consumerFilter; $sort sortFilter; def experienceByTitle($name): - utils::assert((. | type) == "array"; "experienceByTitle takes a array of experiences as input") | + utilsLib::assert((. | type) == "array"; "experienceByTitle takes a array of experiences as input") | map(select(.title == $name))[0]; \ No newline at end of file diff --git a/tool/utils.jq b/tool/lib/utilsLib.jq similarity index 100% rename from tool/utils.jq rename to tool/lib/utilsLib.jq diff --git a/tool/main.jq b/tool/main.jq index 9827e66..04570e1 100644 --- a/tool/main.jq +++ b/tool/main.jq @@ -4,12 +4,11 @@ import "lib/typeLib" as typeLib; import "lib/argsLib" as argsLib; import "lib/stringLib" as stringLib; import "lib/tableLib" as tableLib; +import "lib/utilsLib" as utilsLib; +import "lib/journalLib" as journalLib; -import "journalLib" as journalLib; import "journalUtils" as journalUtils; import "types" as types; -import "utils" as utils; - def printExperienceStats($stats; $substanceFilter; $consumerFilter; $withTitle): . as $experience | @@ -262,7 +261,7 @@ def main: $options.sortMethod; $options.sortOptions ) | - if ($options.sortFilter != null) then utils::sortFilterFromString($options.sortFilter) end | + if ($options.sortFilter != null) then utilsLib::sortFilterFromString($options.sortFilter) end | printExperiences( $exportData.customUnits; $options.substanceFilter; diff --git a/tool/tests.jq b/tool/tests.jq index 4e5241a..bcf8355 100644 --- a/tool/tests.jq +++ b/tool/tests.jq @@ -2,6 +2,7 @@ include "dropins"; import "lib/testLib" as testLib; import "lib/typeLib" as typeLib; +import "lib/journalLib" as journalLib; import "journalUtils" as journalUtils; @@ -11,7 +12,7 @@ def journalUtilsTests: testLib::expectPassed(testLib::runTest( "invalid input to experienceByTitle"; ( - null | journalUtils::experienceByTitle("Test") + null | journalLib::experienceByTitle("Test") ); . == "experienceByTitle takes a array of experiences as input"; true @@ -19,7 +20,7 @@ def journalUtilsTests: testLib::expectPassed(testLib::runTest( "experience not found"; ( - $exportDataArray[0].experiences | journalUtils::experienceByTitle("Test") + $exportDataArray[0].experiences | journalLib::experienceByTitle("Test") ); . == null; false