Skip to content

Commit

Permalink
UI: fix for NaN displayed instead of real average price on details page
Browse files Browse the repository at this point in the history
  • Loading branch information
lwitkowski committed Aug 4, 2024
1 parent 188e76a commit ca6afe8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions backend/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 9 additions & 4 deletions ui/src/views/OfferDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<chartist type="Line" ratio=".ct-chart" :data="chartData" :options="chartOptions" />
</div>
<h2>Offers</h2>
<p>There were {{ offers.length }} offer(s) for this Model. The average offer price is {{ medianPrice }} Euro.</p>
<p>There were {{ offers.length }} offer(s). The average offer price is {{ avgPrice }} .</p>
<table class="modelinformation-table">
<tr>
<th>Date</th>
Expand Down Expand Up @@ -64,7 +64,7 @@ export default {
return {
manufacturer_website: '',
offers: [],
medianPrice: 0,
avgPrice: 0,
chartData: {
series: [[]]
},
Expand Down Expand Up @@ -98,16 +98,21 @@ 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
if (this.offers.length === 0) {
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,
Expand Down Expand Up @@ -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
})
}
}
Expand Down

0 comments on commit ca6afe8

Please sign in to comment.