Datenmodelle angepasst, einige Firmen in CITT übernommen
This commit is contained in:
97
src/paveit/helper/mongo.py
Normal file
97
src/paveit/helper/mongo.py
Normal file
@@ -0,0 +1,97 @@
|
||||
from bson import ObjectId
|
||||
from mongoengine import connect as mongo_connect
|
||||
from pandas import DataFrame
|
||||
|
||||
|
||||
def connect_mongo_db_labtests(username='admin',
|
||||
password='admin',
|
||||
host='mongo',
|
||||
authentication_source='admin'):
|
||||
|
||||
mongo_connect('labtests',
|
||||
username=username,
|
||||
password=password,
|
||||
host=host,
|
||||
authentication_source=authentication_source,
|
||||
alias='dblabtests')
|
||||
|
||||
|
||||
def connect_mongo_db_usser(username='admin',
|
||||
password='admin',
|
||||
host='mongo',
|
||||
authentication_source='admin'):
|
||||
|
||||
mongo_connect('users',
|
||||
username=username,
|
||||
password=password,
|
||||
host=host,
|
||||
authentication_source=authentication_source,
|
||||
alias='dbusers')
|
||||
|
||||
|
||||
def connect_mongo_dbs(username='admin',
|
||||
password='admin',
|
||||
host='mongo',
|
||||
authentication_source='admin'):
|
||||
|
||||
connect_mongo_db_labtests(username=username,
|
||||
password=password,
|
||||
host=host,
|
||||
authentication_source=authentication_source)
|
||||
|
||||
connect_mongo_db_usser(username=username,
|
||||
password=password,
|
||||
host=host,
|
||||
authentication_source=authentication_source)
|
||||
|
||||
|
||||
def mongo_upload_results(resultsmodel, results: DataFrame, datamodel,
|
||||
data: DataFrame, filehash: str, org_id: ObjectId,
|
||||
project_id: ObjectId, material_id: ObjectId,
|
||||
user_id: ObjectId):
|
||||
|
||||
for idx, res in results.iterrows():
|
||||
|
||||
#upload results
|
||||
meta['filehash'] = filehash
|
||||
meta['org_id'] = org_id
|
||||
meta['project_id'] = project_id
|
||||
meta['material'] = material_id
|
||||
meta['user_id'] = user_id
|
||||
|
||||
#check if result in db
|
||||
#n = CITTSiffness.objects(**meta).count()
|
||||
#print(n)
|
||||
|
||||
# write data
|
||||
data_dict = res.to_dict()
|
||||
data_dict.update(meta)
|
||||
|
||||
f = resultsmodel(**data_dict).save()
|
||||
|
||||
# upload data
|
||||
data_sel = data[idx_fit]
|
||||
|
||||
# required data
|
||||
data_out = dict(
|
||||
time=data_sel.index,
|
||||
F=list(data_sel['F']),
|
||||
N=list(data_sel['N']),
|
||||
s_hor_1=list(data_sel['s_hor_1']),
|
||||
s_hor_2=list(data_sel['s_hor_2']),
|
||||
s_hor_sum=list(data_sel['s_hor_sum']),
|
||||
)
|
||||
#optional data
|
||||
for col in ['S_piston']:
|
||||
if col in data_sel.columns:
|
||||
data_out[col] = data_sel[col]
|
||||
|
||||
g = datamodel(result=f.id, **data_out).save()
|
||||
|
||||
|
||||
def mongo_get_results(resultsmodel, results: DataFrame, datamodel,
|
||||
data: DataFrame, filehash: str, org_id: ObjectId,
|
||||
project_id: ObjectId, material_id: ObjectId,
|
||||
user_id: ObjectId):
|
||||
|
||||
return True
|
||||
Reference in New Issue
Block a user