Skip to content

Commit

Permalink
Add integer id mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
cmutel committed Sep 29, 2023
1 parent 301f081 commit 0d767a1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ repos:
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: check-added-large-files
- id: check-ast
- id: check-json
- id: check-merge-conflict
Expand Down
Binary file added ecoinvent_interface/data/mappings.zip
Binary file not shown.
16 changes: 16 additions & 0 deletions ecoinvent_interface/mapping.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json
import zipfile
from pathlib import Path
from time import sleep
from typing import Optional
Expand All @@ -7,6 +9,8 @@

from . import CachedStorage, EcoinventProcess, Settings

DATA_DIR = Path(__file__).parent.resolve() / "data"


def get_rp_text(exchanges: list) -> str:
rp_exchanges = [
Expand Down Expand Up @@ -75,3 +79,15 @@ def create_local_mapping(self, key: str, verbose: bool) -> None:
)

return local_data


def get_cached_mapping(version: str, system_model: str) -> dict:
zf = zipfile.ZipFile(DATA_DIR / "mappings.zip")
try:
catalogue = {
(o["version"], o["system_model"]): o
for o in json.load(zf.open("catalogue.json"))
}
return json.load(zf.open(catalogue[(version, system_model)]["filename"]))
except KeyError:
raise KeyError(f"Combination {version} + {system_model} not yet cached")

0 comments on commit 0d767a1

Please sign in to comment.