Skip to content

Commit ed9dba6

Browse files
committed
First commit
1 parent 05c81d3 commit ed9dba6

28 files changed

+5772
-0
lines changed

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
*.class
2+
target/
3+
.Rhistory
4+
.project
5+
.classpath
6+
7+
.RData
8+
.Rhistory
9+
10+
11+
*.pyc

LICENSE

Whitespace-only changes.

data/events.json

+4,056
Large diffs are not rendered by default.

data/timelines.csv

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
Annex1,1374926400000,17,17,15,16,15,15,15,15,16,15,15,15,15,15,16,15,15,16,16,15,14,12,12,12,12,12,12,12,10,11,12,12,12,14,15,16,17,18,18,18,18,18,17,17,18,19,19,19,21,21,20,20,21,22,22,20,19,19,19,16
2+
Conf1,1374908400000,0,0,0,2,4,8,13,16,18,22,21,19,19,19,19,18,19,19,21,20,20,20,22,22,22,22,21,22,23,22,22,20,19,20,19,18,19,19,18,15,14,14,12,13,12,12,12,12,12,11,11,10,10,9,9,11,13,13,12,12
3+
Conf2,1374915600000,12,12,14,13,10,8,9,9,12,13,13,13,11,12,12,14,14,14,15,14,15,15,15,14,14,14,13,14,13,12,13,12,12,13,12,12,12,12,12,11,10,9,11,14,13,12,11,11,10,12,14,15,16,16,17,18,18,18,20,21
4+
Cafetaria,1374930000000,10,10,11,14,14,14,14,14,13,12,14,13,13,13,13,12,12,12,13,16,16,17,17,19,18,18,20,23,22,20,20,18,17,16,16,15,16,18,19,19,19,19,15,15,15,15,16,16,16,16,16,14,14,14,14,16,16,16,15,15
5+
Conf1,1374930000000,16,17,17,18,17,17,17,18,17,16,16,16,13,13,12,12,13,14,16,16,14,14,13,13,15,15,15,16,16,16,16,16,16,16,15,16,17,15,16,16,16,16,17,16,16,16,14,15,16,17,15,16,16,15,15,16,16,16,16,17
6+
Conf2,1374930000000,12,11,13,13,13,14,14,13,13,15,15,14,14,13,13,13,16,16,16,16,17,17,17,19,17,17,17,18,18,18,20,20,20,19,19,20,20,20,20,19,20,19,19,19,18,18,18,19,19,19,19,19,19,19,19,19,17,19,19,18
7+
Hall,1374919200000,13,12,13,12,11,14,13,14,13,14,15,14,14,16,16,16,16,17,19,19,19,17,19,21,21,23,24,23,24,24,24,23,22,22,21,21,21,22,21,20,19,18,17,19,18,18,19,20,20,20,21,22,21,21,21,21,22,22,18,19
8+
Conf2,1374937200000,17,17,19,19,18,17,15,15,16,16,16,15,15,13,13,13,11,11,10,9,9,9,9,9,9,8,7,6,6,5,4,4,4,4,4,3,2,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
9+
Hall,1374926400000,17,17,12,12,13,14,15,15,16,16,16,15,15,12,11,10,11,12,10,12,12,10,10,10,15,13,12,11,8,9,8,9,8,8,7,8,8,10,10,12,12,13,15,15,16,16,16,15,14,14,14,15,17,17,17,17,15,16,15,14
10+
Lounge,1374908400000,0,0,0,3,4,5,7,9,12,15,15,15,15,15,16,16,15,15,15,15,14,13,13,13,13,13,11,11,10,10,11,11,12,11,11,11,12,11,12,13,13,14,14,15,14,14,14,13,12,12,10,9,9,8,10,11,13,12,11,10
11+
Lounge,1374930000000,23,23,21,23,23,21,20,20,20,20,19,17,16,17,14,13,13,14,15,15,14,13,13,13,11,12,11,10,10,10,11,12,12,11,13,11,13,12,12,12,13,13,12,13,11,14,16,15,16,16,16,17,17,16,14,13,14,15,13,13
12+
Conf2,1374933600000,21,20,17,17,15,16,14,14,16,16,18,18,19,19,20,20,22,20,21,22,23,23,22,21,21,20,20,20,20,17,15,16,16,15,16,17,17,17,14,14,13,12,12,14,13,16,17,20,20,19,18,16,15,16,17,19,19,18,19,19
13+
Lounge,1374933600000,12,13,13,13,14,13,14,13,13,14,15,16,17,18,18,18,18,18,19,19,18,19,19,19,17,17,17,17,17,17,16,15,14,13,18,18,18,18,17,18,19,19,18,18,19,20,18,18,18,17,17,18,16,17,19,18,19,19,19,19
14+
Hall,1374930000000,14,14,16,17,17,15,16,17,16,16,17,17,18,18,18,17,16,15,15,16,14,13,14,13,12,12,12,14,14,14,13,12,14,15,17,17,18,18,18,18,18,19,21,20,21,21,19,18,18,17,16,17,18,17,16,16,17,16,16,17
15+
Annex1,1374937200000,22,22,23,24,21,20,19,17,17,17,16,15,15,15,14,14,13,13,12,12,12,11,11,10,9,9,8,7,6,6,5,5,4,4,4,3,3,3,3,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0
16+
Lounge,1374912000000,10,10,11,11,12,11,13,13,13,12,13,13,12,13,13,13,11,13,13,13,13,15,15,15,15,14,14,12,11,11,12,12,12,12,12,12,11,12,13,13,14,14,14,16,16,16,15,15,14,15,15,15,16,17,16,15,14,16,16,16
17+
Conf1,1374926400000,6,5,4,4,6,5,5,5,5,5,5,5,7,7,6,6,4,4,4,5,5,5,5,6,6,6,10,10,10,12,13,14,14,14,16,17,17,17,18,18,18,19,20,20,20,21,20,21,21,20,19,18,18,18,18,17,17,17,18,17
18+
Conf2,1374922800000,18,18,18,18,19,18,19,19,19,19,19,18,18,17,17,19,17,19,19,18,17,17,18,17,16,15,14,14,15,16,16,15,16,17,19,20,20,21,21,21,22,23,23,24,23,24,23,25,24,24,26,26,26,26,25,26,26,27,27,23
19+
Hall,1374912000000,17,17,21,22,21,22,21,21,22,22,22,21,22,22,24,21,20,19,19,21,20,20,19,20,22,21,24,23,22,25,25,23,22,20,19,22,23,22,23,24,21,22,22,22,22,19,20,18,19,19,19,20,20,20,21,21,19,19,20,20
20+
Annex1,1374908400000,0,0,0,5,7,11,13,14,16,17,17,16,16,14,12,13,13,12,12,13,14,15,15,15,15,15,14,14,14,16,15,15,16,15,17,18,16,17,16,13,13,14,11,11,12,13,13,11,12,13,13,15,15,13,12,15,15,16,17,17
21+
Annex1,1374922800000,19,20,20,20,19,19,19,18,17,16,16,16,17,15,16,16,16,16,14,15,15,13,13,14,13,12,12,12,12,11,11,12,14,14,13,14,11,13,12,13,14,13,12,12,15,16,16,14,15,15,15,15,16,16,15,15,15,14,16,17
22+
Cafetaria,1374908400000,0,0,0,5,8,10,12,17,21,23,24,23,22,22,20,21,21,22,22,23,22,21,21,20,19,18,19,19,19,17,17,18,17,17,17,17,17,16,18,18,18,17,19,19,19,18,17,17,18,18,18,20,20,20,20,20,21,23,22,21
23+
Cafetaria,1374937200000,14,15,15,16,14,13,14,13,14,14,14,13,13,13,13,13,10,10,9,8,8,6,6,6,5,5,5,5,5,5,5,4,3,3,3,3,3,2,2,2,2,2,2,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0
24+
Conf1,1374937200000,20,21,20,20,20,19,19,19,17,15,13,13,12,9,9,8,8,8,8,8,7,7,7,7,6,5,4,3,3,3,3,3,3,3,3,3,2,2,2,2,2,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
25+
Cafetaria,1374933600000,16,14,14,13,12,13,13,13,13,11,11,11,9,9,12,13,12,12,12,11,11,13,13,15,16,16,17,17,17,17,16,15,16,16,18,18,17,17,15,14,14,15,16,16,17,17,17,16,14,16,14,14,14,13,13,16,16,14,14,15
26+
Cafetaria,1374915600000,11,10,9,8,8,8,9,10,10,10,11,11,11,11,11,11,10,10,11,11,12,11,13,13,13,13,12,12,11,10,10,10,10,10,9,11,13,12,12,14,13,12,12,13,13,12,11,12,14,13,12,12,11,10,10,6,8,10,10,10
27+
Conf1,1374915600000,17,16,16,15,14,13,17,17,18,21,21,21,21,20,20,21,20,18,19,20,17,20,20,22,24,22,23,22,22,22,21,20,19,18,18,17,17,18,16,13,11,11,11,11,12,12,11,9,10,9,9,11,12,12,13,15,15,13,13,13
28+
Conf2,1374926400000,23,21,20,19,20,23,24,25,22,23,23,22,22,21,20,24,24,24,24,23,22,22,23,20,18,19,18,19,19,17,18,18,18,19,20,19,18,20,19,18,18,17,16,16,17,17,15,16,15,14,14,14,12,13,13,13,12,11,12,12
29+
Conf2,1374912000000,22,24,25,24,25,26,25,25,25,24,22,19,20,21,19,19,18,17,17,17,17,18,17,16,15,15,14,13,12,13,11,11,11,11,12,12,13,13,13,14,14,13,11,10,9,8,9,9,10,10,9,11,12,11,12,13,13,13,12,12
30+
Lounge,1374915600000,15,16,17,17,18,18,20,20,20,20,20,20,19,17,16,17,15,15,15,16,16,16,16,16,16,16,17,17,17,16,16,16,16,16,15,16,18,19,20,19,20,19,19,18,20,20,20,22,21,19,16,17,17,18,19,18,19,19,19,19
31+
Conf1,1374922800000,16,15,15,13,13,14,12,11,10,10,10,8,10,10,10,10,12,14,14,14,16,15,16,14,14,15,15,16,15,15,15,16,15,16,15,14,14,14,13,13,11,10,11,10,12,11,12,11,11,11,11,11,10,9,8,8,9,8,7,7
32+
Conf2,1374908400000,0,0,0,3,5,6,11,13,18,22,22,21,21,21,21,22,22,22,22,23,24,23,21,22,24,23,24,23,23,22,23,23,23,20,20,20,20,21,22,22,21,24,27,23,22,22,22,21,21,20,21,21,18,18,17,17,17,19,19,21
33+
Lounge,1374919200000,19,18,18,19,19,20,18,17,16,13,13,13,12,13,13,14,14,16,15,14,13,13,13,14,14,13,10,11,12,13,15,15,15,15,15,14,15,16,16,14,15,16,17,17,17,15,15,14,14,14,14,13,12,13,12,12,10,11,10,9
34+
Hall,1374915600000,18,19,18,17,17,18,17,18,19,18,17,17,17,17,17,17,17,16,19,19,18,18,17,17,16,16,17,16,18,18,20,22,23,21,24,23,23,21,20,20,21,22,21,20,19,20,21,24,22,21,20,18,18,16,17,18,17,12,13,14
35+
Conf1,1374933600000,17,17,19,20,20,19,22,20,19,18,18,18,17,16,15,16,14,14,14,11,10,10,10,11,11,13,15,15,12,14,14,15,15,15,15,14,14,14,15,16,15,14,13,13,15,17,17,17,15,17,17,17,15,15,15,16,17,16,16,18
36+
Conf2,1374919200000,22,22,23,24,23,23,22,23,22,23,22,24,22,20,22,20,20,22,21,20,21,21,20,20,20,19,19,18,18,17,17,17,18,19,19,17,16,14,14,15,15,16,16,17,18,16,16,17,17,15,17,17,17,16,18,18,18,20,18,19
37+
Annex1,1374930000000,20,18,17,18,18,18,18,18,18,21,21,24,25,23,23,21,23,25,24,24,24,23,23,21,21,22,23,22,22,20,18,18,18,18,19,19,17,17,19,17,18,19,17,17,17,16,15,14,15,16,15,16,16,16,14,15,15,17,17,17
38+
Hall,1374922800000,17,17,18,17,16,18,17,17,17,16,16,16,15,14,13,12,13,14,14,14,15,15,15,17,17,17,17,17,17,16,14,14,16,17,17,18,17,16,16,17,16,16,15,14,15,15,16,15,15,19,19,18,16,17,16,17,17,16,16,17
39+
Cafetaria,1374922800000,13,14,15,16,17,16,18,18,16,17,16,17,17,17,17,18,19,18,20,21,22,23,23,23,21,21,20,18,19,19,18,17,15,15,15,15,15,14,13,13,13,13,13,12,12,13,13,13,12,9,9,8,9,8,8,11,12,11,11,10
40+
Annex1,1374915600000,25,25,25,24,24,23,23,21,21,23,23,22,22,21,22,22,21,20,18,17,19,20,21,21,21,20,19,21,19,19,21,18,17,16,17,17,16,17,18,18,19,20,18,19,18,20,20,20,22,20,21,21,20,19,18,19,19,20,20,19
41+
Hall,1374908400000,0,0,0,5,9,9,13,15,17,18,18,18,18,18,17,15,15,15,13,13,13,12,13,14,12,11,11,12,12,14,15,15,15,15,15,15,16,14,11,12,12,14,17,18,17,17,17,15,15,13,14,14,15,16,16,17,16,16,16,16
42+
Lounge,1374922800000,10,10,10,12,12,15,15,18,19,18,19,18,18,17,17,19,19,19,21,21,20,19,19,17,16,17,18,20,20,21,21,22,24,24,24,23,22,21,21,21,20,21,20,21,20,20,20,22,20,19,19,19,19,20,23,24,23,22,23,23
43+
Hall,1374937200000,9,8,8,8,9,9,9,9,9,10,9,8,8,8,7,7,6,5,5,3,3,2,2,2,2,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
44+
Conf1,1374912000000,11,11,11,13,12,12,12,13,13,12,12,14,13,12,12,12,12,10,10,12,13,14,14,14,15,13,12,10,10,10,10,9,10,12,11,10,10,11,13,13,13,14,14,14,16,17,17,18,20,19,18,19,21,20,19,19,17,17,17,18
45+
Lounge,1374926400000,22,21,20,20,22,26,25,26,26,24,24,23,22,22,20,20,18,18,17,17,18,15,15,14,13,13,14,13,12,15,14,15,15,16,17,18,18,18,18,17,17,18,19,18,21,22,21,21,22,23,24,24,22,23,23,23,22,24,24,24
46+
Lounge,1374937200000,20,20,21,20,20,19,20,19,18,18,17,17,15,15,14,14,14,11,10,9,8,8,8,7,7,7,5,5,5,4,4,4,4,4,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
47+
Annex1,1374919200000,18,18,17,17,16,16,16,19,20,17,17,17,18,18,18,18,18,19,19,18,17,19,20,18,18,17,17,20,20,19,19,18,18,17,19,18,18,17,16,17,18,18,18,16,19,19,20,19,19,21,21,22,21,20,22,22,23,22,20,20
48+
Annex1,1374933600000,18,18,19,19,20,21,20,19,20,22,22,22,22,20,19,19,21,22,22,21,22,19,18,18,18,16,17,17,16,16,16,19,19,18,17,19,19,19,17,19,20,19,17,18,20,19,20,18,19,21,21,20,20,20,22,22,22,23,22,23
49+
Cafetaria,1374919200000,11,12,12,12,11,13,12,14,14,14,13,12,13,12,12,14,15,15,15,13,13,14,14,13,13,12,12,13,14,14,14,13,13,13,12,11,12,10,10,9,11,10,10,12,11,11,11,13,14,15,15,14,13,14,13,13,13,13,12,13
50+
Hall,1374933600000,18,18,17,16,16,15,14,15,17,16,16,16,15,16,16,16,15,14,14,15,15,15,13,15,15,15,15,16,16,15,16,17,16,16,13,10,11,11,12,13,12,10,11,11,12,11,11,10,10,9,9,9,10,9,11,9,9,8,8,8
51+
Cafetaria,1374912000000,20,20,19,19,19,19,17,17,18,19,19,18,19,21,23,21,21,21,21,20,20,19,18,17,21,19,19,20,20,20,22,24,21,22,21,18,18,18,17,16,16,16,17,19,18,18,18,17,14,12,12,13,14,14,13,14,14,14,14,13
52+
Cafetaria,1374926400000,11,12,12,12,13,15,15,14,17,18,18,19,20,22,22,22,21,22,23,25,25,25,28,28,33,32,31,31,29,28,27,27,25,22,22,21,20,19,19,19,17,17,16,16,15,15,16,15,14,13,13,12,11,10,9,11,10,9,11,10
53+
Annex1,1374912000000,15,13,13,13,13,13,13,14,16,16,15,15,15,15,14,14,14,14,13,12,11,16,14,17,17,17,17,17,18,18,17,16,17,18,17,17,17,17,17,16,15,16,17,18,18,21,21,24,23,22,22,22,23,24,22,22,24,24,24,25
54+
Conf1,1374919200000,14,16,17,16,17,16,17,16,16,15,14,14,14,15,15,15,16,16,15,15,15,16,16,12,14,12,13,12,13,15,14,13,12,12,12,14,12,12,11,11,13,15,16,15,14,13,13,13,13,13,13,14,15,15,16,17,16,16,16,16

pom.xml

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>svend</groupId>
6+
<artifactId>storm-poc</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>storm-poc</name>
11+
<url>http://maven.apache.org</url>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<org.springframework.version>3.0.5.RELEASE</org.springframework.version>
16+
<scala.version>2.10.1</scala.version>
17+
<log4j.version>1.2.16</log4j.version>
18+
<log.logback.version>1.0.13</log.logback.version>
19+
<log.sl4j.version>1.7.5</log.sl4j.version>
20+
<junit.version>4.4</junit.version>
21+
<akka.version>2.3-M2</akka.version>
22+
<akka.scala.version>2.10</akka.scala.version>
23+
<spring.framework.version>3.1.0.RELEASE</spring.framework.version>
24+
<storm.version>0.9.0.1</storm.version>
25+
<cassandra.version>2.0.1</cassandra.version>
26+
<google.gson.version>2.2.4</google.gson.version>
27+
</properties>
28+
29+
<repositories>
30+
<repository>
31+
<id>clojars.org</id>
32+
<url>http://clojars.org/repo</url>
33+
</repository>
34+
35+
</repositories>
36+
37+
<dependencies>
38+
39+
<dependency>
40+
<groupId>com.google.code.gson</groupId>
41+
<artifactId>gson</artifactId>
42+
<version>${google.gson.version}</version>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>ch.qos.logback</groupId>
47+
<artifactId>logback-core</artifactId>
48+
<version>${log.logback.version}</version>
49+
</dependency>
50+
<dependency>
51+
<groupId>ch.qos.logback</groupId>
52+
<artifactId>logback-classic</artifactId>
53+
<version>${log.logback.version}</version>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.slf4j</groupId>
57+
<artifactId>slf4j-api</artifactId>
58+
<version>${log.sl4j.version}</version>
59+
</dependency>
60+
61+
<dependency>
62+
<groupId>junit</groupId>
63+
<artifactId>junit</artifactId>
64+
<version>${junit.version}</version>
65+
<scope>test</scope>
66+
</dependency>
67+
68+
<dependency>
69+
<groupId>storm</groupId>
70+
<artifactId>storm</artifactId>
71+
<version>${storm.version}</version>
72+
<scope>compile</scope>
73+
</dependency>
74+
75+
<dependency>
76+
<groupId>org.codehaus.jackson</groupId>
77+
<artifactId>jackson-core-asl</artifactId>
78+
<version>1.9.12</version>
79+
</dependency>
80+
81+
<dependency>
82+
<groupId>org.codehaus.jackson</groupId>
83+
<artifactId>jackson-mapper-asl</artifactId>
84+
<version>1.9.12</version>
85+
</dependency>
86+
87+
<dependency>
88+
<groupId>com.datastax.cassandra</groupId>
89+
<artifactId>cassandra-driver-core</artifactId>
90+
<version>${cassandra.version}</version>
91+
</dependency>
92+
93+
<dependency>
94+
<groupId>org.xerial.snappy</groupId>
95+
<artifactId>snappy-java</artifactId>
96+
<version>1.0.5</version>
97+
<type>jar</type>
98+
<scope>compile</scope>
99+
</dependency>
100+
</dependencies>
101+
102+
<build>
103+
<plugins>
104+
<plugin>
105+
<artifactId>maven-compiler-plugin</artifactId>
106+
<version>3.0</version>
107+
<configuration>
108+
<source>1.7</source>
109+
<target>1.7</target>
110+
</configuration>
111+
</plugin>
112+
</plugins>
113+
<pluginManagement>
114+
<plugins>
115+
<plugin>
116+
<groupId>org.apache.maven.plugins</groupId>
117+
<artifactId>maven-surefire-plugin</artifactId>
118+
<version>2.12</version>
119+
</plugin>
120+
</plugins>
121+
</pluginManagement>
122+
</build>
123+
124+
</project>

src/main/R/plottimeline.R

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
############################
2+
# plot the cafetaria timeline
3+
4+
setwd("/Users/svend/dev/playgrounds/stormRoomOccupancy/src/main/R")
5+
6+
# all timelines (one row per hour => several rows are necessary to have the full history of a room)
7+
colnames.minutes = paste("m", seq(0,59), sep="")
8+
colnames.all <- c("roomId", "startTime", colnames.minutes)
9+
timelines <- read.table("../../../data/timelines.csv", header=FALSE, sep=",", col.names=colnames.all)
10+
11+
# minute by minute occupancy of cafetaria
12+
cafetaria <- timelines[timelines$roomId == "Cafetaria",]
13+
cafetaria <- cafetaria[order(cafetaria$startTime),]
14+
caf.occupancies <- c(t(cafetaria[,colnames.minutes]))
15+
16+
# plot
17+
library("ggplot2")
18+
occupancies <- data.frame(cafetaria=caf.occupancies, time=seq(1,length(caf.occupancies)))
19+
20+
ggplot(occupancies) +
21+
geom_line(aes(time, cafetaria)) +
22+
scale_y_discrete ("Number of people", breaks = seq(0,35, 5)) +
23+
scale_x_discrete("Time", breaks = seq(1, 540, 60), labels=paste (seq(9,17), ":00", sep="")) +
24+
ggtitle("Cafetaria occupancy") +
25+
theme(text = element_text(size=24))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package com.kiku.gridlattice;
2+
3+
import com.datastax.driver.core.*;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
6+
7+
import java.util.Set;
8+
9+
/**
10+
* Created by rajan on 06/04/2014.
11+
*/
12+
public class CassandraConnection {
13+
14+
private static final Logger LOGGER = LoggerFactory
15+
.getLogger(CassandraConnection.class);
16+
17+
private static CassandraConnection _instance;
18+
private static Cluster cluster;
19+
private static Session session;
20+
private static String connectionDetails;
21+
private static String keySpace = "EVENT_POC";
22+
23+
static {
24+
25+
if (_instance == null) {
26+
_instance = new CassandraConnection();
27+
}
28+
}
29+
30+
private CassandraConnection() {
31+
32+
try {
33+
34+
// TODO Convert this dynamic configuration
35+
String serverIP1 = "127.0.0.1";
36+
//String serverIP2 = "gbl04116.systems.uk.hsbc";
37+
//String serverIP3 = "gbl04117.systems.uk.hsbc";
38+
//String serverIP4 = "gbl04118.systems.uk.hsbc";
39+
40+
LOGGER.info(String.format("Connecting to cluster keyspace=%s....", keySpace));
41+
42+
//String[] hosts = {"gbl04115.systems.uk.hsbc", "gbl04116.systems.uk.hsbc", "gbl04117.systems.uk.hsbc", "gbl04118.systems.uk.hsbc"};
43+
String[] hosts = {"127.0.0.1"};
44+
45+
cluster = Cluster.builder()
46+
.addContactPoints(hosts)
47+
.build();
48+
//cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(30000);
49+
50+
session = cluster.connect(keySpace);
51+
52+
//LOGGER.info(String.format("Connected to cluster=%s hosts=%s",
53+
// session.getCluster().getMetadata().getClusterName(),
54+
// session.getCluster().getMetadata().getAllHosts()));
55+
56+
StringBuilder s = new StringBuilder();
57+
s.append(String.format("Data storage cluster=%s", session.getCluster().getMetadata().getClusterName()));
58+
Set<Host> allHosts = cluster.getMetadata().getAllHosts();
59+
for (Host h : allHosts) {
60+
s.append("[");
61+
s.append(h.getDatacenter());
62+
s.append("-");
63+
s.append(h.getRack());
64+
s.append("-");
65+
s.append(h.getAddress());
66+
s.append("]");
67+
}
68+
69+
connectionDetails = s.toString();
70+
LOGGER.info(String.format("Connected to %s", connectionDetails));
71+
72+
}
73+
catch (Exception ex) {
74+
LOGGER.error(String.format("Failed to connect to Cassandra Cluster for keyspace=$s",keySpace, ex));
75+
throw new RuntimeException(ex);
76+
}
77+
}
78+
79+
public static void close() {
80+
if (getCluster() != null) {
81+
82+
LOGGER.info(String.format("Closing %s ...", connectionDetails));
83+
getSession().close();
84+
getCluster().close();
85+
LOGGER.info(String.format("Closed"));
86+
}
87+
}
88+
89+
90+
public static String getKeySpace() {
91+
return keySpace;
92+
}
93+
94+
public static Cluster getCluster() {
95+
return cluster;
96+
}
97+
98+
public static Session getSession() {
99+
return session;
100+
}
101+
102+
public static ResultSet execute(Statement query) {
103+
if (query != null) {
104+
return session.execute(query);
105+
}
106+
return null;
107+
}
108+
109+
public static ResultSet execute(String query) {
110+
if (query != null) {
111+
return session.execute(query);
112+
}
113+
return null;
114+
}
115+
116+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.kiku.gridlattice;
2+
3+
import java.io.File;
4+
import java.io.FileWriter;
5+
import java.io.IOException;
6+
7+
import com.kiku.gridlattice.timeline.HourlyTimeline;
8+
9+
/**
10+
* short "java script" (aha) to provide an easy to import csv file from R
11+
*
12+
*/
13+
public class ExtractTimelines {
14+
15+
public static void main(String[] args) {
16+
17+
System.out.println("dumping timelines from Cassandra to data/timelines.csv...");
18+
19+
try (FileWriter fw = new FileWriter(new File("data/timelines.csv"))) {
20+
for (HourlyTimeline timeline : StormDB.DB.getAllTimelines()) {
21+
fw.write(timeline.toCsv() + "\n");
22+
}
23+
} catch (IOException e) {
24+
e.printStackTrace();
25+
}
26+
27+
System.out.println("...done");
28+
29+
}
30+
31+
}

0 commit comments

Comments
 (0)