Skip to content

Instantly share code, notes, and snippets.

@nawroth
Forked from dirkschumacher/gist:39b47a50f39e52deacf6
Last active August 29, 2015 14:01
Show Gist options
  • Save nawroth/f14959bb57bc5a5d776f to your computer and use it in GitHub Desktop.
Save nawroth/f14959bb57bc5a5d776f to your computer and use it in GitHub Desktop.
= Donations to German parties
:neo4j-version: 2.1.0
Data from here: https://github.com/pudo/kompromatron
== Sample Data Set
//setup
[source,cypher]
----
LOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/pudo/kompromatron/master/data/spenden.csv" AS data
WITH data SKIP 0 LIMIT 375
MERGE (p:Party { name: data.partei_name, acronym: data.partei_acronym})
MERGE (d:Donor { name: data.spender_name})
MERGE (t:DonorType {theType: data.spender_typ})
CREATE d-[:DONATES_TO {value: toFloat(data.betrag_eur), year: toInt(data.jahr)}]->p
CREATE d-[:IS]->t
----
== Some Numbers
[source,cypher]
----
MATCH (d:Donor) RETURN count(*) AS NumberOfDonors
----
//table
[source,cypher]
----
MATCH (d:Party) RETURN d.name AS PartyName ORDER BY d.name
----
//table
[source,cypher]
----
MATCH (d:Donor)-[r:DONATES_TO]->(p:Party)
RETURN r.year AS Year, count(r.year) AS NumberOfRecords
ORDER BY r.year ASC
----
//table
[source,cypher]
----
MATCH (d:Donor)-[r:DONATES_TO]->(p:Party) RETURN p.name AS PartyName, round(sum(r.value)) as totalDonationsEur ORDER BY totalDonationsEur DESC
----
//table
== Top 10 Donors
[source,cypher]
----
MATCH (d:Donor)-[r:DONATES_TO]->(p:Party) RETURN d.name AS Donor, round(sum(r.value)) as totalDonationsInEUR ORDER BY totalDonationsInEUR DESC
LIMIT 10
----
//table
== Similiar parties by number of common donors
The more common donors two parties have the higher they appear in the table below.
[source,cypher]
----
MATCH path =(p1:Party)<-[r1:DONATES_TO]-(d:Donor)-[r2:DONATES_TO]->(p2:Party)
WHERE p1 <> p2 AND p1.name < p2.name
WITH p1.name AS Party1, p2.name AS Party2, count(path) AS NoCommonDonors, collect(path) as Paths
ORDER BY NoCommonDonors DESC
LIMIT 3
UNWIND Paths AS p
RETURN p
----
//graph_result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment