ai cooking
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

table sumbs in zip index (#418)

Co-authored-by: paul miller <paul.miller>

authored by

Paul Miller
paul miller
and committed by
GitHub
4f470073 4e3a4bb4

+28
+26
cmd/zipstorecount/main.go
··· 211 211 return fmt.Errorf("write table header: %w", err) 212 212 } 213 213 214 + columnTotals := make(map[string]int, len(chains)) 215 + grandTotal := 0 214 216 for _, row := range rows { 215 217 key := rowKey(row) 216 218 line := []string{row.Metro, row.Zip} ··· 219 221 count := countsByRow[key][chain] 220 222 line = append(line, strconv.Itoa(count)) 221 223 total += count 224 + columnTotals[chain] += count 222 225 } 223 226 line = append(line, strconv.Itoa(total)) 227 + grandTotal += total 224 228 if _, err := fmt.Fprintln(tw, strings.Join(line, "\t")); err != nil { 225 229 return fmt.Errorf("write table row: %w", err) 226 230 } 231 + } 232 + 233 + totalLine := []string{"total", ""} 234 + for _, chain := range chains { 235 + totalLine = append(totalLine, strconv.Itoa(columnTotals[chain])) 236 + } 237 + totalLine = append(totalLine, strconv.Itoa(grandTotal)) 238 + if _, err := fmt.Fprintln(tw, strings.Join(totalLine, "\t")); err != nil { 239 + return fmt.Errorf("write table total row: %w", err) 227 240 } 228 241 229 242 if err := tw.Flush(); err != nil { ··· 250 263 return fmt.Errorf("write markdown separator: %w", err) 251 264 } 252 265 266 + columnTotals := make(map[string]int, len(chains)) 267 + grandTotal := 0 253 268 for _, row := range rows { 254 269 key := rowKey(row) 255 270 line := []string{escapeMarkdownCell(row.Metro), escapeMarkdownCell(row.Zip)} ··· 258 273 count := countsByRow[key][chain] 259 274 line = append(line, strconv.Itoa(count)) 260 275 total += count 276 + columnTotals[chain] += count 261 277 } 262 278 line = append(line, strconv.Itoa(total)) 279 + grandTotal += total 263 280 if _, err := fmt.Fprintf(w, "| %s |\n", strings.Join(line, " | ")); err != nil { 264 281 return fmt.Errorf("write markdown row: %w", err) 265 282 } 283 + } 284 + 285 + totalLine := []string{"total", ""} 286 + for _, chain := range chains { 287 + totalLine = append(totalLine, strconv.Itoa(columnTotals[chain])) 288 + } 289 + totalLine = append(totalLine, strconv.Itoa(grandTotal)) 290 + if _, err := fmt.Fprintf(w, "| %s |\n", strings.Join(totalLine, " | ")); err != nil { 291 + return fmt.Errorf("write markdown total row: %w", err) 266 292 } 267 293 268 294 return nil
+2
cmd/zipstorecount/main_test.go
··· 178 178 "metro_name zip_code kroger walmart wholefoods total", 179 179 "Boston 02169 0 0 3 3", 180 180 "Seattle 98032 2 1 0 3", 181 + "total 2 1 3 6", 181 182 } 182 183 if !reflect.DeepEqual(got, want) { 183 184 t.Fatalf("unexpected table output: got=%q want=%q", got, want) ··· 205 206 "| --- | --- | --- | --- | --- | --- |", 206 207 "| Boston \\| Cambridge | 02169 | 0 | 0 | 3 | 3 |", 207 208 "| Seattle | 98032 | 2 | 1 | 0 | 3 |", 209 + "| total | | 2 | 1 | 3 | 6 |", 208 210 "", 209 211 }, "\n") 210 212 if buf.String() != want {