summaryrefslogtreecommitdiff
path: root/frontend/site/projects/museum/views/counter.js
blob: f930b85a8968f23ae0411db6469cacd69c5faa7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import React, { Component, createRef } from 'react'

import "./counter.css"

export default class Counter extends Component {
  constructor(props) {
    super(props)
    this.ref = createRef()
    this.update = this.update.bind(this)
  }

  componentDidMount() {
    this.update()
  }

  componentWillUnmount() {
    clearTimeout(this.timeout)
  }

  update() {
    this.timeout = setTimeout(this.update, 250)
    const population = getPopulation()
    if (this.ref.current) {
      this.ref.current.innerHTML = commatize(population)
    }
  }

  render() {
    return (
      <div className="counter">
        <div className="countValue" ref={this.ref} />
        <div className="description">
          CURRENT GLOBAL POPULATION
        </div>
      </div>
    )
  }
}

const aprilFirst = new Date(2021, 3, 1)

function getPopulation() {
  const popAprilFirst = 7855013899
  const popChangePerDay = 219251.934066
  const secondsDelta = (new Date() - aprilFirst) / 86400000  // april = month 3
  const population = popAprilFirst + secondsDelta * popChangePerDay
  return Math.round(population)
}

const commatize = (n, radix) => {
  radix = radix || -1
  var nums = [], i, counter = 0, r = Math.floor
  if (radix !== -1 && n > radix) {
    n /= radix
    nums.unshift(r((n * 10) % 10))
    nums.unshift(".")
  }
  do {
    i = r(n % 10)
    n = r(n / 10)
    counter += 1
    if (n && ! (counter % 3))
      { i = ',' + r(i) }
    nums.unshift(i)
  }
  while (n)
  return nums.join("")
}

const JAKRAWAL_TEXTS = [
  "Wildfires occur frequently during the dry season in northern Thailand’s high mountains. The source of fire is not natural but arson.",
  "In the past it was hypothesized that local people set the fires to clear land for agricultural use, or for hunting.",
  "There were efforts to solve the problem at the community level, but the fires only became more severe.",
  "Strangely, the blazes often occurred in the national park—an area difficult for villagers to access.",
  "During the wildfire suppression efforts of May 2020, a group of scholars and volunteers discovered important evidence that would change the original hypothesis: They found several instances of improvised devices made of clothes pegs connected to a small battery by a power cable.",
  "Combustion was triggered by a small clod of clay positioned in the middle between the pegs, acting as a timer—after melting in the heat the wires attached to the batteries would ignite.",
  "Villagers who were interviewed said that this was not a technique that they were familiar with.",
  "Although we cannot know the intention of the burners, it is likely that the park’s natural resources are being used to benefit some group of people. And the poor have always been condemned.",
]