<commit_before>﻿// Copyright (c) 2007-2017 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites;
using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using System.Globalization;
using System.Linq;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Framework.Threading;
using System;

namespace osu.Game.Screens.Select
{
    public class BeatmapDetails : Container
    {
        private readonly MetadataSegment description;
        private readonly MetadataSegment source;
        private readonly MetadataSegment tags;

        private readonly DifficultyRow circleSize;
        private readonly DifficultyRow drainRate;
        private readonly DifficultyRow overallDifficulty;
        private readonly DifficultyRow approachRate;
        private readonly DifficultyRow stars;

        private readonly Container ratingsContainer;
        private readonly Bar ratingsBar;
        private readonly OsuSpriteText negativeRatings;
        private readonly OsuSpriteText positiveRatings;
        private readonly BarGraph ratingsGraph;

        private readonly FillFlowContainer retryFailContainer;
        private readonly BarGraph retryGraph;
        private readonly BarGraph failGraph;

        private ScheduledDelegate pendingBeatmapSwitch;
        private BeatmapInfo beatmap;

        public BeatmapInfo Beatmap
        {
            get { return beatmap; }
            set
            {
                beatmap = value;

                pendingBeatmapSwitch?.Cancel();
                pendingBeatmapSwitch = Schedule(updateStats);
            }
        }

        private void updateStats()
        {
            description.Text = beatmap.Version;
            source.Text = beatmap.Metadata.Source;
            tags.Text = beatmap.Metadata.Tags;

            circleSize.Value = beatmap.Difficulty.CircleSize;
            drainRate.Value = beatmap.Difficulty.DrainRate;
            overallDifficulty.Value = beatmap.Difficulty.OverallDifficulty;
            approachRate.Value = beatmap.Difficulty.ApproachRate;
            stars.Value = (float)beatmap.StarDifficulty;

            var requestedBeatmap = beatmap;
            if (requestedBeatmap.Metrics == null)
            {
                var lookup = new GetBeatmapDeatilsRequest(requestedBeatmap);
                lookup.Success += res =>
                {
                    if (beatmap != requestedBeatmap)
                            //the beatmap has been changed since we started the lookup.
                            return;<commit_msg>Fix nullref possibility.<commit_after>﻿// Copyright (c) 2007-2017 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites;
using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using System.Globalization;
using System.Linq;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Framework.Threading;
using System;

namespace osu.Game.Screens.Select
{
    public class BeatmapDetails : Container
    {
        private readonly MetadataSegment description;
        private readonly MetadataSegment source;
        private readonly MetadataSegment tags;

        private readonly DifficultyRow circleSize;
        private readonly DifficultyRow drainRate;
        private readonly DifficultyRow overallDifficulty;
        private readonly DifficultyRow approachRate;
        private readonly DifficultyRow stars;

        private readonly Container ratingsContainer;
        private readonly Bar ratingsBar;
        private readonly OsuSpriteText negativeRatings;
        private readonly OsuSpriteText positiveRatings;
        private readonly BarGraph ratingsGraph;

        private readonly FillFlowContainer retryFailContainer;
        private readonly BarGraph retryGraph;
        private readonly BarGraph failGraph;

        private ScheduledDelegate pendingBeatmapSwitch;
        private BeatmapInfo beatmap;

        public BeatmapInfo Beatmap
        {
            get { return beatmap; }
            set
            {
                beatmap = value;

                pendingBeatmapSwitch?.Cancel();
                pendingBeatmapSwitch = Schedule(updateStats);
            }
        }

        private void updateStats()
        {
            if (beatmap == null) return;

            description.Text = beatmap.Version;
            source.Text = beatmap.Metadata.Source;
            tags.Text = beatmap.Metadata.Tags;

            circleSize.Value = beatmap.Difficulty.CircleSize;
            drainRate.Value = beatmap.Difficulty.DrainRate;
            overallDifficulty.Value = beatmap.Difficulty.OverallDifficulty;
            approachRate.Value = beatmap.Difficulty.ApproachRate;
            stars.Value = (float)beatmap.StarDifficulty;

            var requestedBeatmap = beatmap;
            if (requestedBeatmap.Metrics == null)
            {
                var lookup = new GetBeatmapDeatilsRequest(requestedBeatmap);
                lookup.Success += res =>
                {
                    if (beatmap != requestedBeatmap)
                            //the beatmap has been changed since we started the lookup.
                            return;
{'fraction_non_alphanumeric': 0.06599072005499226, 'fraction_numerical': 0.002749613335624678, 'mean_word_length': 2.395565927654609, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '3735852', 'n_tokens_mistral': 1520, 'n_tokens_neox': 1449, 'n_words': 367}