git ssb

2+

mixmix / ticktack



Commit b00977e5053049e9827db3a20714d9979d7e12d3

collect config/ and get blog ordering working on stats page

mix irving committed on 5/1/2018, 3:16:06 AM
Parent: 290057bfce673063c5629dd99de5b67dab52483a

Files changed

app/page/statsShow.jschanged
ssb-server-blog-stats.jschanged
config.jsdeleted
config/chart.jsadded
config/config-custom.jsonadded
config/config-ssb.jsonadded
config/index.jsadded
default-config.jsondeleted
ssb-config.jsondeleted
app/page/statsShow.jsView
@@ -1,13 +1,15 @@
11 const nest = require('depnest')
2-const { h, resolve, when, Value, Struct, Array: MutantArray, Dict, onceTrue, map, computed, throttle, watchAll } = require('mutant')
2+const { h, when, Value, Struct, Array: MutantArray, Dict, onceTrue, map, computed, throttle, watchAll } = require('mutant')
33 const pull = require('pull-stream')
44 const marksum = require('markdown-summary')
55 const Chart = require('chart.js')
66 const groupBy = require('lodash/groupBy')
77 const flatMap = require('lodash/flatMap')
88 const get = require('lodash/get')
99
10+const chartConfig = require('../../config/chart')
11+
1012 exports.gives = nest('app.page.statsShow')
1113
1214 exports.needs = nest({
1315 'sbot.obs.connection': 'first',
@@ -181,18 +183,24 @@
181183 }
182184
183185 function fetchBlogData ({ server, store }) {
184186 const myKey = server.id
185- pull(
186- server.blogStats.readBlogs({ reverse: false }),
187- pull.drain(blog => {
188- store.blogs.push(blog)
189187
188+ server.blogStats.getBlogs({}, (err, blogs) => {
189+ if (err) console.error(err)
190+
191+ // TODO - change this once merge in the new notifications-hanger work
192+ // i.e. do one query for ALL comments on my blogs as opposed to N queries
193+ blogs.forEach(blog => {
190194 fetchComments({ server, store, blog })
191195 fetchLikes({ server, store, blog })
192196 })
193- )
194197
198+ blogs = blogs
199+ .sort((a, b) => a.value.timestamp > b.value.timestamp ? -1 : +1)
200+ store.blogs.set(blogs)
201+ })
202+
195203 function fetchComments ({ server, store, blog }) {
196204 if (!store.comments.has(blog.key)) store.comments.put(blog.key, MutantArray())
197205
198206 pull(
@@ -319,60 +327,4 @@
319327 }
320328 function toDay (ts) { return Math.floor(ts / DAY) }
321329 }
322330
323-// TODO rm chartData and other overly smart things which didn't work from here
324-function chartConfig ({ context }) {
325- const { lower, upper } = resolve(context.range)
326-
327- // Ticktack Primary color:'hsla(215, 57%, 43%, 1)',
328- const barColor = 'hsla(215, 57%, 60%, 1)'
329-
330- return {
331- type: 'bar',
332- data: {
333- datasets: [{
334- backgroundColor: barColor,
335- borderColor: barColor,
336- data: []
337- }]
338- },
339- options: {
340- legend: {
341- display: false
342- },
343- scales: {
344- xAxes: [{
345- type: 'time',
346- distribution: 'linear',
347- time: {
348- unit: 'day',
349- min: new Date(lower - DAY / 2),
350- max: new Date(upper - DAY / 2),
351- tooltipFormat: 'MMMM D',
352- stepSize: 7
353- },
354- bounds: 'ticks',
355- ticks: {
356- // maxTicksLimit: 4
357- },
358- gridLines: {
359- display: false
360- },
361- maxBarThickness: 20
362- }],
363-
364- yAxes: [{
365- ticks: {
366- min: 0,
367- suggestedMax: 10,
368- // max: Math.max(localMax, 10),
369- stepSize: 5
370- }
371- }]
372- },
373- animation: {
374- // duration: 300
375- }
376- }
377- }
378-}
ssb-server-blog-stats.jsView
@@ -9,9 +9,9 @@
99 const getCommentRoot = (msg) => get(msg, 'value.content.root')
1010 const getLikeRoot = (msg) => get(msg, 'value.content.vote.link')
1111 const getTimestamp = (msg) => get(msg, 'value.timestamp')
1212
13-const FLUME_VIEW_VERSION = 2
13+const FLUME_VIEW_VERSION = 1
1414
1515 module.exports = {
1616 name: 'blogStats',
1717 version: 1,
@@ -76,10 +76,10 @@
7676 }
7777
7878 // a Plog is a Blog shaped Post!
7979 function isPlog (msg) {
80- // if (get(msg, 'value.content.text', '').length >= 3000) console.log(get(msg, 'value.content.text', '').length)
81- return get(msg, 'value.content.text', '').length >= 3000
80+ // if (get(msg, 'value.content.text', '').length >= 2500) console.log(get(msg, 'value.content.text', '').length)
81+ return get(msg, 'value.content.text', '').length >= 2500
8282 }
8383
8484 function readBlogs (options = {}) {
8585 const query = Object.assign({}, {
config.jsView
@@ -1,23 +1,0 @@
1-const Config = require('ssb-config/inject')
2-const nest = require('depnest')
3-const ssbKeys = require('ssb-keys')
4-const Path = require('path')
5-
6-// const appName = process.env.ssb_appname || 'ticktack' //'ticktack' TEMP: this is for the windowsSSB installer only
7-const appName = process.env.ssb_appname || 'ssb'
8-var opts = appName === 'ssb' ? require('./ssb-config.json') : require('./default-config')
9-
10-exports.gives = nest('config.sync.load')
11-exports.create = (api) => {
12- var config
13- return nest('config.sync.load', () => {
14- if (!config) {
15- config = Config(appName, opts)
16- config.keys = ssbKeys.loadOrCreateSync(Path.join(config.path, 'secret'))
17-
18- // HACK: fix offline on windows by specifying 127.0.0.1 instead of localhost (default)
19- config.remote = `net:127.0.0.1:${config.port}~shs:${config.keys.id.slice(1).replace('.ed25519', '')}`
20- }
21- return config
22- })
23-}
config/chart.jsView
@@ -1,0 +1,59 @@
1+const { resolve } = require('mutant')
2+
3+const DAY = 24 * 60 * 60 * 1000
4+
5+module.exports = function chartConfig ({ context }) {
6+ const { lower, upper } = resolve(context.range)
7+
8+ // Ticktack Primary color:'hsla(215, 57%, 43%, 1)',
9+ const barColor = 'hsla(215, 57%, 60%, 1)'
10+
11+ return {
12+ type: 'bar',
13+ data: {
14+ datasets: [{
15+ backgroundColor: barColor,
16+ borderColor: barColor,
17+ data: []
18+ }]
19+ },
20+ options: {
21+ legend: {
22+ display: false
23+ },
24+ scales: {
25+ xAxes: [{
26+ type: 'time',
27+ distribution: 'linear',
28+ time: {
29+ unit: 'day',
30+ min: new Date(lower - DAY / 2),
31+ max: new Date(upper - DAY / 2),
32+ tooltipFormat: 'MMMM D',
33+ stepSize: 7
34+ },
35+ bounds: 'ticks',
36+ ticks: {
37+ // maxTicksLimit: 4
38+ },
39+ gridLines: {
40+ display: false
41+ },
42+ maxBarThickness: 20
43+ }],
44+
45+ yAxes: [{
46+ ticks: {
47+ min: 0,
48+ suggestedMax: 10,
49+ // max: Math.max(localMax, 10),
50+ stepSize: 5
51+ }
52+ }]
53+ },
54+ animation: {
55+ // duration: 300
56+ }
57+ }
58+ }
59+}
config/config-custom.jsonView
@@ -1,0 +1,12 @@
1+{
2+ "_port": 43750,
3+ "_blobsPort": 43751,
4+ "_ws": { "port": 43751 },
5+ "_caps": {"shs": "ErgQF85hFQpUXp69IXtLW+nXDgFIOKKDOWFX/st2aWk="},
6+ "autoinvites": [
7+ "net:128.199.76.241:8008~shs:7xMrWP8708+LDvaJrRMRQJEixWYp4Oipa9ohqY7+NyQ=:oxWZicO67cnXBRyL/VorYknQK8BHkBnj6IRQFXgjGoA=",
8+
9+ "138.68.27.255:8008:@MflVZCcOBOUe6BLrm/8TyirkTu9/JtdnIJALcd8v5bc=.ed25519~Mfz6xcajHDtH3Z2Dp4I7HT7K1l0MWxJxOftlEBct8jU="
10+ ]
11+}
12+
config/config-ssb.jsonView
@@ -1,0 +1,7 @@
1+{
2+ "autoinvites": [
3+ "net:128.199.76.241:8008~shs:7xMrWP8708+LDvaJrRMRQJEixWYp4Oipa9ohqY7+NyQ=:oxWZicO67cnXBRyL/VorYknQK8BHkBnj6IRQFXgjGoA=",
4+ "138.68.27.255:8008:@MflVZCcOBOUe6BLrm/8TyirkTu9/JtdnIJALcd8v5bc=.ed25519~Mfz6xcajHDtH3Z2Dp4I7HT7K1l0MWxJxOftlEBct8jU="
5+ ]
6+}
7+
config/index.jsView
@@ -1,0 +1,23 @@
1+const Config = require('ssb-config/inject')
2+const nest = require('depnest')
3+const ssbKeys = require('ssb-keys')
4+const Path = require('path')
5+
6+// const appName = process.env.ssb_appname || 'ticktack' //'ticktack' TEMP: this is for the windowsSSB installer only
7+const appName = process.env.ssb_appname || 'ssb'
8+var opts = appName === 'ssb' ? require('./config-ssb.json') : require('./config-custom.json')
9+
10+exports.gives = nest('config.sync.load')
11+exports.create = (api) => {
12+ var config
13+ return nest('config.sync.load', () => {
14+ if (!config) {
15+ config = Config(appName, opts)
16+ config.keys = ssbKeys.loadOrCreateSync(Path.join(config.path, 'secret'))
17+
18+ // HACK: fix offline on windows by specifying 127.0.0.1 instead of localhost (default)
19+ config.remote = `net:127.0.0.1:${config.port}~shs:${config.keys.id.slice(1).replace('.ed25519', '')}`
20+ }
21+ return config
22+ })
23+}
default-config.jsonView
@@ -1,12 +1,0 @@
1-{
2- "_port": 43750,
3- "_blobsPort": 43751,
4- "_ws": { "port": 43751 },
5- "_caps": {"shs": "ErgQF85hFQpUXp69IXtLW+nXDgFIOKKDOWFX/st2aWk="},
6- "autoinvites": [
7- "net:128.199.76.241:8008~shs:7xMrWP8708+LDvaJrRMRQJEixWYp4Oipa9ohqY7+NyQ=:oxWZicO67cnXBRyL/VorYknQK8BHkBnj6IRQFXgjGoA=",
8-
9- "138.68.27.255:8008:@MflVZCcOBOUe6BLrm/8TyirkTu9/JtdnIJALcd8v5bc=.ed25519~Mfz6xcajHDtH3Z2Dp4I7HT7K1l0MWxJxOftlEBct8jU="
10- ]
11-}
12-
ssb-config.jsonView
@@ -1,7 +1,0 @@
1-{
2- "autoinvites": [
3- "net:128.199.76.241:8008~shs:7xMrWP8708+LDvaJrRMRQJEixWYp4Oipa9ohqY7+NyQ=:oxWZicO67cnXBRyL/VorYknQK8BHkBnj6IRQFXgjGoA=",
4- "138.68.27.255:8008:@MflVZCcOBOUe6BLrm/8TyirkTu9/JtdnIJALcd8v5bc=.ed25519~Mfz6xcajHDtH3Z2Dp4I7HT7K1l0MWxJxOftlEBct8jU="
5- ]
6-}
7-

Built with git-ssb-web