Skip to content

Instantly share code, notes, and snippets.

@jaimet
Forked from dimalyshev/import.awk
Created December 14, 2021 12:26
Show Gist options
  • Save jaimet/323ffd1f0a0bc245b4f2723926eccda3 to your computer and use it in GitHub Desktop.
Save jaimet/323ffd1f0a0bc245b4f2723926eccda3 to your computer and use it in GitHub Desktop.
libre
# import.awk - convert LibreView.com csv export to Diabetes:M (Android App) import csv
BEGIN {
FS = "[, ]"
print("name:DIABETES_M","version:2.0.0","export:Entries")
print("DateTimeFormatted","glucose","carbs","proteins","fats","calories","carb_bolus","correction_bolus","extended_bolus","extended_bolus_duration","basal","basal_is_rate","bolus_insulin_type","basal_insulin_type","weight_entry","weight","category","category_name","carb_ratio_factor","insulin_sensitivity_factor","notes","is_sensor","pressure_sys","pressure_dia","pulse","injection_bolus_site","injection_basal_site","finger_test_site","ketones","google_fit_source","timezone","exercise_index","exercise_comment","exercise_duration","medications","food","us_units","hba1c","cholesterol_total","cholesterol_ldl","cholesterol_hdl","triglycerides","microalbumin_test_type","microalbumin","creatinine_clearance","egfr","cystatin_c","albumin","creatinine","calcium","total_protein","sodium","potassium","bicarbonate","chloride","alp","alt","ast","bilirubin","bun")
suffix = ""
}
END {
for (r in data)
print data[r,"rec"]
}
/^Export/, /^Meter/{ next}
/.*-2018.*/{
#print "dt:",$1, "tm",$2
split( $1, dt, "-")
tm = dt[3] "-" dt[2] "-" dt[1] " " $2 ":00"
out="";
for(i=3;i<=NF;i++)
{out=out i ": "$i}
#print out
#print "edt:",tm
#print " g:" $4 " b:" $5 "c:" $6 " b:" $8 " eb:" $11
# set record type
t = $3
e = data[tm]
# if date record not in array yet
if (e == ""){
data[tm,"g"] = "0.0"
data[tm,"c"] = "0.0"
data[tm,"b"] = "0.0"
data[tm,"eb"] = "0.0"
}
# BG(blood glucose)
# auto scan (every 15 min)8 if (t == 1 && $4 != "")
if (t == 1)
data[tm,"g"] = $4
# manual scan (by reader)
if (t == 1 && $5 != "" )
data[tm,"g"] = $5
# bolus
if (t == 4 && $7 != "")
data[tm,"b"] = $7
# basel
if (t == 4 && $13 != "" )
data[tm,"eb"] = $13
# carbs
if (t == 5)
data[tm,"c"] = $9
e = data[tm]
print "arr" isarray(data)
#print "data:" data[tm,"g"], data[tm,"c"], data[tm,"b"] ":" data[tm,"eb"]
etm = "\"" tm "\""
g = "\"" data[tm,"g"] "\""
c = "\"" data[tm,"c"] "\""
b = "\"" data[tm,"b"] "\""
eb = "\"" data[tm,"eb"] "\""
#data[tm,"rec"] = etm "," g "," c ",\"0.0\",\"0.0\",\"0.0\"," b ",\"0.0\"," eb ",\"0\",\"0.0\",\"false\",\"0\",\"0\",\"0.0\",\"0.0\",\"7\",,\"0.0","0.0","","false","0","0","0","-1","-1","-1","0.0",,"Europe/Moscow","0","","0","","","false","0.0","0.0","0.0","0.0","0.0","0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0"
rec = etm "," g "," c ",,,," b ",," eb ",,,\"false\",,,,,,,,,,\"false\",,,,\"-1\",\"-1\",\"-1\",,,\"Europe/Moscow\",,,,,,\"false\",,,,,,,,,,,,,,,,,,,,,,,"
data[tm,"rec"] = rec
print t " :: " rec
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment