nightscout

package module
v0.0.0-...-c6ec02f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2021 License: MIT Imports: 13 Imported by: 10

Documentation

Index

Constants

View Source
const (
	SGVType = "sgv"
	MBGType = "mbg"
	CalType = "cal"
)

Values for the Entry Type field.

View Source
const (
	// DateStringLayout is a time format accepted by Nightscout.
	DateStringLayout = time.RFC3339
)

Variables

This section is empty.

Functions

func Date

func Date(t time.Time) int64

Date converts a time.Time value to a Nightscout date value in milliseconds.

func Device

func Device() string

Device returns the Nightscout device name.

func Hostname

func Hostname() string

Hostname returns the host name.

func JSON

func JSON(v interface{}) string

JSON marshals the given data in indented form and returns it as a string.

func Trend

func Trend(entries Entries) string

Trend returns a string describing the glucose trend, assuming the entries are in reverse chronological order.

func Username

func Username() string

Username returns the user name.

Types

type Battery

type Battery struct {
	Voltage Voltage `json:"voltage"`
}

Battery represents the battery data in a Pump record.

type DeviceStatus

type DeviceStatus struct {
	CreatedAt time.Time `json:"created_at"`
	Device    string    `json:"device"`
	Openaps   Openaps   `json:"openaps,omitempty"`
	Pump      Pump      `json:"pump,omitempty"`
	Uploader  Uploader  `json:"uploader,omitempty"`
}

DeviceStatus represents data for the Nightscout devicestatus API.

type Entries

type Entries []Entry

Entries represents a sequence of Entry values.

func MergeEntries

func MergeEntries(u, v Entries) Entries

MergeEntries merges entries that are already in reverse chronological order. Duplicates are removed.

func Missing

func Missing(entries Entries, gaps []Gap) Entries

Missing returns the Entry values that fall within the given gaps. Entries must be in reverse chronological order.

func ReadEntries

func ReadEntries(r io.Reader) (Entries, error)

ReadEntries reads entries in JSON fromat from an io.Reader.

func ReadEntriesFile

func ReadEntriesFile(file string) (Entries, error)

ReadEntriesFile reads entries in JSON format from a file.

func (Entries) Len

func (e Entries) Len() int

func (Entries) Less

func (e Entries) Less(i, j int) bool

func (Entries) Print

func (e Entries) Print()

Print writes entries in JSON format on os.Stdout.

func (Entries) Reverse

func (e Entries) Reverse()

Reverse reverses the entries, in place.

func (Entries) Save

func (e Entries) Save(file string) error

Save writes entries in JSON format to a file.

func (Entries) Sort

func (e Entries) Sort()

Sort sorts the entries into reverse chronological order, in place.

func (Entries) Swap

func (e Entries) Swap(i, j int)

func (Entries) TrimAfter

func (e Entries) TrimAfter(cutoff time.Time) Entries

TrimAfter returns the entries that are more recent than the specified time. The entries must be in reverse chronological order.

func (Entries) Write

func (e Entries) Write(w io.Writer) error

Write writes entries in JSON format to an io.Writer.

func (Entries) X

func (e Entries) X(i int) float64

X returns the x-coordinate of entry i.

func (Entries) Y

func (e Entries) Y(i int) float64

Y returns the y-coordinate of entry i.

type Entry

type Entry struct {
	Type       string  `json:"type"`
	Date       int64   `json:"date"` // Unix time in milliseconds
	DateString string  `json:"dateString"`
	Device     string  `json:"device,omitempty"`
	SGV        int     `json:"sgv,omitempty"`
	Direction  string  `json:"direction,omitempty"`
	Filtered   int     `json:"filtered,omitempty"`
	Unfiltered int     `json:"unfiltered,omitempty"`
	RSSI       int     `json:"rssi,omitempty"`
	Noise      int     `json:"noise,omitempty"`
	Slope      float64 `json:"slope,omitempty"`
	Intercept  float64 `json:"intercept,omitempty"`
	Scale      float64 `json:"scale,omitempty"`
	MBG        int     `json:"mbg,omitempty"`
}

Entry represents data for the Nightscout entries API.

func (Entry) After

func (x Entry) After(y Entry) bool

After returns true if x comes after y chronologically, using the Type field to break ties.

func (Entry) Time

func (e Entry) Time() time.Time

Time returns the time.Time value corresponding to the Date field.

type EntryTime

type EntryTime struct {
	Date int64 `json:"date"` // Unix time in milliseconds
}

EntryTime is used to unmarshal just the Date field of an Entry.

func (EntryTime) Time

func (e EntryTime) Time() time.Time

Time returns the time.Time value corresponding to the Date field.

type EntryTimes

type EntryTimes []EntryTime

EntryTimes represents a sequence of entry times.

func (EntryTimes) Len

func (v EntryTimes) Len() int

func (EntryTimes) Less

func (v EntryTimes) Less(i, j int) bool

func (EntryTimes) Swap

func (v EntryTimes) Swap(i, j int)

type Gap

type Gap struct {
	Start  time.Time
	Finish time.Time
}

Gap represents a temporal gap.

type Glucose

type Glucose int

Glucose corresponds to the medtronic.Glucose type.

type IOB

type IOB struct {
	IOB Insulin `json:"iob"`
}

IOB represents the insulin-on-board data in an Openaps record.

type Insulin

type Insulin float64

Insulin corresponds to the medtronic.Insulin type.

type Line

type Line struct {
	Slope     float64
	Intercept float64
}

Line represents the linear equation y = Slope*x + Intercept.

func FindLine

func FindLine(points Points) Line

FindLine performs simple linear regression on a set of points.

func (Line) Eval

func (l Line) Eval(x float64) float64

Eval evaluates a linear function at the given value.

type Openaps

type Openaps struct {
	IOB IOB `json:"iob"`
}

Openaps represents the openaps data in a DeviceStatus record.

type Points

type Points interface {
	Len() int
	X(int) float64
	Y(int) float64
}

Points is the interface satisfied by a set of points.

type Profile

type Profile struct {
	ID             string                 `json:"_id"`
	CreatedAt      time.Time              `json:"created_at"`
	StartDate      time.Time              `json:"startDate"`
	DefaultProfile string                 `json:"defaultProfile"`
	Store          map[string]ProfileData `json:"store"`
}

Profile represents data for the Nightscout profile API.

type ProfileData

type ProfileData struct {
	DIA        int      `json:"dia"` // hours
	Basal      Schedule `json:"basal"`
	CarbRatio  Schedule `json:"carbratio"`
	Sens       Schedule `json:"sens"`
	TargetLow  Schedule `json:"target_low"`
	TargetHigh Schedule `json:"target_high"`
	TimeZone   string   `json:"timezone"`
	Units      string   `json:"units"`
}

ProfileData represents the information in a Profile record.

type ProfileID

type ProfileID struct {
	ID string `json:"_id"`
}

ProfileID is used to unmarshal just the ID field of a Profile.

type Pump

type Pump struct {
	Battery   Battery   `json:"battery"`
	Clock     time.Time `json:"clock"`
	Reservoir Insulin   `json:"reservoir"`
	Status    Status    `json:"status"`
}

Pump represents the pump data in a DeviceStatus record.

type Schedule

type Schedule []TimeValue

Schedule represents a sequence of times and values.

type Status

type Status struct {
	Status    string `json:"status"`
	Bolusing  bool   `json:"bolusing"`
	Suspended bool   `json:"suspended"`
}

Status represents the status data in a Pump record.

type TimeValue

type TimeValue struct {
	Time  string      `json:"time"`
	Value interface{} `json:"value"`
}

TimeValue represents a value with an associated time.

type Treatment

type Treatment struct {
	CreatedAt time.Time `json:"created_at"`
	EventType string    `json:"eventType"`
	EnteredBy string    `json:"enteredBy,omitempty"`
	Glucose   *Glucose  `json:"glucose,omitempty"`
	Absolute  *Insulin  `json:"absolute,omitempty"`
	Duration  *int      `json:"duration,omitempty"` // minutes
	Insulin   *Insulin  `json:"insulin,omitempty"`
	Units     string    `json:"units,omitempty"`
}

Treatment represents data for the Nightscout treatments API.

type TreatmentTime

type TreatmentTime struct {
	CreatedAt time.Time `json:"created_at"`
}

TreatmentTime is used to unmarshal just the CreatedAt field of a Treatment.

type Uploader

type Uploader struct {
	BatteryLevel   int     `json:"battery"`
	BatteryVoltage Voltage `json:"batteryVoltage,omitempty"`
	RawBattery     int     `json:"rawBattery,omitempty"`
}

Uploader represents the uploader data in a DeviceStatus record.

type Voltage

type Voltage float64

Voltage corresponds to the medtronic.Voltage type.

type Website

type Website struct {
	URL    *url.URL
	Client *http.Client
	Token  string
	// contains filtered or unexported fields
}

func DefaultSite

func DefaultSite() (*Website, error)

func Site

func Site(site string) (*Website, error)

func (*Website) APISecret

func (w *Website) APISecret() (string, error)

func (Website) DownloadEntries

func (w Website) DownloadEntries(n int) (Entries, error)

DownloadEntries downloads the n most recent entries from Nightscout.

func (Website) Gaps

func (w Website) Gaps(since time.Time, gapDuration time.Duration) ([]Gap, error)

Gaps finds gaps in Nightscout entries since the given time that are longer than the specified duration.

func (*Website) Get

func (w *Website) Get(api string, result interface{}) error

Get performs a GET operation on a Nightscout API.

func (*Website) NoUpload

func (w *Website) NoUpload() bool

NoUpload returns the value of the noUpload flag.

func (*Website) Put

func (w *Website) Put(api string, data interface{}) error

Put performs a PUT operation on a Nightscout API.

func (*Website) SetNoUpload

func (w *Website) SetNoUpload(flag bool)

SetNoUpload sets the value of the noUpload flag.

func (*Website) SetVerbose

func (w *Website) SetVerbose(flag bool)

SetVerbose sets the value of the verbose flag.

func (*Website) String

func (w *Website) String() string

func (*Website) Upload

func (w *Website) Upload(api string, data interface{}) error

Upload performs a POST operation on a Nightscout API.

func (*Website) Verbose

func (w *Website) Verbose() bool

Verbose returns the value of the verbose flag.

func (Website) XDripEntries

func (w Website) XDripEntries() (Entries, error)

func (Website) XDripTime

func (w Website) XDripTime() (time.Time, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL