def get_count_domain(): bd = DB() data = bd.Ejecuta( "SELECT idDomain,COUNT(idDomain) AS c FROM consolidatedpagescrawl GROUP BY idDomain" ) bd.cierra() return data
def save_page_optz(idPositions, urlDomain, optzUrl, optzTitle, optzH1, PA): bd = DB() bd.Ejecuta( """insert into consolidatedpagescrawl (idPositions, isHomePage, urlOptz, titleTagOptz, h1Optz, pageAuthority) values(%s,%s,%s,%s,%s,%s)""" % (idPositions, urlDomain, optzUrl, optzTitle, optzH1, PA)) bd.cierra()
def AgregaPreguntaA(email, clave, idtexto): bd = DB(nombrebd="aprende") usuario = login(email, clave, bd) resp = {} if usuario: if duenoPagina(idtexto, bd) == usuario['ID']: rows = bd.Ejecuta( "select orden from preguntas where idtexto=%s order by orden desc limit 1" % idtexto) orden = 1 if rows: orden = rows[0]['orden'] + 1 bd.Ejecuta( "insert into preguntas (idtexto, orden) values(%s, %s)" % (idtexto, orden)) idpregunta = bd.UltimoID() bd.Ejecuta( "insert into posibles (idpregunta, texto) values(%s, 'A')" % idpregunta) bd.Ejecuta( "insert into posibles (idpregunta, texto) values(%s, 'B')" % idpregunta) bd.Ejecuta( "insert into posibles (idpregunta, texto) values(%s, 'C')" % idpregunta) resp['id'] = idpregunta resp['preguntas'] = leePreguntas(idtexto, bd) bd.cierra() return resp
def get_terms_for_vol(): bd = DB() querys = bd.Ejecuta( "SELECT id, term,googleState FROM terms WHERE googleState = 1 LIMIT 0, 900" ) bd.cierra() return querys
def get_page_data(idPositions): bd = DB() data = bd.Ejecuta( "select position, type, text from pagescrawl where idPositions=" + str(idPositions)) bd.cierra() return data
def save_tags(tags): bd = DB() for a in tags: bd.Ejecuta( """insert into pagescrawl (idPositions, position, type, text) values(%s,%s,"%s","%s")""" % (a[0], a[1], a[2].encode("utf-8"), a[3].encode("utf-8"))) bd.cierra()
def get_page_optz(): bd = DB() toDo = bd.Ejecuta( """SELECT positions.id AS idPositions, positions.term, positions.url FROM positions JOIN pagescrawltext ON positions.id = pagescrawltext.idPositions LEFT JOIN consolidatedpagescrawl ON consolidatedpagescrawl.idPositions=pagescrawltext.idPositions LEFT JOIN badurl ON positions.id = badurl.idPositions WHERE badurl.id IS NULL AND pagescrawltext.idPositions IS NOT NULL AND consolidatedpagescrawl.id IS NULL""") # done = bd.Ejecuta("SELECT idPositions FROM consolidatedPagescrawl GROUP BY idPositions") # badUrl = bd.Ejecuta("SELECT idPositions FROM badurl WHERE fix = 0 GROUP BY idPositions") # for a in done: # for b in toDo: # if a["idPositions"] == b["idPositions"]: # toDo.remove(b) # break # for a in badUrl: # for b in toDo: # if a["idPositions"] == b["idPositions"]: # toDo.remove(b) # break bd.cierra() if toDo: return toDo else: return []
def saveScore(file_train, file_test, inputs, hiddens, epochs, score, seg, struc, weights): w = ''.join(['%.10f,' % num for num in weights])[:-1] #Get rid of the last comma db = DB("didi") db.exe("""INSERT INTO score (file_train, file_test, inputs, hiddens, epochs, score, seg, DATETIME, struct, weights) VALUE ('%s', '%s', '%s', '%s', '%s', '%s', '%s', SYSDATE(), '%s', '%s')""" % (file_train, file_test, inputs, hiddens, epochs, score, seg, struc, w)) db.close()
def train_district_multi2(multi): district_id, days_before, fungap, table_test_name, scene_id = multi db = DB("didi") table_results = read_table(table_test_name, district_id, db) table_test = read_table("diditest.gaps", district_id, db) table_source = read_table("gaps", district_id, db) save_case(district_id, [1]) save_l(district_id, 0) save_score(district_id, 1) save_case_gap(district_id, [1]) save_l_2(district_id, 0) print "train_district", district_id for n in xrange(1, 11): list_cases2(district_id, table_results, table_source, table_test, days_before, fungap, (50*n)*n) what_cases(district_id, table_results, table_source, table_test, days_before, fungap, (50*n)*n) # clean_case(district_id, table_results, table_source, table_test, days_before, fungap) score = testdist(table_results, table_test)# 0.47167 es con 1, 0.471369268265 cases = read_case(district_id) db.exe("insert into districts_score (district_id, scene_id, score, cases) values (%s, %s, %s, '%s')" % (district_id, scene_id, score, cases)) db.close() print "#### Scene final score ####" print str(district_id), str(scene_id), str(score)
def train_district(district_id, days_before, fungap, table_test_name, scene_id): db = DB("didi") results = read_table(table_test_name, district_id, db) # gaps to calculate real = read_table("diditest2.gaps", district_id, db) # real gaps source = read_table("diditest2.gaps", district_id, db) # gaps to sieve # algorithm # results -> look in source -> sieve with cases -> results # ^ # ! # test results with real -> modify cases save_case(district_id, [1]) save_l(district_id, 0) save_score(district_id, 1) print "train_district", district_id for n in xrange(1, 21): list_cases(district_id, results, source, real, days_before, fungap, 50*n) clean_case(district_id, results, source, real, days_before, fungap) score = test_district(results, real)# 0.47167 es con 1, 0.471369268265 cases = read_case(district_id) db.exe("insert into districts_score (district_id, scene_id, score, cases) values (%s, %s, %s, '%s')" % (district_id, scene_id, score, cases)) db.close() print "#### Scene final score ####" print district_id, scene_id, score
def get_count_positions(): bd = DB() data = bd.Ejecuta("""SELECT COUNT(positions.id) AS c FROM positions JOIN consolidatedpagescrawl ON positions.id = consolidatedpagescrawl.idPositions""" ) bd.cierra() return data[0]["c"]
def AgregaCuentaF(email, clave, datos): bd = DB(nombrebd="myfinan") usuario = loginf(email, clave, bd) if usuario: AgregaCuenta(usuario["IDcliente"], datos["nombre"], bd) bd.cierra() return None
def readweights(IDnet): db = DB(name="nn") rows = db.exe("select * from weights where IDnet=%s" % IDnet) if rows: ws = rows[0]['weights'].split(",") n = np.array(map(float, ws)) struc = eval(rows[0]["struct"]) return n, struc
def readweights_didi(IDnet): db = DB(name="didi") rows = db.exe("select struct, weights, score from score where id=%s" % IDnet) if rows: ws = rows[0]['weights'].split(",") n = np.array(map(float, ws)) struc = eval(rows[0]["struct"]) return n, struc, rows[0]["score"]
def LeeProductoP(idprov, idproducto): bd = DB(nombrebd="textos") tabla = "prod%s" % idprov rows = bd.Ejecuta("select * from %s where id='%s'" % (tabla, idproducto)) if rows: return rows[0] bd.cierra()
def LeeUltTextoJ(num): bd = DB(nombrebd="textos") # rows = bd.Ejecuta("select * from docs where num=%s"%num) rows = bd.Ejecuta( "select parrafos.* from parrafos inner join docs on docs.id=parrafos.iddoc where num=%s" % num) bd.cierra() return rows
def save_suggested(idTerm, query, suggested): bd = DB() for a in suggested: bd.Ejecuta( """insert into suggesteds (idTerm,term, position, suggested, date) values(%s,"%s",%s,"%s", UTC_TIMESTAMP())""" % (idTerm, query.encode("utf-8"), a["position"], a["suggested"].encode("utf-8"))) bd.cierra()
def check_domain(domain): bd = DB() data = bd.Ejecuta("SELECT id FROM domains WHERE url='" + domain + "'") bd.cierra() if data: return data[0] else: return []
def EliminaCuentaF(email, clave, datos): bd = DB(nombrebd="myfinan") usuario = loginf(email, clave, bd) if usuario: EliminaCuenta(datos["IDcuenta"], bd) bd.cierra() return None
def EliminaMovimientoF(email, clave, IDmovimiento): bd = DB(nombrebd="myfinan") usuario = loginf(email, clave, bd) if usuario: if ChequeaUsuarioMovimiento(IDmovimiento, usuario, bd): bd.Ejecuta("delete from movimientos where ID=%s" % IDmovimiento) bd.cierra()
def ModificaMovF(email, clave, datos): bd = DB(nombrebd="myfinan") usuario = loginf(email, clave, bd) if usuario: ModificaMov(datos, bd) bd.cierra() return None
def LoginF(email, clave): bd = DB(nombrebd="myfinan") usuario = loginf(email, clave, bd) if usuario: bd.cierra() return usuario bd.cierra() return None
def AgregaMovimientoF(email, clave, datos): bd = DB(nombrebd="myfinan") usuario = loginf(email, clave, bd) if usuario: if ChequeaUsuarioCuenta(datos["IDcuentamas"], usuario, bd) and ChequeaUsuarioCuenta(datos["IDcuentamenos"], usuario, bd): bd.Ejecuta("insert into movimientos (IDusuario, IDcuentamas, IDcuentamenos, concepto, valor, fecha) values(%s,%s,%s,'%s',%s,'%s')" % (usuario["ID"], datos["IDcuentamas"], datos["IDcuentamenos"], datos["concepto"], datos["valor"], datos["fecha"])) bd.cierra()
def save_positions(idTerm, query, positions): bd = DB() for a in positions: bd.Ejecuta( """insert into positions (idTerm, term, position, title, url, description, date) values(%s,"%s", %s,"%s","%s","%s", UTC_TIMESTAMP())""" % (idTerm, query.encode("utf-8", 'replace'), a["position"], a["title"].encode("utf-8", 'replace'), a["url"].encode("utf-8"), a["description"].encode("utf-8", 'replace'))) bd.cierra()
def get_url_for_domain(): bd = DB() data = bd.Ejecuta( """SELECT positions.id AS idPositions, positions.url, consolidatedpagescrawl.pageAuthority, positions.title FROM positions JOIN consolidatedpagescrawl ON consolidatedpagescrawl.idPositions = positions.id AND consolidatedpagescrawl.idDomain = 0""" ) bd.cierra() return data
def save_statistic(statistic): list = statistic.keys() bd = DB() for d in list: bd.Ejecuta( "REPLACE into statistic (idTerm,nightmare,hardcore,hard,medium,easy) values(%s,%s,%s,%s,%s,%s) " % (int(d), int(statistic[d]["nightmare"]), int(statistic[d]["hardcore"]), int(statistic[d]["hard"]), int(statistic[d]["medium"]), int(statistic[d]["easy"]))) bd.cierra()
def save_terms(data): bd = DB() for d in data: bd.Ejecuta("""INSERT INTO terms (term) SELECT * FROM (SELECT '%s') AS tmp WHERE NOT EXISTS ( SELECT term FROM terms WHERE term = '%s' ) LIMIT 1; """ % (d.encode("utf-8"), d.encode("utf-8"))) bd.cierra()
def ModificaNivelA(email, clave, idtexto, nivel): bd = DB(nombrebd="aprende") usuario = login(email, clave, bd) if usuario: if duenoPagina(idtexto, bd) == usuario['ID']: bd.Ejecuta("update paginas set idnivel=%s where id=%s" % (nivel, idtexto)) bd.cierra() return None
def GrabaNodoRuta(email, ip, funcion, pag): bd = DB() usuario = bd.Ejecuta("select * from usuarios where email=%s" % email) if usuario: usuario = usuario[0] else: usuario = dict() usuario["ID"]=0 bd.Ejecuta("insert into rutas (IDusuario, ip, funcion, pag, fecha) values (%s,'%s','%s','%s',sysdate())" % (usuario["ID"], ip, funcion, pag)) bd.cierra()
def LeePaginasA(email, clave, idcuaderno): bd = DB(nombrebd="aprende") usuario = login(email, clave, bd) response = {} if usuario: if usuario['modo'] == 'E': response["paginas"] = bd.Ejecuta( "select *, id as ID, titulo as nombre from paginas where idcuaderno=%s order by nombre" % idcuaderno) bd.cierra() return response
def get_data_terms(): bd = DB() data = bd.Ejecuta( """SELECT positions.idTerm, (consolidatedpagescrawl.isHomePage + consolidatedpagescrawl.titleTagOptz + consolidatedpagescrawl.urlOptz + consolidatedpagescrawl.h1Optz + domains.authority) AS score FROM consolidatedpagescrawl JOIN domains ON domains.id = consolidatedpagescrawl.idDomain JOIN positions ON positions.id = consolidatedpagescrawl.idPositions""" ) bd.cierra() return data
def MovimientosF(email, clave, IDcuenta, desde, hasta, tags): bd = DB(nombrebd="myfinan") usuario = loginf(email, clave, bd) if usuario: tags = tags.split(",") response = MovimientosPeriodo(IDcuenta, desde, hasta, tags, usuario, bd) bd.cierra() return response bd.cierra() return None
def LeeCuentasF(email, clave): bd = DB(nombrebd="myfinan") usuario = loginf(email, clave, bd) if usuario: response = {} response["cuentas"] = bd.Ejecuta("select ID, nombre from cuentas where IDcliente=%s" % usuario["IDcliente"]) response["usuario"] = usuario bd.cierra() return response bd.cierra() return None
def YearsF(email, clave): bd = DB(nombrebd="myfinan") usuario = loginf(email, clave, bd) if usuario: response = {} response["datos"] = Years(usuario["IDcliente"], bd) response["usuario"] = usuario bd.cierra() return response bd.cierra() return None
def CuentasEditorF(email, clave): bd = DB(nombrebd="myfinan") usuario = loginf(email, clave, bd) if usuario: response = {} response["datos"] = CuentasEditor(usuario, bd) response["usuario"] = usuario bd.cierra() return response bd.cierra() return None
def EliminaPosibleA(email, clave, idposible): bd = DB(nombrebd="aprende") resp = None usuario = login(email, clave, bd) if usuario: idtexto, idpregunta = idtexto_idpregunta(idposible, bd) if idtexto: if duenoPregunta(idpregunta, bd) == usuario['ID']: bd.Ejecuta("delete from posibles where id=%s" % idposible) resp = leePreguntas(idtexto, bd) bd.cierra() return resp
def EntradasySalidasF(email, clave, fecha, IDcuenta): bd = DB(nombrebd="myfinan") usuario = loginf(email, clave, bd) if usuario: desde, hasta = periodo(fecha) response = {} response["entradas"] = Entradas(IDcuenta, desde, hasta, bd) response["salidas"] = Salidas(IDcuenta, desde, hasta, bd) bd.cierra() return response; bd.cierra() return None
def get_url2(): bd = DB() toDo = bd.Ejecuta("""SELECT positions.id AS idPositions, positions.url FROM positions LEFT JOIN pagescrawltext ON pagescrawltext.idPositions = positions.id LEFT JOIN badurl ON badurl.idpositions = positions.id WHERE pagescrawltext.id IS NULL AND badurl.id IS NULL LIMIT 0, 500""") if toDo: return toDo else: return [] bd.cierra()
def GrabaRespuestaA(request): bd = DB(nombrebd="aprende") email = request.forms.get('email') clave = request.forms.get('clave') usuario = login(email, clave, bd) if usuario: idpregunta = request.forms.get('idpregunta') idrespuesta = request.forms.get('idrespuesta') # print("update preguntas set idrespuesta=%s where id=%s"%(idrespuesta, idpregunta)) if duenoPregunta(idpregunta, bd) == usuario['ID']: bd.Ejecuta("update preguntas set idrespuesta=%s where id=%s" % (idrespuesta, idpregunta)) bd.cierra() return None
def CuentasF(email, clave, fecha): bd = DB(nombrebd="myfinan") usuario = loginf(email, clave, bd) if usuario: desde, hasta = periodo(fecha) response = {} response["datos"] = Cuentas(desde, hasta, usuario, bd) response["usuario"]=usuario bd.cierra() return response; bd.cierra() return None
def ModificaPreguntaA(request): bd = DB(nombrebd="aprende") email = request.forms.get('email') clave = request.forms.get('clave') usuario = login(email, clave, bd) if usuario: idpregunta = request.forms.get('idpregunta') if duenoPregunta(idpregunta, bd) == usuario['ID']: texto = request.forms.get('texto') bd.Ejecuta("update preguntas set texto='%s' where id=%s" % (texto, idpregunta)) bd.cierra() return None
def GrabaTextoA(request): bd = DB(nombrebd="aprende") email = request.forms.get('email') clave = request.forms.get('clave') usuario = login(email, clave, bd) if usuario: idtexto = request.forms.get('idtexto') if duenoPagina(idtexto, bd) == usuario['ID']: upload = request.files.get('texto') texto = upload.file.read().decode() bd.Ejecuta("update paginas set texto='%s' where id=%s" % (texto, idtexto)) bd.cierra() return None
def LeeCliP(telefono): bd = DB(nombrebd="textos") rows = bd.Ejecuta("select * from cli where telefono='%s'" % telefono) if not rows: bd.Ejecuta("insert into cli (telefono) values ('%s')" % telefono) bd.commit() rows = bd.Ejecuta("select * from cli where telefono='%s'" % telefono) if rows: response = {} response['cli'] = rows[0] response['prov'] = bd.Ejecuta( "select *, id as ID from prov where activo=1 order by nombre") return response bd.cierra()
def train_district(district): district_id = district["district_id"] db = DB("didi") save_case(district_id, [1]) save_l(district_id, 0) save_score(district_id, 1) print "train_district", district_id for n in xrange(0, 3): list_cases(district, 20, db) clean_case(district, db) print score = testdist("results_test_roma", district_id, db) # 0.47167 es con 1, 0.471369268265 cases = read_case(district_id) db.exe("update districts set score=%s, cases='%s', complex=%s where district_id=%s" % (score, cases, len(cases), district_id)) db.commit() print "#### Final score ####" print district_id, score
def DespacharP(email, clave, idtextosdo): bd = DB(nombrebd="textos") usuario = login(email, clave, bd) if usuario: bd.Ejecuta("update pedicab set pendiente=0 where id=%s" % idpedido) usuario["pendientes"] = bd.Ejecuta(""" select *, telefono, direccion, pedicab.id as ID, 'X' as despachar from pedicab inner join cli on cli.id=pedicab.idcli where idprov=%s and pendiente=1 """ % usuario['id']) bd.cierra() return usuario bd.cierra() return None
def AgregaClienteF(email, clave, lang, datos): bd = DB(nombrebd="myfinan") usuario = loginf(email, clave, bd) if usuario: bd.cierra() return "ok" else: rows = bd.Ejecuta("select * from usuarios where email='%s'" % email) if rows: bd.cierra() return "existe" else: if datos["d1"]=="*****@*****.**" and datos["d2"]=="gtienda": resp = AgregaCliente(email, clave, lang, datos, bd) bd.cierra() return resp bd.cierra()
def querys_done(): bd = DB() querysDone = bd.Ejecuta("SELECT idTerm FROM positions GROUP BY idTerm") if querysDone: for a in querysDone: bd.Ejecuta("""update terms set state=%s where id = %s """ % (0, int(a["idTerm"]))) bd.cierra()
def EnviarPedP(datos): bd = DB(nombrebd="textos") tabla = "prod%s" % datos['idprov'] bd.Ejecuta( "insert into juricab (idprov, idcli, fecha) values(%s, %s, now())" % (datos['idprov'], datos['idcli'])) idped = bd.UltimoID() s = 0 for row in datos['ped']: bd.Ejecuta( "insert into pedidet (idpedicab, idproducto, cantidad, precio) values(%s, %s, %s, %s)" % (idped, row['id'], row['cantidad'], row['precio'])) s += float(row['cantidad']) * float(row['precio']) bd.Ejecuta("update pedicab set valor=%s where id=%s" % (s, idped)) bd.cierra()
def train_district(district): coment = "con 1, days 14, prom" district_id = district["district_id"] db = DB("didi") table_results = read_table("results_test_roma", district_id, db) table_test = read_table("diditest.gaps", district_id, db) table_source = read_table("gaps", district_id, db) save_case(district_id, [1]) save_l(district_id, 0) save_score(district_id, 1) print "train_district", district_id for n in xrange(0, 20): list_cases(district, table_results, table_source, table_test, 50) clean_case(district, table_results, table_source, table_test) score = testdist(table_results, table_test)# 0.47167 es con 1, 0.471369268265 cases = read_case(district_id) db.exe("insert into districts_score (district_id, score, cases, coment) values (%s, %s, '%s', '%s')" % (district_id, score, cases, coment)) db.commit() print "#### Final score ####" print district_id, score
def Login(email, clave): bd = DB(nombrebd="textos") usuario = login(email, clave, bd) if usuario: bd.cierra() return usuario bd.cierra() return None
def querys_done2(): bd = DB() querysDone = bd.Ejecuta("select term from positions group by term") if querysDone: for a in querysDone: bd.Ejecuta( """update terms set term="%s", state=%s where term = "%s" """ % (a["term"].encode("utf-8"), 0, a["term"].encode("utf-8"))) bd.cierra()
def train_district(district_id, days_before, fungap, table_test_name, scene_id): db = DB("didi") table_results = read_table(table_test_name, district_id, db) # gaps a calcular table_test = read_table("diditest.gaps", district_id, db) # real gaps table_source = read_table("diditest.gaps", district_id, db) # gaps to sieve # algorithm # results -> source -> real -> sieve -> results save_case(district_id, [1]) save_l(district_id, 0) save_score(district_id, 1) print "train_district", district_id for n in xrange(1, 21): list_cases(district_id, table_results, table_source, table_test, days_before, fungap, 10*n) clean_case(district_id, table_results, table_source, table_test, days_before, fungap) score = testdist(table_results, table_test)# 0.47167 es con 1, 0.471369268265 cases = read_case(district_id) db.exe("insert into districts_score (district_id, scene_id, score, cases) values (%s, %s, %s, '%s')" % (district_id, scene_id, score, cases)) db.close() print "#### Scene final score ####" print district_id, scene_id, score
def saveres(nn_params, X, struc, file_train): p = predict(nn_params, X, struc) S = bin_to_dec(p) X, y = readSamples(file_train) db = DB("didi") for i in range(len(X)): rows = db.exe("select date from results0 where weekday(date)=%s limit 1" % X[i,1]) db.exe("INSERT INTO results (district_id, date, slot, gap) VALUES ('%s', '%s', '%s', '%s')" % (X[i, 0], rows[0]["date"], X[i, 2], S[i] )) db.close()
case.remove(case[count]) update2("results_test_roma", district_id, db, case) score = testdist("results_test_roma", district_id, db) if score <= best_score: best_score = score save_score(best_score) best_case = list(case) save_case(best_case) else: case = list(best_case) count += 1 print iter+1, best_score, score, "cuantos if:", len(best_case) if __name__ == '__main__': db = DB("didi") district_id = 2 # row = db.exe("select * from gaps where district_id=%s and date='%s' and slot=%s" % (51, "2016-01-19", 47))[0] # print estimate(row, -0.5, db) # update("results_send", db) # case = read_case() # update2("results_send", db, case) # update2("results_test_roma", db, case) districts = db.exe("select district_id from districts order by district_id") for dist in districts: save_case([1]) save_l(0) save_score(1) district_id = dist["district_id"] for n in xrange(0, 20):
''' Created on 06/06/2016 @author: botpi ''' from result9 import * from apiDB import DB from apididi import test_table from modresult import * import result9 if __name__ == '__main__': print "start" db = DB("didi") #results_name = "results_send" # para enviar results_name = "results_test" # para probar envio districts = db.exe("select district_id from districts where district_id=37 order by district_id") for district in districts: district_id = district["district_id"] days_before, cases, fungap, resuls_name_x, source_name = best_case(district_id, db) fungap = getattr(result9, fungap) source = read_table(source_name, district_id, db) results = read_table(results_name, district_id, db) sieve_district(results, source, days_before, cases, fungap) update_table(district_id, results_name, results, db) print district_id, test_table_district(results_name, district_id, db)
save_score(district_id, 1) print "train_district", district_id for n in xrange(0, 3): list_cases(district, 20, db) clean_case(district, db) print score = testdist("results_test_roma", district_id, db) # 0.47167 es con 1, 0.471369268265 cases = read_case(district_id) db.exe("update districts set score=%s, cases='%s', complex=%s where district_id=%s" % (score, cases, len(cases), district_id)) db.commit() print "#### Final score ####" print district_id, score if __name__ == '__main__': db = DB("didi") district_id = 2 # update("results_send", db) # case = read_case() # update2("results_send", db, case) # update2("results_test_roma", db, case) districts = db.exe("select district_id, 7 as days_before from districts order by district_id") # for i in xrange(0,len(districts)): # districts[i]["db"] = DB("didi") #pool = Pool(processes=10) print "Running..." train_district(districts[52]) #pool.map(train_district, districts)
''' Created on 28/05/2016 @author: botpi ''' from apiDB import DB db = DB("didi") rows = db.exe("select * from results_send") for row in rows: if row["date"]=="2016-01-30": date = "2016-01-16" else: dt = row["date"].split("-") m = "00%s" % (int(dt[2]) - 7) date = "%s-%s-%s" % (dt[0], dt[1], m[-2:]) g = db.exe("select gap from gaps where district_id=%s and date='%s' and slot=%s" % (row["district_id"], date, row["slot"]) ) # if row["date"]=="2016-01-30": # pass # print row gap = 1 if g: if g[0]["gap"] > gap: gap = g[0]["gap"] db.exe("update results_send set gap=%s where district_id=%s and date='%s' and slot=%s"
case.remove(case[count]) case = update2("results_test_roma", db, case) score = test("results_test_roma", db) if score <= best_score: best_score = score save_score(best_score) best_case = list(case) save_case(best_case) else: case = list(best_case) count += 1 print iter+1, best_score, score, "cuantos if:", len(best_case) if __name__ == '__main__': db = DB("didi") # row = db.exe("select * from gaps where district_id=%s and date='%s' and slot=%s" % (51, "2016-01-19", 47))[0] # print estimate(row, -0.5, db) # update("results_send", db) # case = read_case() # update2("results_send", db, case) # update2("results_test_roma", db, case) for n in xrange(0,1): list_cases(5) #clean_case() print print "#### Final score ####" print test("results_test_roma", db) # 0.47167 es con 1, 0.471369268265 # save_send("results5.csv", db) #create_test(db) db.close()
print "train_district", district_id for n in xrange(1, 21): list_cases(district_id, table_results, table_source, table_test, days_before, fungap, 10*n) clean_case(district_id, table_results, table_source, table_test, days_before, fungap) score = testdist(table_results, table_test)# 0.47167 es con 1, 0.471369268265 cases = read_case(district_id) db.exe("insert into districts_score (district_id, scene_id, score, cases) values (%s, %s, %s, '%s')" % (district_id, scene_id, score, cases)) db.close() print "#### Scene final score ####" print district_id, scene_id, score if __name__ == '__main__': print "Running..." db = DB("didi") districts = db.exe("select district_id from districts order by district_id") scenes = db.exe("select * from scenes where active=1") for district in districts: for scene in scenes: train_district(district["district_id"], scene["days_before"], globals()[scene["fungap"]], scene["table_test"], scene["id"]) # train_district(district["district_id"], 7, globals()['read_gap'], "results_test_roma_3", "prueba5") #train_district(districts[52]) # for district in districts: # update2("results_send", "gaps", district["days_before"], case) # pool = Pool(processes=3) # pool.map(train_district, districts)
def saveweights(nn_params, struc, IDnet): w = ''.join(['%.10f,' % num for num in nn_params])[:-1] #Get rid of the last comma db = DB(name="nn") db.exe("insert into weights (IDnet, struct, weights) values (%s,'%s','%s')" % (IDnet, str(struc) , w)) db.close()