Skip to content

Commit

Permalink
Merge branch 'master' into organic_cotton
Browse files Browse the repository at this point in the history
  • Loading branch information
ccomb authored Nov 21, 2024
2 parents dba8423 + ef6287d commit 450e326
Show file tree
Hide file tree
Showing 23 changed files with 10,812 additions and 905 deletions.
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
# Changelog


## [2.5.0](https://github.com/MTES-MCT/ecobalyse/compare/v2.4.0..v2.5.0) (2024-11-06)
## [2.6.0](https://github.com/MTES-MCT/ecobalyse/compare/v2.5.0..v2.6.0) (2024-11-20)



### 🚀 Features

- Add API FAQ page. ([#829](https://github.com/MTES-MCT/ecobalyse/issues/829))
- Intégration Laine woolmark ([#831](https://github.com/MTES-MCT/ecobalyse/issues/831))

### ⚙️ Miscellaneous Tasks

- Upgrade dependencies, Nov. 2024. ([#830](https://github.com/MTES-MCT/ecobalyse/issues/830))
- *(data)* Fixed typo paysane→paysanne ([#836](https://github.com/MTES-MCT/ecobalyse/issues/836))


## [2.5.0](https://github.com/MTES-MCT/ecobalyse/compare/v2.4.0..v2.5.0) (2024-11-07)



Expand Down
19 changes: 14 additions & 5 deletions data/common/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,22 @@ def progress_bar(index, total):
print(f"Export in progress: {str(index)}/{total}", end="\r")


def search(dbname, name, excluded_term=None):
results = bw2data.Database(dbname).search(name)
def search(dbname, search_terms, excluded_term=None):
results = bw2data.Database(dbname).search(search_terms)
if excluded_term:
results = [res for res in results if excluded_term not in res["name"]]
if not results:
print(f"Not found in brightway : '{name}'")
print(f"Not found in brightway : '{search_terms}'")
return None
if len(results) > 1:
# if the search gives more than one results, find the one with exact name
exact_results = [a for a in results if a["name"] == search_terms]
if len(exact_results) == 1:
return exact_results[0]
else:
raise ValueError(
f"This 'search' field returns more than one result in database {dbname}: {search_terms}"
)
return results[0]


Expand Down Expand Up @@ -374,8 +383,8 @@ def load_json(filename):


@functools.cache
def cached_search(dbname, name, excluded_term=None):
return search(dbname, name, excluded_term)
def cached_search(dbname, search_terms, excluded_term=None):
return search(dbname, search_terms, excluded_term)


def find_id(dbname, activity):
Expand Down
50 changes: 25 additions & 25 deletions data/common/import_.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import functools
import json
import os
import re
import sys
from os.path import dirname
import tempfile
from os.path import basename, join, splitext
from subprocess import call
from zipfile import ZipFile

Expand Down Expand Up @@ -186,29 +186,29 @@ def import_simapro_csv(
"""
print(f"### Importing {datapath}...")
# unzip
with ZipFile(datapath) as zf:
print("### Extracting the zip file...")
zf.extractall(path=dirname(datapath))
unzipped = datapath[0:-4]

if "AGB" in datapath:
print("### Patching Agribalyse...")
# `yield` is used as a variable in some Simapro parameters. bw2parameters cannot handle it:
# (sed is faster than Python)
call("sed -i 's/yield/Yield_/g' " + unzipped, shell=True)
# Fix some errors in Agribalyse:
call("sed -i 's/01\\/03\\/2005/1\\/3\\/5/g' " + unzipped, shell=True)
call("sed -i 's/\"0;001172\"/0,001172/' " + unzipped, shell=True)

print(f"### Importing into {dbname}...")
# Do the import
database = bw2io.importers.simapro_csv.SimaProCSVImporter(
unzipped, dbname, normalize_biosphere=True
)
if source:
for ds in database:
ds["source"] = source
os.unlink(unzipped)
with tempfile.TemporaryDirectory() as tempdir:
with ZipFile(datapath) as zf:
print(f"### Extracting the zip file in {tempdir}...")
zf.extractall(path=tempdir)
unzipped, _ = splitext(join(tempdir, basename(datapath)))

if "AGB" in datapath:
print("### Patching Agribalyse...")
# `yield` is used as a variable in some Simapro parameters. bw2parameters cannot handle it:
# (sed is faster than Python)
call("sed -i 's/yield/Yield_/g' " + unzipped, shell=True)
# Fix some errors in Agribalyse:
call("sed -i 's/01\\/03\\/2005/1\\/3\\/5/g' " + unzipped, shell=True)
call("sed -i 's/\"0;001172\"/0,001172/' " + unzipped, shell=True)

print(f"### Importing into {dbname}...")
# Do the import
database = bw2io.importers.simapro_csv.SimaProCSVImporter(
unzipped, dbname, normalize_biosphere=True
)
if source:
for ds in database:
ds["source"] = source

print("### Applying migrations...")
# Apply provided migrations
Expand Down
2 changes: 1 addition & 1 deletion data/create_activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
del bw2data.databases["Ecobalyse"]

if (db := "Ecobalyse") not in bw2data.databases:
for vertical in ("object", "food", "textile"):
for vertical in ("food", "textile", "object"):
file = f"{vertical}/activities_to_create.json"
if os.path.exists(file):
add_created_activities(db, file)
Expand Down
Loading

0 comments on commit 450e326

Please sign in to comment.