This commit is contained in:
Владимир Фёдоров 2026-03-31 15:55:28 +07:00
parent 470c9a9e1e
commit 515591a6eb
3 changed files with 35 additions and 10 deletions

Binary file not shown.

Binary file not shown.

View File

@ -7,6 +7,7 @@ import (
"pinned_message/internal/modules/data_parser"
"pinned_message/internal/modules/date_parser"
"pinned_message/internal/services/schedule_storage"
"sort"
"strings"
"time"
)
@ -76,23 +77,32 @@ func (p *ScheduleParser) parseSchedule(ctx context.Context, sheetURL string) (*m
}
func (p *ScheduleParser) mapSchedule(performances []performance) *models.Schedule {
days := []*models.Day{}
currentDay := &models.Day{}
for i, performance := range performances {
days := map[time.Time]*models.Day{}
var currentDate time.Time
var prevDate time.Time
for _, performance := range performances {
if performance.Name == "" || performance.Name == "-" {
continue
}
if performance.Date != "" {
if i > 0 {
days = append(days, currentDay)
currentDay = &models.Day{}
}
date, err := p.mapDate(performance.Date)
if err != nil {
panic(err)
}
currentDay.Date = date
currentDate = date
}
if performance.Date == "" {
currentDate = prevDate
}
if _, ok := days[currentDate]; !ok {
days[currentDate] = &models.Day{
Date: currentDate,
}
}
currentDay := days[currentDate]
currentDay.Performances = append(
currentDay.Performances,
&models.DayPerformance{
@ -104,11 +114,12 @@ func (p *ScheduleParser) mapSchedule(performances []performance) *models.Schedul
Costumes: performance.Costumes,
},
)
prevDate = currentDate
}
days = append(days, currentDay)
return &models.Schedule{
UpdateTime: time.Now().String(),
Days: days,
Days: p.mapToSortedArray(days),
}
}
@ -132,3 +143,17 @@ func (p *ScheduleParser) mapNumbers(numbers string) []*models.Number {
}
return res
}
func (p *ScheduleParser) mapToSortedArray(m map[time.Time]*models.Day) []*models.Day {
result := make([]*models.Day, 0, len(m))
for _, day := range m {
result = append(result, day)
}
sort.Slice(result, func(i, j int) bool {
return result[i].Date.Before(result[j].Date)
})
return result
}