wiki-plugin-mech 0.1.24 → 0.1.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/mech.js +94 -5
- package/package.json +1 -1
package/client/mech.js
CHANGED
|
@@ -274,7 +274,8 @@
|
|
|
274
274
|
function walk_emit ({elem,command,args,state}) {
|
|
275
275
|
if(!('neighborhood' in state)) return trouble(elem,`WALK expects state.neighborhood, like from NEIGHBORS.`)
|
|
276
276
|
inspect(elem,'neighborhood',state)
|
|
277
|
-
const
|
|
277
|
+
const way = (command.match(/\b(steps|days|weeks|months|hubs)\b/) || ['steps'])[0]
|
|
278
|
+
const steps = walks(way,state.neighborhood)
|
|
278
279
|
const aspects = steps.filter(({graph})=>graph)
|
|
279
280
|
if(state.debug) console.log({steps})
|
|
280
281
|
elem.innerHTML = command
|
|
@@ -284,7 +285,8 @@
|
|
|
284
285
|
const item = elem.closest('.item')
|
|
285
286
|
item.classList.add('aspect-source')
|
|
286
287
|
item.aspectData = () => aspects
|
|
287
|
-
|
|
288
|
+
if (aspects.length)
|
|
289
|
+
state.aspect = [...(state.aspect||[]), {id:item.dataset.id,result:aspects}]
|
|
288
290
|
}
|
|
289
291
|
|
|
290
292
|
function tick_emit ({elem,command,args,body,state}) {
|
|
@@ -777,14 +779,22 @@
|
|
|
777
779
|
}
|
|
778
780
|
|
|
779
781
|
// inspired by aspects-of-recent-changes/roster-graphs.html
|
|
780
|
-
function walks(neighborhood) {
|
|
782
|
+
function walks(way,neighborhood) {
|
|
781
783
|
const prob = n => Math.floor(n * Math.abs(Math.random()-Math.random()))
|
|
782
784
|
const rand = a => a[prob(a.length)]
|
|
783
785
|
const domains = neighborhood
|
|
784
786
|
.map(info => info.domain)
|
|
785
787
|
.filter(uniq)
|
|
786
|
-
|
|
787
|
-
|
|
788
|
+
switch(way) {
|
|
789
|
+
case 'steps': return steps()
|
|
790
|
+
case 'days': return periods(1)
|
|
791
|
+
case 'weeks': return periods(7)
|
|
792
|
+
case 'months': return periods(30)
|
|
793
|
+
case 'hubs': return hubs()
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
function steps() {
|
|
797
|
+
return domains.map(domain => {
|
|
788
798
|
const name = domain.split('.').slice(0,3).join('.')
|
|
789
799
|
const done = new Set()
|
|
790
800
|
const graph = new Graph()
|
|
@@ -803,6 +813,7 @@
|
|
|
803
813
|
const rel = (here,there) => graph.addRel('',here,there)
|
|
804
814
|
const links = nid => graph.nodes[nid].props.links.filter(slug => !done.has(slug))
|
|
805
815
|
const start = rand(here)
|
|
816
|
+
// const start = find('welcome-visitors')
|
|
806
817
|
done.add(start.slug)
|
|
807
818
|
node(start)
|
|
808
819
|
for (let n=5;n>0;n--) {
|
|
@@ -816,6 +827,79 @@
|
|
|
816
827
|
}
|
|
817
828
|
return {name,graph}
|
|
818
829
|
})
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
function periods(days) {
|
|
833
|
+
const interval = days*24*60*60*1000
|
|
834
|
+
const iota = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]
|
|
835
|
+
const dates = iota.map(n => Date.now()-n*interval)
|
|
836
|
+
const aspects = []
|
|
837
|
+
for(const stop of dates) {
|
|
838
|
+
const start = stop-interval
|
|
839
|
+
const name = new Date(stop).toLocaleDateString()
|
|
840
|
+
// const done = new Set()
|
|
841
|
+
const graph = new Graph()
|
|
842
|
+
const find = slug => neighborhood.find(info => info.slug == slug)
|
|
843
|
+
const node = info => {
|
|
844
|
+
return graph.addUniqNode('',{
|
|
845
|
+
name:info.title.replaceAll(/ /g,"\n"),
|
|
846
|
+
title:info.title,
|
|
847
|
+
site:info.domain
|
|
848
|
+
})
|
|
849
|
+
}
|
|
850
|
+
const here = neighborhood
|
|
851
|
+
.filter(info => info.date < stop && info.date >= start)
|
|
852
|
+
.filter(info => !(info.links && Object.keys(info.links).length > 5))
|
|
853
|
+
if(here.length) {
|
|
854
|
+
for (const info of here) {
|
|
855
|
+
const nid = node(info)
|
|
856
|
+
for (const link in (info.links||{})) {
|
|
857
|
+
const linked = find(link)
|
|
858
|
+
if(linked)
|
|
859
|
+
graph.addRel('',nid,node(linked))
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
aspects.push({name,graph})
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
return aspects
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
function hubs() {
|
|
869
|
+
const aspects = []
|
|
870
|
+
const hits = {}
|
|
871
|
+
for (const info of neighborhood)
|
|
872
|
+
if(info.links)
|
|
873
|
+
for(const link in info.links)
|
|
874
|
+
hits[link] = (hits[link]||0) + 1
|
|
875
|
+
const hubs = Object.entries(hits)
|
|
876
|
+
.sort((a,b) => b[1]-a[1])
|
|
877
|
+
.slice(0,10)
|
|
878
|
+
console.log({hits,hubs})
|
|
879
|
+
|
|
880
|
+
for(const hub of hubs) {
|
|
881
|
+
const name = `${hub[1]}-${hub[0]}`
|
|
882
|
+
const graph = new Graph()
|
|
883
|
+
const find = slug => neighborhood.find(info => info.slug == slug)
|
|
884
|
+
const node = info => {
|
|
885
|
+
return graph.addUniqNode('',{
|
|
886
|
+
name:info.title.replaceAll(/ /g,"\n"),
|
|
887
|
+
title:info.title,
|
|
888
|
+
site:info.domain
|
|
889
|
+
})
|
|
890
|
+
}
|
|
891
|
+
const info = find(hub[0])
|
|
892
|
+
const nid = node(info)
|
|
893
|
+
for(const link in (info.links||{})) {
|
|
894
|
+
const linked = find(link)
|
|
895
|
+
if(linked)
|
|
896
|
+
graph.addRel('',nid,node(linked))
|
|
897
|
+
}
|
|
898
|
+
aspects.push({name,graph})
|
|
899
|
+
}
|
|
900
|
+
return aspects
|
|
901
|
+
}
|
|
902
|
+
|
|
819
903
|
}
|
|
820
904
|
|
|
821
905
|
|
|
@@ -865,6 +949,11 @@
|
|
|
865
949
|
return this.nodes.length-1;
|
|
866
950
|
}
|
|
867
951
|
|
|
952
|
+
addUniqNode(type, props={}) {
|
|
953
|
+
const nid = this.nodes.findIndex(node => node.type == type && node.props?.name == props?.name)
|
|
954
|
+
return nid >= 0 ? nid : this.addNode(type, props)
|
|
955
|
+
}
|
|
956
|
+
|
|
868
957
|
addRel(type, from, to, props={}) {
|
|
869
958
|
const obj = {type, from, to, props};
|
|
870
959
|
this.rels.push(obj);
|