Skip to content
Snippets Groups Projects
Commit 352fb7bd authored by Piotr's avatar Piotr
Browse files

propagate to DNI3: change applyPrefix and getDependecyValue 1000 vs 1024

parent b04ca90d
No related branches found
No related tags found
No related merge requests found
......@@ -75,6 +75,12 @@ operation Any toString() : String {
////////////////////////////////////////////////////////////////////////////////////////
operation DNI!Dependency getDependencyValue() : Real {
//self.value - Real / Long
//self.unit - DNIUnit (abstract): TimeUnit, DataUnit, SpeedUnit
//self.unit.unit = Time, Speed
//self.unit.prefix = UnitPrefix
var value = 0.0;
if(self.hasProperty("value")){
......@@ -96,31 +102,44 @@ operation DNI!Dependency getDependencyValue() : Real {
value = value/1000.0/1000.0;
}
}
else if(self.unit.isTypeOf(DNI!DataUnit)){ //////////// this is data unit
//nothing. prefix is applied later
else if(self.unit.isTypeOf(DNI!DataUnit)){ //////////// this is data unit - 1 KB = 1024B
if(self.unit.hasProperty("prefix")){
if(self.unit.prefix.isTypeOf(DNI!EEnumLiteral)){
value = self.unit.prefix.applyPrefix(value, 1024);
}
}
}
else if(self.unit.isTypeOf(DNI!SpeedUnit)){ //////////// this is througput unit
if(self.unit.unit==DNI!Speed#bitsPerSec){
value /= 8d;
//value /= 8d; //whoy do you want to convert it into bytes??
if(self.unit.hasProperty("prefix")){
if(self.unit.prefix.isTypeOf(DNI!EEnumLiteral)){
value = self.unit.prefix.applyPrefix(value, 1000);
}
}
}
else if(self.unit==DNI!Speed#packetsPerSec){
throw ("Cannot convert DNI!SpeedUnit packets per second to Bytes per second!");
if(self.unit.hasProperty("prefix")){
if(self.unit.prefix.isTypeOf(DNI!EEnumLiteral)){
value = self.unit.prefix.applyPrefix(value, 1000);
}
}
throw ("WARNING! WE return packets per second! Make sure that this is what you want");
}
else{
else if(self.unit==DNI!Speed#bytesPerSec){
if(self.unit.hasProperty("prefix")){
if(self.unit.prefix.isTypeOf(DNI!EEnumLiteral)){
value = self.unit.prefix.applyPrefix(value, 1024);
}
}
}
}
if(self.unit.hasProperty("prefix")){
if(self.unit.prefix.isTypeOf(DNI!EEnumLiteral)){
value = self.unit.prefix.applyPrefix(value, 1000); ///this should not be always 1000!!! 1 Kbps = 1000 bps, but 1KBps = 1024 Bps!!
}
}
}
return value;
}
////////////////////////////////////////////////////////////////////////////////////////
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment