예제 #1
0
  /**
   * Initialize exchange specific settings
   *
   * @throws Exception
   */
  public void initialize(PluginConfig config) throws Exception {
    Properties prop = getConfigProperties(config);
    parseSettings(prop);

    String profitPercent = targetProfit.multiply(new BigDecimal(100)).toPlainString();
    String msg =
        String.format(
            "Current exchange: %s, Fees: %s %%, Scalp amount: %s, target profit: %s, Max num operations: %d, Trend: %s",
            new Object[] {
              exchangeSite,
              fee.toPlainString(),
              scalpAmount.toPlainString(),
              profitPercent,
              maxPendingOperations,
              trend.toString()
            });
    logger.info(msg);
    this.exchange = exchangeFactory.createExchange(exchangeSite);
  }
예제 #2
0
  /**
   * 선택한 시작 날짜 및 종료 날짜에 해당하는 Audit Log를 조회한다.
   *
   * @param clusterName Hadoop Cluster명
   * @param searchType 조회 유형
   * @param startDate 시작 날짜 (yyyy-MM-dd HH)
   * @param endDate 종료 날짜 (yyyy-MM-dd HH)
   * @return trend 목록
   */
  @RequestMapping(value = "trend", method = RequestMethod.GET)
  @ResponseStatus(HttpStatus.OK)
  @ResponseBody
  public Response trend(
      @RequestParam(defaultValue = "") String clusterName,
      @RequestParam(defaultValue = "ACT") String searchType,
      @RequestParam(defaultValue = "") String startDate,
      @RequestParam(defaultValue = "") String endDate) {

    EngineService engineService = this.getEngineService(clusterName);
    FileSystemAuditRemoteService service = engineService.getFileSystemAuditRemoteService();
    int level = getSessionUserLevel();
    String username = level == 1 ? "" : getSessionUsername();

    SimpleDateFormat hoursFormat = new SimpleDateFormat("yyyy-MM-dd HH");
    SimpleDateFormat daysFormat = new SimpleDateFormat("yyyy-MM-dd");

    Calendar calendar = Calendar.getInstance();
    List<Trend> trendList;
    Date startTime;
    Date endTime;

    try {
      if ("".equals(startDate) && "".equals(endDate)) {
        calendar.setTime(new Date());
        calendar.add(Calendar.HOUR, -12);
        trendList = trends(hoursFormat, calendar, Calendar.HOUR, 12);
      } else if ("".equals(startDate) && !"".equals(endDate)) {
        calendar.setTime(daysFormat.parse(endDate));
        calendar.add(Calendar.HOUR, -1);
        trendList = trends(hoursFormat, calendar, Calendar.HOUR, 24);
      } else {
        startTime = daysFormat.parse(startDate);
        calendar.setTime(new Date());
        endTime =
            (endDate.equals(""))
                ? daysFormat.parse(daysFormat.format(calendar.getTime()))
                : daysFormat.parse(endDate);
        long difference = (endTime.getTime() - startTime.getTime()) / (1000 * 60 * 60 * 24);
        calendar.setTime(startTime);
        calendar.add(Calendar.DATE, -1);
        trendList = trends(daysFormat, calendar, Calendar.DATE, (int) difference + 1);
        calendar.add(Calendar.DATE, 1);
      }
    } catch (ParseException e) {
      throw new ServiceException("Unable to parse the date.", e);
    }

    List<Trends> trendsList = service.auditTrend(startDate, endDate, searchType, username);
    HashMap<String, String> trendTitle = new HashMap<>();

    for (Trends trends : trendsList) {
      String trendsSearchType = trends.getSearchType();
      if (!trendTitle.containsKey(trendsSearchType)) {
        trendTitle.put(trendsSearchType, "data" + (trendTitle.size() + 1));
      }

      /** 날짜가 같은 필드에 데이터 삽입 */
      for (Trend trend : trendList) {
        if (trend.getTime().equals(trends.getTime())) {
          Integer position =
              Integer.parseInt(trendTitle.get(trendsSearchType).replaceAll("[^\\d]", ""));
          trend.setData(position, trend.getData(position) + trends.getCount());
        }
      }
    }

    Response response = new Response();
    response.getMap().putAll(trendTitle);
    response.getList().addAll(trendList);
    response.setTotal(trendList.size());
    response.setSuccess(true);

    return response;
  }