Package vsql_core :: Package catalog :: Module model_creator
[hide private]
[frames] | no frames]

Source Code for Module vsql_core.catalog.model_creator

 1  # ------------------------------------- 
 2  # -- These are the standard installs 
 3  # ------------------------------------- 
 4  # CREATE TABLE Victor_Models ( 
 5  #     name varchar(1024), 
 6  #     objective varchar(1024),  
 7  #     objective_item varchar(1024), 
 8  #     gradient varchar(1024), 
 9  #     prox varchar(1024), 
10  #     model_type varchar(1024), 
11  #     data_type varchar(1024), 
12  #     PRIMARY KEY (name) 
13  # ); 
14  """ 
15  This class contains functions to build PostgreSQL string and query to insert Victor Models table. 
16  """ 
17   
18  victor_models = "VICTOR_MODELS" 
19   
20  # -- CREATE MODEL ell_two_model ( 
21  # --  objective_item = ell_two_item 
22  # --  model = float8[], data_type=(float8[],int) 
23  # --  gradient=ell_two_grad, prox=gradient 
24  # -- ) 
25 -def build_string_constant(v):
26 """ 27 Builds PostgreSQL string from the given string parameter 28 @type v: string 29 @param v: the string that will be used to build PostgreSQL string 30 31 @rtype: string 32 @return: returns 'v' (PostgreSQL string) 33 """ 34 if not v: 35 return "NULL" 36 else: 37 return ''.join(["'", v, "'"])
38
39 -def insert_to_victor_models(model_name, objective_all, objective_item,gradient, prox,model_type, data_type ):
40 """ 41 Constructs PostgreSQL query to insert given model to the victor models table 42 @type model_name: string 43 @param model_name: name of the model 44 @type objective_all: string 45 @param objective_all: objectivea ll 46 @type objective_item: string 47 @param objective_item: objective item 48 @type gradient: string 49 @param gradient: gradient 50 @type prox: string 51 @param prox: prox 52 @type model_type: string 53 @param model_type: type of the model 54 @type data_type: string 55 @param data_type: type of the data 56 57 @rtype: string 58 @return: returns insert query 59 """ 60 v = [model_name, objective_all, objective_item, model_type, data_type, gradient, prox] 61 vv = [build_string_constant(vi) for vi in v] 62 vals = ','.join(vv) 63 st = ["INSERT INTO ", victor_models, " VALUES (", vals, ");\n"] 64 return ''.join(st)
65 66 # -- we assume this is not another table name... we should add an extra field to be safe. 67 # CREATE TABLE ell_two_model_instance_table ( 68 # model_name varchar(1024), 69 # instance_name varchar(1024), 70 # model_instance_id int REFERENCES Victor_global_instances, 71 # data_query varchar(4096), 72 # serialized_model float8[], 73 # FOREIGN KEY (model_name) REFERENCES Victor_Models(name), 74 # PRIMARY KEY (instance_name) 75 # ); 76