这是来自数据库模型的原始图像,用于赌场的 24/7 员工名册:

在肯尼的回答中,图像上半部分的时间图,每年是否有 12 个月份节点,然后指向一排日节点,其中有一个以上的日节点,其第一天的值为 1月?
对,那是正确的。我在下图中对此进行了建模。

我会为每年构建这些子图,还是会使用特定的查询来添加随着时间的推移不存在的节点?我知道有一个查询可以做到这一点,但它需要考虑月份节点的最后一天并创建正确的结束关系?
我创建了一个 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)
我会遇到闰年或夏令时的问题吗?
不,这应该不是问题,但可能取决于您提出的问题。这是特定于上下文的。由于我们不依赖数据结构在用户界面中构建日历,而是仅回答有关特定日期的特定问题,因此规则是从您导入的数据中继承的。
答案图像的下半部分是游戏节点,它们是否只有一个员工和位置关系?我不确定如何判断将哪个员工分配到哪个表(不向关系边缘添加属性),我应该向边缘添加属性还是应该为每对使用单独的节点?
有一个员工节点和一个位置节点。这样,您可以从员工节点或位置节点开始了解有关该对象的某些内容以及它与其他对象的关系。
我还尝试用一些问题(红色框)计划出一个图表,它是在 illustrator 中完成的,有点乱,我很想知道 Kenny 的图表图像是否是在特定应用程序中完成的,如果是,是哪一个,尽管我认为图表在视觉上往往会变得纠结和凌乱。
我用来生成图形数据模型图像的工具是http://www.apcjones.com/arrows/#
要连接节点,只需将鼠标指针突出显示在节点圆圈的外部,然后单击并将关系拖动到另一个节点。这个小应用程序是开源的,只能在 Chrome 浏览器中运行。
至于您的完整数据模型,我构建了一个 Cypher 数据集示例,因为我真的认为您的领域很有趣。您可以在此处找到这些查询:https ://gist.github.com/kbastani/8529380
这是我使用的数据模型:

回到你之前的帖子,你有一个问题:
哪些员工在某一天在场上工作了 80 分钟或更长时间?
这是回答该问题的 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