Example #1
0
        /* private LineLogic :
         * Input : string InputLine
         * Output : string OutputLine
         * Description : Takes (InputLine), applies logic to produce correct output and outputs (OutputLine). Inline comments. Note I don't understand tennis so may confuse sets and matches*/

        private string LineLogic(string InputLine)
        {
            List <string>      SetScore  = new List <string>();
            List <List <int> > GameScore = new List <List <int> >();
            int    MatchTracker          = 0;
            bool   OrderFlag             = false;
            string OutputString          = "";

            GameScore.Add(new List <int>());
            GameScore[0].Add(0); GameScore[0].Add(0);
            SetScore.Add("0"); SetScore.Add("0");

            foreach (var InputChar in InputLine)
            {
                if (!(InputChar.Equals("")))
                {
                    if (SetScore[PlayerDict[InputChar]] == "40" & ((SetScore[Math.Abs(PlayerDict[InputChar] - 1)]) == "A"))
                    { /* If set score is 40-A or A-40 and player with 40 scores then change A to 40*/
                        SetScore[Math.Abs(PlayerDict[InputChar] - 1)] = "40";
                    }
                    else if (SetScore[PlayerDict[InputChar]] == "A" || SetScore[PlayerDict[InputChar]] == "40" & (SetScore[Math.Abs(PlayerDict[InputChar] - 1)]) != "A" & (SetScore[Math.Abs(PlayerDict[InputChar] - 1)]) != "40")
                    { /* If a player scores and wins the match when the set score is 40-0,40-15,40-30,A-40, then update the end of GameScore which contains the current match wins. NOT OrderFlag to keep track of server*/
                        SetScore[0] = "0"; SetScore[1] = "0";
                        GameScore[MatchTracker][PlayerDict[InputChar]] += 1;
                        OrderFlag = !OrderFlag;

                        if ((GameScore[MatchTracker][0] >= 6 || GameScore[MatchTracker][1] >= 6) & Math.Abs(GameScore[MatchTracker][0] - GameScore[MatchTracker][1]) >= 2)
                        { /* If either players game wins is at least 6 and 2 clear games ahead of opponent then end match and create new match at end of GameScore 0 wins for both players*/
                            MatchTracker++;
                            GameScore.Add(new List <int>());
                            GameScore[MatchTracker].Add(0); GameScore[MatchTracker].Add(0);
                        }
                    }
                    else
                    { /* If no games or matches have been won then update set score for player that scored*/
                        SetScore[PlayerDict[InputChar]] = ScoreDict[SetScore[PlayerDict[InputChar]]];
                    }
                }
            }

            for (int I = 0; I < GameScore.Count; I++)
            {     /* Format output string for previous games and current game*/
                if (OrderFlag)
                { /* Reverse order of scores if server is incorrect*/
                    GameScore[I].Reverse();
                }
                OutputString += GameScore[I][0].ToString() + "-" + GameScore[I][1].ToString() + " ";
            }
            if (SetScore[0] + SetScore[1] != "00")
            {     /* If current set is not 0-0 then add to output string*/
                if (OrderFlag)
                { /* Reverse order of scores if server is incorrect*/
                    SetScore.Reverse();
                }
                OutputString += SetScore[0] + "-" + SetScore[1];
            }

            OutputString = OutputString.TrimEnd(' '); /* Trim trailing space char*/
            return(OutputString);
        }
Example #2
0
 public override int GetHashCode()
 {
     return(InputChar.GetHashCode() ^
            StackHead.GetHashCode() ^
            StackReplace.GetHashCode() ^
            NewState.GetHashCode() ^
            OldState.GetHashCode());
 }
Example #3
0
 public static bool IsMatched(string value, InputChar regexValue)
 {
     if (Regex.IsMatch(value, regexValue.EnumValue()))
     {
         // マッチした
         return true;
     }
     else
     {
         // マッチしなかった
         return false;
     }
 }
Example #4
0
        /// <summary>
        /// Lexical action, performed when token is accepted. The return value is indicator that 
        /// determines whether to pass the token to parser or ignore it. The return value overrides
        /// UseTerminal() and IgnoreTerminal() methods of Lexer.
        /// </summary>
        /// <summary>
        /// Adds transition to given state on input char
        /// </summary>
        /// <param name="state">Target state for transition</param>
        /// <param name="iChar">Input char for transition</param>
        internal void AddTransitionTo(State state, InputChar iChar)
        {
            List<State> states;

            if (state == null) return;

            if (Transitions.TryGetValue(iChar, out states))
            {
                states.Add(state);
            }
            else
            {
                Transitions[iChar] = new List<State> {state};
            }
        }
Example #5
0
        public static bool IsMatched(String value, InputChar regexValue)
        {
            string RegexString = String.Empty;

            switch (regexValue)
            {
                case InputChar.Hankaku_Kana:
                    RegexString = @"^[ァ-ン゙゚]+$";
                    break;
                case InputChar.Zenkaku_Hira:
                    RegexString = @"^[ぁ-ん]+$";
                    break;
                case InputChar.Zenkaku_Kana:
                    RegexString = @"^[ァ-ン]+$";
                    break;
                case InputChar.Alphabet_Only:
                    RegexString = @"^[a-zA-Z]+$";
                    break;
                case InputChar.Number:
                    RegexString = @"^[-.0-9]+$";
                    break;
                case InputChar.Zenkaku_All:
                    RegexString = @"^[^ -~。-゚]*$";
                    break;
                case InputChar.Hankaku_All:
                    RegexString = @"^[ -~。-゚]*$";
                    break;
                case InputChar.Date_Only:
                    RegexString = @"^[/0-9]+$";
                    break;
                case InputChar.Time_Only:
                    RegexString = @"^[:0-9]+$";
                    break;
            }

            if (Regex.IsMatch(value, RegexString))
            {
                // マッチした
                return true;
            }
            else
            {
                // マッチしなかった
                return false;
            }
        }
Example #6
0
        private static HashSet<State> Move(HashSet<State> states, InputChar a)
        {
            var move = new HashSet<State>();

            foreach (State state in states)
            {
                List<State> transitions;
                if (state.Transitions.TryGetValue(a, out transitions) && transitions != null)
                {
                    move.UnionWith(transitions);
                }
            }

            return move;
        }
Example #7
0
        private int KeyboardHookProc(int nCode, Int32 wParam, IntPtr lParam)
        {
            if (nCode == 0)
            {
                EventMsg msg = (EventMsg)Marshal.PtrToStructure(lParam, typeof(EventMsg));
                if (wParam == WM_KEYUP)
                {
                    int vkCode = Marshal.ReadInt32(lParam);

                    Keys key = (Keys)vkCode;

                    if (key == Keys.LShiftKey)
                    {
                        _shift = false;
                        goto END1;
                    }
                }

                if (wParam == WM_KEYDOWN)//WM_KEYDOWN=0x100
                {
                    int vkCode = Marshal.ReadInt32(lParam);

                    Keys key = (Keys)vkCode;

                    if (key == Keys.LShiftKey)
                    {
                        _shift = true;
                        // Console.WriteLine($"modi {(System.Windows.Forms.Keys)vkCode}");
                        goto END1;
                    }

                    TimeSpan ts = DateTime.Now.Subtract(_string.Time);
                    if (ts.TotalMilliseconds > TIME_SHTRESHOLD)
                    {
                        _barcode.Clear();
                    }

                    _string.Time = DateTime.Now;

                    //KeysConverter kc = new KeysConverter();
                    //string keyChar = kc.ConvertToString(key);

                    string keyChar = GetKeyString(key, _shift);
                    Debug.WriteLine($"keyChar='{keyChar}', key='{key.ToString()}'");

                    _barcode.Append(keyChar);

                    // 保护缓冲区
                    if (_barcode.Length > 1000)
                    {
                        _barcode.Clear();
                    }

                    Debug.WriteLine($"msg.message={(msg.message & 0xff)} _barcode:'{_barcode.ToString()}'");

                    if (InputChar != null)
                    {
                        CharInput input = new CharInput {
                            Key     = key,
                            KeyChar = keyChar,
                        };
                        AsyncCallback callback = new AsyncCallback(AsyncBackCharFeed);
                        Delegate[]    delArray = InputChar.GetInvocationList();
                        foreach (Delegate_charFeed del in delArray)
                        {
                            try
                            {
                                del.BeginInvoke(input, callback, del);
                            }
                            catch (Exception ex)
                            {
                                throw ex;
                            }
                        }
                    }

                    if ((msg.message & 0xff) == 13 && _barcode.Length > 3)
                    {
                        // 回车
                        _string.Barcode = _barcode.ToString();// barCode.OriginalBarCode;
                        _string.IsValid = true;
                        _barcode.Remove(0, _barcode.Length);

                        Debug.WriteLine($"isValid = true");
                    }
                    else
                    {
                        goto END1;
                    }

                    try
                    {
                        if (InputLine != null
                            // && _string.IsValid
                            )
                        {
                            Debug.WriteLine($"trigger callback");

                            AsyncCallback callback = new AsyncCallback(AsyncBackLineFeed);
                            Delegate[]    delArray = InputLine.GetInvocationList();
                            foreach (Delegate_lineFeed del in delArray)
                            {
                                try
                                {
                                    del.BeginInvoke(_string, callback, del); // 异步调用防止界面卡死
                                }
                                catch (Exception ex)
                                {
                                    throw ex;
                                }
                            }
                            //BarCodeEvent(barCode);//触发事件
                            _string.Barcode = "";
                            //_char.OriginalChrs = "";
                            //_char.OriginalAsciis = "";
                            //_char.OriginalBarCode = "";
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    finally
                    {
                        _string.IsValid = false;
                        _string.Time    = DateTime.Now;
                    }
                }
            }
END1:
            if (Handled == true)
            {
                return(1);
            }
            return(CallNextHookEx(hKeyboardHook, nCode, wParam, lParam));
        }
Example #8
0
 /// <summary>
 /// 添付プロパティのSetter定義
 /// </summary>
 /// <param name="obj">対象のオブジェクト</param>
 /// <param name="value">設定値</param>
 public static void SetInputCharcter(DependencyObject obj, InputChar value)
 {
     obj.SetValue(InputCharcterProperty, value);
 }
Example #9
0
        public override void Run()
        {
            var representation = new InputRepresentation().Read();
            var inputFolder    = new InputDirectory("Input folder with one CSV file per time series").Read();
            var separator      = new InputChar("Input CSV column separator").Read();
            var timeIndex      = new InputIndex("Input Time column (zero-based index)").Read();
            var valueIndex     = new InputIndex("Input Value column (zero-based index)").Read();
            var holidays       = new InputDates("Holidays (e.g. 2019-12-31,2020-01-01,...)").Read();
            var outputFolder   = Path.Combine(new InputDirectory("Output folder for exporting results").Read(), "ConcatenatedANDLPs");
            var resolutions    = new InputResolutions("Time resolutions (e.g. 5,15,30,...minutes)", new Resolution(15)).Read();
            var kMin           = new InputCount("Minimum number of clusters", 3, "without considering dataset size").Read();
            var kMax           = new InputCount("Maximum number of clusters", 10, "without considering dataset size").Read();

            Console.Write("Press enter to create new time series representations or any other key to cluster the existing ones...");
            bool recreate = Console.ReadKey().Key == ConsoleKey.Enter;

            Console.WriteLine();

            bool export = true;

            if (!recreate)
            {
                Console.Write("Press enter to export the existing representations to CSV or any other key to cluster previously exported data...");
                export = Console.ReadKey().Key == ConsoleKey.Enter;
                Console.WriteLine();
            }

            if (recreate || export)
            {
                if (export)
                {
                    Directory.CreateDirectory(outputFolder);
                }

                using (var db = new QualityTestDB(representation, resolutions, recreate))
                {
                    if (recreate)
                    {
                        int id    = 0;
                        var model = representation.ToInstance(db);
                        foreach (var ts in Directory.GetFiles(inputFolder, "*.csv").OrderNaturally())
                        {
                            id++;
                            var dates = new HashSet <DateTime>();

                            Log($"Processing {ts}");
                            foreach (var tuple in new CSVStream(ts, separator, timeIndex, valueIndex))
                            {
                                model.Process(id, tuple);
                                dates.Add(tuple.Timestamp.Date);
                            }

                            db.SetTSDates(id, dates);
                        }
                    }

                    if (export)
                    {
                        foreach (var resolution in resolutions)
                        {
                            db.ExportConcatenatedANDLPs(outputFolder, resolution, holidays);
                        }
                    }
                }
            }

            Console.WriteLine();
            R.RunScript($"{nameof(MTSR)}.R.TimeSeriesR.R");
            foreach (var cvi in new string[2] {
                "DBI", "CHI"
            })
            {
                R.Run($"LPR('{R.ToRPath(outputFolder)}', {kMin}, {kMax}, 'TSGA', '{cvi}')");
            }
        }