<commit_before>/**
 * @overview Layouter Lib
 * @module layouter
 * @author <NAME>
 * @version 0.1
 * @description Positions Images on Layouts
 * @memberof resilienz
 * @requires module:database
 * @requires module:fs
 * @requires module:child_process
 * @requires bin:imagemagick
 */
var fs = require('fs')
var mkdirp = require('mkdirp')
const execSync = require('child_process').execSync
function Layouter (layoutpath, imagepath, pagespath, database) {
  var self = {}
  self.imagepath = imagepath
  self.database = database
  self.pagespath = pagespath
  self.layoutpath = layoutpath
  self.createPage = createPage
  self.rescaleImage = rescaleImage
  self.getPage = getPage
  return self
}
function rescaleImage (image, x, y, width, height, callback) {
  var cmd = 'convert ' + image + ' -resize ' + width + 'x' + height + '!' + '+' + x + '+' + y + ' ' + image
  var output = execSync(cmd)
  if (output) {
    callback(output)
  } else {
    callback(null)
  }
}
function createPage (actionid, language, page, callback) {
  var self = this
  mkdirp(self.pagespath + '/' + actionid + '/', function (error) {
    if (error) {
      callback(error)
    } else {
      self.database.getLayoutInfo(actionid, page, function (error, information) {
        if (error) {
          callback(error)
        } else {
          var cmd = ''
          var output = ''
          if (page === 2) {
            cmd = 'cp ' + self.layoutpath + '/' + language + '/02_inhalt.png' + self.pagespath + '/' + actionid + '/' + page + '_two.png'
            output = execSync(cmd)
          } else if (page === 44) {
            cmd = 'cp ' + '/' + language + '/16_ruecken.png' + self.pagespath + '/' + actionid + '/' + page + '.png'
            output = execSync(cmd)
          } else {
            for (var i = 0; i < information.length; i++) {
              var info = information[i]
              if (info.image === '') {
                info.image = self.layoutpath + '/placeholder.png'
              } else {
                info.image = self.imagepath + '/' + info.image
              }
              var target = ''
              if (page === 1 || page === '1') {
                target = self.pagespath + '/' + actionid + '/' + page + '.png'
              } else {
                target = self.pagespath + '/' + actionid + '/' + page + '_two.png'
              }
              var bg = ''
              if (i === 0) {
                bg = self.layoutpath + '/' + language + '/' + info.background
              } else {
                bg = target
              }

              cmd = ''
              if (info.spin !== 0) {
                cmd = 'composite -geometry \'' + info.width + 'x' + info.height + '+' + info.x + '+' + info.y + '\' ' +
                '-rotate ' + info.spin +
                ' ' + info.image + ' ' + bg + ' ' + target
              } else {
                cmd = 'composite -geometry \'' + info.width + 'x' + info.height + '+' + info.x + '+' + info.y + '\' ' + info.image + ' ' + bg + ' ' + target
              }
              console.log(cmd)
              output = execSync(cmd, true)
              if (output.stderr !== '' || output.stdout !== '') {
                console.log(output.stdout)
                console.error(output.stderr)
                callback(null, false)
              }
            }
          }
          if (output) {
            callback(null, false)
          } else {<commit_msg>logging pt2<commit_after>/**
 * @overview Layouter Lib
 * @module layouter
 * @author <NAME>
 * @version 0.1
 * @description Positions Images on Layouts
 * @memberof resilienz
 * @requires module:database
 * @requires module:fs
 * @requires module:child_process
 * @requires bin:imagemagick
 */
var fs = require('fs')
var mkdirp = require('mkdirp')
const execSync = require('child_process').execSync
function Layouter (layoutpath, imagepath, pagespath, database) {
  var self = {}
  self.imagepath = imagepath
  self.database = database
  self.pagespath = pagespath
  self.layoutpath = layoutpath
  self.createPage = createPage
  self.rescaleImage = rescaleImage
  self.getPage = getPage
  return self
}
function rescaleImage (image, x, y, width, height, callback) {
  var cmd = 'convert ' + image + ' -resize ' + width + 'x' + height + '!' + '+' + x + '+' + y + ' ' + image
  var output = execSync(cmd)
  if (output) {
    callback(output)
  } else {
    callback(null)
  }
}
function createPage (actionid, language, page, callback) {
  var self = this
  mkdirp(self.pagespath + '/' + actionid + '/', function (error) {
    if (error) {
      callback(error)
    } else {
      self.database.getLayoutInfo(actionid, page, function (error, information) {
        if (error) {
          callback(error)
        } else {
          var cmd = ''
          var output = ''
          if (page === 2) {
            cmd = 'cp ' + self.layoutpath + '/' + language + '/02_inhalt.png' + self.pagespath + '/' + actionid + '/' + page + '_two.png'
            output = execSync(cmd)
          } else if (page === 44) {
            cmd = 'cp ' + '/' + language + '/16_ruecken.png' + self.pagespath + '/' + actionid + '/' + page + '.png'
            output = execSync(cmd)
          } else {
            for (var i = 0; i < information.length; i++) {
              var info = information[i]
              if (info.image === '') {
                info.image = self.layoutpath + '/placeholder.png'
              } else {
                info.image = self.imagepath + '/' + info.image
              }
              var target = ''
              if (page === 1 || page === '1') {
                target = self.pagespath + '/' + actionid + '/' + page + '.png'
              } else {
                target = self.pagespath + '/' + actionid + '/' + page + '_two.png'
              }
              var bg = ''
              if (i === 0) {
                bg = self.layoutpath + '/' + language + '/' + info.background
              } else {
                bg = target
              }

              cmd = ''
              if (info.spin !== 0) {
                cmd = 'composite -geometry \'' + info.width + 'x' + info.height + '+' + info.x + '+' + info.y + '\' ' +
                '-rotate ' + info.spin +
                ' ' + info.image + ' ' + bg + ' ' + target
              } else {
                cmd = 'composite -geometry \'' + info.width + 'x' + info.height + '+' + info.x + '+' + info.y + '\' ' + info.image + ' ' + bg + ' ' + target
              }
              console.log(cmd)
              output = execSync(cmd, true)
              if (output.stderr || output.stdout) {
                console.log(output.stdout)
                console.error(output.stderr)
                callback(null, false)
              }
            }
          }
          if (output) {
            callback(null, false)
          } else {
{'fraction_non_alphanumeric': 0.15281030444964872, 'fraction_numerical': 0.004244730679156909, 'mean_word_length': 1.6200153374233128, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '2919863', 'n_tokens_mistral': 2068, 'n_tokens_neox': 2003, 'n_words': 477}