We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Import intensity could fallback on yearly averages when missing/unknown
When a country, or area, is importing electricity from another country and the exporting country's production sources are unknown, it seems as if the intensity of the imported electricity is set to be equal to the intensity of the importing country. But this is hardly meaningful. Would it be possible to set the unknown intensity of imported electricity to an average or mean value from a historical period? E.g. the last month or the same month last year. Or to the last available dataset (depending on how old that is).

I can see that it happens quite often for Norway, that "Data [is] temporarily unavailable". The intensity of the electricity exported to Sweden is low, while it is medium high when exported to West Denmark.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `utils/config.py`
Content:
```
1 import json
2 import os
3 
4 def relative_path(script_reference_path, rel_path):
5     # __file__ should be passed as script_reference_path
6     script_path = os.path.abspath(
7         script_reference_path)  # i.e. /path/to/dir/foobar.py
8     script_dir = os.path.split(script_path)[0]  # i.e. /path/to/dir/
9     return os.path.join(script_dir, rel_path)
10 
11 
12 # Prepare zone bounding boxes
13 ZONE_BOUNDING_BOXES = {}
14 
15 # Read parser import list from config jsons
16 ZONES_CONFIG = json.load(open(relative_path(
17     __file__, '../config/zones.json')))
18 
19 # Read all zones
20 for zone_id, zone_config in ZONES_CONFIG.items():
21     if 'bounding_box' in zone_config:
22         ZONE_BOUNDING_BOXES[zone_id] = zone_config['bounding_box']
23 
24 # Read parser import list from config jsons
25 ZONES_CONFIG = json.load(open(relative_path(
26     __file__, '../config/zones.json')))
27 EXCHANGES_CONFIG = json.load(open(relative_path(
28     __file__, '../config/exchanges.json')))
29 ZONE_NEIGHBOURS = {}
30 for k, v in EXCHANGES_CONFIG.items():
31     zone_names = k.split('->')
32     pairs = [
33         (zone_names[0], zone_names[1]),
34         (zone_names[1], zone_names[0])
35     ]
36     for zone_name_1, zone_name_2 in pairs:
37         if zone_name_1 not in ZONE_NEIGHBOURS:
38             ZONE_NEIGHBOURS[zone_name_1] = set()
39         ZONE_NEIGHBOURS[zone_name_1].add(zone_name_2)
40 # we want neighbors to always be in the same order
41 for zone, neighbors in ZONE_NEIGHBOURS.items():
42     ZONE_NEIGHBOURS[zone] = sorted(neighbors)
43
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/utils/config.py b/utils/config.py
--- a/utils/config.py
+++ b/utils/config.py
@@ -40,3 +40,22 @@
 # we want neighbors to always be in the same order
 for zone, neighbors in ZONE_NEIGHBOURS.items():
     ZONE_NEIGHBOURS[zone] = sorted(neighbors)
+
+CO2EQ_PARAMETERS = json.load(open(relative_path(
+    __file__, '../config/co2eq_parameters.json')))
+
+def emission_factors(zone_key):
+    fallback_carbon_intensity = CO2EQ_PARAMETERS['fallbackZoneMixes'].get(zone_key, {}).get('carbonIntensity');
+    override = CO2EQ_PARAMETERS['emissionFactors']['zoneOverrides'].get(zone_key, {})
+    defaults = CO2EQ_PARAMETERS['emissionFactors']['defaults']
+    merged = {**defaults, **override}
+    if fallback_carbon_intensity:
+        merged['battery storage'] = {
+            'value': fallback_carbon_intensity,
+            'source': 'Annual carbon intensity'
+        }
+        merged['hydro storage'] = {
+            'value': fallback_carbon_intensity,
+            'source': 'Annual carbon intensity'
+        }
+    return dict([(k, (v or {}).get('value')) for (k, v) in merged.items()])

{"golden_diff": "diff --git a/utils/config.py b/utils/config.py\n--- a/utils/config.py\n+++ b/utils/config.py\n@@ -40,3 +40,22 @@\n # we want neighbors to always be in the same order\n for zone, neighbors in ZONE_NEIGHBOURS.items():\n     ZONE_NEIGHBOURS[zone] = sorted(neighbors)\n+\n+CO2EQ_PARAMETERS = json.load(open(relative_path(\n+    __file__, '../config/co2eq_parameters.json')))\n+\n+def emission_factors(zone_key):\n+    fallback_carbon_intensity = CO2EQ_PARAMETERS['fallbackZoneMixes'].get(zone_key, {}).get('carbonIntensity');\n+    override = CO2EQ_PARAMETERS['emissionFactors']['zoneOverrides'].get(zone_key, {})\n+    defaults = CO2EQ_PARAMETERS['emissionFactors']['defaults']\n+    merged = {**defaults, **override}\n+    if fallback_carbon_intensity:\n+        merged['battery storage'] = {\n+            'value': fallback_carbon_intensity,\n+            'source': 'Annual carbon intensity'\n+        }\n+        merged['hydro storage'] = {\n+            'value': fallback_carbon_intensity,\n+            'source': 'Annual carbon intensity'\n+        }\n+    return dict([(k, (v or {}).get('value')) for (k, v) in merged.items()])\n", "issue": "Import intensity could fallback on yearly averages when missing/unknown\nWhen a country, or area, is importing electricity from another country and the exporting country's production sources are unknown, it seems as if the intensity of the imported electricity is set to be equal to the intensity of the importing country. But this is hardly meaningful. Would it be possible to set the unknown intensity of imported electricity to an average or mean value from a historical period? E.g. the last month or the same month last year. Or to the last available dataset (depending on how old that is).\r\n\r\nI can see that it happens quite often for Norway, that \"Data [is] temporarily unavailable\". The intensity of the electricity exported to Sweden is low, while it is medium high when exported to West Denmark.\n", "before_files": [{"content": "import json\nimport os\n\ndef relative_path(script_reference_path, rel_path):\n    # __file__ should be passed as script_reference_path\n    script_path = os.path.abspath(\n        script_reference_path)  # i.e. /path/to/dir/foobar.py\n    script_dir = os.path.split(script_path)[0]  # i.e. /path/to/dir/\n    return os.path.join(script_dir, rel_path)\n\n\n# Prepare zone bounding boxes\nZONE_BOUNDING_BOXES = {}\n\n# Read parser import list from config jsons\nZONES_CONFIG = json.load(open(relative_path(\n    __file__, '../config/zones.json')))\n\n# Read all zones\nfor zone_id, zone_config in ZONES_CONFIG.items():\n    if 'bounding_box' in zone_config:\n        ZONE_BOUNDING_BOXES[zone_id] = zone_config['bounding_box']\n\n# Read parser import list from config jsons\nZONES_CONFIG = json.load(open(relative_path(\n    __file__, '../config/zones.json')))\nEXCHANGES_CONFIG = json.load(open(relative_path(\n    __file__, '../config/exchanges.json')))\nZONE_NEIGHBOURS = {}\nfor k, v in EXCHANGES_CONFIG.items():\n    zone_names = k.split('->')\n    pairs = [\n        (zone_names[0], zone_names[1]),\n        (zone_names[1], zone_names[0])\n    ]\n    for zone_name_1, zone_name_2 in pairs:\n        if zone_name_1 not in ZONE_NEIGHBOURS:\n            ZONE_NEIGHBOURS[zone_name_1] = set()\n        ZONE_NEIGHBOURS[zone_name_1].add(zone_name_2)\n# we want neighbors to always be in the same order\nfor zone, neighbors in ZONE_NEIGHBOURS.items():\n    ZONE_NEIGHBOURS[zone] = sorted(neighbors)\n", "path": "utils/config.py"}], "after_files": [{"content": "import json\nimport os\n\ndef relative_path(script_reference_path, rel_path):\n    # __file__ should be passed as script_reference_path\n    script_path = os.path.abspath(\n        script_reference_path)  # i.e. /path/to/dir/foobar.py\n    script_dir = os.path.split(script_path)[0]  # i.e. /path/to/dir/\n    return os.path.join(script_dir, rel_path)\n\n\n# Prepare zone bounding boxes\nZONE_BOUNDING_BOXES = {}\n\n# Read parser import list from config jsons\nZONES_CONFIG = json.load(open(relative_path(\n    __file__, '../config/zones.json')))\n\n# Read all zones\nfor zone_id, zone_config in ZONES_CONFIG.items():\n    if 'bounding_box' in zone_config:\n        ZONE_BOUNDING_BOXES[zone_id] = zone_config['bounding_box']\n\n# Read parser import list from config jsons\nZONES_CONFIG = json.load(open(relative_path(\n    __file__, '../config/zones.json')))\nEXCHANGES_CONFIG = json.load(open(relative_path(\n    __file__, '../config/exchanges.json')))\nZONE_NEIGHBOURS = {}\nfor k, v in EXCHANGES_CONFIG.items():\n    zone_names = k.split('->')\n    pairs = [\n        (zone_names[0], zone_names[1]),\n        (zone_names[1], zone_names[0])\n    ]\n    for zone_name_1, zone_name_2 in pairs:\n        if zone_name_1 not in ZONE_NEIGHBOURS:\n            ZONE_NEIGHBOURS[zone_name_1] = set()\n        ZONE_NEIGHBOURS[zone_name_1].add(zone_name_2)\n# we want neighbors to always be in the same order\nfor zone, neighbors in ZONE_NEIGHBOURS.items():\n    ZONE_NEIGHBOURS[zone] = sorted(neighbors)\n\nCO2EQ_PARAMETERS = json.load(open(relative_path(\n    __file__, '../config/co2eq_parameters.json')))\n\ndef emission_factors(zone_key):\n    fallback_carbon_intensity = CO2EQ_PARAMETERS['fallbackZoneMixes'].get(zone_key, {}).get('carbonIntensity');\n    override = CO2EQ_PARAMETERS['emissionFactors']['zoneOverrides'].get(zone_key, {})\n    defaults = CO2EQ_PARAMETERS['emissionFactors']['defaults']\n    merged = {**defaults, **override}\n    if fallback_carbon_intensity:\n        merged['battery storage'] = {\n            'value': fallback_carbon_intensity,\n            'source': 'Annual carbon intensity'\n        }\n        merged['hydro storage'] = {\n            'value': fallback_carbon_intensity,\n            'source': 'Annual carbon intensity'\n        }\n    return dict([(k, (v or {}).get('value')) for (k, v) in merged.items()])\n", "path": "utils/config.py"}]}