Skip to content

Commit 6ff025f

Browse files
avoid dups and most prolific people who join most everything
1 parent 1f81169 commit 6ff025f

1 file changed

Lines changed: 28 additions & 5 deletions

File tree

pages/wiki-in-1996/random-aspects.html

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
<div id=result>working</div>
1+
<table><tr>
2+
<td id=result>working
3+
<td id=stats>
4+
<td><button hidden>again</button>
5+
</table>
6+
27
<script type=module>
38
import {Graph} from 'https://wardcunningham.github.io/graph/graph.js'
49
const uniq = (value, index, self) => self.indexOf(value) === index
@@ -16,6 +21,7 @@
1621
${lines.length} lines
1722
${pages.length} pages
1823
${links.length} links`
24+
lines.length = 0
1925

2026
// number each node and index in and out nodes as numbers
2127

@@ -26,6 +32,7 @@
2632
index.set(name,{i, in:[], out:[]})
2733
names.push(name)
2834
})
35+
pages.length = 0
2936
links.forEach(link => {
3037
const [,source,target] = link.match(/source="(.*?)" target="(.*?)"/)
3138
if(source != target) {
@@ -35,19 +42,31 @@
3542
t.in.push(s.i)
3643
}
3744
})
45+
links.length = 0
46+
again()
47+
const button = document.querySelector('button')
48+
button.addEventListener('click',again)
49+
button.hidden = false
50+
51+
function again() {
3852

3953
// add aspects made from randomly selected starting points
4054

4155
const aspects = []
56+
const done = []
4257
while (aspects.length < 30) {
4358
const random = Math.floor(names.length * Math.random())
4459
const name = names[random]
4560
const here = index.get(name)
46-
if (here.out.length < 2) continue
61+
const out = here.out
62+
.filter(i => index.get(names[i]).in.length < 5)
63+
if (out.length < 2) continue
64+
if (done.includes(here.i)) continue
65+
done.push(here.i)
4766
const graph = new Graph()
4867
graph.addNode('',{name:words(name)})
4968
aspects.push({name,graph})
50-
const todo = here.out.slice(0,5)
69+
const todo = out.slice(0,5)
5170
for(const doing of todo) {
5271
const nid = graph.addUniqNode('',{name:words(names[doing])})
5372
graph.addRel('',0,nid)
@@ -60,6 +79,7 @@
6079
const all = aspects
6180
.map(aspect => aspect.graph.nodes)
6281
.flat()
82+
const most = all
6383
.map(node => node.props.name)
6484
.filter(uniq)
6585

@@ -71,8 +91,11 @@
7191
action: "publishSourceData",
7292
name:'aspect',
7393
sourceData},'*')
74-
window.result.innerText += `
94+
window.stats.innerText = `
7595
${aspects.length} aspects
76-
${all.length} nodes `
96+
${most.length} nodes
97+
${all.length - most.length} dups`
98+
99+
}
77100

78101
</script>

0 commit comments

Comments
 (0)