Пример #1
0
        /// <summary>
        /// Uses the Tensorflow model to predict the most exciting moment.
        /// Returns metadata about the highlight.
        /// </summary>
        /// <param name="matchMetricGroup"></param>
        /// <returns></returns>
        public HighlightInfo GetHighlightPeriod(MatchMetricGroup matchMetricGroup, bool testConfiguration = false)
        {
            if (testConfiguration)
            {
                _deepLearnerScriptPath = ConfigurationManager.AppSettings["AltScriptsPath"] + "DeepLearningModel.py";
            }

            // Packages matchMetricGroup info into a chunked up form that Tensorflow can understand and creates a csv file for the Tensorflow python script to reference.
            var(matchPath, predictedDataPath) = PrepareMatchForTensorFlow(matchMetricGroup, false);

            // Runs the python script that outputs a csv file for the predictions the Tensorflow model made about the excitement level at a particular time in the match.
            GetHighlightInfo(matchPath, predictedDataPath);

            // Load in the predictions made by the model.
            List <string> predictedDataRaw;

            try
            {
                predictedDataRaw = File.ReadAllLines(_tensorflowPath + "Predictions\\" + predictedDataPath).ToList();
            }
            catch (Exception)
            {
                // Very rare edge case when multiple parallel uses of the model can cause a failure to predict.
                GetHighlightInfo(matchPath, predictedDataPath);
                predictedDataRaw = File.ReadAllLines(_tensorflowPath + "Predictions\\" + predictedDataPath).ToList();
            }
            Console.WriteLine(predictedDataPath + " Complete.");

            List <double> predictedData = new List <double>();
            List <double> matchOffset   = new List <double>();

            var matchAnalyzer = new MatchAnalyzer();

            // Parse predicted data into relevant objects. reference is via an offset from the original raw Broadcast video start time.
            var counter = 0.0;

            foreach (var line in predictedDataRaw)
            {
                predictedData.Add(double.Parse(line));
                matchOffset.Add(matchAnalyzer.ConvertVideoTimeToMatchOffset(counter * 15, matchMetricGroup.Match));
                counter += 1;
            }

            // Find the most exciting period in the match and its score.
            var highestScore      = 0.0;
            var index             = 0;
            var highestScoreIndex = 0;

            foreach (var score in predictedData)
            {
                if (score > highestScore)
                {
                    highestScore      = score;
                    highestScoreIndex = index;
                }

                index += 1;
            }

            // We offset the start by an additional 90 seconds to account for time slippage.
            return(new HighlightInfo(matchOffset[highestScoreIndex] + 90, 40, highestScore));
        }