[record,stent,count] -> pomodoro
This commit is contained in:
parent
24672d396e
commit
8c071b0c94
4
main.go
4
main.go
|
@ -20,7 +20,7 @@ func start(path *string) func(*cli.Cmd) {
|
|||
cmd.Spec = "[OPTIONS] MESSAGE"
|
||||
var (
|
||||
duration = cmd.StringOpt("d duration", "25m", "duration of each stent")
|
||||
stents = cmd.IntOpt("s stents", 4, "number of working stents")
|
||||
pomodoros = cmd.IntOpt("p pomodoros", 4, "number of pomodoros")
|
||||
message = cmd.StringArg("MESSAGE", "", "descriptive name of the given task")
|
||||
tags = cmd.StringsOpt("t tag", []string{}, "tags associated with this task")
|
||||
)
|
||||
|
@ -33,7 +33,7 @@ func start(path *string) func(*cli.Cmd) {
|
|||
task := Task{
|
||||
Message: *message,
|
||||
Tags: *tags,
|
||||
stents: *stents,
|
||||
pomodoros: *pomodoros,
|
||||
duration: parsed,
|
||||
}
|
||||
run(task, &I3{}, db)
|
||||
|
|
34
store.go
34
store.go
|
@ -50,12 +50,12 @@ func (s Store) CreateTask(task Task) (int, error) {
|
|||
return taskID, tx.Commit()
|
||||
}
|
||||
|
||||
func (s Store) CreateRecord(taskID int, record Record) error {
|
||||
func (s Store) CreatePomodoro(taskID int, pomodoro Pomodoro) error {
|
||||
_, err := s.db.Exec(
|
||||
`INSERT INTO record (task_id, start, end) VALUES ($1, $2, $3)`,
|
||||
`INSERT INTO pomodoro (task_id, start, end) VALUES ($1, $2, $3)`,
|
||||
taskID,
|
||||
record.Start,
|
||||
record.End,
|
||||
pomodoro.Start,
|
||||
pomodoro.End,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
@ -68,47 +68,47 @@ func (s Store) ReadTasks() ([]*Task, error) {
|
|||
tasks := []*Task{}
|
||||
for rows.Next() {
|
||||
var tags string
|
||||
task := &Task{Records: []*Record{}}
|
||||
task := &Task{Pomodoros: []*Pomodoro{}}
|
||||
err = rows.Scan(&task.ID, &task.Message, &tags)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
task.Tags = strings.Split(tags, ",")
|
||||
records, err := s.ReadRecords(task.ID)
|
||||
pomodoros, err := s.ReadPomodoros(task.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, record := range records {
|
||||
task.Records = append(task.Records, record)
|
||||
for _, pomodoro := range pomodoros {
|
||||
task.Pomodoros = append(task.Pomodoros, pomodoro)
|
||||
}
|
||||
tasks = append(tasks, task)
|
||||
}
|
||||
return tasks, nil
|
||||
}
|
||||
|
||||
func (s Store) ReadRecords(taskID int) ([]*Record, error) {
|
||||
rows, err := s.db.Query(`SELECT start,end FROM record WHERE task_id = $1`, &taskID)
|
||||
func (s Store) ReadPomodoros(taskID int) ([]*Pomodoro, error) {
|
||||
rows, err := s.db.Query(`SELECT start,end FROM pomodoro WHERE task_id = $1`, &taskID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
records := []*Record{}
|
||||
pomodoros := []*Pomodoro{}
|
||||
for rows.Next() {
|
||||
var (
|
||||
startStr string
|
||||
endStr string
|
||||
)
|
||||
record := &Record{}
|
||||
pomodoro := &Pomodoro{}
|
||||
err = rows.Scan(&startStr, &endStr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
start, _ := time.Parse(datetimeFmt, startStr)
|
||||
end, _ := time.Parse(datetimeFmt, endStr)
|
||||
record.Start = start
|
||||
record.End = end
|
||||
records = append(records, record)
|
||||
pomodoro.Start = start
|
||||
pomodoro.End = end
|
||||
pomodoros = append(pomodoros, pomodoro)
|
||||
}
|
||||
return records, nil
|
||||
return pomodoros, nil
|
||||
}
|
||||
|
||||
func (s Store) DeleteTask(taskID int) error {
|
||||
|
@ -137,7 +137,7 @@ func initDB(db *Store) error {
|
|||
message TEXT,
|
||||
tags TEXT
|
||||
);
|
||||
CREATE TABLE record (
|
||||
CREATE TABLE pomodoro (
|
||||
task_id INTEGER,
|
||||
start DATETTIME,
|
||||
end DATETTIME
|
||||
|
|
31
task.go
31
task.go
|
@ -9,18 +9,18 @@ import (
|
|||
|
||||
// Task Starting..
|
||||
//
|
||||
// 20min remaning [stent 1/4]
|
||||
// 20min remaning [pomodoro 1/4]
|
||||
// ..
|
||||
// 15min remaining [stent 2/4]
|
||||
// 15min remaining [pomodoro 2/4]
|
||||
// ..
|
||||
// Task Completed!
|
||||
func display(writer io.Writer, msg Message) {
|
||||
fmt.Fprintf(
|
||||
writer,
|
||||
"%s remaining [ stent %d/%d ]\n",
|
||||
"%s remaining [ pomodoro %d/%d ]\n",
|
||||
(msg.Duration - time.Since(msg.Start)).Truncate(time.Second),
|
||||
msg.CurrentStent,
|
||||
msg.Stents,
|
||||
msg.CurrentPomodoro,
|
||||
msg.Pomodoros,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -31,29 +31,28 @@ func run(task Task, prompter Prompter, db *Store) {
|
|||
writer.Start()
|
||||
ticker := time.NewTicker(RefreshInterval)
|
||||
timer := time.NewTimer(task.duration)
|
||||
var currentStent int
|
||||
for currentStent < task.stents {
|
||||
record := &Record{}
|
||||
var p int
|
||||
for p < task.pomodoros {
|
||||
pomodoro := &Pomodoro{}
|
||||
maybe(prompter.Prompt("Begin working!"))
|
||||
record.Start = time.Now()
|
||||
pomodoro.Start = time.Now()
|
||||
timer.Reset(task.duration)
|
||||
loop:
|
||||
select {
|
||||
case <-ticker.C:
|
||||
display(writer, Message{
|
||||
Start: record.Start,
|
||||
Start: pomodoro.Start,
|
||||
Duration: task.duration,
|
||||
Stents: task.stents,
|
||||
CurrentStent: currentStent,
|
||||
Pomodoros: task.pomodoros,
|
||||
CurrentPomodoro: p,
|
||||
})
|
||||
goto loop
|
||||
case <-timer.C:
|
||||
maybe(prompter.Prompt("Take a break!"))
|
||||
record.End = time.Now()
|
||||
maybe(db.CreateRecord(taskID, *record))
|
||||
currentStent++
|
||||
pomodoro.End = time.Now()
|
||||
maybe(db.CreatePomodoro(taskID, *pomodoro))
|
||||
p++
|
||||
}
|
||||
maybe(db.CreateRecord(taskID, *record))
|
||||
}
|
||||
writer.Stop()
|
||||
}
|
||||
|
|
16
types.go
16
types.go
|
@ -14,25 +14,25 @@ const RefreshInterval = 800 * time.Millisecond
|
|||
type Message struct {
|
||||
Start time.Time
|
||||
Duration time.Duration
|
||||
Stents int
|
||||
CurrentStent int
|
||||
Pomodoros int
|
||||
CurrentPomodoro int
|
||||
}
|
||||
|
||||
// Task describes some activity
|
||||
type Task struct {
|
||||
ID int `json:"id"`
|
||||
Message string `json:"message"`
|
||||
Records []*Record `json:"records"`
|
||||
Pomodoros []*Pomodoro `json:"pomodoros"`
|
||||
// Free-form tags associated with this task
|
||||
Tags []string `json:"tags"`
|
||||
// Number of iterations to perform the task
|
||||
stents int
|
||||
// Number of pomodoros for this task
|
||||
pomodoros int
|
||||
duration time.Duration
|
||||
}
|
||||
|
||||
// Record is a stetch of work performed on a
|
||||
// specific task.
|
||||
type Record struct {
|
||||
// Pomodoro is a unit of time to spend working
|
||||
// on a single task.
|
||||
type Pomodoro struct {
|
||||
Start time.Time `json:"start"`
|
||||
End time.Time `json:"end"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue