<commit_before>'use strict';

var kafka = require('kafka-node');

const NEW_PROPOSALS_RECEIVED_TOPIC = 'new-proposals-recvd';
const PROPOSALS_REVIEWED_TOPIC = 'proposals-reviewed';

var consumerClient = new kafka.Client(),
  consumer = new kafka.Consumer(
    consumerClient, [{
      topic: NEW_PROPOSALS_RECEIVED_TOPIC
    }], {
      autoCommit: true
    }
  );

var producerClient = new kafka.Client(),
  producer = new kafka.Producer(producerClient);

// Use incoming JSON message.
// Use JSON.parse() and JSON.stringify() to process JSON.
consumer.on('message', function(message) {
  console.log('received message', message);
  processProposal(message);
});

function processProposal(proposal) {
  var proposalAccepted = decideOnProposal();
  var proposalMessage = proposal.value;
  //var proposalMessage = JSON.stringify(proposal.value);

  console.log('\n\n');
  //console.log('rawProposalMessage = ' + rawProposalMessage);
  console.log('proposalMessage = ' + proposalMessage);
  console.log('Decision - proposal has been [' +
    (proposalAccepted ? 'Accepted' : 'Rejected') + ']');

  if (proposalAccepted) {
    acceptProposal(proposalMessage);
  } else {
    rejectProposal(proposalMessage);
  }
}

function decideOnProposal() {
  return Math.random() >= 0.5;
}

function acceptProposal(proposalMessage) {
  var acceptedProposal = {
    decision: {
      accepted: true,
      timeSlot: {
        date: "2017-11-06",
        time: "10:00"
      }
    },
    proposal: proposalMessage
  };

  var acceptedProposalMessage = JSON.stringify(acceptedProposal);
  console.log('Accepted Proposal = ' + acceptedProposalMessage);
  publishMessage(acceptedProposalMessage);
}<commit_msg>Parsing proposal upon receipt.<commit_after>'use strict';

var kafka = require('kafka-node');

const NEW_PROPOSALS_RECEIVED_TOPIC = 'new-proposals-recvd';
const PROPOSALS_REVIEWED_TOPIC = 'proposals-reviewed';

var consumerClient = new kafka.Client(),
  consumer = new kafka.Consumer(
    consumerClient, [{
      topic: NEW_PROPOSALS_RECEIVED_TOPIC
    }], {
      autoCommit: true
    }
  );

var producerClient = new kafka.Client(),
  producer = new kafka.Producer(producerClient);

// Use incoming JSON message.
// Use JSON.parse() and JSON.stringify() to process JSON.
consumer.on('message', function(message) {
  console.log('received message', message);
  processProposal(message);
});

function processProposal(proposal) {
  var proposalAccepted = decideOnProposal();
  var proposalMessage = proposal.value;

  console.log('\n\n');
  console.log('proposalMessage = ' + proposalMessage);
  console.log('Decision - proposal has been [' +
    (proposalAccepted ? 'Accepted' : 'Rejected') + ']');

  if (proposalAccepted) {
    acceptProposal(proposalMessage);
  } else {
    rejectProposal(proposalMessage);
  }
}

function decideOnProposal() {
  return Math.random() >= 0.5;
}

function acceptProposal(proposalMessage) {
  var acceptedProposal = {
    decision: {
      accepted: true,
      timeSlot: {
        date: "2017-11-06",
        time: "10:00"
      }
    },
    proposal: JSON.parse(proposalMessage)
  };

  var acceptedProposalMessage = JSON.stringify(acceptedProposal);
  console.log('Accepted Proposal = ' + acceptedProposalMessage);
  publishMessage(acceptedProposalMessage);
}
{'fraction_non_alphanumeric': 0.12956204379562045, 'fraction_numerical': 0.00851581508515815, 'mean_word_length': 4.1390625, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '663426', 'n_tokens_mistral': 1069, 'n_tokens_neox': 1040, 'n_words': 200}