Skip to content

Instantly share code, notes, and snippets.

@tekiegirl
Last active August 29, 2015 14:12
Show Gist options
  • Save tekiegirl/fdc719b1b1b62a6ebc68 to your computer and use it in GitHub Desktop.
Save tekiegirl/fdc719b1b1b62a6ebc68 to your computer and use it in GitHub Desktop.

Calendar

Initial Data Setup

CREATE INDEX ON :Year(year);
CREATE INDEX ON :Month(order);
USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM "https://dl.dropboxusercontent.com/u/2900504/years.csv" AS ycsvLine
//LOAD CSV WITH HEADERS FROM "https://gist.githubusercontent.com/jacquibo/ed5178d0358dbb724444/raw/d3c0a48f01f23dbd9bc7fec8e08870d470d7c9da/years.csv" AS ycsvLine

WITH ycsvLine
MERGE (year:Year {year: toInt(ycsvLine.year), leap: toInt(ycsvLine.leap)})

WITH year

MATCH years = (:Year)
WITH years, year
LOAD CSV WITH HEADERS FROM "https://dl.dropboxusercontent.com/u/2900504/months.csv" AS mcsvLine

WITH mcsvLine, years, year
MERGE (year)<-[r:IN]-(month:Month {order: toInt(mcsvLine.order), name: trim(mcsvLine.name), short_name: left(trim(mcsvLine.name), 3), days: toInt(mcsvLine.days), code: toInt(mcsvLine.code) })
USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM "https://dl.dropboxusercontent.com/u/2900504/dates31.csv" AS csvLine

WITH csvLine
MATCH months = (:Month {days: 31})
FOREACH (m IN nodes(months)| MERGE (m)<-[r:IN]-(date:Date {date: toInt(csvLine.date)}) )
USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM "https://dl.dropboxusercontent.com/u/2900504/dates30.csv" AS csvLine

WITH csvLine
MATCH months = (:Month {days: 30})
FOREACH (m IN nodes(months)| MERGE (m)<-[r:IN]-(date:Date {date: toInt(csvLine.date)}) )
USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM "https://dl.dropboxusercontent.com/u/2900504/dates28.csv" AS csvLine

WITH csvLine
MATCH months = (:Month {days: 28})
FOREACH (m IN nodes(months)| MERGE (m)<-[r:IN]-(date:Date {date: toInt(csvLine.date)}) )
USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM "https://dl.dropboxusercontent.com/u/2900504/weekdays.csv" AS csvLine
WITH csvLine
MERGE (day:WeekDay {name: trim(csvLine.day), code: toInt(csvLine.code)})

WITH day
MATCH dates = (date:Date)-[]->(year:Year)
FOREACH (d IN dates|  )
MATCH (n)
RETURN n, labels(n), id(n)

Notes

  • May be good to create month info nodes, with name, etc, and each year has month nodes with just order and relationship to the month info node. That way can rename months to a different language, etc, easily.

  • Date creation should be done in app code, with for loop (for 1 to month.days)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment