用于定义和处理实时体育赛事的数据库建模

时间:2016-12-21 17:32:00

标签: database database-design real-time dsl

我正在尝试实时存储和处理体育赛事,并希望创建一个最佳系统,因为这将每秒处理100个事件。系统将在体育比赛前存储事件,然后实时处理或在半场/会话/比赛结束时处理。

在我的系统中,每个Event都会分解为以下组件

  • WHO谁是与之相关的事件。团队,球员,refree, 观众等
  • WHAT什么是事件(目标,通过,保存等)
  • WHEN活动的时间细节
  • HOWMUCH如何定义事件值
  • TYPE定义何时应该检查 - INDIVIDUAL:实时, AGGREGATEWHEN
  • 结束

以下是足球的一些例子

1. No goals scored in 2nd Half
TEAM: *, WHAT: __GOAL, WHEN: __HALF_2, HOWMUCH: 0, TYPE: AGGREGATE 
{
    "who" : {"team":*},     
    "what" : "__GOAL",
    "when" : "__HALF_2"
    "howMuch" : {"value":0, "type" :"exact"},
    "type" : "AGGREGATE"
}


2. Either keeper to complete 3 or more punches
PLAYER: (p1 v p2), WHAT: __PUNCH, WHEN: __MATCH, HOWMUCH: 3+, TYPE: INDIVIDUAL
{
    "who" : {"player":{"or":["p1","p2"]}},  
    "what" : "__PUNCH",
    "when" : "__MATCH"
    "howMuch" : {"value":2, "type":"more"},
    "type" : "AGGREGATE"
}

3. Coutinho to score a goal before 65th min
PLAYER: p3, WHAT: __GOAL, WHEN: <65, TYPE: INDIVIDUAL
{
    "who" : {"player":"p3"},    
    "what" : "__GOAL",
    "when" : {"value" : 65, "type" : "before"}
    "type" : "INDIVIDUAL"
}


4. Henderson to play highest number of passes
PLAYER : p4, WHAT: __PASS, WHEN: __MATCH, HOWMUCH: __MAX, TYPE: AGGREGATE
{
    "who" : {"player":"p4"},    
    "what" : "__PASS",
    "when" : "__MATCH",
    "howMuch": "__MAX"    // this is a key word which will be handled accordingly on the application
    "type" : "AGGREGATE"
}

5. Liverpool to have more possession than everton
TEAM: (t1 > t2), WHAT: __POSSESSION, WHEN: __MATCH, TYPE: AGGREGATE      
{
    "who" : {"team":{"compare":["t1","t2"],"winner":"t2"}},     
    "what" : "__POSSESSION",
    "when" : "__MATCH"
    "type" : "AGGREGATE"
}

当匹配状态发生变化时,将检查所有AGGREGATE个事件。例如一半---&gt; MATCH_END

将实时检查所有INDIVIDUAL个事件(一旦收到新事件)。这适用于Web钩子。

E.g。第58分钟进球。 系统收到的事件 - {"type":"goal","player":"_henderson_", "minute":58}

系统现在将运行“查找”("type" == "INDIVIDUAL" && "what" == "__GOAL"),并比较找到的所有事件。

稍后,我想提供一个管理功能来编写可以解析为此结构的句子。我想知道的是,如果我正朝着正确的方向努力,或者我需要以不同的方式开始思考。

1 个答案:

答案 0 :(得分:1)

您的选择可能在Spark和Dataflow之间。这是一个很好的white paper comparing the two,它实际上使用了类似的用例(大规模移动游戏用户实时评分)。祝你好运,看起来像一个很酷的项目(看起来像一个在线书籍制作实施?)。