<commit_before>'use strict';

var Weather = require('../models/weather');
var WeatherView = require('../views/weather_view');
var MapsConf = require('../conf/maps_coordinates');
var Config = require('../conf/config');

module.exports = (function(){
  
  var WeatherConf = {
    url:Config.hardAntUrl.concat('/weather')
  }

  var selectors = {
    searchForm:'form[name=byTown]',
    searchInput:'input[name=search]',
    latitudeSelector: ".text-latitude",
    longitudeSelector: ".text-longitude"
  };  

  var searchWeatherByName = function(event){
    event.preventDefault(); 
    Weather.get({url: WeatherConf.url ,data:$(this).serialize()}).then(success,failure);
  };

  var getWeatherByTown = function (event) {
    event.preventDefault();
    Weather.get({url:WeatherConf.url, data: $(this).serialize()}).then(success, failure);
  };

  var success = function(data){
    var placeInformation = getInformationFromPlace(data);    
    WeatherView.render(placeInformation);
    drawHeatMap(data);
    getTemperatureChart(data);
  };
  
  var failure = function(data){
    console.error("Error");
    console.error(data);
  };

  var bindEvents = function(){
    $(selectors.searchForm).on('submit',searchWeatherByName); 
  };

  var drawMap = function (){
    var map = new google.maps.Map(document.getElementById('map'),{
        zoom: 10,
        center: {lat: 19.45, lng: -99},
        maxZoom: 13,
        minZoom: 8, 
        streetViewControl: false, 
        mapTypeId: google.maps.MapTypeId.HYBRID
      });
    var flightPlanCoordinates_DF = MapsConf.DF_Coordinates;

    var flightPath2 = new google.maps.Polyline({
      path: flightPlanCoordinates_DF,
      geodesic: true,
      strokeColor: '#E0FFFF',
      strokeOpacity: 1.0,
      strokeWeight: 2
    });

    flightPath2.setMap(map);

    var currentMarker = new google.maps.Marker({
      position: {lat: 19.381836, lng: -99.1372371},
      map: map,
      title: 'Latitud/Longitud',
      draggable: true
    });

    google.maps.event.addListener(currentMarker, 'dragend', function(evt){
        $(selectors.latitudeSelector).text(evt.latLng.lat().toFixed(3));
        $(selectors.longitudeSelector).text(evt.latLng.lng().toFixed(3));
    });

    google.maps.event.addListener(currentMarker, 'dragstart', function(evt){
        console.log("moving marker!");
    });

  };

  var drawHeatMap = function (data) {
    /*TODO refactor!*/
    var strictBounds = new google.maps.LatLngBounds(
          new google.maps.LatLng(19.600237, -99.403214), 
          new google.maps.LatLng(19.222031, -98.941788)),
        distritoFederal = new google.maps.LatLng(19.381836, -99.1372371),
        map = new google.maps.Map(document.getElementById('map'),{
          zoom: 10,
          center: {lat: 19.45, lng: -99},
          maxZoom: 13,
          minZoom: 8, 
          streetViewControl: false, 
          mapTypeId: google.maps.MapTypeId.HYBRID
        }),
        heatmapData = [],
        coordinates;
    for(var i=0; i < data.weathers.length; i++) {
      coordinates = data.weathers[i].location.coordinates;
      var googleMapsPoint = new google.maps.LatLng(coordinates[1], coordinates[0]);
      heatmapData.push(googleMapsPoint);
    }

    var heatmap = new google.maps.visualization.HeatmapLayer({
      data: heatmapData
    });

    heatmap.setMap(map);

    var flightPlanCoordinates_DF = MapsConf.DF_Coordinates;

    var flightPath2 = new google.maps.Polyline({
      path: flightPlanCoordinates_DF,
      geodesic: true,
      strokeColor: '#E0FFFF',
      strokeOpacity: 1.0,
      strokeWeight: 2
    });

    flightPath2.setMap(map);
    heatmap.set('radius', 40);

    google.maps.event.addListener(map, 'zoom_changed', function() {
     if (map.getZoom() < minZoomLevel) map.setZoom(minZoomLevel);
    });
  };

  var getInformationFromPlace = function (data) {
    var basicInformation = {},
        maxTemperature = "",
        minTemperature = "",
        averageTemperature = "";

    maxTemperature = "" + Math.max.apply(Math,data.weathers.map(function(element){return element.temperature;}));
    minTemperature = "" + Math.min.apply(Math,data.weathers.map(function(element){return element.temperature;}));
    averageTemperature = "" + data.weathers.map(function(obj) {return obj.temperature})
                  .reduce(function(a, b) { return a + b }) / data.weathers.length;

    basicInformation.place = data.weathers[0].fullName;
    basicInformation.maxTemperature = maxTemperature.substring(maxTemperature.indexOf(".") - 3,  maxTemperature.indexOf(".") + 3);
    basicInformation.minTemperature = minTemperature.substring(minTemperature.indexOf(".") - 3,  minTemperature.indexOf(".") + 3);
    basicInformation.averageTemperature = averageTemperature.substring(minTemperature.indexOf(".") - 3,  minTemperature.indexOf(".") + 3);

    return basicInformation;
  };

  var getTemperatureChart = function(data) {
    var ctx = document.getElementById("weatherChart").getContext("2d");
    var chartOptions = {
      scaleBeginAtZero : true,
      scaleShowGridLines : false,
      scaleGridLineColor : "rgba(0,0,0,.05)",
      scaleGridLineWidth : 1,
      scaleShowHorizontalLines: false,
      scaleShowVerticalLines: false,
      barShowStroke : true,
      animation: false,
    }
    var temperatureData = {
        labels: [],
        datasets: []
    };
    var dataSetContent = {
        fillColor: "rgba(220,220,220,0.5)",
        strokeColor: "rgba(220,220,220,0.8)",
        highlightFill: "rgba(220,220,220,0.75)",
        highlightStroke: "rgba(220,220,220,1)",
        data: []
    };
    for(var i=0; i < data.weathers.length; i++) {
      temperatureData.labels.push("");
      dataSetContent.data.push(data.weathers[i].temperature);
    }

    temperatureData.datasets.push(dataSetContent);
    
    var myBarChart = new Chart(ctx).Bar(temperatureData, chartOptions);
  }

  var start = function(){
    //bindEvents();
    WeatherView.render();
    drawMap();

  };

  return{
    start:start
  };

}());
<commit_msg>coding #10 fixing weather controller<commit_after>'use strict';

var Weather = require('../models/weather');
var WeatherView = require('../views/weather_view');
var MapsManagement = require('../conf/maps_management');
var Config = require('../conf/config');

module.exports = (function(){
  
  var WeatherConf = {
    url:Config.hardAntUrl.concat('/weather')
  }

  var selectors = {
    searchForm:'form[name=byLatLng]',
    latitudeInput: "input[name=latitude]",
    longitudeInput: "input[name=longitude]",
    latitudeSelector: ".text-latitude",
    longitudeSelector: ".text-longitude"
  };  

  var searchWeatherByName = function(event){
    event.preventDefault(); 
    //Weather.get({url: WeatherConf.url ,data:$(this).serialize()}).then(success,failure);
  };

  var getWeatherByLatLng = function (event) {
    event.preventDefault();
    Weather.get({url:WeatherConf.url, data: $(this).serialize()}).then(success, failure);
  };

  var success = function(data){
    var placeInformation = getInformationFromPlace(data);    
    WeatherView.render(placeInformation);
    drawHeatMap(data);
    getTemperatureChart(data);
  };
  
  var failure = function(data){
    console.error("Error");
    console.error(data);
  };

  var bindEvents = function(){
    $(selectors.searchForm).on('submit',getWeatherByLatLng); 
  };

  var drawMap = function (){
    window.globalMap = MapsManagement.createMap();

    var currentMarker = new google.maps.Marker({
      position: {lat: 19.381836, lng: -99.1372371},
      map: window.globalMap,
      title: 'Latitud/Longitud',
      draggable: true
    });
    
    google.maps.event.addListener(currentMarker, 'dragend', function(evt){
      $(selectors.latitudeSelector).text(evt.latLng.lat().toFixed(6));
      $(selectors.longitudeSelector).text(evt.latLng.lng().toFixed(6));
      $(selectors.latitudeInput).val(evt.latLng.lat().toFixed(6));
      $(selectors.longitudeInput).val(evt.latLng.lng().toFixed(6));
    });

  };

  var drawHeatMap = function (data) {
    window.globalMap = MapsManagement.createMap();
    var heatmapData = [],
        coordinates;
    for(var i=0; i < data.weathers.length; i++) {
      coordinates = data.weathers[i].location.coordinates;
      var googleMapsPoint = new google.maps.LatLng(coordinates[1], coordinates[0]);
      heatmapData.push(googleMapsPoint);
    }
    if(window.heatMap) {
      window.heatMap.setMap(null); 
    } else {
      window.heatMap = MapsManagement.createMapHeatMap(heatmapData);
    }
    window.heatMap.setMap(window.globalMap);
  };

  var getInformationFromPlace = function (data) {
    var basicInformation = {},
        maxTemperature = "",
        minTemperature = "",
        averageTemperature = "";

    maxTemperature = "" + Math.max.apply(Math,data.weathers.map(function(element){return element.temperature;}));
    minTemperature = "" + Math.min.apply(Math,data.weathers.map(function(element){return element.temperature;}));
    averageTemperature = "" + data.weathers.map(function(obj) {return obj.temperature})
      .reduce(function(a, b) { return a + b }) / data.weathers.length;

    basicInformation.place = data.weathers[0].fullName;
    basicInformation.maxTemperature = maxTemperature.substring(maxTemperature.indexOf(".") - 3, maxTemperature.indexOf(".") + 3);
    basicInformation.minTemperature = minTemperature.substring(minTemperature.indexOf(".") - 3, minTemperature.indexOf(".") + 3);
    basicInformation.averageTemperature = averageTemperature.substring(minTemperature.indexOf(".") - 3, minTemperature.indexOf(".") + 3);

    return basicInformation;    
  };

  var getTemperatureChart = function(data) {
    var ctx = document.getElementById("weatherChart").getContext("2d");
    var chartOptions = {
      scaleBeginAtZero : true,
      scaleShowGridLines : false,
      scaleGridLineColor : "rgba(0,0,0,.05)",
      scaleGridLineWidth : 1,
      scaleShowHorizontalLines: false,
      scaleShowVerticalLines: false,
      barShowStroke : true,
      animation: false,
    }

    var temperatureData = {
      labels: [],
      datasets: []
    };

    var dataSetContent = {
      fillColor: "rgba(220,220,220,0.5)",
      strokeColor: "rgba(220,220,220,0.8)",
      highlightFill: "rgba(220,220,220,0.75)",
      highlightStroke: "rgba(220,220,220,1)",
      data: []
    };

    for(var i=0; i < data.weathers.length; i++) {
      temperatureData.labels.push("");
      dataSetContent.data.push(data.weathers[i].temperature);
    }

    temperatureData.datasets.push(dataSetContent);

    var myBarChart = new Chart(ctx).Bar(temperatureData, chartOptions);

  }

  var start = function(){
    WeatherView.render(false);
    drawMap();
    bindEvents();
  };

  return{
    start:start
  };

}());

{'fraction_non_alphanumeric': 0.1495457073984795, 'fraction_numerical': 0.023270906730947526, 'mean_word_length': 3.3425925925925926, 'pattern_counts': {'":': 0, '<': 8, '<?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': '3304302', 'n_tokens_mistral': 3576, 'n_tokens_neox': 3355, 'n_words': 544}