1var stats = {}; 2 3var ig_unitconversiontable_validator = (function(){ 4return{ 5 update_all_convert_if_unitlb_to_oz : function(){ 6 ig_unitconversiontable = ig_unitconversiontable.map( function(v){ 7 if( v['qty__1'] && ( v['units__1'] === "lb" || v['units__1'] === "lbs" ) ){ 8 v['qty__1'] = v['qty__1'] *16; 9 v['units__1'] = 'oz'; //Set g as well TODO EASY 10 } 11 if( v['units__1'] && v['units__1'] !== 'oz' ){ 12 console.log(`${v['INGREDIENT']} Not lb or oz`); 13 } 14 return v; 15 }); 16 }, 17 update_all_convert_if_unitkg_to_g : function(){ 18 ig_unitconversiontable = ig_unitconversiontable.map( function(v){ 19 if( v['qty'] && v['units'] === "kg" ){ 20 v['qty'] = v['qty'] *1000; 21 v['units'] = 'g'; //Set g as well TODO EASY 22 } 23 if( v['units'] && v['units'] !== 'g' ){ 24 console.log(`${v['INGREDIENT']} Not g or kg`); 25 } 26 return v; 27 }); 28 }, 29 update_all_add_gpercup_from_ozpercup : function(){ 30 ig_unitconversiontable = ig_unitconversiontable.map( function(v){ 31 if( v['(oz/cup)'] && !v['(g/cup)'] ){ 32 var ozpercup = v['(oz/cup)']; 33 var gpercup = new Qty(`${ozpercup} oz`).to('gram').scalar; 34 v['(g/cup)'] = gpercup; 35 } 36 return v; 37 }); 38 39 }, 40 update_all_add_gperml_from_ozpercup : function(){ 41 ig_unitconversiontable = ig_unitconversiontable.map( function(v){ 42 if( v['(g/cup)'] && !v['Conversion (g/mL)'] ){ 43 var gpercup = v['(g/cup)']; 44 var gperml = gpercup / new Qty('1 cup').to('ml').scalar; 45 v['Conversion (g/mL)'] = gperml; 46 } 47 return v; 48 }); 49 50 }, 51 check_all_for_duplicates(){ 52 53 ig_unitconversiontable.reduce( function(ack, v){ 54 55 if( ig_unitconversiontable_validator.find__ingredientname_in__list(v.INGREDIENT, ack) ){ 56 console.log(`Duplicate data: ${v.INGREDIENT}`); 57 } 58 return [... ack, v.INGREDIENT]; 59 60 }, []); 61 }, 62 check_all_for_nan_in_col(colname){ 63 if( ig_unitconversiontable.filter(function(v){ 64 return isNaN(v['qty']); 65 }).length >0 ) 66 { 67 console.log(`Nans found in column ${colname} `); 68 } 69 } 70 , 71 get_all_missing__colval : function( cv){ 72 colvalmisslist = ig_unitconversiontable.filter( function(v){ 73 return (! v[cv]); 74 } ); 75 return colvalmisslist; 76 } 77 , 78 get_all_has__colval : function( cv){ 79 colvalmisslist = ig_unitconversiontable.filter( function(v){ 80 return ( v[cv]); 81 } ); 82 return colvalmisslist; 83 } 84 85 , 86 get_missing__colval_from__list : function( cv, list){ 87 colvalmisslist = list.filter( function(v){ 88 return (! v[cv]); 89 } ); 90 return colvalmisslist; 91 } 92 , 93 get_has__colval_from__list : function( cv, list){ 94 colvalmisslist = list.filter( function(v){ 95 return ( v[cv]); 96 } ); 97 return colvalmisslist; 98 } 99 , 100 101 find__ingredientname_in__list: function (ingredientname, list) { 102 var regextescapedingredientname = ig_unitconversiontable_validator.escapeRegExp(ingredientname); 103 var ingredientregexp = '^'+regextescapedingredientname+'$'; 104 var ingredientfromrecipenameregex = new RegExp(ingredientregexp, "i"); 105 var ingredient_conversiondata = list.find(function (v) { 106 return v.match(ingredientfromrecipenameregex); // ingredientbymatchedname 107 }); 108 return ingredient_conversiondata; 109 } 110 , 111 escapeRegExp: function(string) { 112 return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string 113 } 114 , 115} 116})(); 117// Convert on init 118ig_unitconversiontable_validator.update_all_convert_if_unitlb_to_oz(); 119ig_unitconversiontable_validator.update_all_convert_if_unitkg_to_g(); 120ig_unitconversiontable_validator.update_all_add_gpercup_from_ozpercup(); 121ig_unitconversiontable_validator.update_all_add_gperml_from_ozpercup(); 122ig_unitconversiontable_validator.check_all_for_duplicates(); 123ig_unitconversiontable_validator.check_all_for_nan_in_col('qty'); 124// update all qty_1 with units_1 as lb to oz TODO EASY 125// update all missing qty that has qty_1 to get grams TODO EASY 126 127 128 129//Checking ingredients against spreadsheet 130//echo json_encode( array_values( array_map( function($v){ return $v->name;} , get_terms(['taxonomy' => 'ingredient']) ) ) ); 131// set above as val to a js var rr 132// rr.filter(function(v){ 133// return ! ig_unit.getconversionkit(v) 134// }) //Gets list of names not matched 135 136 137//Draft for checking all recipes added 138// <?php 139// $bb = new WP_Query(['post_type' =>
139 'recipe', 'posts_per_page' => -1]); 140// echo '<pre>'; 141// $postids = array_map( function($v){return $v->ID;}, $bb->posts) ; 142 143// $ingredients = get_post_meta(1850, 'recipe_ingredients',true); 144// var_dump( array_map( function($v){ return $v["ingredient"]; 145// },$ingredients )); 146 147 148//Check missing conversion data, as for classic red chili peppers 149// ig_unitconversiontable.filter(v =>{ 150// return v['Acceptable Units'].match(/cups \(weight\)/i) && ( !v['(g/cup)'] || !v.qty ); 151// } )
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.