<commit_before>-- Copyright 2015 Boundary, Inc.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
--    http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

local framework = require('framework')
local Plugin = framework.Plugin
local DataSource = framework.DataSource
local Accumulator = framework.Accumulator
local mysql = require('mysql')
local parseValue = framework.util.parseValue
local sum = framework.util.sum
local merge = framework.table.merge

local params = framework.params

local acc = Accumulator:new()

local MySQLDataSource = DataSource:extend()
function MySQLDataSource:initialize(opts)
  self.host = opts.host or 'localhost'
  self.port = opts.port or '3306'
  self.user = opts.user or 'root'
  self.password = <PASSWORD>
  self.logging = false
  self.client = mysql.createClient(self)
end

function MySQLDataSource:fetch(context, callback, params)
  self.client:query('SHOW /*!50002 GLOBAL */ STATUS', function (err, status, fields) 
    if err then
      self:emit('error', err.message)
    else
      self.client:query('SHOW GLOBAL VARIABLES', function (err, variables, fields)
        if (err) then
          self:emit('error', err.message)
        else
          local result = merge(status, variables)
          callback(result)
        end
      end)
    end
  end)
end

local function parse(data)
  local result = { curr = {}, diff = {}}
  for _, row in ipairs(data) do
    local value = tonumber(row.Value)
    if value then
      result.diff[row.Variable_name] = acc:accumulate(row.Variable_name, value)
      result.curr[row.Variable_name] = value
    end
  end
  return result
end

local ds = MySQLDataSource:new(params)
<commit_msg>Minor changes<commit_after>-- Copyright 2015 Boundary, Inc.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
--    http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

local framework = require('framework')
local Plugin = framework.Plugin
local DataSource = framework.DataSource
local Accumulator = framework.Accumulator
local mysql = require('mysql')
local parseValue = framework.util.parseValue
local sum = framework.util.sum
local merge = framework.table.merge

local params = framework.params

local acc = Accumulator:new()

local MySQLDataSource = DataSource:extend()
function MySQLDataSource:initialize(opts)
  self.host = opts.host or 'localhost'
  self.port = opts.port or '3306'
  self.user = opts.user or 'root'
  self.password = opts.password
  self.logging = false
end

function MySQLDataSource:fetch(context, callback, params)
  if not self.client then
    self.client = mysql.createClient(self)
  end
  self.client:query('SHOW /*!50002 GLOBAL */ STATUS', function (err, status, fields) 
    if err then
      self:emit('error', err.message)
    else
      self.client:query('SHOW GLOBAL VARIABLES', function (err, variables, fields)
        if (err) then
          self:emit('error', err.message)
        else
          local result = merge(status, variables)
          callback(result)
        end
      end)
    end
  end)
end

local function parse(data)
  local result = { curr = {}, diff = {}}
  for _, row in ipairs(data) do
    local value = tonumber(row.Value)
    if value then
      result.diff[row.Variable_name] = acc:accumulate(row.Variable_name, value)
      result.curr[row.Variable_name] = value
    end
  end
  return result
end

local ds = MySQLDataSource:new(params)

{'fraction_non_alphanumeric': 0.09903778455761558, 'fraction_numerical': 0.007979347570992725, 'mean_word_length': 3.51005291005291, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '992764', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1190, 'n_words': 424}