text:
from __future__ import print_function
from __future__ import division

from pdb import set_trace
from os import environ, getcwd
from os import walk
from os import remove as rm
from os.path import expanduser
from pdb import set_trace
import sys

# Update PYTHONPATH
HOME = expanduser('~')
axe = HOME + '/git/axe/axe/'  # AXE
pystat = HOME + '/git/pystats/'  # PySTAT
cwd = getcwd()  # Current Directory
sys.path.extend([axe, pystat, cwd])

from pdb import set_trace
from random import uniform, randint, shuffle
import csv

from Planners.XTREE.lib import *
from smote import *
from methods1 import *
import numpy as np

def genTable(tbl, rows):
  name = str(randint(0, 1000))
  header = [h.name for h in tbl.headers[:-1]]
  with open('tmp0.csv', 'w') as csvfile:
    writer = csv.writer(csvfile, delimiter=',')
    writer.writerow(header)
    for el in rows:
      writer.writerow(el[:-1])
  new = createTbl(['tmp0.csv'])
  rm('tmp0.csv')
  return new

class changes():

  def __init__(self):
    self.log = {}

  def save(self, name=None, old=None, new=None):
    if not old == new:
      self.log.update({name: (old, new)})

class deltas():

  def __init__(self, row, myTree, majority=True):
    self.row = row
    self.loc = drop(row, myTree)
    self.contrastSet = None
    self.newRow = row
    self.score = self.scorer(self.loc)
    self.change = []

  def scorer(self, node):
    return np.mean([r.cells[-2] for r in node.rows])

  def createNew(self, stuff, keys, N=1):
    newElem = []
    tmpRow = self.row
    for _ in xrange(N):
      C = changes()
      for s in stuff:
        lo, hi = s[1]
        pos = keys[s[0].name]
        old = tmpRow.cells[pos]
        new = float(max(lo, min(hi, lo + rand() * abs(hi - lo))))
        C.save(name=s[0].name, old=old, new=new)
        tmpRow.cells[pos] = new
      self.change.append(C.log)
      newElem.append(tmpRow)
    return newElem

  def patches(self, keys, N_Patches=10):
    # Search for the best possible contrast set and apply it
    isles = []
    newRow = self.row
    for stuff in self.contrastSet:
      isles.append(self.createNew(stuff, keys, N=N_Patches))
    return isles, self.change

class store():

  def __init__(self, node, majority=False):
    self.node = node
    self.dist = 0
    self.DoC = 0
    self.majority = majority
    self.score = self.scorer(node)

  def minority(self, node):
    unique = list(set([r.cells[-1] for r in node.rows]))
    counts = len(unique) * [0]
#     set_trace()
    for n in xrange(len(unique)):
      for d in [r.cells[-1] for r in node.rows]:
        if unique[n] == d:
          counts[n] += 1
    return unique, counts

  def scorer(self, node):
    if self.majority:
      unq, counts = self.minority(node)
      id, maxel = 0, 0
      for i, el in enumerate(counts):
        if el > maxel:
          maxel = el
          id = i
      return np.mean([r.cells[-2]
                      for r in node.rows if r.cells[-1] == unq[id]])
    else:
      return np.mean([r.cells[-2] for r in node.rows])

class xtrees():

  "Treatments"

  def __init__(self, train=None, test=None, test_DF=None,
               verbose=True, smoteit=True, bin=False, majority=True):
    self.train, self.test = train, test
    try:
      self.train_DF = createTbl(train, _smote=False, isBin=bin)
    except:
      set_trace()
    if not test_DF:
      self.test_DF = createTbl(test, isBin=bin)
    else:
      self.test_DF = test_DF
    self.verbose, self.smoteit = verbose, smoteit
    self.mod, self.keys = [], self.getKey()
    self.majority = majority
    t = discreteNums(
        createTbl(
            train, isBin=bin), map(
            lambda x: x.cells, self.train_DF._rows))
    self.myTree = tdiv(t)
#     showTdiv(self.myTree)
#     set_trace()

  def flatten(self, x):
    """
    Takes an N times nested list of list like [[a,b],[c, [d, e]],[f]]
    and returns a single list [a,b,c,d,e,f]
    """
    result = []
    for el in x:
      if hasattr(el, "__iter__") and not isinstance(el, basestring):
        result.extend(self.flatten(el))
      else:
        result.append(el)
    return result

  def leaves(self, node):
    """
    Returns all terminal nodes.
    """
    L = []
    if len(node.kids) > 1:
      for l in node.kids:
        L.extend(self.leaves(l))
      return L
    elif len(node.kids) == 1:
      return [node.kids]
    else:
      return [node]

  def scorer(self, node):
    """
    Score an leaf node
    """
    return np.mean([r.cells[-2] for r in node.rows])

  def isBetter(self, me, others):
    """
    Compare [me] with a bunch of [others,...], return the best person
    """
    for notme in others:
      #       if '%.2f' % self.scorer(notme) == 0:
      if self.scorer(notme) < self.scorer(me):
        return True, notme.branch
      else:
        return False, []

  def attributes(self, nodes):
    """
    A method to handle unique branch variables that characterizes
    a bunch of nodes.
    """
    xx = []
    attr = []

    def seen(x):
      xx.append(x)
    for node in nodes:
      if not node.node.branch in xx:
        attr.append(node.node.branch)
        seen(node.node.branch)
    return attr

  def finder2(self, node, alpha=0.5, pos='far'):
    """
    finder2 is a more elegant version of finder that performs a search on
    the entire tree to find leaves which are better than a certain 'node'
    """

    euclidDist = lambda a, b: ((b[0] - a[0]) ** 2 + (b[1] - a[1]) ** 2) ** 0.5
    midDist = lambda a, b: abs(sum(b) - sum(a)) / 2
    vals = []
    current = store(node, majority=self.majority)  # Store current sample
    while node.lvl > -1:
      node = node.up  # Move to tree root

    # Get all the terminal nodes
    leaves = self.flatten([self.leaves(_k) for _k in node.kids])

    for leaf in leaves:
      l = store(leaf, majority=self.majority)
      for b in leaf.branch:
        dist = []
        if b[0] in [bb[0] for bb in current.node.branch]:
          l.DoC += 1
          dist.extend([midDist(b[1], bb[1])
                       for bb in current.node.branch if b[0] == bb[0]])
      l.dist = np.sqrt(np.sum(dist))
      vals.append(l)
    vals = sorted(vals, key=lambda F: F.DoC, reverse=False)
    best = [v for v in vals if v.score < alpha * current.score]
    if not len(best) > 0:
      best = vals

    attr = {}
    bests = {}
    unq = sorted(list(set([v.DoC for v in best])))  # A list of all DoCs..
    for dd in unq:
      bests.update(
          {dd: sorted([v for v in best if v.DoC == dd], key=lambda F: F.score)})
      attr.update({dd: self.attributes(
          sorted([v for v in best if v.DoC == dd], key=lambda F: F.score))})

    if pos == 'near':
      return attr[unq[-1]][0]
    elif pos == 'far':
      return attr[unq[0]][-1]
    elif pos == 'Best':
      return self.attributes([sorted(best, key=lambda F: F.score)[0]])[0]

  def getKey(self):
    keys = {}
    for i in xrange(len(self.test_DF.headers)):
      keys.update({self.test_DF.headers[i].name[1:]: i})
    return keys

  def main(self, justDeltas=False, which='near'):
    # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    # Main
    # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    Change = []
    testCase = self.test_DF._rows
    for tC in testCase:
      node = deltas(tC, self.myTree)  # A delta instance for the rows
      node.contrastSet = [self.finder2(node.loc, pos=which)]
      patch, change = node.patches(self.keys, N_Patches=1)
      Change.extend(change)
      self.mod.extend(patch[0])
    if justDeltas:
      return Change
    else:
      return genTable(self.test_DF, rows=[k.cells for k in self.mod])

def _planningTest():
  # Test contrast sets
  n = 0
  Dir = 'Data/Jureczko/'
  one, two = explore(Dir)
  # Training data
  _ = xtrees(train=one[n],
             test=two[n],
             verbose=True,
             smoteit=False).main()

  # <<<<<<<<<<< Debug >>>>>>>>>>>>>>>
  set_trace()

if __name__ == '__main__':
  _planningTest()


text:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:osgi="http://www.springframework.org/schema/osgi"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                      http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">

	<osgi:service id="orderOSGiService" ref="orderService"
		interface="net.martenscs.order.OrderService">
	</osgi:service>

</beans>

redpajama_set_name: RedPajamaGithub


text:
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.getSiteInformation = getSiteInformation;

var _os = _interopRequireDefault(require("os"));

var _package = require("../../../package.json");

var _defaultPersister = _interopRequireDefault(require("./graphql/defaultPersister"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} // Import to demonstrate server-based site settings

// Read environment
require('dotenv').load();

const googleMapsJavascriptAPI = process.env.GOOGLE_MAPS_JAVASCRIPT_API;
if (googleMapsJavascriptAPI == null || typeof googleMapsJavascriptAPI !== 'string')
throw new Error(
'rb-example-inscriptio-webapp requires the environment variable GOOGLE_MAPS_JAVASCRIPT_API to be set');

const siteInformation = {
  artifact_id: _defaultPersister.default.uuidNull(),
  inEditingMode: false,
  isMaDesignerDisabled: true,
  siteConfiguration: {
    webapp: {
      api: { googleMapsJavascriptAPI },
      rebarDemo: { version: _package.version, OSType: _os.default.type(), OSHostName: _os.default.hostname(), OSFreeMem: _os.default.freemem() } },

    server: {},
    builderClient: {} } };

async function getSiteInformation(req, res) {
  return siteInformation;
}
//# sourceMappingURL=siteSettings.js.map


text:
<?php

namespace spec\CultureKings\Afterpay\Model\Merchant;

use CultureKings\Afterpay\Model\Merchant\Contact;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

/**
 * Class ContactSpec
 * @package spec\CultureKings\Afterpay\Model
 * @mixin Contact
 */
class ContactSpec extends ObjectBehavior
{
    function it_is_initializable()
    {
        $this->shouldHaveType(Contact::class);
    }

    function its_name_is_mutable()
    {
        $this->getName()->shouldReturn(null);
        $this->setName('Joe Consumer')->shouldReturn($this);
        $this->getName()->shouldReturn('Joe Consumer');
    }

    function its_line1_is_mutable()
    {
        $this->getLine1()->shouldReturn(null);
        $this->setLine1('Unit 1 16 Floor')->shouldReturn($this);
        $this->getLine1()->shouldReturn('Unit 1 16 Floor');
    }

    function its_line2_is_mutable()
    {
        $this->getLine2()->shouldReturn(null);
        $this->setLine2('300 LaTrobe Street')->shouldReturn($this);
        $this->getLine2()->shouldReturn('300 LaTrobe Street');
    }

    function its_suburb_is_mutable()
    {
        $this->getSuburb()->shouldReturn(null);
        $this->setSuburb('Melbourne')->shouldReturn($this);
        $this->getSuburb()->shouldReturn('Melbourne');
    }

    function its_state_is_mutable()
    {
        $this->getState()->shouldReturn(null);
        $this->setState('VIC')->shouldReturn($this);
        $this->getState()->shouldReturn('VIC');
    }

    function its_postcode_is_mutable()
    {
        $this->getPostcode()->shouldReturn(null);
        $this->setPostcode('3000')->shouldReturn($this);
        $this->getPostcode()->shouldReturn('3000');
    }

    function its_country_code_is_mutable()
    {
        $this->getCountryCode()->shouldReturn(null);
        $this->setCountryCode('AU')->shouldReturn($this);
        $this->getCountryCode()->shouldReturn('AU');
    }

    function its_phone_number_is_mutable()
    {
        $this->getPhoneNumber()->shouldReturn(null);
        $this->setPhoneNumber('0400892011')->shouldReturn($this);
        $this->getPhoneNumber()->shouldReturn('0400892011');
    }
}


text:
declare module '@ember/helper' {
  import type { Opaque } from 'ember/-private/type-utils';

  // In normal TypeScript, these helpers are essentially opaque tokens that just
  // need to be importable. Declaring them with unique interfaces like this,
  // however, gives tools like Glint (that DO have a richer notion of what they
  // are) a place to install more detailed type information.
  export interface ArrayHelper extends Opaque<'helper:array'> {}
  export interface ConcatHelper extends Opaque<'helper:concat'> {}
  export interface FnHelper extends Opaque<'helper:fn'> {}
  export interface GetHelper extends Opaque<'helper:get'> {}
  export interface HashHelper extends Opaque<'helper:hash'> {}

  /**
   * Use the `{{array}}` helper to create an array to pass as an option to your components.
   *
   * @see https://api.emberjs.com/ember/4.1/classes/Ember.Templates.helpers/methods/array?anchor=array
   */
  export const array: ArrayHelper;

  /**
   * Concatenates the given arguments into a string.
   *
   * @see https://api.emberjs.com/ember/4.1/classes/Ember.Templates.helpers/methods/concat?anchor=concat
   */
  export const concat: ConcatHelper;

  /**
   * The `fn` helper allows you to ensure a function that you are passing off to another component, helper, or modifier
   * has access to arguments that are available in the template.
   *
   * @see https://api.emberjs.com/ember/4.1/classes/Ember.Templates.helpers/methods/fn?anchor=fn
   */
  export const fn: FnHelper;

  /**
   * Dynamically look up a property on an object.
   *
   * @see https://api.emberjs.com/ember/4.1/classes/Ember.Templates.helpers/methods/get?anchor=get
   */
  export const get: GetHelper;

  /**
   * Use the `{{hash}}` helper to create a hash to pass as an option to your components.
   *
   * @see https://api.emberjs.com/ember/4.1/classes/Ember.Templates.helpers/methods/hash?anchor=hash
   */
  export const hash: HashHelper;
}