Skip to content
This repository has been archived by the owner on Jul 19, 2022. It is now read-only.

Commit

Permalink
feat(mobile): add others data
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte committed Dec 3, 2017
1 parent acbf6e2 commit c19a10f
Show file tree
Hide file tree
Showing 16 changed files with 7,356 additions and 7,160 deletions.
1 change: 1 addition & 0 deletions cli/conf/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,4 @@ report:
- PhoneGap/Cordova
- NativeScript
- Electron
freeform: Other mobile/desktop apps solutions
26 changes: 26 additions & 0 deletions cli/lib/collector/mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const ignore = [
'None',
'none',
'no',
'No',
'.',
'?',
]
const cleanupFreeValue = value => (ignore.includes(value) ? null : value)

Expand Down Expand Up @@ -356,6 +359,29 @@ exports.response = {
'PhoneGap/Cordova': { type: 'keyword' },
NativeScript: { type: 'keyword' },
Electron: { type: 'keyword' },
'Other mobile/desktop apps solutions': {
type: 'keyword',
transform: normalize([
[/weex/i, 'Weex'],
[/xamarin/i, 'Xamarin'],
[/pwa/i, 'PWA'],
[/progressive web app/i, 'PWA'],
[/nw\.js/i, 'nw.js'],
[/nwjs/i, 'nw.js'],
[/nw/i, 'nw.js'],
[/expo/i, 'Expo'],
[/Flutter/i, 'Flutter'],
[/appcelerator/i, 'Appcelerator'],
[/titanium/i, 'Appcelerator'],
[/fuse/i, 'Fuse'],
[/cef/i, 'CEF'],
[/Chromium Embedded Framework/i, 'CEF'],
[/Angular Native/i, 'Angular Native'],
[/Elm native/i, 'Elm native'],
[/Swift/i, 'Swift'],
[/Kotlin/i, 'Kotlin'],
]),
},
'On a scale of one to five pencils, how happy are you with the current state of mobile apps?': {
type: 'short',
transform: castNumber,
Expand Down
52 changes: 50 additions & 2 deletions cli/lib/collector/reporter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { maxBy, pick, values } = require('lodash')
const { maxBy, pick, values, sortBy } = require('lodash')
const config = require('@ekino/config')
const elastic = require('./elastic')
const dto = require('./dto')
Expand Down Expand Up @@ -216,6 +216,50 @@ exports.experienceByUsers = async (
return result.aggregations
}

/**
* Compute aggregations according to number of tools used.
*
* @param {Array.<string>} tools
*
* @return {Promise.<Array.<Object>>}
*/
exports.distributionByNumberOfToolsUsed = async tools => {
const totalScript = `
def fields = ['${tools.join('\', \'')}'];
def total = 0; for (int i = 0; i < fields.length; i++) {
if(doc[fields[i]][0] == "I've USED it before, and WOULD use it again") {
total += 1;
}
}
return total;
`.trim()

const result = await elastic.client.search({
index: config.get('elastic.index'),
size: 0,
body: {
query: {match_all: {}},
aggs: {
by_count: {
terms: {
script: {
lang: 'painless',
source: totalScript
}
}
}
}
}
})

return sortBy(result.aggregations.by_count.buckets.map(bucket => ({
...bucket,
key: Number(bucket.key),
})), 'key')
}

/**
* Retrieve usage (I've USED it before, and WOULD use it again),
* and compute stats per country.
Expand Down Expand Up @@ -314,13 +358,15 @@ exports.frontend = async () => {
const experienceByUsers = await exports.experienceByUsers(reportConfig.frontend.keys)
const others = await elastic.termsAgg(reportConfig.frontend.freeform, OTHERS_AGG_SIZE)
const countries = await exports.distributionByCountry(reportConfig.frontend.keys)
const numberOfToolsUsed = await exports.distributionByNumberOfToolsUsed(reportConfig.frontend.keys)

return {
keys: reportConfig.frontend.keys,
experience: dto.aggregations(experience.aggregations),
experienceByUsers,
countries,
others: others.aggregations[reportConfig.frontend.freeform],
numberOfToolsUsed,
}
}

Expand Down Expand Up @@ -407,20 +453,22 @@ exports.build = async () => {
keys: reportConfig.buildTools.keys,
experience: dto.aggregations(experience.aggregations),
experienceByUsers,
countries,
others: others.aggregations[reportConfig.buildTools.freeform],
countries,
}
}

exports.mobile = async () => {
const experience = await elastic.termsAggs(reportConfig.mobile.keys)
const experienceByUsers = await exports.experienceByUsers(reportConfig.mobile.keys)
const others = await elastic.termsAgg(reportConfig.mobile.freeform, OTHERS_AGG_SIZE)
const countries = await exports.distributionByCountry(reportConfig.mobile.keys)

return {
keys: reportConfig.mobile.keys,
experience: dto.aggregations(experience.aggregations),
experienceByUsers,
others: others.aggregations[reportConfig.mobile.freeform],
countries,
}
}
Expand Down
42 changes: 21 additions & 21 deletions src/data/backend.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
"average": 8
},
"by_location": {
"doc_count_error_upper_bound": 10,
"doc_count_error_upper_bound": 9,
"sum_other_doc_count": 333,
"buckets": [
{
Expand Down Expand Up @@ -278,7 +278,7 @@
"average": 7
},
"by_location": {
"doc_count_error_upper_bound": 74,
"doc_count_error_upper_bound": 75,
"sum_other_doc_count": 3643,
"buckets": [
{
Expand Down Expand Up @@ -535,7 +535,7 @@
},
"by_location": {
"doc_count_error_upper_bound": 5,
"sum_other_doc_count": 145,
"sum_other_doc_count": 144,
"buckets": [
{
"key": "United States",
Expand Down Expand Up @@ -570,11 +570,11 @@
"doc_count": 12
},
{
"key": "Australia",
"doc_count": 10
"key": "Spain",
"doc_count": 11
},
{
"key": "Spain",
"key": "Australia",
"doc_count": 10
}
]
Expand Down Expand Up @@ -919,7 +919,7 @@
},
"by_location": {
"doc_count_error_upper_bound": 5,
"sum_other_doc_count": 175,
"sum_other_doc_count": 173,
"buckets": [
{
"key": "United States",
Expand Down Expand Up @@ -951,15 +951,15 @@
},
{
"key": "India",
"doc_count": 14
"doc_count": 15
},
{
"key": "Brazil",
"doc_count": 13
},
{
"key": "Mexico",
"doc_count": 11
"doc_count": 12
}
]
}
Expand Down Expand Up @@ -1063,7 +1063,7 @@
},
{
"key": "United Kingdom",
"doc_count": 20
"doc_count": 19
},
{
"key": "Germany",
Expand All @@ -1086,8 +1086,8 @@
"doc_count": 10
},
{
"key": "Argentina",
"doc_count": 6
"key": "Spain",
"doc_count": 7
}
]
}
Expand Down Expand Up @@ -2587,7 +2587,7 @@
],
"others": {
"doc_count_error_upper_bound": 5,
"sum_other_doc_count": 776,
"sum_other_doc_count": 768,
"buckets": [
{
"key": "Node.js",
Expand Down Expand Up @@ -2627,7 +2627,7 @@
},
{
"key": "elixir",
"doc_count": 41
"doc_count": 42
},
{
"key": "python",
Expand All @@ -2638,20 +2638,20 @@
"doc_count": 30
},
{
"key": "golang",
"key": "serverless",
"doc_count": 28
},
{
"key": "serverless",
"doc_count": 28
"key": "golang",
"doc_count": 27
},
{
"key": "socket.io",
"doc_count": 27
},
{
"key": "micro",
"doc_count": 24
"doc_count": 23
},
{
"key": "clojure",
Expand All @@ -2662,11 +2662,11 @@
"doc_count": 19
},
{
"key": "GraphQL",
"doc_count": 10
"key": "Kraken",
"doc_count": 9
},
{
"key": "Kraken",
"key": "GraphQL",
"doc_count": 8
}
]
Expand Down

0 comments on commit c19a10f

Please sign in to comment.