Repository navigation
Expand file tree
/
Copy pathfindings.go
More file actions
310 lines (288 loc) · 9.3 KB
/
Copy pathfindings.go
File metadata and controls
310 lines (288 loc) · 9.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
package main
// Turning a count into something somebody can act on.
import (
"fmt"
"sort"
"strings"
"time"
)
// Under shortList a lineup is a list somebody can go through by hand in a
// weekend, and a language model in an afternoon for a few dollars: that is
// what the attack published in February 2026 cost per person.
const shortList = 1000
func writeUp(in *Input, a *Account, l *Lineup, reveal bool) *Report {
r := &Report{Title: title(in, a)}
r.Gaps = append(r.Gaps, in.Gaps...)
lineupFinding(r, l, reveal)
costs(r, a, l, reveal)
for _, c := range l.Conflicts {
var lines []string
for _, f := range c.Facts {
lines = append(lines, factLine(a, f, reveal)...)
}
r.add(Finding{Tag: "CLASHES", Weight: Narrows, Title: c.Title, Lines: lines, Advice: c.Text})
}
uncounted(r, a, l, reveal)
unread(r, in, a)
groundwork(r, in, a)
return r
}
func title(in *Input, a *Account) string {
var first, last time.Time
for _, p := range a.Posts {
if p.When.IsZero() {
continue
}
if first.IsZero() || p.When.Before(first) {
first = p.When
}
if p.When.After(last) {
last = p.When
}
}
span := ""
if !first.IsZero() {
span = ", " + first.Format("2006-01") + " to " + last.Format("2006-01")
}
return fmt.Sprintf("%s (%s%s)", strings.Join(in.Names, " and "), plural(len(a.Posts), "post", "posts"), span)
}
func lineupFinding(r *Report, l *Lineup, reveal bool) {
var lines []string
counted := 0
for _, s := range l.Steps {
label := s.Masked
if reveal {
label = s.Plain
}
lines = append(lines, columns(label, fmt.Sprintf("%15s", people(s.People)))...)
if !s.base {
counted++
}
}
headline := fmt.Sprintf("About %s people fit everything this account has said", people(l.People))
switch {
case l.People < 1:
headline = "Fewer than one person fits everything this account has said"
case l.People < 1.5:
headline = "About one person fits everything this account has said"
}
band := fmt.Sprintf("somewhere between %s and %s", people(l.Low), people(l.High))
if l.High < 1 {
band = "fewer than one even at the generous end of the range"
}
lines = append([]string{band, ""}, lines...)
advice := ""
switch {
case counted == 0:
headline = "Nothing this account has said about itself narrows it down"
advice = "It never says where it lives, how old it is or what it does, in any way " +
"these patterns read. That is not the same as being safe: the README lists " +
"what this cannot see, and a model reading the same posts sees more."
case l.People < 10:
advice = "That is not a crowd. Anybody who writes these facts down in a list can work " +
"out who wrote them, and when the arithmetic runs out of people before it runs " +
"out of facts, the one left is you."
case l.People < shortList:
advice = "A list somebody could work through by hand in a weekend, and a language model " +
"in an afternoon. The facts below are the ones doing it, and taking any one of " +
"them back makes the list longer."
case l.People < 100000:
advice = "Still a crowd, but a small one. Every fact is a filter somebody looking for " +
"you gets to apply, and each new one divides what is left again."
default:
advice = "A big crowd. Nothing said here narrows it much, which is worth keeping " +
"that way: the posts below are the ones that would change it."
}
r.add(Finding{Tag: "LINEUP ", Weight: Headline, Title: headline, Lines: lines, Advice: advice})
}
// costs lists the facts in the order of how much each cut the lineup, with
// where each was first said and how many posts say it. That last number is
// the one that matters for deleting anything: a fact said in nine posts is
// still said after one of them goes.
func costs(r *Report, a *Account, l *Lineup, reveal bool) {
type cost struct {
step Step
cut float64
}
var all []cost
for _, s := range l.Steps {
if s.base || len(s.Facts) == 0 || s.Factor <= 0 || s.Factor >= 1 {
continue
}
all = append(all, cost{s, 1 / s.Factor})
}
if len(all) == 0 {
return
}
sort.SliceStable(all, func(i, j int) bool { return all[i].cut > all[j].cut })
var lines []string
for i, c := range all {
if i > 0 {
lines = append(lines, "")
}
label := c.step.Masked
if reveal {
label = c.step.Plain
}
lines = append(lines, columns(label, "divides by "+divisor(c.cut))...)
posts := map[int]bool{}
for _, f := range c.step.Facts {
posts[f.Post] = true
}
first := c.step.Facts[0]
for _, f := range c.step.Facts {
if earlier(f, first) {
first = f
}
}
lines = append(lines, " "+plural(len(posts), "post says it", "posts say it")+
", first "+where(a, first))
if reveal {
lines = append(lines, " "+quote(first.Said))
}
}
r.add(Finding{Tag: "COSTS ", Weight: Narrows, Title: "What cost the most, and where it was said",
Lines: atMost(lines, 60),
Advice: "Deleting a post only takes a fact back if no other post says it: the number of " +
"posts is how many would have to go. And a deleted post may already be in an " +
"archive, so what is not posted yet is the part that is still yours to decide."})
}
func earlier(a, b Fact) bool {
switch {
case a.When.IsZero() != b.When.IsZero():
return !a.When.IsZero()
case !a.When.Equal(b.When):
return a.When.Before(b.When)
}
return a.Post < b.Post
}
func divisor(cut float64) string {
if cut < 10 {
return fmt.Sprintf("%.1f", cut)
}
return people(cut)
}
func where(a *Account, f Fact) string {
if f.Post < 0 || f.Post >= len(a.Posts) {
return "in the draft"
}
p := a.Posts[f.Post]
if p.When.IsZero() {
return p.Where
}
return p.Where + ", " + p.When.Format("2006-01-02")
}
func factLine(a *Account, f Fact, reveal bool) []string {
lines := []string{where(a, f)}
if reveal {
lines = append(lines, " "+quote(f.Said))
}
return lines
}
// uncounted is what the account gave away that there is no table for. Each
// of these can end the lineup on its own: a named employer is however many
// people work there, which is usually a few hundred.
func uncounted(r *Report, a *Account, l *Lineup, reveal bool) {
if len(l.Unpriced) == 0 {
return
}
byValue := map[string][]Fact{}
var order []string
for _, f := range l.Unpriced {
if _, seen := byValue[f.Value]; !seen {
order = append(order, f.Value)
}
byValue[f.Value] = append(byValue[f.Value], f)
}
var lines []string
for _, v := range order {
fs := byValue[v]
lines = append(lines, columns(v, plural(len(fs), "time", "times"))...)
for _, f := range fs[:min(len(fs), 3)] {
lines = append(lines, " "+where(a, f))
if reveal {
lines = append(lines, " "+quote(f.Said))
}
}
}
r.add(Finding{Tag: "ALSO ", Weight: Narrows,
Title: plural(len(l.Unpriced), "thing it said is", "things it said are") + " not in the count",
Lines: atMost(lines, 40),
Advice: "There is no table to count these against, and any one of them can end the " +
"lineup by itself. A named employer is the few hundred people who work there; " +
"a move from one city to another is the people who made that same move."})
}
func unread(r *Report, in *Input, a *Account) {
other := map[string]int{}
for _, p := range a.Posts {
if p.Lang != "" && p.Lang != "en" && p.Lang != "es" {
other[p.Lang]++
}
}
for lang, n := range other {
r.Gaps = append(r.Gaps, fmt.Sprintf("%s in %s were counted towards the account's languages "+
"and not read for facts. The patterns in here are English and Spanish sentences.",
plural(n, "post", "posts"), languageLabel(lang)))
}
sort.Strings(r.Gaps)
}
func groundwork(r *Report, in *Input, a *Account) {
var lines []string
kinds := make([]string, 0, len(in.Kinds))
for k := range in.Kinds {
kinds = append(kinds, k)
}
sort.Strings(kinds)
for _, k := range kinds {
lines = append(lines, columns(k, commas(int64(in.Kinds[k])))...)
}
total := 0
for _, n := range a.Langs {
total += n
}
if total > 0 {
var parts []string
for _, lang := range accountLanguagesAll(a.Langs) {
parts = append(parts, fmt.Sprintf("%s %d%%", languageLabel(lang), a.Langs[lang]*100/total))
}
lines = append(lines, "", "written in "+strings.Join(parts, ", "))
}
c := a.Clock
switch {
case c.known:
lines = append(lines, "", fmt.Sprintf("quiet from %02d:00 to %02d:00 UTC, which is night at %s",
c.quietFrom, (c.quietFrom+c.quietHours)%24, c))
case c.posts < enoughTimes:
lines = append(lines, "", fmt.Sprintf("%s with a time, too few to read a night from",
plural(c.posts, "post", "posts")))
default:
lines = append(lines, "", "no clear night in the hours it posts at, so no timezone")
}
var skipped []string
for name, why := range in.Skipped {
skipped = append(skipped, fmt.Sprintf("%s (%s)", name, why))
}
sort.Strings(skipped)
if len(skipped) > 0 {
lines = append(lines, "", "left alone on purpose, because a stranger cannot read it:")
for _, s := range atMost(skipped, 8) {
lines = append(lines, " "+s)
}
}
r.add(Finding{Tag: "NOTE ", Weight: Note, Title: "What this was worked out from", Lines: lines})
}
// accountLanguagesAll is every language seen, most used first, for the
// note. accountLanguages is the stricter list the count uses.
func accountLanguagesAll(counts map[string]int) []string {
var langs []string
for lang := range counts {
langs = append(langs, lang)
}
sort.Slice(langs, func(i, j int) bool {
if counts[langs[i]] != counts[langs[j]] {
return counts[langs[i]] > counts[langs[j]]
}
return langs[i] < langs[j]
})
return langs
}