Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Jan 15, 2024
1 parent 1d8731c commit 98c3f4b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 75 deletions.
45 changes: 45 additions & 0 deletions src/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,49 @@ export default {
.then((response) => response.json())
.then((data) => data.filter(l => !NOMINATIM_RESULT_TYPE_EXCLUDE_LIST.includes(l.type)))
},

updateStats() {
const store = useAppStore()
this.loading = true
// TODO: use Promise
// price stats
this.getPrices({ size: 1 })
.then((data) => {
store.price_total = data.total
})
this.getPrices({ product_id__isnull: true, size: 1 })
.then((data) => {
store.price_without_product_total = data.total
})
// product stats
this.getProducts({ size: 1 })
.then((data) => {
store.product_total = data.total
})
this.getProducts({ price_count__gte: 1, size: 1 })
.then((data) => {
store.product_with_price_total = data.total
})
// location stats
this.getLocations({ size: 1 })
.then((data) => {
store.location_total = data.total
})
this.getLocations({ price_count__gte: 1, size: 1 })
.then((data) => {
store.location_with_price_total = data.total
})
// user stats
this.getUsers({ size: 1 })
.then((data) => {
store.user_total = data.total
})
this.getUsers({ price_count__gte: 1, size: 1 })
.then((data) => {
store.user_with_price_total = data.total
})
// update last_updated
this.last_updated = new Date()
this.loading = false
}
}
11 changes: 11 additions & 0 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ export const useAppStore = defineStore('app', {
last_currency_used: 'EUR', // TODO: init with user locale ?
recent_locations: [],
},
stats: {
price_total: null,
price_without_product_total: null,
product_total: null,
product_with_price_total: null,
location_total: null,
location_with_price_total: null,
user_total: null,
user_with_price_total: null,
last_updated: null
}
}),
getters: {
getRecentLocations: (state) => {
Expand Down
84 changes: 9 additions & 75 deletions src/views/Stats.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</p>
<p>
Without a product <v-chip label size="small" density="comfortable" class="mr-1">category</v-chip>
<strong>{{ priceWithoutProduct }}</strong>
<strong>{{ priceWithoutProductTotal }}</strong>
</p>
</v-card-text>
</v-card>
Expand Down Expand Up @@ -72,14 +72,16 @@
</template>

<script>
import { mapStores } from 'pinia'
import { useAppStore } from '../store'
import api from '../services/api'
export default {
data() {
return {
priceTotal: null,
// priceWithProduct: null,
priceWithoutProduct: null,
priceWithoutProductTotal: null,
productTotal: null,
productWithPriceTotal: null,
locationTotal: null,
Expand All @@ -90,85 +92,17 @@ export default {
}
},
computed: {
...mapStores(useAppStore),
priceWithProduct() {
return this.priceTotal - this.priceWithoutProduct
return this.priceTotal - this.priceWithoutProductTotal
}
},
mounted() {
this.getPrices()
this.getPricesWithProduct()
this.getProducts()
this.getProductsWithPrice()
this.getLocations()
this.getLocationsWithPrice()
this.getUsers()
this.getUsersWithPrice()
if (!this.appStore.stats.last_updated) {
api.updateStats()
}
},
methods: {
getPrices() {
this.loading = true
return api.getPrices({ size: 1 })
.then((data) => {
this.priceTotal = data.total
this.loading = false
})
},
getPricesWithProduct() {
this.loading = true
return api.getPrices({ product_id__isnull: true, size: 1 })
.then((data) => {
this.priceWithoutProduct = data.total
this.loading = false
})
},
getProducts() {
this.loading = true
return api.getProducts({ size: 1 })
.then((data) => {
this.productTotal = data.total
this.loading = false
})
},
getProductsWithPrice() {
this.loading = true
return api.getProducts({ price_count__gte: 1, size: 1 })
.then((data) => {
this.productWithPriceTotal = data.total
this.loading = false
})
},
getLocations() {
this.loading = true
return api.getLocations({ size: 1 })
.then((data) => {
this.locationTotal = data.total
this.loading = false
})
},
getLocationsWithPrice() {
this.loading = true
return api.getLocations({ price_count__gte: 1,size: 1 })
.then((data) => {
this.locationWithPriceTotal = data.total
this.loading = false
})
},
getUsers() {
this.loading = true
return api.getUsers({ size: 1 })
.then((data) => {
this.userTotal = data.total
this.loading = false
})
},
getUsersWithPrice() {
this.loading = true
return api.getUsers({ price_count__gte: 1, size: 1 })
.then((data) => {
this.userWithPriceTotal = data.total
this.loading = false
})
}
}
}
</script>

0 comments on commit 98c3f4b

Please sign in to comment.