From e5d937c9c35042302167b60af3235ad5c6c907c6 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Sat, 3 Dec 2022 00:18:10 +0800 Subject: [PATCH] docs: update wcl, select match time --- examples/worldcup/cli.go | 2 +- examples/worldcup/main.go | 53 ++++++++++++++++++++++++--------------- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/examples/worldcup/cli.go b/examples/worldcup/cli.go index 4ca59b60..f28eed1d 100644 --- a/examples/worldcup/cli.go +++ b/examples/worldcup/cli.go @@ -15,7 +15,7 @@ import ( var rootCmd = &cobra.Command{ Use: "wcl", Short: "Monitor FIFA World Cup Live", - Version: "2022.12.01.2236", + Version: "2022.12.03.0018", PreRun: func(cmd *cobra.Command, args []string) { log.Logger = zerolog.New( zerolog.ConsoleWriter{NoColor: false, Out: os.Stderr}, diff --git a/examples/worldcup/main.go b/examples/worldcup/main.go index 3d38c6c9..f91b6577 100644 --- a/examples/worldcup/main.go +++ b/examples/worldcup/main.go @@ -154,32 +154,49 @@ func (wc *WorldCupLive) getCurrentLiveTime(utcTime time.Time) error { utcTimeStr := utcTime.Format("15:04:05") fileName := filepath.Join( wc.resultDir, "screenshot", utcTimeStr) - ocrTexts, err := wc.driver.GetTextsByOCR(uixt.WithScreenShot(fileName)) + ocrTexts, err := wc.driver.GetTextsByOCR( + uixt.WithScreenShot(fileName), + ) if err != nil { log.Error().Err(err).Msg("get ocr texts failed") return err } - var liveTimeSeconds int + // filter ocr texts with time format + secondsMap := map[string]int{} + var secondsTexts []string for _, ocrText := range ocrTexts { seconds, err := convertTimeToSeconds(ocrText.Text) if err == nil { - liveTimeSeconds = seconds - line := fmt.Sprintf("%s\t%d\t%s\t%d\n", - utcTimeStr, utcTime.Unix(), ocrText.Text, liveTimeSeconds) - log.Info().Str("utcTime", utcTimeStr).Str("liveTime", ocrText.Text).Msg("log live time") - if _, err := wc.file.WriteString(line); err != nil { - log.Error().Err(err).Str("line", line).Msg("write timeseries failed") - } - wc.Timelines = append(wc.Timelines, timeLog{ - UTCTimeStr: utcTimeStr, - UTCTime: utcTime.Unix(), - LiveTime: ocrText.Text, - LiveTimeSeconds: liveTimeSeconds, - }) - break + secondsTexts = append(secondsTexts, ocrText.Text) + secondsMap[ocrText.Text] = seconds } } + + var secondsText string + if len(secondsTexts) == 1 { + secondsText = secondsTexts[0] + } else if len(secondsTexts) >= 2 { + // select the second, the first maybe mobile system time + secondsText = secondsTexts[1] + } else { + log.Warn().Msg("no time text found") + return nil + } + + liveTimeSeconds := secondsMap[secondsText] + line := fmt.Sprintf("%s\t%d\t%s\t%d\n", + utcTimeStr, utcTime.Unix(), secondsText, liveTimeSeconds) + log.Info().Str("utcTime", utcTimeStr).Str("liveTime", secondsText).Msg("log live time") + if _, err := wc.file.WriteString(line); err != nil { + log.Error().Err(err).Str("line", line).Msg("write timeseries failed") + } + wc.Timelines = append(wc.Timelines, timeLog{ + UTCTimeStr: utcTimeStr, + UTCTime: utcTime.Unix(), + LiveTime: secondsText, + LiveTimeSeconds: liveTimeSeconds, + }) return nil } @@ -205,10 +222,6 @@ func (wc *WorldCupLive) EnterLive(bundleID string) error { _ = wc.driver.TapAbsXY(points[1].X, points[1].Y) } - if err = wc.driver.SwipeRelative(0.5, 0.1, 0.8, 0.1); err != nil { - log.Error().Err(err).Msg("swipe failed") - } - // 进入世界杯 tab if err = wc.driver.TapByOCR("世界杯"); err != nil { log.Error().Err(err).Msg("enter 直播中 failed")