Mercurial > hg > nsaunier > traffic-intelligence
comparison python/pavement.py @ 458:28ff95845c65
update to include speed limit
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Wed, 19 Feb 2014 17:46:26 -0500 |
| parents | 95a8eb38d9a2 |
| children | 16fe64136506 |
comparison
equal
deleted
inserted
replaced
| 457:95a8eb38d9a2 | 458:28ff95845c65 |
|---|---|
| 1 #! /usr/bin/env python | 1 #! /usr/bin/env python |
| 2 '''Tools for processing and analyzing pavement marking data''' | 2 '''Tools for processing and analyzing pavement marking data''' |
| 3 | |
| 4 import utils | |
| 3 | 5 |
| 4 import numpy as np | 6 import numpy as np |
| 5 | 7 |
| 6 __metaclass__ = type | 8 __metaclass__ = type |
| 7 | 9 |
| 17 30: "Regionale", | 19 30: "Regionale", |
| 18 10: "Autoroute", | 20 10: "Autoroute", |
| 19 60: "Acces ressources", | 21 60: "Acces ressources", |
| 20 51: "Local 1", | 22 51: "Local 1", |
| 21 52: "Local 2", | 23 52: "Local 2", |
| 22 53: "Local 3" | 24 53: "Local 3", |
| 23 15: "Aut (PRN)", | 25 15: "Aut (PRN)", |
| 24 25: "Nat (PRN)", | 26 25: "Nat (PRN)", |
| 25 70: "Acces isolees", | 27 70: "Acces isolees", |
| 26 99: "Autres" | 28 99: "Autres" |
| 27 } | 29 } |
| 28 | |
| 29 def occ_max(a): | |
| 30 if a != []: | |
| 31 s = set(a) | |
| 32 l = list(s) | |
| 33 occ = [] | |
| 34 for i in range(len(l)): | |
| 35 b = 0 | |
| 36 for j in range(len(a)): | |
| 37 if a[j] == l[i]: | |
| 38 b += 1 | |
| 39 occ.append([l[i], b]) | |
| 40 nbre_occs = [] | |
| 41 for i in range(len(occ)): | |
| 42 nbre_occs.append(occ[i][1]) | |
| 43 return occ[nbre_occs.index(max(nbre_occs))][0] | |
| 44 else: | |
| 45 return "" | |
| 46 | 30 |
| 47 def caracteristiques(rtss, maintenanceLevel, rtssWeatherStation, fmr, paintType): | 31 def caracteristiques(rtss, maintenanceLevel, rtssWeatherStation, fmr, paintType): |
| 48 '''Computes characteristic data for the RTSS (class rtss) | 32 '''Computes characteristic data for the RTSS (class rtss) |
| 49 maintenanceLevel = pylab.csv2rec('C:\Users\Alexandre\Desktop\Projet_maitrise_recherche\BDD_access\\analyse_donnees_deneigement\\exigence_circuits.txt', delimiter = ';') | 33 maintenanceLevel = pylab.csv2rec('C:\Users\Alexandre\Desktop\Projet_maitrise_recherche\BDD_access\\analyse_donnees_deneigement\\exigence_circuits.txt', delimiter = ';') |
| 50 rtssWeatherStation = pylab.csv2rec('C:\Users\Alexandre\Desktop\Projet_maitrise_recherche\stations_environnement_canada\\rtssWeatherStation\juste_pour_rtss_avec_donnees_entretien_hiv\\rtssWeatherStation_EC3.txt', delimiter = ',') | 34 rtssWeatherStation = pylab.csv2rec('C:\Users\Alexandre\Desktop\Projet_maitrise_recherche\stations_environnement_canada\\rtssWeatherStation\juste_pour_rtss_avec_donnees_entretien_hiv\\rtssWeatherStation_EC3.txt', delimiter = ',') |
| 67 y_moy = rtssWeatherStation['y_moy'][i] | 51 y_moy = rtssWeatherStation['y_moy'][i] |
| 68 else: | 52 else: |
| 69 x_moy, y_moy = '','' | 53 x_moy, y_moy = '','' |
| 70 | 54 |
| 71 # determination info fmr | 55 # determination info fmr |
| 72 age_revtm, classe_fonct, type_revtm, milieu, djma, pourc_camions = [], [], [], [], [], [] | 56 age_revtm, classe_fonct, type_revtm, milieu, djma, pourc_camions, vit_max = [], [], [], [], [], [], [] |
| 73 if rtss.id in fmr['rtss_debut']: | 57 if rtss.id in fmr['rtss_debut']: |
| 74 for i in range(len(fmr)): | 58 for i in range(len(fmr)): |
| 75 if fmr['rtss_debut'][i] == rtss.id: | 59 if fmr['rtss_debut'][i] == rtss.id: |
| 76 age_revtm.append(fmr['age_revtm'][i]) | 60 age_revtm.append(fmr['age_revtm'][i]) |
| 77 classe_fonct.append(fmr['des_clasf_fonct'][i]) | 61 classe_fonct.append(fmr['des_clasf_fonct'][i]) |
| 78 type_revtm.append(fmr['des_type_revtm'][i]) | 62 type_revtm.append(fmr['des_type_revtm'][i]) |
| 79 milieu.append(fmr['des_cod_mil'][i]) | 63 milieu.append(fmr['des_cod_mil'][i]) |
| 80 djma.append(fmr['val_djma'][i]) | 64 djma.append(fmr['val_djma'][i]) |
| 81 pourc_camions.append(fmr['val_pourc_camns'][i]) | 65 pourc_camions.append(fmr['val_pourc_camns'][i]) |
| 82 age_revtm = occ_max(age_revtm) | 66 vit_max.append(fmr['val_limt_vitss'][i]) |
| 83 classe_fonct = occ_max(classe_fonct) | 67 age_revtm = utils.mostCommon(age_revtm) |
| 84 type_revtm = occ_max(type_revtm) | 68 classe_fonct = utils.mostCommon(classe_fonct) |
| 85 milieu = occ_max(milieu) | 69 type_revtm = utils.mostCommon(type_revtm) |
| 86 djma = occ_max(djma) | 70 milieu = utils.mostCommon(milieu) |
| 87 pourc_camions = occ_max(pourc_camions) | 71 djma = utils.mostCommon(djma) |
| 72 vit_max = utils.mostCommon(vit_max) | |
| 73 if vit_max < 0: | |
| 74 vit_max = '' | |
| 75 pourc_camions = utils.mostCommon(pourc_camions) | |
| 88 if pourc_camions == "" or pourc_camions < 0: | 76 if pourc_camions == "" or pourc_camions < 0: |
| 89 djma_camions = "" | 77 djma_camions = "" |
| 90 else: | 78 else: |
| 91 djma_camions = pourc_camions*djma/100 | 79 djma_camions = pourc_camions*djma/100 |
| 92 else: | 80 else: |
| 93 age_revtm, classe_fonct, type_revtm, milieu, djma, djma_camions = '','','','','','' | 81 age_revtm, classe_fonct, type_revtm, milieu, djma, djma_camions, vit_max = '','','','','','','' |
| 94 | 82 |
| 95 # determination type peinture | 83 # determination type peinture |
| 96 peinture_rd, peinture_rg, peinture_cl = [], [], [] | 84 peinture_rd, peinture_rg, peinture_cl = [], [], [] |
| 97 peinture_lrd, peinture_lrg, peinture_lc = 0,0,0 | 85 peinture_lrd, peinture_lrg, peinture_lc = 0,0,0 |
| 98 if rtss.id in paintType['rtss_debut_orig']: | 86 if rtss.id in paintType['rtss_debut_orig']: |
| 99 for i in range(len(paintType)): | 87 for i in range(len(paintType)): |
| 100 if paintType['rtss_debut_orig'][i] == rtss.id: | 88 if paintType['rtss_debut_orig'][i] == rtss.id: |
| 101 peinture_rd.append((paintType['peinture_rd'][i])) | 89 peinture_rd.append((paintType['peinture_rd'][i])) |
| 102 peinture_rg.append((paintType['peinture_rg'][i])) | 90 peinture_rg.append((paintType['peinture_rg'][i])) |
| 103 peinture_cl.append((paintType['peinture_cl'][i])) | 91 peinture_cl.append((paintType['peinture_cl'][i])) |
| 104 peinture_lrd = occ_max(peinture_rd) | 92 peinture_lrd = utils.mostCommon(peinture_rd) |
| 105 peinture_lrg = occ_max(peinture_rg) | 93 peinture_lrg = utils.mostCommon(peinture_rg) |
| 106 peinture_lc = occ_max(peinture_cl) | 94 peinture_lc = utils.mostCommon(peinture_cl) |
| 107 else: | 95 else: |
| 108 peinture_lrd, peinture_lrg, peinture_lc = '','','' | 96 peinture_lrd, peinture_lrg, peinture_lc = '','','' |
| 109 | 97 |
| 110 return (exigence, x_moy, y_moy, age_revtm, classe_fonct, type_revtm, milieu, djma, djma_camions, peinture_lrd, peinture_lrg, peinture_lc) | 98 return (exigence, x_moy, y_moy, age_revtm, classe_fonct, type_revtm, milieu, djma, djma_camions, vit_max, peinture_lrd, peinture_lrg, peinture_lc) |
| 111 | 99 |
| 112 def winterMaintenanceIndicators(data, startDate, endDate, circuitReference, snowThreshold): | 100 def winterMaintenanceIndicators(data, startDate, endDate, circuitReference, snowThreshold): |
| 113 '''Computes several winter maintenance indicators | 101 '''Computes several winter maintenance indicators |
| 114 data = entretien_hivernal = pylab.csv2rec('C:\Users\Alexandre\Documents\Cours\Poly\Projet\mesures_entretien_hivernal\mesures_deneigement.txt', delimiter = ',')''' | 102 data = entretien_hivernal = pylab.csv2rec('C:\Users\Alexandre\Documents\Cours\Poly\Projet\mesures_entretien_hivernal\mesures_deneigement.txt', delimiter = ',')''' |
| 115 import datetime | 103 import datetime |
