How do I fix error message. "Remember that ordinal parameters are 1-based!" - nhibernate

given the code snippet (please do not ask why I construct it this way...)
...some more Logic...
def blaParam = ['checkinable':checkinable]
def blaQuery = " AND c.product = :checkinable"
...some more Logic...
and
def paramBox = [] + blaParam
def queryBox = "" + blaQuery
def c = Bla.executeQuery("FROM Bla b WHERE 1 = 1 "+queryBox+" ", paramBox, [max:params.max])
I end up with a message
errors.GrailsExceptionResolver Remember that ordinal parameters are 1-based!
How do I prevent this?

Merging the two last parameter maps worked for me:
Bla.executeQuery("FROM Bla b WHERE 1 = 1 "+queryBox+" ", paramBox + [max:params.max])

if I change
def paramBox = [] + blaParam
to
def paramBox = [:] + blaParam
it is working

Related

Get 2 DataFrames into 1

Hi everyone so I have a DataFrame about Pokemon data
data = pd.read_csv('pokemon.csv')
And I'm only interested in 2 columns 'type1' 'type2' (type2 can be null) as the same way the original videogame does. What I need is to get a DataFrame that looks like this:
data.type1 looks like this:
data.type2:
So basically I need to take a single DataFrames using those 2 columns.
I've code this stuff trying to get 2 DataFrame that I can turn into the final one I am asked to reach:
tabla = {}
def contar(tipo):
buscando=tipo
if tipo == np.NaN:
pass
else:
if tipo in tabla:
tabla[tipo] += 1
else:
tabla[tipo] = 1
tabla2 = {}
def contar2(tipo):
buscando=tipo
if tipo == np.NaN:
pass
else:
if tipo in tabla2:
tabla2[tipo] += 1
else:
tabla2[tipo] = 1
def reset_tabla():
tabla = {}
tabla2 = {}
data['type1'].apply(contar)
df_type1 = pd.DataFrame.from_dict(tabla, orient='index')
reset_tabla()
data['type2'].apply(contar2)
df_type2 = pd.DataFrame.from_dict(tabla2, orient='index')
df_types = pd.concat([df_type1, df_type2])
df_type1
So with above code I get the data I want but no the way I need it.
I expected:
Instead, this was the output:
img continues and data appears 2 times due to 2 types columns
I think what I am doing wrong is the concat because type1 and 2 look like this separately:
and
Finally, if you know how to combine these 2 DataFrames or you think you can solve this problem better let me know.
Thanks you all :).
I've solved this issue, so if it's useful for somebody the solution is here:
tabla = {}
def contar(tipo):
buscando=tipo
if tipo in tabla:
tabla[tipo] += 1
else:
tabla[tipo] = 1
tabla2 = {}
def contar2(tipo):
buscando=tipo
if tipo == np.NaN:
pass
else:
if tipo in tabla2:
tabla2[tipo] += 1
else:
tabla2[tipo] = 1
def reset_tabla():
tabla = {}
tabla2 = {}
reset_tabla()
data['type1'].apply(contar)
data['type2'].apply(contar2)
for x in tabla2.keys():
if type(x)==float:
delete = x
del tabla2[delete]
types = {"type1": tabla,
"type2": tabla2}
df_types = pd.DataFrame(types)
df_types
So I get

How to write equations with sigma in pyomo

I am trying to optimize a micro-grid using pyomo and glpk solver. This is one of my constraint:
https://drive.google.com/file/d/1_iskeKjYPBPicJDFnZl1QIo275sEq3f9/view?usp=sharing
This is how I wrote it in python:
data = pd.read_csv('Data.csv')
load = data['L2']
model = pyo.ConcreteModel()
model.i = pyo.RangeSet(0, 23) #i
model.P_w = pyo.Var(model.i, domain=pyo.NonNegativeReals) #P-wind
model.P_pv = pyo.Var(model.i, domain=pyo.NonNegativeReals) #P-PV
model.P_fc = pyo.Var(model.i, domain=pyo.NonNegativeReals) #P-Fuel Cells
model.P_c = pyo.Var(model.i, domain=pyo.NonNegativeReals) #P-Charged
model.P_d = pyo.Var(model.i, domain=pyo.NonNegativeReals) #P_Discharged
model.UE = pyo.Var(model.i, domain=pyo.NonNegativeReals) #Undelivered Energy
model.EG = pyo.Var(model.i, domain=pyo.NonNegativeReals) #Excess Generated
def constraint1(model,i):
return sum(model.P_w[i] + model.P_pv[i]+ model.P_fc[i] + model.P_d[i] + model.UE[i] for i in model.i) == sum(load[i] + model.P_c[i] + model.EG[i] for i in model.i)
model.constraint1 = pyo.Constraint(model.i, rule=constraint1)
Please excuse the error in indents. However, the values that I am getting are as follows:
(P_w[0] + P_w[1] +..+P_w[23])+(P_pv[0]+P_pv[1]+..)+....+(UE[0]+UE[1]+...) = (load[0] + load[1]+..) +...
Whereas the results I want should be as:
P_w[0]+P_pv[0]+P_fc[0]+..+UE[0] = load[0]+P_c[0]+EG[0]
P_w[1]+P_pv[1]+P_fc[1]+..+UE[1] = load[1]+P_c[1]+EG[1]
I also tried writing:
sum(model.P_w[i] + model.P_pv[i]+ model.P_fc[i] + model.P_d[i] + model.UE[i] - load[i] - model.P_c[i] -model.EG[i] for i in model.i) == 0
But the answers are the same. How do I formulate it?
Thanks in advance :)
It isn't totally clear what you want here. Your linked math expression is nonsensical / not properly expressed.
It appears you want to make an equivalence constraint "for each i in model.i" and yet you are summing, so just remove the sum() statement from both sides of your constraint. You already have the model.constraint1() statement set up to create an individual constraint for each i in that set. So:
def constraint1(model, i):
return model.P_w[i] + model.P_pv[i]+ model.P_fc[i] + model.P_d[i] + model.UE[i] == \
load[i] + model.P_c[i] + model.EG[i]

jDE(Adaptive Differential Evolution)

In jDE, each individual has its own F and CR values. How to assign these values to each individuals programmatically. How to update these values.
A pseudo-code will help.
If you want each individual to have its own F and CR values, you can simply save it in a list. (Pseudo-code: Python)
ID_POS = 0
ID_FIT = 1
ID_F = 2
ID_CR = 3
def create_solution(problem_size):
pos = np.random.uniform(lower_bound, upper_bound, problem_size)
fit = fitness_function(pos)
F = your_values
CR = your values
return [pos, fit, F, CR]
def training(problem_size, pop_size, max_iteration):
# Initialization
pop = [create_solution(problem_size) for _ in range(0, pop_size)]
# Evolution process
for iteration in range(0, max_iteration):
for i in range(0, pop_size):
# Do your stuff here
pos_new = ....
fit_new = ....
F_new = ...
CR_new = ...
if pop[i][ID_FIT] < fit_new: # meaning the new solution has better fitness than the old one.
pop[i][ID_F] = F_new
pop[i][ID_CR] = CR_new # This is how you update F and CR for every individual.
...
You can check out my repo's contains most of the state-of-the-art meta-heuristics here.
https://github.com/thieunguyen5991/metaheuristics

Karate: Remove a dynamic element from from JSON

* def res1 = {"member":{"muid":"MBR1"},"part":[{"PID":"M123"},{"supportedMembers":[{"muid":"MBR3","status":{"code":"A"}},{"muid":"MBR2","status":{"code":"I"}}]}]}
* def res2 = {"members":[{"member":{"muid":"MBR2","test":[{"EID":"E123"}]}},{"member":{"muid":"MBR3","test":[{"EID":"E123"}]}}]}
Karate: Match array elements of two different JSON
I have another requirement which is related to my earlier post.
* def id = res1.member.muid
I want to remove id from res2 response, which can be any where in res2.members.member, and do the matching with res1 to see the presence of muids
I tried something like below, but its not working:
* karate.remove('$res2.members[*]..muid','$.muid[id]')
Sample Code:
Feature: Validation
Scenario:
* def res1 = {"member":{"muid":"MBR1"},"part":[{"PID":"M123"},{"supportedMembers":[{"muid":"MBR3","status":{"code":"A"}},{"muid":"MBR2","status":{"code":"I"}}]}]}
* def res2 = {"members":[{"member":{"muid":"MBR2","test":[{"EID":"E123"}]}},{"member":{"muid":"MBR3","test":[{"EID":"E123"}]}}]}
* def id = res1.member.muid
* def res2ids = $res2.members[*]..muid
* def data2 = karate.mapWithKey(res2ids, 'muid')
* print data2
* def res2ids = karate.jsonPath(data2, "$[?(#.muid != '" + id+ "')]")
* def res2ids = $res2ids[*]..muid
* print res2ids
* match res1.part[1].supportedMembers[*].muid contains only res2ids

How to get an integer value to a complex dictionary

Here the value of abc is an integer and total is a dictionary which contains another dictionaries.But when I run this line,
total[div]['total_transport_allowance'] = abc
This error is shown : "KeyError: None"
Please Help
What I want from this statement is to get the abc's value to the key 'total_transport_allowance'
def print_excel_report(self,cr,uid,ids,data,context=None):
result = self._get_lines(cr,uid,ids,data)
filename= 'PayrollRegister.xls'
workbook= xlwt.Workbook(encoding="UTF-8")
sheet= workbook.add_sheet('Payroll Register',cell_overwrite_ok=True)
style = xlwt.easyxf('font:height 400, bold True, name Arial; align: horiz center, vert center;borders: top medium,right medium,bottom medium,left medium')
a = range(1,10)
row = 1
col =0
header = ['Division','Basic','Transport Allowance']
style2 = xlwt.easyxf('font: bold 1')
total = {}
for index,data in enumerate(result):
div = data.get('Division',False)
abc = data.get('transport_allowance',False) or 0
if div:
if div in total:
total[div]['total_basic'] = total[div]['total_basic'] + data.get('basic',0)
total[div]['total_transport_allowance'] = total[div]['total_transport_allowance'] + abc
else:
total[div] = {}
total[div]['total_basic'] = data.get('basic',0)
total[div]['total_transport_allowance'] = abc
else:
if 'Undefined' in total:
total['Undefined']['total_basic'] = total['Undefined']['total_basic'] + data.get('basic',0)
total[div]['total_transport_allowance'] = total[div]['total_transport_allowance'] + abc
else:
total['Undefined'] = {}
total['Undefined']['total_basic'] = data.get('basic',0)
total[div]['total_transport_allowance'] = abc
.......
.....
To try and rescue something from all the downvotes:
You have an if statment checking the truthy of div. In the falsey case you then use div to access total.
ie you have:
if div:
# stuff
else:
# stuff
total[div]['total_transport_allowance'] = abc
As total doesn't have the key div, this doesn't work.
you need something like total[div] = {}
You are getting this error because div is None:
if div:
....
....
else:
...
...
# div here is None or False ..
# you cannot use it as key!!
total[div]['total_transport_allowance'] = abc
You need to define the key here first. so where
you want to put the abc when div is None.
EDIT
I don't know what the value of div should when it's not in data.get('Division',False):
div = data.get('Division', False)
...
...
if div:
.....
else:
# assing a value to div
div = 'NEW_VALUE'
# add dictionary there
total[div] = {}
if 'Undefined' in total:
....
...
...
total[div]['total_transport_allowance'] = {}
This worked..
I have done like this in
total['Undefined']['total_transport_allowance'] = {}
also..
Thanks for everyone's help
KeyError is None means not defined dictionary. div is a dictionary should be defined.