AnsweredAssumed Answered

a query in a 'multiple to multiple' table

Question asked by Sara_EL_MALKI on Dec 28, 2017
Latest reply on Jan 9, 2018 by Sara_EL_MALKI

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 Derek Law

Outcomes