Neo4j - 24/7 赌场名册

标签 neo4j data-modeling graph-databases rostering

这是一系列新问题,以回应 Kenny 对我之前关于如何围绕 24/7 赌场名册建模数据库的问题的回答。
Database model for a 24/7 Staff roster at a casino

仍然试图让我了解图表以及数据是如何遍历/连接的。使用肯尼回答中图像上半部分的时间图,每年是否有 12 个月的节点指向一排日节点,其中有多个日节点,其中第一天的值为 1月?我会为每年构建这些子图,还是会使用特定的查询来添加随着时间的推移不存在的节点?我知道有一个查询可以做到这一点,但它需要考虑月份节点中的最后一天并创建正确的结束关系?我会遇到闰年或夏令时的问题吗?

答案图片的下半部分是游戏节点,他们是否只有一个员工和位置关系?我不确定如何判断哪个员工被分配到哪个表(不向关系边添加属性),我应该向边添加属性还是应该为每对使用单独的节点?

我制作了一个粗略的图像来显示笔/纸花名册的样子,它可能在某种程度上有所帮助。
Roster example

我也试过用一些问题(红框)来计划一个图表,它是在 illustrator 中完成的,有点凌乱,我很想知道 Kenny 的图形图像是否是在特定应用程序中完成的,如果是,是哪个,虽然我认为图表在视觉上往往会变得困惑和困惑。

Graph model concept
您似乎无法单击图像以获取文本可读的直接链接,您可以在此处查看:http://i.imgur.com/FMfJx6G.png

如果有帮助,我可以在此处添加问题文本或使用建议的软件重新创建图表。

最佳答案

这是来自 24/7 Staff roster at a casino 的数据库模型的原始图像:

24/7 Staff Roster at a Casino

With the time graph at the top half of the image in Kenny's answer, does each year have 12 month nodes that then point to a row of day nodes where there is more then one day node with a value of 1 for the 1st day in a month?



对,那是正确的。我在下图中对此进行了建模。

Multilevel Datetime Index

Would I build these subgraphs for each year or would I use a specific query that adds a node(s) that does not exist as time progresses? I understand there is a query that can do such but it would need to account for the last day in the month node and create the end relationship correct?



我创建了一个 Cypher 脚本,它为年、月、日、小时创建多级时间索引。你可以在这里找到:

https://gist.github.com/kbastani/8519557

例如,要创建一天中的所有小时,我们可以合并任何一天,然后添加年份结构。这是 MERGE Cypher 语句的优点之一。用于创建多级日期时间索引的 Cypher 查询在某种程度上是“容错的”,如果您多次运行它,那么它不会创建重复项或弄乱您的数据结构。

这是用于合并日和小时的 2 级层次结构的 Cypher 脚本:
// Enter the day you would like to create
WITH { day: 18, month: 1, year: 2014 } as dayMap

// Merge hours in a day
MERGE (thisDay:Day 
       { 
           day: dayMap.day, 
           month: dayMap.month, 
           year: dayMap.year 
       })

// Get the first hour in the day (hour 1)
MERGE (firstHour:Hour 
       { 
           day: dayMap.day, 
           month: dayMap.month, 
           year: dayMap.year, 
           hour: 1 
       })

// Connect this day to first hour
CREATE (thisDay)-[:FIRST]->(firstHour)

// For each i in (2-24)
FOREACH (i IN tail(range(1, 24)) |

    // Get this hour
    MERGE (thishour:Hour 
           { 
              day: dayMap.day, 
              month: dayMap.month, 
              year: dayMap.year, 
              hour: i 
           })

    // Get the hour before this hour
    MERGE (lasthour:Hour 
           { 
              day: dayMap.day, 
              month: dayMap.month, 
              year: dayMap.year, 
              hour: i - 1 
           })

    // Link the hours
    CREATE (lasthour)-[:NEXT]->(thishour))

// Get the last hour in the sequence (hour 24)
MERGE (lastHour:Hour 
      { 
           day: dayMap.day, 
           month: dayMap.month, 
           year: dayMap.year, 
           hour: 24 
      })

// Connect this day to the last hour
CREATE (thisDay)-[:LAST]->(lastHour)

Will I have any issues with leap years or daylight savings?



不,这应该不是问题,但可能取决于您提出的问题。这是特定于上下文的。由于我们不依赖于数据结构在用户界面中构建日历,而是仅回答有关特定日期的特定问题,因此规则继承自您导入的数据。

On the lower half of the answer image are the game nodes, do they only have one employee and location relationship? I'm not sure how I could tell which employee is assigned to which table(without adding properties to the relationship edges), should I be adding properties to the edges or should I be using a separate node for each pair?



有一个员工节点和一个位置节点。通过这种方式,您可以从员工节点或位置节点开始了解有关该对象的某些信息以及它与其他对象的关系。

I've also tried to plan out a graph with some questions(red boxes), it was done in illustrator and got a bit messy, I'd love to know if Kenny's graph image was done in a particular application and if so which one, though I take it graphs visually tend to get tangled and messy.



我用来生成图形数据模型图像的工具是 http://www.apcjones.com/arrows/#

要连接节点,只需将鼠标指针突出显示在节点圆圈的外部,然后单击该关系并将其拖动到另一个节点。这个小应用程序是开源的,仅适用于 Chrome 浏览器。

至于你的完整数据模型,我已经构建了一个 Cypher 数据集示例,因为我真的认为你的领域很有趣。您可以在此处找到这些查询:https://gist.github.com/kbastani/8529380

这是我使用的数据模型:

24/7 Staff Roster at a Casino expanded

回到你之前的帖子,你有一个问题:

What staff have been on the floor for 80 minutes or more on a specific day?



这是回答该问题的 Cypher 查询:
// What staff have been on the floor for 80 minutes or more on a specific day?
WITH { day: 18, month: 1, year: 2014 } as dayMap

// The dayMap field acts as a parameter for this script
MATCH (day:Day { day: dayMap.day, month: dayMap.month, year: dayMap.year }),
      (day)-[:FIRST|NEXT*]->(hours:Hour),
      (hours)<-[:BEGINS]-(game:Game),
      (game)<-[:DEALS]-(employee:Employee)

WITH game, employee

ORDER BY game.timestamp DESC
WITH employee, head(collect(game)) as game

MATCH (game)<-[:CONTINUE*]-(games)

WITH employee.firstname as first_name, 
     employee.lastname as last_name, 
     SUM(games.interval) as time_on_floor

// Only return results for staff on the floor more than 80 minutes
WHERE time_on_floor > 80
RETURN first_name, last_name, time_on_floor

关于Neo4j - 24/7 赌场名册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21203743/

相关文章:

java - 按需将 Neo4J 加载到内存中以进行繁重的计算

java - Neo4j 非托管扩展和 GuardTimeoutException

java - 在 OS X 上使用带有 neo4j 的 Java 7

database - 如何将 CSV/MySQL 数据初始批量导入到 neo4j 数据库中

google-app-engine - GAE/J 中的数据库设计 : relational modelling vs entity-attribute-value

data-modeling - MySQL 数据模型到 Cassandra 有帮助吗?

neo4j - 在Neo4j浏览器查询中仅显示特定的关系类型

neo4j rest api cypher 似乎返回节点的笛卡尔积

javascript - Neo4j 与 Node.js 在数组中插入数组

redis - 在 Aerospike 中模拟数百万个存在检查的最佳方法?