From bf0407b933cb793b33f73abf42ef4f74c5243ff1 Mon Sep 17 00:00:00 2001 From: Peter Kleiweg Date: Sun, 24 May 2026 16:42:12 +0200 Subject: [PATCH] weg: cmd/score --- Makefile | 4 -- cmd/score/score.go | 114 --------------------------------------------- 2 files changed, 118 deletions(-) delete mode 100644 cmd/score/score.go diff --git a/Makefile b/Makefile index 826a90b..3fd7538 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,6 @@ all: make bin/dates2json make bin/flush make bin/items2count - make bin/score make bin/top20 make bin/week2files @@ -37,9 +36,6 @@ bin/flush: cmd/flush/*.go bin/items2count: cmd/items2count/*.go go build -o $@ $^ -bin/score: cmd/score/*.go - go build -o $@ $^ - bin/top20: cmd/top20/*.go go build -o $@ $^ diff --git a/cmd/score/score.go b/cmd/score/score.go deleted file mode 100644 index e1ccf09..0000000 --- a/cmd/score/score.go +++ /dev/null @@ -1,114 +0,0 @@ -package main - -import ( - e "codeberg.org/pebbe/errors" - - "bufio" - "fmt" - "os" - "regexp" - "sort" - "strconv" - "strings" -) - -type Item struct { - text string - lctext string - score int - isnew bool -} - -var ( - x = e.ExitErr - reYearWeek = regexp.MustCompile(`(.*)([12][0-9][0-9][0-9]-[0-5][0-9])(.*)`) - count = make(map[string]int) - items = make([]Item, 0) -) - -func main() { - filename := os.Args[1] - prevname := getPrev(filename) - - fp, err := os.Open(prevname) - x(err) - scanner := bufio.NewScanner(fp) - for scanner.Scan() { - aa := strings.SplitN(scanner.Text(), "\t", 2) - n, err := strconv.Atoi(strings.TrimSpace(aa[0])) - x(err) - count[aa[1]] = n - } - x(scanner.Err()) - x(fp.Close()) - - fp, err = os.Open(filename) - x(err) - scanner = bufio.NewScanner(fp) - for scanner.Scan() { - aa := strings.SplitN(scanner.Text(), "\t", 2) - n, err := strconv.Atoi(strings.TrimSpace(aa[0])) - x(err) - n1, ok := count[aa[1]] - items = append(items, Item{ - text: aa[1], - lctext: strings.ToLower(aa[1]), - score: n - n1, - isnew: !ok, - }) - } - x(scanner.Err()) - x(fp.Close()) - - sort.Slice(items, func(i, j int) bool { - /* - if items[i].isnew && !items[j].isnew { - return true - } - if !items[i].isnew && items[j].isnew { - return false - } - */ - if items[i].score != items[j].score { - return items[i].score > items[j].score - } - return items[i].lctext < items[j].lctext - }) - - for _, item := range items { - /* - if item.score < 2 { - break - } - */ - p := "." - if item.isnew { - p = "N" - } - fmt.Printf("%s\t%4d\t%s\n", p, item.score, item.text) - } - -} - -func getPrev(filename string) string { - mm := reYearWeek.FindStringSubmatch(filename) - year, err := strconv.Atoi(mm[2][:4]) - x(err) - week, err := strconv.Atoi(mm[2][5:]) - x(err) - - week-- - if week == 0 { - week = 53 - year-- - } - newname := fmt.Sprintf("%s%d-%02d%s", mm[1], year, week, mm[3]) - if week == 53 { - _, err := os.Stat(newname) - if err == nil { - return newname - } - newname = fmt.Sprintf("%s%d-%02d%s", mm[1], year, week-1, mm[3]) - } - return newname -}