router: let a habit question outrank the day plan, and know the weekend
IsDayPlanQuery fires on the token "планы" and its other-day list does not know weekday names, so "какие у меня обычно планы по вторникам?" was claimed by the day plan, which answered today's calendar stamped with today's date. The habit source never ran. The matcher now declines any utterance ParseHabitQuery claims, which keeps the decision out of the source table's ordering. Two gaps in the same matcher. Sunday had only its dative plural listed, so "в воскресенье" found no weekday. "по выходным" named days that no weekday word matches, so it was answered with the whole-week profile. Both are recognised now, and the weekend is read back as two days rather than pooled. Found in review of #59.
This commit is contained in:
@@ -346,6 +346,30 @@ func (p Profile) FormatWeekdayRU(wd time.Weekday) string {
|
||||
return fmt.Sprintf("по %s я пока не вижу у тебя ничего постоянного.", day)
|
||||
}
|
||||
|
||||
// FormatWeekendRU reads back what distinguishes Saturday and Sunday.
|
||||
//
|
||||
// The two days are answered separately rather than pooled: "по выходным" is a
|
||||
// question about both, and a habit he has on Saturdays only is the interesting
|
||||
// half of the answer, not noise to average away.
|
||||
func (p Profile) FormatWeekendRU() string {
|
||||
sat, sun := p.Weekly[time.Saturday], p.Weekly[time.Sunday]
|
||||
switch {
|
||||
case len(sat) > 0 && len(sun) > 0:
|
||||
return fmt.Sprintf("по субботам ты обычно %s, по воскресеньям — %s.",
|
||||
joinActivities(sat), joinActivities(sun))
|
||||
case len(sat) > 0:
|
||||
return fmt.Sprintf("по субботам ты обычно %s, а по воскресеньям ничего постоянного.",
|
||||
joinActivities(sat))
|
||||
case len(sun) > 0:
|
||||
return fmt.Sprintf("по воскресеньям ты обычно %s, а по субботам ничего постоянного.",
|
||||
joinActivities(sun))
|
||||
case len(p.Everyday) > 0:
|
||||
return fmt.Sprintf("по выходным у тебя нет ничего особенного — то же, что и в остальные дни: %s.",
|
||||
joinActivities(p.Everyday))
|
||||
}
|
||||
return "по выходным я пока не вижу у тебя ничего постоянного."
|
||||
}
|
||||
|
||||
// FormatOverallRU reads back the habits that hold across the whole week, and
|
||||
// says over what stretch of records it is claiming them.
|
||||
//
|
||||
|
||||
@@ -350,3 +350,20 @@ func TestPluralDaysRU(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// "по выходным" is a question about two days, answered as two days.
|
||||
func TestFormatWeekendRU(t *testing.T) {
|
||||
now := behaviorNow()
|
||||
obs := append(
|
||||
habitHistory("workout", time.Saturday, 11, 0, 3, now),
|
||||
habitHistory("walk", time.Sunday, 15, 0, 3, now)...,
|
||||
)
|
||||
got := BuildProfile(obs, now).FormatWeekendRU()
|
||||
if !strings.Contains(got, "по субботам") || !strings.Contains(got, "по воскресеньям") {
|
||||
t.Errorf("got %q, want both weekend days named", got)
|
||||
}
|
||||
empty := BuildProfile(nil, now).FormatWeekendRU()
|
||||
if strings.Contains(empty, "у меня") {
|
||||
t.Errorf("got %q", empty)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user