a query in a 'multiple to multiple' table

738
7
12-28-2017 09:00 AM
SaraEL_MALKI
Occasional Contributor II

Hi guys,

the concept of my algorithm is the following:

I have many bags, and each one has a specific zone (ZONE A or ZONE B),

an agent is controlling these bags every period of time, so I have a multiple to multiple relationship between the bags and the 'agent' ( the person controlling these bags).

I want to render a chart showing the different characteristics found during the control of all the bags inside the two zones, it's like a comparison between the two zones.

my problem is that I have nearly 4000 bags, and it takes TOO much time to go through my code (more the 5 minutes, I wounder if there is a better algorithm than mine !

function main_chart(){

lookingForbacs('ZONE A');

function lookingForbacs(zone){
zone_now=zone;
var bacs_QT = new QueryTask(bacs_url);
found_=0;
roues_main=0;
couvercle_main=0;
bac_main=0;
entier_main=0;
ras_main=0;
bac_index=0;
id_bac_array_1=[];
var QB_query = new Query();
QB_query.where = "ZONE='"+zone+"'"; //BAGS that belongs to the ZONE
QB_query.outSpatialReference = {wkid: 102100};
QB_query.returnGeometry = true;
QB_query.outFields = ["*"];

bacs_QT.execute(QB_query, function(featuresSet) {
for(i = 0; i < featuresSet.features.length; i++) {
var featureBac = featuresSet.features[i];
id_bac_array_1.push(featureBac.attributes['id_bac']);
}
lookingForEtat(id_bac_array_1[bac_index]);
});
function lookingForEtat(id_bac){
;
var QTControleBac = new QueryTask(control_bac_url_ms); //Controle "TABLE"

var queryControleBac = new Query();
queryControleBac.where = "id_bac="+id_bac+" AND etat_abime IS NOT null";
queryControleBac.outSpatialReference = {wkid:102100};
queryControleBac.returnGeometry = false;
queryControleBac.outFields = ["*"];
QTControleBac.execute(queryControleBac);

QTControleBac.on("complete",function(eventContBac){
var fsetContBac= eventContBac.featureSet;
var FeaturesContBac = fsetContBac.features;
for (var k = 0, lengt = FeaturesContBac.length; k < lengt; k++) {
var featureContBac = FeaturesContBac[k];
found_=1;
if(featureContBac.attributes['etat_abime']=='roues'){
roues_main=roues_main+1;
}
else if (featureContBac.attributes['etat_abime']=='couvercle'){
couvercle_main=couvercle_main+1;
// console.log("couvercle_main: "+couvercle_main);
}else if (featureContBac.attributes['etat_abime']=='bac'){
bac_main=bac_main+1;
}else if (featureContBac.attributes['etat_abime']=='entier'){
entier_main=entier_main+1;
}else if (featureContBac.attributes['etat_abime']=='R.A.S.'){
ras_main=ras_main+1;
}

}
bac_index=bac_index+1;
if(id_bac_array_1.length>bac_index){
lookingForEtat(id_bac_array_1[bac_index]);
}else{ //ZONE IS FINISHED
roues_1_Ar.push(roues_main);
couvercle_1_Ar.push(couvercle_main);
bac_1_Ar.push(bac_main);
entier_1_Ar.push(entier_main);
ras_1_Ar.push(ras_main);
if(zone_now=='ZONE A'){
roues_main=0;
couvercle_main=0;
bac_main=0;
entier_main=0;
ras_main=0;
bac_index=0;
id_bac_array_1=[]; //vider la table chaque fois en change la ZONE
lookingForbacs('ZONE B'); //ZONE B is the second and last zone
}else{
rendering_1();
}
}

});
}
}
}

Robert Scheitlin, GISP‌ Rebecca Strauch, GISP dlaw-esristaff

0 Kudos
7 Replies
RobertScheitlin__GISP
MVP Emeritus

Sara,

  Your first query is returning geometry and all fields yet I don't see where you need either. I appears that you only need the "id_bac" attribute. If that is the case then you can get better performance by only setting "id_bac" as the queries outFields and set the returnGeometry to false. Same for your second query it appears that you only use the "etat_abime" field.

SaraEL_MALKI
Occasional Contributor II

Thank you for the notice, but actually it didn't help a lot !

0 Kudos
SaraEL_MALKI
Occasional Contributor II

Can't I use the "RelationshipQuery" query to search in the N,N table ?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

As far as I know yes.

0 Kudos
SaraEL_MALKI
Occasional Contributor II

I tried using it, but it's returning the info of the AGENT not of the control of the bags

the bags and agent are related with N-M relationship, the table of this relationship is named "Bags control"

I get when using the query Related Records on the bags feature Class, I get the info the of the agent that has controlled this bag NOT the info of the control of it !

please if you can tag someone working on these advances queries  !

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Sara,

   Sounds like you are not using the correct relationship id number in your query then.

SaraEL_MALKI
Occasional Contributor II

the table of the control of the bags is NOT a relationship, it is the result of the relationship between the bags and the agents, so there is only the id of the relationship table 

meanwhile that is the resulted table of the N-M relationship: (Number 44)

so I typed the id "16" in the query Related Records

0 Kudos