Changeset 121 for trunk/matml/webselector
- Timestamp:
- 10/26/2004 05:24:02 PM (7 years ago)
- Location:
- trunk/matml/webselector
- Files:
-
- 58 added
- 1 removed
- 5 modified
-
php/Caliban.otf (added)
-
php/Caliban.ttf (added)
-
php/CaslonBold.ttf (added)
-
php/CaslonRoman.ttf (added)
-
php/clicked.inc (added)
-
php/dbquery.php.inc (modified) (4 diffs)
-
php/functions.php.inc (modified) (3 diffs)
-
php/materials (added)
-
php/materials/AISI 1022 Steel, hot rolled, 1.xml (added)
-
php/materials/AISI 1548 Steel, annealed, col.xml (added)
-
php/materials/AISI Type 410 Stainless Steel,.xml (added)
-
php/materials/Allegheny Ludlum Martensitic S.xml (added)
-
php/materials/Aluminum 1199-O.xml (added)
-
php/materials/Ametek High Purity Nickel Stri.xml (added)
-
php/materials/ASTM A606 HSLA Steel, Cold Rol.xml (added)
-
php/materials/ASTM A606 HSLA Steel, Hot Roll1.xml (added)
-
php/materials/ASTM A606 HSLA Steel, Hot Roll.xml (added)
-
php/materials/Carpenter 20Cb-3__ Stainless S.xml (added)
-
php/materials/Carpenter Hiperco__ Alloy 50 F.xml (added)
-
php/materials/Carpenter HyMu _80___ Electron.xml (added)
-
php/materials/Carpenter MP35N_ Ni-Co-Cr-Mo A.xml (added)
-
php/materials/Ceraflex 3Y Thin Zirconia Cera.xml (added)
-
php/materials/Ciba Tactix__ 123 Epoxy.xml (added)
-
php/materials/Ciba Tactix__ 138 Epoxy.xml (added)
-
php/materials/DuPont Kevlar__ 149 Fiber, dia.xml (added)
-
php/materials/DuPont Kevlar__ 49 Aramid Fibe.xml (added)
-
php/materials/EMS-Grivory Grilon A28NZ Nylon.xml (added)
-
php/materials/GE Advanced Ceramics Boralloy_.xml (added)
-
php/materials/GE Plastics LEXAN 500 Polycarb.xml (added)
-
php/materials/GE Plastics LEXAN 503 Polycarb.xml (added)
-
php/materials/GE Plastics Lexan__ Polycarbon.xml (added)
-
php/materials/GE Plastics SUPEC G401 PPS (No.xml (added)
-
php/materials/GE Plastics ULTEM 6000 Polyeth.xml (added)
-
php/materials/Hard Lead (96Pb-4Sb), UNS L529.xml (added)
-
php/materials/Haynes__ 188 alloy, hot rolled.xml (added)
-
php/materials/ICHS Fiberfax__ Alumina-Silica.xml (added)
-
php/materials/Industeel SOLEIL A2 13% Cr Hig.xml (added)
-
php/materials/Lead, Pb.xml (added)
-
php/materials/Magnesium HM21A-T8, Sheet and .xml (added)
-
php/materials/Magnesium M1A Forgings.xml (added)
-
php/materials/Nickelvac__ X-750 Nickel Super.xml (added)
-
php/materials/PolyOne Edgetek__ NN-10KV_000 .xml (added)
-
php/materials/Sam Yang TRILOY__ 200 General .xml (added)
-
php/materials/Sapco Silicon Nitride, Si 3 N.xml (added)
-
php/materials/Sapco Si.SiC Silicon Carbide.xml (added)
-
php/materials/Special Metals DURANICKEL__ 30.xml (added)
-
php/materials/Special Metals Nickel 200.xml (added)
-
php/materials/Special Metals Nickel 270.xml (added)
-
php/materials/Special Metals NIMONIC™ .xml (added)
-
php/materials/Steatite (Magnesium Silicon Ox.xml (added)
-
php/materials/Thornel__ Carbon Fiber T-300 3.xml (added)
-
php/materials/Ticona Celanese__ Nylon 1000 N.xml (added)
-
php/materials/TIMETAL__ 1100 Titanium Alloy .xml (added)
-
php/materials/Titanium Grade 2.xml (added)
-
php/materials/Titanium, Ti.xml (added)
-
php/materials/UNS C81100, Copper Casting All.xml (added)
-
php/materials/UNS C83600, Copper Casting All.xml (added)
-
php/materials/UNS C90300, Copper Casting All.xml (added)
-
php/materials/UNS C96400, Copper Casting All.xml (added)
-
php_parser (deleted)
-
php/php_errors.txt (added)
-
php/plot.php (modified) (4 diffs)
-
php/select.php (modified) (2 diffs)
-
php/style.css (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/matml/webselector/php/dbquery.php.inc
r76 r121 1 <? 2 function db_get_plot_values($plottype, $log){ 3 4 include("db.php.inc"); 1 <?php 2 class Unit 3 { 4 var $name; 5 var $num_name; 6 //Multiple existing value by scale to get num_name 7 var $scale; 8 function Unit($name,$num_name,$scale) 9 { 10 $this->name=$name; 11 $this->num_name=$num_name; 12 $this->scale=$scale; 13 } 14 function name_split() 15 { 16 $ret=explode("/",$this->name); 17 if(!isset($ret[1])) 18 $ret[1]=""; 19 return $ret; 20 } 21 function div($other) 22 { 23 $mine=$this->name_split(); 24 $eirs=$other->name_split(); 25 if($mine[0]&&$eirs[1]) 26 $mine[0].="-$eirs[1]"; 27 else 28 $mine[0].=$eirs[1]; 29 if($mine[1]&&$eirs[0]) 30 $mine[1].="-$eirs[0]"; 31 else 32 $mine[1].=$eirs[0]; 33 if(!$mine[1]) 34 $name=$mine[0]; 35 else 36 $name="$mine[0]/$mine[1]"; 37 $ret=new Unit( 38 $name, 39 $this->num_name/$other->num_name, 40 $this->scale/$other->scale 41 ); 42 return $ret; 43 } 44 function mul($other) 45 { 46 $mine=$this->name_split(); 47 $eirs=$other->name_split(); 48 if($mine[0]&&$eirs[0]) 49 $mine[0].="-$eirs[0]"; 50 else 51 $mine[0].=$eirs[0]; 52 if($mine[1]&&$eirs[1]) 53 $mine[1].="-$eirs[1]"; 54 else 55 $mine[1].=$eirs[1]; 56 if(!$mine[1]) 57 $name=$mine[0]; 58 else 59 $name="$mine[0]/$mine[1]"; 60 $ret=new Unit( 61 "$name", 62 $this->num_name*$other->num_name, 63 $this->scale*$other->scale 64 ); 65 return $ret; 66 } 67 function equals($other) 68 { 69 return abs($this->num_name-$other)<.00000001; 70 } 71 } 72 73 $unit_infos=array( 74 "g"=>new Unit("g",2,1), 75 "m"=>new Unit("m",3,1), 76 "K"=>new Unit("K",5,1), 77 "s"=>new Unit("s",7,1), 78 "°C"=>new Unit("°C",11,1), 79 "lb"=>new Unit("lb",13,1), 80 "°F"=>new Unit("°F",17,1), 81 //kg m s2 82 "N"=>new Unit("N",2*3/(7*7),1000), 83 //1 pound = 4.44822162 Newtons 84 "p"=>new Unit("p",2*3/(7*7),4.44822162*1000), 85 "in"=>new Unit("in",3,0.0254), 86 "cm"=>new Unit("cm",3,.01), 87 //kg*m*m/(s^3) 88 "W"=>new Unit("W",2*3*3/(7*7*7),1000), 89 //N m-2 90 "Pa"=>new Unit("Pa",2*3/(7*7)/(3*3),1000), 91 "MPa"=>new Unit("MPa",2*3/(7*7)/(3*3),1000000*1000), 92 "cc"=>new Unit("cc",3*3*3,.01*.01*.01), 93 //1 kg × 1 m2 × 1 s-2 94 "J"=>new Unit("J",2*3*3/(7*7),1000), 95 "BTU"=>new Unit("BTU",2*3*3/(7*7),1055*1000), 96 "hr"=>new Unit("hr",7,60*60), 97 "ft"=>new Unit("ft",3,12*0.0254) 98 ); 99 100 class PropertyData 101 { 102 //average value out of all the matches 103 var $avg_value; 104 var $num_unit; 105 //number of matches 106 var $count; 107 function PropertyData() 108 { 109 $this->avg_value=0; 110 $this->num_unit=0; 111 $this->count=0; 112 } 113 } 114 115 function parse_units($units_element) 116 { 117 global $unit_infos; 118 global $dom; 119 $scale=1; 120 if(get_class($units_element)=="DOMNodeList") 121 $units_element=$units_element->item(0); 122 if($units_element) 123 { 124 $num_unit=1; 125 $factor=$units_element->getAttribute("factor"); 126 if($factor) 127 $scale*=$factor; 128 //$units=$units_element->get_elements_by_tagname("Unit"); 129 $units=$units_element->getElementsByTagName("Unit"); 130 foreach($units as $unit) 131 { 132 $name=$unit->getElementsByTagName("Name"); 133 $name=$name->item(0); 134 $name=$name->nodeValue; 135 $power=$unit->getAttribute("power"); 136 if(!$power) 137 $power=1; 138 $unit_info=$unit_infos[$name]; 139 if(!$unit_info) 140 echo "Error: unknown unit $name\n"; 141 $scale*=pow($unit_info->scale,$power); 142 $num_unit*=pow($unit_info->num_name,$power); 143 } 144 } 145 else 146 $num_unit=0; 147 return array($scale,$num_unit); 148 } 149 150 function get_property_data($filename,$property_names) 151 { 152 global $dom; 153 $dom=new DOMDocument; 154 $dom->loadXML(file_get_contents($filename)); 155 $context=new DOMXPath($dom); 156 157 $equivalencies=array( 158 array_flip(array("Young's Modulus","Modulus of Elasticity","Tensile Modulus")), 159 array_flip(array("Tensile Strength, Yield","Yield Strength","Tensile Strength @ Yield")), 160 array_flip(array("Heat Capacity","Specific Heat")) 161 ); 162 $translation_string="\"abcdefghijklmnopqrstuvwxyz'\",'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"; 163 $ret=array(); 164 $details=$context->query("/MatML_Doc/Material/BulkDetails/Name/text()"); 165 $item=$details->item(0); 166 $Matid=$item->nodeValue; 167 foreach($property_names as $key=>$property_name) 168 { 169 $found=false; 170 foreach($equivalencies as $equivalency) 171 { 172 if(array_key_exists($property_name,$equivalency)) 173 { 174 $name_condition=""; 175 foreach($equivalency as $equiv=>$value) 176 { 177 if($name_condition!="") 178 $name_condition.=" or "; 179 $name_condition.="translate(Name,$translation_string)='".strtoupper(strtr($equiv,array("'"=>"")))."'"; 180 } 181 $found=true; 182 break; 183 } 184 } 185 if($property_name=="Material Name") 186 { 187 $ret[$key]=$Matid; 188 continue; 189 } 190 else if($property_name=="Material Categories") 191 { 192 $categories=array(); 193 $queried=$context->query("/MatML_Doc/Material/BulkDetails/Class/Name/text()"); 194 foreach($queried as $category) 195 { 196 $categories[]=$category->nodeValue; 197 } 198 $queried=$context->query("/MatML_Doc/Material/BulkDetails/Subclass/Name/text()"); 199 foreach($queried as $category) 200 { 201 $categories[]=$category->nodeValue; 202 } 203 $ret[$key]=$categories; 204 continue; 205 } 206 else if(!$found) 207 { 208 $name_condition="translate(Name,$translation_string)='".strtoupper($property_name)."'"; 209 } 210 $details=$context->query("/MatML_Doc/Metadata/PropertyDetails[$name_condition]"); 211 $data=new PropertyData; 212 if(!$details->length) 213 continue; 214 foreach($details as $detail) 215 { 216 $units=$detail->getElementsByTagName("Units"); 217 list($scale,$num_unit)=parse_units($units); 218 if(!$data->num_unit) 219 $data->num_unit=$num_unit; 220 else 221 { 222 force_unit_match($Matid,new Unit("unknown",$num_unit,$scale),$data); 223 } 224 225 $propid=$detail->getAttribute("id"); 226 $property_datas=$context->query("/MatML_Doc/Material/BulkDetails/PropertyData[@property='$propid']/Data"); 227 foreach($property_datas as $property_data) 228 { 229 $data->count++; 230 $data->avg_value+=$property_data->nodeValue*$scale; 231 } 232 } 233 if($data->count) 234 $data->avg_value/=$data->count; 235 $ret[$key]=$data; 236 } 237 return $ret; 238 } 239 240 function fractionalize($number) 241 { 242 $integer=floor($number); 243 $decimal=$number-$integer; 244 if($decimal<.00000001) 245 return array($integer,1); 246 if($decimal>.99999999) 247 return array($integer+1,1); 248 $denominator=fractionalize(1/$decimal); 249 $denominator=$denominator[0]; 250 return array(round($number*$denominator),$denominator); 251 } 252 253 function get_factor_power($number,$factor) 254 { 255 $power=0; 256 list($numerator,$denominator)=fractionalize($number); 257 if($numerator==0) 258 return 0; 259 list($fn,$fd)=fractionalize($factor); 260 while(($numerator % $fn)==0 && ($denominator % $fd) == 0) 261 { 262 $numerator/=$fn; 263 $denominator/=$fd; 264 $power++; 265 } 266 if($power||$denominator==1) 267 return $power; 268 while(($numerator % $fd)==0 && ($denominator % $fn) == 0) 269 { 270 $numerator/=$fd; 271 $denominator/=$fn; 272 $power--; 273 } 274 return $power; 275 } 276 277 function force_unit_match($material,$unit,&$property_data) 278 { 279 //Convert BTUs per degree F to Joules per degree C 280 $BTUs_per_degree_F=2*3*3/(7*7)/17; 281 $power=get_factor_power($property_data->num_unit,$BTUs_per_degree_F); 282 $property_data->num_unit*=pow($BTUs_per_degree_F,-$power)*pow( 283 2*3*3/(7*7)/11,$power); 284 $property_data->avg_value*=pow( 285 1899.1009999999999/1000,$power); 286 287 if(!$unit->equals($property_data->num_unit)) 288 { 289 $power=get_factor_power($property_data->num_unit,13); 290 if($unit->equals($property_data->num_unit*pow(13,-$power)*pow(2*3/(7*7),$power))) 291 { 292 //it uses pound as a force 293 $property_data->num_unit*=pow(13,-$power)*pow(2*3/(7*7),$power); 294 $property_data->avg_value*=pow(4.44822162*1000,$power); 295 return true; 296 } 297 if($unit->equals($property_data->num_unit*pow(13,-$power)*pow(2,$power))) 298 { 299 //it uses pound as a mass 300 $property_data->num_unit*=pow(13,-$power)*pow(2,$power); 301 $property_data->avg_value*=pow(453.59237,$power); 302 return true; 303 } 304 echo "Error: unit mismatch ($unit->name $unit->num_name vs $property_data->num_unit) in $material\n"; 305 return false; 306 } 307 return true; 308 } 309 310 function db_get_plot_values($plottype, $log, $category_options){ 311 global $unit_infos; 5 312 6 313 // So far only 4 plot types … … 14 321 //$utsys = "0"; 15 322 16 // I am not very proud of the following nasty hacks but we needed this working ASAP for the pilot 17 18 19 // Query values from DB 20 21 // THESE QUERIES are just for testing purpouses 22 23 // Yield strength 24 25 $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%')"; 26 27 // Density 28 $query["density"] = "select matid,value,units from properties where lower(propname) like lower('%density%')"; 29 30 // Young's Modulus 31 $query["young"] = "select matid,value,units from properties where lower(propname) like lower('%Modulus of Elasticity%')"; 32 33 // Thermal conductivity 34 $query["thermcond"] = " select matid,value,units from properties where lower(propname) like lower('%thermal%conductivity')"; 35 36 // Heat capacity (only for 3) 37 $query["Cp"] = "select matid,value,units from properties where lower(propname) like lower('%heat%capacity%') or lower(propname) like lower('%specific%heat%')"; 38 39 40 // select value,matname from materials as m,properties as p where m.matid=p.matid and propid='pr1' 41 42 switch($plottype){ 43 44 case "EvsYield": 45 $Yquery = pg_query($conn,$query["young"]); 46 $Xquery = pg_query($conn,$query["yield"]); 323 324 switch($plottype){ 325 326 case "EvsYield": 327 $query=array( 328 "Yquery"=>"Young's Modulus", 329 "Xquery"=>"Tensile Strength, Yield", 330 "Matid"=>"Material Name" 331 ); 332 $final_units=array( 333 "Yquery"=>$unit_infos["MPa"], 334 "Xquery"=>$unit_infos["MPa"] 335 ); 47 336 break; 48 337 49 338 case "EovDvsYieldovD": 50 $Yquery = pg_query($conn,$query["young"]); 51 $Xquery = pg_query($conn,$query["yield"]); 52 $extra = pg_query($conn,$query["density"]); 339 $query=array( 340 "Yquery"=>"Young's Modulus", 341 "Xquery"=>"Tensile Strength, Yield", 342 "extra"=>"Density", 343 "Matid"=>"Material Name" 344 ); 345 $final_units=array( 346 "Yquery"=>$unit_infos["MPa"], 347 "Xquery"=>$unit_infos["MPa"], 348 "extra"=>$unit_infos["g"]->div($unit_infos["cc"]) 349 ); 53 350 break; 54 351 55 352 case "EvsD": 56 $Yquery = pg_query($conn,$query["young"]); 57 $Xquery = pg_query($conn,$query["density"]); 353 $query=array( 354 "Yquery"=>"Young's Modulus", 355 "Xquery"=>"Density", 356 "Matid"=>"Material Name" 357 ); 358 $final_units=array( 359 "Yquery"=>$unit_infos["MPa"], 360 "Xquery"=>$unit_infos["g"]->div($unit_infos["cc"]) 361 ); 58 362 break; 59 363 60 364 case "KvsDCp": 61 $Yquery = pg_query($conn,$query["thermcond"]); 62 $Xquery = pg_query($conn,$query["Cp"]); 63 $extra = pg_query($conn,$query["density"]); 365 $query=array( 366 "Yquery"=>"Thermal Conductivity", 367 "Xquery"=>"Heat Capacity", 368 "extra"=>"Density", 369 "Matid"=>"Material Name" 370 ); 371 $final_units=array( 372 "Yquery"=>$unit_infos["W"]->div($unit_infos["m"]->mul($unit_infos["K"])), 373 "Xquery"=>$unit_infos["J"]->div($unit_infos["g"]->mul($unit_infos["°C"])), 374 "extra"=>$unit_infos["g"]->div($unit_infos["cc"]) 375 ); 64 376 break; 65 377 } 66 67 68 // Fetch values from DB and sort them in an array (actually 3 arrays) 69 70 if($Yquery && $Xquery){ 71 378 $query["categories"]="Material Categories"; 379 72 380 $valuesY = array(); 73 381 $valuesX = array(); 74 $keysY = array();75 $keysX = array();76 $unitsY = array();77 $unitsX = array();78 79 80 81 while( $rowx = pg_fetch_array ($Xquery) ){82 83 //fetching matid, value, units fields84 85 array_push($keysX,$rowx["matid"]);86 array_push($valuesX,$rowx["value"]);87 array_push($unitsX,$rowx["units"]);88 89 }90 91 92 while( $rowy = pg_fetch_array($Yquery) ){93 94 //fetching matid, value, units fields95 96 array_push($keysY,$rowy["matid"]);97 array_push($valuesY,$rowy["value"]);98 array_push($unitsY,$rowy["units"]);99 }100 101 102 103 // Non very pretty hack for getting the common keys due to the lack104 // of array_intersect_assoc prior PHP <= 4.3105 // Hope this solves the problem for now, and don't slow down things too much106 107 $dataY = array_combine($keysY, $valuesY);108 $dataX = array_combine($keysX, $valuesX);109 110 $uniY = array_combine($keysY, $unitsY);111 $uniX = array_combine($keysX, $unitsX);112 113 114 $valuesX = array();115 $valuesY = array();116 $unitsX = array();117 $unitsY = array();118 119 120 $common_keys = array_intersect($keysX, $keysY);121 122 // for (i in array resultante) { $valores[$llaves[$i]] }123 124 foreach($common_keys as $key){125 126 array_push($valuesY,$dataY[$key]);127 array_push($valuesX,$dataX[$key]);128 129 array_push($unitsY,$uniY[$key]);130 array_push($unitsX,$uniX[$key]);131 132 133 }134 135 }136 137 138 if($extra){139 140 382 $valuese = array(); 141 $keyse = array(); 142 $unitse = array(); 143 144 while($rowextra = pg_fetch_array ($extra) ){ 145 //fetching matid, value, units fields 146 147 array_push($keyse,$rowextra["matid"]); 148 array_push($valuese,$rowextra["value"]); 149 array_push($unitse,$rowextra["units"]); 150 } 151 152 153 $datae = array_combine($keyse, $valuese); 154 $unie = array_combine($keyse, $unitse); 155 156 $valuese = array(); 157 $unitse = array(); 158 159 $common_keys = array_intersect($common_keys, $keyse); 160 161 162 // for (i in array resultante) { $valores[$llaves[$i]] } 163 164 foreach($common_keys as $key){ 165 166 array_push($valuesY,$dataY[$key]); 167 array_push($valuesX,$dataX[$key]); 168 array_push($valuese,$datae[$key]); 169 170 array_push($unitsY,$uniY[$key]); 171 array_push($unitsX,$uniX[$key]); 172 array_push($unitse,$unie[$key]); 173 } 174 } 383 $categories = array(); 384 385 $handle = opendir('materials'); 386 387 while (false !== ($file = readdir($handle))) { 388 if(preg_match("/\.xml?$/",$file)==1) 389 { 390 // Fetch values from DB and sort them in an array (actually 3 arrays) 391 $values=get_property_data("materials/$file",$query); 392 393 if(isset($values["Xquery"])&& 394 isset($values["Yquery"]) 395 ) 396 { 397 $values_categories=$values["categories"]; 398 $values_categories[]=""; 399 foreach($values_categories as $category) 400 { 401 if(isset($category_options[$category])) 402 break; 403 } 404 if(!isset($category_options[$category])) 405 continue; 406 $category=$category_options[$category]; 407 force_unit_match($values["Matid"],$final_units["Xquery"],$values["Xquery"]); 408 force_unit_match($values["Matid"],$final_units["Yquery"],$values["Yquery"]); 409 if(isset($query["extra"])) 410 { 411 if(isset($values["extra"])) 412 { 413 force_unit_match($values["Matid"],$final_units["extra"],$values["extra"]); 414 $valuesX[]=($values["Xquery"]->avg_value/$final_units["Xquery"]->scale); 415 $valuesY[]=($values["Yquery"]->avg_value/$final_units["Yquery"]->scale); 416 $valuese[]=$values["extra"]->avg_value/$final_units["extra"]->scale; 417 $names[]=$values["Matid"]; 418 $categories[]=$category; 419 } 420 } 421 else 422 { 423 $valuesX[]=($values["Xquery"]->avg_value/$final_units["Xquery"]->scale); 424 $valuesY[]=($values["Yquery"]->avg_value/$final_units["Yquery"]->scale); 425 $names[]=$values["Matid"]; 426 $categories[]=$category; 427 } 428 } 429 } 430 } 431 closedir($handle); 175 432 176 433 177 434 // Assign the actual useful data 178 // NOTE: I AM not checking the units yet179 435 180 436 // Labels and Units … … 185 441 186 442 case "EvsYield": 187 $ylabel = "Young's Modulus ( $unitsY[0])";188 $xlabel = "Yield Strength ( $unitsX[0])";443 $ylabel = "Young's Modulus (".$final_units["Yquery"]->name.")"; 444 $xlabel = "Yield Strength (".$final_units["Xquery"]->name.")"; 189 445 break; 190 446 191 447 case "EvsD": 192 $ylabel = "Young's Modulus ( $unitsY[0])";193 $xlabel = "Density ( $unitsX[0])";448 $ylabel = "Young's Modulus (".$final_units["Yquery"]->name.")"; 449 $xlabel = "Density (".$final_units["Xquery"]->name.")"; 194 450 break; 195 451 196 452 case "EovDvsYieldovD": 197 $ylabel = "Young's Modulus / Density ( $unitsY[0] / $unitse[0])";198 $xlabel = "Yield Strength / Density ( $unitsX[0] / $unitse[0])";453 $ylabel = "Young's Modulus / Density (".$final_units["Yquery"]->name." / ".$final_units["extra"]->name.")"; 454 $xlabel = "Yield Strength / Density (".$final_units["Xquery"]->name." / ".$final_units["extra"]->name.")"; 199 455 $valuesY = array_div($valuesY,$valuese); 200 456 $valuesX = array_div($valuesX,$valuese); … … 202 458 203 459 case "KvsDCp": 204 $ylabel = "Thermal Conductivity $unitsY[0]";205 $xlabel = "Heat Capacity * Density ( $unitsX[0] * $unitse[0])";460 $ylabel = "Thermal Conductivity (".$final_units["Yquery"]->name.")"; 461 $xlabel = "Heat Capacity * Density (".$final_units["Xquery"]->name." * ".$final_units["extra"]->name.")"; 206 462 $valuesX = array_mult($valuesX,$valuese); 207 463 break; 208 464 } 209 465 210 211 //Fetch the materials names 212 $in = "('" . implode("', '", $common_keys) . "')"; 213 $name_query = pg_query($conn, "select matname from materials where matid in $in"); 214 215 //echo "select matname from materials where matid in $in"; 216 217 if($name_query){ 218 $names = array(); 219 while( $namerow = pg_fetch_row ($name_query)){ 220 array_push($names,$namerow[0]); 221 } 222 } 223 224 return array(&$valuesX, &$valuesY, &$names, $xlabel, $ylabel); 225 226 } 227 466 return array(&$valuesX, &$valuesY, &$names, $xlabel, $ylabel, $categories); 467 468 } 469 470 //var_dump(db_get_plot_values("EvsD","")); 228 471 ?> -
trunk/matml/webselector/php/functions.php.inc
r48 r121 1 1 <? 2 if(version_compare(phpversion(),"5.0.0","<")) 3 { 2 4 function array_combine($array_keys, $array_values) { 3 5 $t = array(); … … 9 11 } 10 12 return $t; 13 } 11 14 } 12 15 … … 36 39 37 40 38 39 41 ?> -
trunk/matml/webselector/php/plot.php
r79 r121 3 3 include("dbquery.php.inc"); 4 4 5 //by "likavcan at NOSPAN sturak nospan dot sk" at from php.net 6 function arrow($im, $x1, $y1, $x2, $y2, $alength, $awidth, $color) { 7 8 $distance = sqrt(pow($x1 - $x2, 2) + pow($y1 - $y2, 2)); 9 10 $dx = $x2 + ($x1 - $x2) * $alength / $distance; 11 $dy = $y2 + ($y1 - $y2) * $alength / $distance; 12 $k = $awidth / $alength; 13 14 $x2o = $x2 - $dx; 15 $y2o = $dy - $y2; 16 17 $x3 = $y2o * $k + $dx; 18 $y3 = $x2o * $k + $dy; 19 20 $x4 = $dx - $y2o * $k; 21 $y4 = $dy - $x2o * $k; 22 23 imageline($im, $x1, $y1, $dx, $dy, $color); 24 imageline($im, $x3, $y3, $x4, $y4, $color); 25 imageline($im, $x3, $y3, $x2, $y2, $color); 26 imageline($im, $x2, $y2, $x4, $y4, $color); 27 28 } 29 30 function calc_tickscale($max_value,$min_ticks,$max_labels) 31 { 32 //First see how many labels we can get in 33 $tickscale=pow(10,floor(log($max_value,10))); 34 while($max_value/$tickscale*10<=$max_labels) 35 $tickscale/=10; 36 //That's as far as we can break up the labels for powers of 10. 37 //Maybe we can break it up by 5 or 2 38 $ticks=$max_value/$tickscale; 39 $divisions=1; 40 if($ticks*5<=$max_labels) 41 $divisions=5; 42 else if($ticks*2<=$max_labels) 43 $divisions=2; 44 $tickscale/=$divisions; 45 $ticks*=$divisions; 46 47 //Label interval is how many ticks to have before a label 48 $label_interval=1; 49 if($ticks*$divisions<$min_ticks&&$divisions!=1) 50 { 51 //the tickscale needs to be broken up more for the ticks 52 //(but not labels). Gotta undo the last factor then for the ticks. 53 $label_interval=10/$divisions; 54 $tickscale/=10/$divisions; 55 } 56 57 //Do we still need to break the ticks up more? 58 while($max_value/$tickscale<$min_ticks) 59 { 60 if($max_value/$tickscale*2>=$min_ticks) 61 { 62 $label_interval*=2; 63 $tickscale/=2; 64 break; 65 } 66 if($max_value/$tickscale*5>=$min_ticks) 67 { 68 $label_interval*=5; 69 $tickscale/=5; 70 break; 71 } 72 $label_interval*=10; 73 $tickscale/=10; 74 } 75 return array($tickscale,$label_interval); 76 } 77 5 78 //Request arguments 6 79 7 $plottype = $_REQUEST['plot']; 80 if(isset($_REQUEST['plot'])) 81 $plottype = $_REQUEST['plot']; 82 else 83 $plottype = 'EvsYield'; 8 84 if(isset($_REQUEST['log'])) 9 85 $log = $_REQUEST['log']; 10 86 else 11 87 $log = 0; 12 88 if(isset($_REQUEST['selected'])) 89 $selected = $_REQUEST['selected']; 90 else 91 $selected = ''; 92 $categorizations=array(array(""=>0),array("Metals"=>0,"Polymers"=>1,"Ceramics"=>2,"Fibers"=>1)); 93 if(isset($_REQUEST['categorization'])) 94 $categorization=$categorizations[$_REQUEST['categorization']]; 95 else 96 $categorization=$categorizations[0]; 13 97 14 98 //get the values from the database with these function 15 list($valuesX, $valuesY, $names, $xlabel, $ylabel ) = db_get_plot_values($plottype, $log);99 list($valuesX, $valuesY, $names, $xlabel, $ylabel, $categories) = db_get_plot_values($plottype, $log, $categorization); 16 100 17 101 $number_mat = count($names); 18 102 19 103 20 $Isize = 450; 21 22 $image = ImageCreate($Isize, $Isize); 104 $Iwidth=600; 105 $Iheight=450; 106 107 $left_border=35; 108 $top_border=1; 109 $right_border=1; 110 $bottom_border=50; 111 112 $inside_border=5; 113 $tick_length=4; 114 $axis_value_label_size=12; 115 116 $image = ImageCreate($Iwidth, $Iheight); 23 117 24 118 $white = ImageColorAllocate($image, 255, 255, 255); 25 119 $grey = ImageColorAllocate($image, 220, 220, 220); 26 120 $black = ImageColorAllocate($image, 0, 0, 0); 27 $blue = ImageColorAllocate($image, 0, 123, 255); 28 29 30 ImageRectangle($image, 0, 0, 449, 449, $black); 31 ImageFilledRectangle($image, 20, 20, 430, 430, $grey); 32 ImageRectangle($image, 20, 20, 430, 430, $black); 121 $category_colors=array(ImageColorAllocate($image, 0, 0, 255),ImageColorAllocate($image, 255, 0, 0),ImageColorAllocate($image, 0, 255, 0)); 122 $selected_color = ImageColorAllocate($image, 255, 255, 255); 123 124 $bgcolor = ImageColorAllocate($image, 0xe5, 0xe8, 0xb2); 33 125 34 126 // For using a nice font 35 36 $font = "vixar.ttf"; 37 38 //$valuesX = array(0,10,20,30); 39 //$valuesY = array(0,10,20,30); 40 //$number_mat =array(1,10,20,30); 41 // Hardcoded sizes for the plot, better to be left alone 42 43 $width = 380; 44 $height = 380; 45 46 $x_initial = 20; 47 $y_initial = 380; 127 $axis_value_font = "helcr.ttf"; 128 $font = "CaslonBold.ttf"; 129 130 //Figure out extra left border for y axis values 131 if($log == 1){ 132 } 133 else{ 134 $ymax=max($valuesY); 135 $yscale = ($Iheight-$top_border-$bottom_border-2*$inside_border) / $ymax; 136 137 list($ytickscale,$ylabel_interval)=calc_tickscale($ymax,20,25); 138 139 $widest_label_width=0; 140 for($valueY=0; $valueY<$ymax; $valueY+=$ylabel_interval*$ytickscale) 141 { 142 $label_width=imagettfbbox($axis_value_label_size,0,$axis_value_font,$valueY); 143 $label_width=$label_width[2]; 144 if($label_width>$widest_label_width) 145 $widest_label_width=$label_width; 146 } 147 $left_border+=$widest_label_width; 148 } 149 150 ImageFilledRectangle($image, 0, 0, $Iwidth, $Iheight, $bgcolor); 151 //ImageRectangle($image, 0, 0, 449, 449, $black); 152 ImageFilledRectangle($image, $left_border, $top_border, $Iwidth-$right_border-1, $Iheight-$bottom_border-1, $grey); 153 //ImageRectangle($image, 20, 20, 430, 430, $black); 154 arrow($image,$left_border,$Iheight-$bottom_border,$Iwidth-$right_border,$Iheight-$bottom_border,4,4,$black); 155 arrow($image,$left_border,$Iheight-$bottom_border,$left_border,0,4,4,$black); 48 156 49 157 // Broken Log scale Attempt … … 62 170 } 63 171 else{ 64 $width_bar = 0.90 * $width / max($valuesX); 65 $height_bar = 0.90 * $height / max($valuesY); 172 $xmax=max($valuesX); 173 $xscale = ($Iwidth-$left_border-$right_border-2*$inside_border) / $xmax; 174 175 //Draw in the scale ticks on the axes 176 177 //We'll estimate the widest label value as the width of xmax 178 //This isn't entirely correct because a decimal point can occur based 179 //on the divisions 180 $label_width=imagettfbbox($axis_value_label_size,0,$axis_value_font,floor($xmax)); 181 $label_width=$label_width[2]+15; //+15 for padding 182 list($xtickscale,$xlabel_interval)=calc_tickscale($xmax,20,($Iwidth-$left_border-$right_border)/$label_width); 183 184 for($i=0,$valueX=0; $valueX<$xmax; $i++,$valueX+=$xtickscale) 185 { 186 $x = $left_border + $inside_border + $xscale * $valueX; 187 $y = $Iheight - $bottom_border; 188 $label_width=imagettfbbox($axis_value_label_size,0,$axis_value_font,$valueY); 189 $label_width=$label_width[2]; 190 if($i%$xlabel_interval==0) 191 { 192 imageline($image, $x, $y-$tick_length/2, $x, $y+$tick_length, $black); 193 $label_width=imagettfbbox($axis_value_label_size,0,$axis_value_font,$valueX); 194 $label_height=-$label_width[7]; 195 $label_width=$label_width[2]; 196 imagettftext($image,$axis_value_label_size,0,$x-$label_width/2-1,$Iheight-$bottom_border+$label_height+$tick_length/2+4,$black,$axis_value_font,$valueX); 197 } 198 else 199 imageline($image, $x, $y-.5*$tick_length/2, $x, $y+.5*$tick_length, $black); 200 } 201 for($i=0,$valueY=0; $valueY<$ymax; $i++,$valueY+=$ytickscale) 202 { 203 $x = $left_border; 204 $y = $Iheight - $bottom_border - $inside_border - $yscale * $valueY; 205 if($y<10) 206 break; 207 if($i%$ylabel_interval==0) 208 { 209 imageline($image, $x+$tick_length/2, $y, $x-$tick_length, $y, $black); 210 $label_width=imagettfbbox($axis_value_label_size,0,$axis_value_font,$valueY); 211 $label_width=$label_width[2]; 212 imagettftext($image,$axis_value_label_size,0,$left_border-$label_width-$tick_length/2-4,$y+6,$black,$axis_value_font,$valueY); 213 } 214 else 215 imageline($image, $x+.5*$tick_length/2, $y, $x-.5*$tick_length, $y, $black); 216 } 66 217 } 67 218 … … 76 227 } 77 228 else{ 78 $x = $ x_initial + $width_bar* $valuesX[$i];79 $y = $ y_initial - $height_bar* $valuesY[$i];229 $x = $left_border + $inside_border + $xscale * $valuesX[$i]; 230 $y = $Iheight - $bottom_border - $inside_border - $yscale * $valuesY[$i]; 80 231 } 81 232 … … 84 235 // echo "X: $valuesX[$i] Y: $valuesY[$i]<br>"; 85 236 86 237 if($selected==$names[$i]) 238 $color=$selected_color; 239 else 240 $color=$category_colors[$categories[$i]]; 87 241 ImageFilledRectangle($image, $x - 2, $y - 2, $x + 2, 88 $y + 2, $ blue);242 $y + 2, $color); 89 243 ImageRectangle($image, $x - 2, $y - 2, $x + 2, 90 244 $y + 2, $black); 91 245 92 imagettftext($image, 14, 0, $x-25, $y-3, $black, $font, $names[$i]); 93 } 94 imagettftext($image, 14, 0, .75 * $Isize/2, $Isize * 0.99, $black, $font, $xlabel); 95 imagettftext($image, 14, 90, 15 , 1.25*($Isize)/2, $black, $font, $ylabel); 246 //imagettftext($image, 14, 0, $x-25, $y-3, $black, $font, $names[$i]); 247 } 248 $label_width=imagettfbbox(14,0,$font,$xlabel); 249 $label_width=$label_width[2]; 250 imagettftext($image, 14, 0, $left_border+($Iwidth-$left_border-$right_border)/2-$label_width/2, $Iheight-5, $black, $font, $xlabel); 251 252 $label_width=imagettfbbox(14,0,$font,$ylabel); 253 $label_width=$label_width[2]; 254 imagettftext($image, 14, 90, 17 , ($Iheight-$top_border-$bottom_border)/2+$label_width/2, $black, $font, $ylabel); 96 255 97 256 Header("Content-Type: image/png"); -
trunk/matml/webselector/php/select.php
r79 r121 8 8 <meta name="Keywords" content="Materials Engineering, Metallurgy, Materials Learning"> 9 9 <title>MatDL:: Materials Selector</title> 10 <link rel="stylesheet" title="Default" href="style.css" type="text/css" media="screen">11 10 </head> 12 <body> 13 <h1><em>MatDL:: Plot</em></h1> 14 <div id="main"> 11 <body bgcolor="#e5e8b2" style="font-family: arial,helevetica,verdana, sans-serif"> 12 <center> 13 <table width="101%" border="0" cellpadding="0" cellspacing="0"> 14 <tr> 15 <th width="24%" bordercolor="#BDB583" bgcolor="#BDB583" scope="col"><div align="center"><img src="images/MATDL-LOGO.JPG" width="240" height="85" border="0" usemap="#Map" /></div></th> 16 <th width="49%" height="84" bordercolor="#BDB583" bgcolor="#BDB583" scope="col"><p> 17 <b><em style="font-size: 40px">MatDL: MatML and Material Grapher</em></b> 18 </p> </th> 19 <th width="27%" colspan="2" bordercolor="#BDB583" bgcolor="#BDB583" scope="col"><div align="center"><img src="images/NSF+NSDL-LOGO.JPG" width="256" height="77" border="0" usemap="#Map3Map" /> 20 <map name="Map3Map" id="Map32"> 21 <area shape="rect" coords="-2,24,112,59" href="http://www.nsdl.org" /> 22 <area shape="circle" coords="149,29,20" href="http://www.nsf.gov" /> 23 24 <area shape="rect" coords="177,35,245,66" href="http://www.nist.gov" /> 25 </map> 26 </div></th> 27 </tr> 28 </table> 29 <br> 15 30 <? 16 $plot = $_REQUEST["plot"]; 31 if(isset($_REQUEST["plot"])) 32 { 33 $plot = $_REQUEST["plot"]; 34 } 35 else 36 { 37 $plot = "EvsD"; 38 } 39 if(isset($_REQUEST["selected"])) 40 { 41 $selected = $_REQUEST["selected"]; 42 } 43 else 44 $selected = ""; 45 if(isset($_REQUEST["categorization"])) 46 $categorization=$_REQUEST['categorization']; 47 else 48 $categorization=0; 49 include("clicked.inc"); 50 if(isset($_REQUEST["clicked"])) 51 { 52 list($clickX,$clickY)=explode(",",substr($_REQUEST["clicked"],1)); 53 clicked(); 54 } 55 if($selected) 56 get_selected_data(); 17 57 18 if(!isset($plot)){ 19 $plot = "EvsD"; 20 } 21 22 echo "<img src=\"plot.php?plot=$plot\">" 58 echo "<a href=\"select.php?plot=$plot&selected=".urlencode($selected)."&categorization=$categorization&clicked=\"><img width=600 height=450 src=\"plot.php?plot=$plot&selected=".urlencode($selected)."&categorization=$categorization\" ismap style=\"border-style: none\"></a>" 23 59 ?> 24 60 <div class="content"> 25 61 <br> 26 62 <br> 63 <? 64 if($selected) 65 { 66 echo "<table>\n"; 67 echo "<tr>\n<td colspan=3 align=center><h3>Selected Material Information</h3></td>\n</tr>\n"; 68 echo "<tr><td>Name</td><td width=20></td><td>$selected</td></tr>\n"; 69 echo "<tr><td>$xlabel</td><td></td><td>$selected_xval</td></tr>\n"; 70 echo "<tr><td>$ylabel</td><td></td><td>$selected_yval</td></tr>\n"; 71 echo "</table>\n"; 72 } 73 ?> 74 <BR> 75 <BR> 76 <HR> 77 <BR> 78 <BR> 27 79 <form action="select.php" method="get"> 80 <table> 81 <tr> 82 <th>Plot type</th> 83 </tr> 84 <tr> 85 <td align="left"> 28 86 <? 87 echo "<input type=\"hidden\" name=\"selected\" value=\"$selected\">\n"; 88 29 89 $plotypes = array("EvsD","EvsYield","EovDvsYieldovD","KvsDCp"); 30 90 $plotnames = array( … … 55 115 echo $plotnames[$type]; 56 116 } 57 ?><br> 117 ?> 118 </td></tr></table> 119 <BR><BR> 120 <table> 121 <tr> 122 <th>Categorization</th> 123 </tr> 124 <tr> 125 <td align="left"> 126 <? 127 $categorizations=array("None","Metals, Polymers, and Ceramics"); 128 $left="<input type=\"radio\" name=\"categorization\" value=\""; 129 $right = "\">"; 130 131 132 133 foreach($categorizations as $index=>$name){ 134 135 echo $left; 136 echo $index; 137 138 139 140 if($index == $categorization){ 141 echo "\" checked>"; 142 } 143 else{ 144 echo $right; 145 } 146 147 echo $name."<BR>\n"; 148 } 149 ?> 150 </td></tr></table> 58 151 <br> 59 152 <input type="submit" value="Change Plot"> 60 153 </form> 61 154 </div> 62 63 </div> 155 <HR> 156 <table> 157 <tr><td colspan=2 align=center> 158 <h3>People</h3> 159 </td></tr> 160 <tr> 161 <td>Kyle Stemen</td><td>Kent State University</td> 162 </tr> 163 <tr> 164 <td>Jorge Vieyra</td><td>Massachusetts Institute of Technology</td> </tr> 165 </tr> 166 <tr> 167 <td>Cathy Lowe</td><td>Kent State University</td> </tr> 168 </tr> 169 <tr> 170 <td>Laura Bartolo</td><td>Kent State University</td> </tr> 171 </tr> 172 <tr> 173 <td>Adam Powell</td><td>Massachusetts Institute of Technology</td> </tr> 174 </tr> 175 </table> 176 <P> 177 <BR> 178 <h3>Grants</h3> 179 NSF DUE-0333520<BR> 180 NIST 70NANB30H1 181 </center> 64 182 </body> 65 183 </html> -
trunk/matml/webselector/php/style.css
r48 r121 16 16 color: #000000; 17 17 background: #e5e8b2 url(perico.png) no-repeat 0% 0%; 18 line-height: 150%;18 /*line-height: 150%;*/ 19 19 20 20 } … … 36 36 letter-spacing: 0.5em; 37 37 /*text-transform: lowercase; */ 38 font: bold 30px sans-serif; 39 height: 28px; 38 /*font: bold sans-serif; */ 39 /*font-size: 30px;*/ 40 /*height: 28px; */ 40 41 vertical-align: middle; 41 42 white-space: nowrap;