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