0 votes
43 views

Hi there

I have a script that automatically updates names and descriptions of flows and processes given external datasources with the olca-ipc connection with python. 

I have realized, that changes made to names or descriptions are not flagged as changes to the database and thus can't be comitted and pushed to the server. Any idea how to force OLCA to flag the process as changed, so that changed names and descriptions can be commited to the server?
 

The names and descriptions are changed as follows. item.process_A1_A5 is an o.Process() object, item.flow_A1_A5 is an o.Flow() object. 

    # Namen updaten
    if missing_phases_production and build_new_item:
        item.process_A1_A5.name += " (ohne " + missing_phases[:-1] + ")"
        item.flow_A1_A5.name += " (ohne " + missing_phases[:-1] + ")"
        item.process_A1_A5.description += " "
        item.flow_A1_A5.description += " "
 
    # Ă„nderungen schreiben
    client.put(item.flow_A1_A5)
    client.put(item.process_A1_A5)
in LCA Collaboration Server by (150 points)

1 Answer

0 votes
ago by (7.8k points)
selected ago by
 
Best answer

Hello,

The changes to datasets are detected by checking the version. You can see the version in the editor in the format MAJOR.MINOR.PATCH.

One option would be to increment the version when updating datasets. It could be done as follows (partially generated with LLM and then tested):

import re

import olca_schema as s
from olca_ipc import Client

FLOW_ID = "a680e0c7-c362-4494-9618-7768cf274fb6"


def increment_version(version: str) -> str:
    match = re.match(r"(\d{2})\.(\d{2})\.(\d{3})", version)
    if not match:
        raise ValueError("Invalid version format. Expected format: 00.00.000")

    major, minor, revision = map(int, match.groups())

    # Increment revision
    revision += 1
    if revision > 999:
        revision = 0
        minor += 1  # Increment minor if revision overflows

    if minor > 99:
        minor = 0
        major += 1  # Increment major if minor overflows

    return f"{major:02}.{minor:02}.{revision:03}"


client = Client()

process = client.get(s.Flow, FLOW_ID)
process.name = "test"
process.version = increment_version(process.version)
client.put(process)
print(client.get(s.Flow, FLOW_ID))

ago by (150 points)
Amazing, thank you so much for the reply. That works flawlessly!
...