Problem with inheritance

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    Problem with inheritance

    I am trying to create a custom object, with objects that have objects. My problem is with the last object in the chain (sample), rather than create an additional object for a new value it simply replaces the existing value.

    More specifically this is the structure I am looking for:
    (I have included two sample data sets and my code below)

    Job (only one value)
    Boring (one or more occurrences)
    Sample(one or more occurrences)
    sample properties (20 different properties for each sample)

    74550
    12
    1
    sampledate
    depth
    blows
    .
    .
    .
    2
    sampledate
    depth
    blows
    .
    .
    .

    here is the sample data
    Code:
    "reckey","JOBID","BORING","SAMPLE","SAMPLEDATE","DEPTH","BLOWS","CONTNUMB","WWofSC","DWofSC","CONTWEIGHT","MOISTURE","SAMPLEinAIR","SAMPLEinWATER","WATER","DRYUNIT","DIMWEIGHT","DIMLENGTH","DIMDIAMETER","DIMDRYUNIT","DIMCORRECTED","QU","QP","CORRECTED","SOILDESC","WEBUSER","WEBADDEDIT","WEBDATE","prjctname","prjctaddr1","prjctaddr2","prjctcity","prjctst","engineer","name","addr1","addr2","city","st","substr(m.zip,1,5)"
    "74550 12   1",74550,"12   ","1   ","2009-12-17","1-2.5      ","2-2-3      ","390","44.7","34.2","11.2","68.7","34.2","1087.7","1086.3","0.9","0.0","0.00","0.000","0.0"," ","","1.5        ",""," Black and Gray silty CLAY little sand trace gravel and organic very moist CL - FILL                                                                                                                                                                          ","Lab","Edit","2009-12-17","Supplemental Geotechnical Exploration","Proposed Sewer Line","Rohlwing Road","Itasca","IL","CRD","Baxter & Woodman, Inc.","8678 Ridgefield Road","","Crystal Lake","IL","60012"
    "74550 12   2",74550,"12   ","2   ","2009-12-17","3.5-5      ","2-3-3      ","391","56.6","46.5","11.1","77.8","46.7","1108.1","1086.1","0.8","0.0","0.00","0.000","0.0"," ","1.03 ","1.25       ",""," Brown +  Gray silty CLAY little sand trace roots very moist CL                                                                                                                                                                                               ","Lab","Edit","2009-12-17","Supplemental Geotechnical Exploration","Proposed Sewer Line","Rohlwing Road","Itasca","IL","CRD","Baxter & Woodman, Inc.","8678 Ridgefield Road","","Crystal Lake","IL","60012"
    "74550 12   3",74550,"12   ","3   ","2009-12-17","6-7.5      ","1-1-2      ","392","60.5","49.8","11.1","78.3","38.6","1107.5","1084.9","0.8","0.0","0.00","0.000","0.0"," ","0.50 ","0.50       ",""," Brownish Gray silty CLAY little sand very moist CL                                                                                                                                                                                                           ","Lab","Edit","2009-12-17","Supplemental Geotechnical Exploration","Proposed Sewer Line","Rohlwing Road","Itasca","IL","CRD","Baxter & Woodman, Inc.","8678 Ridgefield Road","","Crystal Lake","IL","60012"
    "74550 12   4",74550,"12   ","4   ","2009-12-17","8.5-10     ","1-2-2      ","393","53.3","42.4","11.2","74.1","31.4","1108.4","1086.3","0.8","0.0","0.00","0.000","0.0"," ","","0.25       ",""," Gray silty CLAY little sand very moist CL                                                                                                                                                                                                                    ","Lab","Edit","2009-12-17","Supplemental Geotechnical Exploration","Proposed Sewer Line","Rohlwing Road","Itasca","IL","CRD","Baxter & Woodman, Inc.","8678 Ridgefield Road","","Crystal Lake","IL","60012"
    "74550 12   5",74550,"12   ","5   ","2009-12-17","11-13      ","2-2-2-3    ","394","55.4","45.7","11.1","78.1","35.0","1108.7","1087.8","0.8","0.0","0.00","0.000","0.0"," ","0.63 ","1.0        ",""," Gray silty CLAY little sand trace organic very moist CL                                                                                                                                                                                                      ","Lab","Edit","2009-12-17","Supplemental Geotechnical Exploration","Proposed Sewer Line","Rohlwing Road","Itasca","IL","CRD","Baxter & Woodman, Inc.","8678 Ridgefield Road","","Crystal Lake","IL","60012"
    "74550 12   6",74550,"12   ","6   ","2009-12-17","13-15      ","5-6-7-8    ","395","65.2","58.8","11.1","88.2","26.7","1125.9","1109.9","0.7","0.0","0.00","0.000","0.0"," ","","2.5        ",""," Brown +  Gray silty CLAY little sand trace gravel moist CL                                                                                                                                                                                                   ","Lab","Edit","2009-12-17","Supplemental Geotechnical Exploration","Proposed Sewer Line","Rohlwing Road","Itasca","IL","CRD","Baxter & Woodman, Inc.","8678 Ridgefield Road","","Crystal Lake","IL","60012"
    "74550 12   7",74550,"12   ","7   ","2009-12-17","","","","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.00","0.000","0.0"," ","","","","TEST SAMPLE                                                                                                                                                                                                                                                   ","Lab","Add","2009-12-17","Supplemental Geotechnical Exploration","Proposed Sewer Line","Rohlwing Road","Itasca","IL","CRD","Baxter & Woodman, Inc.","8678 Ridgefield Road","","Crystal Lake","IL","60012"

    2nd sample data set
    Code:
    "reckey","JOBID","BORING","SAMPLE","SAMPLEDATE","DEPTH","BLOWS","CONTNUMB","WWofSC","DWofSC","CONTWEIGHT","MOISTURE","SAMPLEinAIR","SAMPLEinWATER","WATER","DRYUNIT","DIMWEIGHT","DIMLENGTH","DIMDIAMETER","DIMDRYUNIT","DIMCORRECTED","QU","QP","CORRECTED","SOILDESC","WEBUSER","WEBADDEDIT","WEBDATE","prjctname","prjctaddr1","prjctaddr2","prjctcity","prjctst","engineer","name","addr1","addr2","city","st","substr(m.zip,1,5)"
    "74547 1    3",74547,"1    ","3   ","2009-12-21","","","","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.00","0.000","0.0"," ","","",""," Brown and Gray silty CLAY                                                                                                                                                                                                                                    ","Lab","Edit","2009-12-21","Cedarwood Drive Pavement Cores","South of Theodore Street","","Crest Hill","IL","MVM","Christopher B. Burke Engineering, Ltd.","9575 West Higgins Road   Suite 600","","Rosemont","IL","60018"
    "74547 1    4",74547,"1    ","4   ","2009-12-21","","","","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.0","0.00","0.000","0.0"," ","","",""," Brown SILT                                                                                                                                                                                                                                                   ","Lab","Add","2009-12-21","Cedarwood Drive Pavement Cores","South of Theodore Street","","Crest Hill","IL","MVM","Christopher B. Burke Engineering, Ltd.","9575 West Higgins Road   Suite 600","","Rosemont","IL","60018"
    "74547 2    3",74547,"2    ","3   ","2009-12-21","","","32 ","54.2","44.7","10.3","27.6","44.5","1215.2","1193.1","96.5","0.0","0.00","0.000","0.0"," ","","","Corrected"," Brown clayey SAND trace gravel moist SC                                                                                                                                                                                                                      ","Lab","Edit","2009-12-21","Cedarwood Drive Pavement Cores","South of Theodore Street","","Crest Hill","IL","MVM","Christopher B. Burke Engineering, Ltd.","9575 West Higgins Road   Suite 600","","Rosemont","IL","60018"
    "74547 3    3",74547,"3    ","3   ","2009-12-21","","","33 ","56.9","49.6","9.9","18.4","44.3","1213.3","1192.5","52.7","0.0","0.00","0.000","0.0"," ","","4.5+       ","Corrected"," Black silty CLAY little sand trace GRAVEL trace organic moist CL - FILL                                                                                                                                                                                      ","Lab","Edit","2009-12-21","Cedarwood Drive Pavement Cores","South of Theodore Street","","Crest Hill","IL","MVM","Christopher B. Burke Engineering, Ltd.","9575 West Higgins Road   Suite 600","","Rosemont","IL","60018"
    "74547 4    3",74547,"4    ","3   ","2009-12-21","","","34 ","57.7","48.6","10.2","23.7","38.6","1210.8","1191.9","50.4","0.0","0.00","0.000","0.0"," ","","4.0        ","Corrected"," Brown +  Gray silty CLAY little sand moist CL                                                                                                                                                                                                                ","Lab","Edit","2009-12-21","Cedarwood Drive Pavement Cores","South of Theodore Street","","Crest Hill","IL","MVM","Christopher B. Burke Engineering, Ltd.","9575 West Higgins Road   Suite 600","","Rosemont","IL","60018"
    "74547 5    3",74547,"5    ","3   ","2009-12-21","","","35 ","61.4","54.3","10.1","16.1","34.4","1206.8","1191.2","53.7","0.0","0.00","0.000","0.0"," ","","4.0        ","Corrected"," Brown +  Gray silty CLAY little sand trace gravel trace organic moist CL                                                                                                                                                                                     ","Lab","Edit","2009-12-21","Cedarwood Drive Pavement Cores","South of Theodore Street","","Crest Hill","IL","MVM","Christopher B. Burke Engineering, Ltd.","9575 West Higgins Road   Suite 600","","Rosemont","IL","60018"
    "74547 6    3",74547,"6    ","3   ","2009-12-21","","","36 ","58.9","51.0","9.9","19.2","44.1","1210.9","1190.4","52.3","0.0","0.00","0.000","0.0"," ","","4.0        ","Corrected"," Brown silty CLAY little sand moist CL                                                                                                                                                                                                                        ","Lab","Edit","2009-12-21","Cedarwood Drive Pavement Cores","South of Theodore Street","","Crest Hill","IL","MVM","Christopher B. Burke Engineering, Ltd.","9575 West Higgins Road   Suite 600","","Rosemont","IL","60018"
    In my code below I can create the jobObject and a variable number of borings. But my "z" variable for creating the samples simply changes the existing sample on each loop.

    Here is my code:
    Code:
    var JobObject = new createJobObj(aReturn)
    
    function createJobObj(aData)
    {
    	//clientInfo
    	this.client = aData[0];
    	//jobInfo
    	this.job = aData[1]; 
    
    	/*
    	---------------------------------
    	create a boring array with sample 
    	data for each boring
    	---------------------------------
    	*/
    	this.boring = new Object();
    
    	
    	for (var i = 2; i < aData.length; i++ )
    	{
    		var x = aData[i].substr(0,aData[i].indexOf('~'));
    
    		if (x != this.boring)
    		{
    			this.boring[x] = new Object();
    		}
    
    		//add sample data to boring element
    		aZ = new Array()
    		aZ = aData[i].split('~');
    		var z = aZ[1];
    
    		if (z != this.boring[x])
    		{
    			this.boring[x][z] = new Object();
    		}
    		this.boring[x][z].sampleDate = aZ[2];
    		this.boring[x][z].depth = aZ[3];
    		this.boring[x][z].blows = aZ[4];
    		this.boring[x][z].contNumb = aZ[5];
    		this.boring[x][z].WWofSC = aZ[6];
    		this.boring[x][z].DWofSC = aZ[7];
    		this.boring[x][z].contWeight = aZ[8];
    		this.boring[x][z].moisture = aZ[9];
    		this.boring[x][z].sampleInAir = aZ[10];
    		this.boring[x][z].sampleInWater = aZ[11];
    		this.boring[x][z].water = aZ[12];
    		this.boring[x][z].dryUnit = aZ[13];
    		this.boring[x][z].corrected = aZ[14];
    		this.boring[x][z].dimDryUnit = aZ[15];
    		this.boring[x][z].dimCorrected = aZ[16];
    		this.boring[x][z].qu = aZ[17];
    		this.boring[x][z].qp = aZ[18];
    		this.boring[x][z].soilDesc = aZ[19];
    	}
    }
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    I think it’s line 23. you check, whether this.boring equals x, but you certainly mean, whether x is a subobject of this.boring. (same goes for line 33)

    there are 2 ways on my mind:
    Code:
    if (!(x in this.boring)) {}
    if (!this.boring[x]) {} // except if this.boring[x] may be 0, "", false, null, [] or {}

    Comment

    • Claus Mygind
      Contributor
      • Mar 2008
      • 571

      #3
      Of course you are correct, I am looking for a subObject. I had to run the simulation several times before I saw that my problem occurred on line 23.

      I don't seem to be experiencing the problem on line 33 as you suggested and I was having some trouble implementing your suggestions (I believe you say I should use your line #2?

      I am not clear on how I should test for the exceptions you have listed. And on the first go around the subObject has no properties so of course it crashes.

      Comment

      • Claus Mygind
        Contributor
        • Mar 2008
        • 571

        #4
        I see my error. Just repeat your line 1 on my line 33

        Code:
        if (!(z in this.boring[x]))

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          I believe you say I should use your line #2?
          no, both basicly (see comment) do the same.

          and to be precise, your problem has nothing to do with inheritance, that would involve meddling with the prototype property.

          Comment

          Working...