<commit_before>local geolyzer = require('component').geolyzer;
dofile 'tcp.lua'; -- todo: properly package this stuff
dofile 'trackPosition.lua';

function weightedAverage(n1, w1, n2, w2)
  return (n1*w1 + n2*w2)/(w1 + w2);
end

function scanVolume(x, z, y, w, d, h, times)
  -- default to 0 (which is true in lua)
  times = (times - 1) or 0;

  local pos = getPosition();
  local result = {
    x = x + pos.x,
    y = y + pos.y,
    z = z + pos.z,
    w=w,
    d=d,
    data=geolyzer.scan(x, z, y, w, d, h)};

  local weight = 1;
  for i = 1, times do

    local newScan = geolyzer.scan(x, z, y, w, d, h);

    -- average all data points using weights
    for j = 1, result.data.n do
      result.data[j] = weightedAverage(result.data[j], weight, newScan[j], 1);
    end

    weight = weight + 1;

  end
  tcpWrite({['map data']=result});
end

function scanPlane(y, times)
  times = (times - 1) or 0;
  for x = -32, 32 do
    scanVolume(x, -32, y, 1, 64, 1, times);
  end
end<commit_msg>fixed the default value times parameter, scanPlane now scans one additional row it was missing before<commit_after>local geolyzer = require('component').geolyzer;
dofile 'tcp.lua'; -- todo: properly package this stuff
dofile 'trackPosition.lua';

function weightedAverage(n1, w1, n2, w2)
  return (n1*w1 + n2*w2)/(w1 + w2);
end

function scanVolume(x, z, y, w, d, h, times)
  -- default to 0 (which is true in lua)
  if times then
    times = times - 1;
  else
    times = 0;
  end

  local pos = getPosition();
  local result = {
    x = x + pos.x,
    y = y + pos.y,
    z = z + pos.z,
    w=w,
    d=d,
    data=geolyzer.scan(x, z, y, w, d, h)};

  local weight = 1;
  for i = 1, times do

    local newScan = geolyzer.scan(x, z, y, w, d, h);

    -- average all data points using weights
    for j = 1, result.data.n do
      result.data[j] = weightedAverage(result.data[j], weight, newScan[j], 1);
    end

    weight = weight + 1;

  end
  tcpWrite({['map data']=result});
end

function scanPlane(y, times)
  for x = -32, 32 do
    scanVolume(x, -32, y, 1, 64, 1, times);
  end
  -- max shape volume is 64, but we can scan from -32 to 32, inclusive
  -- that's 65, so we have one row we miss in the previous loop to scan
  scanVolume(-32, 32, y, 64, 1, 1, times);
end
{'fraction_non_alphanumeric': 0.14374170720919946, 'fraction_numerical': 0.03272888102609465, 'mean_word_length': 2.77, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4776521', 'n_tokens_mistral': 929, 'n_tokens_neox': 854, 'n_words': 304}