Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

Commit 47a2b2cb authored by Anze Vavpetic's avatar Anze Vavpetic
Browse files

fixed a problem that occured if a mysql column contains strings with accents -...

fixed a problem that occured if a mysql column contains strings with accents - strings that differ only by accents are treated as equal by MySQL  when doing distinct on that column. added a workaround by doing distinct by looking at the binary values instead. also added pretty print for DBContext.
parent 1a015c90
from collections import defaultdict
import pprint
from django import forms
import mysql.connector as sql
......@@ -78,7 +79,6 @@ class DBContext:
self.pkeys[table] = pk
self.target_table = self.tables[0]
self.target_att = None
#self.target_att_val = None
con.close()
def update(self, postdata):
......@@ -135,16 +135,19 @@ class DBContext:
cursor = con.cursor()
for table, cols in self.cols.items():
self.col_vals[table] = {}
now=time.time()
for col in cols:
cursor.execute("SELECT DISTINCT `%s` FROM `%s`" % (col, table))
print str(table),str(col),str(time.time()-now)
self.col_vals[table][col] = [val for (val,) in cursor]
now=time.time()
cursor.execute("SELECT DISTINCT BINARY `%s`, `%s` FROM `%s`" % (col, col, table))
self.col_vals[table][col] = [val for (_,val) in cursor]
con.close()
def __repr__(self):
#import pprint
#return pprint.pformat((self.target_table, self.target_att, self.tables, self.cols, self.connected, self.pkeys, self.fkeys))
return 'fkeys : ' + str(self.fkeys)
return pprint.pformat({
'target_table' : self.target_table,
'target attribute' : self.target_att,
'tables' : self.tables,
'cols' : self.cols,
'connected' : self.connected,
'pkeys' : self.pkeys,
'fkeys' : self.fkeys
})
......@@ -188,8 +188,6 @@ class Orange_Converter(Converter):
Returns the target table as an orange example table.
'''
import orange
import string
from mysql.connector import FieldType
table, cls_att = self.db.target_table, self.db.target_att
cols = self.db.cols[table]
attributes, metas, classVar = [], [], None
......@@ -197,7 +195,7 @@ class Orange_Converter(Converter):
att_type = self.orng_type(col)
if att_type == 'd':
att_vals = self.db.col_vals[table][col]
att_var = orange.EnumVariable(str(col), values=[str(val).encode('ascii', 'ignore') for val in att_vals])
att_var = orange.EnumVariable(str(col), values=[str(val) for val in att_vals])
elif att_type == 'c':
att_var = orange.FloatVariable(str(col))
else:
......@@ -215,14 +213,10 @@ class Orange_Converter(Converter):
for meta in metas:
domain.addmeta(orange.newmetaid(), meta)
dataset = orange.ExampleTable(domain)
aa=[a for a in domain.attributes[1].values if a[0]=="G" and len(a)>2 and a[1]=="o"and a[2]=="n"]
#print domain['last_name'].values
print 'Gonzalez' in [a.name for a in domain['last_name'].values]
for row in self.db.rows(table, cols):
example = orange.Example(domain)
for col, val in zip(cols, row):
example[str(col)] = str(val).encode('ascii', 'ignore')
example[str(col)] = str(val)
dataset.append(example)
return dataset
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment