Skip to content

Commit 61ab6db

Browse files
author
Thomas Rueckstiess
committed
made sampling message dynamic
1 parent 3de9d94 commit 61ab6db

File tree

4 files changed

+68
-43
lines changed

4 files changed

+68
-43
lines changed

src/models/sampled-schema.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ module.exports = Schema.extend({
123123
};
124124
var start = new Date();
125125
var timeAtFirstDoc;
126+
var avgTimePerDoc = 0;
126127
var erroredOnDocs = [];
127128

128129
// No results found
@@ -143,6 +144,7 @@ module.exports = Schema.extend({
143144
if (!timeAtFirstDoc) {
144145
timeAtFirstDoc = new Date();
145146
}
147+
var timePerDoc = new Date();
146148
try {
147149
model.parse(doc);
148150
} catch (err) {
@@ -152,6 +154,9 @@ module.exports = Schema.extend({
152154
schema: model.serialize()
153155
});
154156
}
157+
timePerDoc = new Date() - timePerDoc;
158+
avgTimePerDoc += timePerDoc;
159+
debug('avg time', timePerDoc);
155160
cb(null, doc);
156161
};
157162

@@ -170,12 +175,13 @@ module.exports = Schema.extend({
170175
metrics.track('Schema: Complete', {
171176
Duration: new Date() - start,
172177
'Total Document Count': model.total,
173-
'Document Count': model.documents,
178+
'Sample Size': model.documents.length,
174179
'Errored Document Count': erroredOnDocs.length,
175180
'Time to First Doc': timeAtFirstDoc - start,
176-
'Schema Height': model.height, // # of top level keys
177-
'Schema Width': model.width, // max nesting depth
178-
'Schema Sparsity': model.sparsity // lots of fields missing or consistent
181+
'Average Time Per Doc': avgTimePerDoc / model.documents.length
182+
// 'Schema Height': model.height, // # of top level keys
183+
// 'Schema Width': model.width, // max nesting depth
184+
// 'Schema Sparsity': model.sparsity // lots of fields missing or consistent
179185
});
180186
options.success({});
181187
};

src/refine-view/index.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
}
2121
}
2222
.sampling-message {
23-
font-size: 14px;
23+
font-size: 12px;
2424
font-weight: 200;
2525
padding: 5px 25px;
2626
border-bottom: 2px solid @gray7

src/sampling-message/index.jade

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
.sampling-message
2-
span(data-hook='is_sample') Query returned ### documents. This report is based on a sample of 
3-
span(data-hook='is_query') Query returned 
4-
span(data-hook='sample_size_message')
5-
|.
2+
if is_sample
3+
| Query returned 
4+
b #{formatted_total_count}
5+
|  #{total_count_document}.
6+
| This report is based on a sample of 
7+
b #{formatted_sample_size}
8+
|  #{sample_size_document}.
9+
else
10+
| Query returned 
11+
b #{formatted_sample_size}
12+
|  #{sample_size_document}.

src/sampling-message/index.js

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,71 +2,83 @@ var View = require('ampersand-view');
22
var pluralize = require('pluralize');
33
var format = require('util').format;
44
var app = require('ampersand-app');
5+
var numeral = require('numeral');
56
var debug = require('debug')('scout:sampling-message:index');
67

78
var SamplingMessageView = View.extend({
9+
template: require('./index.jade'),
810
session: {
911
parent: 'state'
1012
},
11-
bindings: {
12-
visible: {
13-
type: 'booleanClass',
14-
no: 'hidden'
15-
},
16-
sample_size_message: {
17-
hook: 'sample_size_message'
18-
},
19-
is_sample: [
20-
{
21-
hook: 'is_sample',
22-
type: 'booleanClass',
23-
no: 'hidden'
24-
},
25-
{
26-
hook: 'is_query',
27-
type: 'booleanClass',
28-
yes: 'hidden'
29-
}
30-
]
31-
},
3213
props: {
33-
schema_sample_size: {
14+
sample_size: {
15+
type: 'number',
16+
default: 0
17+
},
18+
total_count: {
3419
type: 'number',
3520
default: 0
3621
}
3722
},
3823
derived: {
3924
visible: {
40-
deps: ['schema_sample_size'],
25+
deps: ['sample_size'],
4126
fn: function() {
42-
return this.schema_sample_size > 0;
27+
return this.sample_size > 0;
4328
}
4429
},
4530
is_sample: {
46-
deps: ['schema_sample_size'],
31+
deps: ['sample_size'],
32+
fn: function() {
33+
return this.sample_size === app.queryOptions.size;
34+
}
35+
},
36+
formatted_total_count: {
37+
deps: ['total_count'],
4738
fn: function() {
48-
return this.schema_sample_size === app.queryOptions.size;
39+
return numeral(this.total_count).format('0,0');
4940
}
5041
},
51-
sample_size_message: {
52-
deps: ['schema_sample_size'],
42+
formatted_sample_size: {
43+
deps: ['sample_size'],
5344
fn: function() {
54-
return format('%d %s', this.parent.parent.schema.sample_size,
55-
pluralize('document', this.parent.parent.schema.sample_size));
45+
return numeral(this.sample_size).format('0,0');
46+
}
47+
},
48+
total_count_document: {
49+
deps: ['total_count'],
50+
fn: function() {
51+
return pluralize('document', this.total_count);
52+
}
53+
},
54+
sample_size_document: {
55+
deps: ['sample_size'],
56+
fn: function() {
57+
return pluralize('document', this.sample_size);
5658
}
5759
}
5860
},
59-
template: require('./index.jade'),
61+
bindings: {
62+
visible: {
63+
type: 'booleanClass',
64+
no: 'hidden'
65+
}
66+
},
6067
initialize: function() {
6168
this.listenTo(this.parent.parent.schema, 'request', this.hide.bind(this));
6269
this.listenTo(this.parent.parent.schema, 'sync', this.show.bind(this));
6370
},
6471
hide: function() {
65-
this.schema_sample_size = 0;
72+
this.sample_size = 0;
73+
this.total_count = 0;
6674
},
6775
show: function() {
68-
debug('actual count', this.parent.parent.schema.total);
69-
this.schema_sample_size = this.parent.parent.schema.sample_size;
76+
this.sample_size = this.parent.parent.schema.sample_size;
77+
this.total_count = this.parent.parent.schema.total;
78+
this.render();
79+
},
80+
render: function() {
81+
this.renderWithTemplate(this);
7082
}
7183
});
7284
module.exports = SamplingMessageView;

0 commit comments

Comments
 (0)