/*
 * The MIT License
 *
 * Copyright 2017 georgi.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package netrank;

import mark.core.DetectionAgentInterface;
import mark.core.DetectionAgentProfile;
import mark.core.Evidence;
import mark.core.RawData;
import mark.core.ServerInterface;

/**
 *
 * @author Georgi Nikolov
 * Agent tests the ratio of POST methods used by a client-server connection.
 * if the ratio exceeds a specified threshold it is tagged as suspicious.
 */
public class POSTCount implements DetectionAgentInterface<Link> {

    private static final double UPLOAD_THRESHOLD = 0.4;

    /**
     * Analyze function inherited from the DetectionAgentInterface.
     * accepts the subject to analyze
     * trigger of the agent
     * the profile used to load the agent
     * the database to which to connect to gather RawData
     * @throws java.lang.Throwable
     */
    @Override
    public final void analyze(
            final Link subject,
            final String actual_trigger_label,
            final DetectionAgentProfile profile,
            final ServerInterface datastore) throws Throwable {

        RawData[] raw_data = datastore.findRawData(
            actual_trigger_label, subject);

        int number_of_post = 0;
        for (RawData raw_data1 : raw_data) {
            String data = raw_data1.data;
            if (data.contains("POST")) {
                number_of_post = number_of_post + 1;
            }
        }

        float post_percentage = 0;

        post_percentage = (float) number_of_post
                / raw_data.length;

        if (post_percentage > UPLOAD_THRESHOLD) {
            Evidence evidence = new Evidence();
            evidence.score = post_percentage;
            evidence.subject = subject;
            evidence.label = profile.label;
            evidence.time = raw_data[raw_data.length - 1].time;
            evidence.report = "Found a ratio of POST methods in the "
                    + "connection between " + subject.getClient()
                    + " and " + subject.getServer()
                    + " with suspicious ratio of : "
                    + post_percentage + "\n";

            datastore.addEvidence(evidence);
        }
    }

}

@@ -2243,16 +2243,83 @@
 ject);%0A%0A
+        if (raw_data.length == 0) %7B%0A            return;%0A        %7D%0A%0A
         
@@ -2556,21 +2556,22 @@
         
-float
+double
  post_pe
@@ -2616,13 +2616,14 @@
  = (
-float
+double
 ) nu

Update to POSTCount change float to double for better precision and check if fetched rawdata is not 0