Commit 858e6680e313a0e7ea426317a18f59ff5c7098c8
Merge branch 'master' of github.com:ticktackim/ticktack-workplan into notification-hanger
mix irving committed on 5/2/2018, 1:28:49 AMParent: ee8e82af460b4067e37ca225319fad117e33b584
Parent: 1b46fe809a87f906b19ab7dad059971d13730b4f
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 | 'app.html.sideNav': 'first', |
@@ -183,18 +185,24 @@ | ||
183 | 185 | } |
184 | 186 | |
185 | 187 | function fetchBlogData ({ server, store }) { |
186 | 188 | const myKey = server.id |
187 | - pull( | |
188 | - server.blogStats.readBlogs({ reverse: false }), | |
189 | - pull.drain(blog => { | |
190 | - store.blogs.push(blog) | |
191 | 189 | |
190 | + server.blogStats.getBlogs({}, (err, blogs) => { | |
191 | + if (err) console.error(err) | |
192 | + | |
193 | + // TODO - change this once merge in the new notifications-hanger work | |
194 | + // i.e. do one query for ALL comments on my blogs as opposed to N queries | |
195 | + blogs.forEach(blog => { | |
192 | 196 | fetchComments({ server, store, blog }) |
193 | 197 | fetchLikes({ server, store, blog }) |
194 | 198 | }) |
195 | - ) | |
196 | 199 | |
200 | + blogs = blogs | |
201 | + .sort((a, b) => a.value.timestamp > b.value.timestamp ? -1 : +1) | |
202 | + store.blogs.set(blogs) | |
203 | + }) | |
204 | + | |
197 | 205 | function fetchComments ({ server, store, blog }) { |
198 | 206 | if (!store.comments.has(blog.key)) store.comments.put(blog.key, MutantArray()) |
199 | 207 | |
200 | 208 | pull( |
@@ -258,9 +266,9 @@ | ||
258 | 266 | |
259 | 267 | return Object.keys(grouped) |
260 | 268 | .map(day => { |
261 | 269 | return { |
262 | - t: day * DAY + 10, | |
270 | + t: day * DAY + DAY / 2, | |
263 | 271 | y: grouped[day].length |
264 | 272 | } |
265 | 273 | // NOTE - this collects the data points for a day at t = 10ms into the day |
266 | 274 | // this is necessary for getting counts to line up (bars, and daily count) |
@@ -280,9 +288,9 @@ | ||
280 | 288 | const { lower, upper } = range |
281 | 289 | const slice = data |
282 | 290 | .filter(d => d.t > lower && d.t <= upper) |
283 | 291 | .map(d => d.y) |
284 | - .sort((a, b) => a < b) | |
292 | + .sort((a, b) => a > b ? -1 : +1) | |
285 | 293 | |
286 | 294 | var h = slice[0] |
287 | 295 | if (!h || h < 10) h = 10 |
288 | 296 | else h = h + (5 - h % 5) |
@@ -297,11 +305,10 @@ | ||
297 | 305 | // Update the x-axes bounds of the graph! |
298 | 306 | context.range(range => { |
299 | 307 | const { lower, upper } = range |
300 | 308 | |
301 | - chart.options.scales.xAxes[0].time.min = new Date(lower - DAY / 2) | |
302 | - chart.options.scales.xAxes[0].time.max = new Date(upper - DAY / 2) | |
303 | - // the squeezing in by DAY/2 is to stop data outside range from half showing | |
309 | + chart.options.scales.xAxes[0].time.min = lower | |
310 | + chart.options.scales.xAxes[0].time.max = upper | |
304 | 311 | |
305 | 312 | chart.update() |
306 | 313 | }) |
307 | 314 | |
@@ -320,61 +327,4 @@ | ||
320 | 327 | } |
321 | 328 | } |
322 | 329 | function toDay (ts) { return Math.floor(ts / DAY) } |
323 | 330 | } |
324 | - | |
325 | -// TODO rm chartData and other overly smart things which didn't work from here | |
326 | -function chartConfig ({ context }) { | |
327 | - const { lower, upper } = resolve(context.range) | |
328 | - | |
329 | - // Ticktack Primary color:'hsla(215, 57%, 43%, 1)', | |
330 | - const barColor = 'hsla(215, 57%, 60%, 1)' | |
331 | - | |
332 | - return { | |
333 | - type: 'bar', | |
334 | - data: { | |
335 | - datasets: [{ | |
336 | - backgroundColor: barColor, | |
337 | - borderColor: barColor, | |
338 | - data: [] | |
339 | - }] | |
340 | - }, | |
341 | - options: { | |
342 | - legend: { | |
343 | - display: false | |
344 | - }, | |
345 | - scales: { | |
346 | - xAxes: [{ | |
347 | - type: 'time', | |
348 | - distribution: 'linear', | |
349 | - time: { | |
350 | - unit: 'day', | |
351 | - min: new Date(lower - DAY / 2), | |
352 | - max: new Date(upper - DAY / 2), | |
353 | - tooltipFormat: 'MMMM D', | |
354 | - stepSize: 7 | |
355 | - }, | |
356 | - bounds: 'ticks', | |
357 | - ticks: { | |
358 | - // maxTicksLimit: 4 | |
359 | - }, | |
360 | - gridLines: { | |
361 | - display: false | |
362 | - }, | |
363 | - maxBarThickness: 20 | |
364 | - }], | |
365 | - | |
366 | - yAxes: [{ | |
367 | - ticks: { | |
368 | - min: 0, | |
369 | - suggestedMax: 10, | |
370 | - // max: Math.max(localMax, 10), | |
371 | - stepSize: 5 | |
372 | - } | |
373 | - }] | |
374 | - }, | |
375 | - animation: { | |
376 | - // duration: 300 | |
377 | - } | |
378 | - } | |
379 | - } | |
380 | -} |
ssb-server-blog-stats.js | ||
---|---|---|
@@ -10,9 +10,9 @@ | ||
10 | 10 | const getCommentRoot = (msg) => get(msg, 'value.content.root') |
11 | 11 | const getLikeRoot = (msg) => get(msg, 'value.content.vote.link') |
12 | 12 | const getTimestamp = (msg) => get(msg, 'value.timestamp') |
13 | 13 | |
14 | -const FLUME_VIEW_VERSION = 2 | |
14 | +const FLUME_VIEW_VERSION = 1 | |
15 | 15 | |
16 | 16 | module.exports = { |
17 | 17 | name: 'blogStats', |
18 | 18 | version: 1, |
@@ -79,10 +79,10 @@ | ||
79 | 79 | } |
80 | 80 | |
81 | 81 | // a Plog is a Blog shaped Post! |
82 | 82 | function isPlog (msg) { |
83 | - // if (get(msg, 'value.content.text', '').length >= 3000) console.log(get(msg, 'value.content.text', '').length) | |
84 | - return get(msg, 'value.content.text', '').length >= 3000 | |
83 | + // if (get(msg, 'value.content.text', '').length >= 2500) console.log(get(msg, 'value.content.text', '').length) | |
84 | + return get(msg, 'value.content.text', '').length >= 2500 | |
85 | 85 | } |
86 | 86 | |
87 | 87 | function readBlogs (options = {}) { |
88 | 88 | 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: lower, | |
31 | + max: upper, | |
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