From 350782e1b6b956f4cdc90ee1f42e8c1afec4e06c Mon Sep 17 00:00:00 2001 From: khirkjohann Date: Fri, 6 Feb 2026 11:28:59 +0800 Subject: [PATCH 1/3] add main.go for activity --- cur/ayag/go.mod | 3 +++ cur/ayag/main.go | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 cur/ayag/go.mod create mode 100644 cur/ayag/main.go diff --git a/cur/ayag/go.mod b/cur/ayag/go.mod new file mode 100644 index 0000000..9cabb52 --- /dev/null +++ b/cur/ayag/go.mod @@ -0,0 +1,3 @@ +module cur + +go 1.25.6 diff --git a/cur/ayag/main.go b/cur/ayag/main.go new file mode 100644 index 0000000..44b121a --- /dev/null +++ b/cur/ayag/main.go @@ -0,0 +1,66 @@ +package main + +import ( + "encoding/csv" + "fmt" + "os" + "strconv" + "sync" + "time" +) + +func processLine(line []string, result chan<- float64) { + time.Sleep(500 * time.Millisecond) + + price := line[2] + priceFloat, err := strconv.ParseFloat(price, 64) + if err != nil { + fmt.Println(err) + result <- 0.0 + return + } + result <- priceFloat +} + +func main() { + startTime := time.Now() + fileCSV, err := os.Open("../testcur.csv") + if err != nil { + fmt.Println(err) + return + } + + read := csv.NewReader(fileCSV) + lines, err := read.ReadAll() + if err != nil { + fmt.Println(err) + return + } + + total := make(chan float64) + var wg sync.WaitGroup + + rows := lines[1:] + + for _, row := range rows { + wg.Add(1) + + go func(r []string) { + defer wg.Done() + processLine(r, total) + }(row) + } + + go func() { + wg.Wait() + close(total) + }() + + var totals float64 + for price := range total { + totals += price + } + + fmt.Printf("Total: %f\n", totals) + fmt.Printf("Duration: %s\n", time.Since(startTime)) +} From ed083a74221fc4e461cc7cf38848dd890ca43071 Mon Sep 17 00:00:00 2001 From: khirkjohann Date: Fri, 6 Feb 2026 12:27:02 +0800 Subject: [PATCH 2/3] commit From 260d1364aa277e5266be72bfbef080158ecc7907 Mon Sep 17 00:00:00 2001 From: khirkjohann Date: Fri, 6 Feb 2026 13:08:18 +0800 Subject: [PATCH 3/3] add rows processed output --- cur/ayag/main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cur/ayag/main.go b/cur/ayag/main.go index 44b121a..e51bc22 100644 --- a/cur/ayag/main.go +++ b/cur/ayag/main.go @@ -62,5 +62,6 @@ func main() { } fmt.Printf("Total: %f\n", totals) + fmt.Printf("Rows processed: %d\n", len(rows)) fmt.Printf("Duration: %s\n", time.Since(startTime)) }