git ssb

2+

mixmix / ticktack



Commit 858e6680e313a0e7ea426317a18f59ff5c7098c8

Merge branch 'master' of github.com:ticktackim/ticktack-workplan into notification-hanger

mix irving committed on 5/2/2018, 1:28:49 AM
Parent: ee8e82af460b4067e37ca225319fad117e33b584
Parent: 1b46fe809a87f906b19ab7dad059971d13730b4f

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 'app.html.sideNav': 'first',
@@ -183,18 +185,24 @@
183185 }
184186
185187 function fetchBlogData ({ server, store }) {
186188 const myKey = server.id
187- pull(
188- server.blogStats.readBlogs({ reverse: false }),
189- pull.drain(blog => {
190- store.blogs.push(blog)
191189
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 => {
192196 fetchComments({ server, store, blog })
193197 fetchLikes({ server, store, blog })
194198 })
195- )
196199
200+ blogs = blogs
201+ .sort((a, b) => a.value.timestamp > b.value.timestamp ? -1 : +1)
202+ store.blogs.set(blogs)
203+ })
204+
197205 function fetchComments ({ server, store, blog }) {
198206 if (!store.comments.has(blog.key)) store.comments.put(blog.key, MutantArray())
199207
200208 pull(
@@ -258,9 +266,9 @@
258266
259267 return Object.keys(grouped)
260268 .map(day => {
261269 return {
262- t: day * DAY + 10,
270+ t: day * DAY + DAY / 2,
263271 y: grouped[day].length
264272 }
265273 // NOTE - this collects the data points for a day at t = 10ms into the day
266274 // this is necessary for getting counts to line up (bars, and daily count)
@@ -280,9 +288,9 @@
280288 const { lower, upper } = range
281289 const slice = data
282290 .filter(d => d.t > lower && d.t <= upper)
283291 .map(d => d.y)
284- .sort((a, b) => a < b)
292+ .sort((a, b) => a > b ? -1 : +1)
285293
286294 var h = slice[0]
287295 if (!h || h < 10) h = 10
288296 else h = h + (5 - h % 5)
@@ -297,11 +305,10 @@
297305 // Update the x-axes bounds of the graph!
298306 context.range(range => {
299307 const { lower, upper } = range
300308
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
304311
305312 chart.update()
306313 })
307314
@@ -320,61 +327,4 @@
320327 }
321328 }
322329 function toDay (ts) { return Math.floor(ts / DAY) }
323330 }
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.jsView
@@ -10,9 +10,9 @@
1010 const getCommentRoot = (msg) => get(msg, 'value.content.root')
1111 const getLikeRoot = (msg) => get(msg, 'value.content.vote.link')
1212 const getTimestamp = (msg) => get(msg, 'value.timestamp')
1313
14-const FLUME_VIEW_VERSION = 2
14+const FLUME_VIEW_VERSION = 1
1515
1616 module.exports = {
1717 name: 'blogStats',
1818 version: 1,
@@ -79,10 +79,10 @@
7979 }
8080
8181 // a Plog is a Blog shaped Post!
8282 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
8585 }
8686
8787 function readBlogs (options = {}) {
8888 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: 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.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