Exemplo n.º 1
0
def readinadditionaleffects(lulist, filename):
    namelist = [lu['name'] for lu in lulist]
    f = open("inputs/" + filename, 'r')
    print 'reading in', filename
    r = csv.DictReader(f)
    addefflist = []
    for row in r:
        for k, v in row.iteritems():
            try:
                row[k] = float(v)
            except ValueError:
                row[k] = v
        print row
        addefflist.append(row)
    f.close()
    for addeff in addefflist:
        if not ((addeff['laterlu'] in namelist) and
                (addeff['initiallu'] in namelist)):
            print 'warning!!!!!! bad name in additional effects file!!:', addeff[
                'laterlu'], addeff['initiallu'], '....ignoring'
    addefflist = [
        addeff for addeff in addefflist
        if ((addeff['laterlu'] in namelist) and (
            addeff['initiallu'] in namelist))
    ]
    for addeff in addefflist:
        addeff['laterlu'] = convertLUnameToLUI(addeff['laterlu'], lulist)
        addeff['initiallu'] = convertLUnameToLUI(addeff['initiallu'], lulist)
        addeff['yearsbetween'] = int(addeff['yearsbetween'])
    return addefflist
Exemplo n.º 2
0
def readDisallowedCombos(lulist,filename):
    namelist=[lu['name'] for lu in lulist]
    f=open("inputs/"+filename, 'r')
    print 'reading disallowed combinations'
    thisline=f.readline()
    alllines=[]
    while thisline!='':
        thisline=f.readline()
        thislinelist=thisline.split(',')
        thislineconv=[]
        if thisline!='':
            #print thisline,thislinelist
            for item in thislinelist:
                if '\n' in item:
                    item=item[0: (len(item)-1) ]
                #print "*",item
                try:
                    additem=int(item)
                except ValueError:
                    if item in namelist:
                        additem=convertLUnameToLUI(item,lulist)
                    elif item=='' or item=='/n':
                        additem = '???'
                    else:
                        print item,
                        for i in range(5): print 'warning!!!!!! bad name in disallowed combinations file!!:',item
                        additem = '???'
                if additem != '???': thislineconv.append(additem)
            print thislineconv
            alllines.append(thislineconv)
    f.close()
    return alllines
Exemplo n.º 3
0
def readDisallowedCombos(lulist, filename):
    namelist = [lu['name'] for lu in lulist]
    f = open("inputs/" + filename, 'r')
    print 'reading disallowed combinations'
    thisline = f.readline()
    alllines = []
    while thisline != '':
        thisline = f.readline()
        thislinelist = thisline.split(',')
        thislineconv = []
        if thisline != '':
            #print thisline,thislinelist
            for item in thislinelist:
                if '\n' in item:
                    item = item[0:(len(item) - 1)]
                #print "*",item
                try:
                    additem = int(item)
                except ValueError:
                    if item in namelist:
                        additem = convertLUnameToLUI(item, lulist)
                    elif item == '' or item == '/n':
                        additem = '???'
                    else:
                        print item,
                        for i in range(5):
                            print 'warning!!!!!! bad name in disallowed combinations file!!:', item
                        additem = '???'
                if additem != '???': thislineconv.append(additem)
            print thislineconv
            alllines.append(thislineconv)
    f.close()
    return alllines
Exemplo n.º 4
0
def readinadditionaleffects(lulist,filename):
    namelist=[lu['name'] for lu in lulist]
    f=open("inputs/"+filename, 'r')
    print 'reading in',filename
    r=csv.DictReader(f)
    addefflist=[]
    for row in r:
        for k, v in row.iteritems():
            try:
                row[k]=float(v)
            except ValueError:
                row[k]=v
        print row
        addefflist.append(row)
    f.close()
    for addeff in addefflist:
        if not ((addeff['laterlu'] in namelist) and (addeff['initiallu'] in namelist)):
            print 'warning!!!!!! bad name in additional effects file!!:',addeff['laterlu'],addeff['initiallu'],'....ignoring'
    addefflist = [addeff for addeff in addefflist if ((addeff['laterlu'] in namelist) and (addeff['initiallu'] in namelist))]
    for addeff in addefflist:
        addeff['laterlu']=convertLUnameToLUI(addeff['laterlu'],lulist)
        addeff['initiallu']=convertLUnameToLUI(addeff['initiallu'],lulist)
        addeff['yearsbetween']=int(addeff['yearsbetween'])
    return addefflist
Exemplo n.º 5
0
def readPriceMultipliers(lulist, filename):
    namelist = [lu['name'] for lu in lulist]
    f = open("inputs/" + filename, 'r')
    print 'reading price multipliers'
    thisline = f.readline()
    alllines = []
    while thisline != '':
        thisline = f.readline()
        thislinelist = thisline.split(',')
        thislineconv = []
        if thisline != '':
            #print thisline,thislinelist
            for item in thislinelist:
                if '\n' in item:
                    item = item[0:(len(item) - 1)]
                #print "*",item
                try:
                    additem = float(item)
                except ValueError:
                    if item in namelist:
                        additem = convertLUnameToLUI(item, lulist)
                    elif item == '' or item == '/n':
                        additem = '???'
                    else:
                        print item,
                        for i in range(5):
                            print 'warning!!!!!! bad name in price multipliers file!!:', item
                        additem = '???'
                if additem != '???': thislineconv.append(additem)
            print thislineconv
            alllines.append(thislineconv)
            alllines = [line for line in alllines if type(line[0]) == int]
    f.close()
    pricevarlist = []
    for i in range(len(namelist)):
        pricevarlist.append([1.])
    for line in alllines:
        lui = line.pop(0)
        mults = line[:]
        pricevarlist[lui] = mults
    return pricevarlist
Exemplo n.º 6
0
def readPriceMultipliers(lulist,filename):
    namelist=[lu['name'] for lu in lulist]
    f=open("inputs/"+filename, 'r')
    print 'reading price multipliers'
    thisline=f.readline()
    alllines=[]
    while thisline!='':
        thisline=f.readline()
        thislinelist=thisline.split(',')
        thislineconv=[]
        if thisline!='':
            #print thisline,thislinelist
            for item in thislinelist:
                if '\n' in item:
                    item=item[0: (len(item)-1) ]
                #print "*",item
                try:
                    additem=float(item)
                except ValueError:
                    if item in namelist:
                        additem=convertLUnameToLUI(item,lulist)
                    elif item=='' or item=='/n':
                        additem = '???'
                    else:
                        print item,
                        for i in range(5): print 'warning!!!!!! bad name in price multipliers file!!:',item
                        additem = '???'
                if additem != '???': thislineconv.append(additem)
            print thislineconv
            alllines.append(thislineconv)
            alllines=[line for line in alllines if  type(line[0])==int]
    f.close()
    pricevarlist=[]
    for i in range(len(namelist)):
        pricevarlist.append([1.])
    for line in alllines:
        lui=line.pop(0)
        mults=line[:]
        pricevarlist[lui]=mults
    return pricevarlist