Permalink
Browse files

Move format_int to safe.common.utilities, note for issue #449

  • Loading branch information...
1 parent a62c397 commit 25872f3df6239955aa0128f4fd963dc26e0d2494 @ismailsunni ismailsunni committed Feb 25, 2013
View
@@ -47,7 +47,8 @@
temp_dir,
unique_filename,
ugettext as safe_tr,
- get_free_memory)
+ get_free_memory,
+ format_int)
from safe.common.version import get_version
from safe.common.polygon import in_and_outside_polygon
from safe.common.tables import Table, TableCell, TableRow
View
@@ -278,3 +278,35 @@ def get_free_memory_osx():
inactive = stdout_list[2].replace('M inactive', '').replace(' ', '')
free = stdout_list[4].replace('M free.', '').replace(' ', '')
return int(inactive) + int(free)
+
+
+def format_int(x):
+ """Format integer with separator between thousands
+
+ From http://stackoverflow.com/questions/5513615/
+ add-thousands-separators-to-a-number
+
+ # FIXME (Ole)
+ Currently not using locale coz broken
+
+ Instead use this:
+ http://docs.python.org/library/string.html#formatspec
+
+ """
+
+ # This is broken
+ #import locale
+ #locale.setlocale(locale.LC_ALL, '') # Broken, why?
+ #s = locale.format('%d', x, 1)
+
+ lang = os.getenv('LANG')
+
+ s = '{0:,}'.format(x)
+ #s = '{0:n}'.format(x) # n means locale aware (read up on this)
+
+ # Quick solution for the moment
+ if lang == 'id':
+ # Replace commas with dots
+ s = s.replace(',', '.')
+
+ return s
@@ -14,10 +14,10 @@
from safe.impact_functions.core import (FunctionProvider,
get_hazard_layer,
- get_exposure_layer,
- format_int)
+ get_exposure_layer)
from safe.storage.vector import Vector
-from safe.common.utilities import ugettext as tr
+from safe.common.utilities import (ugettext as tr,
+ format_int)
from safe.impact_functions.mappings import osm2bnpb
from safe.impact_functions.mappings import unspecific2bnpb
from safe.impact_functions.mappings import sigab2bnpb
@@ -1,10 +1,10 @@
import numpy
from safe.impact_functions.core import (FunctionProvider,
get_hazard_layer,
- get_exposure_layers,
- format_int)
+ get_exposure_layers)
from safe.storage.raster import Raster
-from safe.common.utilities import verify
+from safe.common.utilities import (verify,
+ format_int)
# Want to use the human readably name in the impact function
# pylint: disable=W0622
@@ -1,8 +1,8 @@
from safe.impact_functions.core import (FunctionProvider,
get_hazard_layer,
- get_exposure_layers,
- format_int)
+ get_exposure_layers)
from safe.impact_functions.styles import earthquake_fatality_style
+from safe.common.utilities import format_int
from safe.storage.raster import Raster
import numpy
@@ -1,10 +1,10 @@
from safe.impact_functions.core import (FunctionProvider,
get_hazard_layer,
get_exposure_layer,
- get_question,
- format_int)
+ get_question)
+from safe.common.utilities import (ugettext as tr,
+ format_int)
from safe.storage.vector import Vector
-from safe.common.utilities import ugettext as tr
from safe.common.tables import Table, TableRow
from safe.engine.interpolation import assign_hazard_values_to_exposure_data
from third_party.odict import OrderedDict
@@ -3,11 +3,11 @@
get_hazard_layer,
get_exposure_layer,
get_question,
- get_function_title,
- format_int)
+ get_function_title)
from safe.impact_functions.styles import flood_population_style as style_info
from safe.storage.raster import Raster
-from safe.common.utilities import ugettext as tr
+from safe.common.utilities import (ugettext as tr,
+ format_int)
from safe.common.tables import Table, TableRow
@@ -23,10 +23,10 @@
from safe.impact_functions.core import (FunctionProvider,
get_hazard_layer,
get_exposure_layer,
- get_question,
- format_int)
+ get_question)
from safe.storage.vector import Vector
-from safe.common.utilities import ugettext as tr
+from safe.common.utilities import (ugettext as tr,
+ format_int)
from safe.common.numerics import lognormal_cdf
from safe.common.tables import Table, TableRow
from safe.impact_functions.mappings import osm2padang, sigab2padang
@@ -26,11 +26,12 @@
from safe.common.interpolation2d import interpolate_raster
from safe.common.numerics import normal_cdf, lognormal_cdf, erf, ensure_numeric
from safe.common.numerics import nanallclose
-from safe.common.utilities import VerificationError, unique_filename
+from safe.common.utilities import (VerificationError,
+ unique_filename,
+ format_int)
from safe.common.testing import TESTDATA, HAZDATA, EXPDATA
from safe.common.exceptions import InaSAFEError
from safe.impact_functions import get_plugins, get_plugin
-from safe.impact_functions.core import format_int
# These imports are needed for impact function registration - dont remove
# If any of these get reinstated as "official" public impact functions,
@@ -786,36 +786,3 @@ def is_function_enabled(func):
if dict_req.get('disabled', False):
return False
return True
-
-
-def format_int(x):
- """Format integer with separator between thousands
-
- From http://stackoverflow.com/questions/5513615/
- add-thousands-separators-to-a-number
-
- # FIXME (Ole)
- Currently not using locale coz broken
-
- Instead use this:
- http://docs.python.org/library/string.html#formatspec
-
- """
-
- # This is broken
- #import locale
- #locale.setlocale(locale.LC_ALL, '') # Broken, why?
- #s = locale.format('%d', x, 1)
-
- import os
- lang = os.getenv('LANG')
-
- s = '{0:,}'.format(x)
- #s = '{0:n}'.format(x) # n means locale aware (read up on this)
-
- # Quick solution for the moment
- if lang == 'id':
- # Replace commas with dots
- s = s.replace(',', '.')
-
- return s
@@ -1,10 +1,10 @@
from safe.impact_functions.core import (FunctionProvider,
get_hazard_layer,
get_exposure_layer,
- get_question,
- format_int)
+ get_question)
from safe.storage.vector import Vector
-from safe.common.utilities import ugettext as tr
+from safe.common.utilities import (ugettext as tr,
+ format_int)
from safe.common.tables import Table, TableRow
from safe.engine.interpolation import assign_hazard_values_to_exposure_data
from third_party.odict import OrderedDict
@@ -1,11 +1,11 @@
from safe.impact_functions.core import (FunctionProvider,
get_hazard_layer,
get_exposure_layer,
- get_question,
- format_int)
+ get_question)
from safe.storage.raster import Raster
from safe.common.utilities import (ugettext as tr,
- get_defaults)
+ get_defaults,
+ format_int)
from safe.common.tables import Table, TableRow
from safe.common.exceptions import InaSAFEError
from third_party.odict import OrderedDict
@@ -1,11 +1,11 @@
from safe.impact_functions.core import (FunctionProvider,
get_hazard_layer,
get_exposure_layer,
- get_question,
- format_int)
+ get_question)
from safe.storage.vector import Vector
from safe.storage.utilities import DEFAULT_ATTRIBUTE
-from safe.common.utilities import ugettext as tr
+from safe.common.utilities import (ugettext as tr,
+ format_int)
from safe.common.tables import Table, TableRow
from safe.engine.interpolation import assign_hazard_values_to_exposure_data
@@ -3,12 +3,12 @@
get_hazard_layer,
get_exposure_layer,
get_question,
- get_function_title,
- format_int)
+ get_function_title)
from safe.impact_functions.styles import flood_population_style as style_info
from safe.storage.raster import Raster
from safe.common.utilities import (ugettext as tr,
- get_defaults)
+ get_defaults,
+ format_int)
from safe.common.utilities import verify
from safe.common.tables import Table, TableRow
from third_party.odict import OrderedDict
@@ -2,10 +2,10 @@
from safe.impact_functions.core import (FunctionProvider,
get_hazard_layer,
get_exposure_layer,
- get_question,
- format_int)
+ get_question)
from safe.storage.vector import Vector
-from safe.common.utilities import ugettext as tr
+from safe.common.utilities import (ugettext as tr,
+ format_int)
from safe.common.tables import Table, TableRow, TableCell
from safe.engine.interpolation import assign_hazard_values_to_exposure_data
from safe.common.utilities import get_defaults
@@ -2,10 +2,10 @@
from safe.impact_functions.core import (FunctionProvider,
get_hazard_layer,
get_exposure_layer,
- get_question,
- format_int)
+ get_question)
from safe.storage.vector import Vector
-from safe.common.utilities import ugettext as tr
+from safe.common.utilities import (ugettext as tr,
+ format_int)
from safe.common.tables import Table, TableRow
from safe.engine.interpolation import (assign_hazard_values_to_exposure_data,
make_circular_polygon)
@@ -2,10 +2,10 @@
from safe.impact_functions.core import (FunctionProvider,
get_hazard_layer,
get_exposure_layer,
- get_question,
- format_int)
+ get_question)
from safe.storage.vector import Vector
-from safe.common.utilities import ugettext as tr
+from safe.common.utilities import (ugettext as tr,
+ format_int)
from safe.common.tables import Table, TableRow
from safe.engine.interpolation import (assign_hazard_values_to_exposure_data,
make_circular_polygon)
@@ -49,7 +49,8 @@
in_and_outside_polygon as points_in_and_outside_polygon,
calculate_polygon_centroid,
get_postprocessors,
- get_postprocessor_human_name)
+ get_postprocessor_human_name,
+ format_int)
from safe.defaults import DEFAULTS
# pylint: enable=W0611
View
@@ -37,7 +37,7 @@
QgsMapLayerRegistry,
QgsRectangle)
# TODO: get this via api
-from safe.impact_functions.core import format_int
+from safe_interface import format_int
from safe.common.testing import HAZDATA, EXPDATA, TESTDATA, UNITDATA, BOUNDDATA
from safe_qgis.utilities_test import (getQgisTestApp,

0 comments on commit 25872f3

Please sign in to comment.