review failed until success but only persist first attempt
parent
a90aa68057
commit
11af5f4d52
81
main.go
81
main.go
|
|
@ -4,7 +4,6 @@ import (
|
|||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -56,7 +55,15 @@ func Main() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Printf("failed %v", failed)
|
||||
for len(failed) > 0 {
|
||||
for i := len(failed) - 1; i >= 0; i-- {
|
||||
if _, passed, err := ReviewQ(db, user, failed[i]); err != nil {
|
||||
return err
|
||||
} else if passed != "n" {
|
||||
failed = append(failed[:i], failed[i+1:]...)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -67,42 +74,17 @@ func Review(db DB, user IDU) ([]IDQ, error) {
|
|||
if time.Until(db.Next(user, q)) > 0 {
|
||||
continue
|
||||
}
|
||||
question := db.Question(q)
|
||||
fmt.Printf("> Q: %s\n", question.Q)
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("> %+v\n", question.Tags)
|
||||
var response string
|
||||
for i := range question.Clues {
|
||||
if i == 0 {
|
||||
fmt.Printf("> /clue for a clue\n")
|
||||
}
|
||||
response = readline()
|
||||
if response != "/clue" {
|
||||
break
|
||||
}
|
||||
fmt.Printf("> %s", question.Clues[i])
|
||||
if i+1 < len(question.Clues) {
|
||||
fmt.Printf(" | /clue for another clue")
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
response, passed, err := ReviewQ(db, user, q)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(question.Clues) == 0 || response == "/clue" {
|
||||
response = readline()
|
||||
}
|
||||
if id, _ := db.LastAnswer(user, q); id == "" {
|
||||
} else if lastAnswer := db.Answer(id); lastAnswer.A != "" {
|
||||
fmt.Printf("> Last time, you responded:\n\t%s\n", lastAnswer.A)
|
||||
}
|
||||
fmt.Printf("> Did you pass this time? [Yns]\n")
|
||||
passed := readline()
|
||||
switch passed {
|
||||
case "s":
|
||||
case "n":
|
||||
failed = append(failed, q)
|
||||
if err := db.PushAnswer(user, q, Renderable(response), false); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
case "y":
|
||||
if err := db.PushAnswer(user, q, Renderable(response), true); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -112,6 +94,43 @@ func Review(db DB, user IDU) ([]IDQ, error) {
|
|||
return failed, nil
|
||||
}
|
||||
|
||||
func ReviewQ(db DB, user IDU, q IDQ) (string, string, error) {
|
||||
question := db.Question(q)
|
||||
fmt.Printf("> Q: %s\n", question.Q)
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("> %+v\n", question.Tags)
|
||||
var response string
|
||||
for i := range question.Clues {
|
||||
if i == 0 {
|
||||
fmt.Printf("> /clue for a clue\n")
|
||||
}
|
||||
response = readline()
|
||||
if response != "/clue" {
|
||||
break
|
||||
}
|
||||
fmt.Printf("> %s", question.Clues[i])
|
||||
if i+1 < len(question.Clues) {
|
||||
fmt.Printf(" | /clue for another clue")
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
if len(question.Clues) == 0 || response == "/clue" {
|
||||
response = readline()
|
||||
}
|
||||
if id, _ := db.LastAnswer(user, q); id == "" {
|
||||
} else if lastAnswer := db.Answer(id); lastAnswer.A != "" {
|
||||
fmt.Printf("> Last time, you responded:\n\t%s\n", lastAnswer.A)
|
||||
}
|
||||
fmt.Printf("> Did you pass this time? [Yns]\n")
|
||||
switch readline() {
|
||||
case "s":
|
||||
return response, "s", nil
|
||||
case "n":
|
||||
return response, "n", nil
|
||||
}
|
||||
return response, "y", nil
|
||||
}
|
||||
|
||||
func readline() string {
|
||||
fmt.Printf("\t")
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
|
|
|
|||
Loading…
Reference in New Issue