Skip to content

Commit

Permalink
Adding headlines
Browse files Browse the repository at this point in the history
  • Loading branch information
jnsprnw committed Aug 19, 2020
1 parent 7f4aa92 commit 8decac8
Showing 1 changed file with 37 additions and 18 deletions.
55 changes: 37 additions & 18 deletions data/Investment Opportunities and Alignment.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,17 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Summing up values\n",
"## Prepare functions\n",
"\n",
"### Summing up values\n",
"\n",
"Each year has it own column in the source data and we want to sum it up as one value.\n",
"Additionally, we need to parse the value and convert it from German notation to English."
]
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 16,
"metadata": {},
"outputs": [
{
Expand All @@ -355,7 +357,7 @@
"(2015, 2020, 2025, 2030, 2035, 2040, 2045, 2050, 2055, 2060, 2065, 2070, 2075, 2080, 2085, 2090, 2095, 2100)"
]
},
"execution_count": 8,
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -373,9 +375,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"sumYears (generic function with 1 method)"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function sumYears(row)\n",
" sum = 0\n",
Expand All @@ -392,7 +405,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## GetValues\n",
"### GetValues\n",
"This function finds the rows in the DataFrame, gets every value and calculates the average.\n",
"\n",
"First, we create an empty Dictionary with `Strings` as keys and `Float64` as numbers.\n",
Expand All @@ -404,7 +417,7 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": 10,
"metadata": {},
"outputs": [
{
Expand All @@ -413,7 +426,7 @@
"getValues (generic function with 1 method)"
]
},
"execution_count": 32,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -444,7 +457,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 11,
"metadata": {},
"outputs": [
{
Expand All @@ -453,7 +466,7 @@
"findRow (generic function with 1 method)"
]
},
"execution_count": 17,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -468,13 +481,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Calculating the change\n",
"\n",
"Function to calculate the change between two values.\n",
"We calculate the absolute change and if its positive or negative. This makes it easier to process later."
]
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 12,
"metadata": {},
"outputs": [
{
Expand All @@ -483,14 +498,14 @@
"calcChange (generic function with 1 method)"
]
},
"execution_count": 18,
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function calcChange(reference, value)\n",
" change = abs(reference - value) / max(reference, value)\n",
" change = round(abs(reference - value) / max(reference, value), digits=3)\n",
" isPositive = reference > value\n",
" return (change, isPositive)\n",
"end"
Expand All @@ -505,7 +520,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 13,
"metadata": {},
"outputs": [
{
Expand All @@ -514,7 +529,7 @@
"calcChanges (generic function with 1 method)"
]
},
"execution_count": 19,
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -534,12 +549,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Build the final data set\n",
"\n",
"Finally, we loop over all scenarios, variables and regions and calculate everything."
]
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -561,16 +578,18 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Export the dataset\n",
"\n",
"`JSON.json` takes two arguments: a Dict and the indent."
]
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"open(\"investments-1.1.json\", \"w\") do io\n",
"open(\"investments-1.2.json\", \"w\") do io\n",
" write(io, JSON.json(runs, 2));\n",
"end;"
]
Expand Down

0 comments on commit 8decac8

Please sign in to comment.