def OnListCtrl1ListItemSelected(self, event): #print "selected" self.item_courant = event.m_itemIndex #self.lig_donnees = donnees[self.item_courant]['nom'] db = getdata.query("select nom from Popu") #print db.data[self.item_courant]['nom'] self.lig_donnees = db.data[self.item_courant]['nom']
def __init__(self, parent): self._init_ctrls(parent) #self._init_utils(parent) #self.lig_donnees = () db = getdata.query("select nom,nom_commun,male,femelle from Popu") index = 0 i=0 self.listCtrl1.Show(True) nop=0 taillefish=(195,120,40,40,40) for item in db.fields: nop=nop+1 self.listCtrl1.InsertColumn(index,item[0].replace("_"," "),width=taillefish[(nop-1)]) index += 1 self.listCtrl1.InsertColumn((index+1), "Total",width=taillefish[(nop)]) nop=0 nopold=9 for row in range(len(db.data)): nop=nop+1 for col in range(len(db.data[row])): values = db.data[row][col] if nop!=nopold : nopold=nop self.listCtrl1.InsertStringItem((nop-1), str(values)) else: self.listCtrl1.SetStringItem(row, col, str(values)) self.listCtrl1.SetStringItem(row, (col+1), str(values+db.data[row][(col-1)]))
def _init_ctrls(self, prnt): # generated method, don't edit wx.Frame.__init__(self, id=wxID_MAINFRAME, name=u'Mainframe', parent=prnt, pos=wx.Point(178, 126), size=wx.Size(794, 599), style=wx.DEFAULT_FRAME_STYLE, title='Frame1') self._init_utils() self.SetClientSize(wx.Size(786, 571)) self.staticBitmap1 = wx.StaticBitmap(bitmap=wx.NullBitmap, id=wxID_MAINFRAMESTATICBITMAP1, name='staticBitmap1', parent=self, pos=wx.Point(16, 56), size=wx.Size(440, 272), style=0) self.textCtrl1 = wx.TextCtrl(id=wxID_MAINFRAMETEXTCTRL1, name='textCtrl1', parent=self, pos=wx.Point(488, 48), size=wx.Size(100, 21), style=0, value='textCtrl1') self.textCtrl2 = wx.TextCtrl(id=wxID_MAINFRAMETEXTCTRL2, name='textCtrl2', parent=self, pos=wx.Point(680, 48), size=wx.Size(100, 21), style=0, value='textCtrl2') self.textCtrl3 = wx.TextCtrl(id=wxID_MAINFRAMETEXTCTRL3, name='textCtrl3', parent=self, pos=wx.Point(488, 88), size=wx.Size(100, 21), style=0, value='textCtrl3') self.textCtrl4 = wx.TextCtrl(id=wxID_MAINFRAMETEXTCTRL4, name='textCtrl4', parent=self, pos=wx.Point(680, 88), size=wx.Size(100, 21), style=0, value='textCtrl4') self.textCtrl5 = wx.TextCtrl(id=wxID_MAINFRAMETEXTCTRL5, name='textCtrl5', parent=self, pos=wx.Point(680, 128), size=wx.Size(100, 21), style=0, value='textCtrl5') self.bitmapButton1 = wx.BitmapButton(bitmap=wx.NullBitmap, id=wxID_MAINFRAMEBITMAPBUTTON1, name='bitmapButton1', parent=self, pos=wx.Point(488, 128), size=wx.Size(24, 24), style=wx.BU_AUTODRAW) self.listCtrl1 = wx.ListCtrl(id=wxID_MAINFRAMELISTCTRL1, name='listCtrl1', parent=self, pos=wx.Point(16, 336), size=wx.Size(440, 208), style=wx.LC_ICON) db = getdata.query("select * from Popu") index = 0 i=0 #for i in db: # self.listCtrl1.InsertStringItem(index, item[0]) # index += 1 self.listCtrl1.InsertStringItem(0, "George") self.listCtrl1.SetStringItem(0, 1, "1234ABC") self.listCtrl1.SetStringItem(0, 2, "100 Maple Ave.") self.listCtrl1.SetStringItem(0, 3, "New York")
def OnListCtrl1LeftDclick(self, event): #nomfiche = globalfunc.Fiche(self,"poisson",self.lig_donnees) donn = self.lig_donnees requete = "SELECT nom , descripteur , famille , synonyme , taille , origine , temperature , PH , durete , zone , description , vie , comportement , reproduction , dimorphisme , url FROM Fiche_POISSON WHERE nom LIKE '" + donn + "'" db = getdata.query(requete) donnees = db.data msg="\n" nop=0 for item in db.fields: msg=msg + item[0].replace("_"," ") + " : " try: msg=msg + donnees[0][nop] except : msg=msg + "\n" nop=nop+1 msg=msg + "\n\n" dlg = wx.lib.dialogs.ScrolledMessageDialog(self, msg, "Fiche du Poisson") dlg.Show()
from sklearn.feature_extraction.text import CountVectorizer from sklearn.feature_extraction.text import TfidfTransformer from sklearn.feature_extraction.text import TfidfVectorizer from sklearn import svm from sklearn import tree from getdata import query from sklearn.linear_model import LogisticRegression from sklearn.ensemble import VotingClassifier from sklearn.naive_bayes import MultinomialNB from sklearn.ensemble import RandomForestClassifier from sklearn.neighbors import KNeighborsClassifier if __name__ == '__main__': sql1 = "select * from trainmessage limit 0,700" #训练数据 sql2 = "select * from trainmessage limit 699,300" #测试数据 train = query(sql1) test = query(sql2) count_v1 = CountVectorizer() counts_train = count_v1.fit_transform(train[0]) # 得到词频矩阵 transformer = TfidfTransformer( ) # Transform a count matrix to a normalized tf or tf-idf representation tfidf_train = transformer.fit_transform(counts_train) # 得到频率矩阵 counts_test = count_v1.transform(test[0]) # fit_transform是将文本转为词频矩阵 # print(counts_test) tfidf_test = transformer.transform(counts_test) # fit_transform是计算tf-idf ####KNN算法 knnclf = KNeighborsClassifier() knnclf.fit(tfidf_train, train[1])
# -*- coding: cp1252 -*- import re, urllib, getdata, html2text, time #time.sleep(60) rown=0 casereq=("descripteur","famille","synonyme","taille","origine","temperature","PH","durete","zone","description","vie","comportement","reproduction","dimorphisme") while rown < 1199 : #while rown < 938 : rown=rown+1 requete = getdata.query("select url from Fiche_POISSON where id = " + str(rown)) bcl=0 htmlsanschar="<strong>Désolé 82.xxx.xxx.xxx, le site est en cours de maintenance...</strong><br/><small>Revenez dans 30 secondes.</small>" bibi = re.findall('</strong><br/><small>(.*?)</small>',htmlsanschar) try: while bibi[0] == "Revenez dans 30 secondes." : print requete.data[0][0] htmlSource = urllib.urlopen(requete.data[0][0]).read() htmlsanschar = htmlSource.replace("\n"," ") print htmlsanschar bibi = re.findall('</strong><br/><small>(.*?)</small>',htmlsanschar) try: if bibi[0] == "Revenez dans 30 secondes." : print "sleeping begin at id " + str(rown) time.sleep(31) print "sleeping end" except : print "IOerror"
htmlSource = urllib.urlopen("http://www.aquabase.org/fish/dump.php3").read() listeDeLiens = re.findall('">(.*?)</A>', htmlSource) listeDeLiensurl = re.findall('<A HREF="(.*?)">', htmlSource) nop = 0 for lien in listeDeLiens: nop = nop + 1 if nop != 1: # print lien # print listeDeLiensurl[(nop-1)] print( "INSERT INTO Fiche_POISSON ( id , nom , url ) VALUES ( " + str(nop - 1) + " , '" + lien + "' , 'http://www.aquabase.org" + listeDeLiensurl[(nop - 1)] + "' ) " ) getdata.query( "INSERT INTO Fiche_POISSON ( id , nom , url ) VALUES ( " + str(nop - 1) + " , '" + lien + "' , 'http://www.aquabase.org" + listeDeLiensurl[(nop - 1)] + "' ) " )