journal/tool/journalUtils.jq

70 lines
2.2 KiB
Plaintext
Raw Normal View History

2024-11-09 00:57:22 +00:00
import "lib/utilsLib" as utilsLib;
2024-11-09 00:49:08 +00:00
import "lib/stringLib" as stringLib;
2024-11-09 15:36:49 +00:00
import "lib/numberLib" as numberLib;
2024-11-09 00:57:22 +00:00
import "lib/journalLib" as journalLib;
2024-11-09 00:49:08 +00:00
2024-11-07 08:58:38 +00:00
def formatExperienceTitle:
. as $experience |
"\"\(.title)\": \(.creationDate / 1000 | strftime("%d-%m-%Y"))";
2024-11-09 15:58:44 +00:00
def formatDose($dose; $unit; $isEstimate; $standardDeviation):
if $dose == null then
2024-11-10 08:13:25 +00:00
"Unknown \($unit)"
2024-11-09 15:58:44 +00:00
else
(if $isEstimate then "~" else "" end) as $estimate |
(if $standardDeviation != null then "±\($standardDeviation)" else "" end) as $standardDeviation |
"\($estimate)\($dose | numberLib::round(2))\($standardDeviation) \($unit)"
end;
2024-11-07 08:58:38 +00:00
def formatIngestionDose($customUnits):
. as $ingestion |
2024-11-09 15:36:49 +00:00
(. | journalLib::ingestionDose($customUnits)) as $dose |
(. | journalLib::ingestionUnit($customUnits)) as $unit |
(. | journalLib::ingestionStandardDeviation($customUnits)) as $standardDeviation |
2024-11-07 08:58:38 +00:00
$customUnits | map(select(.id == $ingestion.customUnitId))[0] as $customUnit |
if $ingestion.dose == null then
"Unknown"
elif $customUnit == null then
2024-11-09 15:58:44 +00:00
formatDose($dose; $unit; $ingestion.isDoseAnEstimate; $standardDeviation)
2024-11-07 08:58:38 +00:00
else
2024-11-09 15:58:44 +00:00
formatDose($dose; $unit; $ingestion.isDoseAnEstimate; $standardDeviation) +
" (" +
formatDose($customUnit.dose; $unit; $customUnit.isEstimate; $customUnit.estimatedDoseStandardDeviation) +
" * " +
2024-11-10 08:13:25 +00:00
formatDose($ingestion.dose; $customUnit.unit; $ingestion.isDoseAnEstimate; $ingestion.estimatedDoseStandardDeviation) +
")"
2024-11-07 08:58:38 +00:00
end;
def formatIngestionTime:
. as $ingestion |
$ingestion.time / 1000 | strftime("%a %I:%M %p");
def formatIngestionROA($customUnits; $substitutions):
. as $ingestion |
$ingestion.administrationRoute as $roa |
(if
$substitutions | has($roa)
then
2024-11-07 21:45:22 +00:00
$substitutions | .[$roa]
2024-11-07 08:58:38 +00:00
else
2024-11-09 00:49:08 +00:00
$roa | stringLib::titleCase
2024-11-07 08:58:38 +00:00
end) as $roaText |
$ingestion.customUnitId as $customUnitId |
if
$customUnitId == null
then
$roaText
else
$customUnits | map(select(.id == $customUnitId))[0] as $customUnit |
"\($roaText) (\($customUnit.name))"
end;
2024-11-09 15:36:49 +00:00
def formatIngestionROA($customUnits): formatIngestionROA($customUnits; {});
def formatIngestionInfo:
. as $ingestionInfo |
2024-11-10 08:13:25 +00:00
formatDose(.dose; .unit; .isEstimate; .standardDeviation);