Skip to content

Commit

Permalink
Merge pull request #6 from joshgabriel/development
Browse files Browse the repository at this point in the history
add a function to insert documents to the mongodb
  • Loading branch information
joshgabriel authored May 4, 2017
2 parents c1402ed + 5c7389a commit b9aef16
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions benchmark-view/non_flask_query_mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,22 @@

db = client['benchmark']

# the default collection 'evk' for energy
def_coll = db.evk

def add_dframe(dset):
"""
extra feature to add: do not add duplicates
"""
count = 0
total = len(list(enumerate(dset.iterrows())))
for n,(index,row) in enumerate(dset.iterrows()):
doc = {key: row[key] for key in dset.columns}
def_coll.insert(doc)
count = count + 1
#print ('inserting {0} {1}'.format(index,row['element'][index]))
return ('inserted {0} of {1}'.format(count,total))

def find_by_query(query):
"""
return a dataframe based on the query
Expand All @@ -18,5 +32,6 @@ def find_by_query(query):
return (dframe)

if __name__ == '__main__':
#add_dframe(pd.read_csv('db_ready.csv'))
dframe_ret = find_by_query({'element':'Ag','structure':'fcc','code':'VASP','k-point':64,'exchange':'PBE'})
print (dframe_ret)

0 comments on commit b9aef16

Please sign in to comment.