diff --git a/backend/db.py b/backend/db.py index c99ad67..3526265 100644 --- a/backend/db.py +++ b/backend/db.py @@ -146,6 +146,9 @@ def get_offers_dict(limit=None, offset=None, aircraft_type=None): offers = session.query(AircraftOffer).order_by(AircraftOffer.date.desc()) if aircraft_type is not None: offers = offers.filter(AircraftOffer.aircraft_type == aircraft_type) + else: + offers = offers.filter(AircraftOffer.aircraft_type is not None) + if limit is not None: offers = offers.limit(limit) if offset is not None: diff --git a/ui/src/views/OfferDetails.vue b/ui/src/views/OfferDetails.vue index 3b81273..3dd7418 100644 --- a/ui/src/views/OfferDetails.vue +++ b/ui/src/views/OfferDetails.vue @@ -12,7 +12,7 @@

Offers

-

There were {{ offers.length }} offer(s) for this Model. The average offer price is {{ medianPrice }} Euro.

+

There were {{ offers.length }} offer(s). The average offer price is {{ avgPrice }} €.

@@ -64,7 +64,7 @@ export default { return { manufacturer_website: '', offers: [], - medianPrice: 0, + avgPrice: 0, chartData: { series: [[]] }, @@ -98,6 +98,8 @@ export default { fetchData() { this.chartData.series = [[]] + this.avgPrice = 0 + axios.get(`/api/offers/${this.manufacturer}/${this.model}`).then((response) => { this.manufacturer_website = response.data.manufacturer_website this.offers = response.data.offers @@ -105,9 +107,12 @@ export default { return } + let priceSum = 0 for (let i = 0; i < this.offers.length; i += 1) { const offer = this.offers[i] - this.medianPrice += offer.price_in_euro + if (!isNaN(offer.price_in_euro)) { + priceSum += Number(offer.price_in_euro) + } const datapoint = { meta: offer.title, @@ -139,7 +144,7 @@ export default { }) ] } - this.medianPrice = Math.round((this.medianPrice / this.offers.length) * 100) / 100 + this.avgPrice = Math.round((priceSum / this.offers.length) * 100) / 100 }) } }
Date