csy3024-assignment-1/scripts/create.cyp

59 lines
2.1 KiB
Plaintext
Raw Normal View History

2024-05-16 16:22:58 +00:00
//Loads data to be imported
LOAD CSV WITH HEADERS FROM 'http://localhost:11001/project-fae68a42-5fd0-4364-9f5f-273e17593d8a/import_data.csv' AS line
WITH line,
//Splits the String from the Date column into it's components
SPLIT(line.Date, ' ') AS date_attributes,
//Splits the String from the FT column into it's components
SPLIT(line.FT, '-') AS full_time_score,
//Splits the String from the HT column into it's components
SPLIT(line.HT, '-') AS half_time_score
WITH line, date_attributes, full_time_score, half_time_score,
CASE date_attributes[2]
WHEN 'Jan' THEN '01'
WHEN 'Feb' THEN '02'
WHEN 'Mar' THEN '03'
WHEN 'Apr' THEN '04'
WHEN 'May' THEN '05'
WHEN 'Jun' THEN '06'
WHEN 'Jul' THEN '07'
WHEN 'Aug' THEN '08'
WHEN 'Sep' THEN '09'
WHEN 'Oct' THEN '10'
WHEN 'Nov' THEN '11'
WHEN 'Dec' THEN '12'
END AS month_number
//Creates the Round Nodes from the Round column in the import data
MERGE (r:Round {id: TOINTEGER(line.Round)})
//Creates the Team Nodes from the Team1 column in the import data
MERGE (t1:Team {name: line.Team1})
//Creates the Team Nodes from the Team2 column in the import data
MERGE (t2:Team {name: line.Team2})
//Creates the Match Nodes from the FT and HT columns in the import data
CREATE (m:Match {
date: date(date_attributes[3] + '-' + month_number + '-' + date_attributes[1]),
half_time_scores: [TOINTEGER(half_time_score[0]), TOINTEGER(half_time_score[1])],
full_time_scores: [TOINTEGER(full_time_score[0]), TOINTEGER(full_time_score[1])]
})
CREATE (r)-[:FIXTURE]->(m)
CREATE (t1)-[:PLAYED_IN {played: "Home"}]->(m)<-[:PLAYED_IN {played: "Away"}]-(t2);
MATCH (t:Team)-[p:PLAYED_IN]->(m:Match)
WITH p, m,
CASE
WHEN p.played = "Home" AND m.full_time_scores[0] > m.full_time_scores[1] THEN "Won"
WHEN p.played = "Home" AND m.full_time_scores[0] < m.full_time_scores[1] THEN "Lost"
WHEN p.played = "Away" AND m.full_time_scores[0] < m.full_time_scores[1] THEN "Won"
WHEN p.played = "Away" AND m.full_time_scores[0] > m.full_time_scores[1] THEN "Lost"
WHEN m.full_time_scores[0] = m.full_time_scores[1] THEN "Drew"
END AS result
SET p.result = result