Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: fix for NaN displayed instead of real average price on details page #26

Merged
merged 1 commit into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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