2016-06-29 10:27:04 +00:00
|
|
|
import React from 'react'
|
|
|
|
import parameters from '../load-parameters'
|
|
|
|
import deepAssign from 'deep-assign'
|
|
|
|
|
|
|
|
let
|
|
|
|
groupedByVariableName = parameters
|
|
|
|
.filter(p => p && p.variable)
|
|
|
|
.reduce((acc, p) => {
|
|
|
|
let variableName = p.variable
|
|
|
|
if (acc[variableName])
|
|
|
|
acc[variableName].push(p)
|
|
|
|
else
|
|
|
|
acc[variableName] = [p]
|
|
|
|
return acc
|
|
|
|
}, {}),
|
|
|
|
|
|
|
|
conflictingTags = (tags1, tags2) =>
|
|
|
|
Object.keys(tags1).reduce((conflicts, k) => {
|
|
|
|
if (typeof tags2[k] != 'undefined' && tags2[k] !== tags1[k])
|
|
|
|
conflicts.push(k)
|
|
|
|
return conflicts
|
|
|
|
}, []),
|
|
|
|
|
|
|
|
groupedMergedVariables =
|
|
|
|
Object.keys(groupedByVariableName)
|
|
|
|
.reduce((list, name) => {
|
|
|
|
let items = groupedByVariableName[name]
|
|
|
|
/* Les items sont des fragments de variables.
|
|
|
|
Les premiers fragments vont être fusionnés dans les suivants,
|
|
|
|
sauf s'il introduit un écrasement d'un tag */
|
|
|
|
let variableList = items.slice(1).reduce((mergedItems, item) => {
|
|
|
|
let mergedItem = mergedItems.reduce((final, itemBefore) => {
|
|
|
|
let oups = conflictingTags(itemBefore.tags, item.tags)
|
|
|
|
//console.log('conflicts for ', itemBefore.tags, item.tags)
|
|
|
|
return oups.length ? item : deepAssign({}, item, itemBefore)
|
|
|
|
},
|
|
|
|
item)
|
|
|
|
mergedItems.push(mergedItem)
|
|
|
|
return mergedItems
|
|
|
|
},
|
|
|
|
[items[0]])
|
|
|
|
return [...variableList, ...list]
|
2016-06-29 16:18:28 +00:00
|
|
|
}, []),
|
|
|
|
|
|
|
|
tagFrequency =
|
|
|
|
groupedMergedVariables
|
|
|
|
.reduce((stats, variable) => {
|
|
|
|
Object.keys(variable.tags).map(
|
|
|
|
k => {
|
|
|
|
stats[k] = stats[k] || {number: 0, choices: new Set()}
|
|
|
|
stats[k].number = stats[k].number + 1
|
|
|
|
stats[k].choices.add(variable.tags[k])
|
|
|
|
}
|
|
|
|
)
|
|
|
|
return stats
|
|
|
|
}
|
|
|
|
, {})
|
|
|
|
|
|
|
|
|
2016-06-29 16:57:56 +00:00
|
|
|
console.log('YOUYOU', tagFrequency)
|
2016-06-29 10:27:04 +00:00
|
|
|
|
|
|
|
export default class Explorer extends React.Component {
|
|
|
|
render() {
|
2016-06-29 16:57:56 +00:00
|
|
|
return (
|
|
|
|
<ul id="tags">
|
|
|
|
{Object.keys(tagFrequency).map(tag =>
|
|
|
|
<li key={tag}>{tag}</li>
|
|
|
|
)}
|
|
|
|
</ul>
|
|
|
|
)
|
2016-06-29 10:27:04 +00:00
|
|
|
}
|
|
|
|
}
|