function sensor_data_collection() {
  var controllerId = Session.get('controller_id');
  return SensorData.find({
    controllerId: controllerId
  }, {
    sort: {
      created_at: -1
    },
    limit: 100
  });
}

Template.log.helpers({
  sensorDataCollection: sensor_data_collection
});

Template.log.events({
  'click clear_log': function() {
    Meteor.call('clearLog');
  }
});

Template.sensorData.helpers({
  created_at_formatted: function() {
    return moment(this.created_at).format(/*"DD.MM.YYYY, */ " (HH:mm)")
  },
  all_temperatures: function(temperatures) {
    var result = '';
    if (temperatures.length > 0) {
      for (var i in temperatures) {
        result += '' + parseFloat(temperatures[i]).toFixed(1) + ' °C  ';
      }
    }
    return result;
  }
});
