<commit_before><!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta name = "format-detection" content = "telephone=no"/>
	<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width" />
	<link rel="stylesheet" type="text/css" href="css/nfcringapp.min.css" />
	<title>NFC Ring App</title>
</head>
<body id="create">
<div id="heatMap"></div>

<div id="message"><p id="helpLink">Struggling to find your Sweet Spot? <br><a href="#">Show help</a></p></div>

<div id="help">
	<div id="helpContents" class="white-popup mfp-hide">
		<h3 class="icon icon-support">Help Tips</h3>
		<ul>
			<li>Make sure the colored, non metal part of the ring is touching and facing the back of your device</li>
			<li>Remove any cases from your device</li>
			<li>Turn your device volume up</li>
			<li>Make sure your device screen is on and the device is on (note devices go to sleep often)</li>
			<li>Move your ring slowly around the back of the device</li>
			<li>Try with another NFC Device if you have one</li>
		</ul>
		<button class="button" id="helpClose">Ok, got it</button>
	</div>
</div>

<div class="container">
	<div class="mainContents">

		<header id="header">
			<div id="logo"><img src="img/nfcring-logo.png"></div>
		</header>
		
		<div id="action" class="step action">
		  <h2>What do you want your Ring to do?</h2>
		  <div class="actionContents">
		    <div class="ringActions">
			    <ul id="ringActions" class="link-list">
			    </ul>
		    </div>
		  </div>
		</div>

		<div id="option" class="step option">
		  <div class="actionName"></div>
		  <div class="actionContents">
		    <form id="optionForm">
		      <label for="optionInput"></label>
		      <input name="option" id="optionInput" type="text">
		      <input type="hidden" id="action" name="action">
		      <button type="submit" class="btn-link icon icon-next" id="submit">Next</button>
		    </form>
		  </div>
		</div>

		<div id="writeRing" class="step writeRing">
		  <div class="actionName"></div>
		  <ul class="link-list bottom">
		  	<li><a href="index.html" id="finish" class="icon icon-exit">Finish</a></li>
		  </ul>
		</div>
	
	</div>
</div>

<script type="text/javascript" src="js/parse-1.2.9.min.js"></script>
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js/magpop.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/actions.js"></script>
<script type="text/javascript" src="js/heatmap.js"></script>
<script type="text/javascript">
app.initialize();

nfcRing.addActions = function() {
  $.each(actions, function (key, action) {
    debug(action);
    if (!action.image) {
      action.image = key.toLowerCase() + ".png";
    };
    $('#ringActions').append('<li><a data-key="'+key+'" class="icon icon-'+ action.label.toLowerCase() +'">' + action.label + '<span>' + action.description + '</span></a></li>');
  });

  
  $('#ringActions a').click(function(){
    nfcRing.location = "option";
    var key = $(this).data("key");
    $('#option').show(); $('#action').hide();
    $('#option > .actionName').html('<h2>' + actions[key].label + '</h2>');
    $('#optionInput').attr("placeholder", actions[key].placeHolder);
    $('form > label').text(actions[key].optionText);
    $('#optionForm').submit(function(e){
      e.preventDefault();
      console.log("Submitting a write value to the nfcRing object");
      nfcRing.submitted(key);
      return false;
    });
  });
}

nfcRing.submitted = function(key){
  var response = $('#optionInput').val();
  if(response){
    nfcRing.location = "writing";
    $('#writeRing').show(); $('#option').hide(); $('#heatMap').show();
    console.log("Formatted as ", actions[key].format(response));
    nfcRing.toWrite = actions[key].format(response);

    // Placeholder data object
    var coOrdinateCounter = {};

    // Getting data from Parse..
    var TestObject = Parse.Object.extend("TestObject");
    var testObject = new TestObject();
    var query = new Parse.Query(TestObject);
    query.equalTo("model", device.model);
	try{
      query.find({
        success: function(results){
          for (var i = 0; i < results.length; i++) { 
            $('#writeRing > .actionName').html("<h2>Hold your NFC Ring to the back of your phone at the location indicated by the colored dots.</h2>");
            var object = results[i];
            var x = object.get('x');
            var y = object.get('y');
            // Turns it into a counted set of objects instead of single objects
            coOrdinateCounter[x+":"+y] = coOrdinateCounter[x+":"+y] || 1;
          }
          if(results.length == 0){ // if there are no results
            $('#writeRing > .actionName').html("<h2>It looks like our awesome community hasn't stored a location of the NFC Sweet Spot for your phone yet.</h2><p>Move the ring around the back of the phone until you recieve a message telling you that you found your sweet spot.  This can take a little bit of time so be patient :)</p>");   
          }else{
            drawHeatMap(coOrdinateCounter);
          }
          setTimeout(function(){nfcRing.showNeedHelp()}, 8000); // this would be better handled by a promise
        },
        failure: function(){
          // fires on failure to connect
          alert("We were unable to connect to our community sweet spot location servers, the sweet spot location will help you identify where to hold the ring on your phone.  You might need to turn on your Internet connection to access our servers, thanks");
          setTimeout(function(){nfcRing.showNeedHelp()}, 8000);
        }
      });
    }catch(e){
      // Windows Phone wont do the Parse XHR request and fails on access is denied, this should be handled by the Parse API but it isn't so we handle it here
      if(device.platform == "Win32NT"){
        alert("Windows Phone is unable to use our Community Sweet Spot location servers, we hope to get this fixed as soon as possible, usually on nokia windows phone the nfc sweet spot is just below the camera");
      }
    }
  }
}

nfcRing.showNeedHelp = function(){
  $('#message').fadeIn('slow');
}

function drawHeatMap(coOrds){

  var data = {
    max: 10,
    data: []
  };

  $.each(coOrds, function(k,v){
    var x = k.split(":")[0];
    var y = k.split(":")[1];
    var coOrd = {
      x: x,
      y: y,
      count: v*5
    };
    data.data.push(coOrd);
  });
<commit_msg>Still show error on parse failure<commit_after><!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta name = "format-detection" content = "telephone=no"/>
	<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width" />
	<link rel="stylesheet" type="text/css" href="css/nfcringapp.min.css" />
	<title>NFC Ring App</title>
</head>
<body id="create">
<div id="heatMap"></div>

<div id="message"><p id="helpLink">Struggling to find your Sweet Spot? <br><a href="#">Show help</a></p></div>

<div id="help">
	<div id="helpContents" class="white-popup mfp-hide">
		<h3 class="icon icon-support">Help Tips</h3>
		<ul>
			<li>Make sure the colored, non metal part of the ring is touching and facing the back of your device</li>
			<li>Remove any cases from your device</li>
			<li>Turn your device volume up</li>
			<li>Make sure your device screen is on and the device is on (note devices go to sleep often)</li>
			<li>Move your ring slowly around the back of the device</li>
			<li>Try with another NFC Device if you have one</li>
		</ul>
		<button class="button" id="helpClose">Ok, got it</button>
	</div>
</div>

<div class="container">
	<div class="mainContents">

		<header id="header">
			<div id="logo"><img src="img/nfcring-logo.png"></div>
		</header>
		
		<div id="action" class="step action">
		  <h2>What do you want your Ring to do?</h2>
		  <div class="actionContents">
		    <div class="ringActions">
			    <ul id="ringActions" class="link-list">
			    </ul>
		    </div>
		  </div>
		</div>

		<div id="option" class="step option">
		  <div class="actionName"></div>
		  <div class="actionContents">
		    <form id="optionForm">
		      <label for="optionInput"></label>
		      <input name="option" id="optionInput" type="text">
		      <input type="hidden" id="action" name="action">
		      <button type="submit" class="btn-link icon icon-next" id="submit">Next</button>
		    </form>
		  </div>
		</div>

		<div id="writeRing" class="step writeRing">
		  <div class="actionName"></div>
		  <ul class="link-list bottom">
		  	<li><a href="index.html" id="finish" class="icon icon-exit">Finish</a></li>
		  </ul>
		</div>
	
	</div>
</div>

<script type="text/javascript" src="js/parse-1.2.9.min.js"></script>
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js/magpop.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/actions.js"></script>
<script type="text/javascript" src="js/heatmap.js"></script>
<script type="text/javascript">
app.initialize();

nfcRing.addActions = function() {
  $.each(actions, function (key, action) {
    debug(action);
    if (!action.image) {
      action.image = key.toLowerCase() + ".png";
    };
    $('#ringActions').append('<li><a data-key="'+key+'" class="icon icon-'+ action.label.toLowerCase() +'">' + action.label + '<span>' + action.description + '</span></a></li>');
  });

  
  $('#ringActions a').click(function(){
    nfcRing.location = "option";
    var key = $(this).data("key");
    $('#option').show(); $('#action').hide();
    $('#option > .actionName').html('<h2>' + actions[key].label + '</h2>');
    $('#optionInput').attr("placeholder", actions[key].placeHolder);
    $('form > label').text(actions[key].optionText);
    $('#optionForm').submit(function(e){
      e.preventDefault();
      console.log("Submitting a write value to the nfcRing object");
      nfcRing.submitted(key);
      return false;
    });
  });
}

nfcRing.submitted = function(key){
  var response = $('#optionInput').val();
  if(response){
    nfcRing.location = "writing";
    $('#writeRing').show(); $('#option').hide(); $('#heatMap').show();
    console.log("Formatted as ", actions[key].format(response));
    nfcRing.toWrite = actions[key].format(response);

    // Placeholder data object
    var coOrdinateCounter = {};

    // Getting data from Parse..
    var TestObject = Parse.Object.extend("TestObject");
    var testObject = new TestObject();
    var query = new Parse.Query(TestObject);
    query.equalTo("model", device.model);
	try{
      query.find({
        success: function(results){
          for (var i = 0; i < results.length; i++) { 
            $('#writeRing > .actionName').html("<h2>Hold your NFC Ring to the back of your phone at the location indicated by the colored dots.</h2>");
            var object = results[i];
            var x = object.get('x');
            var y = object.get('y');
            // Turns it into a counted set of objects instead of single objects
            coOrdinateCounter[x+":"+y] = coOrdinateCounter[x+":"+y] || 1;
          }
          if(results.length == 0){ // if there are no results
            $('#writeRing > .actionName').html("<h2>It looks like our awesome community hasn't stored a location of the NFC Sweet Spot for your phone yet.</h2><p>Move the ring around the back of the phone until you recieve a message telling you that you found your sweet spot.  This can take a little bit of time so be patient :)</p>");   
          }else{
            drawHeatMap(coOrdinateCounter);
          }
          setTimeout(function(){nfcRing.showNeedHelp()}, 8000); // this would be better handled by a promise
        },
        failure: function(){
          // fires on failure to connect
          alert("We were unable to connect to our community sweet spot location servers, the sweet spot location will help you identify where to hold the ring on your phone.  You might need to turn on your Internet connection to access our servers, thanks");
          setTimeout(function(){nfcRing.showNeedHelp()}, 8000);
        }
      });
    }catch(e){
      // Windows Phone wont do the Parse XHR request and fails on access is denied, this should be handled by the Parse API but it isn't so we handle it here
      if(device.platform == "Win32NT"){
        alert("Windows Phone is unable to use our Community Sweet Spot location servers, we hope to get this fixed as soon as possible, usually on nokia windows phone the nfc sweet spot is just below the camera");
      }
      setTimeout(function(){nfcRing.showNeedHelp()}, 8000);
    }
  }
}

nfcRing.showNeedHelp = function(){
  $('#message').fadeIn('slow');
}

function drawHeatMap(coOrds){

  var data = {
    max: 10,
    data: []
  };

  $.each(coOrds, function(k,v){
    var x = k.split(":")[0];
    var y = k.split(":")[1];
    var coOrd = {
      x: x,
      y: y,
      count: v*5
    };
    data.data.push(coOrd);
  });

{'fraction_non_alphanumeric': 0.172348770553628, 'fraction_numerical': 0.006034092623321768, 'mean_word_length': 3.3457882661422484, 'pattern_counts': {'":': 8, '<': 233, '<?xml version=': 0, '>': 239, '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': '6849181', 'n_tokens_mistral': 4337, 'n_tokens_neox': 4095, 'n_words': 1197}