add format to numbers and remove some datas

This commit is contained in:
Cayo Puigdefabregas 2021-02-11 20:00:57 +01:00
parent a2b0d0c02f
commit 1fff5cd32e
3 changed files with 37 additions and 26 deletions

View File

@ -619,7 +619,8 @@ class BenchmarkDataStorage(Benchmark):
write_speed = Column(Float(decimal_return_scale=2), nullable=False)
def __str__(self) -> str:
return 'Read: {} MB/s, write: {} MB/s'.format(self.read_speed, self.write_speed)
return 'Read: {0:.2f} MB/s, write: {0:.2f} MB/s'.format(
self.read_speed, self.write_speed)
class BenchmarkWithRate(Benchmark):
@ -628,7 +629,7 @@ class BenchmarkWithRate(Benchmark):
rate = Column(Float, nullable=False)
def __str__(self) -> str:
return '{} points'.format(self.rate)
return '{0:.2f} points'.format(self.rate)
class BenchmarkProcessor(BenchmarkWithRate):
@ -1022,7 +1023,10 @@ class Rate(JoinedWithOneDeviceMixin, ActionWithOneDevice):
return args
def __str__(self) -> str:
return '{} (v.{})'.format(self.rating_range, self.version)
if self.version:
return '{} (v.{})'.format(self.rating_range, self.version)
return '{}'.format(self.rating_range)
@classmethod
def compute(cls, device) -> 'RateComputer':

View File

@ -195,6 +195,33 @@ class Device(Thing):
and not getattr(c, 'foreign_keys', None)
and c.key not in self._NON_PHYSICAL_PROPS}
@property
def public_properties(self) -> Dict[str, object or None]:
"""Fields that describe the properties of a device than next show
in the public page.
:return A dictionary:
- Column.
- Actual value of the column or None.
"""
non_public = ['amount', 'transfer_state', 'receiver_id']
hide_properties = list(self._NON_PHYSICAL_PROPS) + non_public
return {c.key: getattr(self, c.key, None)
for c in inspect(self.__class__).attrs
if isinstance(c, ColumnProperty)
and not getattr(c, 'foreign_keys', None)
and c.key not in hide_properties}
@property
def public_actions(self) -> List[object]:
"""Actions than we want show in public page as traceability log section
:return a list of actions:
"""
hide_actions = ['Price']
actions = [ac for ac in self.actions if not ac.t in hide_actions]
actions.reverse()
return actions
@property
def url(self) -> urlutils.URL:
"""The URL where to GET this device."""

View File

@ -51,8 +51,8 @@
</div>
<div class="col-md-6">
<ul>
{% for key, value in device.physical_properties.items() %}
<li>{{ key }}: {{ value }}
{% for key, value in device.public_properties.items() %}
<li>{{ key }}: {{ value }}</li>
{% endfor %}
</ul>
{% if isinstance(device, d.Computer) %}
@ -151,26 +151,6 @@
</td>
</tr>
{% endif %}
{% if device.rate and device.rate.price %}
<tr class="active">
<td class="text-right">
Algorithm price
</td>
<td>
{{ device.rate.price }}
</td>
</tr>
{% endif %}
{% if device.price %}
<tr class="active">
<td class="text-right">
Actual price
</td>
<td>
{{ device.price }}
</td>
</tr>
{% endif %}
</tbody>
</table>
</div>
@ -179,7 +159,7 @@
<small>Latest one.</small>
</div>
<ol>
{% for action in device.actions|reverse %}
{% for action in device.public_actions %}
<li>
<strong>
{{ action.type }}