IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Algorithmes et structures de données Discussion :

Fusionner des fichiers changelog


Sujet :

Algorithmes et structures de données

  1. #1
    Membre averti
    Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2003
    Messages
    302
    Détails du profil
    Informations personnelles :
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Distribution

    Informations forums :
    Inscription : Janvier 2003
    Messages : 302
    Points : 316
    Points
    316
    Par défaut Fusionner des fichiers changelog
    Salut à tous,

    J'ai 5 fichiers qui sont sous le format suivant :

    <tab> NomJour NumJour Mois Année
    <nombre arbitraire de lignes>
    <tab> NomJour NumJour Mois Année
    <nombre arbitraire de lignes>

    Le seul truc remarquable c'est que ce sont des blocks de lignes précédées par une ligne spécifique qui annonce la date (en début de block).

    J'aimerais que ces 5 fichiers soient fusionnées en un seul de tel sorte à ce que les blocks soient remis dans l'ordre chronologique

    Des idées ?

  2. #2
    Expert éminent sénior Avatar de Flodelarab
    Homme Profil pro
    Inscrit en
    Septembre 2005
    Messages
    5 243
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Charente (Poitou Charente)

    Informations forums :
    Inscription : Septembre 2005
    Messages : 5 243
    Points : 13 458
    Points
    13 458
    Par défaut
    Bonjour

    Citation Envoyé par yacinechaouche Voir le message
    Des idées ?
    Plein d'idées.

    Pour mettre dans l'ordre, on peut exprimer la date en secondes écoulées depuis l'epoch.
    Pour tronçonner en blocs, on peut prendre les fichiers à l'envers. La ligne de date permet de clore le bloc.

    Pourquoi ne le fais-tu pas à la main s'il y a seulement 5 fichiers ?
    Cette réponse vous apporte quelque chose ? Cliquez sur en bas à droite du message.

  3. #3
    Membre averti
    Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2003
    Messages
    302
    Détails du profil
    Informations personnelles :
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Distribution

    Informations forums :
    Inscription : Janvier 2003
    Messages : 302
    Points : 316
    Points
    316
    Par défaut
    Citation Envoyé par Flodelarab Voir le message
    Pourquoi ne le fais-tu pas à la main s'il y a seulement 5 fichiers ?
    Nom : CBDNtIj.jpg
Affichages : 167
Taille : 43,2 Ko

  4. #4
    Expert confirmé
    Avatar de anapurna
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2002
    Messages
    3 419
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Mai 2002
    Messages : 3 419
    Points : 5 818
    Points
    5 818
    Par défaut
    Salut

    donc tu veut fusionner les fichiers par ordre chronologique
    petite question est ce que les fichiers à fusionner le sont
    je veut dire

    il sont triés comme ceci
    Fichier A D1 ...D8
    Fichier B D9 ...D10
    Fichier C D11.. D15
    Fichier D D16 ..D18
    Fichier E D19 ..D20
    ou il sont plutôt comme cela
    Fichier A D1...D20
    Fichier B D1...D20
    Fichier C D1...D20
    Fichier D D1...D20
    Fichier E D1...D20
    la premier solution une concaténation de fichier est très facilement réalisable

    pour le second il va falloir parcourir les fichiers simultanément est les insérer au fur et à mesure dans un fichier résultant

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    Fonction LIREDATEFICHIER(FIC) :  Date
      SI FINFICHIER(FIC) ALORS
        RETOURNE  Aujourdhui()
      SINON 
         ST = LireLigne(FIC1)
         RETOURNE = TRANSFORMEENDATE(ST)
      FIN SI
    Fin Fonction 
     
    Fonction  LIREFICHIERJUSQUAPROCHAINEDATE(FIC)
      RES= ''
      FIN = FAUX
      TANSQUE  PAS(FIN) ET FINFICHIER(FIC) = FAUX FAIRE
        ST = LireLigne(FIC) 
        SI (ESTUNEDATE(ST) = FAUX) ALORS 
           RES = CONCATENATION(RES,ST);
           CHANGEDELIGNE(FIC) 
        SINON
           FIN = VRAI   
       FINSI
      FIN TANSQUE 
      RETOURNE  RES 
    FIN Fonction
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    FIN = FAUX
    TANSQUE PAS FIN FAIRE 
      DAT1 = LIREDATEFICHIER(FIC1)
      DAT2 = LIREDATEFICHIER(FIC2)
      DRMIN = (DAT1,DAT2,....)
      SI  DAT1 = DRMIN ALORS
          CHANGEDELIGNE(FIC1) 
         RES = LIREFICHIERJUSQUAPROCHAINEDATE(FIC1)
         AJOUTELIGNEDANSFICHIERRESULT(FICTMP,RES)
      FINSI 
      SI  DAT2 = DRMIN ALORS
         CHANGEDELIGNE(FIC2) 
         RES = LIREFICHIERJUSQUAPROCHAINEDATE(FIC2)
         AJOUTELIGNEDANSFICHIERRESULT(FICTMP,RES)
      FINSI 
      ....
       SI DRMIN = AUJOURDHUI ALORS
          FIN = VRAI
    FIN TANSQUE
    Nous souhaitons la vérité et nous trouvons qu'incertitude. [...]
    Nous sommes incapables de ne pas souhaiter la vérité et le bonheur, et sommes incapables ni de certitude ni de bonheur.
    Blaise Pascal
    PS : n'oubliez pas le tag

  5. #5
    Membre averti
    Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2003
    Messages
    302
    Détails du profil
    Informations personnelles :
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Distribution

    Informations forums :
    Inscription : Janvier 2003
    Messages : 302
    Points : 316
    Points
    316
    Par défaut
    Salut anapurna,

    Non les dates sont intermélées, donc ni le premier cas de figure où la date de fin du premier fichier est celle du début du deuxième fichier, ni le deuxième où tous les fichiers débutent et finissent en même temps. Pour reprendre ta notation, voici les dates que j'ai pu extraire de mes fichiers changelog :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    ychaouche#ychaouche-PC 14:41:21 ~/SRV/MESSAGRIE $ grep -P ^$'\t+\w+ \d{2} \w+ \d{4}' changelog-201*   
    changelog-20141225-20160331:    Lundi 05 janvier 2015
    changelog-20141225-20160331:    Mercredi 07 janvier 2015
    changelog-20141225-20160331:            Jeudi 08 janvier 2015
    changelog-20141225-20160331:    Venredi 09 Janvier 2015
    changelog-20141225-20160331:    Dimanche 11 janvier 2015
    changelog-20141225-20160331:    Lundi 12 janvier 2015
    changelog-20141225-20160331:    Mercredi 14 janvier 2015
    changelog-20141225-20160331:    Lundi 26 janvier 2015
    changelog-20141225-20160331:    Mardi 27 janvier 2015
    changelog-20141225-20160331:    Mercredi 28 janvier 2015
    changelog-20141225-20160331:    Dimanche 31 mai 2015
    changelog-20141225-20160331:    Lundi 01 juin 2015
    changelog-20141225-20160331:    Mardi 02 juin 2015
    changelog-20141225-20160331:    Dimanche 07 juin 2015
    changelog-20141225-20160331:    Lundi 08 juin 2015
    changelog-20141225-20160331:    Jeudi 11 juin 2015
    changelog-20141225-20160331:    Dimanche 14 juin 2015
    changelog-20141225-20160331:    Mardi 16 juin 2015
    changelog-20141225-20160331:    Jeudi 18 juin 2015
    changelog-20141225-20160331:    Lundi 06 juillet 2015
    changelog-20141225-20160331:    Mercredi 08 juillet 2015
    changelog-20141225-20160331:    Jeudi 09 juillet 2015
    changelog-20141225-20160331:    Dimanche 12 juillet 2015
    changelog-20141225-20160331:    Lundi 13 juillet 2015
    changelog-20141225-20160331:    Mardi 14 juillet 2015
    changelog-20141225-20160331:    Dimanche 19 juillet 2015
    changelog-20141225-20160331:    Mardi 21 juillet 2015
    changelog-20141225-20160331:    Mercredi 29 juillet 2015
    changelog-20141225-20160331:    Jeudi 10 septembre 2015
    changelog-20141225-20160331:    jeudi 03 mars 2016
    changelog-20141225-20160331:    Lundi 07 mars 2016
    changelog-20141225-20160331:    Lundi 14 mars 2016
    changelog-20141225-20160331:    Mardi 22 mars 2016
    changelog-20141225-20160331:    Mercredi 23 mars 2016
    changelog-20141225-20160331:    Jeudi 24 mars 2016
    changelog-20141225-20160331:    Mardi 27 mars 2016
    changelog-20141225-20160331:    Lundi 28 Mars 2016
    changelog-20141225-20160331:    Mercredi 30 mars 2016
    changelog-20141225-20160331:    Jeudi 31 mars 2016
    changelog-20160307-20181119:    Lundi 07 mars 2016
    changelog-20160307-20181119:    Lundi 14 Mars 2016
    changelog-20160307-20181119:    Mardi 15 mars 2016
    changelog-20160307-20181119:    Jeudi 17 mars 2016
    changelog-20160307-20181119:    Dimanche 20 mars 2016
    changelog-20160307-20181119:    Lundi 21 mars 2016
    changelog-20160307-20181119:    Mardi 23 mars 2016
    changelog-20160307-20181119:    Dimanche 27 mars 2016
    changelog-20160307-20181119:    Lundi 28 mars 2016
    changelog-20160307-20181119:    Mardi 29 mars 2016
    changelog-20160307-20181119:    Mercredi 30 mars 2016
    changelog-20160307-20181119:    Jeudi 31 mars 2016
    changelog-20160307-20181119:    Dimanche 03 avril 2016
    changelog-20160307-20181119:    Lundi 04 avril 2016
    changelog-20160307-20181119:    Mardi 05 avril 2016
    changelog-20160307-20181119:    Mercredi 06 avril 2016
    changelog-20160307-20181119:    Jeudi 07 avril 2016
    changelog-20160307-20181119:    Dimanche 24 avril 2016
    changelog-20160307-20181119:    Lundi 25 avril 2016
    changelog-20160307-20181119:    Mardi 26 avril 2016
    changelog-20160307-20181119:    Mercredi 27 Avril 2016
    changelog-20160307-20181119:    Mardi 28 Avril 2016
    changelog-20160307-20181119:    Mercredi 04 mai 2016
    changelog-20160307-20181119:    Jeudi 05 Mai 2016
    changelog-20160307-20181119:    Dimanche 08 mai 2016
    changelog-20160307-20181119:    Lundi 09 Mai 2016
    changelog-20160307-20181119:    Mercredi 11 Mai 2016
    changelog-20160307-20181119:    Jeudi 12 Mai 2016
    changelog-20160307-20181119:    Mardi 24 Mai 2016
    changelog-20160307-20181119:    Mercredi 25 Mai 2016
    changelog-20160307-20181119:    Jeudi 26 Mai 2016
    changelog-20160307-20181119:    Dimanche 29 Mai 2016
    changelog-20160307-20181119:    Mercredi 01 juin 2016
    changelog-20160307-20181119:    Mercredi 08 juin 2016
    changelog-20160307-20181119:    Dimanche 12 juin 2016
    changelog-20160307-20181119:    Lundi 13 juin 2016
    changelog-20160307-20181119:    Mercredi 15 juin 2016
    changelog-20160307-20181119:    Jeudi 16 juin 2016
    changelog-20160307-20181119:    Dimanche 19 juin 2016
    changelog-20160307-20181119:    Lundi 20 juin 2016
    changelog-20160307-20181119:    Dimanche 26 Juin 2016
    changelog-20160307-20181119:    Mardi 28 juin 2016
    changelog-20160307-20181119:    Jeudi 30 juin 2016
    changelog-20160307-20181119:    Dimanche 03 juillet 2016
    changelog-20160307-20181119:    Lundi 04 juillet 2016
    changelog-20160307-20181119:    Mardi 26 juillet 2016
    changelog-20160307-20181119:    Mercredi 21 Septembre 2016
    changelog-20160307-20181119:    Jeudi 22 Septembre 2016
    changelog-20160307-20181119:    Mardi 27 septembre 2016
    changelog-20160307-20181119:    Mardi 04 octobre 2016
    changelog-20160307-20181119:    Mercredi 05 Octobre 2016
    changelog-20160307-20181119:    Mardi 18 Octobre 2016
    changelog-20160307-20181119:    Lundi 16 janvier 2017
    changelog-20160307-20181119:    Mardi 17 janvier 2017
    changelog-20160307-20181119:    Lundi 13 Mars 2017
    changelog-20160307-20181119:    Jeudi 16 Mars 2017
    changelog-20160307-20181119:    Jeudi 23 Mars 2017
    changelog-20160307-20181119:    Mardi 28 Mars 2017
    changelog-20160307-20181119:    Mercredi 05 Avril 2017
    changelog-20160307-20181119:    Jeudi 06 Avril 2017
    changelog-20160307-20181119:    Lundi 10 Avril 2017
    changelog-20160307-20181119:    Mardi 25 Avril 2017
    changelog-20160307-20181119:    Mercredi 24 Mai 2017
    changelog-20160307-20181119:    Mardi 30 Mai 2017
    changelog-20160307-20181119:    Lundi 05 Juin 2017
    changelog-20160307-20181119:    Mardi 07 Juin 2017
    changelog-20160307-20181119:    Mercredi 07 Juin 2017
    changelog-20160307-20181119:    Lundi 12 Juin 2017
    changelog-20160307-20181119:    Jeudi 06 juillet 2017
    changelog-20160307-20181119:    Lundi 10 Juillet 2017
    changelog-20160307-20181119:    Dimanche 16 juillet 2017
    changelog-20160307-20181119:    Mardi 18 juillet 2017
    changelog-20160307-20181119:    Lundi 19 novembre 2018
    changelog-20160331-20160824:    Mardi 24 Mai 2016
    changelog-20160331-20160824:    Dimanche 29 Mai 2016
    changelog-20160331-20160824:    Mercredi 01 Juin 2016
    changelog-20160331-20160824:    Jeudi 09 juin 2016
    changelog-20160331-20160824:    Mercredi 29 juin 2016
    changelog-20160331-20160824:    Mardi 14 juillet 2016
    changelog-20160331-20160824:    Mercredi 20 juillet 2016
    changelog-20160331-20160824:    Mardi 26 juillet 2016
    changelog-20160331-20160824:    Mercredi 27 juillet 2016
    changelog-20160331-20180703:    Lundi 04 avril 2016
    changelog-20160331-20180703:    Dimanche 24 avril 2016
    changelog-20160331-20180703:    Mercredi 27 Avril 2016
    changelog-20160331-20180703:    Lundi 02 Mai 2016
    changelog-20160331-20180703:    Lundi 23 Mai 2016
    changelog-20160331-20180703:    Dimanche 05 Juin 2016
    changelog-20160331-20180703:    Jeudi 28 Juillet 2016
    changelog-20160331-20180703:    Mercredi 21 Septembre 2016
    changelog-20160331-20180703:    Mardi 03 Juillet 2018
    changelog-20170319-20181128:    Dimanche 19 Mars 2017
    changelog-20170319-20181128:    Lundi 20 Mars 2017
    changelog-20170319-20181128:    Mardi 21 Mars 2017
    changelog-20170319-20181128:    Mercredi 22 Mars 2017
    changelog-20170319-20181128:    Dimanche 26 Mars 2017
    changelog-20170319-20181128:    Lundi 27 Mars 2017
    changelog-20170319-20181128:    Mardi 28 mars 2017
    changelog-20170319-20181128:    Mercredi 29 Mars 2017
    changelog-20170319-20181128:    Dimanche 02 Avril 2017
    changelog-20170319-20181128:    Mardi 04 Avril 2017
    changelog-20170319-20181128:    Lundi 10 Avril 2017
    changelog-20170319-20181128:    Mercredi 12 Avril 2017
    changelog-20170319-20181128:    Lundi 24 Avril 2017
    changelog-20170319-20181128:    Mardi 25 Avril 2017
    changelog-20170319-20181128:    Mercredi 26 Avril 2017
    changelog-20170319-20181128:    Mercredi 17 Mai 2017
    changelog-20170319-20181128:    Lundi 22 Mai 2017
    changelog-20170319-20181128:    Mercredi 24 Mai 2017
    changelog-20170319-20181128:    Mardi 30 Mai 2017
    changelog-20170319-20181128:    Lundi 05 Juin 2017
    changelog-20170319-20181128:    Mardi 06 Juin 2017
    changelog-20170319-20181128:    Mercredi 07 Juin 2017
    changelog-20170319-20181128:    Lundi 12 Juin 2017
    changelog-20170319-20181128:    Mardi 13 juin 2017
    changelog-20170319-20181128:    Lundi 19 juin 2017
    changelog-20170319-20181128:    Jeudi 20 juillet 2017
    changelog-20170319-20181128:    Dimanche 03 Septembre 2017
    changelog-20170319-20181128:    Lundi 04 Septembre 2017
    changelog-20170319-20181128:    Mercredi 06 Septembre 2017
    changelog-20170319-20181128:    Jeudi 07 septembre 2017
    changelog-20170319-20181128:    Jeudi 14 septembre 2017
    changelog-20170319-20181128:    Lundi 18 septembre 2017
    changelog-20170319-20181128:    Mardi 26 septembre 2017
    changelog-20170319-20181128:    Jeudi 05 Octobre 2017
    changelog-20170319-20181128:    Mercredi 11 Octobre 2017
    changelog-20170319-20181128:    Jeudi 12 octobre 2017
    changelog-20170319-20181128:    Dimanche 15 octobre 2017
    changelog-20170319-20181128:    Lundi 16 octobre 2017
    changelog-20170319-20181128:    Mercredi 18 octobre 2017
    changelog-20170319-20181128:    Mardi 24 Octobre 2017
    changelog-20170319-20181128:    Mardi 07 Novembre 2017
    changelog-20170319-20181128:    Mercredi 08 Novembre 2017
    changelog-20170319-20181128:    Dimanche 12 Novembre 2017
    changelog-20170319-20181128:    Mercredi 22 novembre 2017
    changelog-20170319-20181128:    Mardi 28 novembre 2017
    changelog-20170319-20181128:    Mercredi 29 novembre 2017
    changelog-20170319-20181128:    Dimanche 07 Janvier 2018
    changelog-20170319-20181128:    Jeudi 11 janvier 2018
    changelog-20170319-20181128:    Lundi 29 janvier 2018
    changelog-20170319-20181128:    Mercredi 23 Mai 2018
    changelog-20170319-20181128:    Lundi 24 Septembre 2018
    changelog-20170319-20181128:    Mardi 25 septembre 2018
    changelog-20170319-20181128:    Dimanche 14 Octobre 2018
    changelog-20170319-20181128:    Dimanche 18 Novembre 2018
    changelog-20170319-20181128:    Mercredi 28 novembre 2018
    changelog-20180308-20190213:    Lundi 12 Mars 2018
    changelog-20180308-20190213:    Jeudi 22 mars 2018
    changelog-20180308-20190213:    Mardi 27 mars 2018
    changelog-20180308-20190213:    Jeudi 29 mars 2018
    changelog-20180308-20190213:    Dimanche 08 Avril 2018
    changelog-20180308-20190213:    Lundi 16 Avril 2018
    changelog-20180308-20190213:    Mardi 26 Avril 2018
    changelog-20180308-20190213:    Lundi 07 Mai 2018
    changelog-20180308-20190213:    Mardi 08 Mai 2018
    changelog-20180308-20190213:    Mercredi 09 Mai 2018
    changelog-20180308-20190213:    Jeudi 10 Mai 2018
    changelog-20180308-20190213:    Jeudi 17 Mai 2018
    changelog-20180308-20190213:    Dimanche 20 Mai 2018
    changelog-20180308-20190213:    Mardi 22 Mai 2018
    changelog-20180308-20190213:    Mercredi 23 Mai 2018
    changelog-20180308-20190213:    Dimanche 27 Mai 2018
    changelog-20180308-20190213:    Lundi 28 Mai 2018
    changelog-20180308-20190213:    Lundi 04 Juin 2018
    changelog-20180308-20190213:    Jeudi 07 Juin 2018
    changelog-20180308-20190213:    Dimanche 10 Juin 2018
    changelog-20180308-20190213:    Lundi 11 Juin 2018
    changelog-20180308-20190213:    Mercredi 13 Juin 2018
    changelog-20180308-20190213:    Dimanche 17 Juin 2018
    changelog-20180308-20190213:    Mardi 19 Juin 2018
    changelog-20180308-20190213:    Lundi 25 Juin 2018
    changelog-20180308-20190213:    Mardi 26 Juin 2018
    changelog-20180308-20190213:    Mercredi 11 Juillet 2018
    changelog-20180308-20190213:    Lundi 15 Juillet 2018
    changelog-20180308-20190213:    Mardi 24 Juillet 2018
    changelog-20180308-20190213:    Lundi 30 Juillet 2018
    changelog-20180308-20190213:    Mardi 31 Juillet 2018
    changelog-20180308-20190213:    Lundi 10 Septembre 2018
    changelog-20180308-20190213:    Dimanche 16 Septembre 2018
    changelog-20180308-20190213:    Dimanche 23 Septembre 2018
    ychaouche#ychaouche-PC 14:41:28 ~/SRV/MESSAGRIE

    Si j'ai bien compris ta deuxième solution je crois que j'ai commencé à travailler sur qqch de similaire en python où je vais stocker chaque block de text un tableau associatif où la clé serait la date, puis je créé un autre tableau à partir des clés, que je tri, et je pacours le tableau associatif en prenant un à un les dates triées du deuxième tableau, que j'insère dans le fichier finale. Je fais ça en python mais je me demandais si des outils plus spécialisés pourraient le faire plus aisément (awk par ex ?)

  6. #6
    Expert éminent sénior Avatar de Flodelarab
    Homme Profil pro
    Inscrit en
    Septembre 2005
    Messages
    5 243
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Charente (Poitou Charente)

    Informations forums :
    Inscription : Septembre 2005
    Messages : 5 243
    Points : 13 458
    Points
    13 458
    Par défaut
    Mais c'est pas encore réglé ce problème ???
    _

    Le premier os que que je vois est que les dates sont en français.
    Donc pour les transformer en secondes depuis l'epoch, il va falloir les traduire dans un langage que comprend date -d.
    L'anglais ou 2015-12-02, par exemple.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $ date -d "2015-12-02" +%s
    1449010800
    _

    Ensuite, c'est un forum d'algorithmie, ici.
    Or, ta question n'a rien d'algorithmique.
    C'est juste que tu as la flemme.
    Combien paieras-tu les gens pour qu'ils travaillent à ta place ?
    Cette réponse vous apporte quelque chose ? Cliquez sur en bas à droite du message.

  7. #7
    Membre averti
    Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2003
    Messages
    302
    Détails du profil
    Informations personnelles :
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Distribution

    Informations forums :
    Inscription : Janvier 2003
    Messages : 302
    Points : 316
    Points
    316
    Par défaut
    Citation Envoyé par Flodelarab Voir le message
    Ensuite, c'est un forum d'algorithmie, ici.
    Tu préfère que je clôture ou que je déplace dans un forum plus approprié ?

    Citation Envoyé par Flodelarab Voir le message
    Le premier os que que je vois est que les dates sont en français.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    In [2]: dateparser.parse("Jeudi 31 mars 2016")
    Out[2]: datetime.datetime(2016, 3, 31, 0, 0)
     
    In [3]:
    https://dateparser.readthedocs.io/en/latest/

  8. #8
    Expert éminent sénior Avatar de Flodelarab
    Homme Profil pro
    Inscrit en
    Septembre 2005
    Messages
    5 243
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Charente (Poitou Charente)

    Informations forums :
    Inscription : Septembre 2005
    Messages : 5 243
    Points : 13 458
    Points
    13 458
    Par défaut
    Donc tu as toutes les pièces du puzzle.
    Qu'est-ce qui te manque pour réussir ?
    Cette réponse vous apporte quelque chose ? Cliquez sur en bas à droite du message.

  9. #9
    Membre averti
    Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2003
    Messages
    302
    Détails du profil
    Informations personnelles :
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Distribution

    Informations forums :
    Inscription : Janvier 2003
    Messages : 302
    Points : 316
    Points
    316
    Par défaut
    Code Python : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    #-*-encoding=utf-8-*-
     
    """
    [x] Lire les entrées
    [x] Trouver les dates
    [x] Ranger chaque block dans sa date
    [x] Trier les blocks par date
    [x] Parser n fichiers
    [x] Gérer les cas où deux entrées ont la même date
    [x] Spit out le nouvel ordre trié par date
    [x] Comparer l'output avec les input (ouvrir deux fichiers changelog 
        dans emacs et comparer l'output trié sur la console)
     
    """
    import re
    import sys
    import dateparser
     
    # pour lire correctement les février, décembre etc. 
    # (caractères unicode)
    import codecs
     
     
    def parseChangelog(fd):
        """
        La date est intégré au block
        Ceci permet d'avoir autant de fois la date qu'il n'y a d'entrées à la 
        même date dans des changelogs differents, avec moins de code à écrire
        """
        regex    = re.compile("^\s+(\w+ \d{2} \w+ \d{4})",re.U) # unicode flag to match février, décembre et cie.
        blocks   = {}
        datestr  = "1970/01/01"
        for line in fd:
            mo = regex.match(line)
            if mo : 
                datestr=mo.groups()[0].encode("utf-8")
                date=dateparser.parse(datestr)
                if date is None:
                    print "This couldn't be parsed",datestr
                blocks[date]=""
            blocks[date]+=line.encode("utf-8")
        return blocks
     
    def dictextend(A,B):
        """
        Gère le cas où on a deux dates identiques dans deux ou plusieurs
        changlogs différents.
        """
        for key in B:
            if key in A:
                # Peut nécessiter des retours à la ligne
                A[key] += B[key]
            else:
                A[key] = B[key]
        return A
     
     
    changelogfiles = [codecs.open(filepath,mode="r",encoding="utf-8") for filepath in sys.argv[1:]]
    superblocks    = {}
    for changelogfile in changelogfiles : 
        blocks      = parseChangelog(changelogfile)
        superblocks = dictextend(superblocks,blocks)
     
    for date in sorted(superblocks):
        print "#"*80
        print superblocks[date]
        print "#"*80
     
    print "superblocks contient %s dates" % (len(superblocks))

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Fusionner des fichiers par ordre de date décroissant
    Par rvaysse dans le forum Windows
    Réponses: 4
    Dernier message: 29/12/2010, 16h20
  2. Réponses: 2
    Dernier message: 18/02/2010, 10h30
  3. Fusionner des fichiers javahelp
    Par tchize_ dans le forum Interfaces Graphiques en Java
    Réponses: 0
    Dernier message: 22/07/2009, 15h30
  4. [WD14] Fusionner des fichiers .fic
    Par buzz68180 dans le forum WinDev
    Réponses: 1
    Dernier message: 27/05/2009, 23h47
  5. Fusionner des fichiers .mat
    Par zax469 dans le forum MATLAB
    Réponses: 1
    Dernier message: 07/04/2008, 10h34

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo