Skip to content

Commit ac792cd

Browse files
committed
fix: channel code handling in plot data processing
1 parent c63363a commit ac792cd

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

internal/service/helicorder/start.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ type provider struct {
3232
networkCode string
3333
locationCode string
3434

35-
channelCode string
36-
channelCodeIndex int
35+
channelCode string
3736
}
3837

3938
func (d *provider) GetPlotName() string { return "AnyShake Observer" }
@@ -71,21 +70,22 @@ func (d *provider) GetPlotData(startTime, endTime time.Time) ([]heligo.PlotData,
7170
for _, record := range seisRecords {
7271
data := make([]heligo.PlotData, record.sampleRate)
7372
for i := range record.sampleRate {
74-
timeOffset := int64(i * 1000 / record.sampleRate)
75-
data[i].Time = time.UnixMilli(record.timestamp + timeOffset)
76-
if d.channelCodeIndex >= len(record.channelData) {
77-
continue
73+
record.channelData = lo.Filter(record.channelData, func(item explorer.ChannelData, _ int) bool {
74+
return item.ChannelCode == d.channelCode
75+
})
76+
if len(record.channelData) > 0 {
77+
timeOffset := int64(i * 1000 / record.sampleRate)
78+
data[i].Time = time.UnixMilli(record.timestamp + timeOffset)
79+
data[i].Value = float64(record.channelData[0].Data[i])
7880
}
79-
data[i].Value = float64(record.channelData[d.channelCodeIndex].Data[i])
8081
}
8182
plotData = append(plotData, data...)
8283
}
8384

8485
return plotData, nil
8586
}
86-
func (d *provider) setChannelCode(channelCode string, channelCodeIndex int) {
87+
func (d *provider) setChannelCode(channelCode string) {
8788
d.channelCode = channelCode
88-
d.channelCodeIndex = channelCodeIndex
8989
}
9090

9191
func (s *HelicorderServiceImpl) handleInterrupt(timer *time.Timer) {
@@ -156,7 +156,7 @@ func (s *HelicorderServiceImpl) Start() error {
156156
}
157157

158158
// Update current channel code
159-
s.dataProvider.setChannelCode(channelCode, channelIdx)
159+
s.dataProvider.setChannelCode(channelCode)
160160
logger.GetLogger(ID).Infof("start plotting helicorder for channel %s", channelCode)
161161

162162
if err = helicorderCtx.Plot(currentTime, runtime.NumCPU()*4, s.spanSamples, scaleFactor, s.lineWidth, nil); err != nil {

0 commit comments

Comments
 (0)