<commit_before>import React from 'react'
import echarts from 'echarts'
import _ from 'lodash'
import fetch from 'isomorphic-fetch'

import styles from './AbsoluteTrend.css'
import Loading from '../Loading'

import { autobind } from 'react-decoration'
import { checkStatus, serverAddress } from '../../util'

const getOption = ({ topic }) => (
  {
    title: {
      text: '主题分析'
    },
    tooltip: {
      trigger: 'item',
      triggerOn: 'mousemove'
    },
    series: [
      {
        type: 'sankey',
        layout: 'none',
        data: topic.nodes,
        links: topic.links,
        itemStyle: {
          normal: {
            borderWidth: 1,
            borderColor: '#aaa'
          }
        },
        lineStyle: {
          normal: {
            color: 'source',
            curveness: 0.5
          }
        }
      }
    ]
  }
)

const transformData = (rawData) => {
  const links = []
  const nodes = _.map(rawData, (value, index) => (`主题${index + 1}`))

  rawData.forEach((index, topic) => {
    nodes.concat(...topic)
    const source = `主题${index + 1}`
    topic.forEach((word) => {
      links.push({
        source,
        target: word,
        value: 1
      })
    })
  })
  console.log(links)
  console.log(nodes)
  return {links, nodes}
}

export default class AbsoluteTrend extends React.Component {
  constructor () {
    super()
    this.state = {
      topic: []
    }
    fetch(`${serverAddress}/lda-topic`, { method: 'GET' })
      .then(checkStatus)
      .then((res) => (res.json()))
      .then((topic) => this.setState({topic: transformData(topic)}))
  }

  componentDidMount () {
    this.myChart = echarts.init(this.refs.Topic)
  }

  @autobind
  drawTopic () {
    const option = getOption(this.state)
    this.myChart.setOption(option)
  }

  render () {
    return <div
      className={styles.container}
      ref='Topic'>
      {_.isEmpty(this.state.trend) && _.isEmpty(this.state.topic)
        ? <Loading />
        : this.drawTopic()}
    </div>
  }
}<commit_msg>finish topic analize<commit_after>import React from 'react'
import echarts from 'echarts'
import _ from 'lodash'
import fetch from 'isomorphic-fetch'

import styles from './AbsoluteTrend.css'
import Loading from '../Loading'

import { autobind } from 'react-decoration'
import { checkStatus, serverAddress } from '../../util'

const getOption = ({ topic }) => (
  {
    title: {
      text: '主题分析',
      left: 100
    },
    tooltip: {
      trigger: 'item',
      triggerOn: 'mousemove'
    },
    series: [
      {
        type: 'sankey',
        layout: 'none',
        data: topic.nodes,
        links: topic.links,
        itemStyle: {
          normal: {
            borderWidth: 1,
            borderColor: '#aaa'
          }
        },
        lineStyle: {
          normal: {
            color: 'source',
            curveness: 0.5
          }
        }
      }
    ]
  }
)

const transformData = (rawData) => {
  const links = []
  const nodes = _.uniq(_.concat(_.map(rawData, (value, index) => (`主题${index + 1}`)), ...rawData))
  rawData.forEach((topic, index) => {
    const source = `主题${index + 1}`
    topic.forEach((word) => {
      links.push({
        source,
        target: word,
        value: 1
      })
    })
  })

  return {
    links,
    nodes: nodes.map((node) => ({name: node}))
  }
}

export default class AbsoluteTrend extends React.Component {
  constructor () {
    super()
    this.state = {
      topic: []
    }
    fetch(`${serverAddress}/lda-topic`, { method: 'GET' })
      .then(checkStatus)
      .then((res) => (res.json()))
      .then((topic) => this.setState({topic: transformData(topic)}))
  }

  componentDidMount () {
    this.myChart = echarts.init(this.refs.Topic)
  }

  @autobind
  drawTopic () {
    const option = getOption(this.state)
    console.log(JSON.stringify(this.state.topic.links))
    console.log(JSON.stringify(this.state.topic.nodes))
    this.myChart.setOption(option)
  }

  render () {
    return <div
      className={styles.container}
      ref='Topic'>
      {_.isEmpty(this.state.trend) && _.isEmpty(this.state.topic)
        ? <Loading />
        : this.drawTopic()}
    </div>
  }
}
{'fraction_non_alphanumeric': 0.15699904122722916, 'fraction_numerical': 0.003595397890699904, 'mean_word_length': 2.088823094004441, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6429145', 'n_tokens_mistral': 1375, 'n_tokens_neox': 1350, 'n_words': 273}