<commit_before>'use strict';

//array of all paths for image files of the items
var pathArray = ['bag.jpg', 'banana.jpg', 'bathroom.jpg', 'boots.jpg', 'breakfast.jpg', 'bubblegum.jpg', 'chair.jpg', 'cthulhu.jpg', 'dog-duck.jpg', 'dragon.jpg', 'pen.jpg', 'pet-sweep.jpg', 'scissors.jpg', 'shark.jpg', 'sweep.png', 'tauntaun.jpg', 'unicorn.jpg', 'usb.gif', 'water-can.jpg', 'wine-glass.jpg'];

//this array will be used to store our item objects
var items = [];

//this will keep track of how many clicks the user has logged.
var pageClicks = 0;

//creating variable for the list of item images
var imageList = document.getElementById('images');

//creating variable for the submit button
var chartButton = document.getElementById('get_chart');

//this array will be used to keep track of the previous 3 images to avoid repeats
var oldGroup = [];

//these arrays will hold the data and lables for chart
var labelsArray = [];
var clicksArray = [];
var viewsArray = [];

//creating and loading our item objects into an array
loadItems();

//randomly selecting three items to display when page loads
generateItems();

//event listener for clicking on item pictures
imageList.addEventListener('click', clickHandler);
//event listener for generating chart
chartButton.addEventListener('click', buttonHandler);

//logs which image has been clicked and icrements click atrribute, loads three new items
function clickHandler(e) {

  //getting event target and coercing into string then finding coresponding position in item array.
  var click = e.target.getAttribute('src');
  var clickedImage = click.toString().split('/')[1];
  var arrayPosition = pathArray.indexOf(clickedImage);

  //incrimenting item click value
  items[arrayPosition].clicks += 1;

  //incrementing page clicks
  pageClicks += 1;

  if(pageClicks < 25){
    //emptying ul and generating 3 new images
    imageList.textContent = '';
    generateItems();

    //removing the first 3 elements of the array that keeps track of the images from previous group
    for(var i = 0; i < 3; i++) {
      oldGroup.shift();
    }
  } else {
    //let user know they have completed survey
    alert('Awsome! You\'ve completed the survey.');
    //this is the equivalent of them hitting submit.
    buttonHandler();
  }
}

function buttonHandler() {
  //loading arrays with chart data
  loadChartArrays();
  document.getElementById('my_chart').textContent = '';
  //renders data to chart
  renderChart();
  //the following disables the image click and submit disapears
  imageList.removeEventListener('click', clickHandler);
  chartButton.removeEventListener('click', buttonHandler);
  imageList.setAttribute('class', 'clear');
  chartButton.setAttribute('class', 'gone');

  //below save arrays to local storage
  var jsonString = JSON.stringify(items);
  console.log(jsonString);
  localStorage.setItem('jsonString', jsonString);
}

//constructor for item objects
function Item(path){
  this.name = path.substring(0,path.length - 4);
  this.path = path;
  this.views = 0;
  this.clicks = 0;
  items.push(this);<commit_msg>item data stored locally and retrieved when app loads<commit_after>'use strict';

//array of all paths for image files of the items
var pathArray = ['bag.jpg', 'banana.jpg', 'bathroom.jpg', 'boots.jpg', 'breakfast.jpg', 'bubblegum.jpg', 'chair.jpg', 'cthulhu.jpg', 'dog-duck.jpg', 'dragon.jpg', 'pen.jpg', 'pet-sweep.jpg', 'scissors.jpg', 'shark.jpg', 'sweep.png', 'tauntaun.jpg', 'unicorn.jpg', 'usb.gif', 'water-can.jpg', 'wine-glass.jpg'];

//this array will be used to store our item objects
var items;

//this will keep track of how many clicks the user has logged.
var pageClicks = 0;

//creating variable for the list of item images
var imageList = document.getElementById('images');

//creating variable for the submit button
var chartButton = document.getElementById('get_chart');

//this array will be used to keep track of the previous 3 images to avoid repeats
var oldGroup = [];

//these arrays will hold the data and lables for chart
var labelsArray = [];
var clicksArray = [];
var viewsArray = [];

//this first control flow decides on whether or not to intanciate new item objects or load locally stored item objects
if(localStorage.length === 0){
  //creating and loading new item objects into an items array
  items = [];
  loadItems();
} else {
  //retrieving locally stored item object array
  var retrieveItems = localStorage.getItem('itemsString');
  items = JSON.parse(retrieveItems);
}
//randomly selecting three items to display when page loads
generateItems();

//event listener for clicking on item pictures
imageList.addEventListener('click', clickHandler);
//event listener for generating chart
chartButton.addEventListener('click', buttonHandler);

//logs which image has been clicked and icrements click atrribute, loads three new items
function clickHandler(e) {

  //getting event target and coercing into string then finding coresponding position in item array.
  var click = e.target.getAttribute('src');
  var clickedImage = click.toString().split('/')[1];
  var arrayPosition = pathArray.indexOf(clickedImage);

  //incrimenting item click value
  items[arrayPosition].clicks += 1;

  //incrementing page clicks
  pageClicks += 1;

  if(pageClicks < 25){
    //emptying ul and generating 3 new images
    imageList.textContent = '';
    generateItems();

    //removing the first 3 elements of the array that keeps track of the images from previous group
    for(var i = 0; i < 3; i++) {
      oldGroup.shift();
    }
  } else {
    //let user know they have completed survey
    alert('Awsome! You\'ve completed the survey.');
    //this is the equivalent of them hitting submit.
    buttonHandler();
  }
}

function buttonHandler() {
  //loading arrays with chart data
  loadChartArrays();
  document.getElementById('my_chart').textContent = '';
  //renders data to chart
  renderChart();
  //the following disables the image click and submit disapears
  imageList.removeEventListener('click', clickHandler);
  chartButton.removeEventListener('click', buttonHandler);
  imageList.setAttribute('class', 'clear');
  chartButton.setAttribute('class', 'gone');

  //saves items arrays to local storage after submit.
  var itemsString = JSON.stringify(items);
  console.log(itemsString);
  localStorage.setItem('itemsString', itemsString);
}

//constructor for item objects
function Item(path){
  this.name = path.substring(0,path.length - 4);
  this.path = path;
  this.views = 0;
  this.clicks = 0;
  items.push(this);
{'fraction_non_alphanumeric': 0.11890897946674839, 'fraction_numerical': 0.004750229849831444, 'mean_word_length': 4.2216, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '3640458', 'n_tokens_mistral': 1897, 'n_tokens_neox': 1842, 'n_words': 679}