update
This commit is contained in:
parent
bfc7912236
commit
61994bafb0
|
@ -2,6 +2,7 @@ include "dropins";
|
|||
|
||||
import "lib/utilsLib" as utilsLib;
|
||||
import "lib/stringLib" as stringLib;
|
||||
import "lib/numberLib" as numberLib;
|
||||
import "lib/journalLib" as journalLib;
|
||||
|
||||
def formatExperienceTitle:
|
||||
|
@ -10,15 +11,21 @@ def formatExperienceTitle:
|
|||
|
||||
def formatIngestionDose($customUnits):
|
||||
. as $ingestion |
|
||||
. | journalLib::ingestionDose($customUnits) as $dose |
|
||||
. | journalLib::ingestionUnit($customUnits) as $unit |
|
||||
(. | journalLib::ingestionDose($customUnits)) as $dose |
|
||||
(. | journalLib::ingestionUnit($customUnits)) as $unit |
|
||||
(. | journalLib::ingestionStandardDeviation($customUnits)) as $standardDeviation |
|
||||
$customUnits | map(select(.id == $ingestion.customUnitId))[0] as $customUnit |
|
||||
if $ingestion.dose == null then
|
||||
"Unknown"
|
||||
elif $customUnit == null then
|
||||
"\($dose) \($unit)"
|
||||
if $ingestion.isDoseAnEstimate then "~" else "" end +
|
||||
"\($dose | numberLib::round(2))" +
|
||||
if $standardDeviation != null then
|
||||
"±\($standardDeviation)"
|
||||
else "" end +
|
||||
" \($unit)"
|
||||
else
|
||||
"\($dose) \($unit) (\($ingestion.dose) \($unit) * \($customUnit.dose) \($customUnit.unit))"
|
||||
"\($dose) \($unit) (\($customUnit.dose) \($unit) * \($ingestion.dose) \($customUnit.unit))"
|
||||
end;
|
||||
|
||||
def formatIngestionTime:
|
||||
|
@ -48,4 +55,19 @@ def formatIngestionROA($customUnits; $substitutions):
|
|||
"\($roaText) (\($customUnit.name))"
|
||||
end;
|
||||
|
||||
def formatIngestionROA($customUnits): formatIngestionROA($customUnits; {});
|
||||
def formatIngestionROA($customUnits): formatIngestionROA($customUnits; {});
|
||||
|
||||
def formatIngestionInfo:
|
||||
. as $ingestionInfo |
|
||||
if $ingestionInfo.dose == null then
|
||||
"Unknown \($ingestionInfo.unit)"
|
||||
else
|
||||
if $ingestionInfo.isEstimate then "~" else "" end +
|
||||
"\($ingestionInfo.dose * 100 | round / 100)" +
|
||||
if $ingestionInfo.standardDeviation != null then
|
||||
"±\($ingestionInfo.standardDeviation)"
|
||||
else "" end +
|
||||
|
||||
if $ingestionInfo.isUnknown then "+ Unknown" else "" end +
|
||||
" \($ingestionInfo.unit)"
|
||||
end;
|
|
@ -1,4 +1,5 @@
|
|||
import "utilsLib" as utilsLib;
|
||||
import "numberLib" as numberLib;
|
||||
import "journalTypes" as journalTypes;
|
||||
|
||||
def ingestionDose($customUnits):
|
||||
|
@ -19,7 +20,7 @@ def addStandardDeviations($expectationX; $standardDeviationX; $expectationY; $st
|
|||
(pow($expectationX; 2) * pow($expectationY; 2)) as $expectations |
|
||||
($sumX * $sumY - $expectations) as $productVariance |
|
||||
if $productVariance > 0.0000001 then
|
||||
$productVariance | sqrt
|
||||
$productVariance | sqrt | numberLib::round(2)
|
||||
else
|
||||
null
|
||||
end;
|
||||
|
@ -38,7 +39,7 @@ def ingestionStandardDeviation($customUnits):
|
|||
|
||||
addStandardDeviations($expectationX; $standardDeviationX; $expectationY; $standardDeviationY)
|
||||
else
|
||||
.standardDeviation
|
||||
.estimatedDoseStandardDeviation
|
||||
end;
|
||||
|
||||
def ingestionUnit($customUnits):
|
||||
|
@ -58,15 +59,20 @@ def ingestionConsumerName:
|
|||
|
||||
def filterIngestions($substanceFilter; $consumerFilter):
|
||||
. as $ingestions |
|
||||
($substanceFilter // []) as $substanceFilter |
|
||||
(($substanceFilter | length) > 0) as $shouldFilterBySubstance |
|
||||
($consumerFilter // []) as $consumerFilter |
|
||||
(($consumerFilter | length) > 0) as $shouldFilterByConsumer |
|
||||
|
||||
journalTypes::ensureIngestions |
|
||||
|
||||
if (($substanceFilter // [] | length) > 0) then
|
||||
if $shouldFilterBySubstance or $shouldFilterByConsumer then
|
||||
[
|
||||
$ingestions[] as $ingestion |
|
||||
if
|
||||
([$substanceFilter[] | . == $ingestion.substanceName] | any)
|
||||
(if $shouldFilterBySubstance then ([$substanceFilter[] | . == $ingestion.substanceName] | any) else true end
|
||||
and
|
||||
([$consumerFilter[] | . == ($ingestion | ingestionConsumerName)] | any)
|
||||
if $shouldFilterByConsumer then ([$consumerFilter[] | . == ($ingestion | ingestionConsumerName)] | any) else true end)
|
||||
then $ingestion
|
||||
else null end
|
||||
] | map(select(. != null))
|
||||
|
@ -90,9 +96,9 @@ def ingestionsByConsumer:
|
|||
$consumerNames[] as $consumerName |
|
||||
{
|
||||
key: $consumerName,
|
||||
value: [$ingestions | map(select(
|
||||
value: $ingestions | map(select(
|
||||
. | ingestionConsumerName == $consumerName
|
||||
))],
|
||||
)),
|
||||
}
|
||||
] | from_entries;
|
||||
|
||||
|
|
3
tool/lib/numberLib.jq
Normal file
3
tool/lib/numberLib.jq
Normal file
|
@ -0,0 +1,3 @@
|
|||
def round(precision):
|
||||
. * pow(10; precision) | round / pow(10; precision);
|
||||
|
31
tool/main.jq
31
tool/main.jq
|
@ -16,10 +16,11 @@ def printExperienceStats($stats; $substanceFilter; $consumerFilter; $withTitle):
|
|||
($consumerFilter // ["default"]) as $consumerFilter |
|
||||
|
||||
$experience.ingestions |
|
||||
journalLib::filterIngestions($substanceFilter; $consumerFilter) as $ingestions |
|
||||
($ingestions | journalLib::ingestionsByConsumer) as $ingestionsByConsumer |
|
||||
journalLib::filterIngestions($substanceFilter; $consumerFilter) |
|
||||
sort_by(.sortDate) as $ingestions |
|
||||
|
||||
($ingestionsByConsumer | keys) as $consumerNames |
|
||||
($ingestions | journalLib::ingestionsSubstanceNames) as $substanceNames |
|
||||
($ingestions | journalLib::ingestionsByConsumer) as $ingestionsByConsumer |
|
||||
|
||||
"" as $experienceStatsText |
|
||||
$experienceStatsText |
|
||||
|
@ -27,6 +28,7 @@ def printExperienceStats($stats; $substanceFilter; $consumerFilter; $withTitle):
|
|||
. += ($experience | journalUtils::formatExperienceTitle | . + "\n")
|
||||
end | . as $experienceStatsText |
|
||||
|
||||
($ingestionsByConsumer | keys) as $consumerNames |
|
||||
reduce $consumerNames[] as $consumerName ($experienceStatsText;
|
||||
. as $experienceStatsText |
|
||||
$experienceStatsText |
|
||||
|
@ -34,8 +36,7 @@ def printExperienceStats($stats; $substanceFilter; $consumerFilter; $withTitle):
|
|||
then . += "Consumer: \($consumerName)\n"
|
||||
end | . as $experienceStatsText |
|
||||
|
||||
($stats.[$consumerName] | keys) as $substanceNames |
|
||||
|
||||
($ingestionsByConsumer[$consumerName] | journalLib::ingestionsSubstanceNames) as $consumerSubstanceNames |
|
||||
|
||||
$experienceStatsText | reduce $substanceNames[] as $substanceName (.;
|
||||
. as $experienceStatsText |
|
||||
|
@ -51,22 +52,8 @@ def printExperienceStats($stats; $substanceFilter; $consumerFilter; $withTitle):
|
|||
.key as $ingestionMethod |
|
||||
.value as $ingestionInfo |
|
||||
|
||||
def formatIngestionInfo:
|
||||
if $ingestionInfo.dose == null then
|
||||
"Unknown \($ingestionInfo.unit)"
|
||||
else
|
||||
if $ingestionInfo.isEstimate then "~" else "" end +
|
||||
"\($ingestionInfo.dose * 100 | round / 100)" +
|
||||
if $ingestionInfo.standardDeviation != null then
|
||||
"±\($ingestionInfo.standardDeviation)"
|
||||
else "" end +
|
||||
|
||||
if $ingestionInfo.isUnknown then "+ Unknown" else "" end +
|
||||
" \($ingestionInfo.unit)"
|
||||
end;
|
||||
|
||||
$experienceStatsText |
|
||||
. += "Dose (\($ingestionMethod | stringLib::titleCase)): \($ingestionInfo | formatIngestionInfo)\n" |
|
||||
. += "Dose (\($ingestionMethod | stringLib::titleCase)): \($ingestionInfo | journalUtils::formatIngestionInfo)\n" |
|
||||
. as $experienceStatsText |
|
||||
|
||||
$experienceStatsText
|
||||
|
@ -86,8 +73,8 @@ def printExperienceLog($customUnits; $substanceFilter; $consumerFilter; $pretty;
|
|||
($consumerFilter // ["default"]) as $consumerFilter |
|
||||
|
||||
$experience.ingestions |
|
||||
sort_by(.sortDate) |
|
||||
journalLib::filterIngestions($substanceFilter; $consumerFilter) as $ingestions |
|
||||
journalLib::filterIngestions($substanceFilter; $consumerFilter) |
|
||||
sort_by(.sortDate) as $ingestions |
|
||||
|
||||
$ingestions | journalLib::ingestionsConsumerNames as $consumerNames |
|
||||
|
||||
|
|
Loading…
Reference in a new issue