Commit b00977e5053049e9827db3a20714d9979d7e12d3
collect config/ and get blog ordering working on stats page
mix irving committed on 5/1/2018, 3:16:06 AMParent: 290057bfce673063c5629dd99de5b67dab52483a
Files changed
app/page/statsShow.js | changed |
ssb-server-blog-stats.js | changed |
config.js | deleted |
config/chart.js | added |
config/config-custom.json | added |
config/config-ssb.json | added |
config/index.js | added |
default-config.json | deleted |
ssb-config.json | deleted |
app/page/statsShow.js | ||
---|---|---|
@@ -1,13 +1,15 @@ | ||
1 | 1 | 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') | |
3 | 3 | const pull = require('pull-stream') |
4 | 4 | const marksum = require('markdown-summary') |
5 | 5 | const Chart = require('chart.js') |
6 | 6 | const groupBy = require('lodash/groupBy') |
7 | 7 | const flatMap = require('lodash/flatMap') |
8 | 8 | const get = require('lodash/get') |
9 | 9 | |
10 | +const chartConfig = require('../../config/chart') | |
11 | + | |
10 | 12 | exports.gives = nest('app.page.statsShow') |
11 | 13 | |
12 | 14 | exports.needs = nest({ |
13 | 15 | 'sbot.obs.connection': 'first', |
@@ -181,18 +183,24 @@ | ||
181 | 183 | } |
182 | 184 | |
183 | 185 | function fetchBlogData ({ server, store }) { |
184 | 186 | const myKey = server.id |
185 | - pull( | |
186 | - server.blogStats.readBlogs({ reverse: false }), | |
187 | - pull.drain(blog => { | |
188 | - store.blogs.push(blog) | |
189 | 187 | |
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 => { | |
190 | 194 | fetchComments({ server, store, blog }) |
191 | 195 | fetchLikes({ server, store, blog }) |
192 | 196 | }) |
193 | - ) | |
194 | 197 | |
198 | + blogs = blogs | |
199 | + .sort((a, b) => a.value.timestamp > b.value.timestamp ? -1 : +1) | |
200 | + store.blogs.set(blogs) | |
201 | + }) | |
202 | + | |
195 | 203 | function fetchComments ({ server, store, blog }) { |
196 | 204 | if (!store.comments.has(blog.key)) store.comments.put(blog.key, MutantArray()) |
197 | 205 | |
198 | 206 | pull( |
@@ -319,60 +327,4 @@ | ||
319 | 327 | } |
320 | 328 | function toDay (ts) { return Math.floor(ts / DAY) } |
321 | 329 | } |
322 | 330 | |
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.js | ||
---|---|---|
@@ -9,9 +9,9 @@ | ||
9 | 9 | const getCommentRoot = (msg) => get(msg, 'value.content.root') |
10 | 10 | const getLikeRoot = (msg) => get(msg, 'value.content.vote.link') |
11 | 11 | const getTimestamp = (msg) => get(msg, 'value.timestamp') |
12 | 12 | |
13 | -const FLUME_VIEW_VERSION = 2 | |
13 | +const FLUME_VIEW_VERSION = 1 | |
14 | 14 | |
15 | 15 | module.exports = { |
16 | 16 | name: 'blogStats', |
17 | 17 | version: 1, |
@@ -76,10 +76,10 @@ | ||
76 | 76 | } |
77 | 77 | |
78 | 78 | // a Plog is a Blog shaped Post! |
79 | 79 | 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 | |
82 | 82 | } |
83 | 83 | |
84 | 84 | function readBlogs (options = {}) { |
85 | 85 | const query = Object.assign({}, { |
config.js | ||
---|---|---|
@@ -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.js | ||
---|---|---|
@@ -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.json | ||
---|---|---|
@@ -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.json | ||
---|---|---|
@@ -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.js | ||
---|---|---|
@@ -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.json | ||
---|---|---|
@@ -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.json | ||
---|---|---|
@@ -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