Search in sources :

Example 16 with NumberFormat

use of java.text.NumberFormat in project ice by Netflix.

the class BillingFileProcessor method sendOndemandCostAlert.

private void sendOndemandCostAlert() {
    if (ondemandThreshold == null || StringUtils.isEmpty(fromEmail) || StringUtils.isEmpty(alertEmails) || endMilli < lastAlertMillis() + AwsUtils.hourMillis * 24)
        return;
    Map<Long, Map<Ec2InstanceReservationPrice.Key, Double>> ondemandCosts = getOndemandCosts(lastAlertMillis() + AwsUtils.hourMillis);
    Long maxHour = null;
    double maxTotal = ondemandThreshold;
    for (Long hour : ondemandCosts.keySet()) {
        double total = 0;
        for (Double value : ondemandCosts.get(hour).values()) total += value;
        if (total > maxTotal) {
            maxHour = hour;
            maxTotal = total;
        }
    }
    if (maxHour != null) {
        NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
        String subject = String.format("Alert: Ondemand cost per hour reached $%s at %s", numberFormat.format(maxTotal), AwsUtils.dateFormatter.print(maxHour));
        StringBuilder body = new StringBuilder();
        body.append(String.format("Total ondemand cost $%s at %s:<br><br>", numberFormat.format(maxTotal), AwsUtils.dateFormatter.print(maxHour)));
        TreeMap<Double, String> costs = Maps.newTreeMap();
        for (Map.Entry<Ec2InstanceReservationPrice.Key, Double> entry : ondemandCosts.get(maxHour).entrySet()) {
            costs.put(entry.getValue(), entry.getKey().region + " " + entry.getKey().usageType + ": ");
        }
        for (Double cost : costs.descendingKeySet()) {
            if (cost > 0)
                body.append(costs.get(cost)).append("$" + numberFormat.format(cost)).append("<br>");
        }
        body.append("<br>Please go to <a href=\"" + urlPrefix + "dashboard/reservation#usage_cost=cost&groupBy=UsageType&product=ec2_instance&operation=OndemandInstances\">Ice</a> for details.");
        SendEmailRequest request = new SendEmailRequest();
        request.withSource(fromEmail);
        List<String> emails = Lists.newArrayList(alertEmails.split(","));
        request.withDestination(new Destination(emails));
        request.withMessage(new Message(new Content(subject), new Body().withHtml(new Content(body.toString()))));
        AmazonSimpleEmailServiceClient emailService = AwsUtils.getAmazonSimpleEmailServiceClient();
        try {
            emailService.sendEmail(request);
            updateLastAlertMillis(endMilli);
            logger.info("updateLastAlertMillis " + endMilli);
        } catch (Exception e) {
            logger.error("Error in sending alert emails", e);
        }
    }
}
Also used : AmazonSimpleEmailServiceClient(com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient) NumberFormat(java.text.NumberFormat)

Example 17 with NumberFormat

use of java.text.NumberFormat in project druid by alibaba.

the class BenchmarkExecutor method handleResultSummary.

public void handleResultSummary(SQLExecutor sqlExec, BenchmarkCase benchmarkCase, List<Result> resultList) {
    int millis = 0;
    int youngGC = 0;
    int fullGC = 0;
    for (Result result : resultList) {
        millis += result.getMillis();
        youngGC += result.getYoungGC();
        fullGC += result.getFullGC();
    }
    NumberFormat format = NumberFormat.getInstance();
    System.out.println("SUM\t" + benchmarkCase.getName() + "\t" + sqlExec.getName() + "\t" + format.format(millis) + "\tYoungGC " + youngGC + "\tFullGC " + fullGC);
}
Also used : NumberFormat(java.text.NumberFormat)

Example 18 with NumberFormat

use of java.text.NumberFormat in project druid by alibaba.

the class BenchmarkExecutor method handleResult.

public void handleResult(SQLExecutor sqlExec, Result result) {
    if (result.getError() != null) {
        result.getError().printStackTrace();
        return;
    }
    NumberFormat format = NumberFormat.getInstance();
    System.out.println(result.getName() + "\t" + sqlExec.getName() + "\t" + format.format(result.getMillis()) + "\tYoungGC " + result.getYoungGC() + "\tFullGC " + result.getFullGC());
}
Also used : NumberFormat(java.text.NumberFormat)

Example 19 with NumberFormat

use of java.text.NumberFormat in project fastjson by alibaba.

the class FNV32_CollisionTest method test_fnv_hash.

public void test_fnv_hash() throws Exception {
    int COUNT = 1000 * 1000 * 1000;
    long id_hash_64 = fnv_hash("name".toCharArray());
    int id_hash_32 = (int) id_hash_64;
    System.out.println("name : " + id_hash_32 + ", " + id_hash_64);
    long v = 0;
    long time = System.currentTimeMillis();
    NumberFormat format = NumberFormat.getInstance();
    for (int len = 1; len <= 7; ++len) {
        char[] chars = new char[len];
        long n = (long) Math.pow(digLetters.length, chars.length);
        for (; v < n; ++v) {
            long hash = 0x811c9dc5;
            for (int i = 0; i < chars.length; ++i) {
                int power = powers[chars.length - i - 1];
                int d = (int) ((v / power) % digLetters.length);
                char c = digLetters[d];
                hash ^= c;
                hash *= 0x1000193;
            }
            if (hash == id_hash_64) {
                int hash_32 = (int) hash;
                System.out.println("collision : " + build(v, len) + ", hash64 : " + hash + ", hash 32 " + hash_32);
                break;
            }
            if (v != 0 && v % (1000 * 1000 * 100) == 0) {
                long now = System.currentTimeMillis();
                long millis = now - time;
                time = now;
                System.out.println("millis : " + millis + ", " + format.format(v));
            }
        }
        System.out.println("end : " + len);
    }
}
Also used : NumberFormat(java.text.NumberFormat)

Example 20 with NumberFormat

use of java.text.NumberFormat in project fastjson by alibaba.

the class FNV32_CollisionTest_2 method test_fnv_hash_7.

public void test_fnv_hash_7() throws Exception {
    int COUNT = 1000 * 1000 * 1000;
    long id_hash_64 = fnv_hash("name".toCharArray());
    int id_hash_32 = (int) id_hash_64;
    System.out.println("name : " + id_hash_32 + ", " + id_hash_64);
    long v = 0;
    long time = System.currentTimeMillis();
    NumberFormat format = NumberFormat.getInstance();
    final int len = 7;
    char[] chars = new char[len];
    for (int i0 = 0; i0 < digLetters.length; ++i0) {
        long h0 = 0x811c9dc5;
        char c0 = digLetters[i0];
        h0 ^= c0;
        h0 *= 0x1000193;
        chars[0] = c0;
        for (int i1 = 0; i1 < digLetters.length; ++i1) {
            char c1 = digLetters[i1];
            chars[1] = c1;
            long h1 = h0;
            h1 ^= c1;
            h1 *= 0x1000193;
            for (int i2 = 0; i2 < digLetters.length; ++i2) {
                char c2 = digLetters[i2];
                long h2 = h1;
                h2 ^= c2;
                h2 *= 0x1000193;
                chars[2] = c2;
                for (int i3 = 0; i3 < digLetters.length; ++i3) {
                    char c3 = digLetters[i3];
                    long h3 = h2;
                    h3 ^= c3;
                    h3 *= 0x1000193;
                    chars[3] = c3;
                    for (int i4 = 0; i4 < digLetters.length; ++i4) {
                        char c4 = digLetters[i4];
                        long h4 = h3;
                        h4 ^= c4;
                        h4 *= 0x1000193;
                        chars[4] = c4;
                        for (int i5 = 0; i5 < digLetters.length; ++i5) {
                            char c5 = digLetters[i5];
                            chars[5] = c5;
                            long h5 = h4;
                            h5 ^= c5;
                            h5 *= 0x1000193;
                            for (int i6 = 0; i6 < digLetters.length; ++i6) {
                                char c6 = digLetters[i6];
                                long h6 = h5;
                                h6 ^= c6;
                                h6 *= 0x1000193;
                                chars[6] = c6;
                                v++;
                                if (h6 == id_hash_64) {
                                    int hash_32 = (int) h6;
                                    System.out.println("collision : " + build(v, len) + ", hash64 : " + h6 + ", hash 32 " + hash_32);
                                    break;
                                }
                                if (v != 0 && v % (1000 * 1000 * 1000) == 0) {
                                    long now = System.currentTimeMillis();
                                    long millis = now - time;
                                    time = now;
                                    System.out.println("millis : " + millis + ", " + format.format(v));
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    System.out.println("end : " + len);
}
Also used : NumberFormat(java.text.NumberFormat)

Aggregations

NumberFormat (java.text.NumberFormat)429 DecimalFormat (java.text.DecimalFormat)87 BigDecimal (java.math.BigDecimal)23 ArrayList (java.util.ArrayList)23 HashMap (java.util.HashMap)23 Locale (java.util.Locale)22 Map (java.util.Map)18 Test (org.junit.Test)17 ParseException (java.text.ParseException)15 DecimalFormatSymbols (java.text.DecimalFormatSymbols)14 JFreeChart (org.jfree.chart.JFreeChart)13 XYSeries (org.jfree.data.xy.XYSeries)11 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)11 Intent (android.content.Intent)10 ParsePosition (java.text.ParsePosition)10 View (android.view.View)8 TextView (android.widget.TextView)8 Paint (android.graphics.Paint)7 Rect (android.graphics.Rect)6 IOException (java.io.IOException)6