Ejemplo n.º 1
0
 public ProcessStat this[ProcessStatType processStatType]
 {
     get {
         ProcessStat stat;
         if (!_processStats.TryGetValue(processStatType, out stat)) {
             stat = new ProcessStat();
             _processStats[processStatType] = stat;
         }
         return stat;
     }
 }
Ejemplo n.º 2
0
 public static void TrySaveOrUpdateResult(ProcessStat processStat, int rawCompetitionItemID, FullResult fullResult)
 {
     if (rawCompetitionItemID == default(int)) {
         return;
     }
     var competitionResultRaw = RawCompetitionResult.DataSource.GetByKey(rawCompetitionItemID);
     if (competitionResultRaw != null) {
         return;
     }
     competitionResultRaw = new RawCompetitionResult {
         RawcompetitionitemID = rawCompetitionItemID,
         Rawresult = fullResult
     };
     competitionResultRaw.Insert();
     processStat.CreateRawCount++;
 }
Ejemplo n.º 3
0
 public RawTemplateObj<CompetitorParsedTransport> GetCompetitor(ProcessStat competitorStat, BrokerType brokerType, LanguageType languageType, SportType sportType, GenderType genderType, string[] names, GatherBehaviorMode algoMode)
 {
     return InvokeSafeSingleCall(() => {
         names = names
             .Where(name => !string.IsNullOrWhiteSpace(name))
             .Select(name => {
                 var indexOf = name.IndexOf("(", StringComparison.InvariantCultureIgnoreCase);
                 var cleanedName = (indexOf > 0 ? name.Substring(0, indexOf) : name).Trim(_trimChars);
                 return cleanedName.RemoveDiacritics();
             })
             .Where(name => !string.IsNullOrWhiteSpace(name))
             .ToArray();
         if (!names.Any()) {
             throw new Exception("nameFull.IsNullOrWhiteSpace() && nameShort.IsNullOrWhiteSpace()");
         }
         var competitors = new BrokerEntityBuilder<List<RawCompetitor>>(competitorStat)
             .SetupValidateObject(competitorsRaw => competitorsRaw.SafeAny() && competitorsRaw.All(c => c.CompetitoruniqueID != default(int)))
             .SetupGetRaw(() => RawCompetitorHelper.GetRawCompetitor[new RawCompetitorHelper.RawCompetitorCacheKey(brokerType, languageType, sportType, genderType, names)])
             .SetupCreateOriginal(algoMode, list => {
                 var uniqueID = new CompetitorUnique {
                     IsUsed = true
                 };
                 uniqueID.Save();
                 var competitor = new Competitor {
                     CompetitoruniqueID = uniqueID.ID,
                     SportType = sportType,
                     Datecreatedutc = DateTime.UtcNow,
                     Languagetype = languageType,
                     Name = names[0],
                     Gendertype = genderType
                 };
                 competitor.Save();
                 list.Each(el => el.Linkstatus = LinkEntityStatus.Original | LinkEntityStatus.Linked);
                 return list;
             })
             .SetupFinally(list => {
                 var firstElement = list.First();
                 if (algoMode.HasFlag(GatherBehaviorMode.CreateNewLanguageName) && firstElement.CompetitoruniqueID != default(int) && !Competitor.DataSource
                             .WhereEquals(Competitor.Fields.CompetitoruniqueID, firstElement.CompetitoruniqueID)
                             .WhereEquals(Competitor.Fields.Languagetype, (short)languageType)
                             .IsExists()) {
                     new Competitor {
                         CompetitoruniqueID = firstElement.CompetitoruniqueID,
                         SportType = sportType,
                         Datecreatedutc = DateTime.UtcNow,
                         Languagetype = languageType,
                         Name = names[0],
                         Gendertype = genderType
                     }.Save();
                 }
                 list.Each(el => el.Save());
                 return list;
             })
             .MakeObject();
         return competitors.Any()
             ? competitors.Select(c => new RawTemplateObj<CompetitorParsedTransport> {
                 RawObject = {
                     ID = c.ID
                 },
                 Object = {
                     LanguageType = languageType,
                     SportType = sportType,
                     GenderType = genderType,
                     ID = c.CompetitoruniqueID
                 }
             }).First()
             : new RawTemplateObj<CompetitorParsedTransport>();
     }, new RawTemplateObj<CompetitorParsedTransport>());
 }
Ejemplo n.º 4
0
        public CompetitionItemRawTransport GetCompetitionItem(ProcessStat competitorStat, BrokerType brokerType, RawTemplateObj<CompetitorParsedTransport>[] competitors, RawTemplateObj<CompetitionSpecifyTransport> competitionSpecifyTransport, DateTime eventDateUtc, GatherBehaviorMode algoMode, BrokerCompetitionSettings brokerSettings)
        {
            return InvokeSafeSingleCall(() => {
                var utcNow = DateTime.UtcNow;
                if (eventDateUtc > utcNow.AddDays(14) || competitors.Any(c => c.RawObject.ID == default(int))) {
                    return null;
                }
                var competitionItemRaw = new BrokerEntityBuilder<RawCompetitionItem>(competitorStat)
                    .SetupValidateObject(item => item.CompetitionitemID != default(int))
                    .SetupGetRaw(() => RawCompetitionItemHelper.GetCompetitionItem(brokerType, competitors, competitionSpecifyTransport, eventDateUtc, utcNow))
                    .SetupCreateRaw(() => RawCompetitionItemHelper.CreateCompetitionItem(brokerType, competitors, competitionSpecifyTransport, eventDateUtc, utcNow))
                    .SetupTryMatchRaw(GatherBehaviorMode.TryDetectAll, item => {
                        /*brokerSettings*/
                        var ciDs = CompetitionItem.DataSource
                            .Where(new DaoFilterOr(
                                new DaoFilterAnd(
                                    new DaoFilterEq(CompetitionItem.Fields.Competitoruniqueid1, competitors[0].Object.ID),
                                    new DaoFilterEq(CompetitionItem.Fields.Competitoruniqueid2, competitors[1].Object.ID)
                                    ),
                                new DaoFilterAnd(
                                    new DaoFilterEq(CompetitionItem.Fields.Competitoruniqueid2, competitors[0].Object.ID),
                                    new DaoFilterEq(CompetitionItem.Fields.Competitoruniqueid1, competitors[1].Object.ID)
                                    )
                                ))
                            .WhereEquals(CompetitionItem.Fields.Sporttype, (short)competitionSpecifyTransport.Object.SportType)
                            .Where(new DaoFilterOr(
                                new DaoFilterNull(CompetitionItem.Fields.CompetitionSpecifyUniqueID, true),
                                new DaoFilterEq(CompetitionItem.Fields.CompetitionSpecifyUniqueID, competitionSpecifyTransport.Object.ID)))
                            .Where(eventDateUtc > DateTime.MinValue
                                ? new DaoFilterAnd(
                                    new DaoFilter(CompetitionItem.Fields.Dateeventutc, Oper.GreaterOrEq, eventDateUtc.AddDays(-0.7)),
                                    new DaoFilter(CompetitionItem.Fields.Dateeventutc, Oper.LessOrEq, eventDateUtc.AddDays(0.7))
                                )
                                : new DaoFilterAnd(
                                    new DaoFilter(CompetitionItem.Fields.Dateeventutc, Oper.GreaterOrEq, utcNow.AddDays(-0.7)),
                                    new DaoFilter(CompetitionItem.Fields.Dateeventutc, Oper.LessOrEq, utcNow.AddDays(0.7))
                                )
                            )
                            .Sort(CompetitionItem.Fields.ID, SortDirection.Desc);
                        if (!brokerSettings.HasFlag(BrokerCompetitionSettings.NoCompareCompetitionUnique)) {
                            ciDs = ciDs
                                .WhereEquals(CompetitionItem.Fields.CompetitionuniqueID, competitionSpecifyTransport.Object.CompetitionUniqueID);
                        }
                        var ci = ciDs.First(CompetitionItem.Fields.ID);
                        if (ci != null) {
                            item.CompetitionitemID = ci.ID;
                            item.Linkstatus = LinkEntityStatus.LinkByStatistics | LinkEntityStatus.Linked;
                        }
                        return item;
                    })
                    .SetupCreateOriginal(algoMode, item => {
                        CreateCompetitionItem(competitors, competitionSpecifyTransport, eventDateUtc, utcNow, item);
                        return item;
                    })
                    .SetupFinally(item => {
                        if (algoMode.HasFlag(GatherBehaviorMode.CreateOriginalIfMatchedAll) && item.CompetitionitemID == default(int) &&
                                                                                                  competitionSpecifyTransport.Object.CompetitionUniqueID != default(int) &&
                                                                                                  //NOTE competitionSpecifyTransport.Object.CompetitionSpecifyUniqueID != default(int) &&
                                                                                                  competitors[0].Object.ID != default(int) &&
                                                                                                  competitors[1].Object.ID != default(int)) {
                            CreateCompetitionItem(competitors, competitionSpecifyTransport, eventDateUtc, utcNow, item);
                        }
                        item.Save();
                        return item;
                    })
                    .MakeObject();
                if (competitionItemRaw.CompetitionitemID == default(int)) {
                    return null;
                }
                var competitionItem = CompetitionItem.DataSource.GetByKey(competitionItemRaw.CompetitionitemID, CompetitionItem.Fields.ID, CompetitionItem.Fields.Dateeventutc, CompetitionItem.Fields.Competitoruniqueid1, CompetitionItem.Fields.Competitoruniqueid2, CompetitionItem.Fields.CompetitionSpecifyUniqueID);
                if (competitionSpecifyTransport.Object.ID != default(int) && competitionItem.CompetitionSpecifyUniqueID == default(int)) {
                    competitionItem.CompetitionSpecifyUniqueID = competitionSpecifyTransport.Object.ID;
                    competitionItem.Save();
                }

                if (eventDateUtc > DateTime.MinValue && ((algoMode & (GatherBehaviorMode.CreateOriginal | GatherBehaviorMode.CreateOriginalIfMatchedAll)) != 0)) {
                    if (Math.Abs((competitionItem.Dateeventutc - eventDateUtc).TotalMinutes) > 5) {
                        competitionItem.Dateeventutc = eventDateUtc;
                        competitionItem.Save();
                    }
                }

                return new CompetitionItemRawTransport {
                    CompetitionItemID = competitionItem.Competitoruniqueid1 == competitors[0].Object.ID &&
                                           competitionItem.Competitoruniqueid2 == competitors[1].Object.ID
                                    ? competitionItem.ID
                                    : -competitionItem.ID,
                    RawCompetitionItemID = competitionItemRaw.ID
                };
            }, null);
        }
Ejemplo n.º 5
0
 public RawTemplateObj<CompetitionSpecifyTransport> GetCompetitionSpecify(ProcessStat competitionStat, ProcessStat competitionSpecifyStat, BrokerType brokerType, LanguageType language, SportType sportType, string[] nameOrigin, CompetitionParsed competitionToSave, GatherBehaviorMode algoMode)
 {
     return InvokeSafeSingleCall(() => {
         var genderDetected = GenderDetectorHelper.Instance[nameOrigin];
         if (genderDetected == GenderType.Unknown) {
             _logger.Error("{0}: {1}", nameOrigin, genderDetected);
         }
         nameOrigin = CleanCompetitionName(nameOrigin);
         var rawCompetitionSpecify = new BrokerEntityBuilder<RawCompetitionSpecify>(competitionSpecifyStat)
             .SetupValidateObject(specify => true/*NOTE!! && specify.CompetitionSpecifyUniqueID != default(int)*/)
             .SetupGetRaw(() => RawCompetitionHelper.GetRawCompetitionSpecify[new RawCompetitionHelper.RawCompetitorSpecifyKey(brokerType, language, sportType, genderDetected, nameOrigin)])
             .SetupCreateRaw(() => RawCompetitionHelper.CreateCompetitionSpecify(competitionStat, brokerType, language, sportType, genderDetected, nameOrigin, competitionToSave, algoMode))
             .SetupCreateOriginal(algoMode, specify => {
                 if (specify.CompetitionSpecifyUniqueID == default(int)) {
                     var competitionSpecifyUnique = new CompetitionSpecifyUnique {
                         CompetitionuniqueID = specify.CompetitionuniqueID
                     };
                     competitionSpecifyUnique.Save();
                     specify.CompetitionSpecifyUniqueID = competitionSpecifyUnique.ID;
                     specify.Save();
                 }
                 var competitionSpecify = new CompetitionSpecify {
                     Datecreatedutc = DateTime.UtcNow,
                     Languagetype = language,
                     SportType = sportType,
                     Name = CompetitionHelper.ListStringToName(nameOrigin),
                     Gendertype = genderDetected,
                     CompetitionuniqueID = specify.CompetitionuniqueID
                 };
                 specify.CompetitionSpecifyUniqueID = competitionSpecify.CompetitionSpecifyUniqueID;
                 if (competitionSpecify.CompetitionuniqueID != specify.CompetitionuniqueID) {
                     _logger.Error("{0} != {1}. {2}. SKIP", competitionSpecify.CompetitionuniqueID, specify.CompetitionuniqueID, CompetitionHelper.ListStringToName(nameOrigin));
                     return null;
                 }
                 specify.Linkstatus = LinkEntityStatus.Original | LinkEntityStatus.Linked;
                 return specify;
             })
             .SetupFinally(specify => {
                 if (specify.CompetitionSpecifyUniqueID != default(int)) {
                     if (algoMode.HasFlag(GatherBehaviorMode.CreateNewLanguageName)) {
                         if (specify.CompetitionSpecifyUniqueID != default(int) &&
                             specify.CompetitionuniqueID != default(int) && !CompetitionSpecify.DataSource
                                 .WhereEquals(CompetitionSpecify.Fields.CompetitionSpecifyUniqueID, specify.CompetitionSpecifyUniqueID)
                                 .FilterByLanguage(language)
                                 .IsExists()) {
                             new CompetitionSpecify {
                                 Languagetype = language,
                                 Name = CompetitionHelper.ListStringToName(nameOrigin),
                                 CompetitionSpecifyUniqueID = specify.CompetitionSpecifyUniqueID,
                                 CompetitionuniqueID = specify.CompetitionuniqueID,
                                 Datecreatedutc = DateTime.UtcNow,
                                 Gendertype = genderDetected,
                                 SportType = sportType
                             }.Save();
                         }
                     }
                 }
                 specify.Save();
                 return specify;
             })
             .MakeObject();
         return RawCompetitionHelper.CreateCompetitionSpecifyRawObject(rawCompetitionSpecify.ID, rawCompetitionSpecify.RawCompetitionID, rawCompetitionSpecify, language, sportType, genderDetected);
     }, new RawTemplateObj<CompetitionSpecifyTransport>());
 }
Ejemplo n.º 6
0
        public static RawCompetitionSpecify CreateCompetitionSpecify(ProcessStat competitionStat, BrokerType brokerType, LanguageType language, SportType sportType, GenderType genderDetected, string[] nameOrigin, CompetitionParsed competitionToSave, GatherBehaviorMode algoMode)
        {
            var nameOriginShort = CompetitionHelper.GetShortCompetitionName(nameOrigin, sportType);
            var competitionRaw = new BrokerEntityBuilder<RawCompetition>(competitionStat)
                .SetupValidateObject(rawCompetition => rawCompetition.CompetitionuniqueID != default(int))
                .SetupGetRaw(() => {
                    return RawCompetition.DataSource.FilterByBroker(brokerType).FilterByLanguage(language).FilterBySportType(sportType)
                        .FilterByNameCompetition(nameOriginShort)
                        .FilterByGender(genderDetected, RawCompetition.Fields.CompetitionuniqueID, RawCompetition.Fields.Linkstatus).FirstOrDefault();
                })
                .SetupCreateRaw(() => BrokerEntityIfaceCreator.CreateEntity<RawCompetition>(brokerType, language, sportType, genderDetected, LinkEntityStatus.Unlinked, nameOriginShort))
                .SetupCreateOriginal(algoMode, rawCompetition => {
                    var competition = Competition.DataSource.FilterByLanguage(language).FilterBySportType(sportType)
                        .FilterByNameCompetition(nameOriginShort)
                        .FilterByGender(genderDetected, Competition.Fields.CompetitionuniqueID)
                        .FirstOrDefault();
                    if (competition == null) {
                        var competitionUnique = new CompetitionUnique {
                            IsUsed = true
                        };
                        competitionUnique.Save();
                        competition = new Competition {
                            Datecreatedutc = DateTime.UtcNow,
                            Languagetype = language,
                            SportType = sportType,
                            Name = CompetitionHelper.ListStringToName(nameOriginShort),
                            Gendertype = genderDetected,
                            CompetitionuniqueID = competitionUnique.ID
                        };
                        competition.Save();
                    }
                    rawCompetition.CompetitionuniqueID = competition.CompetitionuniqueID;
                    rawCompetition.Linkstatus = LinkEntityStatus.Original | LinkEntityStatus.Linked;
                    return rawCompetition;
                })
                .SetupFinally(rawCompetition => {
                    if (algoMode.HasFlag(GatherBehaviorMode.CreateNewLanguageName)) {
                        if (rawCompetition.CompetitionuniqueID != default(int) && !Competition.DataSource
                            .WhereEquals(Competition.Fields.CompetitionuniqueID, rawCompetition.CompetitionuniqueID)
                            .FilterByLanguage(language)
                            .IsExists()) {
                            new Competition {
                                CompetitionuniqueID = rawCompetition.CompetitionuniqueID,
                                Datecreatedutc = DateTime.UtcNow,
                                Gendertype = genderDetected,
                                SportType = sportType,
                                Name = CompetitionHelper.ListStringToName(nameOriginShort),
                                Languagetype = language
                            }.Save();
                        }
                    }
                    rawCompetition.Save();
                    return rawCompetition;
                })
                .MakeObject();

            return BrokerEntityIfaceCreator.CreateEntity<RawCompetitionSpecify>(brokerType, language, sportType, genderDetected, LinkEntityStatus.Unlinked, nameOrigin, specify => {
                specify.RawCompetitionID = competitionRaw.ID;
                if (specify.CompetitionuniqueID == default(int) && competitionRaw.CompetitionuniqueID != default(int)) {
                    specify.CompetitionuniqueID = competitionRaw.CompetitionuniqueID;
                }
            });
        }
Ejemplo n.º 7
0
 public void SaveResults(ProcessStat processStat, CompetitionItemRawTransport competitionRawTransport, SportType sportType, FullResult fullResult)
 {
     InvokeSafeSingleCall(() => {
         processStat.TotalCount++;
         if (competitionRawTransport == null || fullResult == null) {
             return null;
         }
         RawCompetitionResultHelper.TrySaveOrUpdateResult(processStat, competitionRawTransport.RawCompetitionItemID, fullResult);
         if (competitionRawTransport.CompetitionItemID == default(int)) {
             return null;
         }
         CompetitionResult.ProcessResult(processStat, competitionRawTransport.CompetitionItemID, sportType, fullResult);
         processStat.FinallySuccessCount++;
         return (object) null;
     }, null);
 }