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) write_speed = Column(Float(decimal_return_scale=2), nullable=False)
def __str__(self) -> str: 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): class BenchmarkWithRate(Benchmark):
@ -628,7 +629,7 @@ class BenchmarkWithRate(Benchmark):
rate = Column(Float, nullable=False) rate = Column(Float, nullable=False)
def __str__(self) -> str: def __str__(self) -> str:
return '{} points'.format(self.rate) return '{0:.2f} points'.format(self.rate)
class BenchmarkProcessor(BenchmarkWithRate): class BenchmarkProcessor(BenchmarkWithRate):
@ -1022,8 +1023,11 @@ class Rate(JoinedWithOneDeviceMixin, ActionWithOneDevice):
return args return args
def __str__(self) -> str: def __str__(self) -> str:
if self.version:
return '{} (v.{})'.format(self.rating_range, self.version) return '{} (v.{})'.format(self.rating_range, self.version)
return '{}'.format(self.rating_range)
@classmethod @classmethod
def compute(cls, device) -> 'RateComputer': def compute(cls, device) -> 'RateComputer':
raise NotImplementedError() raise NotImplementedError()

View File

@ -195,6 +195,33 @@ class Device(Thing):
and not getattr(c, 'foreign_keys', None) and not getattr(c, 'foreign_keys', None)
and c.key not in self._NON_PHYSICAL_PROPS} 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 @property
def url(self) -> urlutils.URL: def url(self) -> urlutils.URL:
"""The URL where to GET this device.""" """The URL where to GET this device."""

View File

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