Commit 86e46b52 authored by Sören Henning's avatar Sören Henning

cassandra driver works now

parent 3d5e9585
package anomalydetection;
import java.time.Instant;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
import anomalydetection.measurement.AnomalyScoredMeasurement;
import anomalydetection.storage.CassandraDriver;
import anomalydetection.timeseries.TimeSeries;
import teetime.framework.Execution;
public class AnomalyDetectionTool {
public static void main(final String[] args) {
String ipAddress = "192.168.99.100";
int port = 32770;
String keyspace = "demo2";
Cluster cluster = Cluster.builder().addContactPoint(ipAddress).withPort(port).build();
Session session = cluster.connect(keyspace);
CassandraDriver cassandraDriver = new CassandraDriver(session, "measurements");
cassandraDriver.storeMeasurement("abc", new AnomalyScoredMeasurement(Instant.now(), 1200, 1100, 0.11));
TimeSeries timeSeries = cassandraDriver.retrieveTimeSeries("abc", Instant.now().minusSeconds(60 * 60), Instant.now());
System.out.println(timeSeries);
session.close();
/*
* String ipAddress = "192.168.99.100";
* int port = 32770;
* String keyspace = "demo3";
*
* Cluster cluster = Cluster.builder().addContactPoint(ipAddress).withPort(port).build();
* Session session = cluster.connect(keyspace);
*
* CassandraDriver cassandraDriver = new CassandraDriver(session, "measurements");
* cassandraDriver.storeMeasurement("abc", new AnomalyScoredMeasurement(Instant.now(), 1200, 1100, 0.11));
* cassandraDriver.storeMeasurement("abc", new AnomalyScoredMeasurement(Instant.now(), 1150, 1000, 0.12));
* cassandraDriver.storeMeasurement("abc", new AnomalyScoredMeasurement(Instant.now(), 1150, 1200, 0.13));
* cassandraDriver.storeMeasurement("abc", new AnomalyScoredMeasurement(Instant.now(), 1200, 1100, 0.12));
*
* TimeSeries timeSeries = cassandraDriver.retrieveTimeSeries("abc", Instant.now().minusSeconds(60 * 60), Instant.now());
* System.out.println(timeSeries);
*
* session.close();
*/
final AnomalyDetectionConfiguration configuration = new AnomalyDetectionConfiguration();
final Execution<AnomalyDetectionConfiguration> analysis = new Execution<AnomalyDetectionConfiguration>(configuration);
......
......@@ -27,20 +27,19 @@ public class CassandraDriver implements StorageDriver {
@Override
public TimeSeries retrieveTimeSeries(final String seriesId, final Instant start, final Instant end) {
Select statement = QueryBuilder.select("time", "measurement")
final Select statement = QueryBuilder.select("time", "measurement")
.from(this.table)
.where(QueryBuilder.eq("series_id", seriesId))
.and(QueryBuilder.gte("time", start.toEpochMilli()))
.and(QueryBuilder.lte("time", end.toEpochMilli()))
.orderBy(QueryBuilder.asc("time"));
System.out.println(statement.toString());
ResultSet results = session.execute(statement);
final ResultSet results = session.execute(statement);
TimeSeries timeSeries = new TimeSeries();
final TimeSeries timeSeries = new TimeSeries();
for (Row row : results) {
Instant time = row.getTimestamp("time").toInstant();
double value = row.getDouble("measurement");
final Instant time = row.getTimestamp("time").toInstant();
final double value = row.getDouble("measurement");
timeSeries.appendEnd(new TimeSeriesPoint(time, value));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment