<commit_before>--
--  layout_funktionen.lua
--  speedata publisher
--
--  Copyright 2010-2011 <NAME>.
--  See file COPYING in the root directory for license info.


file_start("layout_functions.lua")

module(...,package.seeall)

local function aktuelle_seite(  )
  publisher.setup_page()
  return  tex.count[0]
end

local function current_row(dataxml,...)
  publisher.setup_page()
  return publisher.current_grid:current_row(select(1,...))
end

--- Get the page number of a marker
local function pagenumber(dataxml,...)
  local m = publisher.markers[select(1,...)]
  if m then
    return m.page
  else
    return nil
  end
end

local function current_column(dataxml,...)
  publisher.setup_page()
  return publisher.current_grid:current_column(select(1,...))
end

local function alternating(dataxml, ... )
  local alt_type = select(1,...)
  if not publisher.alternating[alt_type] then
    publisher.alternating[alt_type] = 1
  else
    publisher.alternating[alt_type] = math.fmod( publisher.alternating[alt_type], select("#",...) - 1 ) + 1
  end
  return select(publisher.alternating[alt_type] + 1 ,...)
end

local function reset_alternating( dataxml,... )
  local alt_type = select(1,...)
  publisher.alternating[alt_type] = 0
end

local function anzahl_datensaetze(dataxml,d)
  local count = 0
  for i=1,#d do
    if type(d[i]) == 'table' then
      count = count + 1
    end
  end
  return count
end

local function number_of_columns(dataxml,...)
  publisher.setup_page()
  return publisher.current_grid:number_of_columns(select(1,...))
end

--- Merge numbers like '1-5, 8, 9,10,11' into '1-5, 8-10'
-- Very simple implementation, not to be used in other cases than 1-3!
local function merge_pagenumbers(dataxml,arg )
  local a,b
  _,_, a, b = string.find(arg,"^(%d).(%d)$")
  if a == b then return a end
  return arg
end

local function anzahl_zeilen(dataxml,...)
  publisher.setup_page()
  return publisher.current_grid:number_of_rows(select(1,...))
end

local function anzahl_seiten( dataxml,... )
  dateiname=select(1,...)
  local img = publisher.imageinfo(dateiname)
  return img.img.pages
end

local function bildbreite(dataxml, ... )
  dateiname=select(1,...)<commit_msg>Bugfix for experimental function merge pagenumbers<commit_after>--
--  layout_funktionen.lua
--  speedata publisher
--
--  Copyright 2010-2011 <NAME>.
--  See file COPYING in the root directory for license info.


file_start("layout_functions.lua")

module(...,package.seeall)

local function aktuelle_seite(  )
  publisher.setup_page()
  return  tex.count[0]
end

local function current_row(dataxml,...)
  publisher.setup_page()
  return publisher.current_grid:current_row(select(1,...))
end

--- Get the page number of a marker
local function pagenumber(dataxml,...)
  local m = publisher.markers[select(1,...)]
  if m then
    return m.page
  else
    return nil
  end
end

local function current_column(dataxml,...)
  publisher.setup_page()
  return publisher.current_grid:current_column(select(1,...))
end

local function alternating(dataxml, ... )
  local alt_type = select(1,...)
  if not publisher.alternating[alt_type] then
    publisher.alternating[alt_type] = 1
  else
    publisher.alternating[alt_type] = math.fmod( publisher.alternating[alt_type], select("#",...) - 1 ) + 1
  end
  return select(publisher.alternating[alt_type] + 1 ,...)
end

local function reset_alternating( dataxml,... )
  local alt_type = select(1,...)
  publisher.alternating[alt_type] = 0
end

local function anzahl_datensaetze(dataxml,d)
  local count = 0
  for i=1,#d do
    if type(d[i]) == 'table' then
      count = count + 1
    end
  end
  return count
end

local function number_of_columns(dataxml,...)
  publisher.setup_page()
  return publisher.current_grid:number_of_columns(select(1,...))
end

--- Merge numbers like '1-5, 8, 9,10,11' into '1-5, 8-10'
-- Very simple implementation, not to be used in other cases than 1-3!
local function merge_pagenumbers(dataxml,arg )
  local a,b
  _,_, a, b = unicode.utf8.find(arg,"^(%d+).(%d+)$")
  if a == b then return a end
  return arg
end

local function anzahl_zeilen(dataxml,...)
  publisher.setup_page()
  return publisher.current_grid:number_of_rows(select(1,...))
end

local function anzahl_seiten( dataxml,... )
  dateiname=select(1,...)
  local img = publisher.imageinfo(dateiname)
  return img.img.pages
end

local function bildbreite(dataxml, ... )
  dateiname=select(1,...)
{'fraction_non_alphanumeric': 0.1368898978433598, 'fraction_numerical': 0.0188422247446084, 'mean_word_length': 3.8047982551799344, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 22}, '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': '1352823', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1498, 'n_words': 376}