Python Forum
Trying to sort a MYSQL Database
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to sort a MYSQL Database
#1
Hello, (first of all sorry for my english, I'm french **biggrin** )

I have a database in MySQL with this table:

CREATE TABLE Tri(
id VARCHAR(200) PRIMARY KEY,
nom TEXT,
adresse TEXT,
CP TEXT,
ville TEXT,
details TEXT,
organisme_gest TEXT,
organisme_gest_associe TEXT,
tel TEXT,
web TEXT,
mail TEXT,
date_d TEXT,
horaire TEXT,
photo TEXT,
date_f TEXT,
handicap TEXT
);
This basicly is storing data for event in France. In details there is all the information about the event.
I actually use only the id and details in my program.

I want to sort the database using keywords. To do so i have an idea:

Creating the list of the keyword (already done):

#MC = ['route','autoroute','éclairage','public','parking','couvert','non','stationnement','rue','habitat',
#          'logement','transport','bus','metro','tramway','train','avion','piste','cyclable','aire','jeu','enfant',
#          'crêche','parentale','haltes','garderies','jardin','d\éveil','assistante maternelle',
#          'école maternelle','école élémentaire','collège','lycée professionel','lycée général','lycée technologi',
#          'lycée polyvalent','université','fac','campus','étudiant','centre','formation','sport','scolaire',
#          'loisir','école','centre','aéré','rythme','péri','extra','MDPH','CDAPH','IME','IEM','ITEP','SESSAD',
#          'FAM','SAVS','SAMSAH','ESAT','maladie','mentale','soin','infirmier','CLIC','aidant','EHPAD','alzheimer',
#          'pôle','accueil','familial','domicile','agé','CDD','senior','loisir','CHRS','hebergement','urgence','asile',
#          'femme','batue','addictologie','desintoxication','insertion','remobilisation','aide','alimentaire','colis',
#          'urgence','RSA','ASE','aide','socia','enfan','protection','enfance','CAF','allocation','famill','aide',
#          'devoir','soutien','MJC','maison','jeune','majeur','accès','soin','APL','résidence','universitaire',
#          'CLE','hebergement','scolaire','mission','locale','Crous','financ','bourse','pharmacie','médicament',
#          'santé','hôpita','hospital','clinique','ambulance','formation','sanitaire','toilette','douche',
#          'patrimoine','château','exposition','collection','musée','art','contemporain','cinéma','projection','film',
#          'télévision','reportage','salsa','tango','danse','hip-hop','bourrée','farandole','rock-and-roll','twist',
#          'valse','bal','musette','country','flamenco','concert','musique','hestiv\'oc','concert','musique','hestiv\'oc',
#          'opéra','théatre','cirque','artifice','illumination','pyrotechnie','pyromusical','carnaval','urbain','défilé',
#          'médiathèque','bibliothèque','livre','lecture','ludothèque','baseball','basket-ball','football',
#          'football américain','handball','hockey','pétanque','boulodrome','rugby','volley-ball','athlétisme',
#          'ball-trap','poing','billard','snooker','bowling','quille','echec','equitation','cheval','equestre',
#          'ecrime','fleuret','epée','gymnastique','musculation','haltérophilie','culturisme','javelot','pentathlon',
#          'roller','skate','roulette','pistolet','carabine','arc','triathlo','twirling','majorette','aikido','aikibudo',
#          'budo','boxe','ring','savate','full contact','judo','kendo','jujitsu','karaté','martiaux','kick','boxing',
#          'lutte','Muaythai','teakwondo','tai','chuan','gong','badminton','tambourin','paume','padel','pelote',
#          'pala','squash','tennis','pong','ping','aviron','canöe','kayak','char','voile','plongée','apnée','sous',
#          'marin','joute','sauvetage','nautique','motonautique','jetski','natation','nage','piscine','pêche','ski',
#          'nautique','surf','voile','aéromodélisme','aéronautique','aérostation','camarguaise','landaise','toromachie',
#          'cyclisme','cyclotourisme','giraviation','golf','escalade','motocyclisme','parachutisme','ULM','pédestre',
#          'sauvetage','secourisme','ski','spéléologie','automobile','glace','patinage','traineau','pulka','parapente',
#          'planeur','état','civil','fiscal','impôt','taxe','administation','numérique','démocratie','participative',
#          'participatif','assainissement','ATMO','déchêt','collecte','traitement','déchetterie','recyclage',
#          'gendarmerie','commisariat','police','municipale','sécurité','ASVP','SDIS','pompiers','parc','potager',
#          'lac','étang','rivière','marais','site','naturel','biodiversité','ENS','forêt','bois','point de vue',
#          'table d\'orientation','chemin','pédestre','propre','netto','énergie','chauffage','électricité',
#          'écologie','renouvable','durable','environnement','économie','innovation','commerc','artisan',
#          'fabication','tourisme','vin','gastronomie','emploi','chômage','job','recrute','entreprise','industrie',
#          'entreupreun','création','agricult','agricole','coopération','international']
And i want to count the occurence of every word in every details. Depending on the word that appears the most i will put the data in a new database(I can manage this part).

The only problem is how to do it efficiently? I've tried this program here:

QUERY="""SELECT details from Tri"""
cur.execute(QUERY)
#result est une liste contenant les détails
result_details=cur.fetchall()
QUERY="""SELECT id from Tri"""
cur.execute(QUERY)
#result est une liste contenant les id
result_id=cur.fetchall()
#On teste les mots clés un par un
MC = ['route',...,'international'] #as writen above
          
          
for i in result_details :
    #création d'un tableau: 1ère colonne: mot-clé 2ème colonne: nb d'occurence
    OCCUR=[0]*len(MC)
    for j in range(len(MC)-1):
        OCCUR[j] = i.count(MC[j])
#Distinction de tous les mots qui sont apparus un maximum de fois
    #Liste qui contient tous les mots apparus un maximum de fois
    MA=[]
    #Occurence du mot étant apparu un nombre maximal de fois
    occ=0
    for k in range(len(MC)-1):
        if OCCUR[k] > occ:
            occ = OCCUR[k]
            MA = [MC[k]]
        elif OCCUR[k] == occ:
            MA.append(MC[k])
But i tried to run the program for an entire night and it keep running....

In the end i don't know if the program is running properly and/or if I do it right!

Do you have any suggestions?

Thank you so much in advance :)
Reply


Messages In This Thread
Trying to sort a MYSQL Database - by PierreSoulier - Jul-04-2018, 08:39 AM
RE: Trying to sort a MYSQL Database - by Larz60+ - Jul-04-2018, 08:51 AM
RE: Trying to sort a MYSQL Database - by Larz60+ - Jul-04-2018, 09:20 AM
RE: Trying to sort a MYSQL Database - by Larz60+ - Jul-04-2018, 04:19 PM
RE: Trying to sort a MYSQL Database - by Larz60+ - Jul-05-2018, 10:23 AM
RE: Trying to sort a MYSQL Database - by Larz60+ - Jul-05-2018, 03:38 PM
RE: Trying to sort a MYSQL Database - by Larz60+ - Jul-06-2018, 11:14 AM
RE: Trying to sort a MYSQL Database - by micseydel - Jul-14-2018, 03:19 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Mysql and mysql.connector error lostintime 2 687 Oct-03-2023, 10:25 PM
Last Post: lostintime
Photo a.sort() == b.sort() all the time 3lnyn0 1 1,327 Apr-19-2022, 06:50 PM
Last Post: Gribouillis
  Mysql error message: Lost connection to MySQL server during query tomtom 6 16,127 Feb-09-2022, 09:55 AM
Last Post: ibreeden
  mySQL Database error not resolving. cybertooth 2 3,232 Aug-30-2021, 05:45 PM
Last Post: ibreeden
  SaltStack: MySQL returner save less data into Database table columns xtc14 2 2,181 Jul-02-2021, 02:19 PM
Last Post: xtc14
  Problem updating value in MySQL database dangermaus33 1 1,639 Nov-24-2020, 08:32 PM
Last Post: dangermaus33
  chatterbot utf-8 errors with mysql database isolatedastronaut 0 1,590 Nov-08-2020, 06:54 AM
Last Post: isolatedastronaut
  MYSQL how to assign a table for each user in my username table database? YoshikageKira 1 2,821 Dec-26-2019, 05:57 AM
Last Post: buran
  How to return value from a stored procedure of a MySQL database? UtiliseIT 0 2,339 Jul-22-2019, 10:14 AM
Last Post: UtiliseIT
  Need help saving data into MySQL database reezalaq 0 2,402 Jun-03-2018, 07:50 PM
Last Post: reezalaq

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020