I want to add another condition in my code.
This is my code:
tablePT = QgsVectorLayer('None', 'table_PT', 'memory')
tablePT.dataProvider().addAttributes(
[QgsField("Type", QVariant.String), QgsField("FT", QVariant.Int),
QgsField("FREE", QVariant.Int), QgsField("PRIVE", QVariant.Int),
])
tablePT.updateFields()
dicoPT = {'CHAMBRE': (0, 0, 0), 'POTEAU': (0, 0, 0)}
nbPTTotal = 0
for pt in self.couchePT.getFeatures() :
typeStruc = pt['TYPE_STRUC']
proprietaire = pt['PROPRIETAI']
if typeStruc in ['CHAMBRE', 'POTEAU'] :
if proprietaire == 'FT' :
dicoPT[typeStruc] = tuple(map(operator.add, (1, 0, 0), dicoPT[typeStruc]))
nbPTTotal += 1
elif proprietaire == 'FREE MOBILE' :
dicoPT[typeStruc] = tuple(map(operator.add, (0, 1, 0), dicoPT[typeStruc]))
nbPTTotal += 1
elif proprietaire == 'PRIVE' :
dicoPT[typeStruc] = tuple(map(operator.add, (0, 0, 1), dicoPT[typeStruc]))
nbPTTotal += 1
else:
QMessageBox.critical(None, "Problème de PT",
"Le point_technique %s possède un propriétaire qui ne fait pas partie de la liste." % str(pt['NOM']))
else:
QMessageBox.critical(None, "Problème de PT",
"Le point_technique %s possède un type de strcture qui ne fait pas partie de la liste." % str(pt['NOM']))
ligneChambre = QgsFeature()
ligneChambre.setAttributes(['chambres', dicoPT['CHAMBRE'][0], dicoPT['CHAMBRE'][1], dicoPT['CHAMBRE'][2]])
lignePoteau = QgsFeature()
lignePoteau.setAttributes(['poteaux', dicoPT['POTEAU'][0], dicoPT['POTEAU'][1], dicoPT['POTEAU'][2]])
ligneTotaux = QgsFeature()
ligneTotaux.setAttributes(['Total général', "", "", nbPTTotal])
tablePT.dataProvider().addFeatures([ligneChambre])
tablePT.dataProvider().addFeatures([lignePoteau])
tablePT.dataProvider().addFeatures([ligneTotaux])
QgsProject.instance().addMapLayer(tablePT)
This is my table for now:
but I want to get information based on two condition just like this:
I want a table with rows that result from two condition in the same time:
First row = (case when typeStruc='CHAMBRE' and ETAT='EN SERVICE') => "CHAMBRE EXISTANT"
Second row = (case when typeStruc='CHAMBRE' and ETAT='EN ETUDE') => "CHAMBRE A POSE"
Third row = (case when typeStruc='POTEAU' and ETAT='EN ETUDE') => "POTEAU EXISTANT"
Fourth row = (case when typeStruc='POTEAU' and ETAT='EN ETUDE') => "POTEAU A POSE"