Skip to content

Commit

Permalink
query csv multi plot and sensor separated by comma; query csv with qu…
Browse files Browse the repository at this point in the history
…ality counter parameter; query csv date and time columns parameters
  • Loading branch information
swoellauer committed Aug 9, 2024
1 parent b29fa2a commit bab6982
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 27 deletions.
28 changes: 14 additions & 14 deletions rTubeDB/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Package: rTubeDB
Type: Package
Title: R connection to TubeDB server
Version: 1.3.3
Author: woellauer
Maintainer: woellauer <email@email>
Description: rTubeDB package provides functionality to query and process time series from TubeDB server.
License: GPL 3
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.1
Imports:
httr,
ISOweek
Package: rTubeDB
Type: Package
Title: R connection to TubeDB server
Version: 1.4
Author: woellauer
Maintainer: woellauer <email@email>
Description: rTubeDB package provides functionality to query and process time series from TubeDB server.
License: GPL 3
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.2
Imports:
httr,
ISOweek
4 changes: 3 additions & 1 deletion rTubeDB/R/tubedb.R
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ query_region_stations <- function(tubedb, regionID) {
#' @param year get data from one full year only (You may use this 'year' parameter OR 'start', 'end' parameters)
#' @param month get data of one full month of one year only, parameter year neads to be specified (You may use this 'month' parameter OR 'start'/'end' parameters)
#' @param day get data of one full day of one month only, parameter month neads to be specified (You may use this 'day' parameter OR 'start'/'end' parameters)
#' @param quality_counter qualityCounter column to count aggregated measured values and interpolated values
#' @param casted all plot-sensor pairs in one row per timestamp, e.g. columns plot1.sensor1, plot2.sensor1, plot1.sensor2
#' @param spatial_aggregated combine all values of one sensor over all plots to one value per timestamp by mean
#' @param datetimeFormat character, requested type of timestamps. one of: "character", "POSIXct", "POSIXlt"
Expand Down Expand Up @@ -718,7 +719,7 @@ query_region_stations <- function(tubedb, regionID) {
#' # show time series
#' plot(tsDF$datetime, tsDF$Ta_200)
#' @export
query_timeseries <- function(tubedb, plot, sensor, aggregation = "hour", quality = "physical", interpolated = FALSE, start = NULL, end = NULL, year = NULL, month = NULL, day = NULL, casted = FALSE, spatial_aggregated = FALSE, datetimeFormat = "character", colYear = FALSE, colPlot = TRUE, colMonth = FALSE, colDay = FALSE, colHour = FALSE, colWeek = FALSE, colDayOfWeek = FALSE, colDayOfYear = FALSE, colMinute = FALSE) {
query_timeseries <- function(tubedb, plot, sensor, aggregation = "hour", quality = "physical", interpolated = FALSE, start = NULL, end = NULL, year = NULL, month = NULL, day = NULL, quality_counter = FALSE, casted = FALSE, spatial_aggregated = FALSE, datetimeFormat = "character", colYear = FALSE, colPlot = TRUE, colMonth = FALSE, colDay = FALSE, colHour = FALSE, colWeek = FALSE, colDayOfWeek = FALSE, colDayOfYear = FALSE, colMinute = FALSE) {
stopifnot(isClass(tubedb, TubeDB))
args <- list(
aggregation = aggregation,
Expand All @@ -729,6 +730,7 @@ query_timeseries <- function(tubedb, plot, sensor, aggregation = "hour", quality
year = year,
month = month,
day = day,
quality_counter = quality_counter,
casted = casted,
spatial_aggregated = spatial_aggregated,
col_plot = colPlot
Expand Down
17 changes: 16 additions & 1 deletion rTubeDB/man/query_timeseries.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion rTubeDB/man/read_timeseries.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/tsdb/TsDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
public class TsDB implements AutoCloseable {

public static final String tubedb_version = "1.31.2";
public static final String tubedb_version = "1.32";

/**
* map regionName -> Region
Expand Down
5 changes: 3 additions & 2 deletions src/tsdb/web/api/Handler_monitoring.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import tsdb.util.DataEntry;
import tsdb.util.Measurement;
import tsdb.util.TimeUtil;
import tsdb.web.util.Web;

public class Handler_monitoring extends MethodHandler {

Expand All @@ -26,8 +27,8 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
baseRequest.setHandled(true);
response.setContentType("application/json;charset=utf-8");

String[] plotIDs = request.getParameterValues("plot");
String[] sensorNames = request.getParameterValues("sensor");
String[] plotIDs = Web.getStrings(baseRequest, "plot");
String[] sensorNames = Web.getStrings(baseRequest, "sensor");

ArrayList<Measurement> result = tsdb.getMonitoring(plotIDs, sensorNames);

Expand Down
28 changes: 22 additions & 6 deletions src/tsdb/web/api/Handler_query_csv.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import tsdb.util.iterator.CSVTimeType;
import tsdb.util.iterator.TimestampSeries;
import tsdb.util.iterator.TsIterator;
import tsdb.web.util.Web;

/**
* Get timeseries data as CSV-file.
Expand Down Expand Up @@ -90,7 +91,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
return;
}
String[] plots = request.getParameterValues("plot");
String[] plots = Web.getStrings(baseRequest, "plot");

String col_plot_text = request.getParameter("col_plot");
boolean col_plot = false;
Expand All @@ -108,8 +109,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
}
}

//String sensorName = request.getParameter("sensor");
String[] sensorNames = request.getParameterValues("sensor");
String[] sensorNames = Web.getStrings(baseRequest, "sensor");

if(sensorNames==null) {
Logger.warn("wrong call no sensor");
Expand Down Expand Up @@ -146,6 +146,22 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
casted = false;
}
}

String quality_counter_text = request.getParameter("quality_counter");
boolean quality_counter = false;
if(quality_counter_text != null) {
switch(quality_counter_text) {
case "true":
quality_counter = true;
break;
case "false":
quality_counter = false;
break;
default:
Logger.warn("unknown input");
quality_counter = false;
}
}

String spatial_aggregated_text = request.getParameter("spatial_aggregated");
boolean spatial_aggregated = false;
Expand Down Expand Up @@ -331,14 +347,14 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
TimestampSeries ts = tsdb.plots_aggregate(plots, processingSensorNames, agg, dataQuality, isInterpolated, startTime, endTime);
if(ts != null) {
TsIterator it = ts.tsIterator();
CSV.write(it, true, bufferedWriter, ',', nanText, csvTimeType, false, false, agg, null);
CSV.write(it, true, bufferedWriter, ',', nanText, csvTimeType, false, quality_counter, agg, null);
}
} else {
if(casted) {
TimestampSeries ts = tsdb.plots_casted(plots, processingSensorNames, agg, dataQuality, isInterpolated, startTime, endTime);
if(ts != null) {
TsIterator it = ts.tsIterator();
CSV.write(it, true, bufferedWriter, ',', nanText, csvTimeType, false, false, agg, null);
CSV.write(it, true, bufferedWriter, ',', nanText, csvTimeType, false, quality_counter, agg, null);
}
} else {
boolean firstPlot = true;
Expand All @@ -351,7 +367,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
if(ts != null) {
ProjectionFillIterator it = new ProjectionFillIterator(ts.tsIterator(), processingSensorNames);
String plot_text = col_plot ? plot : null;
CSV.write(it, firstPlot, bufferedWriter, ',', nanText, csvTimeType, false, false, agg, plot_text);
CSV.write(it, firstPlot, bufferedWriter, ',', nanText, csvTimeType, false, quality_counter, agg, plot_text);
firstPlot = false;
}
} catch (Exception e) {
Expand Down
16 changes: 15 additions & 1 deletion src/tsdb/web/util/Web.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,19 @@ public static byte[] readAllBytes(InputStream in, int startBufferSize) throws IO
}
return (capacity == nread) ? buf : Arrays.copyOf(buf, nread);
}


/**
* Array of all parameters of same name and each parameter split by semicolon ','.
* @param request
* @param name
* @return
*/
public static String[] getStrings(Request request, String name) {
String[] texts = request.getParameterValues(name);
if(texts == null) {
throw new RuntimeException("parameter not found: "+name);
}
String[] splitTexts = Arrays.stream(texts).flatMap(text -> Arrays.stream(text.split(","))).toArray(String[]::new);
return splitTexts;
}
}

0 comments on commit bab6982

Please sign in to comment.