<commit_before># Description:
#   Generate a chart image
#
# Dependencies:
#   "chart.js": "^1.0.1-beta.2"
#   "phantomjs": "^1.9.12"
#
# Commands:
#   hubot chart <type> <data> -- Generate a chart image
#
# Author:
#   yulii

fs   = require('fs')
path = require('path')
ChartImage = require('../module/chart_image')

module.exports = (robot) ->

  hubot_url = () ->
    server = robot.server.address()
    process.env.HEROKU_URL ? "http://#{server.address}:#{server.port}"

  robot.respond /chart\s+(\w+)\s+(.+)/i, (msg) ->
    type = msg.match[1]
    data = msg.match[2]

    msg.send "Please wait a few seconds. Now creating..."
    chart = new ChartImage()
    chart.generate type, data, (err, stdout, stderr) ->
      if err
        msg.send "#{err.name}: #{err.message}"
      filename = encodeURIComponent(chart.filename)
      msg.send "#{hubot_url()}/hubot/charts/#{filename}"

  ## Get an image from `/tmp` dir
  robot.router.get "/hubot/charts/:key", (req, res) ->
    tmp = path.join(__dirname, '..', 'tmp', req.params.key)
    fs.exists tmp, (exists) ->
      if exists
        fs.readFile tmp,(err,data) ->
          res.writeHead(200, { 'Content-Type': 'image/png' })
          res.end(data)
      else
        res.status(404).send('Not found')
<commit_msg>extend hubot<commit_after># Description:
#   Generate a chart image
#
# Dependencies:
#   "chart.js": "^1.0.1-beta.2"
#   "phantomjs": "^1.9.12"
#
# Commands:
#   hubot chart <type> <data> -- Generate a chart image
#
# Author:
#   yulii

fs   = require('fs')
path = require('path')
ChartImage = require('../module/chart_image')

module.exports = (robot) ->

  robot.helper =
    url: () ->
      server = robot.server.address()
      process.env.HEROKU_URL ? "http://#{server.address}:#{server.port}"

  #hubot_url = () ->
  #  server = robot.server.address()
  #  process.env.HEROKU_URL ? "http://#{server.address}:#{server.port}"

  robot.respond /chart\s+(\w+)\s+(.+)/i, (msg) ->
    type = msg.match[1]
    data = msg.match[2]

    msg.send "Please wait a few seconds. Now creating..."
    chart = new ChartImage()
    chart.generate type, data, (err, stdout, stderr) ->
      if err
        msg.send "#{err.name}: #{err.message}"
      filename = encodeURIComponent(chart.filename)
      msg.send "#{robot.helper.url()}/hubot/charts/#{filename}"

  ## Get an image from `/tmp` dir
  robot.router.get "/hubot/charts/:key", (req, res) ->
    tmp = path.join(__dirname, '..', 'tmp', req.params.key)
    fs.exists tmp, (exists) ->
      if exists
        fs.readFile tmp,(err,data) ->
          res.writeHead(200, { 'Content-Type': 'image/png' })
          res.end(data)
      else
        res.status(404).send('Not found')

{'fraction_non_alphanumeric': 0.1935483870967742, 'fraction_numerical': 0.011865035224323322, 'mean_word_length': 2.736842105263158, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 22, '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': '878730', 'n_tokens_mistral': 982, 'n_tokens_neox': 965, 'n_words': 199}