<commit_before>var widget_thermostat = {
  elements: null,
  _thermostat:null,
  getClimaValues: function (device) {

	var state = getDeviceValue( device, '');
	var desi = getDeviceValue( device, 'get');
	return {
		temp: getDeviceValue( device, 'temp'),
		desired: ( state && state.indexOf('set_') < 0 ) ? desi : getPart(state,2),
		valve: getDeviceValue( device, 'valve')
	};
},
  getGradientColor: function(start_color, end_color, percent) {
   // strip the leading # if it's there
   start_color = start_color.replace(/^\s*#|\s*$/g, '');
   end_color = end_color.replace(/^\s*#|\s*$/g, '');

   // convert 3 char codes --> 6, e.g. `E0F` --> `EE00FF`
   if(start_color.length == 3){
     start_color = start_color.replace(/(.)/g, '$1$1');
   }

   if(end_color.length == 3){
     end_color = end_color.replace(/(.)/g, '$1$1');
   }

   // get colors
   var start_red = parseInt(start_color.substr(0, 2), 16),
       start_green = parseInt(start_color.substr(2, 2), 16),
       start_blue = parseInt(start_color.substr(4, 2), 16);

   var end_red = parseInt(end_color.substr(0, 2), 16),
       end_green = parseInt(end_color.substr(2, 2), 16),
       end_blue = parseInt(end_color.substr(4, 2), 16);

   // calculate new color
   var diff_red = end_red - start_red;
   var diff_green = end_green - start_green;
   var diff_blue = end_blue - start_blue;

   diff_red = ( (diff_red * percent) + start_red ).toString(16).split('.')[0];
   diff_green = ( (diff_green * percent) + start_green ).toString(16).split('.')[0];
   diff_blue = ( (diff_blue * percent) + start_blue ).toString(16).split('.')[0];

   // ensure 2 digits by color
   if( diff_red.length == 1 )
     diff_red = '0' + diff_red

   if( diff_green.length == 1 )
     diff_green = '0' + diff_green

   if( diff_blue.length == 1 )
     diff_blue = '0' + diff_blue

   return '#' + diff_red + diff_green + diff_blue;
 },
  drawDial: function () {
  	var c = this.g, // context
	a = this.arc(this.cv), // Arc
	pa, // Previous arc
	r = 1;

	c.lineWidth = this.lineWidth;
	c.lineCap = this.lineCap;
	if (this.o.bgColor !== "none") {
		c.beginPath();
		c.strokeStyle = this.o.bgColor;
		c.arc(this.xy, this.xy, this.radius, this.endAngle - 0.00001, this.startAngle + 0.00001, true);
		c.stroke();
	}
	
	var tick_w = (2 * Math.PI) / 360;
	var step =  (this.o.max - this.o.min) / this.angleArc;
	var acAngle = ((this.o.isValue - this.o.min) / step) + this.startAngle;
	var dist = this.o.tickdistance || 4;
	var mincolor = this.o.minColor || '#ff0000';
	var maxcolor = this.o.maxColor || '#4477ff';
	
	// draw ticks
	for (tick = this.startAngle; tick < this.endAngle + 0.00001; tick+=tick_w*dist) {
		i = step * (tick-this.startAngle)+this.o.min;
		
		c.beginPath();
		
		if ((tick > acAngle && tick < a.s) || (tick-tick_w*4 <= acAngle && tick+tick_w*4 >= a.s)){
			// draw diff range in gradient color
			c.strokeStyle = _thermostat.getGradientColor(maxcolor, mincolor, (this.endAngle-tick)/this.angleArc);   
		}
		else {
			// draw normal ticks
			c.strokeStyle = this.o.tkColor;//'#4477ff';
		}
		
		// thicker lines every 5 ticks
		if ( Math.round(i*10)/10 % 5 == 0 ){ 
			w = tick_w*2;
			w *= (c.strokeStyle != this.o.tkColor) ? 1.5 : 1; 
		}
		else {
			w = tick_w;
			w *= (c.strokeStyle != this.o.tkColor) ? 2 : 1;
		}
		// thicker lines every at current value
		if (acAngle > tick-tick_w && acAngle < tick+tick_w)
			w *= 1.9;	
			
		c.arc( this.xy, this.xy, this.radius, tick, tick+w , false);
		c.stroke();
	}

	// draw target temp cursor
	c.beginPath();
	this.o.fgColor= _thermostat.getGradientColor(maxcolor, mincolor, (this.endAngle-a.e)/(this.endAngle-this.startAngle));
	c.strokeStyle = r ? this.o.fgColor : this.fgColor;
	c.lineWidth = this.lineWidth * 2;
	c.arc(this.xy, this.xy, this.radius-this.lineWidth/2, a.s, a.e, a.d);
	c.stroke();

	//draw current value as text
    var x = this.radius*0.7*Math.cos(acAngle);
    var y = this.radius*0.7*Math.sin(acAngle);
    c.fillStyle = this.o.tkColor;
    c.font="10px sans-serif";
    c.fillText(this.o.isValue ,this.xy+x-5,this.xy+y+5);
  
	//draw valve value as text
	if ( this.o.valveValue ) {
		var x = -5;
		var y = this.radius*0.55;
		c.fillStyle = this.o.tkColor;
		c.font="10px sans-serif";
		c.fillText(this.o.valveValue+'%',this.xy+x,this.xy+y+5);
    }
  return false;
},
  init: function () {
  	_thermostat=this;
	_thermostat.elements=$('div[data-type="thermostat"]');
	_thermostat.elements.each(function( index ) {
		var knob_elem =  jQuery('<input/>', {
			type: 'text',
			value: '10',
			disabled : true,
		}).appendTo($(this));
		  
		var device = $(this).data('device');  
		//default reading parameter name
		$(this).data('get', $(this).data('get') || 'desired-temp');
		$(this).data('temp', $(this).data('temp') || 'measured-temp');
		readings[$(this).data('get')] = true;
		readings[$(this).data('temp')] = true;
		readings[$(this).data('valve')] = true;
		
		knob_elem.knob({
			'min':10,
			'max':30,
			'height':$(this).hasClass('big')?150:100,
			'width':$(this).hasClass('big')?150:100,
			'step': 1*$(this).data('step') || 1,
			'angleOffset': $(this).data('angleoffset') || -120,
			'angleArc': $(this).data('anglearc') || 240,
			'bgColor': $(this).data('bgcolor') || 'transparent',
			'fgColor': $(this).data('fgcolor') || '#cccccc',
			'tkColor': $(this).data('tkcolor') || '#696969',
			'minColor': '#4477ff',
			'maxColor': '#ff0000',<commit_msg>Added data-min,data-max for thermostat<commit_after>var widget_thermostat = {
  elements: null,
  _thermostat:null,
  getClimaValues: function (device) {

	var state = getDeviceValue( device, '');
	var desi = getDeviceValue( device, 'get');
	return {
		temp: getDeviceValue( device, 'temp'),
		desired: ( state && state.indexOf('set_') < 0 ) ? desi : getPart(state,2),
		valve: getDeviceValue( device, 'valve')
	};
},
  getGradientColor: function(start_color, end_color, percent) {
   // strip the leading # if it's there
   start_color = start_color.replace(/^\s*#|\s*$/g, '');
   end_color = end_color.replace(/^\s*#|\s*$/g, '');

   // convert 3 char codes --> 6, e.g. `E0F` --> `EE00FF`
   if(start_color.length == 3){
     start_color = start_color.replace(/(.)/g, '$1$1');
   }

   if(end_color.length == 3){
     end_color = end_color.replace(/(.)/g, '$1$1');
   }

   // get colors
   var start_red = parseInt(start_color.substr(0, 2), 16),
       start_green = parseInt(start_color.substr(2, 2), 16),
       start_blue = parseInt(start_color.substr(4, 2), 16);

   var end_red = parseInt(end_color.substr(0, 2), 16),
       end_green = parseInt(end_color.substr(2, 2), 16),
       end_blue = parseInt(end_color.substr(4, 2), 16);

   // calculate new color
   var diff_red = end_red - start_red;
   var diff_green = end_green - start_green;
   var diff_blue = end_blue - start_blue;

   diff_red = ( (diff_red * percent) + start_red ).toString(16).split('.')[0];
   diff_green = ( (diff_green * percent) + start_green ).toString(16).split('.')[0];
   diff_blue = ( (diff_blue * percent) + start_blue ).toString(16).split('.')[0];

   // ensure 2 digits by color
   if( diff_red.length == 1 )
     diff_red = '0' + diff_red

   if( diff_green.length == 1 )
     diff_green = '0' + diff_green

   if( diff_blue.length == 1 )
     diff_blue = '0' + diff_blue

   return '#' + diff_red + diff_green + diff_blue;
 },
  drawDial: function () {
  	var c = this.g, // context
	a = this.arc(this.cv), // Arc
	pa, // Previous arc
	r = 1;

	c.lineWidth = this.lineWidth;
	c.lineCap = this.lineCap;
	if (this.o.bgColor !== "none") {
		c.beginPath();
		c.strokeStyle = this.o.bgColor;
		c.arc(this.xy, this.xy, this.radius, this.endAngle - 0.00001, this.startAngle + 0.00001, true);
		c.stroke();
	}
	
	var tick_w = (2 * Math.PI) / 360;
	var step =  (this.o.max - this.o.min) / this.angleArc;
	var acAngle = ((this.o.isValue - this.o.min) / step) + this.startAngle;
	var dist = this.o.tickdistance || 4;
	var mincolor = this.o.minColor || '#ff0000';
	var maxcolor = this.o.maxColor || '#4477ff';
	
	// draw ticks
	for (tick = this.startAngle; tick < this.endAngle + 0.00001; tick+=tick_w*dist) {
		i = step * (tick-this.startAngle)+this.o.min;
		
		c.beginPath();
		
		if ((tick > acAngle && tick < a.s) || (tick-tick_w*4 <= acAngle && tick+tick_w*4 >= a.s)){
			// draw diff range in gradient color
			c.strokeStyle = _thermostat.getGradientColor(maxcolor, mincolor, (this.endAngle-tick)/this.angleArc);   
		}
		else {
			// draw normal ticks
			c.strokeStyle = this.o.tkColor;//'#4477ff';
		}
		
		// thicker lines every 5 ticks
		if ( Math.round(i*10)/10 % 5 == 0 ){ 
			w = tick_w*2;
			w *= (c.strokeStyle != this.o.tkColor) ? 1.5 : 1; 
		}
		else {
			w = tick_w;
			w *= (c.strokeStyle != this.o.tkColor) ? 2 : 1;
		}
		// thicker lines every at current value
		if (acAngle > tick-tick_w && acAngle < tick+tick_w)
			w *= 1.9;	
			
		c.arc( this.xy, this.xy, this.radius, tick, tick+w , false);
		c.stroke();
	}

	// draw target temp cursor
	c.beginPath();
	this.o.fgColor= _thermostat.getGradientColor(maxcolor, mincolor, (this.endAngle-a.e)/(this.endAngle-this.startAngle));
	c.strokeStyle = r ? this.o.fgColor : this.fgColor;
	c.lineWidth = this.lineWidth * 2;
	c.arc(this.xy, this.xy, this.radius-this.lineWidth/2, a.s, a.e, a.d);
	c.stroke();

	//draw current value as text
    var x = this.radius*0.7*Math.cos(acAngle);
    var y = this.radius*0.7*Math.sin(acAngle);
    c.fillStyle = this.o.tkColor;
    c.font="10px sans-serif";
    c.fillText(this.o.isValue ,this.xy+x-5,this.xy+y+5);
  
	//draw valve value as text
	if ( this.o.valveValue ) {
		var x = -5;
		var y = this.radius*0.55;
		c.fillStyle = this.o.tkColor;
		c.font="10px sans-serif";
		c.fillText(this.o.valveValue+'%',this.xy+x,this.xy+y+5);
    }
  return false;
},
  init: function () {
  	_thermostat=this;
	_thermostat.elements=$('div[data-type="thermostat"]');
	_thermostat.elements.each(function( index ) {
		var knob_elem =  jQuery('<input/>', {
			type: 'text',
			value: '10',
			disabled : true,
		}).appendTo($(this));
		  
		var device = $(this).data('device');  
		//default reading parameter name
		$(this).data('get', $(this).data('get') || 'desired-temp');
		$(this).data('temp', $(this).data('temp') || 'measured-temp');
		readings[$(this).data('get')] = true;
		readings[$(this).data('temp')] = true;
		readings[$(this).data('valve')] = true;
		
		knob_elem.knob({
			'min':1*$(this).data('min') || 10,
			'max':1*$(this).data('max') || 30,
			'height':$(this).hasClass('big')?150:100,
			'width':$(this).hasClass('big')?150:100,
			'step': 1*$(this).data('step') || 1,
			'angleOffset': $(this).data('angleoffset') || -120,
			'angleArc': $(this).data('anglearc') || 240,
			'bgColor': $(this).data('bgcolor') || 'transparent',
			'fgColor': $(this).data('fgcolor') || '#cccccc',
			'tkColor': $(this).data('tkcolor') || '#696969',
			'minColor': '#4477ff',
			'maxColor': '#ff0000',
{'fraction_non_alphanumeric': 0.1989706828416506, 'fraction_numerical': 0.030144288208804337, 'mean_word_length': 3.3285600636435957, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '7212967', 'n_tokens_mistral': 4660, 'n_tokens_neox': 4194, 'n_words': 834}