def get_jsonfile_ddtree_equipment(self,raw_data): raw_data_mutilparent =[] raw_data_no_mutilparent = [] r_id =[] for raw in raw_data: if raw[0] not in r_id: raw_data_no_mutilparent.append(raw) r_id.append(raw[0]) else: raw_data_mutilparent.append({"equipment_id":raw[0],"parent":raw[2]}) rootNodes = self.json_data(raw_data_no_mutilparent) for rootNode in rootNodes: jsondata = NodeJSONEncoder().encode(rootNode) doc = json.JSONDecoder().decode(jsondata) #TEST mongo db client = ConnectDatabase().connect_mongo() db = client['testdb'] collection = db['testcoll'] id = collection.insert_one(doc) client.close() with open(os.path.join(APP_DATA,'equipmentdata.json'),'w') as file: #jsondata = json.dump(jsondata) file.write(jsondata) with open(os.path.join(APP_DATA,'equipmentdata_multiparent.json'),'w') as file: jsondata = json.dumps(raw_data_mutilparent) file.write(jsondata)
def readmongo(): client = ConnectDatabase().connect_mongo() db = client['testdb'] collection = db['testcoll'] equipments = collection.find_one() eq = ast.literal_eval(dumps(equipments)) client.close() return render_template('testDDCollapsableTree.html',equipments=eq)
def test(): engine = ConnectDatabase().connect_sqlalchemy() connection = engine.connect() data = Data() raw_data = data.query_equipment_cost(connection) return "Test data"