<commit_before>var Stats =  Backbone.View.extend({
	el: '#load',

	initialize: function(){
		this.stats= '<h2>Stats</h2><canvas id="chart" width="300" height="300"></canvas>';
		this.table = '<table class="table table-striped"><thead><tr><th>Highest BAC</th><th>Date(Y-M-D)</th></tr></thead><tbody id="records"></tbody></table>';
	},

	render: function(){
		this.user = you.retrieveProfile();
		this.$el.html(this.stats+''+this.table);
		this.chartGenerate();
		this.populateTable();
	},

	chartGenerate: function(){
		var bacData = this.stringDateAndBac();

		var data = {
			labels: bacData.date,
			datasets : [
				{
					fillColor : "rgba(220,220,220,0.5)",
					strokeColor : "rgba(220,220,220,1)",
					data : bacData.bacLevel
					//data: [0.0245,0.0645,0.0545]					
				}
			]
		}

		var options = {
				scaleFontSize : 9
		}

		var ctx = $("#chart").get(0).getContext("2d");
		new Chart(ctx).Bar(data, options);
	},

	populateTable: function(){
		$('#records').empty(); 
		var userBacRecord = this.user.BACLevels.length - 1;

		for(var i = userBacRecord; i >= 0; i--){
			$('#records').append('<tr><td>'+this.user.BACLevels[i].bacLevelHigh+'</td><td>'+this.user.BACLevels[i].date+'</td></tr>');
		}
	},

	stringDateAndBac: function(){
		var userBacRecord = this.user.BACLevels.length - 1;
		var bacRecord = {bacLevel: [], date: []};

		if(userBacRecord <= 5){
			for(var i = userBacRecord; i >= 0; i--){
				bacRecord.bacLevel[i] = this.user.BACLevels[i].bacLevelHigh;
				bacRecord.date[i] = this.user.BACLevels[i].date;
			}
		}else{ //Gets 5 latest records 
			for(var i = userBacRecord; i >= (5-userBacRecord); i--){
				bacRecord.bacLevel[i] = this.user.BACLevels[i].bacLevelHigh;
				bacRecord.date[i] = this.user.BACLevels[i].date;
			}
		}
		var bacRecord = {bacLevel: [], date: []};
		for(var i = userBacRecord; i >= 0; i--){
			bacRecord.bacLevel[i] = this.user.BACLevels[i].bacLevelHigh;
			bacRecord.date[i] = this.user.BACLevels[i].date;
		}
		return bacRecord;
	}
});

var stats = new Stats();<commit_msg>Fixed data load issue<commit_after>var Stats =  Backbone.View.extend({
	el: '#load',

	initialize: function(){
		this.stats= '<h2>Stats</h2><canvas id="chart" width="300" height="300"></canvas>';
		this.table = '<table class="table table-striped"><thead><tr><th>Highest BAC</th><th>Date(Y-M-D)</th></tr></thead><tbody id="records"></tbody></table>';
	},

	render: function(){
		this.user = you.retrieveProfile();
		this.$el.html(this.stats+''+this.table);
		this.chartGenerate();
		this.populateTable();
	},

	chartGenerate: function(){
		var bacData = this.stringDateAndBac();

		var data = {
			labels: bacData.date,
			datasets : [
				{
					fillColor : "rgba(220,220,220,0.5)",
					strokeColor : "rgba(220,220,220,1)",
					data : bacData.bacLevel
					//data: [0.0245,0.0645,0.0545]					
				}
			]
		}

		var options = {
				scaleFontSize : 9
		}

		var ctx = $("#chart").get(0).getContext("2d");
		new Chart(ctx).Bar(data, options);
	},

	populateTable: function(){
		$('#records').empty(); 
		var userBacRecord = this.user.BACLevels.length - 1;

		for(var i = userBacRecord; i >= 0; i--){
			$('#records').append('<tr><td>'+this.user.BACLevels[i].bacLevelHigh+'</td><td>'+this.user.BACLevels[i].date+'</td></tr>');
		}
	},

	stringDateAndBac: function(){
		var userBacRecord = this.user.BACLevels.length - 1;
		var bacRecord = {bacLevel: [], date: []};

		/*if(userBacRecord <= 5){
			for(var i = userBacRecord; i >= 0; i--){
				bacRecord.bacLevel[i] = this.user.BACLevels[i].bacLevelHigh;
				bacRecord.date[i] = this.user.BACLevels[i].date;
			}
		}else if(userBacRecord <= 5){ //Gets 5 latest records 
			for(var i = userBacRecord; i >= (5-userBacRecord); i--){
				bacRecord.bacLevel[i] = this.user.BACLevels[i].bacLevelHigh;
				bacRecord.date[i] = this.user.BACLevels[i].date;
			}
		}
		else{
			console.log('Cannot retrieve data');
			alert('Cannot retrieve data');
		}*/
		var bacRecord = {bacLevel: [], date: []};
		for(var i = userBacRecord; i >= 0; i--){
			bacRecord.bacLevel[i] = this.user.BACLevels[i].bacLevelHigh;
			bacRecord.date[i] = this.user.BACLevels[i].date;
		}
		return bacRecord;
	}
});

var stats = new Stats();
{'fraction_non_alphanumeric': 0.2089016511127064, 'fraction_numerical': 0.02656137832017229, 'mean_word_length': 3.7178329571106095, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 55, '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': '3466343', 'n_tokens_mistral': 1938, 'n_tokens_neox': 1642, 'n_words': 259}