Ejemplo n.º 1
0
 public static RawCompetitionItem GetCompetitionItem(BrokerType brokerType, RawTemplateObj<CompetitorParsedTransport>[] competitors, RawTemplateObj<CompetitionSpecifyTransport> competitionSpecifyTransport, DateTime eventDateUtc, DateTime utcNow)
 {
     var competitionItem = RawCompetitionItem.DataSource
                 .WhereEquals(RawCompetitionItem.Fields.Rawcompetitorid1, competitors[0].RawObject.ID)
                 .WhereEquals(RawCompetitionItem.Fields.Rawcompetitorid2, competitors[1].RawObject.ID)
                 .WhereEquals(RawCompetitionItem.Fields.Sporttype, (short)competitionSpecifyTransport.Object.SportType)
                 .WhereEquals(RawCompetitionItem.Fields.Brokerid, (short)brokerType)
                 .WhereEquals(RawCompetitionItem.Fields.Languagetype, (short)competitionSpecifyTransport.Object.LanguageType)
                 .WhereEquals(RawCompetitionItem.Fields.RawcompetitionID, competitionSpecifyTransport.RawObject.ParentID)
                 .WhereEquals(RawCompetitionItem.Fields.RawcompetitionspecifyID, competitionSpecifyTransport.RawObject.ID)
                 .Where(eventDateUtc > DateTime.MinValue
                     ? new DaoFilterAnd(
                         new DaoFilter(RawCompetitionItem.Fields.Dateeventutc, Oper.GreaterOrEq, eventDateUtc.AddDays(-1.5)),
                         new DaoFilter(RawCompetitionItem.Fields.Dateeventutc, Oper.LessOrEq, eventDateUtc.AddDays(1.5))
                     )
                     : new DaoFilterAnd(
                         new DaoFilter(RawCompetitionItem.Fields.Dateeventutc, Oper.GreaterOrEq, utcNow.AddDays(-1.5)),
                         new DaoFilter(RawCompetitionItem.Fields.Dateeventutc, Oper.LessOrEq, utcNow.AddDays(1.5))
                     )
                 )
                 .Sort(RawCompetitionItem.Fields.ID, SortDirection.Desc)
                 .First(RawCompetitionItem.Fields.ID, RawCompetitionItem.Fields.Dateeventutc, RawCompetitionItem.Fields.Rawcompetitorid1, RawCompetitionItem.Fields.Rawcompetitorid2, RawCompetitionItem.Fields.RawcompetitionID, RawCompetitionItem.Fields.CompetitionitemID);
     if (eventDateUtc > DateTime.MinValue && competitionItem != null) {
         if (Math.Abs((competitionItem.Dateeventutc - eventDateUtc).TotalMinutes) > 5) {
             competitionItem.Dateeventutc = eventDateUtc;
             competitionItem.Save();
         }
     }
     return competitionItem;
 }
Ejemplo n.º 2
0
 public static RawCompetitionItem CreateCompetitionItem(BrokerType brokerType, RawTemplateObj<CompetitorParsedTransport>[] competitors, RawTemplateObj<CompetitionSpecifyTransport> competitionSpecifyTransport, DateTime eventDateUtc, DateTime utcNow)
 {
     RawCompetitionItem competitionItemRaw = null;
     if (competitionSpecifyTransport.RawObject.ID != default(int) && competitors[0].RawObject.ID != default(int) && competitors[0].RawObject.ID != default(int)) {
         competitionItemRaw = BrokerEntityIfaceCreator.CreateEntity<RawCompetitionItem>(brokerType, competitionSpecifyTransport.Object.LanguageType, competitionSpecifyTransport.Object.SportType,
             LinkEntityStatus.Unlinked, item => {
                 item.RawcompetitionID = competitionSpecifyTransport.RawObject.ParentID;
                 item.RawcompetitionspecifyID = competitionSpecifyTransport.RawObject.ID;
                 item.Rawcompetitorid1 = competitors[0].RawObject.ID;
                 item.Rawcompetitorid2 = competitors[1].RawObject.ID;
                 item.Dateeventutc = eventDateUtc != DateTime.MinValue ? eventDateUtc : utcNow;
             });
         competitionItemRaw.Save();
     }
     return competitionItemRaw;
 }
Ejemplo n.º 3
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.º 4
0
 private static void CreateCompetitionItem(RawTemplateObj<CompetitorParsedTransport>[] competitors, RawTemplateObj<CompetitionSpecifyTransport> competitionSpecifyTransport, DateTime eventDateUtc,
     DateTime utcNow, RawCompetitionItem item)
 {
     var ci = new CompetitionItem {
         SportType = competitionSpecifyTransport.Object.SportType,
         Datecreatedutc = utcNow,
         Dateeventutc = eventDateUtc != DateTime.MinValue ? eventDateUtc : utcNow,
         CompetitionuniqueID = competitionSpecifyTransport.Object.CompetitionUniqueID,
         //CompetitionSpecifyUniqueID = competitionSpecifyTransport.Object.CompetitionSpecifyUniqueID,
         Competitoruniqueid1 = competitors[0].Object.ID,
         Competitoruniqueid2 = competitors[1].Object.ID
     };
     if (competitionSpecifyTransport.Object.ID != default(int)) {
         ci.CompetitionSpecifyUniqueID = competitionSpecifyTransport.Object.ID;
     }
     ci.Save();
     item.Linkstatus = LinkEntityStatus.Original | LinkEntityStatus.Linked;
     item.CompetitionitemID = ci.ID;
 }
Ejemplo n.º 5
0
        public static RawTemplateObj<CompetitionSpecifyTransport> CreateCompetitionSpecifyRawObject(int rawID, int parentRawID, ICompetitionSpecify competitionSpecify, LanguageType language, SportType sportType, GenderType genderDetected)
        {
            var result = new RawTemplateObj<CompetitionSpecifyTransport>();
            result.RawObject.ID = rawID;
            result.RawObject.ParentID = parentRawID;

            result.Object.LanguageType = language;
            result.Object.SportType = sportType;
            result.Object.GenderType = genderDetected;

            result.Object.CompetitionUniqueID = competitionSpecify.CompetitionuniqueID;
            result.Object.ID = competitionSpecify.CompetitionSpecifyUniqueID;
            return result;
        }