Commit 5bf208a7 authored by Bc. Pavol Beňko's avatar Bc. Pavol Beňko
Browse files

uprava vypoctu bandwidthHistorytrend

parent d1042f1e
......@@ -3,8 +3,8 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="2"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/home/esperian/NetBeansProjects/evaluatorik/src/connctions/DatabaseConnection.java</file>
<file>file:/home/esperian/NetBeansProjects/evaluatorik/src/evaluatorik/RunModules.java</file>
<file>file:/home/esperian/NetBeansProjects/evaluatorik/src/connctions/DatabaseConnection.java</file>
<file>file:/home/esperian/NetBeansProjects/evaluatorik/src/module/modules/AmountOfTransferredData.java</file>
<file>file:/home/esperian/NetBeansProjects/evaluatorik/src/module/modules/HistoryTable.java</file>
<file>file:/home/esperian/NetBeansProjects/evaluatorik/src/module/PoolRequest.java</file>
......@@ -26,12 +26,12 @@
<file>file:/home/esperian/NetBeansProjects/evaluatorik/src/module/modules/BandwidthHistoryTrend.java</file>
<file>file:/home/esperian/NetBeansProjects/evaluatorik/src/evaluatorik/Evaluatorik.java</file>
<file>file:/home/esperian/NetBeansProjects/evaluatorik/src/module/calculation/CalculateTransferedData.java</file>
<file>file:/home/esperian/NetBeansProjects/evaluatorik/src/module/MaxValues.java</file>
<file>file:/home/esperian/NetBeansProjects/evaluatorik/src/module/modules/AverageMiniTable.java</file>
<file>file:/home/esperian/NetBeansProjects/evaluatorik/src/module/MaxValues.java</file>
<file>file:/home/esperian/NetBeansProjects/evaluatorik/src/connctions/JedisConnection.java</file>
<file>file:/home/esperian/NetBeansProjects/evaluatorik/src/module/Flow.java</file>
<file>file:/home/esperian/NetBeansProjects/evaluatorik/src/evaluatorik/Config.java</file>
<file>file:/home/esperian/NetBeansProjects/evaluatorik/src/module/PrepareStatement.java</file>
<file>file:/home/esperian/NetBeansProjects/evaluatorik/src/evaluatorik/Config.java</file>
<file>jar:file:/home/esperian/NetBeansProjects/evaluatorik/lib/java-json.jar!/org/json/JSONObject.java</file>
<file>file:/home/esperian/NetBeansProjects/evaluatorik/src/module/modules/TopDownloader.java</file>
</group>
......
......@@ -97,6 +97,46 @@ public class CalculateTransferedData {
long octets= (long)row.get("octetDeltaCount");
if((startRecord<getStartInterval() && endRecord<getStartInterval())||(startRecord>getEndInterval() && endRecord>getEndInterval())){
}else{
if(startRecord>= getStartInterval() && endRecord<= getEndInterval()){
am+= octets;
}else if(startRecord< getStartInterval() && endRecord> getEndInterval()){
am+= (double)((getEndInterval()-getStartInterval())*octets)/(endRecord-startRecord);
}else if(startRecord< getStartInterval() && endRecord< getEndInterval()){
am+= (double) ((endRecord-getStartInterval())*(octets))/(endRecord-startRecord);
}else if(startRecord>= getStartInterval() && endRecord>= getEndInterval()){
am+= (double) ((getEndInterval()-startRecord)*(octets))/(endRecord-startRecord);
}
}
//}
}
//System.out.println("pocet iteracii "+s);
setResutValue(am);
}
public void processData(AggregationOutput aggOut){
double am=0.0;
Iterator<DBObject> result2= aggOut.results().iterator();
while(result2.hasNext()){
DBObject row=result2.next();
long startRecord= (long)row.get("flowStartMilliseconds");
long endRecord= (long)row.get("flowEndMilliseconds");
long octets= (long)row.get("octetDeltaCount");
if((startRecord<getStartInterval() && endRecord<getStartInterval())||(startRecord>getEndInterval() && endRecord>getEndInterval())){
}else{
......
......@@ -19,6 +19,7 @@
package module.calculation;
import com.mongodb.AggregationOutput;
import com.mongodb.DBObject;
import java.util.ArrayList;
import java.util.Hashtable;
......@@ -83,6 +84,46 @@ public class CalculateTransferedDataPacket {
setResutValue(am);
}
public void processData(AggregationOutput aggOut){
double am=0.0;
Iterator<DBObject> result2= aggOut.results().iterator();
while(result2.hasNext()){
DBObject row=result2.next();
long startRecord= (long)row.get("flowStartMilliseconds");
long endRecord= (long)row.get("flowEndMilliseconds");
long octets= (long)row.get("packetDeltaCount");
if((startRecord<getStartInterval() && endRecord<getStartInterval())||(startRecord>getEndInterval() && endRecord>getEndInterval())){
}else{
if(startRecord>= getStartInterval() && endRecord<= getEndInterval()){
am+= octets;
}else if(startRecord< getStartInterval() && endRecord> getEndInterval()){
am+= (double)((getEndInterval()-getStartInterval())*octets)/(endRecord-startRecord);
}else if(startRecord< getStartInterval() && endRecord< getEndInterval()){
am+= (double) ((endRecord-getStartInterval())*(octets))/(endRecord-startRecord);
}else if(startRecord>= getStartInterval() && endRecord>= getEndInterval()){
am+= (double) ((getEndInterval()-startRecord)*(octets))/(endRecord-startRecord);
}
}
//}
}
//System.out.println("pocet iteracii "+s);
setResutValue(am);
}
/**
* @return the startInterval
*/
......
......@@ -108,29 +108,22 @@ public class BandwidthHistoryTrend extends AbstractModule{
//Enumeration<Long[]> keys = intervals.keys();
JSONArray finalResult = new JSONArray();
for(int i=0; i<intervals.size(); i++){
Long[] startEnd = {intervals.get(i),intervals.get(i)+999};
obj.getJSONArray("time").remove(0);
obj.getJSONArray("time").remove(0);
obj.getJSONArray("time").put(startEnd[0]);
obj.getJSONArray("time").put(startEnd[1]);
query =getPrepareStatement().getStatement(obj,this);
DBObject condition = new BasicDBObject("$match",query.get());
DBObject select= new BasicDBObject("$project",new BasicDBObject("flowId",1).append("flowStartMilliseconds", 1).append("flowEndMilliseconds", 1).append("octetDeltaCount", 1));
DBObject sortFields = new BasicDBObject("octetDeltaCount", -1);
DBObject sort = new BasicDBObject("$sort", sortFields );
query =getPrepareStatement().getStatement(obj,this);
DBObject condition = new BasicDBObject("$match",query.get());
DBObject select= new BasicDBObject("$project",new BasicDBObject("flowId",1).append("flowStartMilliseconds", 1).append("flowEndMilliseconds", 1).append("octetDeltaCount", 1));
AggregationOutput aggOut=db.getDatabase().getCollection("records_main").aggregate(condition,select,sort);
Iterator<DBObject> result= aggOut.results().iterator();
DBObject sortFields = new BasicDBObject("octetDeltaCount", -1);
DBObject sort = new BasicDBObject("$sort", sortFields );
AggregationOutput aggOut=db.getDatabase().getCollection("records_main").aggregate(condition,select,sort);
for(int i=0; i<intervals.size(); i++){
calculate.setStartInterval(intervals.get(i));
calculate.setEndInterval(intervals.get(i)+999);
calculate.setStartInterval(startEnd[0]);
calculate.setEndInterval(startEnd[1]);
calculate.processData(result);
finalResult.put(new JSONArray().put(startEnd[0]).put(calculate.getResutValue()));
calculate.processData(aggOut);
finalResult.put(new JSONArray().put(intervals.get(i)).put(calculate.getResutValue()));
}
db.disconnect();
getJedis().publish("ResponseBandwidthHistoryTrend",ModuleResponse.sentDataJsonArray("BandwidthHistoryTrend", "ok", finalResult).toString());
......
......@@ -102,33 +102,29 @@ public class BandwidthHistoryTrendPacket extends AbstractModule{
getJedis().publish("ResponseBandwidthHistoryTrendPacket",ModuleResponse.sentData("BandwidthHistoryTrendPacket", "error", "Some of required attribute is missing").toString());
}else{
db.connect(Config.dbHost,Config.dbPort,Config.dbName);
List<Long> intervals = getIntervals(query,db);
Collections.sort(intervals);
//Enumeration<Long[]> keys = intervals.keys();
JSONArray finalResult = new JSONArray();
long pocet =0;
query =getPrepareStatement().getStatement(obj,this);
DBObject condition = new BasicDBObject("$match",query.get());
DBObject select= new BasicDBObject("$project",new BasicDBObject("flowId",1).append("flowStartMilliseconds", 1).append("flowEndMilliseconds", 1).append("packetDeltaCount", 1));
DBObject sortFields = new BasicDBObject("packetDeltaCount", -1);
DBObject sort = new BasicDBObject("$sort", sortFields );
AggregationOutput aggOut=db.getDatabase().getCollection("records_main").aggregate(condition,select,sort);
for(int i=0; i<intervals.size(); i++){
Long[] startEnd = {intervals.get(i),intervals.get(i)+999};
obj.getJSONArray("time").remove(0);
obj.getJSONArray("time").remove(0);
obj.getJSONArray("time").put(startEnd[0]);
obj.getJSONArray("time").put(startEnd[1]);
calculate.setStartInterval(intervals.get(i));
calculate.setEndInterval(intervals.get(i)+999);
query =getPrepareStatement().getStatement(obj,this);
DBObject condition = new BasicDBObject("$match",query.get());
DBObject select= new BasicDBObject("$project",new BasicDBObject("flowId",1).append("flowStartMilliseconds", 1).append("flowEndMilliseconds", 1).append("packetDeltaCount", 1));
AggregationOutput aggOut=db.getDatabase().getCollection("records_main").aggregate(condition,select);
Iterator<DBObject> result= aggOut.results().iterator();
//pocet+= (((Collection<DBObject>) aggOut.results()).size());
calculate.setStartInterval(startEnd[0]);
calculate.setEndInterval(startEnd[1]);
calculate.processData(result);
finalResult.put(new JSONArray().put(startEnd[0]).put(calculate.getResutValue()));
calculate.processData(aggOut);
finalResult.put(new JSONArray().put(intervals.get(i)).put(calculate.getResutValue()));
}
//System.out.println("--- "+pocet);
db.disconnect();
getJedis().publish("ResponseBandwidthHistoryTrendPacket",ModuleResponse.sentDataJsonArray("BandwidthHistoryTrendPacket", "ok", finalResult).toString());
//System.out.println("|ResponseBandwidthHistoryTrendPacket | Dáta"+finalResult);
}
......@@ -143,7 +139,7 @@ public class BandwidthHistoryTrendPacket extends AbstractModule{
Hashtable<Long,Double> table = new Hashtable<Long,Double>();
List<Long> table2 = new ArrayList<Long>();
DBObject condition = new BasicDBObject("$match",guery.get());
DBObject select= new BasicDBObject("$project",new BasicDBObject("flowId",1).append("flowStartMilliseconds", 1).append("flowEndMilliseconds", 1).append("octetDeltaCount", 1));
DBObject select= new BasicDBObject("$project",new BasicDBObject("flowId",1).append("flowStartMilliseconds", 1).append("flowEndMilliseconds", 1).append("packetDeltaCount", 1));
DBObject sortFields = new BasicDBObject("flowStartMilliseconds", 1);
DBObject sort = new BasicDBObject("$sort", sortFields );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment