Skip to content

Commit

Permalink
Improve documentation of the code
Browse files Browse the repository at this point in the history
  • Loading branch information
ckittl committed Jan 28, 2022
1 parent 8c6b2b6 commit 6b351f0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `"coordinate"` to `"coordinate id"` (as composite word)
- `"diffuseirradiation"` to `"diffuse irradiance"` (as composite word)
- Harmonized the column name definition for coordinate id across implementations of `WeatherSource`
- Allows for different case conventions based on the used data source technology

## [2.1.0] - 2022-01-05

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
public class CouchbaseWeatherSource implements WeatherSource {
private static final Logger logger = LoggerFactory.getLogger(CouchbaseWeatherSource.class);

/* Column names in couchbase come in "flat" case by default */
private static final NamingConvention DEFAULT_NAMING_CONVENTION = NamingConvention.FLAT;
private static final String DEFAULT_TIMESTAMP_PATTERN = "yyyy-MM-dd'T'HH:mm:ssxxx";
/** The start of the document key, comparable to a table name in relational databases */
Expand All @@ -45,6 +46,7 @@ public class CouchbaseWeatherSource implements WeatherSource {
private final String keyPrefix;
private final CouchbaseConnector connector;
private final IdCoordinateSource coordinateSource;
/* Final name of the column within the database */
private final String coordinateIdColumnName;

/**
Expand Down Expand Up @@ -78,7 +80,7 @@ public CouchbaseWeatherSource(
* @deprecated Use {@link CouchbaseWeatherSource#CouchbaseWeatherSource(CouchbaseConnector,
* IdCoordinateSource, String, NamingConvention, TimeBasedWeatherValueFactory)} instead
*/
@Deprecated
@Deprecated(since = "3.0", forRemoval = true)
public CouchbaseWeatherSource(
CouchbaseConnector connector,
IdCoordinateSource coordinateSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
import edu.ie3.datamodel.models.value.WeatherValue;
import edu.ie3.util.StringUtils;
import edu.ie3.util.interval.ClosedInterval;

import java.time.ZonedDateTime;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import edu.ie3.util.naming.Naming;
import org.influxdb.InfluxDB;
import org.influxdb.dto.Query;
import org.influxdb.dto.QueryResult;
Expand All @@ -31,7 +34,10 @@ public class InfluxDbWeatherSource implements WeatherSource {
private static final String MEASUREMENT_NAME_WEATHER = "weather";
private static final int MILLI_TO_NANO_FACTOR = 1000000;

/* Final name of the coordinate id field for use in factories */
private final String coordinateIdFieldName;
/* Final name of the column within the database */
private final String coordinateIdColumnName = Naming.from("coordinate", "id").snakeCase();
private final InfluxDbConnector connector;
private final IdCoordinateSource coordinateSource;
private final TimeBasedWeatherValueFactory weatherValueFactory;
Expand Down Expand Up @@ -162,16 +168,16 @@ private Stream<Optional<TimeBasedValue<WeatherValue>>> optTimeBasedValueStream(
StringUtils.snakeCaseToCamelCase(entry.getKey()).toLowerCase(),
Map.Entry::getValue));

Optional<Point> coordinate =
coordinateSource.getCoordinate(
Integer.parseInt(flatCaseFields.remove(coordinateIdFieldName)));
if (!coordinate.isPresent()) return null;
/* Add a random UUID if necessary */
flatCaseFields.putIfAbsent("uuid", UUID.randomUUID().toString());

return new TimeBasedWeatherValueData(flatCaseFields, coordinate.get());
})
.filter(Objects::nonNull)
.map(weatherValueFactory::get);
/* Get the corresponding coordinate id from map AND REMOVE THE ENTRY !!! */
int coordinateId = Integer.parseInt(flatCaseFields.remove(coordinateIdFieldName));
return coordinateSource
.getCoordinate(coordinateId)
.map(point -> new TimeBasedWeatherValueData(flatCaseFields, point))
.flatMap(weatherValueFactory::get);
});
}

private String createQueryStringForCoordinateAndTimeInterval(
Expand Down Expand Up @@ -207,7 +213,7 @@ private String createTimeConstraint(ZonedDateTime date) {
}

private String createCoordinateConstraintString(int coordinateId) {
return "coordinate_id='" + coordinateId + "'";
return coordinateIdColumnName + "='" + coordinateId + "'";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
public class SqlWeatherSource extends SqlDataSource<TimeBasedValue<WeatherValue>>
implements WeatherSource {
private static final String WHERE = " WHERE ";
/* Column names in sql come in "snake" case by default */
private static final NamingConvention DEFAULT_NAMING_CONVENTION = NamingConvention.SNAKE;

private final IdCoordinateSource idCoordinateSource;
Expand Down Expand Up @@ -52,7 +53,7 @@ public class SqlWeatherSource extends SqlDataSource<TimeBasedValue<WeatherValue>
* @deprecated Use {@link SqlWeatherSource#SqlWeatherSource(SqlConnector, IdCoordinateSource,
* String, String, NamingConvention, TimeBasedWeatherValueFactory)} instead
*/
@Deprecated
@Deprecated(since = "3.0", forRemoval = true)
public SqlWeatherSource(
SqlConnector connector,
IdCoordinateSource idCoordinateSource,
Expand Down

0 comments on commit 6b351f0

Please sign in to comment.