mirror of
https://github.com/urbit/shrub.git
synced 2024-12-11 11:02:25 +03:00
tally: add generator for measuring group activity
Scrapes groups and graphs for member counts and recent activity respectively, and uses that to print out a "tally" of activity for all local groups and their channels. Since this output is intended to be shared with other parties, anonymizes resource identifiers by default.
This commit is contained in:
parent
0fd5ba6054
commit
578f10180a
122
pkg/arvo/gen/tally.hoon
Normal file
122
pkg/arvo/gen/tally.hoon
Normal file
@ -0,0 +1,122 @@
|
||||
/- gr=group, md=metadata-store, ga=graph-store
|
||||
/+ re=resource
|
||||
!:
|
||||
:- %say
|
||||
|= $: [now=@da eny=@uvJ =beak]
|
||||
args=?(~ [shy=? ~])
|
||||
~
|
||||
==
|
||||
::
|
||||
=/ shy=? ?~(args & shy.args)
|
||||
=* our=@p p.beak
|
||||
::
|
||||
|^
|
||||
=; out=(list @t)
|
||||
:- %tang
|
||||
%- flop ::NOTE tang is bottom-up
|
||||
:* ''
|
||||
'tallied your activity score! find the results below.'
|
||||
::
|
||||
?: shy
|
||||
'to show non-anonymized resource identifiers, +tally |'
|
||||
'showing plain resource identifiers, share with care.'
|
||||
::
|
||||
'counted from groups and channels that you are hosting.'
|
||||
'groups are listed with their member count.'
|
||||
'channels are listed with activity from the past week:'
|
||||
' - amount of top-level content'
|
||||
' - amount of unique authors'
|
||||
''
|
||||
(snoc out '')
|
||||
==
|
||||
:: gather local non-dm groups, sorted by size
|
||||
::
|
||||
=/ groups=(list [local=? resource:re members=@ud])
|
||||
%+ murn
|
||||
%~ tap in
|
||||
%~ key by
|
||||
dir:(scry arch %y %group-store /groups)
|
||||
|= i=@ta
|
||||
=/ r=resource:re (de-path:re (stab i))
|
||||
=/ g=(unit group:gr)
|
||||
%+ scry (unit group:gr)
|
||||
[%x %group-store [%groups (snoc (en-path:re r) %noun)]]
|
||||
?: |(?=(~ g) hidden.u.g)
|
||||
~
|
||||
`[=(our entity.r) r ~(wyt in members.u.g)]
|
||||
=/ crowds=(list [resource:re @ud])
|
||||
%+ sort (turn (skim groups head) tail)
|
||||
|= [[* a=@ud] [* b=@ud]]
|
||||
(gth a b)
|
||||
:: gather local per-group channels
|
||||
::
|
||||
=/ channels=(map resource:re (list [module=term =resource:re]))
|
||||
%- ~(gas by *(map resource:re (list [module=term =resource:re])))
|
||||
%+ turn crowds
|
||||
|= [r=resource:re *]
|
||||
:- r
|
||||
%+ murn
|
||||
%~ tap by
|
||||
%+ scry associations:md
|
||||
[%x %metadata-store [%group (snoc (en-path:re r) %noun)]]
|
||||
|= [[* m=md-resource:md] metadata:md]
|
||||
::NOTE we only count graphs for now
|
||||
?. &(=(%graph app-name.m) =(our creator)) ~
|
||||
`[module (de-path:re app-path.m)]
|
||||
:: count activity per channel
|
||||
::
|
||||
=/ activity=(list [resource:re members=@ud (list [resource:re mod=term week=@ud authors=@ud])])
|
||||
%+ turn crowds
|
||||
|= [g=resource:re m=@ud]
|
||||
:+ g m
|
||||
%+ turn (~(got by channels) g)
|
||||
|= [m=term r=resource:re]
|
||||
:+ r m
|
||||
::NOTE graph-store doesn't use the full resource-style path here!
|
||||
=/ upd=update:ga
|
||||
%+ scry update:ga
|
||||
[%x %graph-store /graph/(scot %p entity.r)/[name.r]/noun]
|
||||
?> ?=(%add-graph -.q.upd)
|
||||
=/ mo ((ordered-map atom node:ga) gth)
|
||||
=/ week=(list [@da node:ga])
|
||||
(tap:mo (subset:mo graph.q.upd ~ `(sub now ~d7)))
|
||||
:- (lent week)
|
||||
%~ wyt in
|
||||
%+ roll week
|
||||
|= [[* [author=ship *] *] a=(set ship)]
|
||||
(~(put in a) author)
|
||||
:: render results
|
||||
::
|
||||
:- (tac 'the date is ' (scot %da now))
|
||||
:- :(tac 'you are in ' (render-number (lent groups)) ' group(s).')
|
||||
:- :(tac 'you are hosting ' (render-number (lent crowds)) ' group(s):')
|
||||
%- zing
|
||||
%+ turn activity
|
||||
|= [g=resource:re m=@ud chans=(list [resource:re term @ud @ud])]
|
||||
^- (list @t)
|
||||
:- :(tac 'group, ' (render-resource g) ', ' (render-number m))
|
||||
%+ turn chans
|
||||
|= [c=resource:re m=term w=@ud a=@ud]
|
||||
;: tac ' chan, '
|
||||
(render-resource c) ', '
|
||||
m ', '
|
||||
(render-number w) ', '
|
||||
(render-number a)
|
||||
==
|
||||
::
|
||||
++ scry
|
||||
|* [=mold care=term app=term =path]
|
||||
.^(mold (tac %g care) (scot %p our) app (scot %da now) path)
|
||||
::
|
||||
++ tac (cury cat 3)
|
||||
::
|
||||
++ render-resource
|
||||
|= r=resource:re
|
||||
?: shy
|
||||
(crip ((x-co:co 8) (mug r)))
|
||||
:(tac (scot %p entity.r) '/' name.r)
|
||||
::
|
||||
++ render-number
|
||||
|= n=@ud
|
||||
(crip ((d-co:co 1) n))
|
||||
--
|
Loading…
Reference in New Issue
Block a user