本文整理汇总了Python中safe.common.utilities.format_int函数的典型用法代码示例。如果您正苦于以下问题:Python format_int函数的具体用法?Python format_int怎么用?Python format_int使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了format_int函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: format_breakdown
def format_breakdown(self):
"""Breakdown by road type.
:returns: The roads breakdown report.
:rtype: safe.message.Message
"""
road_breakdown = self.roads_breakdown
attributes = road_breakdown['attributes']
fields = road_breakdown['fields']
message = m.Message(style_class='container')
table = m.Table(style_class='table table-condensed table-striped')
table.caption = None
row = m.Row()
row.add(m.Cell(tr('Breakdown by road type'), header=True))
for _ in attributes:
# Add empty cell as many as affected_categories
row.add(m.Cell('', header=True))
# Add empty cell for total column
row.add(m.Cell('', header=True))
table.add(row)
row = m.Row()
# We align left the first column, then right.
row.add(m.Cell(tr(attributes[0]), header=True))
for attribute in attributes[1:]:
row.add(m.Cell(tr(attribute), header=True, align='right'))
table.add(row)
for field in fields:
row = m.Row()
# First column
# proper format for i186
row.add(m.Cell(
tr('%(road_type)s (m)') % {
'road_type': tr(field[0].capitalize())}))
# Start from second column
for value in field[1:]:
row.add(m.Cell(
format_int(int(value)), align='right'))
table.add(row)
impact_summary_fields = self.impact_summary['fields']
row = m.Row()
row.add(m.Cell(tr('Total (m)'), header=True))
for field in impact_summary_fields:
for value in field:
row.add(m.Cell(
format_int(int(value)),
align='right',
header=True))
table.add(row)
message.add(table)
return message
示例2: action_checklist
def action_checklist(self):
"""Action Checklist Data.
:returns: An action list in dictionary format.
:rtype: dict
"""
title = tr('Action checklist')
fields = [
tr('Which structures have warning capacity (eg. sirens, speakers, '
'etc.)?'),
tr('Are the water and electricity services still operating?'),
tr('Are the health centres still open?'),
tr('Are the other public services accessible?'),
tr('Which buildings will be evacuation centres?'),
tr('Where will we locate the operations centre?'),
tr('Where will we locate warehouse and/or distribution centres?'),
tr('Are the schools and hospitals still active?'),
]
if self.schools_closed > 0:
fields.append(tr(
'Where will the students from the %s closed schools go to '
'study?') % format_int(self.schools_closed))
if self.hospitals_closed > 0:
fields.append(tr(
'Where will the patients from the %s closed hospitals go '
'for treatment and how will we transport them?') % format_int(
self.hospitals_closed))
return {
'title': title,
'fields': fields
}
示例3: action_checklist
def action_checklist(self):
"""Action checklist for the itb earthquake fatality report.
:returns: The action checklist
:rtype: list
"""
total_fatalities = self.total_fatalities
total_displaced = self.total_evacuated
rounded_displaced = format_int(population_rounding(total_displaced))
fields = super(ITBFatalityFunction, self).action_checklist()
if total_fatalities:
fields.append(tr(
'Are there enough victim identification units available '
'for %s people?') % (
format_int(population_rounding(total_fatalities))))
if total_displaced:
fields.append(tr(
'Are there enough shelters and relief items available for '
'%s people?') % rounded_displaced)
if rounded_displaced:
fields.append(tr(
'If yes, where are they located and how will we '
'distribute them?'))
if total_displaced:
fields.append(tr(
'If no, where can we obtain additional relief items '
'from and how will we transport them?'))
return fields
示例4: test_volcano_circle_population_impact
def test_volcano_circle_population_impact(self):
"""Volcano function runs circular evacuation zone."""
# Name file names for hazard level, exposure and expected fatalities
hazard_filename = '%s/Merapi_alert.shp' % TESTDATA
exposure_filename = ('%s/glp10ag.asc' % EXPDATA)
# Calculate impact using API
hazard_layer = read_layer(hazard_filename)
exposure_layer = read_layer(exposure_filename)
plugin_name = 'Volcano Polygon Hazard Population'
impact_function = get_plugin(plugin_name)
impact_layer = calculate_impact(
layers=[hazard_layer, exposure_layer], impact_fcn=impact_function)
impact_filename = impact_layer.get_filename()
impact_layer = read_layer(impact_filename)
keywords = impact_layer.get_keywords()
print keywords
# This is the expected number of people affected
# Distance [km] Total Cumulative
# 3 15.800 15.800
# 5 17.300 33.100
# 10 125.000 158.000
message = 'Result not as expected'
impact_summary = keywords['impact_summary']
self.assertTrue(format_int(15800) in impact_summary, message)
self.assertTrue(format_int(17300) in impact_summary, message)
self.assertTrue(format_int(125000) in impact_summary, message)
示例5: roads_breakdown
def roads_breakdown(self):
"""Breakdown by road type.
:returns: The roads breakdown report.
:rtype: list
"""
category_names = self.affected_road_categories
roads_breakdown_report = [({"content": (tr("Breakdown by road type")), "header": True})]
for road_type in self.road_lengths:
affected_by_usage = []
for category in category_names:
if road_type in self.affected_road_lengths[category]:
affected_by_usage.append(self.affected_road_lengths[category][road_type])
else:
affected_by_usage.append(0)
road_detail = (
# building type
[road_type.capitalize()]
+
# categories
[format_int(int(x)) for x in affected_by_usage]
+
# total
[format_int(int(self.road_lengths[road_type]))]
)
roads_breakdown_report.append({"content": road_detail})
return roads_breakdown_report
示例6: action_checklist
def action_checklist(self):
"""Breakdown by building type.
:returns: The buildings breakdown report.
:rtype: safe.messaging.Message
"""
schools_closed = self.schools_closed
hospitals_closed = self.hospitals_closed
message = m.Message(style_class='container')
message.add(m.Heading(tr('Action checklist'), **styles.INFO_STYLE))
checklist = m.BulletedList()
checklist.add(tr('Are the critical facilities still open?'))
checklist.add(tr(
'Which structures have warning capacity (eg. sirens, speakers, '
'etc.)?'))
checklist.add(tr('Which buildings will be evacuation centres?'))
checklist.add(tr('Where will we locate the operations centre?'))
checklist.add(
tr('Where will we locate warehouse and/or distribution centres?'))
if schools_closed > 0:
checklist.add(tr(
'Where will the students from the %s closed schools '
'go to study?') % format_int(schools_closed))
if hospitals_closed > 0:
checklist.add(tr(
'Where will the patients from the %s closed hospitals go '
'for treatment and how will we transport them?') % format_int(
hospitals_closed))
message.add(checklist)
return message
示例7: test_earthquake_building_impact_function
def test_earthquake_building_impact_function(self):
"""Earthquake Building Impact Function works as expected."""
# Name file names for hazard level, exposure and expected fatalities
hazard_filename = '%s/eq_yogya_2006.asc' % HAZDATA
exposure_filename = '%s/OSM_building_polygons_20110905.shp' % TESTDATA
# Calculate impact using API
hazard_layer = read_layer(hazard_filename)
exposure_layer = read_layer(exposure_filename)
plugin_name = 'Earthquake Building Impact Function'
impact_function = get_plugin(plugin_name)
# Call calculation engine
impact_layer = calculate_impact(
layers=[hazard_layer, exposure_layer], impact_fcn=impact_function)
impact_filename = impact_layer.get_filename()
impact_layer = read_layer(impact_filename)
# calculated_result = I.get_data()
# print calculated_result.shape
keywords = impact_layer.get_keywords()
impact_summary = keywords['impact_summary']
# This is the expected number of building might be affected
# Hazard Level - Buildings Affected
# Low - 845
# Medium - 15524
# High - 122
message = 'Result not as expected'
self.assertTrue(format_int(845) in impact_summary, message)
self.assertTrue(format_int(15524) in impact_summary, message)
self.assertTrue(format_int(122) in impact_summary, message)
示例8: test_format_int
def test_format_int(self):
"""Test formatting integer
"""
my_int = 10000000
lang = os.getenv('LANG')
my_formated_int = format_int(my_int)
if lang == 'id':
expected_str = '10.000.000'
else:
expected_str = '10,000,000'
my_msg = 'Format integer is not valid'
assert (my_formated_int == expected_str or
my_formated_int == str(my_int)), my_msg
my_int = 1234
lang = os.getenv('LANG')
print lang
my_formated_int = format_int(my_int)
if lang == 'id':
expected_str = '1.234'
else:
expected_str = '1,234'
my_msg = 'Format integer %s is not valid' % my_formated_int
assert (my_formated_int == expected_str or
my_formated_int == str(my_int)), my_msg
示例9: action_checklist
def action_checklist(self):
"""Action checklist for the itb earthquake fatality report.
:returns: The action checklist
:rtype: list
"""
total_fatalities = self.total_fatalities
total_displaced = self.total_evacuated
rounded_displaced = format_int(population_rounding(total_displaced))
message = m.Message(style_class='container')
message.add(m.Heading(tr('Action checklist'), **styles.INFO_STYLE))
checklist = m.BulletedList()
if total_fatalities:
checklist.add(tr(
'Are there enough victim identification units available '
'for %s people?') % (
format_int(population_rounding(total_fatalities))))
if total_displaced:
checklist.add(tr(
'Are there enough shelters and relief items available for '
'%s people?') % rounded_displaced)
if rounded_displaced:
checklist.add(tr(
'If yes, where are they located and how will we '
'distribute them?'))
if total_displaced:
checklist.add(tr(
'If no, where can we obtain additional relief items '
'from and how will we transport them?'))
message.add(checklist)
return message
示例10: notes
def notes(self):
"""Return the notes section of the report.
:return: The notes that should be attached to this impact report.
:rtype: list
"""
population = format_int(population_rounding(self.total_population))
threshold = format_int(self.parameters['evacuation_percentage'].value)
if get_needs_provenance_value(self.parameters) is None:
needs_provenance = ''
else:
needs_provenance = tr(get_needs_provenance_value(self.parameters))
fields = [
tr('Total population in the analysis area: %s') % population,
tr('<sup>1</sup>The evacuation threshold used to determine '
'population needing evacuation is %s%%.') % threshold,
needs_provenance,
]
if self.no_data_warning:
fields = fields + no_data_warning
# include any generic exposure specific notes from definitions.py
fields = fields + self.exposure_notes()
# include any generic hazard specific notes from definitions.py
fields = fields + self.hazard_notes()
return fields
示例11: _tabulate
def _tabulate(self, counts, evacuated, minimum_needs, question, rounding,
thresholds, total, no_data_warning):
# noinspection PyListCreation
table_body = [
question,
TableRow([(tr('People in %.1f m of water') % thresholds[-1]),
'%s*' % format_int(evacuated)],
header=True),
TableRow(
tr('* Number is rounded up to the nearest %s') % rounding),
TableRow(tr('Map shows the numbers of people needing evacuation'))]
total_needs = evacuated_population_needs(
evacuated, minimum_needs)
for frequency, needs in total_needs.items():
table_body.append(TableRow(
[
tr('Needs should be provided %s' % frequency),
tr('Total')
],
header=True))
for resource in needs:
table_body.append(TableRow([
tr(resource['table name']),
format_int(resource['amount'])]))
table_body.append(TableRow(tr('Action Checklist:'), header=True))
table_body.append(TableRow(tr('How will warnings be disseminated?')))
table_body.append(TableRow(tr('How will we reach stranded people?')))
table_body.append(TableRow(tr('Do we have enough relief items?')))
table_body.append(TableRow(tr('If yes, where are they located and how '
'will we distribute them?')))
table_body.append(TableRow(tr(
'If no, where can we obtain additional relief items from and how '
'will we transport them to here?')))
# Extend impact report for on-screen display
table_body.extend([
TableRow(tr('Notes'), header=True),
tr('Total population: %s') % format_int(total),
tr('People need evacuation if tsunami levels exceed %(eps).1f m') %
{'eps': thresholds[-1]},
tr('Minimum needs are defined in BNPB regulation 7/2008'),
tr('All values are rounded up to the nearest integer in order to '
'avoid representing human lives as fractions.')])
if len(counts) > 1:
table_body.append(TableRow(tr('Detailed breakdown'), header=True))
for i, val in enumerate(counts[:-1]):
s = (tr('People in %(lo).1f m to %(hi).1f m of water: %(val)i')
% {'lo': thresholds[i],
'hi': thresholds[i + 1],
'val': format_int(val[0])})
table_body.append(TableRow(s))
if no_data_warning:
table_body.extend([
tr('The layers contained `no data`. This missing data was '
'carried through to the impact layer.'),
tr('`No data` values in the impact layer were treated as 0 '
'when counting the affected or total population.')
])
return table_body, total_needs
示例12: hazard_table
def hazard_table(self, hazard_table):
""" Return updated hazard table.
:param hazard_table: hazard table.
:type hazard_table: Table
:returns hazard_table: Updated Hazard Table
:rtype area_name: Table
"""
hazard_table.caption = None
for key, value in self.hazard_levels.iteritems():
name = self.hazard_class_mapping[key][0]
# This skips reporting people not affected in No zone
if key == 'wet':
row = m.Row()
row.add(m.Cell(tr(
'People within hazard field ("%s") of value "%s"')
% (self.hazard_class_field, name),
header=True))
value = format_int(population_rounding(value))
row.add(m.Cell(value, align='right'))
elif key == 'dry':
continue
else:
row = m.Row()
row.add(m.Cell(name, header=True))
value = format_int(population_rounding(value))
row.add(m.Cell(value, align='right'))
hazard_table.add(row)
# Total affected population
row = m.Row()
row.add(m.Cell(
tr('Total affected people'),
header=True))
affected = format_int(
population_rounding(self.total_affected_population))
row.add(m.Cell(affected, align='right'))
hazard_table.add(row)
# Non affected population
row = m.Row()
unaffected = format_int(
population_rounding(self.unaffected_population))
row.add(m.Cell(tr('Unaffected people'), header=True))
row.add(m.Cell(unaffected, align='right'))
hazard_table.add(row)
# Total Population
row = m.Row()
total_population = format_int(
population_rounding(self.total_population))
row.add(m.Cell(tr('Total people'), header=True))
row.add(m.Cell(total_population, align='right'))
hazard_table.add(row)
return hazard_table
示例13: impact_summary
def impact_summary(self):
"""The impact summary as per category
:returns: The impact summary.
:rtype: safe.message.Message
"""
affected_categories = self.affected_road_categories
message = m.Message(style_class='container')
table = m.Table(style_class='table table-condensed table-striped')
table.caption = None
row = m.Row()
row.add(m.Cell(tr('Summary by road type'), header=True))
for _ in affected_categories:
# Add empty cell as many as affected_categories
row.add(m.Cell('', header=True))
if self.add_unaffected_column:
# Add empty cell for un-affected road
row.add(m.Cell('', header=True))
# Add empty cell for total column
row.add(m.Cell('', header=True))
table.add(row)
row = m.Row()
row.add(m.Cell(tr('Road Type'), header=True))
for affected_category in affected_categories:
row.add(m.Cell(affected_category, header=True, align='right'))
if self.add_unaffected_column:
row.add(m.Cell(tr('Unaffected'), header=True, align='right'))
row.add(m.Cell(tr('Total'), header=True, align='right'))
table.add(row)
total_affected = [0] * len(affected_categories)
for (category, road_breakdown) in self.affected_road_lengths.items():
number_affected = sum(road_breakdown.values())
count = affected_categories.index(category)
total_affected[count] = number_affected
row = m.Row()
row.add(m.Cell(tr('All (m)')))
for total_affected_value in total_affected:
row.add(m.Cell(
format_int(int(total_affected_value)), align='right'))
if self.add_unaffected_column:
row.add(m.Cell(format_int(int(
self.total_road_length - sum(total_affected))), align='right'))
row.add(m.Cell(format_int(int(self.total_road_length)), align='right'))
table.add(row)
message.add(table)
return message
示例14: notes
def notes(self):
"""Return the notes section of the report.
:return: The notes that should be attached to this impact report.
:rtype: list
"""
notes = [
{'content': tr('Notes'), 'header': True},
{
'content': tr('Total population: %s') % format_int(
population_rounding(self.total_population))
},
{
'content': tr(
'<sup>1</sup>The evacuation threshold used to determine '
'population needing evacuation is %s%%.'),
'arguments': format_int(
self.parameters['evacuation_percentage'].value)
},
{
'content': tr(
''
'are within any polygons.'),
'condition': not self.use_affected_field
},
{
'content': tr(
'The layers contained `no data`. This missing data was '
'carried through to the impact layer.'),
'condition': self.no_data_warning
},
{
'content': tr(
'`No data` values in the impact layer were treated as 0 '
'when counting the affected or total population.'),
'condition': self.no_data_warning
},
{
'content': get_needs_provenance_value(self.parameters)
},
{
'content': tr(
'All values are rounded up to the nearest integer in '
'order to avoid representing human lives as fractions.'),
},
{
'content': tr(
'Population rounding is applied to all population '
'values, which may cause discrepancies when adding '
'values.'
)
}
]
return notes
示例15: impact_row
def impact_row(
area_name,
affected,
percent_affected,
single_total_area,
number_people_affected,
percent_people_affected,
area_population):
"""Adds the calculated results into respective impact row
:param area_name: Area Name
:type area_name: str
:param affected: table with first and second row
:type affected: Table
:param percent_affected: percentage of affected area
:type percent_affected: float
:param single_total_area: total area of the land
:type single_total_area: float
:param number_people_affected: number of people affected
:type number_people_affected: float
:param percent_people_affected: percentage of people affected
in the area
:type percent_people_affected: float
:param area_population: Population of the area
:type area_population: float
:return row: the new impact row
:rtype row: Row
"""
row = m.Row()
row.add(m.Cell(area_name))
row.add(m.Cell(format_int(int(affected)), align='right'))
row.add(m.Cell(
"%.1f%%" % percent_affected, align='right'))
row.add(m.Cell(
format_int(int(single_total_area)), align='right'))
row.add(m.Cell(
format_int(int(number_people_affected)),
align='right'))
row.add(m.Cell("%.1f%%" % percent_people_affected, align='right'))
row.add(m.Cell(
format_int(int(area_population)),
align='right'))
return row