pkg

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StorageTimeFmt = "2006-01-02T15:04:05.000"
)

Variables

This section is empty.

Functions

func HumanizeDuration

func HumanizeDuration(duration time.Duration) string

HumanizeDuration humanizes time.Duration output to a meaningful value, golang's default “time.Duration“ output is badly formatted and unreadable. From: https://gist.github.com/harshavardhana/327e0577c4fed9211f65

func HumanizeDurationShort

func HumanizeDurationShort(duration time.Duration) string

func NewChart

func NewChart(stats Stats, year int, filename string) error

NewChart read the stats and write single page html to filename

func SecondsToHoursString added in v0.0.3

func SecondsToHoursString(seconds int) string

func Sync

func Sync(db KoboDatabase, storage Storage) error

Types

type JSONStorage

type JSONStorage struct {
	DeviceMap  map[string]StorageDevice   `json:"devices"`
	ContentMap map[string]StorageContent  `json:"contents"`
	EventMap   map[string][]StorageEvents `json:"events"`

	// Extra data that may be interesting. TODO need to think about relating content across devices e.g. books with different CIDs, fine for stats but not for shelve content
	Shelf        map[string]StorageShelf          `json:"shelf"`
	ShelfContent map[string][]StorageShelfContent `json:"shelf_content"`
	Bookmark     map[string][]StorageBookmark     `json:"bookmark"`
	// contains filtered or unexported fields
}

func (*JSONStorage) AddBookmark

func (s *JSONStorage) AddBookmark(bID, vID, cID, typeStr, path string, index, startOffset, endOffset int, text, annotation string, created, modified time.Time)

func (*JSONStorage) AddContent

func (s *JSONStorage) AddContent(fn, title, author, url string, words int, book, finished bool, percent int)

func (*JSONStorage) AddDevice

func (s *JSONStorage) AddDevice(device, model string)

func (*JSONStorage) AddEvent

func (s *JSONStorage) AddEvent(fn, device, name string, t time.Time, duration int)

func (*JSONStorage) AddShelf

func (s *JSONStorage) AddShelf(ID, name, internalName, shelfType string, isDeleted bool)

func (*JSONStorage) AddShelfContent

func (s *JSONStorage) AddShelfContent(shelfName, fn string, isDeleted bool)

func (*JSONStorage) Bookmarks

func (s *JSONStorage) Bookmarks(cID string) []StorageBookmark

func (*JSONStorage) Contents

func (s *JSONStorage) Contents() []StorageContent

func (*JSONStorage) Events

func (s *JSONStorage) Events(cID string) []StorageEvents

func (*JSONStorage) Save

func (s *JSONStorage) Save() error

func (*JSONStorage) ShelfContents

func (s *JSONStorage) ShelfContents(shelfName string) []StorageShelfContent

func (*JSONStorage) Shelfs

func (s *JSONStorage) Shelfs() []StorageShelf

type KoboBook

type KoboBook struct {
	ID     string
	Title  string
	Author string
	URL    string

	Finished        bool
	ProgressPercent int

	Parts map[string]KoboBookPart

	// IsBook true for book, false for Pocket
	IsBook bool
}

func (KoboBook) TotalWords

func (k KoboBook) TotalWords() int

type KoboBookPart

type KoboBookPart struct {
	WordCount int
}

type KoboBookmark

type KoboBookmark struct {
	ID          string
	VolumeID    string
	ContentID   string
	BookPath    string
	Index       int
	StartOffset int
	EndOffset   int
	Text        string
	Annotation  string
	Created     time.Time
	Modified    time.Time
	Type        string
}

type KoboDatabase

type KoboDatabase interface {
	Device() (string, string)

	Contents() ([]KoboBook, error)
	Events() ([]KoboEvent, error)

	Shelves() ([]KoboShelf, error)
	ShelfContents() ([]KoboShelfContent, error)

	Bookmarks() ([]KoboBookmark, error)

	Close() error
}

func NewKoboDatabase

func NewKoboDatabase(fn string) (KoboDatabase, error)

type KoboEvent

type KoboEvent struct {
	// BookID is the filename or Pocket ID
	BookID string

	EventType KoboEventType

	Time            time.Time
	ReadingSessions []KoboEventReadingSession
}

KoboEvent minimal event for reading start/stop/session

type KoboEventReadingSession

type KoboEventReadingSession struct {
	UnixStart int
	UnixEnd   int

	Start time.Time
	End   time.Time
}

type KoboEventType

type KoboEventType string
const (
	KoboFilenamePrefix = "/mnt/onboard/"

	KoboTimeFmt = "2006-01-02T15:04:05.000"

	GuessReadEvent  KoboEventType = "GuessRead"
	ReadEvent       KoboEventType = "Read"
	Progress25Event KoboEventType = "25%"
	Progress50Event KoboEventType = "50%"
	Progress75Event KoboEventType = "75%"
	FinishEvent     KoboEventType = "Finish"
)

func (KoboEventType) String

func (t KoboEventType) String() string

type KoboShelf

type KoboShelf struct {
	ID           string
	Name         string
	InternalName string
	Type         string
	IsDeleted    bool
}

type KoboShelfContent

type KoboShelfContent struct {
	ShelfName string
	ContentID string
	IsDeleted bool
}

type MonthStats

type MonthStats struct {
	FinishedBooks    map[string]*StatsBook `json:"finished"`
	FinishedArticles map[string]*StatsBook `json:"finished_articles"`

	Books    map[string]*StatsBook `json:"progressed"`
	Articles map[string]*StatsBook `json:"progressed_articles"`
}

type Stats

type Stats struct {
	Years map[int]YearStats `json:"years"`

	Content map[string]StatsBook `json:"content"`
}

func NewStats

func NewStats(storage Storage) Stats

NewStats take a Storage and calculate the full stats

func (Stats) ArticleSecondsReadWeek added in v0.0.3

func (s Stats) ArticleSecondsReadWeek(year, week int) int

func (Stats) ArticlesFinishedMonth

func (s Stats) ArticlesFinishedMonth(year, month int) []*StatsBook

func (Stats) ArticlesFinishedYear

func (s Stats) ArticlesFinishedYear(year int) []*StatsBook

func (Stats) ArticlesSecondsReadMonth

func (s Stats) ArticlesSecondsReadMonth(year, month int) int

func (Stats) ArticlesSecondsReadYear

func (s Stats) ArticlesSecondsReadYear(year int) int

func (Stats) BooksFinishedMonth

func (s Stats) BooksFinishedMonth(year, month int) []*StatsBook

func (Stats) BooksFinishedYear

func (s Stats) BooksFinishedYear(year int) []*StatsBook

func (Stats) BooksSecondsReadMonth

func (s Stats) BooksSecondsReadMonth(year, month int) int

func (Stats) BooksSecondsReadWeek added in v0.0.3

func (s Stats) BooksSecondsReadWeek(year, week int) int

func (Stats) BooksSecondsReadYear

func (s Stats) BooksSecondsReadYear(year int) int

type StatsBook

type StatsBook struct {
	BookID string `json:"id"`
	Title  string `json:"title"`
	Author string `json:"author"`
	URL    string `json:"url"`

	Words int `json:"words"`

	IsBook       bool   `json:"is_book"`
	IsFinished   bool   `json:"is_finished"`
	FinishedTime string `json:"finished_time"`

	Reads     []StatsRead     `json:"reads"`
	Bookmarks []StatsBookmark `json:"bookmarks"`
}

func (StatsBook) FirstReadTime

func (b StatsBook) FirstReadTime() string

func (StatsBook) NumSessions

func (b StatsBook) NumSessions() int

func (StatsBook) NumSessionsInMonth added in v0.0.4

func (b StatsBook) NumSessionsInMonth(year, month int) int

func (StatsBook) NumSessionsInYear

func (b StatsBook) NumSessionsInYear(year int) int

func (StatsBook) ReadSeconds

func (b StatsBook) ReadSeconds() int

func (StatsBook) ReadSecondsInMonth added in v0.0.3

func (b StatsBook) ReadSecondsInMonth(year, month int) int

func (StatsBook) ReadSecondsInWeek added in v0.0.3

func (b StatsBook) ReadSecondsInWeek(year int, week int) int

func (StatsBook) ReadSecondsInYear

func (b StatsBook) ReadSecondsInYear(year int) int

type StatsBookmark

type StatsBookmark struct {
	ID          string `json:"id,omitempty"`
	Index       int    `json:"idx,omitempty"`
	StartOffset int    `json:"start_offset,omitempty"`
	EndOffset   int    `json:"end_offset,omitempty"`
	Text        string `json:"text,omitempty"`
	Annotation  string `json:"annotation,omitempty"`
	Created     string `json:"created,omitempty"`
	Modified    string `json:"modified,omitempty"`
	Type        string `json:"type,omitempty"`
}

type StatsRead

type StatsRead struct {
	Time     string `json:"time"`
	Duration int    `json:"duration"`
}

type Statter

type Statter interface {
	BooksFinishedYear(year int) []*StatsBook
	BooksFinishedMonth(year, month int) []*StatsBook

	ArticlesFinishedYear(year int) []*StatsBook
	ArticlesFinishedMonth(year, month int) []*StatsBook

	BooksSecondsReadYear(year int) int
	BooksSecondsReadMonth(year, month int) int

	ArticlesSecondsReadYear(year int) int
	ArticlesSecondsReadMonth(year, month int) int
}

type Storage

type Storage interface {
	Save() error

	AddContent(fn, title, author, url string, words int, book, finished bool, percent int)
	AddDevice(device, model string)
	AddEvent(fn, device, name string, t time.Time, duration int)

	AddShelf(ID, name, internalName, shelfType string, isDeleted bool)
	AddShelfContent(shelfName, fn string, isDeleted bool)

	Contents() []StorageContent
	Events(cID string) []StorageEvents
	Bookmarks(cID string) []StorageBookmark

	Shelfs() []StorageShelf
	ShelfContents(shelfName string) []StorageShelfContent

	AddBookmark(bID, vID, cID, typeStr, path string, index, startOffset, endOffset int, text, annotation string, created, modified time.Time)
}

func OpenStorageOrCreate

func OpenStorageOrCreate(fn string) (Storage, error)

type StorageBookmark

type StorageBookmark struct {
	ID          string `json:"id,omitempty"`
	VolumeID    string `json:"volume_id,omitempty"`
	ContentID   string `json:"content_id,omitempty"`
	BookPath    string `json:"book_path,omitempty"`
	Index       int    `json:"idx,omitempty"`
	StartOffset int    `json:"start_offset,omitempty"`
	EndOffset   int    `json:"end_offset,omitempty"`
	Text        string `json:"text,omitempty"`
	Annotation  string `json:"annotation,omitempty"`
	Created     string `json:"created,omitempty"`
	Modified    string `json:"modified,omitempty"`
	Type        string `json:"type,omitempty"`
}

type StorageContent

type StorageContent struct {
	ID     string `json:"id"`
	Title  string `json:"title"`
	Author string `json:"author"`
	URL    string `json:"url"`

	Words int `json:"words"`

	IsBook     bool `json:"book"`
	IsFinished bool `json:"article_is_finished"`
}

type StorageDevice

type StorageDevice struct {
	Device string `json:"device"`
	Model  string `json:"model"`
}

type StorageEvents

type StorageEvents struct {
	EventName string `json:"event"`
	Time      string `json:"time"`
	Duration  int    `json:"duration"`
	Device    string `json:"device"`
}

type StorageShelf

type StorageShelf struct {
	ID           string `json:"id"`
	Name         string `json:"name"`
	InternalName string `json:"internal_name"`
	Type         string `json:"type"`
	IsDeleted    bool   `json:"is_deleted"`
}

type StorageShelfContent

type StorageShelfContent struct {
	ShelfID   string `json:"shelf_id"`
	ContentID string `json:"content_id"`
	IsDeleted bool   `json:"is_deleted"`
}

type YearStats

type YearStats struct {
	Months map[int]MonthStats `json:"months"`
	Weeks  map[int]MonthStats `json:"weeks"`
}

Jump to

Keyboard shortcuts

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