/** * Created by PhpStorm. * User: master * Date: 2016/3/7 * Time: 13:31 */ function getLabels() { $sql = "SELECT name FROM manufacturers"; $brands = $GLOBALS['db']->getAllValues($sql); $brands = json_encode($brands); //print_r($brands); $lang = $_SESSION['lang']; if ($lang == "en_us") { $labels = <<<EOF [ {"type":"range","name":"total test result","label":"Total test result", "value":[{">=":0,"<=":1.5},{">":1.5,"<=":2.5},{">":2.5,"<=":3.5},{">":3.5,"<=":4.5},{">":4.5,"<=":5.5}], "option":["very good ","good ","average","sufficient","poor"]}, {"type":"date","name":"Publication date","label":"Tested date", "value":[2016,2015,2014], "option":[2016,2015,2014]}, {"type":"string","name":"Brand","label":"Brands", "value":{$brands}, "option":{$brands}}, {"type":"multi","name":"","label":"Key features", "value":["Backlit screen (y,n)","Touch sensitive screen (y,n)","NFC (y,n)"," * Make/receive phone calls? (y,n)","Integrated heart monitor present? (y,n)","Water resistant (y,n)"], "option":["Backlit screen","Touch screen","NFC","Make/receive calls","Heart rate monitor","Water resistant"]}, {"type":"multi","name":"","label":"Phone compatibility", "value":["Connects to Android phone (y,n)","Connects to iOS phone (y,n)"], "option":["Android","Apple iPhone"]} ] EOF; } else { if ($lang == "zh_cn") { /* $sql="select CHN from sdictionary where oriword in( SELECT distinct value FROM results where id_evaluation=100001759)"; $brandLabels=$GLOBALS['db']->getAllValues($sql); $brandLabels=json_encode($brandLabels);*/ $labels = <<<EOF [ {"type":"range","name":"total test result","label":"总评分", "value":[{">=":0,"<=":1.5},{">":1.5,"<=":2.5},{">":2.5,"<=":3.5},{">":3.5,"<=":4.5},{">":4.5,"<=":5.5}], "option":["优秀","良好","中等","尚可","差劣"]}, {"type":"date","name":"Publication date","label":"测试时间", "value":[2016,2015,2014], "option":[2016,2015,2014]}, {"type":"string","name":"Brand","label":"品牌", "value":{$brands}, "option":{$brands}} ] EOF; } } $arr = json_decode($labels, true); foreach ($arr as $key => $item) { if ($item['type'] == 'string') { $index = 0; foreach ($item['value'] as $value) { if ($item['name'] == 'Brand') { $sql = "select count(*)from products where id_manufacturer=(select id_manufacturer from manufacturers where `name`='" . $value . "')"; } else { $sql = "select count(*) from results where id_evaluation in(select id_evaluation from evaluations where id_evaluation>99999999 and name='" . $item['name'] . "') and value like'%{$value}%'"; } //echo $sql; $v = $GLOBALS['db']->getOne($sql); //echo $value." ".$v." ".$index."+++\n"; if ($v == 0) { array_splice($arr[$key]['option'], $index, 1); array_splice($arr[$key]['value'], $index, 1); $index--; // print_r($arr[$key]['option']); } else { $arr[$key]['number'][] = $v; } $index++; } } else { if ($item['type'] == 'range') { foreach ($item['value'] as $value) { $opts = array_keys($value); $len = count($opts); if ($item['name'] == 'total test result') { //评分数据四舍五入 if ($len == 1 && $opts[0] != -1) { $sql = "select count(*) from results where format(6-value,1)" . $opts[0] . $value[$opts[0]]; } else { if ($len == 2 && $opts[0] != -1) { $sql = "select count(*) from results where format(6-value,1)" . $opts[0] . $value[$opts[0]] . " and format(6-value,1)" . $opts[1] . $value[$opts[1]]; } } } else { //property数值正常读取 if ($len == 1 && $opts[0] != -1) { $sql = "select count(*) from results where value" . $opts[0] . $value[$opts[0]]; } else { if ($len == 2 && $opts[0] != -1) { $sql = "select count(*) from results where value" . $opts[0] . $value[$opts[0]] . " and value" . $opts[1] . $value[$opts[1]]; } } } $sql .= " and id_evaluation=(select id_evaluation from evaluations where "; if ($item['name'] == 'total test result') { $sql .= "name='" . $item['name'] . "')"; } else { $sql .= "id_evaluation>99999999 and name='" . $item['name'] . "')"; } $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } else { if ($item['type'] == 'date') { foreach ($item['value'] as $value) { $sql = "select count(*) from products where FROM_UNIXTIME(timestamp_created, '%Y' )='" . $value . "'"; //echo $sql; $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } else { if ($item['type'] == 'multi') { foreach ($item['value'] as $value) { $sql = "select count(*) from results where value=1" . " and id_evaluation=(select id_evaluation from evaluations where id_evaluation>99999999 and name='" . $value . "')"; //echo $sql; $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } } } } } sortByNumber($arr[2]); //print_r($arr); return json_encode($arr); }
/** * Created by PhpStorm. * User: master * Date: 2016/3/7 * Time: 13:31 */ function getLabels() { $sql = "SELECT name FROM manufacturers"; $brands = $GLOBALS['db']->getAllValues($sql); $brands = json_encode($brands); $lang = $_SESSION['lang']; if ($lang == "en_us") { $labels = <<<EOF [ {"type":"range","name":"total test result","label":"Total test result", "value":[{">=":0,"<=":1.5},{">":1.5,"<=":2.5},{">":2.5,"<=":3.5},{">":3.5,"<=":4.5},{">":4.5,"<=":5.5}], "option":["very good ","good ","average","adequate","poor"]}, {"type":"date","name":"Publication date","label":"Tested date", "value":[2016], "option":[2016]}, {"type":"string","name":"Brand","label":"Brands", "value":{$brands}, "option":{$brands}}, {"type":"string","name":"Months of infant age","label":"Months of infant age", "value":["> 12"], "option":["above 12"]}, {"type":"string","name":"Country of production (stated)","label":"Country of production", "value":["China","Germany","Netherlands","Ireland","Switzerland"], "option":["China","Germany","Netherlands","Ireland","Switzerland"]}, \t\t {"type":"string","name":"Geographical origin of milk (stated)","label":"Geographical origin of milk (stated)", "value":["China","Germany","Irland","Netherlands","Switzerland","Imported"], "option":["China","Germany","Irland","Netherlands","Switzerland","Imported"]}, \t\t {"type":"range","name":"DHA measurement","label":"Docosahexaenoic acid (DHA)", "value":[{"=":"< LOQ"},{">":1,"<":2.4},{">=":2.4,"<=":4.8}], "option":["< LOQ","< 2.4 mg/100kJ","2.4 ~ 4.8 mg/100kJ"]}, \t\t {"type":"range","name":"Aerobic bacterial count measurement","label":"Aerobic bacterial count", "value":[{"=":"<10"},{">=":"10","<=":50},{">=":51,"<=":100},{">=":101,"<=":200},{">=":201,"<=":300},{">=":301,"<=":500}], "option":["< 10","10 ~ 50","51 ~ 100","101 ~ 200","201 ~ 300","301 ~ 500"]}, \t\t {"type":"range","name":"Sum of Dioxins and dioxin-like PCB","label":"Dioxins and dioxin-like PCB in pg WHO-TEQ/g prepared milk", "value":[{"<":0.007},{">=":0.007,"<=":0.010},{">=":0.011,"<=":0.020},{">=":0.021,"<=":0.030}], "option":["< 0.007","0.007 ~ 0.010","0.011 ~ 0.020","0.021 ~ 0.030"]} ] EOF; } else { if ($lang == "zh_cn") { $sql = "select CHN from sdictionary where oriword in( SELECT distinct value FROM mobilephones.results where id_evaluation=100001759)"; $brandLabels = $GLOBALS['db']->getAllValues($sql); $brandLabels = json_encode($brandLabels); $labels = <<<EOF [ {"type":"range","name":"total test result","label":"总评分", "value":[{">=":0,"<=":1.5},{">":1.5,"<=":2.5},{">":2.5,"<=":3.5},{">":3.5,"<=":4.5},{">":4.5,"<=":5.5}], "option":["优秀","良好","中等","尚可","差劣"]}, {"type":"date","name":"Publication date","label":"测试时间", "value":[2016], "option":[2016]}, {"type":"string","name":"Brand","label":"品牌", "value":{$brands}, "option":{$brandLabels}} ] EOF; } } $arr = json_decode($labels, true); foreach ($arr as $key => $item) { if ($item['type'] == 'string') { foreach ($item['value'] as $value) { $sql = "select count(*) from results where value='" . $value . "'" . "and id_evaluation=(select id_evaluation from evaluations where id_evaluation>99999999 and name='" . $item['name'] . "')"; //echo $sql; $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } else { if ($item['type'] == 'range') { foreach ($item['value'] as $value) { $opts = array_keys($value); $len = count($opts); if ($item['name'] == 'total test result') { //评分数据四舍五入 if ($len == 1 && $opts[0] != -1) { $sql = "select count(*) from results where format(6-value,1)" . $opts[0] . $value[$opts[0]]; } else { if ($len == 2 && $opts[0] != -1) { $sql = "select count(*) from results where format(6-value,1)" . $opts[0] . $value[$opts[0]] . " and format(6-value,1)" . $opts[1] . $value[$opts[1]]; } } } else { //property数值正常读取 if ($len == 1 && $opts[0] != -1) { if (is_numeric($value[$opts[0]])) { $sql = "select count(*) from results where value" . $opts[0] . $value[$opts[0]]; } else { $sql = "select count(*) from results where value" . $opts[0] . "'" . $value[$opts[0]] . "'"; } } else { if ($len == 2 && $opts[0] != -1) { $sql = "select count(*) from results where value" . $opts[0] . $value[$opts[0]] . " and value" . $opts[1] . $value[$opts[1]]; } } } $sql .= " and id_evaluation=(select id_evaluation from evaluations where "; if ($item['name'] == 'total test result') { $sql .= "name='" . $item['name'] . "')"; } else { $sql .= "id_evaluation>99999999 and name='" . $item['name'] . "')"; } //echo $sql."\n"; $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } else { if ($item['type'] == 'date') { foreach ($item['value'] as $value) { $sql = "select count(*) from products where FROM_UNIXTIME(timestamp_created, '%Y' )='" . $value . "'"; //echo $sql; $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } else { if ($item['type'] == 'multi') { foreach ($item['value'] as $value) { $sql = "select count(*) from results where value=1" . " and id_evaluation=(select id_evaluation from evaluations where id_evaluation>99999999 and name='" . $value . "')"; //echo $sql; $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } } } } } sortByNumber($arr[2]); return json_encode($arr); }
/** * Created by PhpStorm. * User: master * Date: 2016/3/7 * Time: 13:31 */ function getLabels() { $sql = "SELECT name FROM manufacturers"; $brands = $GLOBALS['db']->getAllValues($sql); $brands = json_encode($brands); //print_r($brands); $lang = $_SESSION['lang']; if ($lang == "en_us") { $labels = <<<EOF [ {"type":"range","name":"total test result","label":"Total test result", "value":[{">=":0,"<=":1.5},{">":1.5,"<=":2.5},{">":2.5,"<=":3.5},{">":3.5,"<=":4.5},{">":4.5,"<=":5.5}], "option":["very good ","good ","average","sufficient","poor"]}, {"type":"date","name":"Publication date","label":"Tested date", "value":[2016,2015,2014], "option":[2016,2015,2014]}, {"type":"string","name":"Brand","label":"Brands", "value":{$brands}, "option":{$brands}}, {"type":"range","name":"Zoom range, stated","label":"Zoom range, stated", "value":[{">=":1,"<":3},{">=":3,"<":5},{">=":5,"<":7},{">=":7,"<":9},{">=":9,"<":11},{">=":11,"<=":15},{">":15}], "option":["1 - 3 ","3 - 5","5 - 7","7 - 9","9 - 11","11 - 15","> 15"]}, {"type":"range","name":"Effective sensor diagonal","label":"Image sensor diagonal", "value":[{"<":7},{">=":7,"<=":12},{">":12,"<=":14},{">":14,"<=":18},{">":18,"<=":25},{">":25,"<=":40},{">":40,"<=":45}], "option":["< 7 mm","7-12 mm","12-14 mm","14-18 mm","18-25 mm","25-40 mm","40-45 mm"]}, {"type":"range","name":"Weight, complete system camera","label":"Weight, complete", "value":[{"<":150},{">=":150,"<=":190},{">":190,"<=":250},{">":250,"<=":550},{">":550,"<=":1000},{">":1000}], "option":["< 150 g","150 - 190 g","190 - 250 g","250 - 550 g","550 - 1000 g","> 1000 g"]}, {"type":"range","name":"normalised focal length wide","label":"Normalised focal length wide (the smaller the better)", "value":[{"<":0.58},{">=":0.58,"<":0.61},{">=":0.61,"<=":0.65},{">":0.65,"<=":0.75},{">":0.75,"<=":1.00},{">":1.00}], "option":["< 0.58","0.58 - 0.61","0.61 - 0.65","0.65 - 0.75","0.75 - 1.00","> 1.00"]}, {"type":"range","name":"normalised focal length tele","label":"Normalised focal length tele (the bigger the better)", "value":[{">":5.5},{">":2.6,"<=":5.5},{">":2.2,"<=":2.6},{">":1.9,"<=":2.2},{">":0.5,"<=":1.9}], "option":["> 5.5","2.6 - 5.5","2.2 - 2.6","1.9 - 2.2","0.5 - 1.9"]}, {"type":"range","name":"shutter delay 8,5m","label":"Shutter delay 8.5m", "value":[{"<":0.25},{">=":0.25,"<=":0.36},{">":0.36,"<=":0.49},{">":0.49,"<=":0.70},{">":0.70}], "option":["< 0.25 s","0.25 - 0.36 s","0.36 -0.49 s","0.49 - 0.70 s","> 0.70 s"]}, {"type":"range","name":"continuous shooting mode","label":"Continuous pictures/s", "value":[{">":8.7},{">":6.8,"<=":8.7},{">":4.9,"<=":6.8},{">":2.1,"<=":4.9},{">=":0.3,"<=":2.1}], "option":["> 8.7","6.8 - 8.7","4.9 - 6.8","2.1 - 4.9","0.3 -2.1"]}, {"type":"range","name":"Wide setting, minimum F-number, stated","label":"Minimum F-number wide", "value":[{"<":2.8},{">=":2.8,"<=":3.2},{">":3.2,"<=":3.5},{">":3.5,"<=":5.6}], "option":["< 2.8","2.8 - 3.2","3.2 - 3.5","3.5 - 5.6"]}, {"type":"range","name":"Tele setting, minimum F-number, stated","label":"Minimum F-number tele", "value":[{"<":4.7},{">=":4.7,"<=":5.2},{">":5.2,"<=":5.6},{">":5.6,"<=":5.9},{">":5.9,"<=":8.5}], "option":["< 4.7","4.7 - 5.2","5.2 -5.6","5.6 - 5.9","5.9 - 8.5"]}, {"type":"multi","name":"","label":"Key features", "value":["Viewfinder existing (either built in, delivered or optional)","Touchscreen","Manual focus (continuosly, more than 5 settings)","Wi-Fi (WLAN) connection","GPS tagging in camera","HDR function (high dynamic range with several shots)","Panorama record function (panning)"], "option":["Viewfinder","Touchscreen","Manual focus","WLAN","GPS","HDR","Panorama record"]}, {"type":"multi","name":"","label":"Robustness", "value":["Water / dust resistance (rain, humidity, dust, snow)","Water proof (for diving)","Shock proof"], "option":["Water / dust resistance","Waterproof for diving","Shock proof"]} ] EOF; } else { if ($lang == "zh_cn") { /* $sql="select CHN from sdictionary where oriword in( SELECT distinct value FROM results where id_evaluation=100001759)"; $brandLabels=$GLOBALS['db']->getAllValues($sql); $brandLabels=json_encode($brandLabels);*/ $labels = <<<EOF [ {"type":"range","name":"total test result","label":"总评分", "value":[{">=":0,"<=":1.5},{">":1.5,"<=":2.5},{">":2.5,"<=":3.5},{">":3.5,"<=":4.5},{">":4.5,"<=":5.5}], "option":["优秀","良好","中等","尚可","差劣"]}, {"type":"date","name":"Publication date","label":"测试时间", "value":[2016,2015,2014], "option":[2016,2015,2014]}, {"type":"string","name":"Brand","label":"品牌", "value":{$brands}, "option":{$brands}}, {"type":"range","name":"Zoom range, stated","label":"Zoom range, stated", "value":[{">=":1,"<=":2},{">=":3,"<=":4},{">=":5,"<=":6},{">=":7,"<=":8},{">=":9,"<=":10},{">=":11,"<=":15},{">":15}], "option":["1 - 2 ","3 - 4","5 - 6","7 - 8","9 - 10","11 - 15","> 15"]}, {"type":"range","name":"Effective sensor diagonal","label":"Image sensor diagonal", "value":[{"<":7},{">=":7,"<=":12},{">":12,"<=":14},{">":14,"<=":17},{">=":18,"<=":22},{">=":25,"<=":30},{">=":40,"<=":45}], "option":["< 7 mm","7-12 mm","12-14 mm","14-17 mm","18-22 mm","25-30 mm","40-45 mm"]}, {"type":"range","name":"Weight, complete system camera","label":"Weight, complete", "value":[{"<":150},{">=":150,"<=":190},{">":190,"<=":250},{">":250,"<=":550},{">":550,"<=":1000},{">":1000}], "option":["< 150 g","150 - 190 g","190 - 250 g","250 - 550 g","550 - 1000 g","> 1000 g"]}, {"type":"range","name":"normalised focal length wide","label":"Normalised focal length wide(the smaller the better)", "value":[{"<":0.58},{">=":0.58,"<":0.61},{">=":0.61,"<=":0.65},{">":0.65,"<=":0.75},{">":0.75,"<=":1.00},{">":1.00}], "option":["< 0.58","0.58 - 0.61","0.61 - 0.65","0.65 - 0.75","0.75 - 1.00","> 1.00"]}, {"type":"range","name":"normalised focal length tele","label":"Normalised focal length tele (the bigger the better)", "value":[{">":5.5},{">":2.6,"<=":5.5},{">":2.2,"<=":2.6},{">":1.9,"<=":2.2},{">":0.5,"<=":1.9}], "option":["> 5.5","2.6 - 5.5","2.2 - 2.6","1.9 - 2.2","0.5 - 1.9"]}, {"type":"range","name":"shutter delay 8,5m","label":"Shutter delay 8,5m", "value":[{"<":0.25},{">=":0.25,"<=":0.36},{">":0.36,"<=":0.49},{">":0.49,"<=":0.70},{">":0.70}], "option":["< 0.25 s","0.25 - 0.36 s","0.36 -0.49 s","0.49 - 0.70 s","> 0.70 s"]}, {"type":"range","name":"continuous shooting mode - pictures in row","label":"Continuous pictures/s", "value":[{">":8.7},{">":6.8,"<=":8.7},{">":4.9,"<=":6.8},{">":2.1,"<=":4.9},{">":0.3,"<=":2.1}], "option":["> 8.7","6.8 - 8.7","4.9 - 6.8","2.1 - 4.9","0.3 -2.1"]} ] EOF; } } $arr = json_decode($labels, true); foreach ($arr as $key => $item) { if ($item['type'] == 'string') { $index = 0; foreach ($item['value'] as $value) { if ($item['name'] == 'Brand') { $sql = "select count(*)from products where id_manufacturer=(select id_manufacturer from manufacturers where `name`='" . $value . "')"; } //echo $sql; $v = $GLOBALS['db']->getOne($sql); //echo $value." ".$v." ".$index."+++\n"; if ($v == 0) { array_splice($arr[$key]['option'], $index, 1); array_splice($arr[$key]['value'], $index, 1); $index--; // print_r($arr[$key]['option']); } else { $arr[$key]['number'][] = $v; } $index++; } } else { if ($item['type'] == 'range') { foreach ($item['value'] as $value) { $opts = array_keys($value); $len = count($opts); if ($item['name'] == 'total test result') { //评分数据四舍五入 if ($len == 1 && $opts[0] != -1) { $sql = "select count(*) from results where format(6-value,1)" . $opts[0] . $value[$opts[0]]; } else { if ($len == 2 && $opts[0] != -1) { $sql = "select count(*) from results where format(6-value,1)" . $opts[0] . $value[$opts[0]] . " and format(6-value,1)" . $opts[1] . $value[$opts[1]]; } } } else { //property数值正常读取 if ($len == 1 && $opts[0] != -1) { $sql = "select count(*) from results where value" . $opts[0] . $value[$opts[0]]; } else { if ($len == 2 && $opts[0] != -1) { $sql = "select count(*) from results where value" . $opts[0] . $value[$opts[0]] . " and value" . $opts[1] . $value[$opts[1]]; } } } $sql .= " and id_evaluation=(select id_evaluation from evaluations where "; if ($item['name'] == 'total test result') { $sql .= "name='" . $item['name'] . "')"; } else { $sql .= "id_evaluation>99999999 and name='" . $item['name'] . "')"; } $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } else { if ($item['type'] == 'date') { foreach ($item['value'] as $value) { $sql = "select count(*) from products where FROM_UNIXTIME(timestamp_created, '%Y' )='" . $value . "'"; //echo $sql; $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } else { if ($item['type'] == 'multi') { foreach ($item['value'] as $value) { $sql = "select count(*) from results where value=1" . " and id_evaluation=(select id_evaluation from evaluations where id_evaluation>99999999 and name='" . $value . "')"; //echo $sql; $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } } } } } sortByNumber($arr[2]); //print_r($arr); return json_encode($arr); }
/** * Created by PhpStorm. * User: master * Date: 2016/3/7 * Time: 13:31 */ function getLabels() { $sql = "SELECT name FROM tablets.manufacturers"; $brands = $GLOBALS['db']->getAllValues($sql); $brands = json_encode($brands); //print_r($brands); $lang = $_SESSION['lang']; if ($lang == "en_us") { $labels = <<<EOF [ {"type":"range","name":"total test result","label":"Total test result", "value":[{">=":0,"<=":1.5},{">":1.5,"<=":2.5},{">":2.5,"<=":3.5},{">":3.5,"<=":4.5},{">":4.5,"<=":5.5}], "option":["very good ","good ","average","sufficient","poor"]}, {"type":"date","name":"Publication date","label":"Tested date", "value":[2016,2015,2014], "option":[2016,2015,2014]}, {"type":"string","name":"Brand","label":"Brands", "value":{$brands}, "option":{$brands}}, {"type":"range","name":"Screen image diagonal","label":"Screen image diagonal", "value":[{"<":8},{">=":8,"<=":10},{">":10}], <<<<<<< HEAD "option":["< 8\\"","8 - 10\\"","> 10\\""]}, ======= "option":["> 8\\"","8 - 10\\"","> 10\\""]}, >>>>>>> 7f3fb6250d696d7e9e5bba2a85f6050a0c02fc75 {"type":"range","name":"Native resolution (height)","label":"Native resolution (height)", "value":[{"<":800},{">=":800,"<=":1200},{">":1200,"<=":1500},{">":1500,"<=":2736}], "option":["< 800 Pixel","800 - 1200 Pixel","1200 - 1500 Pixel","1500 -2736 Pixel"]}, {"type":"range","name":"Native resolution (width)","label":"Native resolution (width)", "value":[{"<":1300},{">=":1300,"<=":1900},{">":1900,"<=":2000},{">":2000,"<=":2736}], "option":["< 1300 Pixel","1300 - 1900 Pixel","1900 - 2000 Pixel","2000 - 2736 Pixel"]}, {"type":"string","name":"OS installed","label":"OS installed", "value":["Android","iOS","Windows"], "option":["Android","iOS","Windows"]}, {"type":"string","name":"Claimed size of internal storage [Gb]","label":"Claimed size of internal storage", "value":[4,8,16,32,64,128,256], "option":["4GB","8GB","16GB","32GB","64GB","128GB","256GB"]}, {"type":"multi","name":"","label":"Connection", "value":["3G","LTE","Bluetooth","GPS","NFC","Phone functionality"], "option":["3G","LTE","Bluetooth","GPS","NFC","Phone functionality"]}, {"type":"multi","name":"","label":"WLAN", "value":["Wi-Fi G","Wi-Fi N","Wi-Fi 5GHzN","Wi-Fi AC"], "option":["Wi-Fi G","Wi-Fi N","Wi-Fi 5GHzN","Wi-Fi AC"]}, {"type":"multi","name":"","label":"USB", "value":["USB 4.0 [y/n]","USB 3.0 [y/n]","USB 2.0 [y/n]","Mini-USB [y/n]" ,"Micro-USB [y/n]", "HDMI"], "option":["USB 4.0","USB 3.0","USB 2.0","Mini-USB" ,"Micro-USB", "HDMI"]}, {"type":"multi","name":"","label":"SD", "value":["full SD size","mini-SD","micro-SD"], "option":["full SD size","mini-SD","micro-SD"]}, {"type":"multi","name":"","label":"Accessories", "value":["Physical keyboard provided","Stylus supplied"], "option":["Physical keyboard provided","Stylus supplied"]}, {"type":"multi","name":"","label":"Robustness", "value":["Manufacturer claims waterproof?","Manufacturer claims water resistant?"], "option":["Waterproof, stated","Water resistant, stated"]} ] EOF; } else { if ($lang == "zh_cn") { $sql = "select CHN from sdictionary where oriword in( SELECT distinct value FROM mobilephones.results where id_evaluation=100001759)"; $brandLabels = $GLOBALS['db']->getAllValues($sql); $brandLabels = json_encode($brandLabels); $labels = <<<EOF [ {"type":"range","name":"total test result","label":"总评分", "value":[{">=":0,"<=":1.5},{">":1.5,"<=":2.5},{">":2.5,"<=":3.5},{">":3.5,"<=":4.5},{">":4.5,"<=":5.5}], "option":["优秀","良好","中等","尚可","差劣"]}, {"type":"date","name":"Publication date","label":"测试时间", "value":[2016,2015,2014], "option":[2016,2015,2014]}, {"type":"string","name":"Brand","label":"品牌", "value":{$brands}, "option":{$brandLabels}} ] EOF; } } $arr = json_decode($labels, true); foreach ($arr as $key => $item) { if ($item['type'] == 'string') { $index = 0; foreach ($item['value'] as $value) { if ($item['name'] == 'Brand') { $sql = "select count(*)from products where id_manufacturer=(select id_manufacturer from manufacturers where `name`='" . $value . "')"; } else { $sql = "select count(*) from results where id_evaluation in(select id_evaluation from evaluations where name='" . $item['name'] . "') and value like'%{$value}%'"; } //echo $sql; $v = $GLOBALS['db']->getOne($sql); //echo $value." ".$v." ".$index."+++\n"; if ($v == 0) { array_splice($arr[$key]['option'], $index, 1); array_splice($arr[$key]['value'], $index, 1); $index--; // print_r($arr[$key]['option']); } else { $arr[$key]['number'][] = $v; } $index++; } } else { if ($item['type'] == 'range') { foreach ($item['value'] as $value) { $opts = array_keys($value); $len = count($opts); if ($item['name'] == 'total test result') { //评分数据四舍五入 if ($len == 1 && $opts[0] != -1) { $sql = "select count(*) from results where format(6-value,1)" . $opts[0] . $value[$opts[0]]; } else { if ($len == 2 && $opts[0] != -1) { $sql = "select count(*) from results where format(6-value,1)" . $opts[0] . $value[$opts[0]] . " and format(6-value,1)" . $opts[1] . $value[$opts[1]]; } } } else { //property数值正常读取 if ($len == 1 && $opts[0] != -1) { $sql = "select count(*) from results where value" . $opts[0] . $value[$opts[0]]; } else { if ($len == 2 && $opts[0] != -1) { $sql = "select count(*) from results where value" . $opts[0] . $value[$opts[0]] . " and value" . $opts[1] . $value[$opts[1]]; } } } $sql .= " and id_evaluation=(select id_evaluation from evaluations where "; if ($item['name'] == 'total test result') { $sql .= "name='" . $item['name'] . "')"; } else { $sql .= "id_evaluation>99999999 and name='" . $item['name'] . "')"; } $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } else { if ($item['type'] == 'date') { foreach ($item['value'] as $value) { $sql = "select count(*) from products where FROM_UNIXTIME(timestamp_created, '%Y' )='" . $value . "'"; //echo $sql; $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } else { if ($item['type'] == 'multi') { foreach ($item['value'] as $value) { $sql = "select count(*) from results where value=1" . " and id_evaluation=(select id_evaluation from evaluations where id_evaluation>99999999 and name='" . $value . "')"; //echo $sql; $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } } } } } sortByNumber($arr[2]); //print_r($arr); return json_encode($arr); }
/** * Created by PhpStorm. * User: master * Date: 2016/3/7 * Time: 13:31 */ function getLabels() { $sql = "SELECT name FROM manufacturers"; $brands = $GLOBALS['db']->getAllValues($sql); $brands = json_encode($brands); //print_r($brands); $lang = $_SESSION['lang']; if ($lang == "en_us") { $labels = <<<EOF [ {"type":"range","name":"total test result","label":"Total test result", "value":[{">=":0,"<=":1.5},{">":1.5,"<=":2.5},{">":2.5,"<=":3.5},{">":3.5,"<=":4.5},{">":4.5,"<=":5.5}], "option":["very good ","good ","average","sufficient","poor"]}, {"type":"date","name":"Publication date","label":"Tested date", "value":[2016,2015], "option":[2016,2015]}, {"type":"string","name":"Brand","label":"Brands", "value":{$brands}, "option":{$brands}}, {"type":"string","name":"Headphone type e.g. in ear etc","label":"Headphone type", "value":["In","Around","Over","On"], "option":["In ear","Around ear","Over ear","On ear"]}, \t\t {"type":"multi","name":"","label":"Key features", "value":["Wireless headphones","Phone call controls and mic built into cable (answer button etc)","Do headphones fold","Travel case","External noise cancelling present"], "option":["Wireless connectivity","Mic for phonecall","Folding headphones","Travel case","Noise canceling"]} ] EOF; } else { if ($lang == "zh_cn") { /* $sql="select CHN from sdictionary where oriword in( SELECT distinct value FROM results where id_evaluation=100001759)"; $brandLabels=$GLOBALS['db']->getAllValues($sql); $brandLabels=json_encode($brandLabels);*/ $labels = <<<EOF [ {"type":"range","name":"total test result","label":"总评分", "value":[{">=":0,"<=":1.5},{">":1.5,"<=":2.5},{">":2.5,"<=":3.5},{">":3.5,"<=":4.5},{">":4.5,"<=":5.5}], "option":["优秀","良好","中等","尚可","差劣"]}, {"type":"date","name":"Publication date","label":"测试时间", "value":[2016,2015], "option":[2016,2015]}, {"type":"string","name":"Brand","label":"品牌", "value":{$brands}, "option":{$brands}} ] EOF; } } $arr = json_decode($labels, true); foreach ($arr as $key => $item) { if ($item['type'] == 'string') { $index = 0; foreach ($item['value'] as $value) { if ($item['name'] == 'Brand') { $sql = "select count(*)from products where id_manufacturer=(select id_manufacturer from manufacturers where `name`='" . $value . "')"; } else { $sql = "select count(*) from results where id_evaluation in(select id_evaluation from evaluations where id_evaluation>99999999 and name='" . $item['name'] . "') and value like'%{$value}%'"; } //echo $sql; $v = $GLOBALS['db']->getOne($sql); //echo $value." ".$v." ".$index."+++\n"; if ($v == 0) { array_splice($arr[$key]['option'], $index, 1); array_splice($arr[$key]['value'], $index, 1); $index--; // print_r($arr[$key]['option']); } else { $arr[$key]['number'][] = $v; } $index++; } } else { if ($item['type'] == 'range') { foreach ($item['value'] as $value) { $opts = array_keys($value); $len = count($opts); if ($item['name'] == 'total test result') { //评分数据四舍五入 if ($len == 1 && $opts[0] != -1) { $sql = "select count(*) from results where format(6-value,1)" . $opts[0] . $value[$opts[0]]; } else { if ($len == 2 && $opts[0] != -1) { $sql = "select count(*) from results where format(6-value,1)" . $opts[0] . $value[$opts[0]] . " and format(6-value,1)" . $opts[1] . $value[$opts[1]]; } } } else { //property数值正常读取 if ($len == 1 && $opts[0] != -1) { $sql = "select count(*) from results where value" . $opts[0] . $value[$opts[0]]; } else { if ($len == 2 && $opts[0] != -1) { $sql = "select count(*) from results where value" . $opts[0] . $value[$opts[0]] . " and value" . $opts[1] . $value[$opts[1]]; } } } $sql .= " and id_evaluation=(select id_evaluation from evaluations where "; if ($item['name'] == 'total test result') { $sql .= "name='" . $item['name'] . "')"; } else { $sql .= "id_evaluation>99999999 and name='" . $item['name'] . "')"; } $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } else { if ($item['type'] == 'date') { foreach ($item['value'] as $value) { $sql = "select count(*) from products where FROM_UNIXTIME(timestamp_created, '%Y' )='" . $value . "'"; //echo $sql; $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } else { if ($item['type'] == 'multi') { foreach ($item['value'] as $value) { $sql = "select count(*) from results where value=1" . " and id_evaluation=(select id_evaluation from evaluations where id_evaluation>99999999 and name='" . $value . "')"; //echo $sql; $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } } } } } sortByNumber($arr[2]); //print_r($arr); return json_encode($arr); }
/** * Created by PhpStorm. * User: master * Date: 2016/3/7 * Time: 13:31 */ function getLabels() { $sql = "SELECT name FROM manufacturers"; $brands = $GLOBALS['db']->getAllValues($sql); $brands = json_encode($brands); //print_r($brands); $lang = $_SESSION['lang']; if ($lang == "en_us") { $labels = <<<EOF [ {"type":"range","name":"total test result","label":"Total test result", "value":[{">=":0,"<=":1.5},{">":1.5,"<=":2.5},{">":2.5,"<=":3.5},{">":3.5,"<=":4.5},{">":4.5,"<=":5.5}], "option":["very good ","good ","average","sufficient","poor"]}, {"type":"date","name":"Publication date","label":"Tested date", "value":[2016,2015,2014], "option":[2016,2015,2014]}, {"type":"string","name":"Brand","label":"Brands", "value":{$brands}, "option":{$brands}}, {"type":"string","name":"Primary location to wear band (wrist, belt etc.)","label":"Type of tracker", "value":["Wrist","Waist","Wrist or waist","Wrist, waist, foot or around neck","Wrist, waist, foot or around neck _can also be clipped anywhere on the body","Belt. Instructions suggest the device can also be clipped on upper body clothing or bra."], "option":["Wrist","Waist","Wrist or waist","Wrist, waist, foot or around neck","Wrist, waist, foot, neck or anywhere","Belt (also on upper body clothing or bra)"]}, {"type":"multi","name":"","label":"Fitness", "value":["Integrated heart monitor present? (y,n)","Sleep tracking? (y,n)","Integrated altimeter? (y,n)"], "option":["Heart rate monitor","Sleep tracking","Altimeter"]}, {"type":"multi","name":"","label":"Phone compatibility", "value":["iOS supported? (y,n)","Android supported? (y,n)","Windows phone supported? (y,n)"], "option":["iOS","Android","Windows phone"]}, {"type":"multi","name":"","label":"Smart", "value":["Can the information displayed be customised? (y,n)","Any smart watch functionality present? (y,n)"," * Text message notification? (y,n)"," * Make/receive phone calls? (y,n)"], "option":["Personalisation","Smart watch","Messaging","Calling"]}, {"type":"multi","name":"","label":"Connection", "value":["GPS enabled? (y,n)","Wi-Fi enabled? (y,n)","Bluetooth enabled? (y,n)","USB connection available? (y,n)"], "option":["GPS","Wi-Fi","Bluetooth","USB"]}, {"type":"multi","name":"","label":"Features", "value":["Water resistant? (y,n)","Is the display touch sensitive? (y,n)"], "option":["Water resistant","Touch screen"]} ] EOF; } else { if ($lang == "zh_cn") { /* $sql="select CHN from sdictionary where oriword in( SELECT distinct value FROM results where id_evaluation=100001759)"; $brandLabels=$GLOBALS['db']->getAllValues($sql); $brandLabels=json_encode($brandLabels);*/ $labels = <<<EOF [ {"type":"range","name":"total test result","label":"总评分", "value":[{">=":0,"<=":1.5},{">":1.5,"<=":2.5},{">":2.5,"<=":3.5},{">":3.5,"<=":4.5},{">":4.5,"<=":5.5}], "option":["优秀","良好","中等","尚可","差劣"]}, {"type":"date","name":"Publication date","label":"测试时间", "value":[2015,2014], "option":[2015,2014]}, {"type":"string","name":"Brand","label":"品牌", "value":{$brands}, "option":{$brands}} ] EOF; } } $arr = json_decode($labels, true); foreach ($arr as $key => $item) { if ($item['type'] == 'string') { $index = 0; foreach ($item['value'] as $value) { if ($item['name'] == 'Brand') { $sql = "select count(*)from products where id_manufacturer=(select id_manufacturer from manufacturers where `name`='" . $value . "')"; } else { $sql = "select count(*) from results where id_evaluation in(select id_evaluation from evaluations where id_evaluation>99999999 and name='" . $item['name'] . "') and value ='{$value}'"; } //echo $sql; $v = $GLOBALS['db']->getOne($sql); //echo $value." ".$v." ".$index."+++\n"; if ($v == 0) { array_splice($arr[$key]['option'], $index, 1); array_splice($arr[$key]['value'], $index, 1); $index--; // print_r($arr[$key]['option']); } else { $arr[$key]['number'][] = $v; } $index++; } } else { if ($item['type'] == 'range') { foreach ($item['value'] as $value) { $opts = array_keys($value); $len = count($opts); if ($item['name'] == 'total test result') { //评分数据四舍五入 if ($len == 1 && $opts[0] != -1) { $sql = "select count(*) from results where format(6-value,1)" . $opts[0] . $value[$opts[0]]; } else { if ($len == 2 && $opts[0] != -1) { $sql = "select count(*) from results where format(6-value,1)" . $opts[0] . $value[$opts[0]] . " and format(6-value,1)" . $opts[1] . $value[$opts[1]]; } } } else { //property数值正常读取 if ($len == 1 && $opts[0] != -1) { $sql = "select count(*) from results where value" . $opts[0] . $value[$opts[0]]; } else { if ($len == 2 && $opts[0] != -1) { $sql = "select count(*) from results where value" . $opts[0] . $value[$opts[0]] . " and value" . $opts[1] . $value[$opts[1]]; } } } $sql .= " and id_evaluation=(select id_evaluation from evaluations where "; if ($item['name'] == 'total test result') { $sql .= "name='" . $item['name'] . "')"; } else { $sql .= "id_evaluation>99999999 and name='" . $item['name'] . "')"; } $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } else { if ($item['type'] == 'date') { foreach ($item['value'] as $value) { $sql = "select count(*) from products where FROM_UNIXTIME(timestamp_created, '%Y' )='" . $value . "'"; //echo $sql; $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } else { if ($item['type'] == 'multi') { foreach ($item['value'] as $value) { $sql = "select count(*) from results where value=1" . " and id_evaluation=(select id_evaluation from evaluations where id_evaluation>99999999 and name='" . $value . "')"; //echo $sql; $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } } } } } sortByNumber($arr[2]); //print_r($arr); return json_encode($arr); }
/** * Created by PhpStorm. * User: master * Date: 2016/3/7 * Time: 13:31 */ function getLabels() { $sql = "SELECT name FROM milk.manufacturers"; $brands = $GLOBALS['db']->getAllValues($sql); $brands = json_encode($brands); $lang = $_SESSION['lang']; if ($lang == "en_us") { $labels = <<<EOF [ {"type":"range","name":"total test result","label":"Total test result", "value":[{">=":0,"<=":1.5},{">":1.5,"<=":2.5},{">":2.5,"<=":3.5},{">":3.5,"<=":4.5},{">":4.5,"<=":5.5}], "option":["very good ","good ","average","adequate","poor"]}, {"type":"date","name":"Publication date","label":"Tested date", "value":[2016], "option":[2016]}, {"type":"string","name":"Brand","label":"Brands", "value":{$brands}, "option":{$brands}}, \t\t {"type":"string","name":"Country of production (stated)","label":"Country of production", "value":["China","Germany"], "option":["China","Germany"]}, {"type":"string","name":"Manufacturing process (stated)","label":"Manufacturing process", "value":["UHT"], "option":["UHT"]}, {"type":"string","name":"Fat content","label":"Fat content", "value":["Whole milk"], "option":["Whole milk"]}, {"type":"range","name":"Shelf life (stated)","label":"Shelf life(Days)", "value":[{">=":180,"<=":215},{">":215,"<=":360},{">":360,"<=":366}], "option":["from 180d to 215d","from 215d to 360d","from 360d to 365d"]}, {"type":"range","name":"Bacterial count","label":"Bacterial count", "value":[{"<=":0},{">":0,"<=":3},{">":3,"<=":10},{">":10,"<=":20}], "option":["below 0","from 1 to 3","from 4 to 10","from 11 to 20"]}, {"type":"range","name":"Dioxins incl. LOQ","label":"Dioxins in pg WHO-TEQ/g fat", "value":[{"<":0.56},{">=":0.56,"<=":1.0},{">":1.0,"<=":2.0},{">":2.0,"<=":2.5},{">":2.5}], "option":["below 0.56","from 0.56 to 1","from 1.01 to 2.0","from 2.01 to 2.5","above 2.5"]}, {"type":"range","name":"Dioxins and dioxin-like PCB incl. LOQ","label":"Dioxins and dioxin-like PCB in pg WHO-TEQ/g fat", "value":[{"<":1.2},{">=":1.2,"<=":2.0},{">":2.0,"<=":4.0},{">":4.0,"<=":5.5},{">":5.5}], "option":["below 1.2","from 1.2 to 2.0","from 2.01 to 4.0","from 4.01 to 5.5","above 5.5"]} ] EOF; } else { if ($lang == "zh_cn") { $sql = "select CHN from sdictionary where oriword in( SELECT distinct value FROM mobilephones.results where id_evaluation=100001759)"; $brandLabels = $GLOBALS['db']->getAllValues($sql); $brandLabels = json_encode($brandLabels); $labels = <<<EOF [ {"type":"range","name":"total test result","label":"总评分", "value":[{">=":0,"<=":1.5},{">":1.5,"<=":2.5},{">":2.5,"<=":3.5},{">":3.5,"<=":4.5},{">":4.5,"<=":5.5}], "option":["优秀","良好","中等","尚可","差劣"]}, {"type":"date","name":"Publication date","label":"测试时间", "value":[2016], "option":[2016]}, {"type":"string","name":"Brand","label":"品牌", "value":{$brands}, "option":{$brandLabels}} ] EOF; } } $arr = json_decode($labels, true); foreach ($arr as $key => $item) { if ($item['type'] == 'string') { foreach ($item['value'] as $value) { $sql = "select count(*) from results where value='" . $value . "'" . "and id_evaluation=(select id_evaluation from evaluations where id_evaluation>99999999 and name='" . $item['name'] . "')"; //echo $sql; $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } else { if ($item['type'] == 'range') { foreach ($item['value'] as $value) { $opts = array_keys($value); $len = count($opts); if ($item['name'] == 'total test result') { //评分数据四舍五入 if ($len == 1 && $opts[0] != -1) { $sql = "select count(*) from results where format(6-value,1)" . $opts[0] . $value[$opts[0]]; } else { if ($len == 2 && $opts[0] != -1) { $sql = "select count(*) from results where format(6-value,1)" . $opts[0] . $value[$opts[0]] . " and format(6-value,1)" . $opts[1] . $value[$opts[1]]; } } } else { //property数值正常读取 if ($len == 1 && $opts[0] != -1) { $sql = "select count(*) from results where value" . $opts[0] . $value[$opts[0]]; } else { if ($len == 2 && $opts[0] != -1) { $sql = "select count(*) from results where value" . $opts[0] . $value[$opts[0]] . " and value" . $opts[1] . $value[$opts[1]]; } } } $sql .= " and id_evaluation=(select id_evaluation from evaluations where "; if ($item['name'] == 'total test result') { $sql .= "name='" . $item['name'] . "')"; } else { $sql .= "id_evaluation>99999999 and name='" . $item['name'] . "')"; } //echo $sql."\n"; $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } else { if ($item['type'] == 'date') { foreach ($item['value'] as $value) { $sql = "select count(*) from products where FROM_UNIXTIME(timestamp_created, '%Y' )='" . $value . "'"; //echo $sql; $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } else { if ($item['type'] == 'multi') { foreach ($item['value'] as $value) { $sql = "select count(*) from results where value=1" . " and id_evaluation=(select id_evaluation from evaluations where id_evaluation>99999999 and name='" . $value . "')"; //echo $sql; $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } } } } } sortByNumber($arr[2]); return json_encode($arr); }
/** * Created by PhpStorm. * User: master * Date: 2016/3/7 * Time: 13:31 */ function getLabels() { $sql = "SELECT name FROM manufacturers"; $brands = $GLOBALS['db']->getAllValues($sql); $brands = json_encode($brands); //print_r($brands); $lang = $_SESSION['lang']; if ($lang == "en_us") { $labels = <<<EOF [ {"type":"range","name":"total test result","label":"Total test result", "value":[{">=":0,"<=":1.5},{">":1.5,"<=":2.5},{">":2.5,"<=":3.5},{">":3.5,"<=":4.5},{">":4.5,"<=":5.5}], "option":["very good ","good ","average","sufficient","poor"]}, {"type":"date","name":"Publication date","label":"Tested date", "value":[2016,2015,2014], "option":[2016,2015,2014]}, {"type":"string","name":"Brand","label":"Brands", "value":{$brands}, "option":{$brands}}, {"type":"string","name":"OS version on hard disk","label":"Operating System", "value":["windows","OS X","Android"], "option":["Windows","Mac OS","Android"]}, {"type":"string","name":"Size of main memory (Ram)","label":"Memory (RAM)", "value":["2","4","6","8","12","16"], "option":["2GB","4GB","6GB","8GB","12GB","16GB"]}, {"type":"range","name":"Claimed Capacity [GB]","label":"Storage capacity", "value":[{">=":8,"<=":64},{">=":65,"<=":128},{">":129,"<=":256},{">":257,"<=":500},{">=":1000}], "option":["8 - 64 GB","65 - 128 GB","129 - 256 GB","257 - 500 GB","1+ TB"]}, {"type":"range","name":"Screen image diagonal","label":"Screen diagonal", "value":[{">":10,"<=":12},{">":12,"<=":14},{">":14,"<=":16},{">":16,"<=":18}], "option":["10 - 12\\"","12 - 14\\"","14 - 16\\"","16 - 18\\""]}, {"type":"range","name":"Weight (with mid capacity battery)","label":"Weight incl. battery", "value":[{"<":1.2},{">=":1.2,"<=":1.7},{">":1.7,"<=":2.5},{">":2.5}], "option":["< 1.2kg","1.2 - 1.7kg","1.7 - 2.5kg","> 2.5kg"]}, {"type":"string","name":"Type of drive","label":"Type of drive", "value":["DVD","BD"], "option":["DVD drive","Blu-ray drive"]}, {"type":"string","name":"Type SSD HD?","label":"SSD", "value":["1","0"], "option":["Yes","No"]}, {"type":"string","name":"Touch screen [y/n]","label":"Touch screen", "value":["1","0"], "option":["Yes","No"]} ] EOF; } else { if ($lang == "zh_cn") { /* $sql="select CHN from sdictionary where oriword in( SELECT distinct value FROM results where id_evaluation=100001759)"; $brandLabels=$GLOBALS['db']->getAllValues($sql); $brandLabels=json_encode($brandLabels);*/ $labels = <<<EOF [ {"type":"range","name":"total test result","label":"总评分", "value":[{">=":0,"<=":1.5},{">":1.5,"<=":2.5},{">":2.5,"<=":3.5},{">":3.5,"<=":4.5},{">":4.5,"<=":5.5}], "option":["优秀","良好","中等","尚可","差劣"]}, {"type":"date","name":"Publication date","label":"测试时间", "value":[2016,2015,2014], "option":[2016,2015,2014]}, {"type":"string","name":"Brand","label":"品牌", "value":{$brands}, "option":{$brands}} ] EOF; } } $arr = json_decode($labels, true); foreach ($arr as $key => $item) { if ($item['type'] == 'string') { $index = 0; foreach ($item['value'] as $value) { if ($item['name'] == 'Brand') { $sql = "select count(*)from products where id_manufacturer=(select id_manufacturer from manufacturers where `name`='" . $value . "')"; } else { $sql = "select count(*) from results where id_evaluation in(select id_evaluation from evaluations where name='" . $item['name'] . "' and id_evaluation>99999999) and value like'{$value}%'"; } //echo $sql; $v = $GLOBALS['db']->getOne($sql); //echo $value." ".$v." ".$index."+++\n"; if ($v == 0) { array_splice($arr[$key]['option'], $index, 1); array_splice($arr[$key]['value'], $index, 1); $index--; // print_r($arr[$key]['option']); } else { $arr[$key]['number'][] = $v; } $index++; } } else { if ($item['type'] == 'range') { foreach ($item['value'] as $value) { $opts = array_keys($value); $len = count($opts); if ($item['name'] == 'total test result') { //评分数据四舍五入 if ($len == 1 && $opts[0] != -1) { $sql = "select count(*) from results where format(6-value,1)" . $opts[0] . $value[$opts[0]]; } else { if ($len == 2 && $opts[0] != -1) { $sql = "select count(*) from results where format(6-value,1)" . $opts[0] . $value[$opts[0]] . " and format(6-value,1)" . $opts[1] . $value[$opts[1]]; } } } else { //property数值正常读取 if ($len == 1 && $opts[0] != -1) { $sql = "select count(*) from results where value" . $opts[0] . $value[$opts[0]]; } else { if ($len == 2 && $opts[0] != -1) { $sql = "select count(*) from results where value" . $opts[0] . $value[$opts[0]] . " and value" . $opts[1] . $value[$opts[1]]; } } } $sql .= " and id_evaluation=(select id_evaluation from evaluations where "; if ($item['name'] == 'total test result') { $sql .= "name='" . $item['name'] . "')"; } else { $sql .= "id_evaluation>99999999 and name='" . $item['name'] . "')"; } $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } else { if ($item['type'] == 'date') { foreach ($item['value'] as $value) { $sql = "select count(*) from products where FROM_UNIXTIME(timestamp_created, '%Y' )='" . $value . "'"; //echo $sql; $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } else { if ($item['type'] == 'multi') { foreach ($item['value'] as $value) { $sql = "select count(*) from results where value=1" . " and id_evaluation=(select id_evaluation from evaluations where id_evaluation>99999999 and name='" . $value . "')"; //echo $sql; $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } } } } } sortByNumber($arr[2]); //print_r($arr); return json_encode($arr); }
/** * Created by PhpStorm. * User: master * Date: 2016/3/7 * Time: 13:31 */ function getLabels() { $sql = "SELECT name FROM manufacturers"; $brands = $GLOBALS['db']->getAllValues($sql); $brands = json_encode($brands); //print_r($brands); $lang = $_SESSION['lang']; if ($lang == "en_us") { $labels = <<<EOF [ {"type":"range","name":"total test result","label":"Total test result", "value":[{">=":0,"<=":1.5},{">":1.5,"<=":2.5},{">":2.5,"<=":3.5},{">":3.5,"<=":4.5},{">":4.5,"<=":5.5}], "option":["very good ","good ","average","adequate","poor"]}, {"type":"date","name":"Publication date","label":"Tested date", "value":[2016,2015], "option":[2016,2015]}, {"type":"string","name":"Brand","label":"Brands", "value":{$brands}, "option":{$brands}}, {"type":"range","name":"Screen Size","label":"Screen size", "value":[{">=":60,"<=":65},{">=":51,"<=":59},{">=":47,"<=":50},{">=":39,"<=":46},{">=":24,"<=":38},{">=":17,"<=":23}], "option":["60-65\\"","51-59\\"","47-50\\"","39-46\\"","24-38\\"","17-23\\""]}, {"type":"string","name":"Product category (LCD, Plasma, OLED, etc.)","label":"Screen type", "value":["OLED","Plasma","LCD"], "option":["OLED","Plasma","LCD"]}, {"type":"multi","name":"","label":"Screen features", "value":["Curved screen","Can TV cope with 3D","HDR"], "option":["Curved","3D","HDR"]}, {"type":"string","name":"Resolution level (HD-Ready, Full-HD or Ultra-HD)","label":"Resolution level", "value":["Full-HD","HD-Ready","Ultra-HD"], "option":["Full HD","HD ready","4K ultra HD"]}, {"type":"string","name":"Native (physical) resolution","label":"Resolution", "value":["1024 x 1080","1024 x 768","1366 x 768","1440 x 900","1920 x 1080","3840 x 2160","640 x 480"], "option":["1024 x 1080","1024 x 768","1366 x 768","1440 x 900","1920 x 1080","3840 x 2160","640 x 480"]}, {"type":"multi","name":"","label":"Smart TV", "value":["Wi-Fi Direct","Ethernet Connector","Recording one channel while watching other? (different MX)","Internet browsing and watching TV simultaneously","Smart menu: personalization (placing favorite apps)"], "option":["Wi-Fi","Ethernet","Twin-tuner","Browsing/watching","Personalization"]} ] EOF; } else { if ($lang == "zh_cn") { /* $sql="select CHN from sdictionary where oriword in( SELECT distinct value FROM results where id_evaluation=100001759)"; $brandLabels=$GLOBALS['db']->getAllValues($sql); $brandLabels=json_encode($brandLabels);*/ $labels = <<<EOF [ {"type":"range","name":"total test result","label":"总评分", "value":[{">=":0,"<=":1.5},{">":1.5,"<=":2.5},{">":2.5,"<=":3.5},{">":3.5,"<=":4.5},{">":4.5,"<=":5.5}], "option":["优秀","良好","中等","尚可","差劣"]}, {"type":"date","name":"Publication date","label":"测试时间", "value":[2016,2015], "option":[2016,2015]}, {"type":"string","name":"Brand","label":"品牌", "value":{$brands}, "option":{$brands}}, {"type":"range","name":"Screen Size","label":"屏幕大小", "value":[{">":65},{">=":60,"<=":65},{">=":51,"<=":55},{">=":47,"<=":50},{">=":39,"<=":46},{">=":24,"<=":32},{">=":17,"<=":22}], "option":["> 65\\"","60-65\\"","51-55\\"","47-50\\"","39-46\\"","24-32\\"","17-22\\""]}, {"type":"string","name":"Product category (LCD, Plasma, OLED, etc.)","label":"屏幕类型", "value":["OLED","Plasma","LCD"], "option":["OLED","Plasma","LCD"]} ] EOF; } } $arr = json_decode($labels, true); foreach ($arr as $key => $item) { if ($item['type'] == 'string') { $index = 0; foreach ($item['value'] as $value) { if ($item['name'] == 'Brand') { $sql = "select count(*)from products where id_manufacturer=(select id_manufacturer from manufacturers where `name`='" . $value . "')"; } else { $sql = "select count(*) from results where id_evaluation in(select id_evaluation from evaluations where name='" . $item['name'] . "') and value='{$value}'"; } //echo $sql; $v = $GLOBALS['db']->getOne($sql); //echo $value." ".$v." ".$index."+++\n"; if ($v == 0) { array_splice($arr[$key]['option'], $index, 1); array_splice($arr[$key]['value'], $index, 1); $index--; // print_r($arr[$key]['option']); } else { $arr[$key]['number'][] = $v; } $index++; } } else { if ($item['type'] == 'range') { foreach ($item['value'] as $value) { $opts = array_keys($value); $len = count($opts); if ($item['name'] == 'total test result') { //评分数据四舍五入 if ($len == 1 && $opts[0] != -1) { $sql = "select count(*) from results where format(6-value,1)" . $opts[0] . $value[$opts[0]]; } else { if ($len == 2 && $opts[0] != -1) { $sql = "select count(*) from results where format(6-value,1)" . $opts[0] . $value[$opts[0]] . " and format(6-value,1)" . $opts[1] . $value[$opts[1]]; } } } else { //property数值正常读取 if ($len == 1 && $opts[0] != -1) { $sql = "select count(*) from results where value" . $opts[0] . $value[$opts[0]]; } else { if ($len == 2 && $opts[0] != -1) { $sql = "select count(*) from results where value" . $opts[0] . $value[$opts[0]] . " and value" . $opts[1] . $value[$opts[1]]; } } } $sql .= " and id_evaluation=(select id_evaluation from evaluations where "; if ($item['name'] == 'total test result') { $sql .= "name='" . $item['name'] . "')"; } else { $sql .= "id_evaluation>99999999 and name='" . $item['name'] . "')"; } $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } else { if ($item['type'] == 'date') { foreach ($item['value'] as $value) { $sql = "select count(*) from products where FROM_UNIXTIME(timestamp_created, '%Y' )='" . $value . "'"; //echo $sql; $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } else { if ($item['type'] == 'multi') { $index = 0; foreach ($item['value'] as $k => $value) { $sql = "select count(*) from results where value=1" . " and id_evaluation=(select id_evaluation from evaluations where id_evaluation>99999999 and name='" . $value . "')"; //echo $sql; $v = $GLOBALS['db']->getOne($sql); //echo $value." ".$v." ".$index."+++\n"; if ($v == 0) { array_splice($arr[$key]['option'], $index, 1); array_splice($arr[$key]['value'], $index, 1); $index--; // print_r($arr[$key]['option']); } else { $arr[$key]['number'][] = $v; } $index++; } } } } } } sortByNumber($arr[2]); //print_r($arr); return json_encode($arr); }
/** * Created by PhpStorm. * User: master * Date: 2016/3/7 * Time: 13:31 */ function getLabels() { $sql = "SELECT name FROM manufacturers"; $brands = $GLOBALS['db']->getAllValues($sql); $brands = json_encode($brands); $sql = "select distinct value from results where id_evaluation=100001770"; $OSs = $GLOBALS['db']->getAllValues($sql); $OSs = json_encode($OSs); //print_r($brands); $lang = $_SESSION['lang']; if ($lang == "en_us") { $labels = <<<EOF [ {"type":"range","name":"total test result","label":"Total test result", "value":[{">=":0,"<=":1.5},{">":1.5,"<=":2.5},{">":2.5,"<=":3.5},{">":3.5,"<=":4.5},{">":4.5,"<=":5.5}], "option":["very good ","good ","average","adequate","poor"]}, {"type":"date","name":"Publication date","label":"Tested date", "value":[2016,2015,2014], "option":[2016,2015,2014]}, {"type":"string","name":"Brand","label":"Brands", "value":{$brands}, "option":{$brands}}, {"type":"string","name":"Operating system name","label":"Operating system", "value":{$OSs}, "option":{$OSs}}, {"type":"range","name":"Display diagonal","label":"Display diagonal","unit":"mm", "value":[{">=":130},{">=":110},{">=":100},{">=":84},{">=":51}], "option":["from 130 mm","from 110 mm","from 100 mm","from 84 mm","from 51 mm"]}, {"type":"multi","name":"","label":"SIM card format", "value":["Micro SIM","Mini SIM","Nano SIM","Dual SIM"], "option":["Micro SIM","Mini SIM","Nano SIM","Dual SIM"]}, {"type":"string","name":"Memory card slot","label":"Micro-SD card slot", "value":[1,0], "option":["Yes","No"]}, {"type":"range","name":"Water resistance in 1m if this is claimed?","label":"Water resistance", "value":[{">=":0.5,"<=":5.5}], "option":["Yes"]} ] EOF; } else { if ($lang == "zh_cn") { $sql = "select CHN from sdictionary where oriword in( SELECT distinct value FROM mobilephones.results where id_evaluation=100001759)"; $brandLabels = $GLOBALS['db']->getAllValues($sql); $brandLabels = json_encode($brandLabels); $labels = <<<EOF [ {"type":"range","name":"total test result","label":"总评分", "value":[{">=":0,"<=":1.5},{">":1.5,"<=":2.5},{">":2.5,"<=":3.5},{">":3.5,"<=":4.5},{">":4.5,"<=":5.5}], "option":["优秀","良好","中等","尚可","差劣"]}, {"type":"date","name":"Publication date","label":"测试时间", "value":[2016,2015,2014], "option":[2016,2015,2014]}, {"type":"string","name":"Brand","label":"品牌", "value":{$brands}, "option":{$brandLabels}}, {"type":"string","name":"Operating system name","label":"操作系统", "value":{$OSs}, "option":{$OSs}}, {"type":"range","name":"Display diagonal","label":"屏幕对角线长度","unit":"mm", "value":[{">=":130},{">=":110},{">=":100},{">=":84},{">=":51}], "option":["130 mm以上","110 mm以上","100 mm以上","84 mm以上","51 mm以上"]}, {"type":"multi","name":"","label":"SIM卡格式", "value":["Micro SIM","Mini SIM","Nano SIM","Dual SIM"], "option":["Micro SIM","Mini SIM","Nano SIM","Dual SIM"]}, {"type":"string","name":"Memory card slot","label":"Micro-SD card slot", "value":[1,0], "option":["有","无"]}, {"type":"range","name":"Water resistance in 1m if this is claimed?","label":"防1米深水性能", "value":[{">=":0.5,"<=":5.5}], "option":["有"]} ] EOF; } } $arr = json_decode($labels, true); foreach ($arr as $key => $item) { if ($item['type'] == 'string') { $index = 0; foreach ($item['value'] as $value) { if ($item['name'] == 'Brand') { $sql = "select count(*)from products where id_manufacturer=(select id_manufacturer from manufacturers where `name`='" . $value . "')"; } else { $sql = "select count(*) from results where id_evaluation in(select id_evaluation from evaluations where name='" . $item['name'] . "') and value='{$value}'"; } //echo $sql."\n"; $v = $GLOBALS['db']->getOne($sql); //echo $value." ".$v." ".$index."+++\n"; if ($v == 0) { array_splice($arr[$key]['option'], $index, 1); array_splice($arr[$key]['value'], $index, 1); $index--; // print_r($arr[$key]['option']); } else { $arr[$key]['number'][] = $v; } $index++; } } else { if ($item['type'] == 'range') { foreach ($item['value'] as $value) { $opts = array_keys($value); $len = count($opts); if ($item['name'] == 'total test result') { //评分数据四舍五入 if ($len == 1 && $opts[0] != -1) { $sql = "select count(*) from results where format(6-value,1)" . $opts[0] . $value[$opts[0]]; } else { if ($len == 2 && $opts[0] != -1) { $sql = "select count(*) from results where format(6-value,1)" . $opts[0] . $value[$opts[0]] . " and format(6-value,1)" . $opts[1] . $value[$opts[1]]; } } } else { //property数值正常读取 if ($len == 1 && $opts[0] != -1) { $sql = "select count(*) from results where value" . $opts[0] . $value[$opts[0]]; } else { if ($len == 2 && $opts[0] != -1) { $sql = "select count(*) from results where value" . $opts[0] . $value[$opts[0]] . " and value" . $opts[1] . $value[$opts[1]]; } } } $sql .= " and id_evaluation=(select id_evaluation from evaluations where "; if ($item['name'] == 'total test result') { $sql .= "name='" . $item['name'] . "')"; } else { $sql .= "id_evaluation>99999999 and name='" . $item['name'] . "')"; } $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } else { if ($item['type'] == 'date') { foreach ($item['value'] as $value) { $sql = "select count(*) from products where FROM_UNIXTIME(timestamp_created, '%Y' )='" . $value . "'"; //echo $sql; $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } else { if ($item['type'] == 'multi') { foreach ($item['value'] as $value) { $sql = "select count(*) from results where value=1" . " and id_evaluation=(select id_evaluation from evaluations where id_evaluation>99999999 and name='" . $value . "')"; //echo $sql; $v = $GLOBALS['db']->getOne($sql); $arr[$key]['number'][] = $v; } } } } } } sortByNumber($arr[2]); sortByNumber($arr[3]); return json_encode($arr); }