Skip to content

Commit

Permalink
Allow History requests to use zoned times
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyjward committed Nov 24, 2021
1 parent a12b3a7 commit 879184b
Show file tree
Hide file tree
Showing 16 changed files with 242 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.sensinact.gateway.historic.storage.reader.api.HistoricSpatialRequest;
import org.eclipse.sensinact.gateway.historic.storage.reader.api.HistoricSpatioTemporalRequest;
import org.eclipse.sensinact.gateway.historic.storage.reader.api.HistoricTemporalRequest;
import org.eclipse.sensinact.gateway.historic.storage.reader.api.HistoricValueRequest;
import org.eclipse.sensinact.gateway.tools.connector.influxdb.InfluxDbConnector;

/**
Expand Down Expand Up @@ -70,5 +71,11 @@ public HistoricSpatioTemporalRequest newSpatioTemporalRequest() {
return request;
}

@Override
public HistoricValueRequest newValueRequest() {
// TODO Auto-generated method stub
return null;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2021 Kentyou.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Kentyou - initial API and implementation
*/
package org.eclipse.sensinact.gateway.agent.storage.influxdb.read;

import java.time.ZonedDateTime;

import org.eclipse.sensinact.gateway.tools.connector.influxdb.InfluxDbConnector;


public abstract class AbstractInfluxDBTemporalRequest<T> extends InfluxDBRequest<T> {

protected String function;
protected long temporalWindow;
protected ZonedDateTime start;
protected ZonedDateTime end;

public AbstractInfluxDBTemporalRequest(InfluxDbConnector influxDbConnector) {
super(influxDbConnector);
}

public void setHistoricStartTime(ZonedDateTime fromTime) {
this.start = fromTime;
}

public void setHistoricEndTime(ZonedDateTime toTime) {
this.end = toTime;
}

public void setFunction(String function) {
this.function = function;
}

public void setTemporalWindow(long temporalWindow) {
this.temporalWindow = temporalWindow;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2021 Kentyou.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Kentyou - initial API and implementation
*/
package org.eclipse.sensinact.gateway.agent.storage.influxdb.read;

import java.time.ZonedDateTime;

import org.eclipse.sensinact.gateway.tools.connector.influxdb.InfluxDbConnector;


public abstract class AbstractInfluxDBValueRequest<T> extends InfluxDBRequest<T> {

protected ZonedDateTime time;

public AbstractInfluxDBValueRequest(InfluxDbConnector influxDbConnector) {
super(influxDbConnector);
}

public void setHistoricTime(ZonedDateTime time) {
this.time = time;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
package org.eclipse.sensinact.gateway.agent.storage.influxdb.read;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -40,8 +40,6 @@ public abstract class InfluxDBRequest<T> implements HistoricRequest<T>{
protected String provider;
protected String service;
protected String resource;
protected LocalDateTime start;
protected LocalDateTime end;

protected InfluxDbConnector influxDbConnector;

Expand Down Expand Up @@ -71,16 +69,6 @@ public void setServiceIdentifier(String service) {
public void setResourceIdentifier(String resource) {
this.resource = resource;
}

@Override
public void setHistoricStartTime(LocalDateTime fromTime) {
this.start = fromTime;
}

@Override
public void setHistoricEndTime(LocalDateTime toTime) {
this.end = toTime;
}

protected InfluxDBTagDTO getDataSourcePath() {
InfluxDBTagDTO historicAttributeDTO = new InfluxDBTagDTO();
Expand Down Expand Up @@ -217,7 +205,7 @@ protected List<TemporalDTO> get(InfluxDbDatabase db, String measurement, List<In
* @param start the LocalDateTime defining the chronological beginning of records in which to search
* @return the JSON formated String result of the research
*/
protected List<TemporalDTO> get(InfluxDbDatabase db, String measurement, List<InfluxDBTagDTO> tags, LocalDateTime start) {
protected List<TemporalDTO> get(InfluxDbDatabase db, String measurement, List<InfluxDBTagDTO> tags, ZonedDateTime start) {
QueryResult result = db.getResult(measurement, tags, Arrays.asList("time","value"), start);
List<TemporalDTO> list = buildTemporalDTOList(result);
return list;
Expand All @@ -237,7 +225,7 @@ protected List<TemporalDTO> get(InfluxDbDatabase db, String measurement, List<In
*
* @return the JSON formated String result of the research
*/
protected List<TemporalDTO> get(InfluxDbDatabase db, String measurement, List<InfluxDBTagDTO> tags, String function, long timeWindow, LocalDateTime start) {
protected List<TemporalDTO> get(InfluxDbDatabase db, String measurement, List<InfluxDBTagDTO> tags, String function, long timeWindow, ZonedDateTime start) {
QueryResult result = db.getResult(measurement, tags, "value", function, timeWindow, start);
List<TemporalDTO> list = buildTemporalDTOList(result);
return list;
Expand All @@ -256,7 +244,7 @@ protected List<TemporalDTO> get(InfluxDbDatabase db, String measurement, List<I
*
* @return the JSON formated String result of the research
*/
protected List<TemporalDTO> get(InfluxDbDatabase db, String measurement, List<InfluxDBTagDTO> tags, LocalDateTime start, LocalDateTime end) {
protected List<TemporalDTO> get(InfluxDbDatabase db, String measurement, List<InfluxDBTagDTO> tags, ZonedDateTime start, ZonedDateTime end) {
QueryResult result = db.getResult(measurement, tags, Arrays.asList("time","value"), start, end);
List<TemporalDTO> list = buildTemporalDTOList(result);
return list;
Expand All @@ -277,7 +265,7 @@ protected List<TemporalDTO> get(InfluxDbDatabase db, String measurement, List<In
*
* @return the JSON formated String result of the research
*/
protected List<TemporalDTO> get(InfluxDbDatabase db, String measurement, List<InfluxDBTagDTO> tags, String function, long timeWindow, LocalDateTime start, LocalDateTime end) {
protected List<TemporalDTO> get(InfluxDbDatabase db, String measurement, List<InfluxDBTagDTO> tags, String function, long timeWindow, ZonedDateTime start, ZonedDateTime end) {
QueryResult result = db.getResult(measurement, tags, "value", function, timeWindow, start, end);
List<TemporalDTO> list = buildTemporalDTOList(result);
return list;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
*/
package org.eclipse.sensinact.gateway.agent.storage.influxdb.read;

import java.util.Collections;
import java.util.List;

import org.eclipse.sensinact.gateway.historic.storage.reader.api.HistoricSpatialRequest;
import org.eclipse.sensinact.gateway.historic.storage.reader.api.SpatialDTO;
import org.eclipse.sensinact.gateway.tools.connector.influxdb.InfluxDbConnector;


public class InfluxDBSpatialRequest extends InfluxDBRequest<SpatialDTO> implements HistoricSpatialRequest{
public class InfluxDBSpatialRequest extends AbstractInfluxDBValueRequest<SpatialDTO> implements HistoricSpatialRequest{

protected String region;

Expand All @@ -27,8 +24,8 @@ public InfluxDBSpatialRequest(InfluxDbConnector influxDbConnector) {
}

@Override
public List<SpatialDTO> execute() {
return Collections.emptyList();
public SpatialDTO execute() {
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
import org.eclipse.sensinact.gateway.tools.connector.influxdb.InfluxDbConnector;


public class InfluxDBSpatioTemporalRequest extends InfluxDBRequest<SpatioTemporalDTO> implements HistoricSpatioTemporalRequest{
public class InfluxDBSpatioTemporalRequest extends AbstractInfluxDBTemporalRequest<List<SpatioTemporalDTO>> implements HistoricSpatioTemporalRequest{

protected String region;
protected String function;
protected long temporalWindow;

public InfluxDBSpatioTemporalRequest(InfluxDbConnector influxDbConnector) {
super(influxDbConnector);
Expand All @@ -33,16 +31,6 @@ public List<SpatioTemporalDTO> execute() {
return Collections.emptyList();
}

@Override
public void setFunction(String function) {
this.function = function;
}

@Override
public void setTemporalWindow(long temporalWindow) {
this.temporalWindow = temporalWindow;
}

@Override
public void setRegion(String region) {
this.region = region;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
import org.eclipse.sensinact.gateway.tools.connector.influxdb.InfluxDbDatabase;


public class InfluxDBTemporalRequest extends InfluxDBRequest<TemporalDTO> implements HistoricTemporalRequest{
public class InfluxDBTemporalRequest extends AbstractInfluxDBTemporalRequest<List<TemporalDTO>> implements HistoricTemporalRequest {

protected String function;
protected long temporalWindow;

public InfluxDBTemporalRequest(InfluxDbConnector influxDbConnector) {
super(influxDbConnector);
}
Expand All @@ -39,28 +36,18 @@ public List<TemporalDTO> execute() {
s = super.get(db,
super.measurement.concat("_num"),
Arrays.asList(super.getDataSourcePath(), super.getResource()),
super.start,
super.end);
start,
end);
} else {
s = super.get(db,
super.measurement.concat("_num"),
Arrays.asList(super.getDataSourcePath(), super.getResource()),
this.function,
this.temporalWindow <=0?10000:temporalWindow,
super.start,
super.end);
start,
end);
}
return s;
}

@Override
public void setFunction(String function) {
this.function = function;
}

@Override
public void setTemporalWindow(long temporalWindow) {
this.temporalWindow = temporalWindow;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2021 Kentyou.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Kentyou - initial API and implementation
*/
package org.eclipse.sensinact.gateway.agent.storage.influxdb.read;

import org.eclipse.sensinact.gateway.historic.storage.reader.api.HistoricValueRequest;
import org.eclipse.sensinact.gateway.historic.storage.reader.api.TemporalDTO;
import org.eclipse.sensinact.gateway.tools.connector.influxdb.InfluxDbConnector;


public class InfluxDBValueRequest extends AbstractInfluxDBValueRequest<TemporalDTO> implements HistoricValueRequest{

protected String region;

public InfluxDBValueRequest(InfluxDbConnector influxDbConnector) {
super(influxDbConnector);
}

@Override
public TemporalDTO execute() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
public interface HistoricProvider {

HistoricValueRequest newValueRequest();

HistoricTemporalRequest newTemporalRequest();

HistoricSpatialRequest newSpatialRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
*/
package org.eclipse.sensinact.gateway.historic.storage.reader.api;

import java.time.LocalDateTime;
import java.util.List;
import java.time.ZonedDateTime;

/**
* HistoricRequest allows to collect a set of points from a connected
* historic database depending on a targeted path and a time window defined
* using a {@link LocalDateTime} start time and a {@link LocalDateTime} end time
* using a {@link ZonedDateTime} start time and a {@link ZonedDateTime} end time
*/
public interface HistoricRequest<T> {

Expand All @@ -26,10 +25,6 @@ public interface HistoricRequest<T> {

void setResourceIdentifier(String resourceId);

void setHistoricStartTime(LocalDateTime fromTime);

void setHistoricEndTime(LocalDateTime toTime);

List<T> execute();
T execute();

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
*/
package org.eclipse.sensinact.gateway.historic.storage.reader.api;

import java.time.ZonedDateTime;

/**
*
*/
public interface HistoricSpatialRequest extends HistoricRequest<SpatialDTO> {

void setRegion(String region);
void setHistoricTime(ZonedDateTime time);
void setRegion(String region);
}


Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@
*/
package org.eclipse.sensinact.gateway.historic.storage.reader.api;

import java.time.ZonedDateTime;
import java.util.List;

/**
*
*/
public interface HistoricSpatioTemporalRequest extends HistoricRequest<SpatioTemporalDTO> {
public interface HistoricSpatioTemporalRequest extends HistoricRequest<List<SpatioTemporalDTO>> {

void setHistoricStartTime(ZonedDateTime fromTime);

void setHistoricEndTime(ZonedDateTime toTime);

void setFunction(String function);

void setTemporalWindow(long period);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@
*/
package org.eclipse.sensinact.gateway.historic.storage.reader.api;

import java.time.ZonedDateTime;
import java.util.List;

/**
*
*/
public interface HistoricTemporalRequest extends HistoricRequest<TemporalDTO> {
public interface HistoricTemporalRequest extends HistoricRequest<List<TemporalDTO>> {

void setHistoricStartTime(ZonedDateTime fromTime);

void setHistoricEndTime(ZonedDateTime toTime);

void setFunction(String function);

void setTemporalWindow(long period);
Expand Down

0 comments on commit 879184b

Please sign in to comment.