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 ZONEQB_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 FINISHEDroues_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 ZONElookingForbacs('ZONE B'); //ZONE B is the second and last zone}else{rendering_1();}}});}}}
Robert Scheitlin, GISP Rebecca Strauch, GISP dlaw-esristaff
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.
Thank you for the notice, but actually it didn't help a lot !
Can't I use the "RelationshipQuery" query to search in the N,N table ?
As far as I know yes.
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 !
Sara,
Sounds like you are not using the correct relationship id number in your query then.
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