prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <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.
  
  </issue>
  <code>
  [start of utils/config.py]
  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 of utils/config.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: 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()])
  
verification_info: {"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"}]}