model

package
v0.9.11 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoalForRange

func GoalForRange(goal Goal, startDate, endDate Date) time.Duration

GoalForRange is a helper to sum up the duration for the given range expected by the given Goal.

func ToString

func ToString(w time.Weekday) string

Types

type Backlog added in v0.8.0

type Backlog struct {
	Tasks []*Task
	Mtx   sync.RWMutex
}

Backlog holds Tasks which can be popped out of the backlog to a concrete timeslot. Backlogging Tasks is a planning mechanism; the Backlog can be seen as a to-do list.

func BacklogFromReader added in v0.8.0

func BacklogFromReader(r io.Reader, categoryGetter func(string) Category) (*Backlog, error)

BacklogFromReader reads and deserializes a backlog from the io.Reader and returns the backlog.

func (*Backlog) AddAfter added in v0.8.0

func (b *Backlog) AddAfter(anchorTask *Task) (newTask *Task, parent *Task, err error)

AddAfter adds a new task after the given anchorTask.

func (*Backlog) AddBefore added in v0.9.2

func (b *Backlog) AddBefore(anchorTask *Task) (newTask *Task, parent *Task, err error)

AddBefore adds a new task before the given anchorTask.

func (*Backlog) AddLast added in v0.8.0

func (b *Backlog) AddLast() *Task

AddFirst

func (*Backlog) Locate added in v0.8.0

func (b *Backlog) Locate(task *Task) (prev *Task, next *Task, parentage []*Task, index int, err error)

Locate the given task, i.e. give its neighbors and parentage. Returns an error when the task cannot be found.

func (*Backlog) Pop added in v0.8.0

func (b *Backlog) Pop(task *Task) (prev *Task, next *Task, parentage []*Task, err error)

Pop the given task out from wherever it is in this backlog, returning that location (by surrounding tasks and parentage).

func (*Backlog) Write added in v0.8.0

func (b *Backlog) Write(w io.Writer) error

Write writes the Backlog to the given io.Writer, e.g., an opened file.

type BacklogStored added in v0.8.0

type BacklogStored struct {
	TasksByCategory map[string][]BaseTask `yaml:",inline"`
}

BacklogStored.

type BaseTask added in v0.8.0

type BaseTask struct {
	Name     string         `yaml:"name"`
	Duration *time.Duration `yaml:"duration,omitempty"`
	Deadline *time.Time     `yaml:"deadline,omitempty"`
	Subtasks []BaseTask     `yaml:"subtasks,omitempty"`
}

BaseTask.

type ByName

type ByName []Category

func (ByName) Len

func (a ByName) Len() int

func (ByName) Less

func (a ByName) Less(i, j int) bool

func (ByName) Swap

func (a ByName) Swap(i, j int)

type ByStartConsideringDuration

type ByStartConsideringDuration []*Event

func (ByStartConsideringDuration) Len

func (ByStartConsideringDuration) Less

func (a ByStartConsideringDuration) Less(i, j int) bool

func (ByStartConsideringDuration) Swap

func (a ByStartConsideringDuration) Swap(i, j int)

type Category

type Category struct {
	Name       string `dpedit:"name"`
	Priority   int    `dpeditr:"priority"`
	Goal       Goal   `dpedit:",ignore"`
	Deprecated bool   `dpedit:",ignore"`
}

type Date

type Date struct {
	Year  int
	Month int
	Day   int
}

func FromString

func FromString(s string) (Date, error)

func (Date) Backward

func (d Date) Backward(by int) Date

func (Date) DaysUntil

func (a Date) DaysUntil(b Date) int

Returns the number of days from a date A until a date B is reached. (e.g. from 2021-12-14 until 2021-12-19 -> 5 days) expects b not to be before a

func (Date) Forward

func (d Date) Forward(by int) Date

func (Date) GetDayInMonth

func (d Date) GetDayInMonth(index int) Date

GetDayInMonth returns the indexed day in the month of the receiver.

Note that indexing 0 will return the first of the month.

func (Date) GetDayInWeek

func (d Date) GetDayInWeek(index int) Date

GetDayInWeek returns the date that is on the weekday for the given index in the week the receiver is in.

Index here means that 0 is Monday, 6 is Sunday.

func (Date) GetLastOfMonth

func (d Date) GetLastOfMonth() Date

GetLastOfMonth returns the last date of the month of the receiver.

func (Date) GetSunTimes

func (d Date) GetSunTimes(latitude, longitude float64) SunTimes

Warning: slow (TODO)

func (Date) Is

func (d Date) Is(t time.Time) bool

func (Date) IsAfter

func (a Date) IsAfter(b Date) bool

Whether a date A is after a date B.

func (Date) IsBefore

func (a Date) IsBefore(b Date) bool

Whether a date A is before a date B.

func (Date) MonthBounds

func (d Date) MonthBounds() (first Date, last Date)

func (Date) Next

func (d Date) Next() Date

func (Date) Prev

func (d Date) Prev() Date

func (Date) ToGotime

func (d Date) ToGotime() time.Time

func (Date) ToString

func (d Date) ToString() string

func (Date) ToWeekday

func (d Date) ToWeekday() time.Weekday

func (Date) Valid

func (d Date) Valid() bool

func (Date) Week

func (d Date) Week() (monday Date, sunday Date)

TODO: rename WeekBounds or similar

type Day

type Day struct {
	Events  []*Event
	Current *Event
}

func NewDay

func NewDay() *Day

func NewDayWithEvents

func NewDayWithEvents(events []*Event) *Day

func (*Day) AddEvent

func (day *Day) AddEvent(e *Event) error

func (*Day) Clone

func (day *Day) Clone() *Day

func (*Day) CurrentNext

func (day *Day) CurrentNext()

func (*Day) CurrentPrev

func (day *Day) CurrentPrev()

func (*Day) Flatten

func (day *Day) Flatten()

"Flattens" the events of a given day, i.E. ensures that no overlapping events exist. It does this by e.g. trimming one of two overlapping events or splitting a less prioritized event if it had a higher-priority event occur during it as shown here:

+-------+         +-------+
| a     |         | a     |    (`a` lower prio than `B`)
|   +-----+       +-------+
|   | B   |  ~~>  | B     |
|   +-----+       +-------+
|       |         | a     |
+-------+         +-------+

+-------+         +-------+
| a     |         | a     |    (`a` lower prio than `B`)
|   +-----+       +-------+
|   | B   |  ~~>  | B     |
+---|     |       |       |
    +-----+       +-------+

func (*Day) GetEventsFrom

func (day *Day) GetEventsFrom(event *Event) []*Event

TODO(ja-he): remove

func (*Day) GetNextEventAfter

func (day *Day) GetNextEventAfter(t Timestamp) *Event

func (*Day) GetPrevEventBefore

func (day *Day) GetPrevEventBefore(t Timestamp) *Event

func (*Day) GetTimesheetEntry added in v0.9.0

func (day *Day) GetTimesheetEntry(matcher func(string) bool) TimesheetEntry

GetTimesheetEntry returns the TimesheetEntry for this day for a given category (e.g. "work").

func (*Day) MoveEventsPushingBy

func (day *Day) MoveEventsPushingBy(event *Event, duration int, snapMinsMod int) error

func (*Day) MoveSingleEventBy

func (day *Day) MoveSingleEventBy(event *Event, duration int, snapMinsMod int) error

func (*Day) MoveSingleEventTo

func (day *Day) MoveSingleEventTo(event *Event, newStart Timestamp) error

func (*Day) RemoveEvent

func (day *Day) RemoveEvent(event *Event)

func (*Day) ResizeBy

func (day *Day) ResizeBy(event *Event, delta int) error

func (*Day) ResizeTo

func (day *Day) ResizeTo(event *Event, newEnd Timestamp) error

func (*Day) SnapEnd

func (day *Day) SnapEnd(event *Event, resolution int) error

func (*Day) SplitEvent

func (day *Day) SplitEvent(originalEvent *Event, timestamp Timestamp) error

func (*Day) SumUpByCategory

func (day *Day) SumUpByCategory() map[Category]int

Sum up the event durations of a given day per category. Time cannot be counted multiple times, so if multiple events overlap, only one of them can have the time of the overlap counted. The prioritization for this is according to category priority.

func (*Day) ToSlice

func (day *Day) ToSlice() []string

func (*Day) UpdateEventOrder

func (day *Day) UpdateEventOrder()

type DayAndTime

type DayAndTime struct {
	Date      Date
	Timestamp Timestamp
}

func FromTime

func FromTime(t time.Time) *DayAndTime

type Event

type Event struct {
	Name  string    `dpedit:"name"`
	Cat   Category  `dpedit:"category"`
	Start Timestamp `dpedit:",ignore"`
	End   Timestamp `dpedit:",ignore"`
}

func NewEvent

func NewEvent(s string, knownCategories []Category) *Event

func (*Event) CanBeResizedBy

func (event *Event) CanBeResizedBy(delta int) bool

func (*Event) CanMoveBy

func (event *Event) CanMoveBy(minutes int, snapMinsMod int) bool

func (*Event) CanMoveTo

func (event *Event) CanMoveTo(newStart Timestamp) bool

func (*Event) Clone

func (e *Event) Clone() *Event

func (*Event) Duration

func (e *Event) Duration() int

func (*Event) IsContainedIn

func (b *Event) IsContainedIn(a *Event) bool

Whether one event A contains another B, i.E. - B's start is _not before_ A's start and - B's end is _not after_ A's end

func (*Event) MoveBy

func (e *Event) MoveBy(duration int, snapMinsMod int) error

func (*Event) MoveTo

func (e *Event) MoveTo(newStart Timestamp) error

func (*Event) ResizeBy

func (e *Event) ResizeBy(delta int) error

func (*Event) Snap

func (e *Event) Snap(minuteResolution int)

func (*Event) StartsDuring

func (b *Event) StartsDuring(a *Event) bool

Whether one event B starts during another A.

type Goal

type Goal interface {
	Requires(Date) time.Duration
}

Goal defines a time goal. It can be queried, for any given date, what duration the goal requires.

type RangedGoal

type RangedGoal struct {
	Entries []rangedGoalEntry
}

RangedGoal is a Goal that is defined by any number of ranges and the expected duration for each.

func NewRangedGoalFromConfig

func NewRangedGoalFromConfig(cfg []config.RangedGoal) (*RangedGoal, error)

NewRangedGoalFromConfig constructs a new RangedGoal from config data.

func (*RangedGoal) Requires

func (g *RangedGoal) Requires(date Date) time.Duration

Requires returns the duration required for the given date.

It is (Time/ DAYSINRANGE(Start, End)) for any day in range, 0 otherwise.

type SunTimes

type SunTimes struct {
	Rise, Set Timestamp
}

type Task added in v0.8.0

type Task struct {
	Name     string         `dpedit:"name"`
	Category Category       `dpedit:"category"`
	Duration *time.Duration `dpedit:"duration"`
	Deadline *time.Time     `dpedit:"deadline"`
	Subtasks []*Task        `dpedit:",ignore"`
}

A Task remains to be done (or dropped) but is not yet scheduled. It has a name and belongs to a category (by name); it can further have a duration (estimate), a deadline (due date) and subtasks.

func (*Task) ToEvent added in v0.8.0

func (t *Task) ToEvent(startTime time.Time, namePrefix string) []*Event

ToEvent convernts a task (including potential subtasks) to the corresponding set of events (subtasks becoming events during the main event, recursively).

type TasksByDeadline added in v0.9.2

type TasksByDeadline []*Task

TasksByDeadline is a sort interface to stort tasks by their deadlines

func (TasksByDeadline) Len added in v0.9.2

func (a TasksByDeadline) Len() int

func (TasksByDeadline) Less added in v0.9.2

func (a TasksByDeadline) Less(i, j int) bool

func (TasksByDeadline) Swap added in v0.9.2

func (a TasksByDeadline) Swap(i, j int)

type TimeOffset

type TimeOffset struct {
	T   Timestamp
	Add bool
}

type TimesheetEntry added in v0.9.0

type TimesheetEntry struct {
	Start         Timestamp
	BreakDuration time.Duration
	End           Timestamp
}

A TimesheetEntry represents an entry in a common timesheet.

It defines a beginning (i.e. the time you clocked in), an end (i.e. the time you clocked out), and the total length of breaks taken between them.

func (*TimesheetEntry) IsEmpty added in v0.9.0

func (e *TimesheetEntry) IsEmpty() bool

IsEmpty is a helper to identify empty timesheet entries.

type Timestamp

type Timestamp struct {
	Hour, Minute int
}

func NewTimestamp

func NewTimestamp(s string) *Timestamp

func NewTimestampFromGotime

func NewTimestampFromGotime(time time.Time) *Timestamp

func (Timestamp) DurationInMinutesUntil

func (t1 Timestamp) DurationInMinutesUntil(t2 Timestamp) int

Returns the duration in minutes between to a given timestamp t2. Does not check that t2 is in fact later!

func (Timestamp) DurationUntil added in v0.7.8

func (t1 Timestamp) DurationUntil(t2 Timestamp) time.Duration

Returns the duration (time.Duration) to a given timestamp t2. Does not check that t2 is in fact later!

func (Timestamp) IsAfter

func (a Timestamp) IsAfter(b Timestamp) bool

func (Timestamp) IsBefore

func (a Timestamp) IsBefore(b Timestamp) bool

func (Timestamp) Legal

func (t Timestamp) Legal() bool

func (Timestamp) Offset

func (t Timestamp) Offset(o TimeOffset) Timestamp

Returns a timestamp offset by a given offset, which can be additive or subtractive. "Loops around", meaning offsetting 0:10 by -1 hour results in 23:10, offsetting 23:10 by +1 hour results in 0:10.

func (Timestamp) OffsetMinutes

func (t Timestamp) OffsetMinutes(minutes int) Timestamp

func (Timestamp) Snap

func (t Timestamp) Snap(minutesModulus int) Timestamp

TODO: migrate to time.Duration-based

func (Timestamp) ToString

func (a Timestamp) ToString() string

type WorkweekGoal

type WorkweekGoal struct {
	Monday    time.Duration
	Tuesday   time.Duration
	Wednesday time.Duration
	Thursday  time.Duration
	Friday    time.Duration
	Saturday  time.Duration
	Sunday    time.Duration
}

WorkweekGoal is a goal that defines the duration per day of the week.

func NewWorkweekGoalFromConfig

func NewWorkweekGoalFromConfig(cfg config.WorkweekGoal) (*WorkweekGoal, error)

NewWorkweekGoalFromConfig constructs a new WorkweekGoal from config data.

func (*WorkweekGoal) Requires

func (g *WorkweekGoal) Requires(date Date) time.Duration

Requires returns the duration required for the given date.

It is just the duration defined for the date's weekday.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳