Compare commits
	
		
			3 commits
		
	
	
		
			f04aaf12a2
			...
			9bdf21ea5b
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
							
							
								
									
								
								 | 
						9bdf21ea5b | ||
| 
							
							
								
									
								
								 | 
						63c7c54bfc | ||
| 
							
							
								
									
								
								 | 
						a66565a785 | 
| 
						 | 
				
			
			@ -204,6 +204,10 @@ class Trip:
 | 
			
		|||
            else None
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def total_co2_kg(self) -> float | None:
 | 
			
		||||
        """Total CO₂ for trip."""
 | 
			
		||||
        return sum(float(t.get("co2_kg", 0)) for t in self.travel)
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def flights(self) -> list[StrDict]:
 | 
			
		||||
        """Flights."""
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -113,7 +113,7 @@
 | 
			
		|||
      {% endif %}
 | 
			
		||||
    {% endif %}
 | 
			
		||||
  </div>
 | 
			
		||||
  {% for i in range(8) %}
 | 
			
		||||
  {% for i in range(9) %}
 | 
			
		||||
    <div class="grid-item"></div>
 | 
			
		||||
  {% endfor %}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -143,6 +143,7 @@
 | 
			
		|||
        {{ "{:,.0f} km / {:,.0f} miles".format(item.distance, item.distance / 1.60934) }}
 | 
			
		||||
      {% endif %}
 | 
			
		||||
    </div>
 | 
			
		||||
    <div class="grid-item text-end">{{ "{:,.1f}".format(item.co2_kg) }} kg</div>
 | 
			
		||||
  {% endfor %}
 | 
			
		||||
{% endmacro %}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -306,6 +307,7 @@
 | 
			
		|||
{% macro trip_item(trip) %}
 | 
			
		||||
  {% set distances_by_transport_type = trip.distances_by_transport_type() %}
 | 
			
		||||
  {% set total_distance = trip.total_distance() %}
 | 
			
		||||
  {% set total_co2_kg = trip.total_co2_kg() %}
 | 
			
		||||
  {% set end = trip.end %}
 | 
			
		||||
  <div class="border border-2 rounded mb-2 p-2">
 | 
			
		||||
    <h3>
 | 
			
		||||
| 
						 | 
				
			
			@ -335,6 +337,7 @@
 | 
			
		|||
      </div>
 | 
			
		||||
    {% endif %}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    {% if distances_by_transport_type %}
 | 
			
		||||
      {% for transport_type, distance in distances_by_transport_type %}
 | 
			
		||||
        <div>
 | 
			
		||||
| 
						 | 
				
			
			@ -344,6 +347,10 @@
 | 
			
		|||
      {% endfor %}
 | 
			
		||||
    {% endif %}
 | 
			
		||||
 | 
			
		||||
    {% if total_co2_kg %}
 | 
			
		||||
      <div>Total CO₂: {{ "{:,.1f}".format(total_co2_kg) }} kg</div>
 | 
			
		||||
    {% endif %}
 | 
			
		||||
 | 
			
		||||
    {{ conference_list(trip) }}
 | 
			
		||||
 | 
			
		||||
    {% for day, elements in trip.elements_grouped_by_day() %}
 | 
			
		||||
| 
						 | 
				
			
			@ -381,6 +388,7 @@
 | 
			
		|||
                  <span class="text-nowrap"><strong>duration:</strong> {{ e.detail.duration }}</span>
 | 
			
		||||
                {% endif %}
 | 
			
		||||
                {# <pre>{{ e.detail | pprint }}</pre> #}
 | 
			
		||||
      <span class="text-nowrap"><strong>CO₂:</strong> {{ "{:,.1f}".format(e.detail.co2_kg) }} kg</span>
 | 
			
		||||
              {% endif %}
 | 
			
		||||
              {% if e.detail.distance %}
 | 
			
		||||
                <span class="text-nowrap"><strong>distance:</strong> {{ format_distance(e.detail.distance) }}</span>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,7 +3,7 @@
 | 
			
		|||
 | 
			
		||||
{% block title %}Travel - Edward Betts{% endblock %}
 | 
			
		||||
 | 
			
		||||
{% set flight_column_count = 10 %}
 | 
			
		||||
{% set flight_column_count = 11 %}
 | 
			
		||||
{% set column_count = 10 %}
 | 
			
		||||
 | 
			
		||||
{% block style %}
 | 
			
		||||
| 
						 | 
				
			
			@ -47,6 +47,7 @@
 | 
			
		|||
      <div class="grid-item">flight</div>
 | 
			
		||||
      <div class="grid-item">tracking</div>
 | 
			
		||||
      <div class="grid-item">distance</div>
 | 
			
		||||
      <div class="grid-item">CO₂ (kg)</div>
 | 
			
		||||
 | 
			
		||||
    {% for item in flights %}
 | 
			
		||||
      {{ flight_booking_row(item) }}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -62,6 +62,7 @@
 | 
			
		|||
        distance: {{format_distance(distance) }}
 | 
			
		||||
      </div>
 | 
			
		||||
    {% endfor %}
 | 
			
		||||
    <div>Total CO₂: {{ "{:,.1f}".format(total_co2_kg / 1000.0) }} tonnes</div>
 | 
			
		||||
 | 
			
		||||
    {% for trip in items %}
 | 
			
		||||
      {{ trip_item(trip) }}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,7 +8,7 @@ import typing
 | 
			
		|||
from datetime import date, datetime
 | 
			
		||||
from time import time
 | 
			
		||||
 | 
			
		||||
import deepdiff  # type: ignore
 | 
			
		||||
import deepdiff
 | 
			
		||||
import flask
 | 
			
		||||
import requests
 | 
			
		||||
import yaml
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										10
									
								
								web_view.py
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								web_view.py
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -404,13 +404,17 @@ def calc_total_distance(trips: list[Trip]) -> float:
 | 
			
		|||
    """Total distance for trips."""
 | 
			
		||||
    total = 0.0
 | 
			
		||||
    for item in trips:
 | 
			
		||||
        dist = item.total_distance()
 | 
			
		||||
        if dist:
 | 
			
		||||
        if dist := item.total_distance():
 | 
			
		||||
            total += dist
 | 
			
		||||
 | 
			
		||||
    return total
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def calc_total_co2_kg(trips: list[Trip]) -> float:
 | 
			
		||||
    """Total CO₂ for trips."""
 | 
			
		||||
    return sum(item.total_co2_kg() for item in trips)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def sum_distances_by_transport_type(trips: list[Trip]) -> list[tuple[str, float]]:
 | 
			
		||||
    """Sum distances by transport type."""
 | 
			
		||||
    distances_by_transport_type: defaultdict[str, float] = defaultdict(float)
 | 
			
		||||
| 
						 | 
				
			
			@ -443,6 +447,7 @@ def trip_past_list() -> str:
 | 
			
		|||
        format_list_with_ampersand=format_list_with_ampersand,
 | 
			
		||||
        fx_rate=agenda.fx.get_rates(app.config),
 | 
			
		||||
        total_distance=calc_total_distance(past),
 | 
			
		||||
        total_co2_kg=calc_total_co2_kg(past),
 | 
			
		||||
        distances_by_transport_type=sum_distances_by_transport_type(past),
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -475,6 +480,7 @@ def trip_future_list() -> str:
 | 
			
		|||
        format_list_with_ampersand=format_list_with_ampersand,
 | 
			
		||||
        fx_rate=agenda.fx.get_rates(app.config),
 | 
			
		||||
        total_distance=calc_total_distance(current + future),
 | 
			
		||||
        total_co2_kg=calc_total_co2_kg(current + future),
 | 
			
		||||
        distances_by_transport_type=sum_distances_by_transport_type(current + future),
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue