Ejemplo n.º 1
1
  /**
   * Joins array elements to string.
   *
   * @param arr Array.
   * @return String.
   */
  @Nullable
  public static String compactArray(Object[] arr) {
    if (arr == null || arr.length == 0) return null;

    String sep = ", ";

    StringBuilder sb = new StringBuilder();

    for (Object s : arr) sb.append(s).append(sep);

    if (sb.length() > 0) sb.setLength(sb.length() - sep.length());

    return U.compact(sb.toString());
  }
Ejemplo n.º 2
1
  /// <summary>
  /// FileStreamから読み込みながらコンストラクト
  /// </summary>
  /// <param name="sr">読み込み対象</param>
  public VsqHandle(TextMemoryStream sr, int value, StringBuilder last_line) {
    try {
      this.index = value;
      String[] spl;
      String[] spl2;

      // default値で梅
      m_type = VsqHandleType.Vibrato;
      iconID = "";
      IDS = "normal";
      L0 = new Lyric("");
      original = 0;
      caption = "";
      length = 0;
      startDepth = 0;
      depthBP = null;
      int depth_bp_num = 0;
      startRate = 0;
      rateBP = null;
      int rate_bp_num = 0;
      language = 0;
      program = 0;
      duration = 0;
      depth = 64;

      String tmpDepthBPX = "";
      String tmpDepthBPY = "";
      String tmpRateBPX = "";
      String tmpRateBPY = "";

      // "["にぶち当たるまで読込む
      last_line.setLength(0);
      last_line.append(sr.readLine());
      while (!last_line.toString().startsWith("[")) {
        spl = Misc.splitString(last_line.toString(), "=");
        if (spl[0].equals("Language")) {
          m_type = VsqHandleType.Singer;
          language = Integer.parseInt(spl[1]);
        } else if (spl[0].equals("Program")) {
          program = Integer.parseInt(spl[1]);
        } else if (spl[0].equals("IconID")) {
          iconID = spl[1];
        } else if (spl[0].equals("IDS")) {
          IDS = spl[1];
        } else if (spl[0].equals("Original")) {
          original = Integer.parseInt(spl[1]);
        } else if (spl[0].equals("Caption")) {
          caption = spl[1];
          for (int i = 2; i < spl.length; i++) {
            caption += "=" + spl[i];
          }
        } else if (spl[0].equals("Length")) {
          length = Integer.parseInt(spl[1]);
        } else if (spl[0].equals("StartDepth")) {
          startDepth = Integer.parseInt(spl[1]);
        } else if (spl[0].equals("DepthBPNum")) {
          depth_bp_num = Integer.parseInt(spl[1]);
        } else if (spl[0].equals("DepthBPX")) {
          tmpDepthBPX = spl[1];
        } else if (spl[0].equals("DepthBPY")) {
          tmpDepthBPY = spl[1];
        } else if (spl[0].equals("StartRate")) {
          m_type = VsqHandleType.Vibrato;
          startRate = Integer.parseInt(spl[1]);
        } else if (spl[0].equals("RateBPNum")) {
          rate_bp_num = Integer.parseInt(spl[1]);
        } else if (spl[0].equals("RateBPX")) {
          tmpRateBPX = spl[1];
        } else if (spl[0].equals("RateBPY")) {
          tmpRateBPY = spl[1];
        } else if (spl[0].equals("L0")) {
          m_type = VsqHandleType.Lyric;
          L0 = new Lyric(spl[1]);
        } else if (spl[0].equals("Duration")) {
          m_type = VsqHandleType.NoteHeadHandle;
          duration = Integer.parseInt(spl[1]);
        } else if (spl[0].equals("Depth")) {
          duration = Integer.parseInt(spl[1]);
        }
        if (sr.peek() < 0) {
          break;
        }
        last_line.setLength(0);
        last_line.append(sr.readLine());
      }
      /*if ( IDS != "normal" ) {
          m_type = VsqHandleType.Singer;
      } else if ( IconID != "" ) {
          m_type = VsqHandleType.Vibrato;
      } else {
          m_type = VsqHandleType.Lyric;
      }*/

      // RateBPX, RateBPYの設定
      if (m_type == VsqHandleType.Vibrato) {
        if (rate_bp_num > 0) {
          float[] rate_bp_x = new float[rate_bp_num];
          spl2 = tmpRateBPX.split(",");
          for (int i = 0; i < rate_bp_num; i++) {
            rate_bp_x[i] = Float.parseFloat(spl2[i]);
          }

          int[] rate_bp_y = new int[rate_bp_num];
          spl2 = tmpRateBPY.split(",");
          for (int i = 0; i < rate_bp_num; i++) {
            rate_bp_y[i] = Integer.parseInt(spl2[i]);
          }
          rateBP = new VibratoBPList(rate_bp_x, rate_bp_y);
        } else {
          // m_rate_bp_x = null;
          // m_rate_bp_y = null;
          rateBP = new VibratoBPList();
        }

        // DepthBPX, DepthBPYの設定
        if (depth_bp_num > 0) {
          float[] depth_bp_x = new float[depth_bp_num];
          spl2 = tmpDepthBPX.split(",");
          for (int i = 0; i < depth_bp_num; i++) {
            depth_bp_x[i] = Float.parseFloat(spl2[i]);
          }

          int[] depth_bp_y = new int[depth_bp_num];
          spl2 = tmpDepthBPY.split(",");
          for (int i = 0; i < depth_bp_num; i++) {
            depth_bp_y[i] = Integer.parseInt(spl2[i]);
          }
          depthBP = new VibratoBPList(depth_bp_x, depth_bp_y);
        } else {
          depthBP = new VibratoBPList();
          // m_depth_bp_x = null;
          // m_depth_bp_y = null;
        }
      } else {
        depthBP = new VibratoBPList();
        rateBP = new VibratoBPList();
      }
    } catch (Exception ex) {
      System.out.println("VsqHandle(TextMemoryStream,int,StringBuilder); ex=" + ex);
    }
  }
  /**
   * Keep track, collect and update the stats of all the <tt>MediaStreamStats</tt> this
   * <tt>HammerStats</tt> handles.
   *
   * <p>Also write the results in the stats files.
   */
  public void run() {
    PrintWriter writer = null;
    StringBuilder allBldr = new StringBuilder();
    String delim;
    String delim_ = "";
    synchronized (this) {
      threadStop = false;
    }

    logger.info("Running the main loop");
    System.out.println("Inside HammerStats run method.\n");

    while (!threadStop) {
      synchronized (this) {
        if (overallStatsLogging || allStatsLogging || summaryStatsLogging) {
          if (allStatsLogging || summaryStatsLogging) {
            if (writer == null) {
              try {
                writer = new PrintWriter(allStatsFile, "UTF-8");
                writer.print("[\n");
              } catch (FileNotFoundException e) {
                logger.fatal("HammerStats stopping due to FileNotFound", e);
                stop();
              } catch (UnsupportedEncodingException e) {
                logger.fatal("HammerStats stopping due to " + "UnsupportedEncoding", e);
              }
            }

            // Clear the StringBuilder
            allBldr.setLength(0);

            writer.print(delim_ + '\n');
            delim_ = ",";
            writer.print("{\n");
            writer.print("  \"timestamp\":" + System.currentTimeMillis() + ",\n");
          }

          delim = "";
          logger.info("Updating the MediaStreamStats");
          for (FakeUserStats stats : fakeUserStatsList) {
            // We update the stats before using/reading them.
            stats.updateStats();
          }

          for (FakeUserStats stats : fakeUserStatsList) {
            if (allStatsLogging) {
              allBldr.append(delim + stats.getStatsJSON(2) + '\n');
              delim = ",";
            }

            if (summaryStatsLogging || overallStatsLogging) {
              logger.info(
                  "Adding stats values from the"
                      + " MediaStreamStats to their"
                      + " HammerSummaryStats objects");
              audioSummaryStats.add(stats.getMediaStreamStats(MediaType.AUDIO));
              videoSummaryStats.add(stats.getMediaStreamStats(MediaType.VIDEO));
            }
          }

          if (allStatsLogging) {
            logger.info("Writing all stats to file");
            writer.print("  \"users\":\n");
            writer.print("  [\n");
            writer.print(allBldr.toString());
            writer.print("  ]");
            if (summaryStatsLogging) writer.print(',');
            writer.print('\n');
          }
          if (summaryStatsLogging) {
            logger.info("Writing summary stats to file");
            writer.print("  \"summary\":\n");
            writer.print("  {\n");

            writer.print("    \"max\":\n");
            writer.print("    {\n");
            writer.print("        \"audio\":");
            writer.print(audioSummaryStats.getMaxJSON() + ",\n");
            writer.print("        \"video\":");
            writer.print(videoSummaryStats.getMaxJSON() + '\n');
            writer.print("    },\n");

            writer.print("    \"mean\":\n");
            writer.print("    {\n");
            writer.print("       \"audio\":");
            writer.print(audioSummaryStats.getMeanJSON() + ",\n");
            writer.print("        \"video\":");
            writer.print(videoSummaryStats.getMeanJSON() + '\n');
            writer.print("    },\n");

            writer.print("    \"min\":\n");
            writer.print("    {\n");
            writer.print("        \"audio\":");
            writer.print(audioSummaryStats.getMinJSON() + ",\n");
            writer.print("        \"video\":");
            writer.print(videoSummaryStats.getMinJSON() + '\n');
            writer.print("    },\n");

            writer.print("    \"standard_deviation\":\n");
            writer.print("    {\n");
            writer.print("        \"audio\":");
            writer.print(audioSummaryStats.getStandardDeviationJSON() + ",\n");
            writer.print("        \"video\":");
            writer.print(videoSummaryStats.getStandardDeviationJSON() + '\n');
            writer.print("    }\n");

            writer.print("  }\n");
          }
          if (allStatsLogging || summaryStatsLogging) {
            writer.append("}");
            writer.flush();
          }
        }

        if (summaryStatsLogging || overallStatsLogging) {
          logger.info(
              "Clearing the HammerSummaryStats by creating new"
                  + " SummaryStats objects for each watched stats");
          audioSummaryStats.clear();
          videoSummaryStats.clear();
        }
      }

      try {
        Thread.sleep(timeBetweenUpdate * 1000);
      } catch (InterruptedException e) {
        logger.fatal("Error during sleep in main loop : " + e);
        stop();
      }
    }
    logger.info("Exiting the main loop");

    if (writer != null) {
      writer.print("]\n");
      writer.close();
    }

    if (overallStatsLogging) writeOverallStats();
  }