Ejemplo n.º 1
0
 def test_format_length(self):
     self.assertEqual('0 metres', humanfriendly.format_length(0))
     self.assertEqual('1 metre', humanfriendly.format_length(1))
     self.assertEqual('42 metres', humanfriendly.format_length(42))
     self.assertEqual('1 km', humanfriendly.format_length(1 * 1000))
     self.assertEqual('15.3 cm', humanfriendly.format_length(0.153))
     self.assertEqual('1 cm', humanfriendly.format_length(1e-02))
     self.assertEqual('1 mm', humanfriendly.format_length(1e-03))
     self.assertEqual('1 nm', humanfriendly.format_length(1e-09))
Ejemplo n.º 2
0
 def test_format_length(self):
     """Test :func:`humanfriendly.format_length()`."""
     self.assertEqual('0 metres', humanfriendly.format_length(0))
     self.assertEqual('1 metre', humanfriendly.format_length(1))
     self.assertEqual('42 metres', humanfriendly.format_length(42))
     self.assertEqual('1 km', humanfriendly.format_length(1 * 1000))
     self.assertEqual('15.3 cm', humanfriendly.format_length(0.153))
     self.assertEqual('1 cm', humanfriendly.format_length(1e-02))
     self.assertEqual('1 mm', humanfriendly.format_length(1e-03))
     self.assertEqual('1 nm', humanfriendly.format_length(1e-09))
Ejemplo n.º 3
0
    def list_files(self):
        port = self.plugin.get_port()
        baseurl = self.plugin.get_settings().get(["baseurl"])
        if baseurl is None or baseurl == "":
            baseurl = "%s:%s" % (self.plugin.get_ip_address(), port)

        builder = EmbedBuilder()
        builder.set_title('Files and Details')
        builder.set_author(name=self.plugin.get_printer_name())
        file_list = self.get_flat_file_list()
        for details in file_list:
            description = ''
            title = ''
            try:
                title = details['path'].lstrip('/')
            except:
                pass

            try:
                description += 'Location: %s\n' % details['location']
            except:
                pass

            try:
                estimated_print_time = humanfriendly.format_timespan(
                    details['analysis']['estimatedPrintTime'], max_units=2)
                description += 'Estimated Print Time: %s\n' % estimated_print_time
            except:
                pass

            try:
                average_print_time = humanfriendly.format_timespan(
                    details['statistics']['averagePrintTime']['_default'],
                    max_units=2)
                description += 'Average Print Time: %s\n' % average_print_time
            except:
                pass

            try:
                filament_required = humanfriendly.format_length(
                    details['analysis']['filament']['tool0']['length'] / 1000)
                description += 'Filament Required: %s\n' % filament_required
            except:
                pass

            try:
                url = "http://" + baseurl + "/downloads/files/" + details[
                    'location'] + "/" + details['path'].lstrip('/')
                description += 'Download Path: %s\n' % url
            except:
                pass

            builder.add_field(title=title, text=description)

        return None, builder.get_embeds()
Ejemplo n.º 4
0
    def get_context_data(self, **kwargs):
        self.object: Trip
        context = super().get_context_data(**kwargs)

        #map_coords = []
        #for loc in self.object.localisations.all():
        #    map_coords.append({"lat": loc.latitude, "lng": loc.longitude})

        #context['map_coords'] = json.dumps(map_coords)
        gpx = render_trip_to_gpxpy_object(self.get_object())
        denivele = gpx.get_uphill_downhill()

        elevations = list(
            map(
                lambda point:
                [point.time.timestamp(),
                 round(point.elevation, 2)], gpx.tracks[0].segments[0].points))
        duration = gpx.get_duration()
        duration = max(duration if duration else 1, 1)
        length_2d = gpx.length_2d()
        length_3d = gpx.length_3d()
        # context['gpx_object'] = gpx
        statistics = {
            "length_2d": humanfriendly.format_length(length_2d),  # Metres
            "length_3d": humanfriendly.format_length(length_3d),  # Metres
            "uphill": humanfriendly.format_length(denivele.uphill),  # Metres
            "downhill":
            humanfriendly.format_length(denivele.downhill),  # Metres
            "altitude_over_time": json.dumps(elevations,
                                             cls=DjangoJSONEncoder),
            "duration": humanfriendly.format_timespan(duration),  # Minutes
            "speed": int(length_2d / duration * (60 * 60 / 1000)),  # km/h
        }

        context['statistics'] = statistics

        return context
Ejemplo n.º 5
0
def print_formatted_length(value):
    """Print a human readable length."""
    if '.' in value:
        output(format_length(float(value)))
    else:
        output(format_length(int(value)))
Ejemplo n.º 6
0
def print_formatted_length(value):
    """Print a human readable length."""
    if '.' in value:
        print(format_length(float(value)))
    else:
        print(format_length(int(value)))
Ejemplo n.º 7
0
Archivo: view.py Proyecto: leinardi/gst
def format_length(value: Optional[float]) -> Optional[str]:
    return humanfriendly.format_length(value) if value else None