[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [metrics-web/release] Provide no-data pictures, pdfs, and csv files instead of server error.



commit 533225c4250490857b0ed3e31232914da725cc13
Author: iwakeh <iwakeh@xxxxxxxxxxxxxx>
Date:   Sat Mar 24 09:31:08 2018 +0000

    Provide no-data pictures, pdfs, and csv files instead of server error.
    
    Implements task-25264.
---
 build.xml                                           |   1 +
 src/main/R/rserver/graphs.R                         |  20 ++++++++++++++++++++
 .../torproject/metrics/web/RObjectGenerator.java    |   7 ++++---
 src/main/resources/web/images/no-data-available.pdf | Bin 0 -> 33824 bytes
 src/main/resources/web/images/no-data-available.png | Bin 0 -> 26209 bytes
 src/main/resources/web/images/no-data-available.xcf | Bin 0 -> 104450 bytes
 6 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/build.xml b/build.xml
index 3b4222e..17160ee 100644
--- a/build.xml
+++ b/build.xml
@@ -504,6 +504,7 @@
     <copy todir="${rdatadir}" >
       <fileset dir="${modulebase}/clients/RData" includes="*.RData" />
       <fileset dir="${modulebase}/webstats/RData" includes="*.RData" />
+      <fileset dir="${resources}/web/images/" includes="no-data-available.*" />
     </copy>
   </target>
 
diff --git a/src/main/R/rserver/graphs.R b/src/main/R/rserver/graphs.R
index 57d2be2..332204b 100644
--- a/src/main/R/rserver/graphs.R
+++ b/src/main/R/rserver/graphs.R
@@ -328,6 +328,26 @@ stats_dir <- "/srv/metrics.torproject.org/metrics/shared/stats/"
 
 rdata_dir <- "/srv/metrics.torproject.org/metrics/shared/RData/"
 
+# Helper function that copies the appropriate no data object to filename.
+copy_no_data <- function(filename) {
+  len <- nchar(filename)
+  extension <- substr(filename, len - 3, len)
+  if (".csv" == extension) {
+    write("# No data available for the given parameters.", file=filename)
+  } else {
+    file.copy(paste(rdata_dir, "no-data-available", extension, sep = ""),
+      filename)
+  }
+}
+
+# Helper function wrapping calls into error handling.
+robust_call <- function(wrappee, filename) {
+  tryCatch(eval(wrappee), error = function(e) copy_no_data(filename),
+     finally = if (!file.exists(filename) || file.size(filename) == 0) {
+       copy_no_data(filename)
+       })
+}
+
 prepare_networksize <- function(start, end) {
   read.csv(paste(stats_dir, "servers.csv", sep = ""),
     colClasses = c("date" = "Date")) %>%
diff --git a/src/main/java/org/torproject/metrics/web/RObjectGenerator.java b/src/main/java/org/torproject/metrics/web/RObjectGenerator.java
index 04bda0c..e3a2419 100644
--- a/src/main/java/org/torproject/metrics/web/RObjectGenerator.java
+++ b/src/main/java/org/torproject/metrics/web/RObjectGenerator.java
@@ -117,19 +117,20 @@ public class RObjectGenerator implements ServletContextListener {
         == null) {
       return null;
     }
-    String function = this.availableGraphs.get(requestedGraph)
-        .getFunction();
     Map<String, String[]> checkedParameters = GraphParameterChecker
         .getInstance().checkParameters(requestedGraph, parameterMap);
     if (checkedParameters == null) {
       return null;
     }
     StringBuilder queryBuilder = new StringBuilder();
+    queryBuilder.append("robust_call(as.call(list(");
     if ("csv".equalsIgnoreCase(fileType)) {
       queryBuilder.append("write_");
     } else {
       queryBuilder.append("plot_");
     }
+    String function = this.availableGraphs.get(requestedGraph)
+        .getFunction();
     queryBuilder.append(function).append("(");
     StringBuilder imageFilenameBuilder =
         new StringBuilder(requestedGraph);
@@ -154,7 +155,7 @@ public class RObjectGenerator implements ServletContextListener {
     }
     imageFilenameBuilder.append(".").append(fileType);
     String imageFilename = imageFilenameBuilder.toString();
-    queryBuilder.append("path = '%s')");
+    queryBuilder.append("path = '%1$s'))), '%1$s')");
     String query = queryBuilder.toString();
     File imageFile = new File(this.cachedGraphsDirectory + "/"
         + imageFilename);
diff --git a/src/main/resources/web/images/no-data-available.pdf b/src/main/resources/web/images/no-data-available.pdf
new file mode 100644
index 0000000..8c9ca25
Binary files /dev/null and b/src/main/resources/web/images/no-data-available.pdf differ
diff --git a/src/main/resources/web/images/no-data-available.png b/src/main/resources/web/images/no-data-available.png
new file mode 100644
index 0000000..36310ad
Binary files /dev/null and b/src/main/resources/web/images/no-data-available.png differ
diff --git a/src/main/resources/web/images/no-data-available.xcf b/src/main/resources/web/images/no-data-available.xcf
new file mode 100644
index 0000000..42a7170
Binary files /dev/null and b/src/main/resources/web/images/no-data-available.xcf differ



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits