<commit_before>﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace AppLib.WPF.Converters
{
    /// <summary>
    /// Converts a long value to a human readable File size
    /// </summary>
    public class FileSizeConverter : ConverterBase<FileSizeConverter>, IValueConverter
    {
        /// <summary>
        /// Calculate a file size in bytes to a human readable size
        /// </summary>
        /// <param name="value">long input value</param>
        /// <returns>Human readable file size</returns>
        public static string Calculate(long value)
        {
            double val = System.Convert.ToDouble(value);
            string unit = "Byte";
            if (val > 1099511627776D)
            {
                val /= 1099511627776D;
                unit = "TiB";
            }
            else if (val > 1073741824D)
            {
                val /= 1073741824D;
                unit = "GiB";
            }
            else if (val > 1048576D)
            {
                val /= 1048576D;
                unit = "MiB";
            }
            else if (val > 1024D)
            {
                val /= 1024D;
                unit = "kiB";
            }
            return string.Format("{0:0.000} {1}", val, unit);
        }

        /// <summary>
        /// Converts a long value to a human readable File size
        /// </summary>
        /// <param name="value">The value produced by the binding source.</param>
        /// <param name="targetType">The type of the binding target property.</param>
        /// <param name="parameter">The converter parameter to use.</param>
        /// <param name="culture">The culture to use in the converter.</param>
        /// <returns>string, file size as a readable file size</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var ip = System.Convert.ToInt64(value);
            return Calculate(ip);
        }

        /// <summary>
        /// Returns the unmodified input
        /// </summary>
        /// <param name="value">The value produced by the binding source.</param>
        /// <param name="targetType">The type of the binding target property.</param>
        /// <param name="parameter">The converter parameter to use.</param>
        /// <param name="culture">The culture to use in the converter.</param>
        /// <returns>string, file size</returns>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {<commit_msg>File size converter change<commit_after>﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace AppLib.WPF.Converters
{
    /// <summary>
    /// Converts a long value to a human readable File size
    /// </summary>
    public class FileSizeConverter : ConverterBase<FileSizeConverter>, IValueConverter
    {
        /// <summary>
        /// Calculate a file size in bytes to a human readable size
        /// </summary>
        /// <param name="value">long input value</param>
        /// <returns>Human readable file size</returns>
        public static string Calculate(long value)
        {
            double val = System.Convert.ToDouble(value);
            string unit = "Byte";
            if (val > 1099511627776D)
            {
                val /= 1099511627776D;
                unit = "TiB";
            }
            else if (val > 1073741824D)
            {
                val /= 1073741824D;
                unit = "GiB";
            }
            else if (val > 1048576D)
            {
                val /= 1048576D;
                unit = "MiB";
            }
            else if (val > 1024D)
            {
                val /= 1024D;
                unit = "kiB";
            }
            return string.Format("{0:0.###} {1}", val, unit);
        }

        /// <summary>
        /// Converts a long value to a human readable File size
        /// </summary>
        /// <param name="value">The value produced by the binding source.</param>
        /// <param name="targetType">The type of the binding target property.</param>
        /// <param name="parameter">The converter parameter to use.</param>
        /// <param name="culture">The culture to use in the converter.</param>
        /// <returns>string, file size as a readable file size</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var ip = System.Convert.ToInt64(value);
            return Calculate(ip);
        }

        /// <summary>
        /// Returns the unmodified input
        /// </summary>
        /// <param name="value">The value produced by the binding source.</param>
        /// <param name="targetType">The type of the binding target property.</param>
        /// <param name="parameter">The converter parameter to use.</param>
        /// <param name="culture">The culture to use in the converter.</param>
        /// <returns>string, file size</returns>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
{'fraction_non_alphanumeric': 0.11872942087933372, 'fraction_numerical': 0.028859190393182257, 'mean_word_length': 1.6867845993756503, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 77, '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': '4927389', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1295, 'n_words': 417}