<commit_before>﻿using Microsoft.Kinect;
using Microsoft.Kinect.Face;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KGP.Processors
{
    /// <summary>
    /// Processes a single hd face
    /// </summary>
    public class SingleHdFaceProcessor : IDisposable
    {
        private HighDefinitionFaceFrameSource frameSource;
        private HighDefinitionFaceFrameReader framereader;
        private FaceModel faceModel = new FaceModel();
        private FaceAlignment faceAlignment = new FaceAlignment();
        private FaceModelBuilder faceModelBuilder;


        /// <summary>
        /// Raised when we got a new face model refreshed
        /// </summary>
        public event EventHandler<Tuple<FaceModel, FaceAlignment>> FaceModelRefreshed;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="sensor">Kinect sensor</param>
        public SingleHdFaceProcessor(KinectSensor sensor)
        {
            this.frameSource = new HighDefinitionFaceFrameSource(sensor);
            this.framereader = this.frameSource.OpenReader();
            this.framereader.FrameArrived += this.FrameArrived;

            this.faceModelBuilder = this.frameSource.OpenModelBuilder(FaceModelBuilderAttributes.None);
            this.faceModelBuilder.CollectionCompleted += this.CollectionCompleted;
            this.faceModelBuilder.BeginFaceDataCollection();
        }

        private void CollectionCompleted(object sender, FaceModelBuilderCollectionCompletedEventArgs e)
        {
            var modelData = e.ModelData;
            this.faceModel = modelData.ProduceFaceModel();
            this.faceModelBuilder.Dispose();
            this.faceModelBuilder = null;
        }

        private void FrameArrived(object sender, HighDefinitionFaceFrameArrivedEventArgs e)
        {
            using (HighDefinitionFaceFrame frame = e.FrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    if (frame.IsTrackingIdValid == false) { return; }
                    frame.GetAndRefreshFaceAlignmentResult(this.faceAlignment);
                    //frame.Dispose();
                    if (this.FaceModelRefreshed != null)
                    {
                        this.FaceModelRefreshed(this, new Tuple<FaceModel, FaceAlignment>(this.faceModel, this.faceAlignment));
                    }
                }
            }
        }

        /// <summary><commit_msg>Removed collector, since never looked to complete or do anything useful<commit_after>﻿using Microsoft.Kinect;
using Microsoft.Kinect.Face;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KGP.Processors
{
    /// <summary>
    /// Processes a single hd face
    /// </summary>
    public class SingleHdFaceProcessor : IDisposable
    {
        private HighDefinitionFaceFrameSource frameSource;
        private HighDefinitionFaceFrameReader framereader;
        private FaceModel faceModel = new FaceModel();
        private FaceAlignment faceAlignment = new FaceAlignment();
        private FaceModelBuilder faceModelBuilder;


        /// <summary>
        /// Raised when we got a new face model refreshed
        /// </summary>
        public event EventHandler<Tuple<FaceModel, FaceAlignment>> FaceModelRefreshed;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="sensor">Kinect sensor</param>
        public SingleHdFaceProcessor(KinectSensor sensor)
        {
            this.frameSource = new HighDefinitionFaceFrameSource(sensor);
            this.framereader = this.frameSource.OpenReader();
            this.framereader.FrameArrived += this.FrameArrived;
        }

        private void FrameArrived(object sender, HighDefinitionFaceFrameArrivedEventArgs e)
        {
            using (HighDefinitionFaceFrame frame = e.FrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    if (frame.IsTrackingIdValid == false) { return; }
                    frame.GetAndRefreshFaceAlignmentResult(this.faceAlignment);
                    frame.Dispose();
                    if (this.FaceModelRefreshed != null)
                    {
                        this.FaceModelRefreshed(this, new Tuple<FaceModel, FaceAlignment>(this.faceModel, this.faceAlignment));
                    }
                }
            }
        }

        /// <summary>
{'fraction_non_alphanumeric': 0.08746993221080254, 'fraction_numerical': 0.0, 'mean_word_length': 2.1073369565217392, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '6639822', 'n_tokens_mistral': 1134, 'n_tokens_neox': 1093, 'n_words': 240}