Commit 860d1fac authored by Steeve FOURNEAUX's avatar Steeve FOURNEAUX

Addind file size functions

parent 7a597ea9
......@@ -146,4 +146,39 @@ class ExpressedPercentageDataType(FloatDataType):
def r_format(self):
return str(round(self.value, 2))
# =========================================================================
class DataSizeDataType(IntegerDataType):
"""
DataSizeDataType apply to all file size parameters parameters and, for LaTeX, the value is truncated in function
of the size unit Ko, Mo, Go before being formatted with the convention 123,456,789
"""
type_name = 'data size'
def standard_format(self):
return int(self.value)
def latex_format(self):
if (self.value % 1000000000) != self.value:
divider = 1000000000
unit = 'Go'
elif (self.value % 1000000) != self.value:
divider = 1000000
unit = 'Mo'
elif (self.value % 1000) != self.value:
divider = 1000
unit = 'Ko'
elif (self.value % 1000) == self.value:
divider = 1
unit = 'o'
else:
raise ValueError("the size value is incorrect: {0}".format(self.value))
# click.secho("{0} : {1} : {2} : {3} : {4} : {5}".format(
# self.value,
# divider,
# round(self.value / float(divider), 1),
# round(self.value / float(divider), 2),
# '{0} {1}'.format("{:,.1f}".format(round(self.value / float(divider), 1)), unit),
# '{0} {1}'.format("{:,.1f}".format(round(self.value / float(divider), 2)), unit)
# ), fg="blue")
return '{0} {1}'.format("{:,.1f}".format(round(self.value / float(divider), 2)), unit)
......@@ -25,13 +25,12 @@ Credits:
# Modules
# =========================================================================
from Agoge.NumericalDataTypes import IntegerDataType, MegaIntegerDataType, FloatDataType, BasePercentageDataType, \
ExpressedPercentageDataType
ExpressedPercentageDataType, DataSizeDataType
from Agoge.OtherDataTypes import ListDataType, DictDataType, SliceOfChromosomeCoordinatesWithIntegerDataType
from Agoge.StringDataTypes import StringDataType, FastQCDataType, PathDataType, ChromosomeCoordinatesDataType
# =========================================================================
AVAILABLE_DATA_TYPES = {}
AVAILABLE_DATA_TYPES['string'] = StringDataType
......@@ -44,6 +43,7 @@ AVAILABLE_DATA_TYPES['mega integer'] = MegaIntegerDataType
AVAILABLE_DATA_TYPES['float'] = FloatDataType
AVAILABLE_DATA_TYPES['base percentage'] = BasePercentageDataType
AVAILABLE_DATA_TYPES['expressed percentage'] = ExpressedPercentageDataType
AVAILABLE_DATA_TYPES['data size'] = DataSizeDataType
AVAILABLE_DATA_TYPES['list'] = ListDataType
AVAILABLE_DATA_TYPES['dict'] = DictDataType
......
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