Skip to content

Commit

Permalink
Merge branch 'main' of github.com:StateOfJS/Monorepo into lightweight…
Browse files Browse the repository at this point in the history
…-repackage
  • Loading branch information
dfcowell committed Dec 5, 2021
2 parents c8e6f24 + 1900ffd commit 645945d
Show file tree
Hide file tree
Showing 132 changed files with 2,645 additions and 47,627 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ esdata

.env

sitemap.yml
blocks.yml

.logs
.logs/*

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
93 changes: 60 additions & 33 deletions api/src/compute/brackets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@ export const winsAggregationFunction = async (

const rawResults = (await collection.aggregate(winsPipeline).toArray()) as WinsBucket[]

console.log(
inspect(
{
match,
winsPipeline,
rawResults
},
{ colors: true, depth: null }
)
)
// console.log(
// inspect(
// {
// match,
// winsPipeline,
// rawResults
// },
// { colors: true, depth: null }
// )
// )

// add proper ids
const resultsWithId = rawResults.map(result => ({
Expand All @@ -106,10 +106,23 @@ export const winsAggregationFunction = async (
const completionByYear = await computeCompletionByYear(db, match)

// group by years and add counts
const resultsByYear = await groupByYears(resultsWithId, db, survey, match, totalRespondentsByYear, completionByYear)

// console.log(JSON.stringify(resultsByYear, '', 2))
return resultsByYear
const resultsByYear = await groupByYears(
resultsWithId,
db,
survey,
match,
totalRespondentsByYear,
completionByYear
)

// add "fake" facet for now
const resultsWithFacets = resultsByYear.map(y => ({
...y,
facets: [{ completion: y.completion, type: 'default', id: 'default', buckets: y.buckets }]
}))

// console.log(JSON.stringify(resultsWithFacets, undefined, 2))
return resultsWithFacets
}

export const matchupsAggregationFunction = async (
Expand All @@ -134,18 +147,20 @@ export const matchupsAggregationFunction = async (
}

const matchupsPipeline = getMatchupsPipeline(match, key)
const rawResults = (await collection.aggregate(matchupsPipeline).toArray()) as MatchupAggregationResult[]

console.log(
inspect(
{
match,
matchupsPipeline,
rawResults
},
{ colors: true, depth: null }
)
)
const rawResults = (await collection
.aggregate(matchupsPipeline)
.toArray()) as MatchupAggregationResult[]

// console.log(
// inspect(
// {
// match,
// matchupsPipeline,
// rawResults
// },
// { colors: true, depth: null }
// )
// )

// add proper ids
// const resultsWithId = rawResults.map(result => ({
Expand All @@ -167,15 +182,27 @@ export const matchupsAggregationFunction = async (
const completionByYear = await computeCompletionByYear(db, match)

// group by years and add counts
const resultsByYear = await groupByYears(rawResults, db, survey, match, totalRespondentsByYear, completionByYear)
const resultsByYear = await groupByYears(
rawResults,
db,
survey,
match,
totalRespondentsByYear,
completionByYear
)

// console.log('// resultsByYear')
// console.log(JSON.stringify(resultsByYear, '', 2))
// add "fake" facet for now
const resultsWithFacets = resultsByYear.map(y => ({
...y,
facets: [{ completion: y.completion, type: 'default', id: 'default', buckets: y.buckets }]
}))

// console.log('// resultsWithFacets')
// console.log(JSON.stringify(resultsWithFacets, '', 2))

return resultsByYear
return resultsWithFacets
}


interface GroupByYearResult {
id: string | number
year: number
Expand Down Expand Up @@ -217,12 +244,12 @@ export async function groupByYears(
completion: {
total: totalRespondents,
count: completionCount,
percentage: ratioToPercentage(completionCount / totalRespondents)
percentage_survey: ratioToPercentage(completionCount / totalRespondents)
},
buckets: yearBuckets
}
return yearObject
})

return orderBy(resultsWithYears, 'year')
}
}
17 changes: 17 additions & 0 deletions api/src/compute/experience.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,20 @@ export async function computeToolsExperienceRanking(

return byTool
}

export async function computeToolsExperienceRankingYears(
db: Db,
survey: SurveyConfig,
tools: string[],
filters?: Filters
) {
let availableYears: any[] = []
for (const tool of tools) {
const toolAllYearsExperience = await computeExperienceOverYears(db, survey, tool, filters)
toolAllYearsExperience.forEach((toolYear: any) => {
availableYears.push(toolYear.year)
})
}
availableYears = _.uniq(availableYears).sort()
return availableYears
}
22 changes: 11 additions & 11 deletions api/src/compute/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,16 @@ export async function computeDefaultTermAggregationByYear(
.aggregate(getGenericPipeline(pipelineProps))
.toArray()) as ResultsByYear[]

console.log(
inspect(
{
match,
sampleAggregationPipeline: getGenericPipeline(pipelineProps),
results
},
{ colors: true, depth: null }
)
)
// console.log(
// inspect(
// {
// match,
// sampleAggregationPipeline: getGenericPipeline(pipelineProps),
// results
// },
// { colors: true, depth: null }
// )
// )

await addEntities(results)

Expand All @@ -182,7 +182,7 @@ export async function computeDefaultTermAggregationByYear(

await sortResults(results, { sort, order, values })

console.log(JSON.stringify(results, undefined, 2))
// console.log(JSON.stringify(results, undefined, 2))

return results
}
Expand Down
4 changes: 2 additions & 2 deletions api/src/compute/generic_pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ export const getGenericPipeline = (pipelineProps: PipelineProps) => {
year: `$_id.year`,
facets: 1
}
}
// { $sort: { [sort]: order } }
},
{ $sort: { year: 1 } }
]

// if (cutoff) {
Expand Down
3 changes: 2 additions & 1 deletion api/src/compute/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Filters } from '../filters'
import config from '../config'
import { computeChoicesOverYearsGraph } from './choices_over_years_graph'
import { getParticipationByYearMap } from './demographics'
import round from 'lodash/round'

export const allToolExperienceIds = [
'would_use',
Expand Down Expand Up @@ -211,7 +212,7 @@ export async function computeToolsCardinalityByUser(
const resultsWithPercentage = results.map(result => ({
cardinality: result.cardinality,
count: result.count,
percentage: result.count / numberOfRespondents * 100
percentage_survey: round(result.count / numberOfRespondents * 100, 1)
}))

// console.log(inspect({ numberOfRespondents, pipeline, results, resultsWithPercentage }, { colors: true, depth: null }))
Expand Down
8 changes: 7 additions & 1 deletion api/src/data/keys.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,10 @@ opinions:
- 1
- 2
- 3
- 4
- 4

bracket:
- round1
- round2
- round3
- combined
25 changes: 17 additions & 8 deletions api/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,8 @@ Get locale strings for a specific locale
export const getLocaleStrings = (locale: Locale, contexts?: string[]) => {
let stringFiles = locale.stringFiles

// if contexts are specified, filter strings by them
if (contexts) {
stringFiles = stringFiles.filter((sf: StringFile) => {
return contexts.includes(sf.context)
})
}

// flatten all stringFiles together
const strings = stringFiles
let strings = stringFiles
.map((sf: StringFile) => {
let { strings, prefix, context } = sf
if (strings === null) {
Expand All @@ -204,6 +197,22 @@ export const getLocaleStrings = (locale: Locale, contexts?: string[]) => {
})
.flat()

// resolve aliases
strings = strings.map((s: TranslationStringObject) => {
if (s.aliasFor) {
const s2 = strings.find(ss => ss.key === s.aliasFor)
s = { ...s2, ...s }
}
return s
})

// if contexts are specified, filter strings by them
if (contexts) {
strings = strings.filter((s: TranslationStringObject) => {
return contexts.includes(s.context)
})
}

return { strings }
}

Expand Down
20 changes: 12 additions & 8 deletions api/src/resolvers/brackets.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { getDynamicResolvers } from '../helpers'
import { winsAggregationFunction, matchupsAggregationFunction } from '../compute/brackets'
import keys from '../data/keys.yml'

export default {
BracketWins: getDynamicResolvers(
id => {
const fullPath = id.replace('__', '.')
return fullPath
},
{},
winsAggregationFunction
),
BracketWins: {
keys: () => keys.bracket,
...getDynamicResolvers(
id => {
const fullPath = id.replace('__', '.')
return fullPath
},
{},
winsAggregationFunction
)
},

BracketMatchups: getDynamicResolvers(
id => {
Expand Down
5 changes: 2 additions & 3 deletions api/src/resolvers/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ export default {
},
Feature: {
name: async ({ id }: { id: string }) => {
const features = await getEntities({ tag: 'feature' })
const features = await getEntities({ tag: 'features' })
const feature = features.find((f: Entity) => f.id === id)

return feature && feature.name
},
mdn: async ({ id }: { id: string }) => {
const features = await getEntities({ tag: 'feature' })
const features = await getEntities({ tag: 'features' })
const feature = features.find((f: Entity) => f.id === id)
if (!feature || !feature.mdn) {
return
Expand Down
4 changes: 2 additions & 2 deletions api/src/resolvers/surveys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ export default {
surveyName: (survey: SurveyConfig) => {
return survey.survey
},
bracketWins: (survey: SurveyConfig, args: ResolverArguments) => ({
bracket_wins: (survey: SurveyConfig, args: ResolverArguments) => ({
survey,
...args
}),
bracketMatchups: (survey: SurveyConfig, args: ResolverArguments) => ({
bracket_matchups: (survey: SurveyConfig, args: ResolverArguments) => ({
survey,
...args
}),
Expand Down
7 changes: 6 additions & 1 deletion api/src/resolvers/tools.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { computeToolsExperienceRanking } from '../compute'
import { computeToolsExperienceRankingYears, computeToolsExperienceRanking } from '../compute'
import { useCache } from '../caching'
import { Filters } from '../filters'
import keys from '../data/keys.yml'
Expand All @@ -10,6 +10,11 @@ import {

export default {
ToolsRankings: {
years: async (
{ survey, ids, filters }: { survey: SurveyConfig; ids: string[]; filters?: Filters },
args: any,
{ db }: RequestContext
) => useCache(computeToolsExperienceRankingYears, db, [survey, ids, filters]),
experience: async (
{ survey, ids, filters }: { survey: SurveyConfig; ids: string[]; filters?: Filters },
args: any,
Expand Down
Loading

0 comments on commit 645945d

Please sign in to comment.