<commit_before>var setCost = require('../cost').parcel;
var incomeCalculator = require('../income');

module.exports = function(datastore, farmBudgetSdk, poplarModel) {
  return function(options) {
      var sortList = [];
      var parcel, sortList;
      
      var minPrice = 9999;
      var maxPrice = 0;
      
      for( var i = 0; i < datastore.validParcels.length; i++ ) {
        parcel = datastore.validParcels[i];
        
        setCost(parcel, datastore); 
       
        parcel.properties.ucd.income = {
            crops : incomeCalculator.crops(parcel, datastore)
        }
          
        parcel.properties.ucd.adoptionPrice = calcAdoptionPrice(parcel);
        
        if( parcel.properties.ucd.adoptionPrice < minPrice ) {
            minPrice = parcel.properties.ucd.adoptionPrice;
        }
        if( parcel.properties.ucd.adoptionPrice > maxPrice ) {
            maxPrice = parcel.properties.ucd.adoptionPrice;
        }
        
        var transportationCost = 0;
        for( var j = 0; j < parcel.properties.ucd.farmCost.poplar.yearlyData.length; j++ ) {
          transportationCost += parcel.properties.ucd.farmCost.poplar.yearlyData[j].transportation;
        }
        parcel.properties.ucd.transportationCost = transportationCost / parcel.properties.ucd.harvest.totalPerAcre;
        parcel.properties.ucd.refineryGateCost = parcel.properties.ucd.adoptionPrice + parcel.properties.ucd.transportationCost;
        
        
        if( parcel.properties.ucd.refineryGateCost < datastore.selectedRefinery.maxWillingToPay ) {
            sortList.push(parcel);
        }
      }
      
      sortList.sort((a, b) => {
         if( a.properties.ucd.refineryGateCost > b.properties.ucd.refineryGateCost ) {
             return 1;
         }
         if( a.properties.ucd.refineryGateCost < b.properties.ucd.refineryGateCost ) {
             return -1;
         }
         return 0;
      });
      
      var requiredYield = datastore.selectedRefinery.feedstockCapacity.value * poplarModel.years;
      
      var results = {
          parcels : sortList,
          count : 0,
          acres : 0,
          yield : 0,
          requiredYield : requiredYield,
          capacityReachedAt : -1
      }
      var props;
      datastore.selectedParcels = [];
      
      var poplarPrice = -1;
      
      for( var i = 0; i < sortList.length; i++ ) {
          props = sortList[i].properties;
          results.count++;
          results.acres += props.usableSize;
          results.yield += props.ucd.harvest.total;
          datastore.selectedParcels.push(sortList[i]);
          
          if( sortList[i].properties.ucd.adoptionPrice > poplarPrice ) {
              poplarPrice = sortList[i].properties.ucd.adoptionPrice;
          }
          
          if( results.yield > requiredYield ) {
              datastore.poplarPrice = parseFloat(poplarPrice.toFixed(2))+0.01;
              datastore.mwa = datastore.poplarPrice;
              results.capacityReachedAt = i;
              break;<commit_msg>quick fix<commit_after>var setCost = require('../cost').parcel;
var incomeCalculator = require('../income');

module.exports = function(datastore, farmBudgetSdk, poplarModel) {
  return function(options) {
      var sortList = [];
      var parcel, sortList;
      
      var minPrice = 9999;
      var maxPrice = 0;
      
      for( var i = 0; i < datastore.validParcels.length; i++ ) {
        parcel = datastore.validParcels[i];
        
        setCost(parcel, datastore); 
       
        parcel.properties.ucd.income = {
            crops : incomeCalculator.crops(parcel, datastore)
        }
          
        parcel.properties.ucd.adoptionPrice = calcAdoptionPrice(parcel);
        
        if( parcel.properties.ucd.adoptionPrice < minPrice ) {
            minPrice = parcel.properties.ucd.adoptionPrice;
        }
        if( parcel.properties.ucd.adoptionPrice > maxPrice ) {
            maxPrice = parcel.properties.ucd.adoptionPrice;
        }
        
        var transportationCost = 0;
        for( var j = 0; j < parcel.properties.ucd.farmCost.poplar.yearlyData.length; j++ ) {
          transportationCost += parcel.properties.ucd.farmCost.poplar.yearlyData[j].transportation;
        }
        parcel.properties.ucd.transportationCost = transportationCost / parcel.properties.ucd.harvest.totalPerAcre;
        parcel.properties.ucd.refineryGateCost = parcel.properties.ucd.adoptionPrice + parcel.properties.ucd.transportationCost;
        
        
        if( parcel.properties.ucd.refineryGateCost < datastore.selectedRefinery.maxWillingToPay ) {
            sortList.push(parcel);
        }
      }
      
      sortList.sort((a, b) => {
         if( a.properties.ucd.refineryGateCost > b.properties.ucd.refineryGateCost ) {
             return 1;
         }
         if( a.properties.ucd.refineryGateCost < b.properties.ucd.refineryGateCost ) {
             return -1;
         }
         return 0;
      });
      
      var requiredYield = datastore.selectedRefinery.feedstockCapacity.value * poplarModel.years;
      
      var results = {
          parcels : sortList,
          count : 0,
          acres : 0,
          yield : 0,
          requiredYield : requiredYield,
          capacityReachedAt : -1
      }
      var props;
      datastore.selectedParcels = [];
      
      var poplarPrice = -1;
      
      for( var i = 0; i < sortList.length; i++ ) {
          props = sortList[i].properties;
          results.count++;
          results.acres += props.usableSize;
          results.yield += props.ucd.harvest.total;
          datastore.selectedParcels.push(sortList[i]);
          
          if( sortList[i].properties.ucd.adoptionPrice > poplarPrice ) {
              poplarPrice = sortList[i].properties.ucd.adoptionPrice;
          }
          
          if( results.yield > requiredYield ) {
              datastore.poplarPrice = parseFloat((poplarPrice+0.01).toFixed(2));
              datastore.mwa = datastore.poplarPrice;
              results.capacityReachedAt = i;
              break;
{'fraction_non_alphanumeric': 0.10503786631544287, 'fraction_numerical': 0.00691471847217649, 'mean_word_length': 1.9376208897485494, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, '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': '1411982', 'n_tokens_mistral': 1885, 'n_tokens_neox': 1831, 'n_words': 280}