コード例 #1
0
  // \u63cf\u753b
  public void draw() {

    // \u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u30bf\u30a4\u30e0\u30b9\u30bf\u30f3\u30d7\u3092\u8868\u793a
    Calendar cal = Calendar.getInstance();
    Date theDate = cal.getTime();
    println("now : " + theDate);

    // \u30c7\u30fc\u30bf\u53d6\u5f97
    getAllData();

    // \u63cf\u753b
    drawAllData();

    // \u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u63cf\u753b
    drawParam();
  }
コード例 #2
0
  // xively\u304b\u3089\u306e\u30c7\u30fc\u30bf\u53d6\u5f97
  // \u73fe\u5728\u306e\u65e5\u4ed8\u304b\u30892\u65e5\u3055\u304b\u306e\u307c\u3063\u305f\u65e5\u4ed8\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97
  public String[] getDataFromXively(String URL, String MY_KEY) {

    // \u73fe\u5728\u306e\u65e5\u4ed8\u3092\u53d6\u5f97
    Calendar cal = Calendar.getInstance();
    // \u6307\u5b9a\u3057\u305f\u65e5\u6570\u3092\u52a0\u7b97
    cal.add(Calendar.DATE, -10);

    // \u57fa\u6e96\u65e5(\u73fe\u5728\u3088\u308a7\u65e5\u524d\u306e\u65e5\u4ed8\u3092\u57fa\u6e96\u65e5\u3068\u3057\u3066\u3044\u308b)\u3088\u308a\u5f8c\u306e\u65e5\u4ed8\u306b\u306a\u3063\u305f\u5834\u5408\u306f\u521d\u671f\u5316
    Calendar before1 = Calendar.getInstance();
    before1.add(Calendar.DATE, -1);
    int result = cal.compareTo(before1);
    if (result > 0) {
      cal = Calendar.getInstance();
      cal.add(Calendar.DATE, -2);
    }
    // \u6307\u5b9a\u3057\u305f\u65e5\u4ed8\u3092Data\u578b\u3067\u53d6\u5f97
    Date theDate = cal.getTime();
    println("data: " + theDate);

    // \u6307\u5b9a\u3057\u305f\u65e5\u4ed8\u3092ISO
    // 8601(UTC)\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3067\u6587\u5b57\u5217\u5316
    SimpleDateFormat dateFormat = getDateFormat_ISO8601();
    String startDate = dateFormat.format(theDate);
    println("format: " + startDate);

    // \u623b\u308a\u5024\u7528\u914d\u5217
    String[] retlines = new String[0];
    String[] dataLines = new String[0];

    // \u6587\u5b57\u5217\u683c\u7d0d\u7528\u306e\u52d5\u7684\u914d\u5217
    ArrayList<String> strList = new ArrayList<String>();

    // xively\u3078\u306eURL\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u4f5c\u6210
    // String strDuration = "&duration=1days&interval=300";  //
    // 300\u79d2\u9593\u9694\u30671\u65e5\u5206\u306e\u30c7\u30fc\u30bf\u3092\u53d6\u5f97
    // String URL_REQUEST = URL + "?start=" + startDate + strDuration + "&limit=450" + "?key=" +
    // MY_KEY;
    String strDuration =
        "&duration=6hours&interval=0"; // 1\u79d2\u9593\u9694\u30671\u65e5\u5206\u306e\u30c7\u30fc\u30bf\u3092\u53d6\u5f97
    String URL_REQUEST =
        URL + "?start=" + startDate + strDuration + "&limit=450" + "?key=" + MY_KEY;

    println(URL_REQUEST);

    // xively\u304b\u3089\u306e\u30c7\u30fc\u30bf\u53d6\u5f97(\u53d6\u5f97\u3067\u304d\u306a\u3044\u5834\u5408\u306f\u4f55\u3082\u3057\u306a\u3044)
    try {
      // xivly\u304b\u3089\u306e\u30c7\u30fc\u30bf\u3092\u4e00\u6642\u7684\u306b\u683c\u7d0d
      dataLines = loadStrings(URL_REQUEST);
    } catch (Exception e) {
      // \u53d6\u5f97\u3067\u304d\u306a\u3044\u5834\u5408
      e.printStackTrace();
      dataLines = null;
    }

    // \u53d6\u5f97\u3067\u304d\u306a\u3044\u5834\u5408
    if (dataLines == null) {
      background(60);
      text("error!", width / 2, height / 2);
      dataLines = new String[0];
      strList.clear();
    }

    // xivly\u304b\u3089\u306e\u30c7\u30fc\u30bf\u3092\u52d5\u7684\u914d\u5217\u306b\u8ffd\u52a0
    for (int i = 0; i < dataLines.length; i++) {
      strList.add(dataLines[i]);
    }

    // \u623b\u308a\u5024\u7528\u914d\u5217\u3078\u30c7\u30fc\u30bf\u3092\u30b3\u30d4\u30fc
    retlines = new String[strList.size()];
    for (int i = 0; i < strList.size(); i++) {
      retlines[i] = strList.get(i);
    }

    return retlines;
  }