Exemplo n.º 1
0
 def get_code_with_function(self, function_name):
     if self.code_collection_name not in db.collection_names():
         db.create_collection(self.code_collection_name)
     for doc in db[self.code_collection_name].find():
         if function_name in doc["metadata"]["functions"]:
             return doc["the_code"]
     return None
Exemplo n.º 2
0
 def get_code_with_class(self, class_name):
     if self.code_collection_name not in db.collection_names():
         db.create_collection(self.code_collection_name)
     for doc in db[self.code_collection_name].find():
         if class_name in doc["metadata"]["classes"]:
             return doc["the_code"]
     return None
Exemplo n.º 3
0
 def tile_module_names(self,):
     if self.tile_collection_name not in db.collection_names():
         db.create_collection(self.tile_collection_name)
         return []
     my_tile_names = []
     for doc in db[self.tile_collection_name].find(projection=["tile_module_name"]):
         my_tile_names.append(doc["tile_module_name"])
     return sorted([str(t) for t in my_tile_names], key=str.lower)
Exemplo n.º 4
0
 def list_names(self):
     if self.list_collection_name not in db.collection_names():
         db.create_collection(self.list_collection_name)
         return []
     my_list_names = []
     for doc in db[self.list_collection_name].find(projection=["list_name"]):
         my_list_names.append(doc["list_name"])
     return sorted([str(t) for t in my_list_names], key=str.lower)
Exemplo n.º 5
0
 def data_collections(self):
     cnames = db.collection_names()
     string_start = self.username + ".data_collection."
     my_collection_names = []
     for cname in cnames:
         m = re.search(string_start + "(.*)", cname)
         if m:
             my_collection_names.append(m.group(1))
     return sorted([str(t) for t in my_collection_names], key=str.lower)
Exemplo n.º 6
0
 def function_tags_dict(self):
     if self.code_collection_name not in db.collection_names():
         db.create_collection(self.code_collection_name)
         return {}
     functions = {}
     for doc in db[self.code_collection_name].find():
         tags = doc["metadata"]["tags"]
         for f in doc["metadata"]["functions"]:
             functions[f] = tags
     return functions
Exemplo n.º 7
0
 def class_tags_dict(self,):
     if self.code_collection_name not in db.collection_names():
         db.create_collection(self.code_collection_name)
         return {}
     classes = {}
     for doc in db[self.code_collection_name].find():
         tags = doc["metadata"]["tags"]
         for c in doc["metadata"]["classes"]:
             classes[c] = tags
     return classes
Exemplo n.º 8
0
 def tile_module_names_with_metadata(self):
     if self.tile_collection_name not in db.collection_names():
         db.create_collection(self.tile_collection_name)
         return []
     my_tile_names = []
     for doc in db[self.tile_collection_name].find(projection=["tile_module_name", "metadata"]):
         if "metadata" in doc:
             my_tile_names.append([doc["tile_module_name"], doc["metadata"]])
         else:
             my_tile_names.append([doc["tile_module_name"], None])
     return sorted(my_tile_names, key=self.sort_data_list_key)
Exemplo n.º 9
0
    def data_collection_names_with_metadata(self):
        cnames = db.collection_names()
        string_start = self.username + ".data_collection."
        my_collection_names = []
        for cname in cnames:
            m = re.search(string_start + "(.*)", cname)
            if m:
                mdata = db[cname].find_one({"name": "__metadata__"})
                my_collection_names.append([m.group(1), mdata])

        return sorted(my_collection_names, key=self.sort_data_list_key)
Exemplo n.º 10
0
 def duplicate_collection(self):
     user_obj = current_user
     collection_to_copy = user_obj.full_collection_name(request.json['res_to_copy'])
     new_collection_name = user_obj.full_collection_name(request.json['new_res_name'])
     if new_collection_name in db.collection_names():
         return jsonify({"success": False, "message": "There is already a collection with that name.",
                         "alert_type": "alert-warning"})
     for doc in db[collection_to_copy].find():
         db[new_collection_name].insert_one(doc)
     self.update_selector_list(request.json['new_res_name'])
     return jsonify({"success": True})
Exemplo n.º 11
0
    def load_files(self, collection_name):
        user_obj = current_user
        file_list = request.files.getlist("file")
        full_collection_name = user_obj.build_data_collection_name(collection_name)
        if full_collection_name in db.collection_names():
            return jsonify({"success": False, "message": "There is already a collection with that name.",
                            "alert_type": "alert-warning"})
        mdata = create_initial_metadata()
        try:
            db[full_collection_name].insert_one({"name": "__metadata__", "datetime": mdata["datetime"],
                                                 "tags": "", "notes": ""})
        except:
            error_string = "Error creating collection: " + str(sys.exc_info()[0]) + " " + str(sys.exc_info()[1])
            return jsonify({"success": False, "message": error_string, "alert_type": "alert-warning"})

        for the_file in file_list:
            filename, file_extension = os.path.splitext(the_file.filename)
            if file_extension == ".csv":
                (success, result_dict, header_list) = read_csv_file_to_dict(the_file)
            elif file_extension == ".tsv":
                (success, result_dict, header_list) = read_tsv_file_to_dict(the_file)
            elif file_extension == ".txt":
                (success, result_dict, header_list) = read_txt_file_to_dict(the_file)
            # elif file_extension == ".xml":
            #     (success, result_dict, header_list) = read_xml_file_to_dict(file)
            else:
                return jsonify({"success": False, "message": "Not a valid file extension " + file_extension,
                                "alert_type": "alert-warning"})
            if not success:  # then result_dict contains an error object
                e = result_dict
                return jsonify({"message": e.message, "alert_type": "alert-danger"})

            try:
                if AUTOSPLIT and len(result_dict.keys()) > AUTOSPLIT_SIZE:
                    docs = self.autosplit_doc(filename, result_dict)
                    for doc in docs:
                        db[full_collection_name].insert_one({"name": doc["name"], "data_rows": doc["data_rows"],
                                                             "header_list": header_list})
                else:
                    db[full_collection_name].insert_one({"name": filename, "data_rows": result_dict,
                                                         "header_list": header_list})
            except:
                error_string = "Error creating collection: " + str(sys.exc_info()[0]) + " " + str(sys.exc_info()[1])
                stop_spinner()
                return jsonify({"success": False, "message": error_string, "alert_type": "alert-warning"})

        self.update_selector_list(collection_name)
        return jsonify({"message": "Collection successfully loaded", "alert_type": "alert-success"})
Exemplo n.º 12
0
 def get_resource_names(self, res_type, tag_filter=None, search_filter=None):
     if tag_filter is not None:
         tag_filter = tag_filter.lower()
     if search_filter is not None:
         search_filter = search_filter.lower()
     if res_type == "collection":
         dcollections = self.data_collections
         res_names = []
         for dcol in dcollections:
             cname = self.build_data_collection_name(dcol)
             mdata = db[cname].find_one({"name": "__metadata__"})
             if tag_filter is not None:
                 if mdata is not None and "tags" in mdata:
                     if tag_filter in mdata["tags"].lower():
                         res_names.append(dcol)
             elif search_filter is not None:
                 if search_filter in dcol.lower():
                     res_names.append(dcol)
             else:
                 res_names.append(dcol)
     else:
         cnames = {"tile": self.tile_collection_name, "list": self.list_collection_name,
                   "project": self.project_collection_name}
         name_keys = {"tile": "tile_module_name", "list": "list_name", "project": "project_name"}
         cname = cnames[res_type]
         name_key = name_keys[res_type]
         if cname not in db.collection_names():
             db.create_collection(cname)
             return []
         res_names = []
         for doc in db[cname].find():
             if tag_filter is not None:
                 if "metadata" in doc:
                     if "tags" in doc["metadata"]:
                         if tag_filter in doc["metadata"]["tags"].lower():
                             res_names.append(doc[name_key])
             elif search_filter is not None:
                 if search_filter in doc[name_key].lower():
                     res_names.append(doc[name_key])
             else:
                 res_names.append(doc[name_key])
     return sorted([str(t) for t in res_names], key=str.lower)