0 votes
196 views

import csv

import operator

filePath = 'C:/Osama/Beef_Production/category_test.csv'

def findId(folder, process, location):

    id = []

    def checkProc(p):

        if p.category.name == folder and p.name == process and p.location.name==location:

            id.append(p.id)

    return id       

    olca.eachProcess(checkProc)

    if len(id)==1:

        return id[0]

    elif len(id)>1:

        log.error("Whoops I found more than one {}{} to update in {}", process, location, folder)        return (0)

    else:

        log.error("Uh oh! I couldn't find {}{} anywhere in {}. Check your spelling and try again!",process,location,folder)

        return(0)

# updates discovered process

def updateProcess(id,List_flow):

    pro = olca.getProcess(id)

    #exs = pro.getExchanges()

    exs = pro.exchanges

    for ex in exs:

        k=0       

        for j in List_flow:  

            if ex.flow.name == List_flow[k][0] and ex.flow.category.name==List_flow[k][2]:                

                ex.amount = float(List_flow[k][1])

                # This work

                log.info("{} uncertainty", ex.uncertainty)

               

          ***      # It does not work

                ex.uncertainty.mean = 3

                ex.uncertainty.sd = 0.25

                break

            k=k+1

    olca.updateProcess(pro)

    log.info("{} has been updated",pro.name)

    return

List_Process = []

process_count=0

with open(filePath, 'rb') as csvfile:

    linereader = csv.reader(csvfile, delimiter=',',quotechar='"')

    next(linereader)

    for row in linereader:

        process_count=process_count+ 1       

        List_Process.append([row[0],row[1],row[2],row[3],row[4],row[5]])

List_Process.sort(key = operator.itemgetter(0, 1, 5))

i=0

List_flow= []

while True:

    f_name= List_Process[i][0]

    p_name= List_Process[i][1]

    location=List_Process[i][5]

    id = findId(f_name,p_name,location)

    if id!=0:

        #List_flow.clear()

        List_flow= []

        while (List_Process[i][0]==f_name and List_Process[i][1]==p_name and List_Process[i][5]==location):

            List_flow.append([List_Process[i][2], List_Process[i][4], List_Process[i][3]])

            i=i+1

            if i==process_count:

                break

        #updateProcess(id,row[2],row[4],row[3])

        updateProcess(id, List_flow)

    else:

        i=i+1

    if i==process_count:

        break

in openLCA by (230 points)

Please log in or register to answer this question.

...