<commit_before><script>
	window.Cosmoz = window.Cosmoz || {};

	/** @polymerBehavior */
	Cosmoz.RangeColumnBehavior = {
		properties: {
			bindValues: {
				type: Boolean,
				readOnly: true,
				value: true
			},

			values: {
				type: Array,
				value: function () {
					return [];
				}
			},

			min: {
				type: Number,
				value: null
			},

			max: {
				type: Number,
				value: null
			},

			locale: {
				type: String,
				value: null
			},

			_filterInput: {
				type: Object,
				value() {
					return { min: null, max: null };
				}
			},

			_range: {
				type: Object,
				computed: '_computeRange(values.*)'
			},

			_limit: {
				type: Object,
				computed: '_computeLimit(_range, _filterInput.*, min, max)',
				value() {
					return {};
				}
			},

			_tooltip: {
				type: String,
				computed: '_computeTooltip(title, _filterText)'
			},
		},

		observers: [
			'_filterInputChanged(_filterInput.*)',
			'_filterChanged(filter.*)'
		],

		detached() {
			this.cancelDebouncer('_limitInput');
		},

		/**
		 * Converts a value to number optionaly limiting it.
		 *
		 * @param  {Number|*} value  The value to convert to number
		 * @param  {Number|*} limit  The value used to limit the number
		 * @param  {Function} limitFunc  The function used to limit the number (Math.min|Math.max)
		 * @returns {Number|void}    Value converted to Number or void
		 */
		toNumber(value, limit, limitFunc) {
			if (value == null || value === '') {
				return;
			}
			const number = typeof value === 'number' ? value : Number(value);
			if (Number.isNaN(number)) {
				return;
			}
			if (limitFunc == null || limit == null) {
				return number;
			}
			let lNumber = this.toNumber(limit);
			if (lNumber == null) {
				return number;
			}
			return limitFunc(number, lNumber);
		},

		toValue() {
			return this.toNumber.apply(this, arguments);
		},

		/**
		 *   Get the comparable value of an item.
		 *
		 * @param  {Object} item       Item to be processed
		 * @param  {String} valuePath  Property path
		 * @returns {Number|void}      Valid value or void
		 */
		getComparableValue(item, valuePath) {
			if (item == null) {
				return;
			}
			let value = item;
			if (valuePath != null) {
				value = this.get(valuePath, item);
			}
			return this.toValue(value);
		},

		toXlsxValue: function (item, valuePath = this.valuePath) {
			const value = this.getComparableValue(item, valuePath);
			if (value == null) {
				return '';
			}
			return value;
		},

		getString(item, valuePath = this.valuePath) {
			if (valuePath === undefined) {
				console.error(this, 'has undefined valuePath', valuePath, 'for item', item);
				return;
			}
			const value = this.get(valuePath, item);
			if (value == null) {
				return '';
			}
			return this.renderValue(value);
		},
		renderValue() {
			//overrideable
		},

		getInputString(item, valuePath = this.valuePath) {
			const value = this.toValue(this.get(valuePath, item));
			return this._toInputString(value);
		},

		/**
		 * Computes min/max range from values.
		 *
		 * @param  {Object} change `values` property changes
		 * @returns {Object} Computed min/max
		 */
		_computeRange(change) {
			const allValues = change.base,
				values = Array.isArray(allValues) && allValues.length
				&& allValues.map(v => this.toValue(v)).filter(n => n != null);

			if (!values || values.length < 1) {
				return {
					min: null,
					max: null
				};
			}
			return values.reduce((p, n) => {
				return {
					min: this.toValue(n, p.min, Math.min),
					max: this.toValue(n, p.max, Math.max)
				};
			}, {});
		},

		_computeLimit(range, inputChange, min, max) {
			if (!range) {
				return;
			}
			const input = inputChange.base,
				nMin = this.toValue(min),
				nMax = this.toValue(max);
			return {
				fromMin: nMin != null ? nMin : this.toValue(range.min),
				fromMax: this.toValue(range.max, this._fromInputString(input.max, 'max'), Math.min),
				toMin: this.toValue(range.min, this._fromInputString(input.min, 'min'), Math.max),
				toMax: nMax != null ? nMax : this.toValue(range.max)<commit_msg>Refactor computeLimit to use min/max<commit_after><script>
	window.Cosmoz = window.Cosmoz || {};

	/** @polymerBehavior */
	Cosmoz.RangeColumnBehavior = {
		properties: {
			bindValues: {
				type: Boolean,
				readOnly: true,
				value: true
			},

			values: {
				type: Array,
				value: function () {
					return [];
				}
			},

			min: {
				type: Number,
				value: null
			},

			max: {
				type: Number,
				value: null
			},

			locale: {
				type: String,
				value: null
			},

			_filterInput: {
				type: Object,
				value() {
					return { min: null, max: null };
				}
			},

			_range: {
				type: Object,
				computed: '_computeRange(values.*)'
			},

			_limit: {
				type: Object,
				computed: '_computeLimit(_range, _filterInput.*, min, max)',
				value() {
					return {};
				}
			},

			_tooltip: {
				type: String,
				computed: '_computeTooltip(title, _filterText)'
			},
		},

		observers: [
			'_filterInputChanged(_filterInput.*)',
			'_filterChanged(filter.*)'
		],

		detached() {
			this.cancelDebouncer('_limitInput');
		},

		/**
		 * Converts a value to number optionaly limiting it.
		 *
		 * @param  {Number|*} value  The value to convert to number
		 * @param  {Number|*} limit  The value used to limit the number
		 * @param  {Function} limitFunc  The function used to limit the number (Math.min|Math.max)
		 * @returns {Number|void}    Value converted to Number or void
		 */
		toNumber(value, limit, limitFunc) {
			if (value == null || value === '') {
				return;
			}
			const number = typeof value === 'number' ? value : Number(value);
			if (Number.isNaN(number)) {
				return;
			}
			if (limitFunc == null || limit == null) {
				return number;
			}
			let lNumber = this.toNumber(limit);
			if (lNumber == null) {
				return number;
			}
			return limitFunc(number, lNumber);
		},

		toValue() {
			return this.toNumber.apply(this, arguments);
		},

		/**
		 *   Get the comparable value of an item.
		 *
		 * @param  {Object} item       Item to be processed
		 * @param  {String} valuePath  Property path
		 * @returns {Number|void}      Valid value or void
		 */
		getComparableValue(item, valuePath) {
			if (item == null) {
				return;
			}
			let value = item;
			if (valuePath != null) {
				value = this.get(valuePath, item);
			}
			return this.toValue(value);
		},

		toXlsxValue: function (item, valuePath = this.valuePath) {
			const value = this.getComparableValue(item, valuePath);
			if (value == null) {
				return '';
			}
			return value;
		},

		getString(item, valuePath = this.valuePath) {
			if (valuePath === undefined) {
				console.error(this, 'has undefined valuePath', valuePath, 'for item', item);
				return;
			}
			const value = this.get(valuePath, item);
			if (value == null) {
				return '';
			}
			return this.renderValue(value);
		},
		renderValue() {
			//overrideable
		},

		getInputString(item, valuePath = this.valuePath) {
			const value = this.toValue(this.get(valuePath, item));
			return this._toInputString(value);
		},

		/**
		 * Computes min/max range from values.
		 *
		 * @param  {Object} change `values` property changes
		 * @returns {Object} Computed min/max
		 */
		_computeRange(change) {
			const allValues = change.base,
				values = Array.isArray(allValues) && allValues.length
				&& allValues.map(v => this.toValue(v)).filter(n => n != null);

			if (!values || values.length < 1) {
				return {
					min: null,
					max: null
				};
			}
			return values.reduce((p, n) => {
				return {
					min: this.toValue(n, p.min, Math.min),
					max: this.toValue(n, p.max, Math.max)
				};
			}, {});
		},

		_computeLimit(range, inputChange, min, max) {
			if (!range) {
				return;
			}
			const input = inputChange.base,
				nMin = this.toValue(min),
				nMax = this.toValue(max),
				aMin = nMin != null ? nMin : this.toValue(range.min),
				aMax = nMax != null ? nMax : this.toValue(range.max);
			return {
				fromMin: aMin,
				fromMax: this.toValue(aMax, this._fromInputString(input.max, 'max'), Math.min),
				toMin: this.toValue(aMin, this._fromInputString(input.min, 'min'), Math.max),
				toMax: aMax
{'fraction_non_alphanumeric': 0.14844227244960292, 'fraction_numerical': 0.0002443494196701283, 'mean_word_length': 2.641459074733096, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '1358460', 'n_tokens_mistral': 3474, 'n_tokens_neox': 2718, 'n_words': 667}