| 25 | | // I am not very proud of the following nasty hacks but we needed this working ASAP for the pilot |
| 26 | | |
| 27 | | |
| 28 | | // Query values from DB |
| 29 | | |
| 30 | | // THESE QUERIES are just for testing purpouses |
| 31 | | |
| 32 | | // Yield strength |
| 33 | | |
| 34 | | $query["yield"] = "select matid,propname,value,units from properties where lower(propname) like lower('Yield strength%') or lower(propname) like lower('%Strength%Yield%') or lower(propname) like lower('Tensile%Strength%Yield%')"; |
| 35 | | |
| 36 | | // Density |
| 37 | | $query["density"] = "select matid,value,units from properties where lower(propname) like lower('%density%')"; |
| 38 | | |
| 39 | | // Young's Modulus |
| 40 | | $query["young"] = "select matid,value,units from properties where lower(propname) like lower('%Modulus of Elasticity%')"; |
| 41 | | |
| 42 | | // Thermal conductivity |
| 43 | | $query["thermcond"] = " select matid,value,units from properties where lower(propname) like lower('%thermal%conductivity')"; |
| 44 | | |
| 45 | | // Heat capacity (only for 3) |
| 46 | | $query["Cp"] = "select matid,value,units from properties where lower(propname) like lower('%heat%capacity%') or lower(propname) like lower('%specific%heat%')"; |
| 47 | | |
| 48 | | |
| 49 | | // select value,matname from materials as m,properties as p where m.matid=p.matid and propid='pr1' |
| 50 | | |
| 51 | | switch($plot){ |
| 52 | | |
| 53 | | case "EvsYield": |
| 54 | | $Yquery = pg_query($conn,$query["young"]); |
| 55 | | $Xquery = pg_query($conn,$query["yield"]); |
| 56 | | break; |
| 57 | | |
| 58 | | case "EovDvsYieldovD": |
| 59 | | $Yquery = pg_query($conn,$query["young"]); |
| 60 | | $Xquery = pg_query($conn,$query["yield"]); |
| 61 | | $extra = pg_query($conn,$query["density"]); |
| 62 | | break; |
| 63 | | |
| 64 | | case "EvsD": |
| 65 | | $Yquery = pg_query($conn,$query["young"]); |
| 66 | | $Xquery = pg_query($conn,$query["density"]); |
| 67 | | break; |
| 68 | | |
| 69 | | case "KvsDCp": |
| 70 | | $Yquery = pg_query($conn,$query["thermcond"]); |
| 71 | | $Xquery = pg_query($conn,$query["Cp"]); |
| 72 | | $extra = pg_query($conn,$query["density"]); |
| 73 | | break; |
| 74 | | } |
| 75 | | |
| 76 | | |
| 77 | | // Fetch values from DB and sort them in an array (actually 3 arrays) |
| 78 | | |
| 79 | | if($Yquery && $Xquery){ |
| 80 | | |
| 81 | | $valuesY = array(); |
| 82 | | $valuesX = array(); |
| 83 | | $keysY = array(); |
| 84 | | $keysX = array(); |
| 85 | | $unitsY = array(); |
| 86 | | $unitsX = array(); |
| 87 | | |
| 88 | | |
| 89 | | |
| 90 | | while( $rowx = pg_fetch_array ($Xquery) ){ |
| 91 | | |
| 92 | | //fetching matid, value, units fields |
| 93 | | |
| 94 | | array_push($keysX,$rowx["matid"]); |
| 95 | | array_push($valuesX,$rowx["value"]); |
| 96 | | array_push($unitsX,$rowx["units"]); |
| 97 | | |
| 98 | | } |
| 99 | | |
| 100 | | |
| 101 | | while( $rowy = pg_fetch_array($Yquery) ){ |
| 102 | | |
| 103 | | //fetching matid, value, units fields |
| 104 | | |
| 105 | | array_push($keysY,$rowy["matid"]); |
| 106 | | array_push($valuesY,$rowy["value"]); |
| 107 | | array_push($unitsY,$rowy["units"]); |
| 108 | | } |
| 109 | | |
| 110 | | |
| 111 | | |
| 112 | | // Non very pretty hack for getting the common keys due to the lack |
| 113 | | // of array_intersect_assoc prior PHP <= 4.3 |
| 114 | | // Hope this solves the problem for now, and don't slow down things too much |
| 115 | | |
| 116 | | $dataY = array_combine($keysY, $valuesY); |
| 117 | | $dataX = array_combine($keysX, $valuesX); |
| 118 | | |
| 119 | | $uniY = array_combine($keysY, $unitsY); |
| 120 | | $uniX = array_combine($keysX, $unitsX); |
| 121 | | |
| 122 | | |
| 123 | | $valuesX = array(); |
| 124 | | $valuesY = array(); |
| 125 | | $unitsX = array(); |
| 126 | | $unitsY = array(); |
| 127 | | |
| 128 | | |
| 129 | | $common_keys = array_intersect($keysX, $keysY); |
| 130 | | |
| 131 | | // for (i in array resultante) { $valores[$llaves[$i]] } |
| 132 | | |
| 133 | | foreach($common_keys as $key){ |
| 134 | | |
| 135 | | array_push($valuesY,$dataY[$key]); |
| 136 | | array_push($valuesX,$dataX[$key]); |
| 137 | | |
| 138 | | array_push($unitsY,$uniY[$key]); |
| 139 | | array_push($unitsX,$uniX[$key]); |
| 140 | | |
| 141 | | |
| 142 | | } |
| 143 | | |
| 144 | | } |
| 145 | | |
| 146 | | |
| 147 | | if($extra){ |
| 148 | | |
| 149 | | $valuese = array(); |
| 150 | | $keyse = array(); |
| 151 | | $unitse = array(); |
| 152 | | |
| 153 | | while($rowextra = pg_fetch_array ($extra) ){ |
| 154 | | //fetching matid, value, units fields |
| 155 | | |
| 156 | | array_push($keyse,$rowextra["matid"]); |
| 157 | | array_push($valuese,$rowextra["value"]); |
| 158 | | array_push($unitse,$rowextra["units"]); |
| 159 | | } |
| 160 | | |
| 161 | | |
| 162 | | $datae = array_combine($keyse, $valuese); |
| 163 | | $unie = array_combine($keyse, $unitse); |
| 164 | | |
| 165 | | $valuese = array(); |
| 166 | | $unitse = array(); |
| 167 | | |
| 168 | | $common_keys = array_intersect($common_keys, $keyse); |
| 169 | | |
| 170 | | |
| 171 | | // for (i in array resultante) { $valores[$llaves[$i]] } |
| 172 | | |
| 173 | | foreach($common_keys as $key){ |
| 174 | | |
| 175 | | array_push($valuesY,$dataY[$key]); |
| 176 | | array_push($valuesX,$dataX[$key]); |
| 177 | | array_push($valuese,$datae[$key]); |
| 178 | | |
| 179 | | array_push($unitsY,$uniY[$key]); |
| 180 | | array_push($unitsX,$uniX[$key]); |
| 181 | | array_push($unitse,$unie[$key]); |
| 182 | | } |
| 183 | | } |
| 184 | | |
| 185 | | |
| 186 | | // Assign the actual useful data |
| 187 | | // NOTE: I AM not checking the units yet |
| 188 | | |
| 189 | | // Labels and Units |
| 190 | | //$xlabel = "Density (lb/cu in.)"; |
| 191 | | //$ylabel = "Electrical Conductivity (ohm-cir mil/ft)"; |
| 192 | | |
| 193 | | switch($plot){ |
| 194 | | |
| 195 | | case "EvsYield": |
| 196 | | $ylabel = "Young's Modulus ($unitsY[0])"; |
| 197 | | $xlabel = "Yield Strength ($unitsX[0])"; |
| 198 | | break; |
| 199 | | |
| 200 | | case "EvsD": |
| 201 | | $ylabel = "Young's Modulus ($unitsY[0])"; |
| 202 | | $xlabel = "Density ($unitsX[0])"; |
| 203 | | break; |
| 204 | | |
| 205 | | case "EovDvsYieldovD": |
| 206 | | $ylabel = "Young's Modulus / Density ($unitsY[0] / $unitse[0])"; |
| 207 | | $xlabel = "Yield Strength / Density ($unitsX[0] / $unitse[0])"; |
| 208 | | $valuesY = array_div($valuesY,$valuese); |
| 209 | | $valuesX = array_div($valuesX,$valuese); |
| 210 | | break; |
| 211 | | |
| 212 | | case "KvsDCp": |
| 213 | | $ylabel = "Thermal Conductivity $unitsY[0]"; |
| 214 | | $xlabel = "Heat Capacity * Density ($unitsX[0] * $unitse[0])"; |
| 215 | | $valuesX = array_mult($valuesX,$valuese); |
| 216 | | break; |
| 217 | | } |
| 218 | | |
| 219 | | |
| 220 | | //Fetch the materials names |
| 221 | | $in = "('" . implode("', '", $common_keys) . "')"; |
| 222 | | $name_query = pg_query($conn, "select matname from materials where matid in $in"); |
| 223 | | |
| 224 | | //echo "select matname from materials where matid in $in"; |
| 225 | | |
| 226 | | if($name_query){ |
| 227 | | $names = array(); |
| 228 | | while( $namerow = pg_fetch_row ($name_query)){ |
| 229 | | array_push($names,$namerow[0]); |
| 230 | | } |
| 231 | | } |
| 232 | | |
| 233 | | // Image generation part |