<commit_before>var maxSentiment    = 0,
    minSentiment    = 0,
    tweetCount      = 0,
    currentCountry = null,
    world_50m=null;

var CountrySentiment = function(data, countryInfo){
    var that = this;
    this.code = data.code;
    this.positive = 0;
    this.negative = 0;
    this.neutral = 0;
    this.alpha = 0;
    this.count = 0;
    this.avg = 0;
    this.numericCode = parseInt(countryInfo[0]);
    this.countryName = countryInfo[1];

    var addPositive = function(positive){
        that.positive += positive;
        addCount(1);
        calcAvg();
    };

    var addNegative = function(negative){
        that.negative += negative;
        addCount(1);
        calcAvg();
    };

    var addNeutral = function(neutral){
        that.neutral += 1;
        addCount(1);
    };

    var addCount = function(cnt){
        that.count += cnt;
    };

    var calcAvg = function() {
        that.avg = (that.positive + that.negative) / (that.count - that.neutral);
        if (that.avg > maxSentiment ){
            maxSentiment = that.avg;
        }
        if( that.avg < minSentiment ){
            minSentiment = that.avg;
        }
    }

    this.addValue = function(data){
        if(data.sentiment == 0){addNeutral(data.sentiment)}
        else if(data.sentiment > 0){addPositive(data.sentiment)}
        else if(data.sentiment < 0 ){addNegative(data.sentiment)}
    }

    this.addValue(data);
};


$(function () {
    var width = "100%",
        height = "80%";

    var countrySentimentDict = {};
    var countrySentimentDictNumericKey = {};

    var socket = io.connect();

    socket.on("tweet", function(d){
      var data = JSON.parse(d);
      if(currentCountry == data.code){
        updateSmileyBox(countrySentimentDict[data.code]);
      }
      $("#tweet-stream").prepend("<b>Country: </b>"+ countryNameDict[data.code][1] +" Sentiment: "+data.sentiment+"<br/>");
      addSentiment(data);
    })


    var addSentiment = function(data){
        var countrySentiment =  countrySentimentDict[data.code];

        if(countrySentiment !== undefined){
            countrySentiment.addValue(data);
        } else {
            var cs = new CountrySentiment(data, countryNameDict[data.code]);
            countrySentimentDict[data.code] = cs;
            countrySentimentDictNumericKey[ parseInt(countryNameDict[data.code][0]) ] = cs;
        }
    }

    var updateSmileyBox = function(obj){
      $("#smiley-box").html("<b>Country: </b>" + obj.countryName + "<br/><b>Positive: </b> "+ obj.positive + "<br/><b>Negative: </b> "+ obj.negative + "<br/><b>Neutral: </b> "+ obj.neutral);
    }

    var clearTweets = function(){
      countrySentimentDict = {};
      countrySentimentDictNumericKey = {};
    }

    var projection = d3.geo.mercator().translate([370, 300]).scale(120);

    var path = d3.geo.path().projection(projection);

    var svg = d3.select("#map").append("svg")
      .attr("width", width)
      .attr("height", height)
      .call(d3.behavior.zoom()
      .on("zoom", redraw))
      .append("g");


    function redraw() {
      svg.attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
    }

    queue()
      .defer(d3.json, "data/world-50m.json")
      .await(ready);<commit_msg>second visualization<commit_after>var maxSentiment    = 0,
    minSentiment    = 0,
    tweetCount      = 0,
    currentCountry = null,
    world_50m=null;

var CountrySentiment = function(data, countryInfo){
    var that = this;
    this.code = data.code;
    this.positive = 0;
    this.negative = 0;
    this.neutral = 0;
    this.alpha = 0;
    this.count = 0;
    this.avg = 0;
    this.numericCode = parseInt(countryInfo[0]);
    this.countryName = countryInfo[1];

    var addPositive = function(positive){
        that.positive += positive;
        addCount(1);
        calcAvg();
    };

    var addNegative = function(negative){
        that.negative -= negative;
        addCount(1);
        calcAvg();
    };

    var addNeutral = function(neutral){
        that.neutral += 1;
        addCount(1);
    };

    var addCount = function(cnt){
        that.count += cnt;
    };

    var calcAvg = function() {
        that.avg = (that.positive + that.negative) / (that.count - that.neutral);
        if (that.avg > maxSentiment ){
            maxSentiment = that.avg;
        }
        if( that.avg < minSentiment ){
            minSentiment = that.avg;
        }
    }

    this.addValue = function(data){
        if(data.sentiment == 0){addNeutral(data.sentiment)}
        else if(data.sentiment > 0){addPositive(data.sentiment)}
        else if(data.sentiment < 0 ){addNegative(data.sentiment)}
    }

    this.addValue(data);
};


$(function () {
    var width = "100%",
        height = "80%";

    var countrySentimentDict = {};
    var countrySentimentDictNumericKey = {};

    var socket = io.connect();

    socket.on("tweet", function(d){
      var data = JSON.parse(d);
      if(currentCountry == data.code){
        updateSmileyBox(countrySentimentDict[data.code]);
      }
      $("#tweet-stream").prepend("<b>Country: </b>"+ countryNameDict[data.code][1] +" Sentiment: "+data.sentiment+"<br/>");
      addSentiment(data);
    })


    var addSentiment = function(data){
        var countrySentiment =  countrySentimentDict[data.code];

        if(countrySentiment !== undefined){
            countrySentiment.addValue(data);
        } else {
            var cs = new CountrySentiment(data, countryNameDict[data.code]);
            countrySentimentDict[data.code] = cs;
            countrySentimentDictNumericKey[ parseInt(countryNameDict[data.code][0]) ] = cs;
        }
    }

    var updateSmileyBox = function(obj){
      $("#smiley-box").html("<b>Country: </b>" + obj.countryName + "<br><br><svg id='chart' width='250' height='250'></svg><br>neutral: <b>" + obj.neutral + " </b> - positive: <b>" + obj.positive + "</b> - negative: <b>" + obj.negative + "</b>");

      var cScale = d3.scale.linear().domain([0, obj.positive+obj.neutral+obj.negative]).range([0, 2 * Math.PI]);
      data = [[0, obj.positive, "#3c763d"], [obj.positive, obj.positive+obj.neutral, "#ffffff"], [obj.positive+obj.neutral, obj.positive+obj.neutral+obj.negative, "#a94442"]]
      var vis = d3.select("#chart");

      var arc = d3.svg.arc()
        .innerRadius(60)
        .outerRadius(110)
        .startAngle(function(d){return cScale(d[0]);})
        .endAngle(function(d){return cScale(d[1]);});

      vis.selectAll("path")
        .data(data)
        .enter()
        .append("path")
        .attr("d", arc)
        .attr("stroke", "black")
        .attr("stroke-width", "0.3")
        .attr("class", "slice")
        .style("fill", function(d){return d[2];})
        .attr("transform", "translate(110,110)");
    }

    var clearTweets = function(){
      countrySentimentDict = {};
      countrySentimentDictNumericKey = {};
    }

    var projection = d3.geo.mercator().translate([370, 300]).scale(120);

    var path = d3.geo.path().projection(projection);

    var svg = d3.select("#map").append("svg")
      .attr("width", width)
      .attr("height", height)
      .call(d3.behavior.zoom()
      .on("zoom", redraw))
      .append("g");


    function redraw() {
      svg.attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
    }

    queue()
      .defer(d3.json, "data/world-50m.json")
      .await(ready);
{'fraction_non_alphanumeric': 0.1670030951419728, 'fraction_numerical': 0.017225137935674876, 'mean_word_length': 2.5122873345935726, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, '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': '4865022', 'n_tokens_mistral': 2518, 'n_tokens_neox': 2363, 'n_words': 423}