Change ranking of country

Location of ranking data is : src/assets/ranking

Changing data is very simple, first, let's take a look at the structure:

{
    "data": [
        {
            "country": "Country Name",
            "value": "Value",
            "unit": "Unit" (may or may not be present)
        }
    ],
    "unit": [
        {
            "name": "Unit Name",
            "position": "before - middle - after",
            "value": "Unit value"
        }
    ]
}

How did the system rank?

The first element in the unit array is the default data, the following elements must be based on the value of the first element to calculate the value of the element.

Example:

We can see that the first element has the value 1 and the following elements are based on the value of the first element )trillion = 1000 billion = 1000000 million).

Formula:

rank.value = rank.value * unit[0].value / unit[rank.unit].value

This formula calculates the value of different units into one unit for sorting.

Example, we have data:

"data":
  [
    {
      "country":"United States Minor Outlying Islands",
      "value":14.3,
      "unit":0
    },
    {
      "country":"China",
      "value":7.8,
      "unit":0
    },
    {
      "country":"Vietnam",
      "value":241.8,
      "unit":1
    },
    {
      "country":"Saint Helena",
      "value":18,
      "unit":2
    }
  ]

and unit:

"unit":[
    {
      "name":"$ %s trillion",
      "position":"middle",
      "value": 1
    },
    {
      "name":"$ %s billion",
      "position":"middle",
      "value": 1000
    },
    {
      "name":"$ %s million",
      "position":"middle",
      "value": 1000000
    }
  ]

When processing is complete, all data will become:

"data":
    [
        {
            "country":"United States Minor Outlying Islands",
            "value":14.3,
            "unit":0
        },
        {
            "country":"China",
            "value":7.8,
            "unit":0
        },
        {
            "country":"Vietnam",
            "value":0.2418,
            "unit":1
        },
        {
          "country":"Saint Helena",
          "value":0.000018,
          "unit": 2
        }
    ]

All data has been converted to unit "trillion", the default unit.

Let's take a look at the two properties are "name" and "position", how it works?

This is very simple, value will be associated with the given position, there are 3 values of that position: before, middle, after

With "before" position, value will be set before the name, with "after" position, value will be set before the name, example:

value: 5
name: "abcxyz"

postion: "before"
=> "5 abcxyz"

postion: "after"
=> "abcxyz 5"

With "middle" position, The value will be filled in "%s" in the name, example:

value: 5
name: "$ %s trillion dollars"
postion: "middle"

=> "$ 5 trillion dollars"

results matching ""

    No results matching ""