예제 #1
0
        private List <Result> BuildResultObjects(List <OrionResult> actualResults)
        {
            var settings          = SettingsHelper.GetSettings();
            var result            = new List <Result>();
            var resultsForShooter = actualResults.GroupBy(r => r.ShooterId);

            foreach (var shooterRes in resultsForShooter)
            {
                var results          = shooterRes.OrderBy(r => r.Team);
                var resultForShooter = new Result();
                resultForShooter.ShooterId = results.First().ShooterId;
                resultForShooter.Class     = results.First().Class;
                resultForShooter.ClubName  = results.First().ClubName;
                resultForShooter.Name      = results.First().Name;
                resultForShooter.FeltHolds = new List <FeltHold>();
                var series = new List <string>();

                var allRanges = settings.OrionSetting.OrionViewModels.SelectMany(o => o.RangeViews).OrderBy(r => r.RangeId);
                ////foreach (var orion in settings.OrionSetting.OrionViewModels)
                ////{
                foreach (var rangeViewModel in allRanges)
                {
                    if (rangeViewModel.RangeType == RangeType.Shooting)
                    {
                        var orionResult = CalculateOrionAndRange.GetResultForThisRange(results, rangeViewModel.Parent, rangeViewModel);
                        if (orionResult == null)
                        {
                            if (rangeViewModel.ResultType == ResultType.Felt)
                            {
                                var fh = new FeltHold {
                                    Hits = 0, InnerHits = 0
                                };
                                resultForShooter.FeltHolds.Add(fh);
                                series.Add("x/x");
                            }
                            else
                            {
                                resultForShooter.Minne      = 0;
                                resultForShooter.MinneInner = 0;
                            }
                        }
                        else
                        {
                            if (orionResult.ResultType == ResultType.Felt)
                            {
                                if (orionResult.DoubleRange)
                                {
                                    var fh1 = new FeltHold {
                                        Hits = orionResult.GetSum(ResultType.Felt, rangeViewModel.CountingShoots, 1), InnerHits = orionResult.GetInnerHits(1, rangeViewModel.CountingShoots)
                                    };
                                    var fh2 = new FeltHold {
                                        Hits = orionResult.GetSum(ResultType.Felt, rangeViewModel.CountingShoots, 2), InnerHits = orionResult.GetInnerHits(2, rangeViewModel.CountingShoots)
                                    };
                                    resultForShooter.FeltHolds.Add(fh1);
                                    resultForShooter.TotalSum       += fh1.Hits;
                                    resultForShooter.TotalInnerHits += fh1.InnerHits;
                                    series.Add(string.Format("{0}/{1}", fh1.Hits, fh1.InnerHits));

                                    resultForShooter.FeltHolds.Add(fh2);
                                    resultForShooter.TotalSum       += fh2.Hits;
                                    resultForShooter.TotalInnerHits += fh2.InnerHits;
                                    series.Add(string.Format("{0}/{1}", fh2.Hits, fh2.InnerHits));
                                }
                                else
                                {
                                    var fh = new FeltHold {
                                        Hits = orionResult.GetSum(ResultType.Felt, rangeViewModel.CountingShoots), InnerHits = orionResult.GetInnerHits(0, rangeViewModel.CountingShoots)
                                    };
                                    resultForShooter.FeltHolds.Add(fh);
                                    resultForShooter.TotalSum       += fh.Hits;
                                    resultForShooter.TotalInnerHits += fh.InnerHits;
                                    series.AddRange(orionResult.GetPrintableSeries(rangeViewModel.CountingShoots));
                                }
                            }
                            else
                            {
                                resultForShooter.Minne      = orionResult.GetSum(ResultType.Bane, rangeViewModel.CountingShoots);
                                resultForShooter.MinneInner = orionResult.GetInnerHits(rangeViewModel.CountingShoots);
                            }
                        }
                    }
                }
                ////}

                //////foreach (var orionResult in results)
                //////{
                //////    if (orionResult.ResultType == ResultType.Felt)
                //////    {
                //////        if (orionResult.DoubleRange)
                //////        {
                //////            var fh1 = new FeltHold { Hits = orionResult.GetSum(ResultType.Felt, 1), InnerHits = orionResult.GetInnerHits(1) };
                //////            var fh2 = new FeltHold { Hits = orionResult.GetSum(ResultType.Felt, 2), InnerHits = orionResult.GetInnerHits(2) };
                //////            resultForShooter.FeltHolds.Add(fh1);
                //////            resultForShooter.TotalSum += fh1.Hits;
                //////            resultForShooter.TotalInnerHits += fh1.InnerHits;
                //////            series.Add(string.Format("{0}/{1}", fh1.Hits, fh1.InnerHits));

                //////            resultForShooter.FeltHolds.Add(fh2);
                //////            resultForShooter.TotalSum += fh2.Hits;
                //////            resultForShooter.TotalInnerHits += fh2.InnerHits;
                //////            series.Add(string.Format("{0}/{1}", fh2.Hits, fh2.InnerHits));
                //////        }
                //////        else
                //////        {
                //////            var fh = new FeltHold { Hits = orionResult.GetSum(), InnerHits = orionResult.GetInnerHits() };
                //////            resultForShooter.FeltHolds.Add(fh);
                //////            resultForShooter.TotalSum += fh.Hits;
                //////            resultForShooter.TotalInnerHits += fh.InnerHits;
                //////            series.AddRange(orionResult.GetPrintableSeries());
                //////        }
                //////    }
                //////    else
                //////    {
                //////        resultForShooter.Minne = orionResult.GetSum();
                //////        resultForShooter.MinneInner = orionResult.GetInnerHits();
                //////    }
                //////}

                resultForShooter.TotalResult = string.Join(" ", series);
                result.Add(resultForShooter);
            }

            return(result);
        }
예제 #2
0
        public static void WriteLeonResults(List <int> finishedShooters, List <OrionResult> orionResults, OrionSetupViewModel orionSetup, List <LeonPerson> leonPersons, List <MinneRegistration> minnePersons)
        {
            var tmpBasePath = DatabaseApi.GetActiveCompetition();

            var tmpPath      = Path.Combine(tmpBasePath, "LeonTmp");
            var tmpPathMinne = Path.Combine(tmpBasePath, "MinneLeonTemp");

            if (!Directory.Exists(tmpPath))
            {
                Directory.CreateDirectory(tmpPath);
            }

            if (!Directory.Exists(tmpPathMinne))
            {
                Directory.CreateDirectory(tmpPathMinne);
            }

            var leonResultsFelt           = new List <string>();
            var leonResultsBane           = new List <string>();
            MinneRegistration minnePerson = null;
            LeonPerson        leonPerson  = null;

            foreach (var finishedShooter in finishedShooters)
            {
                var allResultsForShooter = orionResults.Where(o => o.ShooterId == finishedShooter);
                leonPerson = leonPersons.SingleOrDefault(l => l.ShooterId == finishedShooter);

                if (minnePersons != null)
                {
                    minnePerson = minnePersons.SingleOrDefault(l => l.ShooterId == finishedShooter);
                }

                int           sumFelt        = 0;
                int           sumBane        = 0;
                List <string> allFeltSeries  = new List <string>();
                List <string> allMinneSeries = new List <string>();

                foreach (var orion in orionSetup.OrionViewModels)
                {
                    foreach (var rangeViewModel in orion.RangeViews)
                    {
                        if (rangeViewModel.RangeType == RangeType.Shooting)
                        {
                            var resultForThisRange = CalculateOrionAndRange.GetResultForThisRange(allResultsForShooter, orion, rangeViewModel);
                            if (resultForThisRange == null)
                            {
                                if (rangeViewModel.ResultType == ResultType.Felt)
                                {
                                    allFeltSeries.Add(string.Empty);
                                }
                            }
                            else
                            {
                                if (resultForThisRange.ResultType == ResultType.Felt)
                                {
                                    sumFelt += resultForThisRange.GetSum();
                                    allFeltSeries.AddRange(resultForThisRange.Series);
                                }
                                else if (resultForThisRange.ResultType == ResultType.Bane)
                                {
                                    sumBane += resultForThisRange.GetSum();
                                    allMinneSeries.AddRange(resultForThisRange.Series);
                                }
                            }
                        }
                    }
                }

                ////foreach (var orionResult in allResultsForShooter)
                ////{
                ////    if (orionResult.ResultType == ResultType.Felt)
                ////    {
                ////        sumFelt += orionResult.GetSum();
                ////        allFeltSeries.AddRange(orionResult.Series);
                ////    }
                ////    else if (orionResult.ResultType == ResultType.Bane)
                ////    {
                ////        sumBane += orionResult.GetSum();
                ////        allMinneSeries.AddRange(orionResult.Series);
                ////    }
                ////}

                if (allFeltSeries.Any() && leonPerson != null)
                {
                    var allShots = string.Join(";", allFeltSeries).ToUpper();

                    var leonLine = string.Format(
                        "{0};{1};{2};{3};{4};{5};{6};{7};{8}",
                        leonPerson.Range,
                        leonPerson.Team,
                        leonPerson.Target,
                        leonPerson.ShooterId,
                        leonPerson.Name,
                        leonPerson.ClubName,
                        leonPerson.Class,
                        sumFelt,
                        allShots);

                    leonResultsFelt.Add(leonLine);
                }

                if (allMinneSeries.Any() && minnePerson != null)
                {
                    var allShots = string.Join(";", allMinneSeries).ToUpper();

                    var leonLine = string.Format(
                        "{0};{1};{2};{3};{4};{5};{6};{7};{8}",
                        minnePerson.Range,
                        minnePerson.Team,
                        minnePerson.Target,
                        minnePerson.ShooterId,
                        minnePerson.Name,
                        minnePerson.ClubName,
                        minnePerson.Class,
                        sumBane,
                        allShots);

                    leonResultsBane.Add(leonLine);
                }

                var finishedPerson = new FinishedPerson
                {
                    Name      = leonPerson.Name,
                    ShooterId = leonPerson.ShooterId,
                    Target    = leonPerson.Target,
                    Team      = leonPerson.Team
                };
                DatabaseApi.Save(finishedPerson);
            }

            if (leonResultsFelt.Any())
            {
                var filenameTmp = Path.Combine(tmpPath, ToLeonDataTmp);

                File.AppendAllLines(filenameTmp, leonResultsFelt, Encoding.GetEncoding("ISO-8859-1"));
            }

            if (leonResultsBane.Any())
            {
                var filenameTmp = Path.Combine(tmpPathMinne, ToLeonDataTmp);

                File.AppendAllLines(filenameTmp, leonResultsBane, Encoding.GetEncoding("ISO-8859-1"));
            }
        }
예제 #3
0
        public static void WriteLeonResults(
            List <int> finishedShooters,
            List <OrionResult> orionResults,
            OrionSetupViewModel orionSetup,
            List <LeonPerson> leonPersons,
            List <MinneRegistration> minnePersons)
        {
            var tmpBasePath = DatabaseApi.GetActiveCompetition();

            var tmpPath      = Path.Combine(tmpBasePath, "LeonTmp");
            var tmpPathMinne = Path.Combine(tmpBasePath, "MinneLeonTemp");


            if (!Directory.Exists(tmpPath))
            {
                Directory.CreateDirectory(tmpPath);
            }

            if (!Directory.Exists(tmpPathMinne))
            {
                Directory.CreateDirectory(tmpPathMinne);
            }

            var leonResultsFelt           = new List <string>();
            var leonResultsBane           = new List <string>();
            MinneRegistration minnePerson = null;
            LeonPerson        leonPerson  = null;

            foreach (var finishedShooter in finishedShooters)
            {
                var allResultsForShooter = orionResults.Where(o => o.ShooterId == finishedShooter);
                leonPerson = leonPersons.SingleOrDefault(l => l.ShooterId == finishedShooter);

                if (minnePersons != null)
                {
                    minnePerson = minnePersons.SingleOrDefault(l => l.ShooterId == finishedShooter);
                }

                int           sumFelt        = 0;
                int           sumBane        = 0;
                List <string> allFeltSeries  = new List <string>();
                List <string> allMinneSeries = new List <string>();

                var allRanges = orionSetup.OrionViewModels.SelectMany(o => o.RangeViews).OrderBy(r => r.RangeId);
                ////foreach (var orion in orionSetup.OrionViewModels)
                ////{
                foreach (var rangeViewModel in allRanges)
                {
                    if (rangeViewModel.RangeType == RangeType.Shooting)
                    {
                        var resultForThisRange = CalculateOrionAndRange.GetResultForThisRange(
                            allResultsForShooter,
                            rangeViewModel.Parent,
                            rangeViewModel);
                        if (resultForThisRange == null)
                        {
                            if (rangeViewModel.ResultType == ResultType.Felt)
                            {
                                allFeltSeries.Add(string.Empty);
                            }
                        }
                        else
                        {
                            if (resultForThisRange.ResultType == ResultType.Felt)
                            {
                                sumFelt += resultForThisRange.GetSum();
                                resultForThisRange.ValidSeries = resultForThisRange.CalculateValidSeriesForRange(rangeViewModel);

                                allFeltSeries.AddRange(resultForThisRange.ValidSeries);
                            }
                            else if (resultForThisRange.ResultType == ResultType.Bane)
                            {
                                sumBane += resultForThisRange.GetSum();
                                foreach (var rawSerie in resultForThisRange.Series)
                                {
                                    int len = rangeViewModel.CountingShoots;

                                    if (rawSerie.Length < rangeViewModel.CountingShoots)
                                    {
                                        len = rawSerie.Length;
                                    }
                                    string serieSingle = rawSerie.Substring(0, len);
                                    int    slen        = serieSingle.Length;
                                    while (slen < rangeViewModel.CountingShoots)
                                    {
                                        serieSingle = serieSingle + "0";
                                        slen++;
                                    }
                                    allMinneSeries.Add(serieSingle);
                                }
                            }
                        }
                    }
                }
                ////}

                ////foreach (var orionResult in allResultsForShooter)
                ////{
                ////    if (orionResult.ResultType == ResultType.Felt)
                ////    {
                ////        sumFelt += orionResult.GetSum();
                ////        allFeltSeries.AddRange(orionResult.Series);
                ////    }
                ////    else if (orionResult.ResultType == ResultType.Bane)
                ////    {
                ////        sumBane += orionResult.GetSum();
                ////        allMinneSeries.AddRange(orionResult.Series);
                ////    }
                ////}

                if (allFeltSeries.Any() && leonPerson != null)
                {
                    var allShots = string.Join(";", allFeltSeries).ToUpper();

                    var leonLine = string.Format(
                        "{0};{1};{2};{3};{4};{5};{6};{7};{8};",
                        leonPerson.Range,
                        leonPerson.Team,
                        leonPerson.Target,
                        leonPerson.ShooterId,
                        leonPerson.Name,
                        leonPerson.ClubName,
                        leonPerson.Class,
                        sumFelt,
                        allShots);

                    leonResultsFelt.Add(leonLine);
                }

                if (allMinneSeries.Any() && minnePerson != null)
                {
                    var allShots = string.Join(";", allMinneSeries).ToUpper();

                    var leonLine = string.Format(
                        "{0};{1};{2};{3};{4};{5};{6};{7};{8};",
                        minnePerson.Range,
                        minnePerson.Team,
                        minnePerson.Target,
                        minnePerson.ShooterId,
                        minnePerson.Name,
                        minnePerson.ClubName,
                        minnePerson.Class,
                        sumBane,
                        allShots);

                    leonResultsBane.Add(leonLine);
                }

                var finishedPerson = new FinishedPerson
                {
                    Name      = leonPerson.Name,
                    ShooterId = leonPerson.ShooterId,
                    Target    = leonPerson.Target,
                    Team      = leonPerson.Team
                };
                DatabaseApi.Save(finishedPerson);
            }

            lock (syncObject)
            {
                if (leonResultsFelt.Any())
                {
                    //var writefilenameTmp = Path.Combine(tmpPath, "WRITE"+ToLeonDataTmp);
                    var filenameTmp = Path.Combine(tmpPath, ToLeonDataTmp);
                    File.AppendAllLines(filenameTmp, leonResultsFelt, Encoding.GetEncoding("ISO-8859-1"));
                    //if (File.Exists(filenameTmp))
                    //{
                    //    Log.Error("File alredy exsist deliting {0}", filenameTmp);
                    //    File.Delete(filenameTmp);
                    //}

                    //File.Move(writefilenameTmp, filenameTmp);
                }

                if (leonResultsBane.Any())
                {
                    //var writefilenameTmp = Path.Combine(tmpPathMinne, "WRITE"+ToLeonDataTmp);
                    var filenameTmp = Path.Combine(tmpPathMinne, ToLeonDataTmp);
                    File.AppendAllLines(filenameTmp, leonResultsBane, Encoding.GetEncoding("ISO-8859-1"));
                    //if (File.Exists(filenameTmp))
                    //{
                    //    Log.Error("File alredy exsist deliting {0}", filenameTmp);
                    //    File.Delete(filenameTmp);
                    //}
                    //File.Move(writefilenameTmp, filenameTmp);
                }
            }
        }