Skip to content

Commit

Permalink
use latest api results
Browse files Browse the repository at this point in the history
  • Loading branch information
roaldchristesen committed Oct 4, 2023
1 parent 6f11733 commit 8b05147
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
30 changes: 15 additions & 15 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class App extends Controller {
updateView() {
this.setProperties('text-distict-details', { 'html': `<h1>Stadtteil: <strong>${this.model.districtName()}</strong></h1>` })

const residentsInDestrict = this.model.districtData.valueByPath(['district_detail', '2021', 'residents'])
const residentsInDestrict = this.model.districtData.valueByPath(['residents'])
const residentsTotal = this.model.residentsTotal()
const percent = residentsInDestrict / residentsTotal * 100 // TODO

Expand All @@ -49,14 +49,14 @@ export default class App extends Controller {

updateViewAgeSection() {
const items = [
{ 'id': 'age-view-1', 'path': ['district_detail', '2021', 'age_groups', 'age_to_under_18'] },
{ 'id': 'age-view-2', 'path': ['district_detail', '2021', 'age_groups', 'age_18_to_under_30'] },
{ 'id': 'age-view-3', 'path': ['district_detail', '2021', 'age_groups', 'age_30_to_under_45'] },
{ 'id': 'age-view-4', 'path': ['district_detail', '2021', 'age_groups', 'age_45_to_under_65'] },
{ 'id': 'age-view-5', 'path': ['district_detail', '2021', 'age_groups', 'age_65_to_under_80'] },
{ 'id': 'age-view-6', 'path': ['district_detail', '2021', 'age_groups', 'age_80_and_above'] },
{ 'id': 'age-view-7', 'path': ['district_detail', '2021', 'age_groups', 'age_0_to_under_7'] },
{ 'id': 'age-view-8', 'path': ['district_detail', '2021', 'age_groups', 'age_60_and_above'] }
{ 'id': 'age-view-1', 'path': ['age_groups', 'age_to_under_18'] },
{ 'id': 'age-view-2', 'path': ['age_groups', 'age_18_to_under_30'] },
{ 'id': 'age-view-3', 'path': ['age_groups', 'age_30_to_under_45'] },
{ 'id': 'age-view-4', 'path': ['age_groups', 'age_45_to_under_65'] },
{ 'id': 'age-view-5', 'path': ['age_groups', 'age_65_to_under_80'] },
{ 'id': 'age-view-6', 'path': ['age_groups', 'age_80_and_above'] },
{ 'id': 'age-view-7', 'path': ['age_groups', 'age_0_to_under_7'] },
{ 'id': 'age-view-8', 'path': ['age_groups', 'age_60_and_above'] }
]

let sum = 0
Expand All @@ -81,9 +81,9 @@ export default class App extends Controller {

updateViewAgeSection2() {
const items = [
{ 'id': 'residents-0-18', 'path': ['district_detail', '2021', 'age_groups', 'age_to_under_18'] },
{ 'id': 'residents-18-65', 'path': ['district_detail', '2021', 'age_groups', 'age_18_to_under_65'] },
{ 'id': 'residents-65-above', 'path': ['district_detail', '2021', 'age_groups', 'age_65_and_above'] }
{ 'id': 'residents-0-18', 'path': ['age_groups', 'age_to_under_18'] },
{ 'id': 'residents-18-65', 'path': ['age_groups', 'age_18_to_under_65'] },
{ 'id': 'residents-65-above', 'path': ['age_groups', 'age_65_and_above'] }
]

let sum = 0
Expand All @@ -107,15 +107,15 @@ export default class App extends Controller {
}

updateSectionBirths() {
const births = this.model.districtData.valueByPath(['district_detail', '2021', 'births'])
const births = this.model.districtData.valueByPath(['births'])
const birthsTotal = this.model.birthsTotal()
const percent = births / birthsTotal * 100
const birthRate = this.model.districtData.valueByPath(['birth_rate'])

this.setProperties('births', { 'value': this.formatNumber(births) })
this.setProperties('births-percent', { 'value': this.formatNumber(percent) })
this.setProperties('births-total', { 'value': this.formatNumber(birthsTotal) })
this.setProperties('births-rate', { 'value': this.formatNumber(0) }) // TODO: Use the correct value from data

this.setProperties('births-rate', { 'value': this.formatNumber(birthRate) })

const c = this.componentById('births-chart')
c.setProperties({ 'values': this.model.birthsInDistrictsArray() })
Expand Down
17 changes: 5 additions & 12 deletions src/appModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,19 @@ export default class AppModel extends Model {
/**
* Get number of residents total for a specific year.
*/
residentsTotal(year) {
residentsTotal(...params) {
// TODO: Use year
// TODO: Check! Get value from data?
const values = this.residentsInDistrictsArray()
let sum = 0

values.forEach((v) => {
sum += v
})

return sum
return this.data.data.summary.sum_residents
}

residentsInDistrictsArray(year) {
residentsInDistrictsArray(...params) {
// TODO: Use year
// TODO: Check!
return this.data.data.detail.map((item) => item.residents)
}

birthsTotal(year) {
birthsTotal(...params) {
// TODO: Use year
// TODO: Check! Get value from data?
const values = this.birthsInDistrictsArray()
Expand All @@ -82,7 +75,7 @@ export default class AppModel extends Model {
return sum
}

birthsInDistrictsArray(year) {
birthsInDistrictsArray(...params) {
// TODO: Use year
// TODO: Check!
return this.data.data.detail.map((item) => item.births)
Expand Down

0 comments on commit 8b05147

Please sign in to comment.