Here is the project script:
def getChargeTons(startDate, endDate):
query = 'Charging/select_ChargeTotals'
params = {'startDate': startDate, 'endDate': endDate}
ChargeTonsDB = system.dataset.toPyDataSet(system.db.runNamedQuery(query,params))
ChargeTons = ChargeTonsDB.getValueAt(0, 'totaltons')
return ChargeTons
def getEF(stack, endDate):
query = 'StackTest/select_TestBeforeDate'
params = {'stackID': stack, 'chemicalID': 1, 'endDate': endDate}
EFDB = system.dataset.toPyDataSet(system.db.runNamedQuery(query,params))
EF = EFDB.getValueAt(0, 'amount')
return EF
def getSCslagcharge(endDate):
query = 'SulferContent/select_SulferRollingAvgbySample'
params = {'sampleID': 5, 'endDate': endDate}
SCslagchargeDB = system.dataset.toPyDataSet(system.db.runNamedQuery(query,params))
SCslagcharge = SCslagchargeDB.getValueAt(0, 'avg_sulfer')/100
return SCslagcharge
def getSCcokecharge(endDate):
query = 'SulferContent/select_SulferRollingAvgbySample'
params = {'sampleID': 4, 'endDate': endDate}
SCcokechargeDB = system.dataset.toPyDataSet(system.db.runNamedQuery(query,params))
SCcokecharge = SCcokechargeDB.getValueAt(0, 'avg_sulfer')/100
return SCcokecharge
def getSCcoketest(stack, endDate):
query = 'StackTest/select_TestBeforeDate'
params = {'stackID': stack,'chemicalID': 2, 'endDate': endDate}
SCcoketestDB = system.dataset.toPyDataSet(system.db.runNamedQuery(query,params))
SCcoketest = (SCcoketestDB.getValueAt(0, 'amount'))/100
return SCcoketest
def getSCslagtest(stack, endDate):
query = 'StackTest/select_TestBeforeDate'
params = {'stackID': stack,'chemicalID': 3, 'endDate': endDate}
SCslagtestDB = system.dataset.toPyDataSet(system.db.runNamedQuery(query,params))
SCslagtest = (SCslagtestDB.getValueAt(0, 'amount'))/100
return SCslagtest
def getTcoketest(stack, endDate):
query = 'StackTest/select_TestBeforeDate'
params = {'stackID': stack,'chemicalID': 4, 'endDate': endDate}
TcoketestDB = system.dataset.toPyDataSet(system.db.runNamedQuery(query,params))
Tcoketest = TcoketestDB.getValueAt(0, 'amount')
return Tcoketest
def getTslagtest(stack, endDate):
query = 'StackTest/select_TestBeforeDate'
params = {'stackID': stack,'chemicalID': 5, 'endDate': endDate}
TslagtestDB = system.dataset.toPyDataSet(system.db.runNamedQuery(query,params))
Tslagtest = TslagtestDB.getValueAt(0, 'amount')
return Tslagtest
def getARsulfurcontentcoke(stack, startDate, endDate):
SCcoketest = getSCcoketest(stack, endDate)
SCcokecharge = getSCcokecharge(endDate)
if SCcoketest > 0:
return SCcokecharge/SCcoketest
else:
return 0
def getARsulfurcontentslag(stack, startDate, endDate):
SCslagtest = getSCslagtest(stack, endDate)
SCslagcharge = getSCslagcharge(endDate)
if SCslagtest > 0:
return SCslagcharge/SCslagtest
else:
return 0
def getChargeTotals(startDate, endDate):
query = 'Charging/select_PoundsPerMonthbyMaterial'
params = {'startDate': startDate, 'endDate': endDate}
ChargeTotalsDB = system.dataset.toPyDataSet(system.db.runNamedQuery(query,params))
ChargeTotals = ChargeTotalsDB.getValueAt(0, 'total_pounds')
return ChargeTotals
def getSTinputsulfermass(stack, startDate, endDate):
SCslagtest = getSCslagtest(stack, endDate)
SCcoketest = getSCcoketest(stack, endDate)
Tslagtest = getTslagtest(stack, endDate)
Tcoketest = getTcoketest(stack, endDate)
STinputsulfermass = (SCslagtest * Tslagtest) + (SCcoketest * Tcoketest)
return STinputsulfermass
def getWSOflyashsulfercontent(endDate):
query = 'SulferContent/select_SulferRollingAvgbySample'
params = {'sampleID': 2, 'endDate': endDate}
WSOflyashsulfercontentDB = system.dataset.toPyDataSet(system.db.runNamedQuery(query,params))
WSOflyashsulfercontent = (WSOflyashsulfercontentDB.getValueAt(0, 'avg_sulfer'))/100
return WSOflyashsulfercontent
def getWSOslagwastesulfercontent(endDate):
query = 'SulferContent/select_SulferRollingAvgbySample'
params = {'sampleID': 3, 'endDate': endDate}
WSOslagwastesulfercontentDB = system.dataset.toPyDataSet(system.db.runNamedQuery(query,params))
WSOslagwastesulfercontent = (WSOslagwastesulfercontentDB.getValueAt(0, 'avg_sulfer'))/100
return WSOslagwastesulfercontent
def getWSOwoolsulfercontent(endDate):
query = 'SulferContent/select_SulferRollingAvgbySample'
params = {'sampleID': 1, 'endDate': endDate}
WSOwoolsulfercontentDB = system.dataset.toPyDataSet(system.db.runNamedQuery(query,params))
WSOwoolsulfercontent = (WSOwoolsulfercontentDB.getValueAt(0, 'avg_sulfer'))/100
return WSOwoolsulfercontent
def getWSOflyash(startDate, endDate):
# get the date and amount of the last flyash bin before the start date
query = 'Flyash/select_LastWeightBefore'
params = {'startDate': startDate}
flyashStartDB = system.dataset.toPyDataSet(system.db.runNamedQuery(query,params))
flyashStart = flyashStartDB.getValueAt(0, 'amount')
flyashStartDate = flyashStartDB.getValueAt(0, 'date_weighed')
#print 'flyashStartDate'
#print flyashStartDate
# get the date of the next flyash bin after the end date
query = 'Flyash/select_nextWeightAfter'
params = {'endDate': endDate}
flyashEndDB = system.dataset.toPyDataSet(system.db.runNamedQuery(query,params))
flyashEnd = flyashEndDB.getValueAt(0, 'amount')
flyashEndDate = flyashEndDB.getValueAt(0, 'date_weighed')
#print 'flyashEndDate'
#print flyashEndDate
#get the total flyash between the two dates (these queries doesn't have the date <= but only <, etc)
query = 'Flyash/select_WasteTotalPounds'
params = {'startDate': flyashStartDate, 'endDate' : flyashEndDate}
flyashTotalDB = system.dataset.toPyDataSet(system.db.runNamedQuery(query,params))
flyashTotal = flyashTotalDB.getValueAt(0, 'total')
#print 'flyashTotal'
#print flyashTotal
#get the total runtime during that period
query = 'Cupola/select_CupolaRunTimeTotal'
params = {'startDate': flyashStartDate, 'endDate' : flyashEndDate}
flyashRuntimeDB = system.dataset.toPyDataSet(system.db.runNamedQuery(query,params))
flyashRuntime = flyashRuntimeDB.getValueAt(0, 'hours')
#print 'flyashRuntime'
#print flyashRuntime
#flyash average lbs/hr between the date of the bin before the month and the date of the bin after the month
if flyashRuntime > 0:
WSOflyash = (flyashTotal / flyashRuntime)
else:
WSOflyash = 0
return WSOflyash
def getWSOwool(startDate, endDate):
query = 'Wool/select_WoolBinTotal'
params = {'startDate': startDate, 'endDate' : endDate}
woolBinTotalDB = system.dataset.toPyDataSet(system.db.runNamedQuery(query,params))
woolBinTotal = woolBinTotalDB.getValueAt(0, 'WoolTotal')
query = 'Wool/select_BaleTotal'
params = {'startDate': startDate, 'endDate' : endDate}
woolBaleTotalDB = system.dataset.toPyDataSet(system.db.runNamedQuery(query,params))
woolBaleTotal = woolBaleTotalDB.getValueAt(0, 'WoolTotal')
query = 'Wool/select_CafcoBagWoolTotal'
params = {'startDate': startDate, 'endDate' : endDate}
cafcoWoolTotalDB = system.dataset.toPyDataSet(system.db.runNamedQuery(query,params))
cafcoWoolTotal = cafcoWoolTotalDB.getValueAt(0, 'WoolTotal')
WSOwool = woolBinTotal + cafcoWoolTotal + woolBaleTotal
return WSOwool
def getWSOslagwaste(startDate, endDate):
#initialize the material Total
materialTotal = 0
#get total wool and total material to calculate recovery
WSOwool = getWSOwool(startDate, endDate)
query = 'Charging/select_PoundsPerMonthbyMaterial'
params = {'startDate': startDate, 'endDate': endDate}
ChargeTotalsDB = system.dataset.toPyDataSet(system.db.runNamedQuery(query,params))
for row in range(ChargeTotalsDB.rowCount):
if ChargeTotalsDB.getValueAt(row, 'material') == 'rocks':
materialTotal = (ChargeTotalsDB.getValueAt(row, 'total_pounds'))/2000
if materialTotal > 0:
WSOslagwaste = materialTotal - WSOwool
else:
WSOslagwaste = 0
return WSOslagwaste
def getMWPWSsulfermass(startDate, endDate):
WSOflyash = getWSOflyash(startDate, endDate)
WSOflyashsulfercontent = getWSOflyashsulfercontent(endDate)
WSOwool = getWSOwool(startDate, endDate)
WSOwoolsulfercontent = getWSOwoolsulfercontent(endDate)
WSOslagwaste = getWSOslagwaste(startDate, endDate)
WSOslagwastesulfercontent = getWSOslagwastesulfercontent(endDate)
MWPWSsulfermass = ((WSOslagwastesulfercontent/100) * WSOslagwaste) + ((WSOwoolsulfercontent/100) * WSOwool) + ((WSOflyashsulfercontent/100) * WSOflyash)
return MWPWSsulfermass
def getH12(startDate, endDate):
query = 'Cupola/select_CupolaRunTimeTotal'
params = {'startDate': startDate, 'endDate' : endDate}
H12DB = system.dataset.toPyDataSet(system.db.runNamedQuery(query,params))
H12 = H12DB.getValueAt(0, 'hours')
return H12
def SO2(stack, startDate, endDate):
Tmaterial = getChargeTons(startDate, endDate)
EF = getEF(stack, endDate)
print 'EF'
print EF
ARsulfurcontentslag = getARsulfurcontentslag(stack, startDate, endDate)
print 'ARsulfurcontentslag'
print ARsulfurcontentslag
ARsulfurcontentcoke = getARsulfurcontentcoke(stack, startDate, endDate)
print 'ARsulfurcontentcoke'
print ARsulfurcontentcoke
STinputsulfermass = getSTinputsulfermass(stack, startDate, endDate)
print 'STinputsulfermass'
print STinputsulfermass
MWPWSsulfermass = getMWPWSsulfermass(startDate, endDate)
print 'MWPWSsulfermass'
print MWPWSsulfermass
H12 = getH12(startDate, endDate)
print 'H12'
print H12
SO2base =(Tmaterial * EF)
print 'SO2base'
print SO2base
WasteFactorAdjustment = ((STinputsulfermass-MWPWSsulfermass)/STinputsulfermass)
SO2 = (SO2base + ((SO2base * (ARsulfurcontentslag-1)) + (SO2base * (ARsulfurcontentcoke-1))) * WasteFactorAdjustment)/H12
print 'SO2'
print SO2
return SO2
def SO2report(startDate, endDate):
reportDSHeader = ["month", "EFcupola", "EFscreenhouse", "Material", "Hours", "SO2cupola", "SO2screenhouse"]
reportDS = []
Tmaterial = getChargeTons(startDate, endDate)
MWPWSsulfermass = getMWPWSsulfermass(startDate, endDate)
H12 = getH12(startDate, endDate)
stack = 1
EF_1 = getEF(stack, endDate)
ARsulfurcontentslag_1 = getARsulfurcontentslag(stack, startDate, endDate) - 1
ARsulfurcontentcoke_1 = getARsulfurcontentcoke(stack, startDate, endDate) - 1
STinputsulfermass_1 = getSTinputsulfermass(stack, startDate, endDate)
SO2base_1 =(Tmaterial * EF_1)
WasteFactorAdjustment_1 = (STinputsulfermass_1-MWPWSsulfermass)/STinputsulfermass_1
print 'ARsulfurcontentcoke_1'
print ARsulfurcontentcoke_1
SO2_1 = (SO2base_1 + (((SO2base_1 * ARsulfurcontentslag_1) + (SO2base_1 * ARsulfurcontentcoke_1)) * WasteFactorAdjustment_1))/H12
stack = 2
EF_2 = getEF(stack, endDate)
ARsulfurcontentslag_2 = getARsulfurcontentslag(stack, startDate, endDate) - 1
ARsulfurcontentcoke_2 = getARsulfurcontentcoke(stack, startDate, endDate) - 1
STinputsulfermass_2 = getSTinputsulfermass(stack, startDate, endDate)
SO2base_2 =(Tmaterial * EF_2)
WasteFactorAdjustment_2 = ((STinputsulfermass_2-MWPWSsulfermass)/STinputsulfermass_2)
print 'ARsulfurcontentcoke_2'
print ARsulfurcontentcoke_2
SO2_2 = (SO2base_2 + (((SO2base_2 * ARsulfurcontentslag_2) + (SO2base_2 * ARsulfurcontentcoke_2)) * WasteFactorAdjustment_2))/H12
#month = system.date.getMonth(startDate)
month = "December"
EFcupola = EF_1
EFscreenhouse = EF_2
Material = Tmaterial
Hours = H12
SO2cupola = SO2_1
SO2screenhouse = SO2_2
reportDS.append([month, EFcupola, EFscreenhouse, Material, Hours, SO2cupola, SO2screenhouse])
return system.dataset.toDataSet(reportDSHeader, reportDS)