<commit_before>﻿// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Collections.Generic;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Users;
using static osu.Game.Users.User;

namespace osu.Game.Overlays.Profile.Sections.Historical
{
    public abstract class ChartProfileSubsection : ProfileSubsection
    {
        private ProfileLineChart chart;

        protected ChartProfileSubsection(Bindable<User> user, string headerText)
            : base(user, headerText)
        {
        }

        protected override Drawable CreateContent() => new Container
        {
            RelativeSizeAxes = Axes.X,
            AutoSizeAxes = Axes.Y,
            Padding = new MarginPadding
            {
                Top = 10,
                Left = 20,
                Right = 40
            },
            Child = chart = new ProfileLineChart()
        };

        protected override void LoadComplete()
        {
            base.LoadComplete();
            User.BindValueChanged(onUserChanged, true);
        }

        private void onUserChanged(ValueChangedEvent<User> e)
        {
            var values = GetValues(e.NewValue);

            if (values?.Length > 1)
            {
                // Fill dates with 0 count

                var newValues = new List<UserHistoryCount> { values[0] };
                var newLast = values[0];

                for (int i = 1; i < values.Length; i++)
                {
                    while (hasMissingDates(newLast, values[i]))
                    {
                        newValues.Add(newLast = new UserHistoryCount
                        {
                            Count = 0,
                            Date = newLast.Date.AddMonths(1)
                        });
                    }

                    newValues.Add(newLast = values[i]);
                }

                static bool hasMissingDates(UserHistoryCount prev, UserHistoryCount current)
                {
                    var possibleCurrent = prev.Date.AddMonths(1);
                    return possibleCurrent != current.Date;
                }

                chart.Values = newValues.ToArray();
                Show();
                return;
            }

            Hide();
        }

        protected abstract UserHistoryCount[] GetValues(User user);
    }<commit_msg>Move dates fill into it's own method<commit_after>﻿// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Collections.Generic;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Users;
using static osu.Game.Users.User;

namespace osu.Game.Overlays.Profile.Sections.Historical
{
    public abstract class ChartProfileSubsection : ProfileSubsection
    {
        private ProfileLineChart chart;

        protected ChartProfileSubsection(Bindable<User> user, string headerText)
            : base(user, headerText)
        {
        }

        protected override Drawable CreateContent() => new Container
        {
            RelativeSizeAxes = Axes.X,
            AutoSizeAxes = Axes.Y,
            Padding = new MarginPadding
            {
                Top = 10,
                Left = 20,
                Right = 40
            },
            Child = chart = new ProfileLineChart()
        };

        protected override void LoadComplete()
        {
            base.LoadComplete();
            User.BindValueChanged(onUserChanged, true);
        }

        private void onUserChanged(ValueChangedEvent<User> e)
        {
            var values = GetValues(e.NewValue);

            if (values?.Length > 1)
            {
                chart.Values = fillZeroValues(values);
                Show();
                return;
            }

            Hide();
        }

        private UserHistoryCount[] fillZeroValues(UserHistoryCount[] values)
        {
            var newValues = new List<UserHistoryCount> { values[0] };
            var newLast = values[0];

            for (int i = 1; i < values.Length; i++)
            {
                while (hasMissingDates(newLast, values[i]))
                {
                    newValues.Add(newLast = new UserHistoryCount
                    {
                        Count = 0,
                        Date = newLast.Date.AddMonths(1)
                    });
                }

                newValues.Add(newLast = values[i]);
            }

            return newValues.ToArray();

            static bool hasMissingDates(UserHistoryCount prev, UserHistoryCount current)
            {
                var possibleCurrent = prev.Date.AddMonths(1);
                return possibleCurrent != current.Date;
            }
        }

        protected abstract UserHistoryCount[] GetValues(User user);
    }
{'fraction_non_alphanumeric': 0.08293460925039872, 'fraction_numerical': 0.005382775119617225, 'mean_word_length': 1.4799802273850717, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '5108489', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1208, 'n_words': 303}