<commit_before>var OrderBook = function (options) {
  var self    = this, asks, bids, isLoading;
  self.offers;
  
  var r      = options.remote; 
  var chart  = d3.select("#"+options.chartID).attr('class','orderbookChart'),
    svg, depth, gEnter, 
    xAxis, leftAxis, rightAxis,
    xTitle, leftTitle, rightTitle,
    hover, focus, centerline, path, midpoint,
    status, details, loader;
    
  if (!options.margin) options.margin = {top: 2, right: 60, bottom: 20, left: 60};
  if (!options.width)  options.width  = parseInt(chart.style('width'), 10) - options.margin.left - options.margin.right;
  if (!options.height) options.height = options.width/4;
      
  var xScale = d3.scale.linear(),
    yScale   = d3.scale.linear(),
    lineData = [];
    
  if (options.resize && typeof addResizeListener === 'function') {
    addResizeListener(window, resizeChart);
  } else {
    var padding = parseInt(details.style('padding-left'), 10)+parseInt(details.style('padding-right'), 10);
    details.style("width", (options.width-padding)+"px").style("right","auto");
  }

//set up the order book  
  var bookTables = d3.select("#"+options.tableID).attr("class","bookTables");
  var bidsTable = bookTables.append("table").attr("class","bidsTable"),
    bidsHead    = bidsTable.append("thead"),
    bidsBody    = bidsTable.append("tbody");

  // append the top header
  bidsHead.append("tr").selectAll("th")
    .data(["Bids"])
    .enter().append("th")
    .attr("class","type")
    .attr("colspan",3)
    .text(function(d) {return d;}); 
  
  //append second header      
  bidsHead.append("tr").attr("class","headerRow").selectAll("th")
    .data(["Total","Size","Bid Price"])
    .enter().append("th")
    .text(function(d) {return d;})
    .append("span"); 
    
  var asksTable = bookTables.append("table").attr("class","asksTable"),
    asksHead    = asksTable.append("thead"),
    asksBody    = asksTable.append("tbody");

  // append the top header
  asksHead.append("tr").selectAll("th")
    .data(["Asks"])
    .enter().append("th")
    .attr("class","type")
    .attr("colspan",3)
    .text(function(d) {return d;}); 
  
  //append second header      
  asksHead.append("tr").attr("class","headerRow").selectAll("th")
    .data(["Ask Price","Size","Total"])
    .enter().append("th")
    .text(function(d) {return d;})
    .append("span");  
  

  drawChart(); //draw the blank chart


//subscribe to market data for trading pair
  this.getMarket = function (base, trade) {
    options.base  = base;
    options.trade = trade;
    lineData      = [];
    self.offers   = {};

    bookTables.transition().style("opacity", 0.5);
    fadeChart();
    isLoading = true;
    if (!r.connected) r.connect();
    
    if (asks) {
      asks.removeListener('model', handleAskModel);
      r.request_unsubscribe()
        .books([asks.to_json()])
        .request();
    }
    if (bids) {
      bids.removeListener('model', handleBidModel); 
      r.request_unsubscribe()
        .books([bids.to_json()])
        .request();
      }  
     
    r._books = {};
    r._events.prepare_subscribe = [];
    
    asks = r.book(options.base.currency, options.base.issuer, options.trade.currency, options.trade.issuer)
    bids = r.book(options.trade.currency, options.trade.issuer, options.base.currency, options.base.issuer);         
    
    function handleAskModel (offers) {
      self.offers.asks = handleBook(offers,'asks');
      drawData(); 
      redrawBook();     
    }
    
    function handleBidModel (offers) {
      self.offers.bids = handleBook(offers,'bids');
      drawData(); 
      redrawBook();      
    }
    
    asks.on('model', handleAskModel);   
    bids.on('model', handleBidModel); 
  }


//handle data returned from ripple-lib
  function handleBook (data,action) {
    var max_rows = options.max_rows || 100,
      rowCount   = 0,
      offers     = [];
    
    for (var i=0; i<data.length; i++) {
      var d = data[i];
 
      // prefer taker_pays_funded & taker_gets_funded
      if (d.hasOwnProperty('taker_gets_funded')) {
        d.TakerGets = d.taker_gets_funded;
        d.TakerPays = d.taker_pays_funded;
      }

      d.TakerGets = ripple.Amount.from_json(d.TakerGets);
      d.TakerPays = ripple.Amount.from_json(d.TakerPays);

      d.price = ripple.Amount.from_quality(d.BookDirectory, "1", "1");

      if (action !== "asks") d.price = ripple.Amount.from_json("1/1/1").divide(d.price);
      
      // Adjust for drops: The result would be a million times too large.
      if (d[action === "asks" ? "TakerPays" : "TakerGets"].is_native())
        d.price  = d.price.divide(ripple.Amount.from_json("1000000"));

      // Adjust for drops: The result would be a million times too small.
      if (d[action === "asks" ? "TakerGets" : "TakerPays"].is_native())
        d.price  = d.price.multiply(ripple.Amount.from_json("1000000"));
          
      if (rowCount++ > max_rows) break;

      offers.push(d);              
    }
    <commit_msg>orderbook use from_quality<commit_after>var OrderBook = function (options) {
  var self    = this, asks, bids, isLoading;
  self.offers;
  
  var r      = options.remote; 
  var chart  = d3.select("#"+options.chartID).attr('class','orderbookChart'),
    svg, depth, gEnter, 
    xAxis, leftAxis, rightAxis,
    xTitle, leftTitle, rightTitle,
    hover, focus, centerline, path, midpoint,
    status, details, loader;
    
  if (!options.margin) options.margin = {top: 2, right: 60, bottom: 20, left: 60};
  if (!options.width)  options.width  = parseInt(chart.style('width'), 10) - options.margin.left - options.margin.right;
  if (!options.height) options.height = options.width/4;
      
  var xScale = d3.scale.linear(),
    yScale   = d3.scale.linear(),
    lineData = [];
    
  if (options.resize && typeof addResizeListener === 'function') {
    addResizeListener(window, resizeChart);
  } else {
    var padding = parseInt(details.style('padding-left'), 10)+parseInt(details.style('padding-right'), 10);
    details.style("width", (options.width-padding)+"px").style("right","auto");
  }

//set up the order book  
  var bookTables = d3.select("#"+options.tableID).attr("class","bookTables");
  var bidsTable = bookTables.append("table").attr("class","bidsTable"),
    bidsHead    = bidsTable.append("thead"),
    bidsBody    = bidsTable.append("tbody");

  // append the top header
  bidsHead.append("tr").selectAll("th")
    .data(["Bids"])
    .enter().append("th")
    .attr("class","type")
    .attr("colspan",3)
    .text(function(d) {return d;}); 
  
  //append second header      
  bidsHead.append("tr").attr("class","headerRow").selectAll("th")
    .data(["Total","Size","Bid Price"])
    .enter().append("th")
    .text(function(d) {return d;})
    .append("span"); 
    
  var asksTable = bookTables.append("table").attr("class","asksTable"),
    asksHead    = asksTable.append("thead"),
    asksBody    = asksTable.append("tbody");

  // append the top header
  asksHead.append("tr").selectAll("th")
    .data(["Asks"])
    .enter().append("th")
    .attr("class","type")
    .attr("colspan",3)
    .text(function(d) {return d;}); 
  
  //append second header      
  asksHead.append("tr").attr("class","headerRow").selectAll("th")
    .data(["Ask Price","Size","Total"])
    .enter().append("th")
    .text(function(d) {return d;})
    .append("span");  
  

  drawChart(); //draw the blank chart


//subscribe to market data for trading pair
  this.getMarket = function (base, trade) {
    options.base  = base;
    options.trade = trade;
    lineData      = [];
    self.offers   = {};

    bookTables.transition().style("opacity", 0.5);
    fadeChart();
    isLoading = true;
    if (!r.connected) r.connect();
    
    if (asks) {
      asks.removeListener('model', handleAskModel);
      r.request_unsubscribe()
        .books([asks.to_json()])
        .request();
    }
    if (bids) {
      bids.removeListener('model', handleBidModel); 
      r.request_unsubscribe()
        .books([bids.to_json()])
        .request();
      }  
     
    r._books = {};
    r._events.prepare_subscribe = [];
    
    asks = r.book(options.base.currency, options.base.issuer, options.trade.currency, options.trade.issuer)
    bids = r.book(options.trade.currency, options.trade.issuer, options.base.currency, options.base.issuer);         
    
    function handleAskModel (offers) {
      self.offers.asks = handleBook(offers,'asks');
      drawData(); 
      redrawBook();     
    }
    
    function handleBidModel (offers) {
      self.offers.bids = handleBook(offers,'bids');
      drawData(); 
      redrawBook();      
    }
    
    asks.on('model', handleAskModel);   
    bids.on('model', handleBidModel); 
  }


//handle data returned from ripple-lib
  function handleBook (data,action) {
    var max_rows = options.max_rows || 100,
      rowCount   = 0,
      offers     = [];
    
    for (var i=0; i<data.length; i++) {
      var d = data[i];
 
      // prefer taker_pays_funded & taker_gets_funded
      if (d.hasOwnProperty('taker_gets_funded')) {
        d.TakerGets = d.taker_gets_funded;
        d.TakerPays = d.taker_pays_funded;
      }

      d.TakerGets = Amount.from_json(d.TakerGets);
      d.TakerPays = Amount.from_json(d.TakerPays);

      if (action === "asks") {
        d.price = Amount.from_quality(d.BookDirectory,
                                      d.TakerPays.currency(),
                                      d.TakerPays.issuer(), {
          base_currency: d.TakerGets.currency(),
          reference_date: new Date()
        });
      } else {
        d.price = Amount.from_quality(d.BookDirectory,
                                      d.TakerGets.currency(),
                                      d.TakerGets.issuer(), {
          inverse: true,
          base_currency: d.TakerPays.currency(),
          reference_date: new Date()
        });
      }
          
      if (rowCount++ > max_rows) break;

      offers.push(d);              
    }
    
{'fraction_non_alphanumeric': 0.16588247071778958, 'fraction_numerical': 0.0073080388427269995, 'mean_word_length': 2.64067055393586, 'pattern_counts': {'":': 0, '<': 5, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1646090', 'n_tokens_mistral': 3397, 'n_tokens_neox': 3248, 'n_words': 593}