I have the following doubt, I am building a query that performs a massive insertion in mongodb, but part of the data is brought from a function.
The following is the function that I use, my problem maybe is with the return
def formula(df,W, tipo):
LEQ = []
pd=data(df,W)
for index,info in pd.iterrows():
bands = info[2:]
LEQ.append(10**(NivelesPd(bands)/10))
level = round(10 * math.log10(sum(LEQ)/len(LEQ)),1)
maxNps = round(10 * math.log10(max(LEQ)),1)
minNps = round(10 * math.log10(min(LEQ)),1)
metrica = "'" +tipo +"' : "+ str(level) +", '"+tipo+"_MAX' : " + str(maxNps) + ", '"+tipo+"_MIN' : " + str(minNps)
return metrica
Once I get the information from the formula, I perform a "for" cycle
for index, df in grouped_per_time:
data= { 'ids' : str(ids), 'time' : str(index), 'tzone' : str(tzone) +", "+ formula(df,A, tipo='1') +"," + formula(df,B, tipo='2')+"," + formula(df,C, tipo='3') }
#realiso el insert en mongo
pd.save( data)
The insertion is done well, but the concatenation that I do with the function, I put all the data of the formulas as one
{'tzone': "-3, 'a' : 30.5, 'amx' : 30.5, 'amn' : 30.5,'c' : 29.9, 'cmx' : 30.0, 'cmn' : 29.9,'z' : 30.9, 'zmx' : 30.9, 'zmn' : 30.9", 'ids': 'b827', 'time': '1534250153'}
As you can see the following data that are in quotes and should be separated
'tzone': "- 3, 'a': 30.5, 'amx': 30.5, 'amn': 30.5, 'c': 29.9, 'cmx': 30.0, 'cmn': 29.9, 'z': 30.9, 'zmx': 30.9, 'zmn': 30.9 "
The data should look like this:
{'tzone': '-3', 'a' : 30.5, 'amx' : 30.5, 'amn' : 30.5,'c' : 29.9, 'cmx' : 30.0, 'cmn' : 29.9,'z' : 30.9, 'zmx' : 30.9, 'zmn' : 30.9, 'ids': 'b827', 'time': '1534250153'}