<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using Gma.System.MouseKeyHook;
using System.IO;

namespace GazePlusMouse
{
    public struct Event
    {
        public System.DateTime time;
        public Point location;
        public Point delta;
    }

    class GazeCalibrator
    {
        IKeyboardMouseEvents mouseGlobalHook;
        WarpPointer warp;
        MouseController controller;
        List<Event> events;

        public GazeCalibrator(MouseController controller, WarpPointer warp)
        {
            this.controller = controller;
            this.warp = warp;
            events = new List<Event>();

            mouseGlobalHook = Hook.GlobalEvents();
            mouseGlobalHook.MouseDownExt += GlobalHookMouseDownExt;
        }

        public List<Event> GetEvents()
        {
            return events;
        }

        private void GlobalHookMouseDownExt(object sender, MouseEventExtArgs e)
        {
            if (controller.GetTrackingState() == "Running")
            {
                Point curr = new Point(e.X, e.Y);
                Point gaze = warp.calculateSmoothedPoint();
                Point d = Point.Subtract(gaze, new Size(curr));

                Event evt = new Event() { time = System.DateTime.Now, location = curr, delta = d };
                events.Add(evt);

                var csv = new StringBuilder();
                var newLine = string.Format("{0},{1},{2},{3},{4}", System.DateTime.Now, curr.X, curr.Y, d.X, d.Y);
                csv.AppendLine(newLine);
                File.AppendAllText("CalibrationData.csv", csv.ToString());
            }
        }
    }
}
<commit_msg>Saving calibration data to file is configurable now<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using Gma.System.MouseKeyHook;
using System.IO;

namespace GazePlusMouse
{
    public struct Event
    {
        public System.DateTime time;
        public Point location;
        public Point delta;
    }

    class GazeCalibrator
    {
        IKeyboardMouseEvents mouseGlobalHook;
        WarpPointer warp;
        MouseController controller;
        List<Event> events;
        bool saveToFile = true;

        public GazeCalibrator(MouseController controller, WarpPointer warp)
        {
            this.controller = controller;
            this.warp = warp;
            events = new List<Event>();

            mouseGlobalHook = Hook.GlobalEvents();
            mouseGlobalHook.MouseDownExt += GlobalHookMouseDownExt;
        }

        public List<Event> GetEvents()
        {
            return events;
        }

        private void GlobalHookMouseDownExt(object sender, MouseEventExtArgs e)
        {
            if (controller.GetTrackingState() == "Running")
            {
                Point curr = new Point(e.X, e.Y);
                Point gaze = warp.calculateSmoothedPoint();
                Point d = Point.Subtract(gaze, new Size(curr));

                Event evt = new Event() { time = System.DateTime.Now, location = curr, delta = d };
                events.Add(evt);

                if (saveToFile)
                {
                    var csv = new StringBuilder();
                    var newLine = string.Format("{0},{1},{2},{3},{4}", System.DateTime.Now, curr.X, curr.Y, d.X, d.Y);
                    csv.AppendLine(newLine);
                    File.AppendAllText("CalibrationData.csv", csv.ToString());
                }
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.09790979097909791, 'fraction_numerical': 0.0027502750275027505, 'mean_word_length': 1.8865079365079365, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5371869', 'n_tokens_mistral': 993, 'n_tokens_neox': 960, 'n_words': 230}