| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 239 |
liveuser |
6 |
Copyright (C) 2014~2026 MIN ZHI, CHEN
|
| 3 |
liveuser |
7 |
|
|
|
8 |
This file is part of QBPWCF.
|
|
|
9 |
|
|
|
10 |
QBPWCF is free software: you can redistribute it and/or modify
|
|
|
11 |
it under the terms of the GNU General Public License as published by
|
|
|
12 |
the Free Software Foundation, either version 3 of the License, or
|
|
|
13 |
(at your option) any later version.
|
|
|
14 |
|
|
|
15 |
QBPWCF is distributed in the hope that it will be useful,
|
|
|
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
18 |
GNU General Public License for more details.
|
|
|
19 |
|
|
|
20 |
You should have received a copy of the GNU General Public License
|
|
|
21 |
along with QBPWCF. If not, see <http://www.gnu.org/licenses/>.
|
|
|
22 |
|
|
|
23 |
*/
|
|
|
24 |
namespace qbpwcf;
|
|
|
25 |
|
|
|
26 |
/*
|
|
|
27 |
類別說明:
|
|
|
28 |
應用R的類別.
|
|
|
29 |
備註:
|
|
|
30 |
R的線上學習網站=>https://sites.google.com/site/rlearningsite/
|
|
|
31 |
*/
|
|
|
32 |
class R{
|
|
|
33 |
|
|
|
34 |
/*
|
|
|
35 |
#函式說明:
|
|
|
36 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
37 |
#回傳結果:
|
|
|
38 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
39 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
40 |
#$result["function"],當前執行的函式名稱.
|
|
|
41 |
#必填參數:
|
|
|
42 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
43 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
44 |
#參考資料:
|
|
|
45 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
46 |
#備註:
|
|
|
47 |
#無
|
|
|
48 |
*/
|
|
|
49 |
public function __call($method,$arguments){
|
| 226 |
liveuser |
50 |
|
| 3 |
liveuser |
51 |
#取得當前執行的函式
|
|
|
52 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
53 |
|
| 3 |
liveuser |
54 |
#設置執行不正常
|
|
|
55 |
$result["status"]="false";
|
| 226 |
liveuser |
56 |
|
| 3 |
liveuser |
57 |
#設置執行錯誤
|
|
|
58 |
$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
|
| 226 |
liveuser |
59 |
|
| 3 |
liveuser |
60 |
#設置所丟入的參數
|
|
|
61 |
$result["error"][]=$arguments;
|
| 226 |
liveuser |
62 |
|
| 3 |
liveuser |
63 |
#回傳結果
|
|
|
64 |
return $result;
|
| 226 |
liveuser |
65 |
|
| 3 |
liveuser |
66 |
}#function __call end
|
| 226 |
liveuser |
67 |
|
| 3 |
liveuser |
68 |
/*
|
|
|
69 |
#函式說明:
|
|
|
70 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
71 |
#回傳結果:
|
|
|
72 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
73 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
74 |
#$result["function"],當前執行的函式名稱.
|
|
|
75 |
#必填參數:
|
|
|
76 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
77 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
78 |
#參考資料:
|
|
|
79 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
80 |
#備註:
|
|
|
81 |
#無
|
|
|
82 |
*/
|
|
|
83 |
public static function __callStatic($method,$arguments){
|
| 226 |
liveuser |
84 |
|
| 3 |
liveuser |
85 |
#取得當前執行的函式
|
|
|
86 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
87 |
|
| 3 |
liveuser |
88 |
#設置執行不正常
|
|
|
89 |
$result["status"]="false";
|
| 226 |
liveuser |
90 |
|
| 3 |
liveuser |
91 |
#設置執行錯誤
|
|
|
92 |
$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
|
| 226 |
liveuser |
93 |
|
| 3 |
liveuser |
94 |
#設置所丟入的參數
|
|
|
95 |
$result["error"][]=$arguments;
|
| 226 |
liveuser |
96 |
|
| 3 |
liveuser |
97 |
#回傳結果
|
|
|
98 |
return $result;
|
| 226 |
liveuser |
99 |
|
| 3 |
liveuser |
100 |
}#function __callStatic end
|
|
|
101 |
|
|
|
102 |
/*
|
|
|
103 |
#函式說明:
|
|
|
104 |
#執行R腳本,執行完畢後,會刪除R的腳本與暫存R執行後的輸出的檔案.
|
|
|
105 |
#回傳結果:
|
|
|
106 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
107 |
#$result["errror"],錯誤訊息陣列
|
|
|
108 |
#$result["function"],當前執行的函數名稱
|
|
|
109 |
#$result["lineArray"],字串陣列,R輸出結果,每個元素代表一行的輸出.
|
|
|
110 |
#$result["lineCount"],整數,R輸出的總共行數.
|
|
|
111 |
#$result["RscriptContent"],執行的R腳本內容,一個元素代表一列.
|
|
|
112 |
#必填參數:
|
|
|
113 |
#$conf["rPositionAndName"],字串,R腳本的位置與名稱.
|
|
|
114 |
$conf["rPositionAndName"]=".R";
|
|
|
115 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
116 |
$conf["fileArgu"]=__FILE__;
|
|
|
117 |
#可省略參數:
|
|
|
118 |
#$conf["disbaleOptimal"],字串,"true"代表取消輸出的優化,可以顯示版本訊息、歡迎訊息、儲存暫存檔,預設為"false"要進行優化.
|
|
|
119 |
#$conf["disbaleOptimal"]="true";
|
|
|
120 |
#參考資料:
|
|
|
121 |
#無.
|
|
|
122 |
#備註:
|
|
|
123 |
#無.
|
| 226 |
liveuser |
124 |
*/
|
| 3 |
liveuser |
125 |
public static function executeR(&$conf){
|
| 226 |
liveuser |
126 |
|
| 3 |
liveuser |
127 |
#初始化要回傳的結果
|
|
|
128 |
$result=array();
|
| 226 |
liveuser |
129 |
|
| 3 |
liveuser |
130 |
#設置當前函數名稱
|
|
|
131 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
132 |
|
| 3 |
liveuser |
133 |
#如果 $conf 不等於 "array"
|
| 226 |
liveuser |
134 |
if(gettype($conf)!="array"){
|
|
|
135 |
|
| 3 |
liveuser |
136 |
#設定錯誤識別
|
|
|
137 |
$result["status"]="false";
|
| 226 |
liveuser |
138 |
|
| 3 |
liveuser |
139 |
#設置錯誤訊息
|
|
|
140 |
$result["error"]="參數的Key指定有誤!";
|
| 226 |
liveuser |
141 |
|
| 3 |
liveuser |
142 |
#如果傳入的參數為 null
|
|
|
143 |
if($conf==null){
|
| 226 |
liveuser |
144 |
|
| 3 |
liveuser |
145 |
#設置執行錯誤訊息
|
|
|
146 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
147 |
|
| 3 |
liveuser |
148 |
}#if end
|
| 226 |
liveuser |
149 |
|
| 3 |
liveuser |
150 |
#回傳結果
|
|
|
151 |
return $result;
|
| 226 |
liveuser |
152 |
|
| 3 |
liveuser |
153 |
}#if end
|
| 226 |
liveuser |
154 |
|
| 3 |
liveuser |
155 |
#如果 $conf["disbaleOptimal"] 未設定
|
|
|
156 |
if(!isset($conf["disbaleOptimal"])){
|
| 226 |
liveuser |
157 |
|
| 3 |
liveuser |
158 |
#預設 $conf["disbaleOptimal"] 為 "false"
|
|
|
159 |
$conf["disbaleOptimal"]="false";
|
| 226 |
liveuser |
160 |
|
| 3 |
liveuser |
161 |
}#if end
|
| 226 |
liveuser |
162 |
|
| 3 |
liveuser |
163 |
#檢查參數
|
|
|
164 |
#涵式說明:
|
|
|
165 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
166 |
#回傳的結果:
|
|
|
167 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
168 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
169 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
170 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
171 |
#必填寫的參數:
|
|
|
172 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
173 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("rPositionAndName","fileArgu");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
174 |
#可以省略的參數:
|
| 226 |
liveuser |
175 |
$conf["variableCheck"]["isexistMuti"]["variableType"]=array("string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
176 |
$conf["variableCheck"]["isexistMuti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
177 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
178 |
unset($conf["variableCheck"]["isexistMuti"]);
|
| 226 |
liveuser |
179 |
|
| 3 |
liveuser |
180 |
#如果 $checkResult["status"] 等於 "false"
|
|
|
181 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
182 |
|
| 3 |
liveuser |
183 |
#設置錯誤識別
|
|
|
184 |
$result["status"]="false";
|
| 226 |
liveuser |
185 |
|
| 3 |
liveuser |
186 |
#設置錯誤訊息
|
|
|
187 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
188 |
|
| 3 |
liveuser |
189 |
#回傳結果
|
|
|
190 |
return $result;
|
| 226 |
liveuser |
191 |
|
| 3 |
liveuser |
192 |
}#if end
|
| 226 |
liveuser |
193 |
|
| 3 |
liveuser |
194 |
#如果 $checkResult["passed"] 等於 "false"
|
|
|
195 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
196 |
|
| 3 |
liveuser |
197 |
#設置錯誤識別
|
|
|
198 |
$result["status"]="false";
|
| 226 |
liveuser |
199 |
|
| 3 |
liveuser |
200 |
#設置錯誤訊息
|
|
|
201 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
202 |
|
| 3 |
liveuser |
203 |
#回傳結果
|
|
|
204 |
return $result;
|
| 226 |
liveuser |
205 |
|
| 3 |
liveuser |
206 |
}#if end
|
| 226 |
liveuser |
207 |
|
| 3 |
liveuser |
208 |
#產生暫時存放執行結果的檔案
|
|
|
209 |
#函式說明:
|
|
|
210 |
#檢查要建立的檔案路徑是否存在,若不存在則建立新檔案,若檔案已存在則會在原檔名後面加上從(1)開始的編號,再度嘗試建立檔案,以避免資料異常.
|
|
|
211 |
#回傳的結果:
|
|
|
212 |
#$result["status"],執行狀態,"true"代表執行正常,"false"代表執行失敗.
|
|
|
213 |
#$result["error"],錯誤訊息陣列.
|
|
|
214 |
#$result["createdFileName"],建立好的檔案名稱.
|
|
|
215 |
#$result["createdFilePath"],檔案建立的路徑.
|
|
|
216 |
#$result["createdFilePathAndName"].建立好的檔案名稱與路徑.
|
|
|
217 |
#必填的參數:
|
|
|
218 |
#$conf["checkedFileAndPath"],字串陣列,要建立的檔案路徑
|
|
|
219 |
$conf["fileAccess"]["createFileAfterCheck"]["checkedFileAndPath"]=".R/tempOutPut";
|
|
|
220 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
221 |
$conf["fileAccess"]["createFileAfterCheck"]["fileArgu"]=$conf["fileArgu"];
|
|
|
222 |
$createTempFileOfOutput=fileAccess::createFileAfterCheck($conf["fileAccess"]["createFileAfterCheck"]);
|
|
|
223 |
unset($conf["fileAccess"]["createFileAfterCheck"]);
|
| 226 |
liveuser |
224 |
|
| 3 |
liveuser |
225 |
#如果 $createTempFileOfOutput["status"] 等於 "false"
|
|
|
226 |
if($createTempFileOfOutput["status"]=="false"){
|
| 226 |
liveuser |
227 |
|
| 3 |
liveuser |
228 |
#設置錯誤識別
|
|
|
229 |
$result["status"]="false";
|
| 226 |
liveuser |
230 |
|
| 3 |
liveuser |
231 |
#設置錯誤訊息
|
|
|
232 |
$result["error"]=$createTempFileOfOutput;
|
| 226 |
liveuser |
233 |
|
| 3 |
liveuser |
234 |
#回傳結果
|
|
|
235 |
return $result;
|
| 226 |
liveuser |
236 |
|
| 3 |
liveuser |
237 |
}#if end
|
| 226 |
liveuser |
238 |
|
| 3 |
liveuser |
239 |
#取得R腳本內容
|
|
|
240 |
#函式說明:
|
|
|
241 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
242 |
#回傳的變數說明:
|
|
|
243 |
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗。
|
|
|
244 |
#$result["error"],錯誤訊息提示
|
|
|
245 |
#$result["fileContent"],爲檔案的內容陣列
|
|
|
246 |
#$result["lineCount"],爲檔案內容總共的行數
|
|
|
247 |
#$result["fullContent"],為檔案的完整內容
|
|
|
248 |
#必填的參數:
|
|
|
249 |
$conf["file.getFileContent"]["filePositionAndName"]=$conf["rPositionAndName"];#爲檔案的位置以及名稱
|
|
|
250 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
251 |
$conf["file.getFileContent"]["fileArgu"]=$conf["fileArgu"];
|
|
|
252 |
#參考資料:
|
|
|
253 |
#file():取得檔案內容的行數
|
|
|
254 |
#http:#php.net/manual/en/function.file.php
|
|
|
255 |
#rtrim():剔除透過file()取得每行內容結尾的換行符號.
|
|
|
256 |
$getRscriptContent=fileAccess::getFileContent($conf["file.getFileContent"]);
|
|
|
257 |
unset($conf["file.getFileContent"]);
|
| 226 |
liveuser |
258 |
|
| 3 |
liveuser |
259 |
#如果取得R腳本內容失敗
|
|
|
260 |
if($getRscriptContent["status"]=="false"){
|
| 226 |
liveuser |
261 |
|
| 3 |
liveuser |
262 |
#設置錯誤識別
|
|
|
263 |
$result["status"]="false";
|
| 226 |
liveuser |
264 |
|
| 3 |
liveuser |
265 |
#設置錯誤訊息
|
|
|
266 |
$result["error"]=$getRscriptContent;
|
| 226 |
liveuser |
267 |
|
| 3 |
liveuser |
268 |
#回傳結果
|
|
|
269 |
return $result;
|
| 226 |
liveuser |
270 |
|
| 3 |
liveuser |
271 |
}#if end
|
| 226 |
liveuser |
272 |
|
| 3 |
liveuser |
273 |
#取得R腳本內容
|
|
|
274 |
$result["RscriptContent"]=$getRscriptContent["fileContent"];
|
| 226 |
liveuser |
275 |
|
| 3 |
liveuser |
276 |
#初始化要執行的R指令參數
|
|
|
277 |
$paramsArray=array();
|
| 226 |
liveuser |
278 |
|
| 3 |
liveuser |
279 |
#如果要優化R的執行
|
|
|
280 |
if($conf["disbaleOptimal"]=="false"){
|
| 226 |
liveuser |
281 |
|
| 3 |
liveuser |
282 |
#設定要執行的R指令參數
|
|
|
283 |
$paramsArray=array("--vanilla","-q","-f",$conf["rPositionAndName"],">",$createTempFileOfOutput["createdFilePathAndName"]);
|
| 226 |
liveuser |
284 |
|
| 3 |
liveuser |
285 |
}#if end
|
| 226 |
liveuser |
286 |
|
| 3 |
liveuser |
287 |
#反之代表不優化R的執行
|
|
|
288 |
else{
|
| 226 |
liveuser |
289 |
|
| 3 |
liveuser |
290 |
#設定要執行的R指令參數
|
|
|
291 |
$paramsArray=array("-f",$conf["rPositionAndName"],">",$createTempFileOfOutput["createdFilePathAndName"]);
|
| 226 |
liveuser |
292 |
|
| 3 |
liveuser |
293 |
}#else end
|
| 226 |
liveuser |
294 |
|
| 3 |
liveuser |
295 |
#函式說明:
|
|
|
296 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
297 |
#回傳結果:
|
|
|
298 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
299 |
#$result["error"],錯誤訊息陣列.
|
|
|
300 |
#$result["function"],當前執行的函數名稱.
|
|
|
301 |
#$result["argu"],使用的參數.
|
|
|
302 |
#$result["cmd"],執行的指令內容.
|
|
|
303 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
304 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
305 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
306 |
#$result["running"],是否還在執行.
|
|
|
307 |
#$result["pid"],pid.
|
|
|
308 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
309 |
#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
|
|
|
310 |
#必填參數:
|
|
|
311 |
#$conf["command"],字串,要執行的指令.
|
|
|
312 |
$conf["external"]["callShell"]["command"]="R";
|
|
|
313 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
314 |
$conf["external"]["callShell"]["fileArgu"]=__FILE__;
|
|
|
315 |
#可省略參數:
|
|
|
316 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
317 |
$conf["external"]["callShell"]["argu"]=$paramsArray;
|
|
|
318 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
319 |
#$conf["arguIsAddr"]=array();
|
|
|
320 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
321 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
322 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
323 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
324 |
#$conf["enablePrintDescription"]="true";
|
|
|
325 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
326 |
#$conf["printDescription"]="";
|
|
|
327 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
328 |
$conf["external"]["callShell"]["escapeshellarg"]="true";
|
|
|
329 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
330 |
#$conf["thereIsShellVar"]=array();
|
|
|
331 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
332 |
#$conf["username"]="";
|
|
|
333 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
334 |
#$conf["password"]="";
|
|
|
335 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
336 |
#$conf["useScript"]="";
|
|
|
337 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
338 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
339 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
340 |
#$conf["inBackGround"]="";
|
|
|
341 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
342 |
#$conf["getErr"]="false";
|
|
|
343 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
344 |
#$conf["doNotRun"]="false";
|
|
|
345 |
#參考資料:
|
|
|
346 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
347 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
348 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
349 |
#備註:
|
|
|
350 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
351 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
352 |
$executionResult=external::callShell($conf["external"]["callShell"]);
|
|
|
353 |
unset($conf["external"]["callShell"]);
|
| 226 |
liveuser |
354 |
|
| 3 |
liveuser |
355 |
#如果 $executionResult["status"] 等於 "false"
|
|
|
356 |
if($executionResult["status"]=="false"){
|
| 226 |
liveuser |
357 |
|
| 3 |
liveuser |
358 |
#設置錯誤識別
|
|
|
359 |
$result["status"]="false";
|
| 226 |
liveuser |
360 |
|
| 3 |
liveuser |
361 |
#設置錯誤訊息
|
|
|
362 |
$result["error"]=$executionResult;
|
| 226 |
liveuser |
363 |
|
| 3 |
liveuser |
364 |
#回傳結果
|
|
|
365 |
return $result;
|
| 226 |
liveuser |
366 |
|
| 3 |
liveuser |
367 |
}#if end
|
| 226 |
liveuser |
368 |
|
| 3 |
liveuser |
369 |
#取得暫存檔裡面的R輸出結果
|
|
|
370 |
#函式說明:
|
|
|
371 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
372 |
#回傳的變數說明:
|
|
|
373 |
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗。
|
|
|
374 |
#$result["error"],錯誤訊息提示
|
|
|
375 |
#$result["fileContent"],爲檔案的內容陣列
|
|
|
376 |
#$result["lineCount"],爲檔案內容總共的行數
|
|
|
377 |
#$result["fullContent"],為檔案的完整內容
|
|
|
378 |
#必填的參數:
|
|
|
379 |
$conf["fileAccess"]["getFileContent"]["filePositionAndName"]=$createTempFileOfOutput["createdFilePathAndName"];#爲檔案的位置以及名稱
|
|
|
380 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
381 |
$conf["fileAccess"]["getFileContent"]["fileArgu"]=$conf["fileArgu"];
|
|
|
382 |
#參考資料:
|
|
|
383 |
#file():取得檔案內容的行數
|
|
|
384 |
#http:#php.net/manual/en/function.file.php
|
|
|
385 |
#rtrim():剔除透過file()取得每行內容結尾的換行符號.
|
|
|
386 |
$readRtempOutPutFile=fileAccess::getFileContent($conf["fileAccess"]["getFileContent"]);
|
|
|
387 |
unset($conf["fileAccess"]["getFileContent"]);
|
| 226 |
liveuser |
388 |
|
| 3 |
liveuser |
389 |
#如果 $readRtempOutPutFile["status"] 等於 "false"
|
|
|
390 |
if($readRtempOutPutFile["status"]=="false"){
|
| 226 |
liveuser |
391 |
|
| 3 |
liveuser |
392 |
#設置錯誤識別
|
|
|
393 |
$result["status"]="false";
|
| 226 |
liveuser |
394 |
|
| 3 |
liveuser |
395 |
#設置錯誤訊息
|
|
|
396 |
$result["error"]=$readRtempOutPutFile;
|
| 226 |
liveuser |
397 |
|
| 3 |
liveuser |
398 |
#回傳結果
|
|
|
399 |
return $result;
|
| 226 |
liveuser |
400 |
|
| 3 |
liveuser |
401 |
}#if end
|
| 226 |
liveuser |
402 |
|
| 3 |
liveuser |
403 |
#取得輸出內容行數
|
|
|
404 |
$result["lineCount"]=$readRtempOutPutFile["lineCount"];
|
| 226 |
liveuser |
405 |
|
| 3 |
liveuser |
406 |
#取得輸出內容陣列
|
|
|
407 |
$result["lineArray"]=$readRtempOutPutFile["fileContent"];
|
| 226 |
liveuser |
408 |
|
| 3 |
liveuser |
409 |
#移除R腳本檔案
|
|
|
410 |
#涵式說明:
|
|
|
411 |
#移除檔案
|
|
|
412 |
#回傳的結果:
|
|
|
413 |
#$result["status"],"true"代表移除成功,"false"代表移除失敗.
|
|
|
414 |
#必填的參數:
|
|
|
415 |
$conf["fileAccess"]["delFile"]["fileAddress"]=$conf["rPositionAndName"];#要移除檔案的位置
|
|
|
416 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
417 |
$conf["fileAccess"]["delFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
418 |
$eraseRsh=fileAccess::delFile($conf["fileAccess"]["delFile"]);
|
|
|
419 |
unset($conf["fileAccess"]["delFile"]);
|
| 226 |
liveuser |
420 |
|
| 3 |
liveuser |
421 |
#如果 $eraseRsh["status"] 等於 "false"
|
|
|
422 |
if($eraseRsh["status"]=="false"){
|
| 226 |
liveuser |
423 |
|
| 3 |
liveuser |
424 |
#設置錯誤識別
|
|
|
425 |
$result["status"]="false";
|
| 226 |
liveuser |
426 |
|
| 3 |
liveuser |
427 |
#設置錯誤訊息
|
|
|
428 |
$result["error"]=$eraseRsh;
|
| 226 |
liveuser |
429 |
|
| 3 |
liveuser |
430 |
#回傳結果
|
|
|
431 |
return $result;
|
| 226 |
liveuser |
432 |
|
| 3 |
liveuser |
433 |
}#if end
|
| 226 |
liveuser |
434 |
|
| 3 |
liveuser |
435 |
#移除暫存R輸出的檔案
|
|
|
436 |
#涵式說明:
|
|
|
437 |
#移除檔案
|
|
|
438 |
#回傳的結果:
|
|
|
439 |
#$result["status"],"true"代表移除成功,"false"代表移除失敗.
|
|
|
440 |
#必填的參數:
|
|
|
441 |
$conf["fileAccess"]["delFile"]["fileAddress"]=$createTempFileOfOutput["createdFilePathAndName"];#要移除檔案的位置
|
|
|
442 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
443 |
$conf["fileAccess"]["delFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
444 |
$eraseRtempOutputFile=fileAccess::delFile($conf["fileAccess"]["delFile"]);
|
|
|
445 |
unset($conf["fileAccess"]["delFile"]);
|
| 226 |
liveuser |
446 |
|
| 3 |
liveuser |
447 |
#如果 $eraseRsh["status"] 等於 "false"
|
|
|
448 |
if($eraseRtempOutputFile["status"]=="false"){
|
| 226 |
liveuser |
449 |
|
| 3 |
liveuser |
450 |
#設置錯誤識別
|
|
|
451 |
$result["status"]="false";
|
| 226 |
liveuser |
452 |
|
| 3 |
liveuser |
453 |
#設置錯誤訊息
|
|
|
454 |
$result["error"]=$eraseRsh;
|
| 226 |
liveuser |
455 |
|
| 3 |
liveuser |
456 |
#回傳結果
|
|
|
457 |
return $result;
|
| 226 |
liveuser |
458 |
|
| 3 |
liveuser |
459 |
}#if end
|
| 226 |
liveuser |
460 |
|
| 3 |
liveuser |
461 |
#執行到這邊代表執行正常
|
|
|
462 |
$result["status"]="true";
|
| 226 |
liveuser |
463 |
|
| 3 |
liveuser |
464 |
#回傳結果
|
|
|
465 |
return $result;
|
| 226 |
liveuser |
466 |
|
| 3 |
liveuser |
467 |
}#function executeR end
|
|
|
468 |
|
|
|
469 |
/*
|
|
|
470 |
#涵式說明:
|
|
|
471 |
#展示R的文字輸出範例
|
|
|
472 |
#回傳的結果:
|
|
|
473 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
|
|
|
474 |
#$result["error"],錯誤訊息陣列.
|
|
|
475 |
#$result["function"],當前執行的函數名稱.
|
|
|
476 |
#$result["newCreatedRfilePathAndName"],R腳本檔的位置與名稱
|
|
|
477 |
#$result["content"],執行完後的結果陣列,一個元素代表一列內容.
|
|
|
478 |
#必填參數:
|
|
|
479 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
480 |
$conf["fileArgu"]=__FILE__;
|
|
|
481 |
#可省略參數:
|
|
|
482 |
#無.
|
|
|
483 |
#參考資料:
|
|
|
484 |
#無.
|
|
|
485 |
#備註:
|
|
|
486 |
#無.
|
|
|
487 |
*/
|
|
|
488 |
public static function demoTextOutput(&$conf=array()){
|
|
|
489 |
|
|
|
490 |
#初始化要回傳的結果
|
|
|
491 |
$result=array();
|
|
|
492 |
|
|
|
493 |
#取得當前執行的函數名稱
|
|
|
494 |
$result["function"]=__FUNCTION__;
|
|
|
495 |
|
|
|
496 |
#如果沒有參數
|
|
|
497 |
if(func_num_args()==0){
|
| 226 |
liveuser |
498 |
|
| 3 |
liveuser |
499 |
#設置執行失敗
|
|
|
500 |
$result["status"]="false";
|
| 226 |
liveuser |
501 |
|
| 3 |
liveuser |
502 |
#設置執行錯誤訊息
|
|
|
503 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
504 |
|
| 3 |
liveuser |
505 |
#回傳結果
|
|
|
506 |
return $result;
|
| 226 |
liveuser |
507 |
|
| 3 |
liveuser |
508 |
}#if end
|
|
|
509 |
|
|
|
510 |
#取得參數
|
|
|
511 |
$result["argu"]=$conf;
|
|
|
512 |
|
|
|
513 |
#如果 $conf 不為陣列
|
|
|
514 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
515 |
|
| 3 |
liveuser |
516 |
#設置執行失敗
|
|
|
517 |
$result["status"]="false";
|
| 226 |
liveuser |
518 |
|
| 3 |
liveuser |
519 |
#設置執行錯誤訊息
|
|
|
520 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
521 |
|
| 3 |
liveuser |
522 |
#如果傳入的參數為 null
|
|
|
523 |
if($conf===null){
|
| 226 |
liveuser |
524 |
|
| 3 |
liveuser |
525 |
#設置執行錯誤訊息
|
|
|
526 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
527 |
|
| 3 |
liveuser |
528 |
}#if end
|
|
|
529 |
|
|
|
530 |
#回傳結果
|
|
|
531 |
return $result;
|
| 226 |
liveuser |
532 |
|
| 3 |
liveuser |
533 |
}#if end
|
|
|
534 |
|
|
|
535 |
#檢查參數
|
|
|
536 |
#函式說明:
|
|
|
537 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
538 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
539 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
540 |
#$result["function"],當前執行的函式名稱.
|
|
|
541 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
542 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
543 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
544 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
545 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
546 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
547 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
548 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
549 |
#必填寫的參數:
|
|
|
550 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
551 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
552 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
553 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
|
|
|
554 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
555 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
556 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
557 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
558 |
#可以省略的參數:
|
|
|
559 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
560 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
561 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
562 |
#$conf["canNotBeEmpty"]=array();
|
|
|
563 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
564 |
#$conf["canBeEmpty"]=array();
|
|
|
565 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
566 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
567 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
568 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
569 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
570 |
#$conf["skipableVariableType"]=array();
|
|
|
571 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
572 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
573 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
574 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
575 |
#參考資料來源:
|
|
|
576 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
577 |
#建議:
|
|
|
578 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
579 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
580 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
581 |
|
|
|
582 |
#如果檢查參數失敗
|
|
|
583 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
584 |
|
| 3 |
liveuser |
585 |
#設置執行失敗
|
|
|
586 |
$result["status"]="false";
|
| 226 |
liveuser |
587 |
|
| 3 |
liveuser |
588 |
#設置錯誤訊息
|
|
|
589 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
590 |
|
| 3 |
liveuser |
591 |
#回傳結果
|
|
|
592 |
return $result;
|
| 226 |
liveuser |
593 |
|
| 3 |
liveuser |
594 |
}#if end
|
| 226 |
liveuser |
595 |
|
| 3 |
liveuser |
596 |
#如果參數檢查不通過
|
|
|
597 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
598 |
|
| 3 |
liveuser |
599 |
#設置執行失敗
|
|
|
600 |
$result["status"]="false";
|
| 226 |
liveuser |
601 |
|
| 3 |
liveuser |
602 |
#設置錯誤訊息
|
|
|
603 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
604 |
|
| 3 |
liveuser |
605 |
#回傳結果
|
|
|
606 |
return $result;
|
| 226 |
liveuser |
607 |
|
| 3 |
liveuser |
608 |
}#if end
|
|
|
609 |
|
|
|
610 |
#建立要寫入的行內容
|
|
|
611 |
$rCode[]="#宣告變數k,其值等於1";
|
|
|
612 |
$rCode[]="k=1";
|
|
|
613 |
|
|
|
614 |
$rCode[]="#檢視變數內容";
|
|
|
615 |
$rCode[]="k";
|
| 226 |
liveuser |
616 |
|
|
|
617 |
$rCode[]="#判斷變數k是否爲integer";
|
| 3 |
liveuser |
618 |
$rCode[]="is.integer(k)";
|
| 226 |
liveuser |
619 |
|
| 3 |
liveuser |
620 |
$rCode[]="#宣告變數k,其值等於integer型態的1";
|
|
|
621 |
$rCode[]="k=as.integer(1)";
|
| 226 |
liveuser |
622 |
|
|
|
623 |
$rCode[]="#檢視變數內容";
|
|
|
624 |
$rCode[]="k";
|
|
|
625 |
|
|
|
626 |
$rCode[]="#判斷變數k是否爲integer";
|
|
|
627 |
$rCode[]="is.integer(k)";
|
|
|
628 |
|
| 3 |
liveuser |
629 |
#涵式說明:
|
|
|
630 |
#建立R檔案
|
|
|
631 |
#回傳的結果:
|
|
|
632 |
#true代表寫入成功,false代表寫入失敗
|
|
|
633 |
#必填的參數:
|
|
|
634 |
$conf["R"]["writeRfile"]["addAndName"]=".rOutput/rDemo.R";#R檔案的位置與名稱
|
|
|
635 |
$conf["R"]["writeRfile"]["textToWrite"]=$rCode;#要寫入的字串內容陣列,一個元素代表一行文字,每行結尾會自動換行。
|
|
|
636 |
#必填參數:
|
|
|
637 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
|
|
|
638 |
$conf["R"]["writeRfile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
639 |
$writeRfile=R::writeRfile($conf["R"]["writeRfile"]);
|
|
|
640 |
unset($conf["R"]["writeRfile"]);
|
|
|
641 |
|
|
|
642 |
#如果建立R腳本檔案失敗
|
|
|
643 |
if($writeRfile["status"]=="false"){
|
| 226 |
liveuser |
644 |
|
| 3 |
liveuser |
645 |
#設置執行失敗
|
|
|
646 |
$result["status"]="false";
|
| 226 |
liveuser |
647 |
|
| 3 |
liveuser |
648 |
#設置執行錯誤訊息
|
|
|
649 |
$result["error"]=$writeRfile;
|
| 226 |
liveuser |
650 |
|
| 3 |
liveuser |
651 |
#回傳結果
|
|
|
652 |
return $result;
|
| 226 |
liveuser |
653 |
|
| 3 |
liveuser |
654 |
}#if end
|
|
|
655 |
|
|
|
656 |
#呼叫系統命令使用R來執行檔案內的指令,將結果輸出到檔案裏面。
|
|
|
657 |
#system("R <.rOutput/rDemo.R --no-save > .rOutput/".$_SESSION["username"]."-output");
|
|
|
658 |
#函式說明:
|
|
|
659 |
#執行R腳本,執行完畢後,會刪除R的腳本與暫存R執行後的輸出的檔案.
|
|
|
660 |
#回傳的結果:
|
|
|
661 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
662 |
#$result["errror"],錯誤訊息陣列
|
|
|
663 |
#$result["lineArray"],字串陣列,R輸出結果,每個元素代表一行的輸出.
|
|
|
664 |
#$result["lineCount"],整數,R輸出的總共行數.
|
|
|
665 |
#$result["RscriptContent"],執行的R腳本內容,一個元素代表一列.
|
|
|
666 |
#必填的參數:
|
|
|
667 |
#$conf["R::executeR"]["rPositionAndName"],字串,R腳本的位置與名稱.
|
|
|
668 |
$conf["R::executeR"]["rPositionAndName"]=".rOutput/rDemo.R";
|
|
|
669 |
#可省略的參數:
|
|
|
670 |
#$conf["disbaleOptimal"],字串,"true"代表取消輸出的優化,可以顯示版本訊息、歡迎訊息、儲存暫存檔,預設為"false"要進行優化.
|
|
|
671 |
#$conf["disbaleOptimal"]="true";
|
|
|
672 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
|
|
|
673 |
$conf["R::executeR"]["fileArgu"]=$conf["fileArgu"];
|
|
|
674 |
$executeR=R::executeR($conf["R::executeR"]);
|
|
|
675 |
unset($conf["R::executeR"]);
|
| 226 |
liveuser |
676 |
|
| 3 |
liveuser |
677 |
#如果執行R腳本失敗
|
|
|
678 |
if($executeR["status"]=="false"){
|
| 226 |
liveuser |
679 |
|
| 3 |
liveuser |
680 |
#設置執行失敗
|
|
|
681 |
$result["status"]="false";
|
| 226 |
liveuser |
682 |
|
| 3 |
liveuser |
683 |
#設置執行錯誤訊息
|
|
|
684 |
$result["error"]=$executeR;
|
| 226 |
liveuser |
685 |
|
| 3 |
liveuser |
686 |
#回傳結果
|
|
|
687 |
return $result;
|
| 226 |
liveuser |
688 |
|
| 3 |
liveuser |
689 |
}#if end
|
| 226 |
liveuser |
690 |
|
| 3 |
liveuser |
691 |
#取得執行完的結果
|
|
|
692 |
$result["content"]=$executeR["lineArray"];
|
|
|
693 |
|
|
|
694 |
#設置執行正常
|
|
|
695 |
$result["status"]="true";
|
|
|
696 |
|
|
|
697 |
#回傳執行結果
|
|
|
698 |
return $result;
|
|
|
699 |
|
|
|
700 |
}#if end
|
|
|
701 |
|
|
|
702 |
/*
|
|
|
703 |
#涵式說明:
|
|
|
704 |
#展示R的繪圖範例
|
|
|
705 |
#回傳結果:
|
|
|
706 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
|
|
|
707 |
#$result["error"],錯誤訊息陣列.
|
|
|
708 |
#$result["function"],當前執行的函數名稱.
|
|
|
709 |
#$result["text"],執行R所得到的文字內容.
|
|
|
710 |
#$result["img"],顯示圖表的語法.
|
|
|
711 |
#必填參數:
|
|
|
712 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
713 |
$conf["fileArgu"]=__FILE__;
|
|
|
714 |
#可省略參數:
|
|
|
715 |
#無
|
|
|
716 |
#參考資料:
|
|
|
717 |
#無.
|
|
|
718 |
#備註:
|
|
|
719 |
#無
|
|
|
720 |
*/
|
|
|
721 |
public static function demoGraphiOutput(&$conf=array()){
|
|
|
722 |
|
|
|
723 |
#初始化要回傳的結果
|
|
|
724 |
$result=array();
|
|
|
725 |
|
|
|
726 |
#取得當前執行的函數名稱
|
|
|
727 |
$result["function"]=__FUNCTION__;
|
|
|
728 |
|
|
|
729 |
#如果沒有參數
|
|
|
730 |
if(func_num_args()==0){
|
| 226 |
liveuser |
731 |
|
| 3 |
liveuser |
732 |
#設置執行失敗
|
|
|
733 |
$result["status"]="false";
|
| 226 |
liveuser |
734 |
|
| 3 |
liveuser |
735 |
#設置執行錯誤訊息
|
|
|
736 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
737 |
|
| 3 |
liveuser |
738 |
#回傳結果
|
|
|
739 |
return $result;
|
| 226 |
liveuser |
740 |
|
| 3 |
liveuser |
741 |
}#if end
|
|
|
742 |
|
|
|
743 |
#取得參數
|
|
|
744 |
$result["argu"]=$conf;
|
|
|
745 |
|
|
|
746 |
#如果 $conf 不為陣列
|
|
|
747 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
748 |
|
| 3 |
liveuser |
749 |
#設置執行失敗
|
|
|
750 |
$result["status"]="false";
|
| 226 |
liveuser |
751 |
|
| 3 |
liveuser |
752 |
#設置執行錯誤訊息
|
|
|
753 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
754 |
|
| 3 |
liveuser |
755 |
#如果傳入的參數為 null
|
|
|
756 |
if($conf===null){
|
| 226 |
liveuser |
757 |
|
| 3 |
liveuser |
758 |
#設置執行錯誤訊息
|
|
|
759 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
760 |
|
| 3 |
liveuser |
761 |
}#if end
|
|
|
762 |
|
|
|
763 |
#回傳結果
|
|
|
764 |
return $result;
|
| 226 |
liveuser |
765 |
|
| 3 |
liveuser |
766 |
}#if end
|
|
|
767 |
|
|
|
768 |
#檢查參數
|
|
|
769 |
#函式說明:
|
|
|
770 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
771 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
772 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
773 |
#$result["function"],當前執行的函式名稱.
|
|
|
774 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
775 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
776 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
777 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
778 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
779 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
780 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
781 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
782 |
#必填寫的參數:
|
|
|
783 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
784 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
785 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
786 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
|
|
|
787 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
788 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
789 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
790 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
791 |
#可以省略的參數:
|
|
|
792 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
793 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
794 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
795 |
#$conf["canNotBeEmpty"]=array();
|
|
|
796 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
797 |
#$conf["canBeEmpty"]=array();
|
|
|
798 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
799 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
800 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
801 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
802 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
803 |
#$conf["skipableVariableType"]=array();
|
|
|
804 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
805 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
806 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
807 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
808 |
#參考資料來源:
|
|
|
809 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
810 |
#建議:
|
|
|
811 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
812 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
813 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
814 |
|
|
|
815 |
#如果檢查參數失敗
|
|
|
816 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
817 |
|
| 3 |
liveuser |
818 |
#設置執行失敗
|
|
|
819 |
$result["status"]="false";
|
| 226 |
liveuser |
820 |
|
| 3 |
liveuser |
821 |
#設置錯誤訊息
|
|
|
822 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
823 |
|
| 3 |
liveuser |
824 |
#回傳結果
|
|
|
825 |
return $result;
|
| 226 |
liveuser |
826 |
|
| 3 |
liveuser |
827 |
}#if end
|
| 226 |
liveuser |
828 |
|
| 3 |
liveuser |
829 |
#如果參數檢查不通過
|
|
|
830 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
831 |
|
| 3 |
liveuser |
832 |
#設置執行失敗
|
|
|
833 |
$result["status"]="false";
|
| 226 |
liveuser |
834 |
|
| 3 |
liveuser |
835 |
#設置錯誤訊息
|
|
|
836 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
837 |
|
| 3 |
liveuser |
838 |
#回傳結果
|
|
|
839 |
return $result;
|
| 226 |
liveuser |
840 |
|
| 3 |
liveuser |
841 |
}#if end
|
|
|
842 |
|
|
|
843 |
#建立要寫入的行內容
|
|
|
844 |
$rCode[]="#創建圖片,將繪圖的結果都存在該圖裏面";
|
|
|
845 |
$rCode[]="svg(filename=\".rOutput/temp.svg\")";
|
|
|
846 |
|
|
|
847 |
$rCode[]="#產生常態分配資料100筆";
|
|
|
848 |
$rCode[]="y=rnorm(100,5,10)";
|
|
|
849 |
|
|
|
850 |
$rCode[]="#繪製直方圖";
|
|
|
851 |
$rCode[]="hist(y,prob=TRUE)";
|
| 226 |
liveuser |
852 |
|
| 3 |
liveuser |
853 |
#涵式說明:
|
|
|
854 |
#建立R檔案
|
|
|
855 |
#回傳的結果:
|
|
|
856 |
#true代表寫入成功,false代表寫入失敗
|
|
|
857 |
#必填的參數:
|
|
|
858 |
$conf["R"]["writeRfile"]["addAndName"]=".rOutput/rGraphiDemo.R";#R檔案的位置與名稱
|
|
|
859 |
$conf["R"]["writeRfile"]["textToWrite"]=$rCode;#要寫入的字串內容陣列,一個元素代表一行文字,每行結尾會自動換行。
|
|
|
860 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
861 |
$conf["R"]["writeRfile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
862 |
$writeRfile=R::writeRfile($conf["R"]["writeRfile"]);
|
|
|
863 |
unset($conf["R"]["writeRfile"]);
|
|
|
864 |
|
|
|
865 |
#如果建立R腳本檔案失敗
|
|
|
866 |
if($writeRfile["status"]=="false"){
|
| 226 |
liveuser |
867 |
|
| 3 |
liveuser |
868 |
#設置執行失敗
|
|
|
869 |
$result["status"]="false";
|
| 226 |
liveuser |
870 |
|
| 3 |
liveuser |
871 |
#設置執行錯誤訊息
|
|
|
872 |
$result["error"]=$writeRfile;
|
| 226 |
liveuser |
873 |
|
| 3 |
liveuser |
874 |
#回傳結果
|
|
|
875 |
return $result;
|
| 226 |
liveuser |
876 |
|
| 3 |
liveuser |
877 |
}#if end
|
|
|
878 |
|
|
|
879 |
#呼叫系統命令使用R來執行檔案內的指令,將結果輸出到檔案裏面。
|
|
|
880 |
#system("R <.rOutput/rDemo.R --no-save > .rOutput/".$_SESSION["username"]."-output");
|
|
|
881 |
#函式說明:
|
|
|
882 |
#執行R腳本,執行完畢後,會刪除R的腳本與暫存R執行後的輸出的檔案.
|
|
|
883 |
#回傳的結果:
|
|
|
884 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
885 |
#$result["errror"],錯誤訊息陣列
|
|
|
886 |
#$result["lineArray"],字串陣列,R輸出結果,每個元素代表一行的輸出.
|
|
|
887 |
#$result["lineCount"],整數,R輸出的總共行數.
|
|
|
888 |
#$result["RscriptContent"],執行的R腳本內容,一個元素代表一列.
|
|
|
889 |
#必填的參數:
|
|
|
890 |
#$conf["R::executeR"]["rPositionAndName"],字串,R腳本的位置與名稱.
|
|
|
891 |
$conf["R::executeR"]["rPositionAndName"]=".rOutput/rGraphiDemo.R";
|
|
|
892 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
893 |
$conf["R::executeR"]["fileArgu"]=$conf["fileArgu"];
|
|
|
894 |
#可省略的參數:
|
|
|
895 |
#$conf["disbaleOptimal"],字串,"true"代表取消輸出的優化,可以顯示版本訊息、歡迎訊息、儲存暫存檔,預設為"false"要進行優化.
|
|
|
896 |
#$conf["disbaleOptimal"]="true";
|
|
|
897 |
$executeR=R::executeR($conf["R::executeR"]);
|
|
|
898 |
unset($conf["R::executeR"]);
|
| 226 |
liveuser |
899 |
|
| 3 |
liveuser |
900 |
#如果執行R腳本失敗
|
|
|
901 |
if($executeR["status"]=="false"){
|
| 226 |
liveuser |
902 |
|
| 3 |
liveuser |
903 |
#設置執行失敗
|
|
|
904 |
$result["status"]="false";
|
| 226 |
liveuser |
905 |
|
| 3 |
liveuser |
906 |
#設置執行錯誤訊息
|
|
|
907 |
$result["error"]=$executeR;
|
| 226 |
liveuser |
908 |
|
| 3 |
liveuser |
909 |
#回傳結果
|
|
|
910 |
return $result;
|
| 226 |
liveuser |
911 |
|
| 3 |
liveuser |
912 |
}#if end
|
|
|
913 |
|
|
|
914 |
#印出統計圖的語法
|
|
|
915 |
#函數說明:
|
|
|
916 |
#用data:mimeType;base64,imgVar的形式來提供圖片的連結,亦即圖片儲存在變數裡面,本函式包含顯示圖片的語法.
|
|
|
917 |
#回傳結果:
|
|
|
918 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
919 |
#$result["error"],錯誤訊息
|
|
|
920 |
#$result["content"],圖片的連結資訊
|
| 226 |
liveuser |
921 |
#$result["function"],當前執行的函數名稱
|
| 3 |
liveuser |
922 |
#必填參數:
|
|
|
923 |
#$conf["imgPosition"],要轉存成2元碼的圖片檔案位置與名稱
|
|
|
924 |
$conf["img::data"]["imgPosition"]=".rOutput/temp.svg";
|
|
|
925 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
926 |
$conf["img::data"]["fileArgu"]=$conf["fileArgu"];
|
|
|
927 |
#可省略參數:
|
|
|
928 |
#$conf["alt"],若沒有圖片要用什麼文字顯示。
|
|
|
929 |
#$conf["alt"]="";
|
|
|
930 |
#$conf["style"],字串陣列,要使用的style,key為樣式名稱,value為樣式值.
|
|
|
931 |
$conf["img::data"]["style"]=array("width"=>"100%");
|
|
|
932 |
#$conf["class"],圖片要套用的css樣式名稱.
|
|
|
933 |
#$conf["class"]="";
|
|
|
934 |
#$conf["mimeType"],2元碼的內容是什麼,預設為"image/*".
|
|
|
935 |
$conf["img::data"]["mimeType"]="image/svg+xml";
|
|
|
936 |
#$conf["compressType"],2元碼壓縮的方式,預設為"base64".
|
|
|
937 |
#$conf["compressType"]="base64";
|
|
|
938 |
#$conf["delImg"],讀取完圖片檔案後,要移除圖片嗎?"true"代表要移除,"false"代表不要移除,預設為"false".
|
|
|
939 |
$conf["img::data"]["delImg"]="false";
|
|
|
940 |
#參考資料:
|
|
|
941 |
#將檔案用字串變數儲存起來=>http://php.net/manual/en/function.file-get-contents.php
|
|
|
942 |
#壓縮2元碼=>http://php.net/manual/en/function.base64-encode.php
|
|
|
943 |
$data=img::data($conf["img::data"]);
|
|
|
944 |
unset($conf["img::data"]);
|
|
|
945 |
|
|
|
946 |
#如果顯示圖片失敗
|
|
|
947 |
if($data["status"]=="false"){
|
| 226 |
liveuser |
948 |
|
| 3 |
liveuser |
949 |
#設置執行失敗
|
|
|
950 |
$result["status"]="false";
|
| 226 |
liveuser |
951 |
|
| 3 |
liveuser |
952 |
#設置執行錯誤訊息
|
|
|
953 |
$result["error"]=$data;
|
| 226 |
liveuser |
954 |
|
| 3 |
liveuser |
955 |
#回傳結果
|
|
|
956 |
return $result;
|
| 226 |
liveuser |
957 |
|
| 3 |
liveuser |
958 |
}#if end
|
|
|
959 |
|
|
|
960 |
#取得執行R過後的結果
|
|
|
961 |
$result["text"]=$executeR["lineArray"];
|
|
|
962 |
|
|
|
963 |
#取得顯示圖表的語法
|
|
|
964 |
$result["img"]=$data["content"];
|
|
|
965 |
|
|
|
966 |
#設置執行正常
|
|
|
967 |
$result["status"]="true";
|
|
|
968 |
|
|
|
969 |
#回傳結果
|
|
|
970 |
return $result;
|
|
|
971 |
|
|
|
972 |
}#function demoGraphiOutput end
|
| 226 |
liveuser |
973 |
|
| 3 |
liveuser |
974 |
/*
|
|
|
975 |
#涵式說明:
|
|
|
976 |
#建立R檔案
|
|
|
977 |
#回傳的結果:
|
|
|
978 |
#$result["status"],執行正常與否,"true"代表正常;"false"代表不正常
|
|
|
979 |
#$result["error"],錯誤訊息陣列
|
|
|
980 |
#$result["function"],當前函數名稱
|
|
|
981 |
#$result["newCreatedRfilePathAndName"],R腳本檔的位置與名稱
|
|
|
982 |
#必填參數:
|
|
|
983 |
#$conf["addAndName"],字串,檔案的位置與名稱,"folderName/fileName.R"
|
|
|
984 |
$conf["addAndName"]="";
|
|
|
985 |
#$conf["textToWrite"],字串陣列,要寫入的字串內容陣列,一個元素代表一行文字,每行結尾會自動換行.
|
|
|
986 |
$conf["textToWrite"]=array("");
|
|
|
987 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
988 |
$conf["fileArgu"]=__FILE__;
|
|
|
989 |
#可省略參數
|
|
|
990 |
#無.
|
|
|
991 |
#參考資料:
|
|
|
992 |
#無.
|
|
|
993 |
#備註:
|
|
|
994 |
#無.
|
| 226 |
liveuser |
995 |
*/
|
| 3 |
liveuser |
996 |
public static function writeRfile(&$conf=array()){
|
| 226 |
liveuser |
997 |
|
| 3 |
liveuser |
998 |
#初始化要回傳的結果
|
|
|
999 |
$result=array();
|
| 226 |
liveuser |
1000 |
|
| 3 |
liveuser |
1001 |
#設置當前執行的涵式
|
|
|
1002 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
1003 |
|
| 3 |
liveuser |
1004 |
#如果 $conf 不等於 "array"
|
| 226 |
liveuser |
1005 |
if(gettype($conf)!="array"){
|
|
|
1006 |
|
| 3 |
liveuser |
1007 |
#設定錯誤識別
|
|
|
1008 |
$result["status"]="false";
|
| 226 |
liveuser |
1009 |
|
| 3 |
liveuser |
1010 |
#設置錯誤訊息
|
|
|
1011 |
$result["error"]="參數的Key指定有誤!";
|
| 226 |
liveuser |
1012 |
|
| 3 |
liveuser |
1013 |
#如果傳入的參數為 null
|
|
|
1014 |
if($conf==null){
|
| 226 |
liveuser |
1015 |
|
| 3 |
liveuser |
1016 |
#設置執行錯誤訊息
|
|
|
1017 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1018 |
|
| 3 |
liveuser |
1019 |
}#if end
|
| 226 |
liveuser |
1020 |
|
| 3 |
liveuser |
1021 |
#回傳結果
|
|
|
1022 |
return $result;
|
| 226 |
liveuser |
1023 |
|
| 3 |
liveuser |
1024 |
}#if end
|
| 226 |
liveuser |
1025 |
|
| 3 |
liveuser |
1026 |
#檢查參數
|
|
|
1027 |
#涵式說明:
|
|
|
1028 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
1029 |
#回傳的結果:
|
|
|
1030 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1031 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1032 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1033 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1034 |
#必填寫的參數:
|
|
|
1035 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
1036 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("addAndName","textToWrite","fileArgu");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
1037 |
#可以省略的參數:
|
| 226 |
liveuser |
1038 |
$conf["variableCheck"]["isexistMuti"]["variableType"]=array("string","array","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
1039 |
$conf["variableCheck"]["isexistMuti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
1040 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
1041 |
unset($conf["variableCheck"]["isexistMuti"]);
|
| 226 |
liveuser |
1042 |
|
| 3 |
liveuser |
1043 |
#如果 $checkResult["status"] 等於 "false"
|
|
|
1044 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
1045 |
|
| 3 |
liveuser |
1046 |
#設置錯誤識別
|
|
|
1047 |
$result["status"]="false";
|
| 226 |
liveuser |
1048 |
|
| 3 |
liveuser |
1049 |
#設置錯誤訊息
|
|
|
1050 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1051 |
|
| 3 |
liveuser |
1052 |
#回傳結果
|
|
|
1053 |
return $result;
|
| 226 |
liveuser |
1054 |
|
| 3 |
liveuser |
1055 |
}#if end
|
| 226 |
liveuser |
1056 |
|
| 3 |
liveuser |
1057 |
#如果 $checkResult["passed"] 等於 "false"
|
|
|
1058 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
1059 |
|
| 3 |
liveuser |
1060 |
#設置錯誤識別
|
|
|
1061 |
$result["status"]="false";
|
| 226 |
liveuser |
1062 |
|
| 3 |
liveuser |
1063 |
#設置錯誤訊息
|
|
|
1064 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1065 |
|
| 3 |
liveuser |
1066 |
#回傳結果
|
|
|
1067 |
return $result;
|
| 226 |
liveuser |
1068 |
|
| 3 |
liveuser |
1069 |
}#if end
|
| 226 |
liveuser |
1070 |
|
| 3 |
liveuser |
1071 |
#建立R腳本檔
|
|
|
1072 |
#函式說明:
|
|
|
1073 |
#檢查要建立的檔案路徑是否存在,若不存在則建立新檔案,若檔案已存在則會在原檔名後面加上從(1)開始的編號,再度嘗試建立檔案,以避免資料異常.
|
|
|
1074 |
#回傳的結果:
|
|
|
1075 |
#$result["status"],執行狀態,"true"代表執行正常,"false"代表執行失敗.
|
|
|
1076 |
#$result["error"],錯誤訊息陣列.
|
|
|
1077 |
#$result["createdFileName"],建立好的檔案名稱.
|
|
|
1078 |
#$result["createdFilePath"],檔案建立的路徑.
|
|
|
1079 |
#$result["createdFilePathAndName"].建立好的檔案名稱與路徑.
|
|
|
1080 |
#必填的參數:
|
|
|
1081 |
#$conf["checkedFileAndPath"],字串陣列,要建立的檔案路徑
|
|
|
1082 |
$conf["fileAccess"]["createFileAfterCheck"]["checkedFileAndPath"]=$conf["addAndName"];
|
|
|
1083 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1084 |
$conf["fileAccess"]["createFileAfterCheck"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1085 |
$createResult=fileAccess::createFileAfterCheck($conf["fileAccess"]["createFileAfterCheck"]);
|
|
|
1086 |
unset($conf["fileAccess"]["createFileAfterCheck"]);
|
| 226 |
liveuser |
1087 |
|
| 3 |
liveuser |
1088 |
#如果R腳本檔案建立失敗
|
|
|
1089 |
if($createResult["status"]=="false"){
|
| 226 |
liveuser |
1090 |
|
| 3 |
liveuser |
1091 |
#建立錯誤識別
|
|
|
1092 |
$result["status"]="false";
|
| 226 |
liveuser |
1093 |
|
| 3 |
liveuser |
1094 |
#建立錯誤訊息
|
|
|
1095 |
$result["error"]=$createResult;
|
| 226 |
liveuser |
1096 |
|
| 3 |
liveuser |
1097 |
#回傳結果
|
|
|
1098 |
return $result;
|
| 226 |
liveuser |
1099 |
|
| 3 |
liveuser |
1100 |
}#if end
|
| 226 |
liveuser |
1101 |
|
| 3 |
liveuser |
1102 |
#取得R腳本檔的位置與名稱
|
|
|
1103 |
$result["newCreatedRfilePathAndName"]=$createResult["createdFilePathAndName"];
|
| 226 |
liveuser |
1104 |
|
| 3 |
liveuser |
1105 |
#針對$conf["textToWrite"]的每個元素
|
|
|
1106 |
foreach($conf["textToWrite"] as $key=>$value){
|
| 226 |
liveuser |
1107 |
|
| 3 |
liveuser |
1108 |
#涵式說明:
|
|
|
1109 |
#將字串寫入到檔案
|
|
|
1110 |
#回傳的結果:
|
|
|
1111 |
#$result,true表示檔案建立成功,false表示檔案建立失敗
|
|
|
1112 |
#必填的參數:
|
|
|
1113 |
$conf["fileAccess"]["writeTextIntoFile"]["fileName"]=$result["newCreatedRfilePathAndName"];#爲要編輯的檔案名稱
|
|
|
1114 |
$conf["fileAccess"]["writeTextIntoFile"]["inputString"]=$value."\r\n";#爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可。
|
|
|
1115 |
$conf["fileAccess"]["writeTextIntoFile"]["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
|
|
|
1116 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1117 |
$conf["fileAccess"]["writeTextIntoFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1118 |
$writeFileresult=fileAccess::writeTextIntoFile($conf["fileAccess"]["writeTextIntoFile"]);
|
|
|
1119 |
unset($conf["fileAccess"]["writeTextIntoFile"]);
|
|
|
1120 |
|
|
|
1121 |
#如果 寫入結果爲 "false"
|
|
|
1122 |
if($writeFileresult["status"]=="false"){
|
|
|
1123 |
|
|
|
1124 |
#設置錯誤識別
|
|
|
1125 |
$result["status"]="false";
|
| 226 |
liveuser |
1126 |
|
| 3 |
liveuser |
1127 |
#設置錯誤訊息
|
|
|
1128 |
$result["error"][]="寫入檔案失敗,可能http沒有權限,或 ".$conf["addAndName"]." 檔案不存在.";
|
|
|
1129 |
|
|
|
1130 |
#回傳結果
|
|
|
1131 |
return $result;
|
|
|
1132 |
|
|
|
1133 |
}#if end
|
|
|
1134 |
|
|
|
1135 |
}#foreach end
|
| 226 |
liveuser |
1136 |
|
| 3 |
liveuser |
1137 |
#執行到這邊代表執行成功
|
|
|
1138 |
$result["status"]="true";
|
| 226 |
liveuser |
1139 |
|
| 3 |
liveuser |
1140 |
#回傳結果
|
|
|
1141 |
return $result;
|
|
|
1142 |
|
|
|
1143 |
}#function createRfile end
|
| 226 |
liveuser |
1144 |
|
| 3 |
liveuser |
1145 |
/*
|
|
|
1146 |
#函式說明:
|
|
|
1147 |
#針對csv樣本檔作決策樹分析,可以設定分析完後是否要刪除csv樣本檔.
|
|
|
1148 |
#回傳的結果:
|
|
|
1149 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
|
|
|
1150 |
#$result["error"],錯誤訊息陣列.
|
|
|
1151 |
#$result["function"],當前執行的函數名稱.
|
|
|
1152 |
#$result["lineArray"],執行結果輸出的逐行內容.
|
|
|
1153 |
#$result["lineCount"],執行結果輸出的行數.
|
|
|
1154 |
#$result["content"],顯示圖表的語法.
|
|
|
1155 |
#$result["img"],圖表的位置與名稱
|
|
|
1156 |
#必填參數:
|
|
|
1157 |
#$conf["inputCsvFilePosition"],字串,csv資料檔的路徑與名稱,資料檔的第一欄為各變數的標題.
|
|
|
1158 |
$conf["inputCsvFilePosition"]=".csv";
|
|
|
1159 |
#$conf["targetVar"],字串,要預測的變數名稱.
|
|
|
1160 |
$conf["targetVar"]="";
|
|
|
1161 |
#$conf["independentVar"],陣列字串,用來預測的變數名稱陣列.
|
|
|
1162 |
$conf["independentVar"]=array();
|
|
|
1163 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1164 |
$conf["fileArgu"]=__FILE__;
|
|
|
1165 |
#可省略參數:
|
|
|
1166 |
#$conf["trainDataPercent"],字串,訓練資料要佔多少,預設為"0.7".
|
|
|
1167 |
#$conf["trainDataPercent"]="0.7";
|
|
|
1168 |
#$conf["testDataPercent"],字串,測試資料要佔多少,預設"0.3".
|
|
|
1169 |
#$conf["testDataPercent"]="0.3";
|
|
|
1170 |
#$conf["trainDataReportImgPositionAndName"],字串,決策樹分析訓練資料後的關聯圖表輸出位置與名稱,預設為"report.png".
|
|
|
1171 |
#$conf["trainDataReportImgPositionAndName"]="report.png";
|
|
|
1172 |
#$conf["delSampleCsvFile"],字串,是否要在分析結束後,移除樣本csv檔案,預設為"false"不移除,"true"則代表要移除.
|
|
|
1173 |
#$conf["delSampleCsvFile"]="false";
|
|
|
1174 |
#參考資料:
|
|
|
1175 |
#R的決策樹分析範例=>http://www.rdatamining.com/examples/decision-tree
|
|
|
1176 |
#備註:
|
|
|
1177 |
#測試資料分析尚未撰寫
|
|
|
1178 |
*/
|
|
|
1179 |
public static function decisionTreeWithPackageParty(&$conf){
|
| 226 |
liveuser |
1180 |
|
| 3 |
liveuser |
1181 |
#初始化要回傳的結果
|
|
|
1182 |
$result=array();
|
| 226 |
liveuser |
1183 |
|
| 3 |
liveuser |
1184 |
#取得當前執行函數名稱
|
|
|
1185 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
1186 |
|
| 3 |
liveuser |
1187 |
#如果 $conf 不為陣列
|
|
|
1188 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1189 |
|
| 3 |
liveuser |
1190 |
#設置執行失敗
|
|
|
1191 |
$result["status"]="false";
|
| 226 |
liveuser |
1192 |
|
| 3 |
liveuser |
1193 |
#設置執行錯誤訊息
|
|
|
1194 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1195 |
|
|
|
1196 |
#如果傳入的參數為 null
|
|
|
1197 |
if($conf==null){
|
| 226 |
liveuser |
1198 |
|
| 3 |
liveuser |
1199 |
#設置執行錯誤訊息
|
|
|
1200 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1201 |
|
| 3 |
liveuser |
1202 |
}#if end
|
|
|
1203 |
|
|
|
1204 |
#回傳結果
|
|
|
1205 |
return $result;
|
| 226 |
liveuser |
1206 |
|
| 3 |
liveuser |
1207 |
}#if end
|
| 226 |
liveuser |
1208 |
|
| 3 |
liveuser |
1209 |
#檢查參數
|
|
|
1210 |
#涵式說明:
|
|
|
1211 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
1212 |
#回傳的結果:
|
|
|
1213 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1214 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1215 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1216 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1217 |
#必填寫的參數:
|
|
|
1218 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
1219 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("fileArgu","inputCsvFilePosition","targetVar","independentVar");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
1220 |
#可以省略的參數:
|
| 226 |
liveuser |
1221 |
$conf["variableCheck"]["isexistMuti"]["variableType"]=array("string","string","string","array");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
1222 |
$conf["variableCheck"]["isexistMuti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
1223 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
1224 |
unset($conf["variableCheck"]["isexistMuti"]);
|
| 226 |
liveuser |
1225 |
|
| 3 |
liveuser |
1226 |
#如果 $checkResult["status"] 等於 "false"
|
|
|
1227 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
1228 |
|
| 3 |
liveuser |
1229 |
#設置錯誤識別
|
|
|
1230 |
$result["status"]="false";
|
| 226 |
liveuser |
1231 |
|
| 3 |
liveuser |
1232 |
#設置錯誤訊息
|
|
|
1233 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1234 |
|
| 3 |
liveuser |
1235 |
#回傳結果
|
|
|
1236 |
return $result;
|
| 226 |
liveuser |
1237 |
|
| 3 |
liveuser |
1238 |
}#if end
|
| 226 |
liveuser |
1239 |
|
| 3 |
liveuser |
1240 |
#如果 $checkResult["passed"] 等於 "false"
|
|
|
1241 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
1242 |
|
| 3 |
liveuser |
1243 |
#設置錯誤識別
|
|
|
1244 |
$result["status"]="false";
|
| 226 |
liveuser |
1245 |
|
| 3 |
liveuser |
1246 |
#設置錯誤訊息
|
|
|
1247 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1248 |
|
| 3 |
liveuser |
1249 |
#回傳結果
|
|
|
1250 |
return $result;
|
| 226 |
liveuser |
1251 |
|
| 3 |
liveuser |
1252 |
}#if end
|
| 226 |
liveuser |
1253 |
|
| 3 |
liveuser |
1254 |
#如果 $conf["trainDataPercent"] 未設定
|
|
|
1255 |
if(!isset($conf["trainDataPercent"])){
|
| 226 |
liveuser |
1256 |
|
| 3 |
liveuser |
1257 |
#預設為 0.7
|
|
|
1258 |
$conf["trainDataPercent"]="0.7";
|
| 226 |
liveuser |
1259 |
|
| 3 |
liveuser |
1260 |
}#if end
|
| 226 |
liveuser |
1261 |
|
|
|
1262 |
#如果 $conf["testDataPercent"] 未設定
|
| 3 |
liveuser |
1263 |
if(!isset($conf["testDataPercent"])){
|
| 226 |
liveuser |
1264 |
|
| 3 |
liveuser |
1265 |
#預設為 0.3
|
|
|
1266 |
$conf["testDataPercent"]="0.3";
|
| 226 |
liveuser |
1267 |
|
| 3 |
liveuser |
1268 |
}#if end
|
| 226 |
liveuser |
1269 |
|
| 3 |
liveuser |
1270 |
#如果 $conf["trainDataReportImgPositionAndName"] 未設定
|
|
|
1271 |
if(!isset($conf["trainDataReportImgPositionAndName"])){
|
| 226 |
liveuser |
1272 |
|
| 3 |
liveuser |
1273 |
#預設為 trainDataReport.png
|
|
|
1274 |
$conf["trainDataReportImgPositionAndName"]="report.png";
|
| 226 |
liveuser |
1275 |
|
| 3 |
liveuser |
1276 |
}#if end
|
| 226 |
liveuser |
1277 |
|
| 3 |
liveuser |
1278 |
#如果 $conf["delSampleCsvFile"] 未設定
|
|
|
1279 |
if(!isset($conf["delSampleCsvFile"])){
|
| 226 |
liveuser |
1280 |
|
| 3 |
liveuser |
1281 |
#預設為 "false"
|
|
|
1282 |
$conf["delSampleCsvFile"]="false";
|
| 226 |
liveuser |
1283 |
|
| 3 |
liveuser |
1284 |
}#if end
|
| 226 |
liveuser |
1285 |
|
| 3 |
liveuser |
1286 |
#初始化要寫入到R腳本的內容
|
|
|
1287 |
$rCode=array();
|
| 226 |
liveuser |
1288 |
|
| 3 |
liveuser |
1289 |
#讀取 csv檔的內容
|
|
|
1290 |
$rCode[]="Data <- read.csv(\"".$conf["inputCsvFilePosition"]."\")";
|
| 226 |
liveuser |
1291 |
|
| 3 |
liveuser |
1292 |
#分割讀到的資料檔為訓練資料、測試資料
|
|
|
1293 |
$rCode[]="ind <- sample(2, nrow(Data), replace=TRUE, prob=c(".$conf["trainDataPercent"].",".$conf["testDataPercent"]."))";
|
| 226 |
liveuser |
1294 |
|
| 3 |
liveuser |
1295 |
#將Data的第一組資料,亦即70%的Data資料放置到trainData裡面作為訓練資料。
|
|
|
1296 |
$rCode[]="trainData <- Data[ind==1,]";
|
|
|
1297 |
|
|
|
1298 |
#將Data的第二組資料,亦即30%的Data資料放置到testData裡面作為測試資料。
|
|
|
1299 |
$rCode[]="testData <- Data[ind==2,]";
|
| 226 |
liveuser |
1300 |
|
| 3 |
liveuser |
1301 |
#使用 party 套件,內包含 ctree()與predict()
|
|
|
1302 |
$rCode[]="library(party)";
|
| 226 |
liveuser |
1303 |
|
| 3 |
liveuser |
1304 |
#建立要預測變數的字串
|
|
|
1305 |
#myFormula指定 $conf["targetVar"] 為被預測變數,其他變數則為獨立變數.
|
|
|
1306 |
$formula="myFormula <- ".$conf["targetVar"]." ~ ";
|
| 226 |
liveuser |
1307 |
|
| 3 |
liveuser |
1308 |
#初始化獨立變數的字串
|
|
|
1309 |
$independentStr="";
|
| 226 |
liveuser |
1310 |
|
| 3 |
liveuser |
1311 |
#建立獨立變數字串
|
|
|
1312 |
for($i=0;$i<count($conf["independentVar"]);$i++){
|
| 226 |
liveuser |
1313 |
|
| 3 |
liveuser |
1314 |
#串連獨立變數字串
|
|
|
1315 |
$independentStr=$independentStr." + ".$conf["independentVar"][$i];
|
| 226 |
liveuser |
1316 |
|
| 3 |
liveuser |
1317 |
}#for end
|
| 226 |
liveuser |
1318 |
|
| 3 |
liveuser |
1319 |
#儲存要預測變數與獨立變數到R腳本裡面
|
|
|
1320 |
$rCode[]=$formula.$independentStr;
|
| 226 |
liveuser |
1321 |
|
| 3 |
liveuser |
1322 |
#使用 ctree 建立決策樹,被預測變數與預測變數的設定存在myFormula,用來建立決策樹的資料為儲存在trainData的資料
|
|
|
1323 |
$rCode[]="Data_ctree <- ctree(myFormula, data=trainData)";
|
| 226 |
liveuser |
1324 |
|
| 3 |
liveuser |
1325 |
#用表來檢測預測的狀態
|
|
|
1326 |
$rCode[]="table(predict(Data_ctree), trainData$".$conf["targetVar"].")";
|
| 226 |
liveuser |
1327 |
|
| 3 |
liveuser |
1328 |
#輸出文字模式的決策樹結果
|
|
|
1329 |
$rCode[]="print(Data_ctree)";
|
| 226 |
liveuser |
1330 |
|
| 3 |
liveuser |
1331 |
#指定等等繪製出來的圖表要儲存在哪邊,寬度與高度為何。
|
| 226 |
liveuser |
1332 |
$rCode[]="svg(filename=\"".$conf["trainDataReportImgPositionAndName"]."\")";
|
|
|
1333 |
|
| 3 |
liveuser |
1334 |
#畫出詳細版的決策樹結果,含預測出來的變數內容為何。
|
|
|
1335 |
$rCode[]="plot(Data_ctree)";
|
| 226 |
liveuser |
1336 |
|
| 3 |
liveuser |
1337 |
#預測測試資料
|
|
|
1338 |
$rCode[]="testPred <- predict(Data_ctree, newdata = testData)";
|
|
|
1339 |
$rCode[]="table(testPred, testData$".$conf["targetVar"].")";
|
| 226 |
liveuser |
1340 |
|
| 3 |
liveuser |
1341 |
#寫入R腳本的內容
|
|
|
1342 |
#涵式說明:
|
|
|
1343 |
#建立R檔案
|
|
|
1344 |
#回傳的結果:
|
|
|
1345 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
|
|
|
1346 |
#$result["error"],錯誤訊息陣列.
|
|
|
1347 |
#$result["newCreatedRfilePathAndName"],R腳本檔的位置與名稱
|
|
|
1348 |
#必填的參數:
|
|
|
1349 |
$conf["R"]["writeRfile"]["addAndName"]=".R/party-".$_SESSION["username"]."-.R";#R檔案的位置與名稱
|
|
|
1350 |
$conf["R"]["writeRfile"]["textToWrite"]=$rCode;#要寫入的字串內容陣列,一個元素代表一行文字,每行結尾會自動換行。
|
|
|
1351 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1352 |
$conf["R"]["writeRfile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1353 |
$writeRfileResult=R::writeRfile($conf["R"]["writeRfile"]);
|
|
|
1354 |
unset($conf["R"]["writeRfile"]);
|
| 226 |
liveuser |
1355 |
|
| 3 |
liveuser |
1356 |
#var_dump($writeRfileResult);
|
| 226 |
liveuser |
1357 |
|
| 3 |
liveuser |
1358 |
#如果 $writeRfileResult["status"] 等於 "false"
|
|
|
1359 |
if($writeRfileResult["status"]=="false"){
|
| 226 |
liveuser |
1360 |
|
| 3 |
liveuser |
1361 |
#設置錯誤識別
|
|
|
1362 |
$result["status"]="false";
|
| 226 |
liveuser |
1363 |
|
| 3 |
liveuser |
1364 |
#設置錯誤訊息
|
|
|
1365 |
$result["error"]=$writeRfileResult;
|
| 226 |
liveuser |
1366 |
|
| 3 |
liveuser |
1367 |
#回傳結果
|
|
|
1368 |
return $result;
|
| 226 |
liveuser |
1369 |
|
| 3 |
liveuser |
1370 |
}#if end
|
| 226 |
liveuser |
1371 |
|
| 3 |
liveuser |
1372 |
#執行 R 腳本
|
|
|
1373 |
#函式說明:
|
|
|
1374 |
#執行R腳本,執行完畢後,會刪除R的腳本與暫存R執行後的輸出的檔案.
|
|
|
1375 |
#回傳的結果:
|
|
|
1376 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1377 |
#$result["errror"],錯誤訊息陣列
|
|
|
1378 |
#$result["lineArray"],字串陣列,R輸出結果,每個元素代表一行的輸出.
|
|
|
1379 |
#$result["lineCount"],整數,R輸出的總共行數.
|
|
|
1380 |
#必填的參數:
|
|
|
1381 |
#$conf["rPositionAndName"],字串,R腳本的位置與名稱.
|
|
|
1382 |
$conf["R"]["executeR"]["rPositionAndName"]=$writeRfileResult["newCreatedRfilePathAndName"];
|
|
|
1383 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1384 |
$conf["R"]["executeR"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1385 |
#可省略的參數:
|
|
|
1386 |
#$conf["disbaleOptimal"],字串,"true"代表取消輸出的優化,可以顯示版本訊息、歡迎訊息、儲存暫存檔,預設為"false"要進行優化.
|
|
|
1387 |
#$conf["R"]["executeR"]["disbaleOptimal"]="true";
|
|
|
1388 |
$executeRresult=R::executeR($conf["R"]["executeR"]);
|
|
|
1389 |
unset($conf["R"]["executeR"]);
|
| 226 |
liveuser |
1390 |
|
| 3 |
liveuser |
1391 |
#如果 $executeRresult["status"] 等於 "false"
|
|
|
1392 |
if($executeRresult["status"]=="false"){
|
| 226 |
liveuser |
1393 |
|
| 3 |
liveuser |
1394 |
#設置錯誤識別
|
|
|
1395 |
$result["status"]="false";
|
| 226 |
liveuser |
1396 |
|
| 3 |
liveuser |
1397 |
#設置錯誤訊息
|
|
|
1398 |
$result["error"]=$executeRresult;
|
| 226 |
liveuser |
1399 |
|
| 3 |
liveuser |
1400 |
#回傳結果
|
|
|
1401 |
return $result;
|
| 226 |
liveuser |
1402 |
|
| 3 |
liveuser |
1403 |
}#if end
|
| 226 |
liveuser |
1404 |
|
| 3 |
liveuser |
1405 |
#如果 $conf["delSampleCsvFile"] 等於 "true"
|
|
|
1406 |
if($conf["delSampleCsvFile"]=="true"){
|
| 226 |
liveuser |
1407 |
|
| 3 |
liveuser |
1408 |
#則要移除樣本csv檔案
|
|
|
1409 |
#涵式說明:
|
|
|
1410 |
#移除檔案
|
|
|
1411 |
#回傳的結果:
|
|
|
1412 |
#$result["status"],"true"代表移除成功,"false"代表移除失敗.
|
|
|
1413 |
#必填的參數:
|
|
|
1414 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1415 |
$conf["fileAccess"]["delFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1416 |
$conf["fileAccess"]["delFile"]["fileAddress"]=$conf["inputCsvFilePosition"];#要移除檔案的位置
|
|
|
1417 |
$eraseSampleCsvResult=fileAccess::delFile($conf["fileAccess"]["delFile"]);
|
|
|
1418 |
unset($conf["fileAccess"]["delFile"]);
|
| 226 |
liveuser |
1419 |
|
| 3 |
liveuser |
1420 |
#如果 $eraseSampleCsvResult["status"] 等於 "false"
|
|
|
1421 |
if($eraseSampleCsvResult["status"]=="false"){
|
| 226 |
liveuser |
1422 |
|
| 3 |
liveuser |
1423 |
#設置錯誤識別
|
|
|
1424 |
$result["status"]="false";
|
| 226 |
liveuser |
1425 |
|
| 3 |
liveuser |
1426 |
#設置錯誤訊息
|
|
|
1427 |
$result["error"]=$eraseSampleCsvResult;
|
| 226 |
liveuser |
1428 |
|
| 3 |
liveuser |
1429 |
#回傳結果
|
|
|
1430 |
return $result;
|
| 226 |
liveuser |
1431 |
|
| 3 |
liveuser |
1432 |
}#if end
|
| 226 |
liveuser |
1433 |
|
|
|
1434 |
}#if end
|
|
|
1435 |
|
| 3 |
liveuser |
1436 |
#取得 R 的執行結果
|
|
|
1437 |
$result["lineArray"]=$executeRresult["lineArray"];
|
| 226 |
liveuser |
1438 |
|
| 3 |
liveuser |
1439 |
#取得 R 的執行結果行數
|
|
|
1440 |
$result["lineCount"]=$executeRresult["lineCount"];
|
| 226 |
liveuser |
1441 |
|
| 3 |
liveuser |
1442 |
#取得圖表的位置
|
|
|
1443 |
$result["img"]=$conf["trainDataReportImgPositionAndName"];
|
| 226 |
liveuser |
1444 |
|
| 3 |
liveuser |
1445 |
#放置圖表的語法
|
|
|
1446 |
#函數說明:
|
|
|
1447 |
#用data:mimeType;base64,imgVar的形式來提供圖片的連結,亦即圖片儲存在變數裡面,本函式包含顯示圖片的語法.
|
|
|
1448 |
#回傳結果:
|
|
|
1449 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1450 |
#$result["error"],錯誤訊息
|
|
|
1451 |
#$result["content"],圖片的連結資訊
|
| 226 |
liveuser |
1452 |
#$result["function"],當前執行的函數名稱
|
| 3 |
liveuser |
1453 |
#必填參數:
|
|
|
1454 |
#$conf["imgPosition"],要轉存成2元碼的圖片檔案位置與名稱
|
|
|
1455 |
$conf["img::data"]["imgPosition"]=$conf["trainDataReportImgPositionAndName"];
|
|
|
1456 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1457 |
$conf["img::data"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1458 |
#可省略參數:
|
|
|
1459 |
#$conf["alt"],若沒有圖片要用什麼文字顯示。
|
|
|
1460 |
#$conf["alt"]="";
|
|
|
1461 |
#$conf["style"],字串陣列,要使用的style,key為樣式名稱,value為樣式值.
|
|
|
1462 |
$conf["img::data"]["style"]=array("width"=>"100%");
|
|
|
1463 |
#$conf["class"],圖片要套用的css樣式名稱.
|
|
|
1464 |
#$conf["class"]="";
|
|
|
1465 |
#$conf["mimeType"],2元碼的內容是什麼,預設為"image/*".
|
|
|
1466 |
$conf["img::data"]["mimeType"]="image/svg+xml";
|
|
|
1467 |
#$conf["compressType"],2元碼壓縮的方式,預設為"base64".
|
|
|
1468 |
#$conf["compressType"]="base64";
|
|
|
1469 |
#$conf["delImg"],讀取完圖片檔案後,要移除圖片嗎?"true"代表要移除,"false"代表不要移除,預設為"false".
|
|
|
1470 |
#$conf["delImg"]="false";
|
|
|
1471 |
#參考資料:
|
|
|
1472 |
#將檔案用字串變數儲存起來=>http://php.net/manual/en/function.file-get-contents.php
|
|
|
1473 |
#壓縮2元碼=>http://php.net/manual/en/function.base64-encode.php
|
|
|
1474 |
$data=img::data($conf["img::data"]);
|
|
|
1475 |
unset($conf["img::data"]);
|
| 226 |
liveuser |
1476 |
|
| 3 |
liveuser |
1477 |
#如果顯示圖片失敗
|
|
|
1478 |
if($data["status"]=="false"){
|
| 226 |
liveuser |
1479 |
|
| 3 |
liveuser |
1480 |
#設置執行失敗
|
|
|
1481 |
$result["status"]="false";
|
| 226 |
liveuser |
1482 |
|
| 3 |
liveuser |
1483 |
#設置執行錯誤訊息
|
|
|
1484 |
$result["error"]=$data;
|
| 226 |
liveuser |
1485 |
|
| 3 |
liveuser |
1486 |
#回傳結果
|
|
|
1487 |
return $result;
|
| 226 |
liveuser |
1488 |
|
| 3 |
liveuser |
1489 |
}#if end
|
| 226 |
liveuser |
1490 |
|
| 3 |
liveuser |
1491 |
#放置圖表的語法
|
|
|
1492 |
$result["content"]=$data["content"];
|
| 226 |
liveuser |
1493 |
|
| 3 |
liveuser |
1494 |
#執行到這邊代表執行正常
|
|
|
1495 |
$result["status"]="true";
|
| 226 |
liveuser |
1496 |
|
| 3 |
liveuser |
1497 |
#回傳結果
|
|
|
1498 |
return $result;
|
| 226 |
liveuser |
1499 |
|
| 3 |
liveuser |
1500 |
}#function DecisionTreeWithPackageParty end
|
| 226 |
liveuser |
1501 |
|
| 3 |
liveuser |
1502 |
/*
|
|
|
1503 |
#函式說明:
|
|
|
1504 |
#依據樣本內容進行選項內容次數的統計
|
|
|
1505 |
#回傳結果:
|
|
|
1506 |
#$result["status"],執行正常與否,"true"代表正常;"false"代表不正常.
|
|
|
1507 |
#$result["error"],錯誤訊息陣列
|
|
|
1508 |
#$result["function"],當前函數名稱
|
|
|
1509 |
#$result["content"],回傳的內容
|
|
|
1510 |
#$result["content"][$i]["title"],第$+1個欄位的題目。
|
|
|
1511 |
#$result["content"][$i][$j]["optionValue"],第$+1個欄位的第$j+1個選項的內容。
|
|
|
1512 |
#$result["content"][$i][$j]["optionCount"],第$+1個欄位的第$j+1個選項的出現頻率。
|
|
|
1513 |
#$result["content"][$i][$j]["optionPercent"],第$+1個欄位的第$j+1個選項的出現次數所佔全部選項的百分比。
|
|
|
1514 |
#$result["content"]["questCount"],題目計數
|
|
|
1515 |
#必填參數:
|
|
|
1516 |
#$conf["csvFileAddress"],字串,csv檔的位置與名稱
|
|
|
1517 |
$conf["csvFileAddress"]=".csv";
|
|
|
1518 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1519 |
$conf["fileArgu"]=__FILE__;
|
|
|
1520 |
#可省略參數:
|
|
|
1521 |
#參考資料:
|
|
|
1522 |
#R的敘述統計=>http://netstat.stat.tku.edu.tw/desc.php
|
|
|
1523 |
#備註:
|
|
|
1524 |
#目前欄位中文名稱讀出來會變成亂碼,因此建議交由php讀檔時就取得其欄位中文名稱
|
|
|
1525 |
*/
|
|
|
1526 |
public static function describedStatistic(&$conf){
|
| 226 |
liveuser |
1527 |
|
| 3 |
liveuser |
1528 |
#初始化要回傳的結果
|
|
|
1529 |
$result=array();
|
| 226 |
liveuser |
1530 |
|
| 3 |
liveuser |
1531 |
#取得當前執行函數名稱
|
|
|
1532 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
1533 |
|
| 3 |
liveuser |
1534 |
#如果 $conf 不為陣列
|
|
|
1535 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1536 |
|
| 3 |
liveuser |
1537 |
#設置執行失敗
|
|
|
1538 |
$result["status"]="false";
|
| 226 |
liveuser |
1539 |
|
| 3 |
liveuser |
1540 |
#設置執行錯誤訊息
|
|
|
1541 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1542 |
|
|
|
1543 |
#如果傳入的參數為 null
|
|
|
1544 |
if($conf==null){
|
| 226 |
liveuser |
1545 |
|
| 3 |
liveuser |
1546 |
#設置執行錯誤訊息
|
|
|
1547 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1548 |
|
| 3 |
liveuser |
1549 |
}#if end
|
|
|
1550 |
|
|
|
1551 |
#回傳結果
|
|
|
1552 |
return $result;
|
| 226 |
liveuser |
1553 |
|
| 3 |
liveuser |
1554 |
}#if end
|
| 226 |
liveuser |
1555 |
|
| 3 |
liveuser |
1556 |
#檢查參數
|
|
|
1557 |
#涵式說明:
|
|
|
1558 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
1559 |
#回傳的結果:
|
|
|
1560 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1561 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1562 |
#$result["function"],當前執行的函式名稱.
|
|
|
1563 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1564 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1565 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1566 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1567 |
#必填寫的參數:
|
|
|
1568 |
$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
1569 |
$conf["variableCheck.isexistMulti"]["variableCheck"]=array("csvFileAddress","fileArgu");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
1570 |
#可以省略的參數:
|
| 226 |
liveuser |
1571 |
$conf["variableCheck.isexistMulti"]["variableType"]=array("string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
1572 |
$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
1573 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
|
| 226 |
liveuser |
1574 |
unset($conf["variableCheck.isexistMulti"]);
|
|
|
1575 |
|
| 3 |
liveuser |
1576 |
#如果檢查失敗
|
|
|
1577 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
1578 |
|
| 3 |
liveuser |
1579 |
#設置執行失敗
|
|
|
1580 |
$result["status"]="false";
|
| 226 |
liveuser |
1581 |
|
| 3 |
liveuser |
1582 |
#設置執行錯誤
|
|
|
1583 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1584 |
|
| 3 |
liveuser |
1585 |
#回傳結果
|
|
|
1586 |
return $result;
|
| 226 |
liveuser |
1587 |
|
| 3 |
liveuser |
1588 |
}#if end
|
| 226 |
liveuser |
1589 |
|
| 3 |
liveuser |
1590 |
#如果檢查失敗
|
|
|
1591 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
1592 |
|
| 3 |
liveuser |
1593 |
#設置執行失敗
|
|
|
1594 |
$result["status"]="false";
|
| 226 |
liveuser |
1595 |
|
| 3 |
liveuser |
1596 |
#設置執行錯誤
|
|
|
1597 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1598 |
|
| 3 |
liveuser |
1599 |
#回傳結果
|
|
|
1600 |
return $result;
|
| 226 |
liveuser |
1601 |
|
| 3 |
liveuser |
1602 |
}#if end
|
| 226 |
liveuser |
1603 |
|
| 3 |
liveuser |
1604 |
#檢查csv檔案是否存在
|
|
|
1605 |
#涵式說明:檢查多個檔案與資料夾是否存在.
|
|
|
1606 |
#回傳的結果:
|
|
|
1607 |
#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
|
|
|
1608 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
1609 |
#必填的參數:
|
|
|
1610 |
$conf["fileAccess.checkMultiFileExist"]["fileArray"]=array($conf["csvFileAddress"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
1611 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1612 |
$conf["fileAccess.checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1613 |
#參考資料來源:
|
|
|
1614 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
1615 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
1616 |
$checkResult=fileAccess::checkMultiFileExist($conf["fileAccess.checkMultiFileExist"]);
|
|
|
1617 |
unset($conf["fileAccess.checkMultiFileExist"]);
|
| 226 |
liveuser |
1618 |
|
| 3 |
liveuser |
1619 |
#如果檢查失敗
|
|
|
1620 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
1621 |
|
| 3 |
liveuser |
1622 |
#設置執行失敗
|
|
|
1623 |
$result["status"]="false";
|
| 226 |
liveuser |
1624 |
|
| 3 |
liveuser |
1625 |
#設置執行錯誤
|
|
|
1626 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1627 |
|
| 3 |
liveuser |
1628 |
#回傳結果
|
|
|
1629 |
return $result;
|
| 226 |
liveuser |
1630 |
|
| 3 |
liveuser |
1631 |
}#if end
|
| 226 |
liveuser |
1632 |
|
| 3 |
liveuser |
1633 |
#如果檢查失敗
|
|
|
1634 |
if($checkResult["varExist"][0]=="false"){
|
| 226 |
liveuser |
1635 |
|
| 3 |
liveuser |
1636 |
#設置執行失敗
|
|
|
1637 |
$result["status"]="false";
|
| 226 |
liveuser |
1638 |
|
| 3 |
liveuser |
1639 |
#設置執行錯誤
|
|
|
1640 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1641 |
|
| 3 |
liveuser |
1642 |
#回傳結果
|
|
|
1643 |
return $result;
|
| 226 |
liveuser |
1644 |
|
| 3 |
liveuser |
1645 |
}#if end
|
| 226 |
liveuser |
1646 |
|
| 3 |
liveuser |
1647 |
#讀取csv檔案的內容
|
|
|
1648 |
#回傳得結果:
|
|
|
1649 |
#$result["status"],執行是否正常,"true"代表正常;"false"代表不正常.
|
|
|
1650 |
#$result["error"],錯誤訊息陣列.
|
|
|
1651 |
#$result["function"],當前執行的函數名稱.
|
|
|
1652 |
#$result["csvFileContent"],csv檔案內容的陣列.
|
|
|
1653 |
#$result["csvFileContent"]["$i"]["$j"]代表第$i+1列第$j+1欄位的內容.
|
|
|
1654 |
#如果 $conf["firstLineVarName"]爲"true"的話則會多回傳 $result["csvFileContent"]["第幾列"]["第一列各個欄位的名稱"]
|
|
|
1655 |
#$result["lineArray"],csv檔案逐列內容的陣列.
|
|
|
1656 |
#$result["lineArrayCount"],總共幾列資料.
|
|
|
1657 |
#必填的參數:
|
|
|
1658 |
$conf["csv.loadCsvFile"]["csvFilePositionAndName"]=$conf["csvFileAddress"];#csv檔案的位置
|
|
|
1659 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1660 |
$conf["csv.loadCsvFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1661 |
#可省略的參數:
|
|
|
1662 |
$conf["csv.loadCsvFile"]["firstLineVarName"]="false";#第一行是否爲變數名稱(各個欄位的名稱)
|
|
|
1663 |
#參考資料來源:
|
|
|
1664 |
#http://www.php.net/manual/en/function.str-split.php
|
|
|
1665 |
#參考資料來源
|
|
|
1666 |
#http://chuangmaster.pixnet.net/blog/post/33560606-%5B%E8%BD%89%E8%B2%BC%5D%E9%97%9C%E6%96%BC%E5%9B%9E%E8%BB%8A(%5Cr)%E8%88%87%E6%8F%9B%E8%A1%8C(%5Cn)
|
|
|
1667 |
$readCsvResult=csv::loadCsvFile($conf["csv.loadCsvFile"]);
|
|
|
1668 |
unset($conf["csv.loadCsvFile"]);
|
| 226 |
liveuser |
1669 |
|
| 3 |
liveuser |
1670 |
#var_dump($readCsvResult);
|
| 226 |
liveuser |
1671 |
|
| 3 |
liveuser |
1672 |
#如果 $readCsvResult["status"] 等於 "false"
|
|
|
1673 |
if($readCsvResult["status"]=="false"){
|
| 226 |
liveuser |
1674 |
|
| 3 |
liveuser |
1675 |
#設置執行失敗
|
|
|
1676 |
$result["status"]="false";
|
| 226 |
liveuser |
1677 |
|
| 3 |
liveuser |
1678 |
#設置執行錯誤
|
|
|
1679 |
$result["error"]=$readCsvResult;
|
| 226 |
liveuser |
1680 |
|
| 3 |
liveuser |
1681 |
#回傳結果
|
|
|
1682 |
return $result;
|
| 226 |
liveuser |
1683 |
|
| 3 |
liveuser |
1684 |
}#if end
|
| 226 |
liveuser |
1685 |
|
| 3 |
liveuser |
1686 |
#宣告儲存csv檔標題欄名稱的陣列
|
|
|
1687 |
$columnNameList=array();
|
| 226 |
liveuser |
1688 |
|
| 3 |
liveuser |
1689 |
#迴圈從i等等於1到不小於count($readCsvResult["csvFileContent"][0])為止
|
|
|
1690 |
#亦即第二欄到最後一欄
|
|
|
1691 |
for($i=1;$i<count($readCsvResult["csvFileContent"][0]);$i++){
|
| 226 |
liveuser |
1692 |
|
| 3 |
liveuser |
1693 |
#紀錄第$i+1欄的欄位名稱
|
|
|
1694 |
$columnNameList[]=$readCsvResult["csvFileContent"][0][$i];
|
| 226 |
liveuser |
1695 |
|
| 3 |
liveuser |
1696 |
}#for end
|
| 226 |
liveuser |
1697 |
|
| 3 |
liveuser |
1698 |
#初始化要寫入到R腳本的逐行內容
|
|
|
1699 |
$dataToWrite=array();
|
| 226 |
liveuser |
1700 |
|
| 3 |
liveuser |
1701 |
#讀取 $conf["csvFileAddress"] 檔案,進行敘述性統計
|
|
|
1702 |
$dataToWrite[]="data=read.csv(file=\"".$conf["csvFileAddress"]."\",header=TRUE)";
|
| 226 |
liveuser |
1703 |
|
| 3 |
liveuser |
1704 |
#取得csv檔有幾欄內容
|
|
|
1705 |
$dataToWrite[]="columnCount=dim(data)[2]";
|
| 226 |
liveuser |
1706 |
|
| 3 |
liveuser |
1707 |
#迴圈開始,執行第2欄到第 columnCount 欄
|
|
|
1708 |
$dataToWrite[]="for(i in 2:columnCount){";
|
| 226 |
liveuser |
1709 |
|
| 3 |
liveuser |
1710 |
#迴圈內容
|
|
|
1711 |
#對第i欄進行敘述行統計
|
|
|
1712 |
#印出來
|
|
|
1713 |
$dataToWrite[]="write.table(table(data[i]),sep=\",\")";
|
| 226 |
liveuser |
1714 |
|
| 3 |
liveuser |
1715 |
#迴圈結束
|
|
|
1716 |
$dataToWrite[]="}";
|
| 226 |
liveuser |
1717 |
|
| 3 |
liveuser |
1718 |
#涵式說明:
|
|
|
1719 |
#建立R檔案
|
|
|
1720 |
#回傳的結果:
|
|
|
1721 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
|
|
|
1722 |
#$result["error"],錯誤訊息陣列.
|
|
|
1723 |
#$result["newCreatedRfilePathAndName"],R腳本檔的位置與名稱
|
|
|
1724 |
#必填的參數:
|
|
|
1725 |
$conf["R.writeRfile"]["addAndName"]=".R/".$_SESSION["username"]."-describedStatistic.R";#R檔案的位置與名稱
|
|
|
1726 |
$conf["R.writeRfile"]["textToWrite"]=$dataToWrite;#要寫入的字串內容陣列,一個元素代表一行文字,每行結尾會自動換行。
|
|
|
1727 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1728 |
$conf["R.writeRfile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1729 |
$createRscriptResult=R::writeRfile($conf["R.writeRfile"]);
|
|
|
1730 |
unset($conf["R.writeRfile"]);
|
| 226 |
liveuser |
1731 |
|
| 3 |
liveuser |
1732 |
#如果建立 R腳本 失敗
|
|
|
1733 |
if($createRscriptResult["status"]=="false"){
|
| 226 |
liveuser |
1734 |
|
| 3 |
liveuser |
1735 |
#設置執行失敗
|
|
|
1736 |
$result["status"]="false";
|
| 226 |
liveuser |
1737 |
|
| 3 |
liveuser |
1738 |
#設置執行錯誤
|
|
|
1739 |
$result["error"]=$createRscriptResult;
|
| 226 |
liveuser |
1740 |
|
| 3 |
liveuser |
1741 |
#回傳結果
|
|
|
1742 |
return $result;
|
| 226 |
liveuser |
1743 |
|
| 3 |
liveuser |
1744 |
}#if end
|
| 226 |
liveuser |
1745 |
|
| 3 |
liveuser |
1746 |
#函式說明:
|
|
|
1747 |
#執行R腳本,執行完畢後,會刪除R的腳本與暫存R執行後的輸出的檔案.
|
|
|
1748 |
#回傳的結果:
|
|
|
1749 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1750 |
#$result["errror"],錯誤訊息陣列
|
|
|
1751 |
#$result["lineArray"],字串陣列,R輸出結果,每個元素代表一行的輸出.
|
|
|
1752 |
#$result["lineCount"],整數,R輸出的總共行數.
|
|
|
1753 |
#必填的參數:
|
|
|
1754 |
#$conf["R.executeR"]["rPositionAndName"],字串,R腳本的位置與名稱.
|
|
|
1755 |
$conf["R.executeR"]["rPositionAndName"]=$createRscriptResult["newCreatedRfilePathAndName"];
|
|
|
1756 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
1757 |
$conf["R.executeR"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1758 |
#可省略的參數:
|
|
|
1759 |
#$conf["R.executeR"]["disbaleOptimal"],字串,"true"代表取消輸出的優化,可以顯示版本訊息、歡迎訊息、儲存暫存檔,預設為"false"要進行優化.
|
|
|
1760 |
#$conf["R.executeR"]["disbaleOptimal"]="true";
|
|
|
1761 |
$excuteRscriptResult=R::executeR($conf["R.executeR"]);
|
|
|
1762 |
unset($conf["R.executeR"]);
|
| 226 |
liveuser |
1763 |
|
| 3 |
liveuser |
1764 |
#如果執行 R腳本 失敗
|
|
|
1765 |
if($excuteRscriptResult["status"]=="false"){
|
| 226 |
liveuser |
1766 |
|
| 3 |
liveuser |
1767 |
#設置執行失敗
|
|
|
1768 |
$result["status"]="false";
|
| 226 |
liveuser |
1769 |
|
| 3 |
liveuser |
1770 |
#設置執行錯誤
|
|
|
1771 |
$result["error"]=$excuteRscriptResult;
|
| 226 |
liveuser |
1772 |
|
| 3 |
liveuser |
1773 |
#回傳結果
|
|
|
1774 |
return $result;
|
| 226 |
liveuser |
1775 |
|
| 3 |
liveuser |
1776 |
}#if end
|
| 226 |
liveuser |
1777 |
|
| 3 |
liveuser |
1778 |
#debug
|
|
|
1779 |
#var_dump($excuteRscriptResult);
|
| 226 |
liveuser |
1780 |
|
| 3 |
liveuser |
1781 |
#宣告識別要開始抓取內容的旗標變數
|
|
|
1782 |
$columnStatisticData=array();
|
| 226 |
liveuser |
1783 |
|
| 3 |
liveuser |
1784 |
#初始化欄位計數
|
|
|
1785 |
$columnCount=-1;
|
| 226 |
liveuser |
1786 |
|
| 3 |
liveuser |
1787 |
#初始化選項計數
|
| 226 |
liveuser |
1788 |
$optionCount=1;
|
|
|
1789 |
|
| 3 |
liveuser |
1790 |
#解析從R取得的結果
|
|
|
1791 |
for($i=5;$i<count($excuteRscriptResult["lineArray"]);$i++){
|
| 226 |
liveuser |
1792 |
|
| 3 |
liveuser |
1793 |
#如果讀到 ""Var1","Freq""
|
|
|
1794 |
if($excuteRscriptResult["lineArray"][$i]=="\"Var1\",\"Freq\""){
|
| 226 |
liveuser |
1795 |
|
| 3 |
liveuser |
1796 |
#欄位計數加1
|
|
|
1797 |
$columnCount++;
|
| 226 |
liveuser |
1798 |
|
| 3 |
liveuser |
1799 |
#初始化選項計數
|
|
|
1800 |
$optionCount=1;
|
| 226 |
liveuser |
1801 |
|
| 3 |
liveuser |
1802 |
#跳過該次迴圈
|
|
|
1803 |
continue;
|
| 226 |
liveuser |
1804 |
|
| 3 |
liveuser |
1805 |
}#if end
|
| 226 |
liveuser |
1806 |
|
| 3 |
liveuser |
1807 |
#如果讀到 "Freq"
|
|
|
1808 |
if($excuteRscriptResult["lineArray"][$i]=="\"Freq\""){
|
| 226 |
liveuser |
1809 |
|
| 3 |
liveuser |
1810 |
#欄位計數加1
|
|
|
1811 |
$columnCount++;
|
| 226 |
liveuser |
1812 |
|
| 3 |
liveuser |
1813 |
#初始化選項計數
|
|
|
1814 |
$optionCount=1;
|
| 226 |
liveuser |
1815 |
|
| 3 |
liveuser |
1816 |
#跳過該次迴圈
|
|
|
1817 |
continue;
|
| 226 |
liveuser |
1818 |
|
| 3 |
liveuser |
1819 |
}#if end
|
| 226 |
liveuser |
1820 |
|
| 3 |
liveuser |
1821 |
#取得題目
|
|
|
1822 |
$columnStatisticData[$columnCount]["title"]=$columnNameList[$columnCount];
|
| 226 |
liveuser |
1823 |
|
|
|
1824 |
#取得要解析的字串
|
| 3 |
liveuser |
1825 |
$dataNeedToFilted=$excuteRscriptResult["lineArray"][$i];
|
| 226 |
liveuser |
1826 |
|
| 3 |
liveuser |
1827 |
#debug
|
|
|
1828 |
#var_dump($dataNeedToFilted);
|
| 226 |
liveuser |
1829 |
|
| 3 |
liveuser |
1830 |
#涵式說明:
|
|
|
1831 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
1832 |
#回傳的參數:
|
|
|
1833 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1834 |
#$result["error"],錯誤訊息陣列
|
|
|
1835 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
1836 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
1837 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
1838 |
#必填的參數:
|
|
|
1839 |
$conf["stringProcess.spiltString"]["stringIn"]=$dataNeedToFilted;#要處理的字串。
|
|
|
1840 |
$conf["stringProcess.spiltString"]["spiltSymbol"]=",";#爲以哪個符號作爲分割
|
|
|
1841 |
$spiltedStr=stringProcess::spiltString($conf["stringProcess.spiltString"]);
|
|
|
1842 |
unset($conf["stringProcess.spiltString"]);
|
| 226 |
liveuser |
1843 |
|
| 3 |
liveuser |
1844 |
#debug
|
|
|
1845 |
#var_dump($spiltedStr);
|
| 226 |
liveuser |
1846 |
|
| 3 |
liveuser |
1847 |
#若 $spiltedStr["status"] 等於 "false"
|
|
|
1848 |
if($spiltedStr["status"]=="false"){
|
| 226 |
liveuser |
1849 |
|
| 3 |
liveuser |
1850 |
#設置執行失敗
|
|
|
1851 |
$result["status"]="false";
|
| 226 |
liveuser |
1852 |
|
| 3 |
liveuser |
1853 |
#設置執行錯誤
|
|
|
1854 |
$result["error"]=$spiltedStr;
|
| 226 |
liveuser |
1855 |
|
| 3 |
liveuser |
1856 |
#回傳結果
|
|
|
1857 |
return $result;
|
| 226 |
liveuser |
1858 |
|
| 3 |
liveuser |
1859 |
}#if end
|
| 226 |
liveuser |
1860 |
|
| 3 |
liveuser |
1861 |
#如果 $spiltedStr["dataCounts"]<=1
|
|
|
1862 |
if($spiltedStr["dataCounts"]<=1){
|
| 226 |
liveuser |
1863 |
|
| 3 |
liveuser |
1864 |
#欄位計數加1
|
|
|
1865 |
#$columnCount++;
|
| 226 |
liveuser |
1866 |
|
| 3 |
liveuser |
1867 |
#跳過該次迴圈
|
|
|
1868 |
continue;
|
| 226 |
liveuser |
1869 |
|
| 3 |
liveuser |
1870 |
}#if end
|
| 226 |
liveuser |
1871 |
|
| 3 |
liveuser |
1872 |
#處理選項名稱不必要的內容
|
|
|
1873 |
#涵式說明:
|
|
|
1874 |
#處理字串避免網頁出錯
|
|
|
1875 |
#回傳的結果:
|
|
|
1876 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1877 |
#$result["function"],當前執行的函數.
|
|
|
1878 |
#$result["content"],爲處理好的字串.
|
|
|
1879 |
#$result["error"],錯誤訊息陣列.
|
|
|
1880 |
#必填的參數:
|
|
|
1881 |
$conf["stringProcess.correctCharacter"]["stringIn"]=$spiltedStr["dataArray"][1];#爲要處理的字串
|
|
|
1882 |
#可省略的參數:
|
|
|
1883 |
$conf["stringProcess.correctCharacter"]["selectedCharacter"]=array("\"");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
1884 |
#若不設定則預設爲要將這些字串作替換("<",">","=","//","'","$","%","&","|","/*","*\/","#","\"")。
|
|
|
1885 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
1886 |
$conf["stringProcess.correctCharacter"]["changeTo"]=array("");#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
1887 |
$spiltedStr["dataArray"][1]=stringProcess::correctCharacter($conf["stringProcess.correctCharacter"]);
|
|
|
1888 |
unset($conf["stringProcess.correctCharacter"]);
|
| 226 |
liveuser |
1889 |
|
| 3 |
liveuser |
1890 |
#如果修正內容失敗
|
|
|
1891 |
if($spiltedStr["dataArray"][1]["status"]=="false"){
|
| 226 |
liveuser |
1892 |
|
| 3 |
liveuser |
1893 |
#設置執行失敗
|
|
|
1894 |
$result["status"]="false";
|
| 226 |
liveuser |
1895 |
|
| 3 |
liveuser |
1896 |
#設置執行錯誤
|
|
|
1897 |
$result["error"]=$spiltedStr["dataArray"][1];
|
| 226 |
liveuser |
1898 |
|
| 3 |
liveuser |
1899 |
#回傳結果
|
|
|
1900 |
return $result;
|
| 226 |
liveuser |
1901 |
|
| 3 |
liveuser |
1902 |
}#if end
|
| 226 |
liveuser |
1903 |
|
| 3 |
liveuser |
1904 |
#如果選項爲 $spiltedStr["dataArray"][1]["content"] 等於 ""
|
|
|
1905 |
if($spiltedStr["dataArray"][1]["content"]==""){
|
| 226 |
liveuser |
1906 |
|
| 3 |
liveuser |
1907 |
#設爲空值
|
|
|
1908 |
$spiltedStr["dataArray"][1]["content"]="空值";
|
| 226 |
liveuser |
1909 |
|
| 3 |
liveuser |
1910 |
}#if end
|
| 226 |
liveuser |
1911 |
|
| 3 |
liveuser |
1912 |
#處理選項名稱不必要的內容
|
|
|
1913 |
#涵式說明:
|
|
|
1914 |
#處理字串避免網頁出錯
|
|
|
1915 |
#回傳的結果:
|
|
|
1916 |
#$result,爲處理好的字串。
|
|
|
1917 |
#必填的參數:
|
|
|
1918 |
$conf["stringProcess.correctCharacter"]["stringIn"]=$spiltedStr["dataArray"][2];#爲要處理的字串
|
|
|
1919 |
#可省略的參數:
|
|
|
1920 |
$conf["stringProcess.correctCharacter"]["selectedCharacter"]=array("\"");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
1921 |
#若不設定則預設爲要將這些字串作替換("<",">","=","//","'","$","%","&","|","/*","*\/","#","\"")。
|
|
|
1922 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
1923 |
$conf["stringProcess.correctCharacter"]["changeTo"]=array("");#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
1924 |
$spiltedStr["dataArray"][2]=stringProcess::correctCharacter($conf["stringProcess.correctCharacter"]);
|
|
|
1925 |
unset($conf["stringProcess.correctCharacter"]);
|
| 226 |
liveuser |
1926 |
|
| 3 |
liveuser |
1927 |
#如果修正內容失敗
|
|
|
1928 |
if($spiltedStr["dataArray"][2]["status"]=="false"){
|
| 226 |
liveuser |
1929 |
|
| 3 |
liveuser |
1930 |
#設置執行失敗
|
|
|
1931 |
$result["status"]="false";
|
| 226 |
liveuser |
1932 |
|
| 3 |
liveuser |
1933 |
#設置執行錯誤
|
|
|
1934 |
$result["error"]=$spiltedStr["dataArray"][2];
|
| 226 |
liveuser |
1935 |
|
| 3 |
liveuser |
1936 |
#回傳結果
|
|
|
1937 |
return $result;
|
| 226 |
liveuser |
1938 |
|
| 3 |
liveuser |
1939 |
}#if end
|
| 226 |
liveuser |
1940 |
|
| 3 |
liveuser |
1941 |
#以整數key紀錄選項名稱
|
|
|
1942 |
$columnStatisticData[$columnCount][$optionCount]["optionValue"]=$spiltedStr["dataArray"][1]["content"];
|
| 226 |
liveuser |
1943 |
|
| 3 |
liveuser |
1944 |
#以整數key紀錄選項頻率
|
|
|
1945 |
$columnStatisticData[$columnCount][$optionCount]["optionCount"]=$spiltedStr["dataArray"][2]["content"];
|
| 226 |
liveuser |
1946 |
|
| 3 |
liveuser |
1947 |
#選項計數加1
|
|
|
1948 |
$optionCount++;
|
| 226 |
liveuser |
1949 |
|
| 3 |
liveuser |
1950 |
#debug
|
|
|
1951 |
#var_dump($columnStatisticData[$columnCount]);
|
| 226 |
liveuser |
1952 |
|
| 3 |
liveuser |
1953 |
#排序含有選項名稱與頻率的二維陣列
|
|
|
1954 |
#函數說明:
|
|
|
1955 |
#排序含有多資訊的二維陣列
|
|
|
1956 |
#回傳結果:
|
|
|
1957 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1958 |
#$result["function"],當前執行的function名稱
|
|
|
1959 |
#$result["error"],錯誤訊息陣列.
|
|
|
1960 |
#$result["content"],處理好的字串.
|
|
|
1961 |
#必填參數:
|
|
|
1962 |
#$conf["arrays.arrangeTwoDmensionArray"]["unArrangeArray"],參考二維陣列,要的排序二維陣列。
|
|
|
1963 |
$conf["arrays.arrangeTwoDmensionArray"]["unArrangeArray"]=&$columnStatisticData[$columnCount];
|
|
|
1964 |
#$conf["arrays.arrangeTwoDmensionArray"]["compareKey"],字串,儲存用來比較大小的一維陣列key名稱。
|
|
|
1965 |
$conf["arrays.arrangeTwoDmensionArray"]["compareKey"]="optionCount";
|
|
|
1966 |
#可省參數:
|
|
|
1967 |
#$conf["arrays.arrangeTwoDmensionArray"]["type"],字串,排序的類型,"asc"代表遞增,"desc"代表遞減,預設為"desc"。
|
|
|
1968 |
$conf["arrays.arrangeTwoDmensionArray"]["type"]="desc";
|
|
|
1969 |
$arrangedResult=arrays::arrangeTwoDmensionArray($conf["arrays.arrangeTwoDmensionArray"]);
|
|
|
1970 |
unset($conf["arrays.arrangeTwoDmensionArray"]);
|
| 226 |
liveuser |
1971 |
|
| 3 |
liveuser |
1972 |
#如果排序失敗
|
|
|
1973 |
if($arrangedResult["status"]=="false"){
|
| 226 |
liveuser |
1974 |
|
| 3 |
liveuser |
1975 |
#設置執行失敗
|
|
|
1976 |
$result["status"]="false";
|
| 226 |
liveuser |
1977 |
|
| 3 |
liveuser |
1978 |
#設置執行錯誤
|
|
|
1979 |
$result["error"]=$arrangedResult;
|
| 226 |
liveuser |
1980 |
|
| 3 |
liveuser |
1981 |
#回傳結果
|
|
|
1982 |
return $result;
|
| 226 |
liveuser |
1983 |
|
| 3 |
liveuser |
1984 |
}#if end
|
| 226 |
liveuser |
1985 |
|
| 3 |
liveuser |
1986 |
}#for end
|
| 226 |
liveuser |
1987 |
|
| 3 |
liveuser |
1988 |
#debug
|
| 226 |
liveuser |
1989 |
#var_dump(count($columnStatisticData));
|
|
|
1990 |
|
|
|
1991 |
#計算每個題目各選項所佔的百分比
|
| 3 |
liveuser |
1992 |
for($i=0;$i<count($columnStatisticData);$i++){
|
| 226 |
liveuser |
1993 |
|
| 3 |
liveuser |
1994 |
#初始化總共的選項填達次數
|
|
|
1995 |
$total=0;
|
| 226 |
liveuser |
1996 |
|
| 3 |
liveuser |
1997 |
#如果該題有填答的記錄
|
|
|
1998 |
if(isset($columnStatisticData[$i])){
|
| 226 |
liveuser |
1999 |
|
| 3 |
liveuser |
2000 |
#有幾個選項就執行幾次
|
|
|
2001 |
#-1是因爲title的關係
|
|
|
2002 |
for($j=1;$j<=count($columnStatisticData[$i])-1;$j++){
|
| 226 |
liveuser |
2003 |
|
| 3 |
liveuser |
2004 |
#如果 $columnStatisticData[$i][$j]["optionValue"] 不等於 "空值"
|
|
|
2005 |
if($columnStatisticData[$i][$j]["optionValue"]!="空值"){
|
| 226 |
liveuser |
2006 |
|
| 3 |
liveuser |
2007 |
#加總填達次數
|
|
|
2008 |
$total=$total+$columnStatisticData[$i][$j]["optionCount"];
|
| 226 |
liveuser |
2009 |
|
| 3 |
liveuser |
2010 |
}#if end
|
| 226 |
liveuser |
2011 |
|
| 3 |
liveuser |
2012 |
}#for end
|
| 226 |
liveuser |
2013 |
|
| 3 |
liveuser |
2014 |
#有幾個選項就執行幾次
|
|
|
2015 |
for($j=1;$j<count($columnStatisticData[$i]);$j++){
|
| 226 |
liveuser |
2016 |
|
| 3 |
liveuser |
2017 |
#如果 $columnStatisticData[$i][$j]["optionValue"] 不等於 "空值"
|
|
|
2018 |
if($columnStatisticData[$i][$j]["optionValue"]!="空值"){
|
| 226 |
liveuser |
2019 |
|
| 3 |
liveuser |
2020 |
#取得選項的填達比率
|
|
|
2021 |
$columnStatisticData[$i][$j]["optionPercent"]=$columnStatisticData[$i][$j]["optionCount"]/$total;
|
| 226 |
liveuser |
2022 |
|
| 3 |
liveuser |
2023 |
}#if end
|
| 226 |
liveuser |
2024 |
|
| 3 |
liveuser |
2025 |
}#for end
|
| 226 |
liveuser |
2026 |
|
| 3 |
liveuser |
2027 |
}#if end
|
| 226 |
liveuser |
2028 |
|
| 3 |
liveuser |
2029 |
}#for end
|
| 226 |
liveuser |
2030 |
|
| 3 |
liveuser |
2031 |
#設置要回傳的內容
|
|
|
2032 |
$result["content"]=$columnStatisticData;
|
| 226 |
liveuser |
2033 |
|
| 3 |
liveuser |
2034 |
#取得題項數目的計數
|
|
|
2035 |
$result["content"]["questCount"]=count($result["content"]);
|
| 226 |
liveuser |
2036 |
|
| 3 |
liveuser |
2037 |
#設置執行成功
|
|
|
2038 |
$reuslt["status"]="true";
|
| 226 |
liveuser |
2039 |
|
| 3 |
liveuser |
2040 |
#回傳結果
|
|
|
2041 |
return $result;
|
| 226 |
liveuser |
2042 |
|
| 3 |
liveuser |
2043 |
}#function decriptionStatistic end
|
| 226 |
liveuser |
2044 |
|
| 3 |
liveuser |
2045 |
/*
|
|
|
2046 |
#函式說明:
|
|
|
2047 |
#繪製圓餅圖
|
|
|
2048 |
#回傳結果:
|
|
|
2049 |
#$result["status"],執行正常與否,"true"代表正常;"false"代表不正常
|
|
|
2050 |
#$result["error"],錯誤訊息陣列
|
|
|
2051 |
#$result["function"],當前函數名稱
|
|
|
2052 |
#$result["content"],放置圖片的語法
|
|
|
2053 |
#$result["img"],圖表的位置與名稱
|
|
|
2054 |
#必填參數:
|
|
|
2055 |
#$conf["percentArray"],要變成圓餅圖的數據,R會自動計算比例.
|
|
|
2056 |
$conf["percentArray"]=array();
|
|
|
2057 |
#$conf["labels"],字串陣列,比例名稱.
|
|
|
2058 |
$conf["labels"]=array();
|
|
|
2059 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
2060 |
$conf["fileArgu"]=__FILE__;
|
|
|
2061 |
#可省略參數:
|
|
|
2062 |
#$conf["pngFileName"],字串,圖片存放的位置與名稱,預設爲 "pie-".$SESSION["username"]."png"
|
|
|
2063 |
#$conf["pngFileName"]=".R/pie-".$SESSION["username"]."png";
|
|
|
2064 |
#$conf["pieTitle"],字串,圓餅圖的標題,預設爲空。
|
|
|
2065 |
#$conf["pieTitle"]="";
|
|
|
2066 |
#參考資料:
|
|
|
2067 |
#無.
|
|
|
2068 |
#備註:
|
|
|
2069 |
#無
|
|
|
2070 |
*/
|
|
|
2071 |
public static function createPie(&$conf){
|
| 226 |
liveuser |
2072 |
|
| 3 |
liveuser |
2073 |
#初始化要回傳的內容
|
|
|
2074 |
$result=array();
|
| 226 |
liveuser |
2075 |
|
| 3 |
liveuser |
2076 |
#取得當前函數名稱
|
|
|
2077 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
2078 |
|
| 3 |
liveuser |
2079 |
#如果 $conf 不為陣列
|
|
|
2080 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
2081 |
|
| 3 |
liveuser |
2082 |
#設置執行失敗
|
|
|
2083 |
$result["status"]="false";
|
| 226 |
liveuser |
2084 |
|
| 3 |
liveuser |
2085 |
#設置執行錯誤訊息
|
|
|
2086 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2087 |
|
|
|
2088 |
#如果傳入的參數為 null
|
|
|
2089 |
if($conf==null){
|
| 226 |
liveuser |
2090 |
|
| 3 |
liveuser |
2091 |
#設置執行錯誤訊息
|
|
|
2092 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
2093 |
|
| 3 |
liveuser |
2094 |
}#if end
|
|
|
2095 |
|
|
|
2096 |
#回傳結果
|
|
|
2097 |
return $result;
|
| 226 |
liveuser |
2098 |
|
| 3 |
liveuser |
2099 |
}#if end
|
| 226 |
liveuser |
2100 |
|
| 3 |
liveuser |
2101 |
#檢查必填的參數
|
|
|
2102 |
#涵式說明:
|
|
|
2103 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
2104 |
#回傳的結果:
|
|
|
2105 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2106 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2107 |
#$result["function"],當前執行的函式名稱.
|
|
|
2108 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2109 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2110 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2111 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2112 |
#必填寫的參數:
|
|
|
2113 |
$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
2114 |
$conf["variableCheck.isexistMulti"]["variableCheck"]=array("fileArgu","percentArray","labels");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
2115 |
#可以省略的參數:
|
| 226 |
liveuser |
2116 |
$conf["variableCheck.isexistMulti"]["variableType"]=array("string","array","array");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
2117 |
$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
2118 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
|
|
|
2119 |
unset($conf["variableCheck.isexistMulti"]);
|
| 226 |
liveuser |
2120 |
|
| 3 |
liveuser |
2121 |
#如果檢查失敗
|
|
|
2122 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
2123 |
|
| 3 |
liveuser |
2124 |
#設置執行不正常
|
|
|
2125 |
$result["status"]="false";
|
| 226 |
liveuser |
2126 |
|
| 3 |
liveuser |
2127 |
#設置執行錯誤訊息
|
|
|
2128 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
2129 |
|
| 3 |
liveuser |
2130 |
#回傳結果
|
|
|
2131 |
return $result;
|
| 226 |
liveuser |
2132 |
|
| 3 |
liveuser |
2133 |
}#if end
|
| 226 |
liveuser |
2134 |
|
| 3 |
liveuser |
2135 |
#如果檢查不通過
|
|
|
2136 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
2137 |
|
| 3 |
liveuser |
2138 |
#設置執行不正常
|
|
|
2139 |
$result["status"]="false";
|
| 226 |
liveuser |
2140 |
|
| 3 |
liveuser |
2141 |
#設置執行錯誤訊息
|
|
|
2142 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
2143 |
|
| 3 |
liveuser |
2144 |
#回傳結果
|
|
|
2145 |
return $result;
|
| 226 |
liveuser |
2146 |
|
| 3 |
liveuser |
2147 |
}#if end
|
| 226 |
liveuser |
2148 |
|
| 3 |
liveuser |
2149 |
#如果 $_SESSION["username"] 不存在
|
|
|
2150 |
if(!isset($_SESSION["username"])){
|
| 226 |
liveuser |
2151 |
|
| 3 |
liveuser |
2152 |
#設為"NULL"
|
|
|
2153 |
$_SESSION["username"]="NULL";
|
| 226 |
liveuser |
2154 |
|
| 3 |
liveuser |
2155 |
}#if end
|
| 226 |
liveuser |
2156 |
|
| 3 |
liveuser |
2157 |
#檢查可省略的參數
|
|
|
2158 |
#函式說明:
|
|
|
2159 |
#檢查一包含數個可省略變數的陣列變數,其型態是否正確,省略掉的陣列變數可以直接給定預設值。
|
|
|
2160 |
#回傳結果:
|
|
|
2161 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2162 |
#$result["error"],錯誤訊息陣列.
|
|
|
2163 |
#$result["function"],當前執行的函式名稱.
|
|
|
2164 |
#$result["passed"],參數是否都通過檢查,"true",代表有通過檢查,"false"代表沒有通過檢查。
|
|
|
2165 |
#必填參數:
|
|
|
2166 |
#$conf["checkedVar"],陣列,要檢查的變數陣列名稱為?
|
|
|
2167 |
$conf["variableCheck.checkSkipableVarType"]["checkedVar"]=$conf;
|
|
|
2168 |
#$conf["sikpableVarNameArray"],字串陣列,要檢查型態是否設定正確的變數名稱陣列.
|
|
|
2169 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"]=array("pngFileName","pieTitle");
|
|
|
2170 |
#$conf["skipableVarTypeArray"],字串陣列,要檢查的每個變數,其型態應該要為何?
|
|
|
2171 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"]=array("string","string");
|
|
|
2172 |
#$argu,要直接存取的陣列變數名稱,變數前面加上「&」,如果要在別的函式裡面使用本函式,請記得將變動過結果($argu)給使用該函式的設定變數(通常是$conf=$argu).
|
|
|
2173 |
$argu=&$conf;
|
|
|
2174 |
#可省略參數:
|
|
|
2175 |
#$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"],字串陣列,每個不存的變數要初始化為什麼,"null"代表不指定.
|
|
|
2176 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"]=array(".R/pie-".$_SESSION["username"].".png"," ");
|
|
|
2177 |
#無
|
|
|
2178 |
$checkResult=variableCheck::checkSkipableVarType($conf["variableCheck.checkSkipableVarType"],$argu);
|
|
|
2179 |
unset($conf["variableCheck.checkSkipableVarType"]);
|
| 226 |
liveuser |
2180 |
|
| 3 |
liveuser |
2181 |
#如果檢查失敗
|
|
|
2182 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
2183 |
|
| 3 |
liveuser |
2184 |
#設置執行不正常
|
|
|
2185 |
$result["status"]="false";
|
| 226 |
liveuser |
2186 |
|
| 3 |
liveuser |
2187 |
#設置執行錯誤訊息
|
|
|
2188 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
2189 |
|
| 3 |
liveuser |
2190 |
#回傳結果
|
|
|
2191 |
return $result;
|
| 226 |
liveuser |
2192 |
|
| 3 |
liveuser |
2193 |
}#if end
|
| 226 |
liveuser |
2194 |
|
| 3 |
liveuser |
2195 |
#如果檢查不通過
|
|
|
2196 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
2197 |
|
| 3 |
liveuser |
2198 |
#設置執行不正常
|
|
|
2199 |
$result["status"]="false";
|
| 226 |
liveuser |
2200 |
|
| 3 |
liveuser |
2201 |
#設置執行錯誤訊息
|
|
|
2202 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
2203 |
|
| 3 |
liveuser |
2204 |
#回傳結果
|
|
|
2205 |
return $result;
|
| 226 |
liveuser |
2206 |
|
| 3 |
liveuser |
2207 |
}#if end
|
| 226 |
liveuser |
2208 |
|
| 3 |
liveuser |
2209 |
#初始化 percent 字串
|
|
|
2210 |
$percent="percent=c(";
|
| 226 |
liveuser |
2211 |
|
| 3 |
liveuser |
2212 |
#初始化 labels 字串
|
|
|
2213 |
$labels="labels=c(";
|
| 226 |
liveuser |
2214 |
|
| 3 |
liveuser |
2215 |
#有幾個比例陣列就執行幾次
|
|
|
2216 |
for($i=0;$i<count($conf["percentArray"]);$i++){
|
| 226 |
liveuser |
2217 |
|
| 3 |
liveuser |
2218 |
#如果不是最後一個比例
|
|
|
2219 |
if($i!=count($conf["percentArray"])-1){
|
| 226 |
liveuser |
2220 |
|
| 3 |
liveuser |
2221 |
#串接比例,結尾加逗號
|
|
|
2222 |
$percent=$percent.$conf["percentArray"][$i].",";
|
| 226 |
liveuser |
2223 |
|
| 3 |
liveuser |
2224 |
#串接比例名稱,結尾加逗號
|
|
|
2225 |
$labels=$labels."\"".$conf["labels"][$i]."\",";
|
| 226 |
liveuser |
2226 |
|
| 3 |
liveuser |
2227 |
}#if end
|
| 226 |
liveuser |
2228 |
|
| 3 |
liveuser |
2229 |
#反之是最後一個比例
|
|
|
2230 |
else{
|
| 226 |
liveuser |
2231 |
|
| 3 |
liveuser |
2232 |
#串接比例,最後面加上)
|
|
|
2233 |
$percent=$percent.$conf["percentArray"][$i].")";
|
| 226 |
liveuser |
2234 |
|
| 3 |
liveuser |
2235 |
#串接比例名稱,最後面加上)
|
|
|
2236 |
$labels=$labels."\"".$conf["labels"][$i]."\")";
|
| 226 |
liveuser |
2237 |
|
| 3 |
liveuser |
2238 |
}#else end
|
| 226 |
liveuser |
2239 |
|
| 3 |
liveuser |
2240 |
}#for end
|
| 226 |
liveuser |
2241 |
|
| 3 |
liveuser |
2242 |
#涵式說明:
|
|
|
2243 |
#建立R檔案
|
|
|
2244 |
#回傳的結果:
|
|
|
2245 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
|
|
|
2246 |
#$result["error"],錯誤訊息陣列.
|
|
|
2247 |
#$result["newCreatedRfilePathAndName"],R腳本檔的位置與名稱
|
|
|
2248 |
#必填的參數:
|
|
|
2249 |
$conf["R.writeRfile"]["addAndName"]=".R/pie-".$_SESSION["username"].".R";#R檔案的位置與名稱
|
|
|
2250 |
$conf["R.writeRfile"]["textToWrite"][]="#pie圓餅圖";
|
|
|
2251 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
2252 |
$conf["R.writeRfile"]["textToWrite"][]="#比例資料,總和須爲1";
|
|
|
2253 |
$conf["R.writeRfile"]["textToWrite"][]=$percent;
|
|
|
2254 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
2255 |
$conf["R.writeRfile"]["textToWrite"][]="#比例資料對應的名稱向量";
|
|
|
2256 |
$conf["R.writeRfile"]["textToWrite"][]=$labels;
|
|
|
2257 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
2258 |
$conf["R.writeRfile"]["textToWrite"][]="#轉換成UTF-8";
|
|
|
2259 |
$conf["R.writeRfile"]["textToWrite"][]="Encoding(labels)<-\"UTF-8\"";
|
|
|
2260 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
2261 |
$conf["R.writeRfile"]["textToWrite"][]="#設置圖片輸出的設定";
|
|
|
2262 |
$conf["R.writeRfile"]["textToWrite"][]="svg(filename=\"".$conf["pngFileName"]."\")";
|
|
|
2263 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
2264 |
$conf["R.writeRfile"]["textToWrite"][]="#繪製圓餅圖";
|
|
|
2265 |
$conf["R.writeRfile"]["textToWrite"][]="#比例資料爲 percent 向量";
|
|
|
2266 |
$conf["R.writeRfile"]["textToWrite"][]="#比例資料的名稱爲 labels 向量";
|
|
|
2267 |
$conf["R.writeRfile"]["textToWrite"][]="#從12點開始順時針依據少到多排序";
|
|
|
2268 |
$conf["R.writeRfile"]["textToWrite"][]="#圖的標題爲 \"系統整體感覺\"";
|
|
|
2269 |
$conf["R.writeRfile"]["textToWrite"][]="pie(percent,label=labels,clockwise=1,main=\"".$conf["pieTitle"]."\");";
|
|
|
2270 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
2271 |
$conf["R.writeRfile"]["textToWrite"][]="#關閉繪圖裝置";
|
|
|
2272 |
$conf["R.writeRfile"]["textToWrite"][]="dev.off()";
|
|
|
2273 |
#$conf["textToWrite"],要寫入的字串內容陣列,一個元素代表一行文字,每行結尾會自動換行。
|
|
|
2274 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
2275 |
$conf["R.writeRfile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
2276 |
$rScriptCreateResult=R::writeRfile($conf["R.writeRfile"]);
|
|
|
2277 |
unset($conf["R.writeRfile"]);
|
| 226 |
liveuser |
2278 |
|
| 3 |
liveuser |
2279 |
#如果R腳本檔建立失敗
|
|
|
2280 |
if($rScriptCreateResult["status"]=="false"){
|
| 226 |
liveuser |
2281 |
|
| 3 |
liveuser |
2282 |
#設置執行不正常
|
|
|
2283 |
$result["status"]="false";
|
| 226 |
liveuser |
2284 |
|
| 3 |
liveuser |
2285 |
#設置執行錯誤訊息
|
|
|
2286 |
$result["error"]=$rScriptCreateResult;
|
| 226 |
liveuser |
2287 |
|
| 3 |
liveuser |
2288 |
#回傳結果
|
|
|
2289 |
return $result;
|
| 226 |
liveuser |
2290 |
|
| 3 |
liveuser |
2291 |
}#if end
|
| 226 |
liveuser |
2292 |
|
| 3 |
liveuser |
2293 |
#執行R腳本
|
|
|
2294 |
#函式說明:
|
|
|
2295 |
#執行R腳本,執行完畢後,會刪除R的腳本與暫存R執行後的輸出的檔案.
|
|
|
2296 |
#回傳的結果:
|
|
|
2297 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2298 |
#$result["errror"],錯誤訊息陣列
|
|
|
2299 |
#$result["lineArray"],字串陣列,R輸出結果,每個元素代表一行的輸出.
|
|
|
2300 |
#$result["lineCount"],整數,R輸出的總共行數.
|
|
|
2301 |
#必填的參數:
|
|
|
2302 |
#$conf["rPositionAndName"],字串,R腳本的位置與名稱.
|
|
|
2303 |
$conf["R.executeR"]["rPositionAndName"]=$rScriptCreateResult["newCreatedRfilePathAndName"];
|
|
|
2304 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
2305 |
$conf["R.executeR"]["fileArgu"]=$conf["fileArgu"];
|
|
|
2306 |
#可省略的參數:
|
|
|
2307 |
#$conf["disbaleOptimal"],字串,"true"代表取消輸出的優化,可以顯示版本訊息、歡迎訊息、儲存暫存檔,預設為"false"要進行優化.
|
|
|
2308 |
#$conf["disbaleOptimal"]="true";
|
|
|
2309 |
$executeRresult=R::executeR($conf["R.executeR"]);
|
|
|
2310 |
unset($conf["R.executeR"]);
|
| 226 |
liveuser |
2311 |
|
| 3 |
liveuser |
2312 |
#如果執行R失敗
|
|
|
2313 |
if($executeRresult["status"]=="false"){
|
| 226 |
liveuser |
2314 |
|
| 3 |
liveuser |
2315 |
#設置執行不正常
|
|
|
2316 |
$result["status"]="false";
|
| 226 |
liveuser |
2317 |
|
| 3 |
liveuser |
2318 |
#設置執行錯誤訊息
|
|
|
2319 |
$result["error"]=$executeRresult;
|
| 226 |
liveuser |
2320 |
|
| 3 |
liveuser |
2321 |
#回傳結果
|
|
|
2322 |
return $result;
|
| 226 |
liveuser |
2323 |
|
| 3 |
liveuser |
2324 |
}#if end
|
| 226 |
liveuser |
2325 |
|
| 3 |
liveuser |
2326 |
#檢查圖片檔案是否有產生
|
|
|
2327 |
#涵式說明:檢查多個檔案與資料夾是否存在.
|
|
|
2328 |
#回傳的結果:
|
|
|
2329 |
#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
|
|
|
2330 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
2331 |
#必填的參數:
|
|
|
2332 |
$conf["fileAccess.checkMultiFileExist"]["fileArray"]=array($conf["pngFileName"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
2333 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
2334 |
$conf["fileAccess.checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
|
|
|
2335 |
#參考資料來源:
|
|
|
2336 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
2337 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
2338 |
$fileCheckResult=fileAccess::checkMultiFileExist($conf["fileAccess.checkMultiFileExist"]);
|
|
|
2339 |
unset($conf["fileAccess.checkMultiFileExist"]);
|
| 226 |
liveuser |
2340 |
|
| 3 |
liveuser |
2341 |
#如果檢查圖片失敗
|
|
|
2342 |
if($fileCheckResult["status"]=="false"){
|
| 226 |
liveuser |
2343 |
|
| 3 |
liveuser |
2344 |
#設置執行不正常
|
|
|
2345 |
$result["status"]="false";
|
| 226 |
liveuser |
2346 |
|
| 3 |
liveuser |
2347 |
#設置執行錯誤訊息
|
|
|
2348 |
$result["error"]=$fileCheckResult;
|
| 226 |
liveuser |
2349 |
|
| 3 |
liveuser |
2350 |
#回傳結果
|
|
|
2351 |
return $result;
|
| 226 |
liveuser |
2352 |
|
| 3 |
liveuser |
2353 |
}#if end
|
| 226 |
liveuser |
2354 |
|
| 3 |
liveuser |
2355 |
#如果要產生的圖片不存在
|
|
|
2356 |
if($fileCheckResult["varExist"][0]=="false"){
|
| 226 |
liveuser |
2357 |
|
| 3 |
liveuser |
2358 |
#設置執行不正常
|
|
|
2359 |
$result["status"]="false";
|
| 226 |
liveuser |
2360 |
|
| 3 |
liveuser |
2361 |
#設置執行錯誤訊息
|
|
|
2362 |
$result["error"]=$fileCheckResult;
|
| 226 |
liveuser |
2363 |
|
| 3 |
liveuser |
2364 |
#回傳結果
|
|
|
2365 |
return $result;
|
| 226 |
liveuser |
2366 |
|
| 3 |
liveuser |
2367 |
}#if end
|
| 226 |
liveuser |
2368 |
|
| 3 |
liveuser |
2369 |
#取得圖表的位置與名稱
|
| 226 |
liveuser |
2370 |
$result["img"]=$conf["pngFileName"];
|
|
|
2371 |
|
| 3 |
liveuser |
2372 |
#函數說明:
|
|
|
2373 |
#用data:mimeType;base64,imgVar的形式來提供圖片的連結,亦即圖片儲存在變數裡面,本函式包含顯示圖片的語法.
|
|
|
2374 |
#回傳結果:
|
|
|
2375 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2376 |
#$result["error"],錯誤訊息
|
|
|
2377 |
#$result["content"],圖片的連結資訊
|
| 226 |
liveuser |
2378 |
#$result["function"],當前執行的函數名稱
|
| 3 |
liveuser |
2379 |
#必填參數:
|
|
|
2380 |
#$conf["imgPosition"],要轉存成2元碼的圖片檔案位置與名稱
|
|
|
2381 |
$conf["img::data"]["imgPosition"]=$conf["pngFileName"];
|
|
|
2382 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
2383 |
$conf["img::data"]["fileArgu"]=$conf["fileArgu"];
|
|
|
2384 |
#可省略參數:
|
|
|
2385 |
#$conf["alt"],若沒有圖片要用什麼文字顯示。
|
|
|
2386 |
#$conf["alt"]="";
|
|
|
2387 |
#$conf["style"],字串陣列,要使用的style,key為樣式名稱,value為樣式值.
|
|
|
2388 |
$conf["img::data"]["style"]=array("width"=>"100%");
|
|
|
2389 |
#$conf["class"],圖片要套用的css樣式名稱.
|
|
|
2390 |
#$conf["class"]="";
|
|
|
2391 |
#$conf["mimeType"],2元碼的內容是什麼,預設為"image/*".
|
|
|
2392 |
$conf["img::data"]["mimeType"]="image/svg+xml";
|
|
|
2393 |
#$conf["compressType"],2元碼壓縮的方式,預設為"base64".
|
|
|
2394 |
#$conf["compressType"]="base64";
|
|
|
2395 |
#$conf["delImg"],讀取完圖片檔案後,要移除圖片嗎?"true"代表要移除,"false"代表不要移除,預設為"false".
|
|
|
2396 |
#$conf["img::data"]["delImg"]="false";
|
|
|
2397 |
#參考資料:
|
|
|
2398 |
#將檔案用字串變數儲存起來=>http://php.net/manual/en/function.file-get-contents.php
|
|
|
2399 |
#壓縮2元碼=>http://php.net/manual/en/function.base64-encode.php
|
|
|
2400 |
$data=img::data($conf["img::data"]);
|
|
|
2401 |
unset($conf["img::data"]);
|
| 226 |
liveuser |
2402 |
|
| 3 |
liveuser |
2403 |
#如果顯示圖片失敗
|
|
|
2404 |
if($data["status"]=="false"){
|
| 226 |
liveuser |
2405 |
|
| 3 |
liveuser |
2406 |
#設置執行失敗
|
|
|
2407 |
$result["status"]="false";
|
| 226 |
liveuser |
2408 |
|
| 3 |
liveuser |
2409 |
#設置執行錯誤訊息
|
|
|
2410 |
$result["error"]=$data;
|
| 226 |
liveuser |
2411 |
|
| 3 |
liveuser |
2412 |
#回傳結果
|
|
|
2413 |
return $result;
|
| 226 |
liveuser |
2414 |
|
|
|
2415 |
}#if end
|
|
|
2416 |
|
| 3 |
liveuser |
2417 |
#取得顯示圖片的語法
|
|
|
2418 |
$result["content"]=$data["content"];
|
| 226 |
liveuser |
2419 |
|
| 3 |
liveuser |
2420 |
#執行到這邊代表執行正常
|
|
|
2421 |
$result["status"]="true";
|
| 226 |
liveuser |
2422 |
|
| 3 |
liveuser |
2423 |
#回傳結果
|
| 226 |
liveuser |
2424 |
return $result;
|
|
|
2425 |
|
| 3 |
liveuser |
2426 |
}#function createPie end
|
| 226 |
liveuser |
2427 |
|
| 3 |
liveuser |
2428 |
/*
|
|
|
2429 |
#函式說明:
|
|
|
2430 |
#繪製長條圖
|
|
|
2431 |
#回傳結果:
|
|
|
2432 |
#$result["status"],執行正常與否,"true"代表正常;"false"代表不正常
|
|
|
2433 |
#$result["error"],錯誤訊息陣列
|
|
|
2434 |
#$result["function"],當前函數名稱
|
|
|
2435 |
#$result["img"],圖片的位置與名稱
|
|
|
2436 |
#$result["content"],放置圖表的語法
|
|
|
2437 |
#必填參數:
|
|
|
2438 |
#$conf["countArray"],字串陣列,每個要呈現資料的次數,請輸入大於零的整數.
|
|
|
2439 |
$conf["countArray"]=array();
|
|
|
2440 |
#$conf["countNameArray"],字串陣列,每個要呈現資料的名稱.
|
|
|
2441 |
$conf["countNameArray"]=array();
|
|
|
2442 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
2443 |
$conf["fileArgu"]=__FILE__;
|
|
|
2444 |
#可省略參數:
|
|
|
2445 |
#$conf["imgFileName"],字串,圖片存放的位置與名稱,預設爲 "pie-".$SESSION["username"].".png",若 $SESSION["username"] 不存在則會用 "NULL" 替代
|
|
|
2446 |
#$conf["imgFileName"]=".R/barplot-".$SESSION["username"].".png";
|
|
|
2447 |
#$conf["del"],字串,是否要讀取完圖片後就把圖片檔案移除,"false"代表不要,"true"代表要,預設為"true".
|
|
|
2448 |
#$conf["del"]="true";
|
|
|
2449 |
#$conf["barPlotTitle"],字串,長條圖的標題,預設爲空。
|
|
|
2450 |
#$conf["barPlotTitle"]="";
|
|
|
2451 |
#$conf["xlabName"],x軸的名稱,預設爲項目
|
|
|
2452 |
#$conf["xlabName"]="項目";
|
|
|
2453 |
#$conf["ylabName"],y軸的名稱,預設爲頻率
|
|
|
2454 |
#$conf["ylabName"]="頻率";
|
|
|
2455 |
#$conf["autoRadioByCountArray"],字串,是否要自動計算與呈現每個項目在當前長條所有項目中的比例,"true"為要顯示,"false"為不顯示,預設為"true".
|
|
|
2456 |
#$conf["autoRadioByCountArray"]="true";
|
|
|
2457 |
#$conf["disableText"],字串,是否要取消圖例的顯示,直接顯示項目名稱在長條圖裡面,"true"代表要取消圖例,"false"代表不取消圖例,預設為"false".
|
|
|
2458 |
#$conf["disableText"]="true";
|
|
|
2459 |
#$conf["picWidth"],字串,圖片的寬度(px),預設為不指定.
|
|
|
2460 |
#$conf["picWidth"]="";
|
|
|
2461 |
#$conf["picHeight"],字串,圖片的高度(px),預設為不指定.
|
|
|
2462 |
#$conf["picHeight"]="";
|
|
|
2463 |
#$conf["line"],二維字串陣列,代表要在圖上面畫幾條線
|
|
|
2464 |
#$conf["line"]=array();
|
|
|
2465 |
#$conf["line"][$i],一維字串陣列,代表要在圖上劃第$i+1條線的資訊
|
|
|
2466 |
#$conf["line"][$i]["startX"],整數,代表線條起始點的X軸坐標.
|
|
|
2467 |
#$conf["line"][$i]["startY"],整數,代表線條起始點的Y軸坐標.
|
|
|
2468 |
#$conf["line"][$i]["endX"],整數,代表線條終點的X軸坐標.
|
|
|
2469 |
#$conf["line"][$i]["endY"],整數,代表線條終點的Y軸坐標.
|
|
|
2470 |
#$conf["line"][$i]["color"],顏色,目前有black,green,red三種
|
|
|
2471 |
#參考資料:
|
|
|
2472 |
#無.
|
|
|
2473 |
#備註:
|
|
|
2474 |
#無
|
|
|
2475 |
*/
|
|
|
2476 |
public static function createBarPlot(&$conf){
|
| 226 |
liveuser |
2477 |
|
| 3 |
liveuser |
2478 |
#初始化要回傳的內容
|
|
|
2479 |
$result=array();
|
| 226 |
liveuser |
2480 |
|
| 3 |
liveuser |
2481 |
#取得當前函數名稱
|
|
|
2482 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
2483 |
|
| 3 |
liveuser |
2484 |
#如果 $conf 不為陣列
|
|
|
2485 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
2486 |
|
| 3 |
liveuser |
2487 |
#設置執行失敗
|
|
|
2488 |
$result["status"]="false";
|
| 226 |
liveuser |
2489 |
|
| 3 |
liveuser |
2490 |
#設置執行錯誤訊息
|
|
|
2491 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2492 |
|
|
|
2493 |
#如果傳入的參數為 null
|
|
|
2494 |
if($conf==null){
|
| 226 |
liveuser |
2495 |
|
| 3 |
liveuser |
2496 |
#設置執行錯誤訊息
|
|
|
2497 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
2498 |
|
| 3 |
liveuser |
2499 |
}#if end
|
|
|
2500 |
|
|
|
2501 |
#回傳結果
|
|
|
2502 |
return $result;
|
| 226 |
liveuser |
2503 |
|
| 3 |
liveuser |
2504 |
}#if end
|
| 226 |
liveuser |
2505 |
|
| 3 |
liveuser |
2506 |
#檢查必填的參數
|
|
|
2507 |
#涵式說明:
|
|
|
2508 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
2509 |
#回傳的結果:
|
|
|
2510 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2511 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2512 |
#$result["function"],當前執行的函式名稱.
|
|
|
2513 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2514 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2515 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2516 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2517 |
#必填寫的參數:
|
|
|
2518 |
$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
2519 |
$conf["variableCheck.isexistMulti"]["variableCheck"]=array("fileArgu","countArray","countNameArray");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
2520 |
#可以省略的參數:
|
| 226 |
liveuser |
2521 |
$conf["variableCheck.isexistMulti"]["variableType"]=array("string","array","array");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
2522 |
$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
2523 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
|
|
|
2524 |
unset($conf["variableCheck.isexistMulti"]);
|
| 226 |
liveuser |
2525 |
|
| 3 |
liveuser |
2526 |
#如果檢查失敗
|
|
|
2527 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
2528 |
|
| 3 |
liveuser |
2529 |
#設置執行不正常
|
|
|
2530 |
$result["status"]="false";
|
| 226 |
liveuser |
2531 |
|
| 3 |
liveuser |
2532 |
#設置執行錯誤訊息
|
|
|
2533 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
2534 |
|
| 3 |
liveuser |
2535 |
#回傳結果
|
|
|
2536 |
return $result;
|
| 226 |
liveuser |
2537 |
|
| 3 |
liveuser |
2538 |
}#if end
|
| 226 |
liveuser |
2539 |
|
| 3 |
liveuser |
2540 |
#如果檢查不通過
|
|
|
2541 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
2542 |
|
| 3 |
liveuser |
2543 |
#設置執行不正常
|
|
|
2544 |
$result["status"]="false";
|
| 226 |
liveuser |
2545 |
|
| 3 |
liveuser |
2546 |
#設置執行錯誤訊息
|
|
|
2547 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
2548 |
|
| 3 |
liveuser |
2549 |
#回傳結果
|
|
|
2550 |
return $result;
|
| 226 |
liveuser |
2551 |
|
| 3 |
liveuser |
2552 |
}#if end
|
| 226 |
liveuser |
2553 |
|
| 3 |
liveuser |
2554 |
#如果 $_SESSION["username"] 不存在
|
|
|
2555 |
if(!isset($_SESSION["username"])){
|
| 226 |
liveuser |
2556 |
|
| 3 |
liveuser |
2557 |
#設為"NULL"
|
|
|
2558 |
$_SESSION["username"]="NULL";
|
| 226 |
liveuser |
2559 |
|
| 3 |
liveuser |
2560 |
}#if end
|
| 226 |
liveuser |
2561 |
|
| 3 |
liveuser |
2562 |
#取得最高的頻率
|
|
|
2563 |
#涵式說明:
|
|
|
2564 |
#找最大值,結果會回傳最大值.
|
|
|
2565 |
#回傳的結果:
|
|
|
2566 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
2567 |
#$result["error"],錯誤訊息陣列.
|
|
|
2568 |
#$result["function"],當前執行的函數名稱.
|
|
|
2569 |
#$result["key"],最大值原先的key.
|
|
|
2570 |
#$result["value"],最大值的數字.
|
|
|
2571 |
#必填的參數:
|
|
|
2572 |
$conf["math::getMaxValue"]["rawDataArray"]=$conf["countArray"];#爲原始數據
|
|
|
2573 |
$getMaxValue=math::getMaxValue($conf["math::getMaxValue"]);
|
|
|
2574 |
unset($conf["math::getMaxValue"]);
|
| 226 |
liveuser |
2575 |
|
| 3 |
liveuser |
2576 |
#如果取得最大值失敗
|
|
|
2577 |
if($getMaxValue["status"]=="false"){
|
| 226 |
liveuser |
2578 |
|
| 3 |
liveuser |
2579 |
#設置執行不正常
|
|
|
2580 |
$result["status"]="false";
|
| 226 |
liveuser |
2581 |
|
| 3 |
liveuser |
2582 |
#設置執行錯誤訊息
|
|
|
2583 |
$result["error"]=$getMaxValue;
|
| 226 |
liveuser |
2584 |
|
| 3 |
liveuser |
2585 |
#回傳結果
|
|
|
2586 |
return $result;
|
| 226 |
liveuser |
2587 |
|
| 3 |
liveuser |
2588 |
}#if end
|
| 226 |
liveuser |
2589 |
|
| 3 |
liveuser |
2590 |
#取得頻率最大值
|
|
|
2591 |
$maxFreq=$getMaxValue["value"];
|
| 226 |
liveuser |
2592 |
|
| 3 |
liveuser |
2593 |
#取得最低的頻率
|
|
|
2594 |
#涵式說明
|
|
|
2595 |
#找最小值,結果會回傳最小值
|
|
|
2596 |
#回傳的內容
|
|
|
2597 |
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
|
|
|
2598 |
#$result["error"],錯誤訊息陣列.
|
|
|
2599 |
#$result["function"],當前執行的函數名稱.
|
|
|
2600 |
#$result["key"],最大值原先的key.
|
|
|
2601 |
#$result["value"],陣列裏面最小的數值.
|
|
|
2602 |
#必填的參數:
|
|
|
2603 |
$conf["max::getMinValue"]["rawDataArray"]=$conf["countArray"];#爲原始數據
|
|
|
2604 |
$getMinValue=math::getMinValue($conf["max::getMinValue"]);
|
|
|
2605 |
unset($conf["max::getMinValue"]);
|
| 226 |
liveuser |
2606 |
|
| 3 |
liveuser |
2607 |
#如果取得最小值失敗
|
|
|
2608 |
if($getMinValue["status"]=="false"){
|
| 226 |
liveuser |
2609 |
|
| 3 |
liveuser |
2610 |
#設置執行不正常
|
|
|
2611 |
$result["status"]="false";
|
| 226 |
liveuser |
2612 |
|
| 3 |
liveuser |
2613 |
#設置執行錯誤訊息
|
|
|
2614 |
$result["error"]=$getMaxValue;
|
| 226 |
liveuser |
2615 |
|
| 3 |
liveuser |
2616 |
#回傳結果
|
|
|
2617 |
return $result;
|
| 226 |
liveuser |
2618 |
|
| 3 |
liveuser |
2619 |
}#if end
|
| 226 |
liveuser |
2620 |
|
| 3 |
liveuser |
2621 |
#取得頻率最小值
|
|
|
2622 |
$minFreq=$getMinValue["value"];
|
| 226 |
liveuser |
2623 |
|
| 3 |
liveuser |
2624 |
#debug
|
|
|
2625 |
#var_dump($maxFreq);
|
|
|
2626 |
#var_dump($minFreq);
|
| 226 |
liveuser |
2627 |
|
| 3 |
liveuser |
2628 |
#檢查可省略的參數
|
|
|
2629 |
#函式說明:
|
|
|
2630 |
#檢查一包含數個可省略變數的陣列變數,其型態是否正確,省略掉的陣列變數可以直接給定預設值。
|
|
|
2631 |
#回傳結果:
|
|
|
2632 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2633 |
#$result["error"],錯誤訊息陣列.
|
|
|
2634 |
#$result["function"],當前執行的函式名稱.
|
|
|
2635 |
#$result["passed"],參數是否都通過檢查,"true",代表有通過檢查,"false"代表沒有通過檢查。
|
|
|
2636 |
#必填參數:
|
|
|
2637 |
#$conf["checkedVar"],陣列,要檢查的變數陣列名稱為?
|
|
|
2638 |
$conf["variableCheck.checkSkipableVarType"]["checkedVar"]=$conf;
|
|
|
2639 |
#$conf["sikpableVarNameArray"],字串陣列,要檢查型態是否設定正確的變數名稱陣列.
|
|
|
2640 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"]=array("imgFileName","del","barPlotTitle","xlabName","ylabName","autoRadioByCountArray","picWidth","picHeight","line","disableText");
|
|
|
2641 |
#$conf["skipableVarTypeArray"],字串陣列,要檢查的每個變數,其型態應該要為何?
|
|
|
2642 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"]=array("string","del","string","string","string","string","string","string","array","string");
|
|
|
2643 |
#$argu,要直接存取的陣列變數名稱,變數前面加上「&」,如果要在別的函式裡面使用本函式,請記得將變動過結果($argu)給使用該函式的設定變數(通常是$conf=$argu).
|
|
|
2644 |
$argu=&$conf;
|
|
|
2645 |
#可省略參數:
|
|
|
2646 |
#$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"],字串陣列,每個不存的變數要初始化為什麼,null代表不指定.
|
|
|
2647 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"]=array(".R/barplot-".$_SESSION["username"].".png","true"," ","項目","頻率","true",null,null,null,"false");
|
|
|
2648 |
#無
|
|
|
2649 |
$checkResult=variableCheck::checkSkipableVarType($conf["variableCheck.checkSkipableVarType"],$argu);
|
|
|
2650 |
unset($conf["variableCheck.checkSkipableVarType"]);
|
| 226 |
liveuser |
2651 |
|
| 3 |
liveuser |
2652 |
#如果檢查失敗
|
|
|
2653 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
2654 |
|
| 3 |
liveuser |
2655 |
#設置執行不正常
|
|
|
2656 |
$result["status"]="false";
|
| 226 |
liveuser |
2657 |
|
| 3 |
liveuser |
2658 |
#設置執行錯誤訊息
|
|
|
2659 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
2660 |
|
| 3 |
liveuser |
2661 |
#回傳結果
|
|
|
2662 |
return $result;
|
| 226 |
liveuser |
2663 |
|
| 3 |
liveuser |
2664 |
}#if end
|
| 226 |
liveuser |
2665 |
|
| 3 |
liveuser |
2666 |
#如果檢查不通過
|
|
|
2667 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
2668 |
|
| 3 |
liveuser |
2669 |
#設置執行不正常
|
|
|
2670 |
$result["status"]="false";
|
| 226 |
liveuser |
2671 |
|
| 3 |
liveuser |
2672 |
#設置執行錯誤訊息
|
|
|
2673 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
2674 |
|
| 3 |
liveuser |
2675 |
#回傳結果
|
|
|
2676 |
return $result;
|
| 226 |
liveuser |
2677 |
|
| 3 |
liveuser |
2678 |
}#if end
|
| 226 |
liveuser |
2679 |
|
| 3 |
liveuser |
2680 |
#初始化總頻率
|
|
|
2681 |
$totalCount=0;
|
| 226 |
liveuser |
2682 |
|
| 3 |
liveuser |
2683 |
#有幾個要統計的物件陣列就執行幾次
|
|
|
2684 |
for($i=0;$i<count($conf["countArray"]);$i++){
|
| 226 |
liveuser |
2685 |
|
| 3 |
liveuser |
2686 |
#加總頻率
|
|
|
2687 |
$totalCount=$totalCount+$conf["countArray"][$i];
|
| 226 |
liveuser |
2688 |
|
|
|
2689 |
}#for end
|
|
|
2690 |
|
| 3 |
liveuser |
2691 |
#初始化 $counts 字串
|
|
|
2692 |
$counts="count=c(";
|
| 226 |
liveuser |
2693 |
|
| 3 |
liveuser |
2694 |
#初始化 $labels 字串
|
|
|
2695 |
$labels="timeLabel=c(";
|
| 226 |
liveuser |
2696 |
|
| 3 |
liveuser |
2697 |
#初始化 $legendStr 字串
|
|
|
2698 |
$legendStr="legendStr=c(";
|
| 226 |
liveuser |
2699 |
|
| 3 |
liveuser |
2700 |
#有幾個要統計的物件陣列就執行幾次
|
|
|
2701 |
for($i=0;$i<count($conf["countArray"]);$i++){
|
| 226 |
liveuser |
2702 |
|
| 3 |
liveuser |
2703 |
#如果不是最後一個要統計的物件
|
|
|
2704 |
if($i!=count($conf["countArray"])-1){
|
| 226 |
liveuser |
2705 |
|
| 3 |
liveuser |
2706 |
#串接頻率,結尾加逗號
|
|
|
2707 |
$counts=$counts."".$conf["countArray"][$i].",";
|
| 226 |
liveuser |
2708 |
|
| 3 |
liveuser |
2709 |
#如果 $conf["autoRadioByCountArray"] 等於 "true"
|
|
|
2710 |
if($conf["autoRadioByCountArray"]=="true"){
|
| 226 |
liveuser |
2711 |
|
| 3 |
liveuser |
2712 |
#串接含有比例的輔助說明文字,結尾加逗號
|
|
|
2713 |
$legendStr=$legendStr."\"".$i."->".$conf["countNameArray"][$i]."(".$conf["ylabName"]."=".$conf["countArray"][$i].",比例=".round($conf["countArray"][$i]/$totalCount,2).")\",";
|
| 226 |
liveuser |
2714 |
|
| 3 |
liveuser |
2715 |
}#if end
|
| 226 |
liveuser |
2716 |
|
| 3 |
liveuser |
2717 |
#反之
|
|
|
2718 |
else{
|
| 226 |
liveuser |
2719 |
|
| 3 |
liveuser |
2720 |
#串接輔助說明文字,結尾加逗號
|
|
|
2721 |
$legendStr=$legendStr."\"".$i."->".$conf["countNameArray"][$i]."(".$conf["ylabName"]."=".$conf["countArray"][$i].")\",";
|
| 226 |
liveuser |
2722 |
|
| 3 |
liveuser |
2723 |
}#else end
|
| 226 |
liveuser |
2724 |
|
| 3 |
liveuser |
2725 |
#如果要取消圖例
|
|
|
2726 |
if($conf["disableText"]=="true"){
|
| 226 |
liveuser |
2727 |
|
| 3 |
liveuser |
2728 |
#如果 $conf["autoRadioByCountArray"] 等於 "true"
|
|
|
2729 |
if($conf["autoRadioByCountArray"]=="true"){
|
| 226 |
liveuser |
2730 |
|
| 3 |
liveuser |
2731 |
#串接項目的名稱
|
|
|
2732 |
$labels=$labels."\"".$conf["countNameArray"][$i]."\r\n".$conf["ylabName"]."=".$conf["countArray"][$i]."(比例=".round($conf["countArray"][$i]/$totalCount,2).")\",";
|
| 226 |
liveuser |
2733 |
|
| 3 |
liveuser |
2734 |
}#if end
|
| 226 |
liveuser |
2735 |
|
|
|
2736 |
#反之 不需要比例資訊
|
| 3 |
liveuser |
2737 |
else{
|
| 226 |
liveuser |
2738 |
|
| 3 |
liveuser |
2739 |
#串接項目的名稱
|
|
|
2740 |
$labels=$labels."\"".$conf["countNameArray"][$i]."\r\n".$conf["ylabName"]."=".$conf["countArray"][$i]."\",";
|
| 226 |
liveuser |
2741 |
|
| 3 |
liveuser |
2742 |
}#else end
|
| 226 |
liveuser |
2743 |
|
| 3 |
liveuser |
2744 |
}#if end
|
| 226 |
liveuser |
2745 |
|
|
|
2746 |
#反之不要取消圖例
|
| 3 |
liveuser |
2747 |
else{
|
| 226 |
liveuser |
2748 |
|
| 3 |
liveuser |
2749 |
#串接物件名稱,結尾加逗號
|
|
|
2750 |
$labels=$labels."\"".$i."\",";
|
| 226 |
liveuser |
2751 |
|
| 3 |
liveuser |
2752 |
}#else end
|
| 226 |
liveuser |
2753 |
|
| 3 |
liveuser |
2754 |
}#if end
|
| 226 |
liveuser |
2755 |
|
| 3 |
liveuser |
2756 |
#反之是最後一個物件
|
|
|
2757 |
else{
|
| 226 |
liveuser |
2758 |
|
| 3 |
liveuser |
2759 |
#串接頻率,最後面加上)
|
|
|
2760 |
$counts=$counts.$conf["countArray"][$i].")";
|
| 226 |
liveuser |
2761 |
|
| 3 |
liveuser |
2762 |
#如果 $conf["autoRadioByCountArray"] 等於 "true"
|
|
|
2763 |
if($conf["autoRadioByCountArray"]=="true"){
|
| 226 |
liveuser |
2764 |
|
| 3 |
liveuser |
2765 |
#串接含有比例的輔助說明文字
|
|
|
2766 |
$legendStr=$legendStr."\"".$i."->".$conf["countNameArray"][$i]."(".$conf["ylabName"]."=".$conf["countArray"][$i].",比例=".round($conf["countArray"][$i]/$totalCount,2).")\")";
|
| 226 |
liveuser |
2767 |
|
| 3 |
liveuser |
2768 |
}#if end
|
| 226 |
liveuser |
2769 |
|
| 3 |
liveuser |
2770 |
#反之
|
|
|
2771 |
else{
|
| 226 |
liveuser |
2772 |
|
| 3 |
liveuser |
2773 |
#串接含有比例的輔助說明文字
|
|
|
2774 |
$legendStr=$legendStr."\"".$i."->".$conf["countNameArray"][$i]."(".$conf["ylabName"]."=".$conf["countArray"][$i].")\")";
|
| 226 |
liveuser |
2775 |
|
| 3 |
liveuser |
2776 |
}#else end
|
| 226 |
liveuser |
2777 |
|
| 3 |
liveuser |
2778 |
#如果要取消圖例
|
|
|
2779 |
if($conf["disableText"]=="true"){
|
| 226 |
liveuser |
2780 |
|
| 3 |
liveuser |
2781 |
#如果 $conf["autoRadioByCountArray"] 等於 "true"
|
|
|
2782 |
if($conf["autoRadioByCountArray"]=="true"){
|
| 226 |
liveuser |
2783 |
|
| 3 |
liveuser |
2784 |
#串接項目的名稱
|
|
|
2785 |
$labels=$labels."\"".$conf["countNameArray"][$i]."\r\n".$conf["ylabName"]."=".$conf["countArray"][$i]."(比例=".round($conf["countArray"][$i]/$totalCount,2).")\")";
|
| 226 |
liveuser |
2786 |
|
| 3 |
liveuser |
2787 |
}#if end
|
| 226 |
liveuser |
2788 |
|
|
|
2789 |
#反之不要比例資訊
|
| 3 |
liveuser |
2790 |
else{
|
| 226 |
liveuser |
2791 |
|
| 3 |
liveuser |
2792 |
#串接項目的名稱
|
|
|
2793 |
$labels=$labels."\"".$conf["countNameArray"][$i]."\r\n".$conf["ylabName"]."=".$conf["countArray"][$i]."\")";
|
| 226 |
liveuser |
2794 |
|
| 3 |
liveuser |
2795 |
}#else end
|
| 226 |
liveuser |
2796 |
|
|
|
2797 |
}#if end
|
|
|
2798 |
|
|
|
2799 |
#反之不要取消圖例
|
| 3 |
liveuser |
2800 |
else{
|
| 226 |
liveuser |
2801 |
|
| 3 |
liveuser |
2802 |
#串接物件名稱,最後面加上)
|
|
|
2803 |
$labels=$labels."\"".$i."\")";
|
| 226 |
liveuser |
2804 |
|
|
|
2805 |
}#else end
|
|
|
2806 |
|
| 3 |
liveuser |
2807 |
}#else end
|
| 226 |
liveuser |
2808 |
|
| 3 |
liveuser |
2809 |
}#for end
|
| 226 |
liveuser |
2810 |
|
| 3 |
liveuser |
2811 |
#$conf["line"]=array();
|
|
|
2812 |
#$conf["line"][$i],一維字串陣列,代表要在圖上劃第$i+1條線的資訊
|
|
|
2813 |
#$conf["line"][$i]["startX"],整數,代表線條起始點的X軸坐標.
|
|
|
2814 |
#$conf["line"][$i]["startY"],整數,代表線條起始點的Y軸坐標.
|
|
|
2815 |
#$conf["line"][$i]["endX"],整數,代表線條終點的X軸坐標.
|
| 226 |
liveuser |
2816 |
#$conf["line"][$i]["endY"],整數,代表線條終點的Y軸坐標.
|
|
|
2817 |
#$conf["line"][$i]["color"],顏色,目前有black,green,red三種
|
|
|
2818 |
|
| 3 |
liveuser |
2819 |
#初始化儲存劃線R語法陣列
|
| 226 |
liveuser |
2820 |
$line=array();
|
|
|
2821 |
|
| 3 |
liveuser |
2822 |
#如果 $conf["line"] 有設定
|
|
|
2823 |
if(isset($conf["line"])){
|
| 226 |
liveuser |
2824 |
|
| 3 |
liveuser |
2825 |
#有幾條線就執行幾次
|
|
|
2826 |
for($i=0;$i<count($conf["line"]);$i++){
|
| 226 |
liveuser |
2827 |
|
| 3 |
liveuser |
2828 |
#設置線條的x軸啟起點與終點坐標
|
|
|
2829 |
$line[]="#設置線條的x軸啟起點與終點坐標";
|
|
|
2830 |
$line[]="xp=c(".$conf["line"][$i]["startX"].",".$conf["line"][$i]["endX"].")";
|
| 226 |
liveuser |
2831 |
|
| 3 |
liveuser |
2832 |
#設置線條的y軸啟起點與終點坐標
|
|
|
2833 |
$line[]="#設置線條的y軸啟起點與終點坐標";
|
|
|
2834 |
$line[]="yp=c(".$conf["line"][$i]["startY"].",".$conf["line"][$i]["endY"].")";
|
| 226 |
liveuser |
2835 |
|
| 3 |
liveuser |
2836 |
#判斷 $conf["line"][$i]["color"]
|
|
|
2837 |
switch($conf["line"][$i]["color"]){
|
| 226 |
liveuser |
2838 |
|
| 3 |
liveuser |
2839 |
#如果是 "black"
|
|
|
2840 |
case "black":
|
| 226 |
liveuser |
2841 |
|
| 3 |
liveuser |
2842 |
#劃線
|
|
|
2843 |
$line[]="#劃線";
|
|
|
2844 |
$line[]="lines(xp,yp)";
|
| 226 |
liveuser |
2845 |
|
| 3 |
liveuser |
2846 |
#跳出 switch
|
|
|
2847 |
break;
|
| 226 |
liveuser |
2848 |
|
| 3 |
liveuser |
2849 |
#如果是 "green"
|
|
|
2850 |
case "green":
|
| 226 |
liveuser |
2851 |
|
| 3 |
liveuser |
2852 |
#劃綠色的線
|
|
|
2853 |
$line[]="#劃線綠色的線";
|
|
|
2854 |
$line[]="lines(xp,yp,col=3)";
|
| 226 |
liveuser |
2855 |
|
| 3 |
liveuser |
2856 |
#跳出 switch
|
|
|
2857 |
break;
|
| 226 |
liveuser |
2858 |
|
| 3 |
liveuser |
2859 |
#如果是 "red"
|
|
|
2860 |
case "red":
|
| 226 |
liveuser |
2861 |
|
| 3 |
liveuser |
2862 |
#劃紅色的線
|
|
|
2863 |
$line[]="#劃線紅色的線";
|
|
|
2864 |
$line[]="lines(xp,yp,col=2)";
|
| 226 |
liveuser |
2865 |
|
| 3 |
liveuser |
2866 |
#跳出 switch
|
|
|
2867 |
break;
|
| 226 |
liveuser |
2868 |
|
| 3 |
liveuser |
2869 |
#如果是其他
|
|
|
2870 |
default:
|
| 226 |
liveuser |
2871 |
|
| 3 |
liveuser |
2872 |
#設置執行不正常
|
|
|
2873 |
$result["status"]="false";
|
| 226 |
liveuser |
2874 |
|
| 3 |
liveuser |
2875 |
#設置執行錯誤訊息
|
|
|
2876 |
$result["error"][]="未知的顏色:".$conf["line"][$i]["color"];
|
| 226 |
liveuser |
2877 |
|
| 3 |
liveuser |
2878 |
#回傳結果
|
|
|
2879 |
return $result;
|
| 226 |
liveuser |
2880 |
|
| 3 |
liveuser |
2881 |
}#switch end
|
| 226 |
liveuser |
2882 |
|
| 3 |
liveuser |
2883 |
}#for end
|
| 226 |
liveuser |
2884 |
|
|
|
2885 |
}#if end
|
|
|
2886 |
|
| 3 |
liveuser |
2887 |
#如果有設置圖片寬度
|
|
|
2888 |
if(isset($conf["picWidth"])){
|
| 226 |
liveuser |
2889 |
|
| 3 |
liveuser |
2890 |
#設置圖片寬度的語法
|
|
|
2891 |
$conf["picWidth"]=",width=\"".$conf["picWidth"]."\"";
|
| 226 |
liveuser |
2892 |
|
|
|
2893 |
}#if end
|
|
|
2894 |
|
| 3 |
liveuser |
2895 |
#反之
|
|
|
2896 |
else{
|
| 226 |
liveuser |
2897 |
|
| 3 |
liveuser |
2898 |
#不設置圖片寬度
|
|
|
2899 |
$conf["picWidth"]="";
|
| 226 |
liveuser |
2900 |
|
| 3 |
liveuser |
2901 |
}#else end
|
| 226 |
liveuser |
2902 |
|
| 3 |
liveuser |
2903 |
#如果有設置圖片寬度
|
|
|
2904 |
if(isset($conf["picHeight"])){
|
| 226 |
liveuser |
2905 |
|
| 3 |
liveuser |
2906 |
#設置圖片寬度的語法
|
|
|
2907 |
$conf["picHeight"]=",Height=\"".$conf["picHeight"]."\"";
|
| 226 |
liveuser |
2908 |
|
|
|
2909 |
}#if end
|
|
|
2910 |
|
| 3 |
liveuser |
2911 |
#反之
|
|
|
2912 |
else{
|
| 226 |
liveuser |
2913 |
|
| 3 |
liveuser |
2914 |
#不設置圖片寬度
|
|
|
2915 |
$conf["picHeight"]="";
|
| 226 |
liveuser |
2916 |
|
| 3 |
liveuser |
2917 |
}#else end
|
| 226 |
liveuser |
2918 |
|
| 3 |
liveuser |
2919 |
#涵式說明:
|
|
|
2920 |
#建立R檔案
|
|
|
2921 |
#回傳的結果:
|
|
|
2922 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
|
|
|
2923 |
#$result["error"],錯誤訊息陣列.
|
|
|
2924 |
#$result["newCreatedRfilePathAndName"],R腳本檔的位置與名稱
|
|
|
2925 |
#必填的參數:
|
|
|
2926 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
2927 |
$conf["R.writeRfile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
2928 |
$conf["R.writeRfile"]["addAndName"]=".R/barplot-".$_SESSION["username"].".R";#R檔案的位置與名稱
|
|
|
2929 |
$conf["R.writeRfile"]["textToWrite"][]="#barplot長條圖";
|
|
|
2930 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
2931 |
$conf["R.writeRfile"]["textToWrite"][]="#欲繪出的資料頻率名稱";
|
|
|
2932 |
$conf["R.writeRfile"]["textToWrite"][]=$labels;
|
|
|
2933 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
2934 |
$conf["R.writeRfile"]["textToWrite"][]="#改用UTF-8去讀";
|
|
|
2935 |
$conf["R.writeRfile"]["textToWrite"][]="Encoding(timeLabel)<-\"UTF-8\"";
|
|
|
2936 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
2937 |
$conf["R.writeRfile"]["textToWrite"][]="#欲繪出的輔助說明內容";
|
|
|
2938 |
$conf["R.writeRfile"]["textToWrite"][]=$legendStr;
|
| 226 |
liveuser |
2939 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
| 3 |
liveuser |
2940 |
$conf["R.writeRfile"]["textToWrite"][]="#改用UTF-8去讀";
|
|
|
2941 |
$conf["R.writeRfile"]["textToWrite"][]="Encoding(legendStr)<-\"UTF-8\"";
|
|
|
2942 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
2943 |
$conf["R.writeRfile"]["textToWrite"][]="#要繪出的資料頻率";
|
|
|
2944 |
$conf["R.writeRfile"]["textToWrite"][]=$counts;
|
|
|
2945 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
2946 |
$conf["R.writeRfile"]["textToWrite"][]="#設置圖片輸出的設定";
|
|
|
2947 |
$conf["R.writeRfile"]["textToWrite"][]="svg(filename=\"".$conf["imgFileName"]."\"".$conf["picWidth"].$conf["picHeight"].")";
|
|
|
2948 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
2949 |
$conf["R.writeRfile"]["textToWrite"][]="#長條圖的標題";
|
|
|
2950 |
$conf["R.writeRfile"]["textToWrite"][]="barplotMain=c(\"".$conf["barPlotTitle"]."\")";
|
|
|
2951 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
2952 |
$conf["R.writeRfile"]["textToWrite"][]="#改用UTF-8去讀";
|
|
|
2953 |
$conf["R.writeRfile"]["textToWrite"][]="Encoding(barplotMain)<-\"UTF-8\"";
|
|
|
2954 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
2955 |
$conf["R.writeRfile"]["textToWrite"][]="#x軸標題";
|
|
|
2956 |
$conf["R.writeRfile"]["textToWrite"][]="xlabStr=c(\"".$conf["xlabName"]."\")";
|
|
|
2957 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
2958 |
$conf["R.writeRfile"]["textToWrite"][]="#改用UTF-8去讀";
|
|
|
2959 |
$conf["R.writeRfile"]["textToWrite"][]="Encoding(xlabStr)<-\"UTF-8\"";
|
|
|
2960 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
2961 |
$conf["R.writeRfile"]["textToWrite"][]="#y軸標題";
|
|
|
2962 |
$conf["R.writeRfile"]["textToWrite"][]="ylabStr=c(\"".$conf["ylabName"]."\")";
|
|
|
2963 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
2964 |
$conf["R.writeRfile"]["textToWrite"][]="#改用UTF-8去讀";
|
|
|
2965 |
$conf["R.writeRfile"]["textToWrite"][]="Encoding(ylabStr)<-\"UTF-8\"";
|
|
|
2966 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
2967 |
$conf["R.writeRfile"]["textToWrite"][]="#繪製長條圖";
|
|
|
2968 |
$conf["R.writeRfile"]["textToWrite"][]="#頻率資料爲count";
|
|
|
2969 |
$conf["R.writeRfile"]["textToWrite"][]="#頻率名稱資料爲timeLabel";
|
|
|
2970 |
$conf["R.writeRfile"]["textToWrite"][]="#圖的標題爲 \"一年內的每月的分佈\"";
|
|
|
2971 |
$conf["R.writeRfile"]["textToWrite"][]="#x軸標題爲 xlabStr";
|
|
|
2972 |
$conf["R.writeRfile"]["textToWrite"][]="#y軸標題爲 ylabStr";
|
|
|
2973 |
$conf["R.writeRfile"]["textToWrite"][]="#註解文字為 legendStr";
|
| 226 |
liveuser |
2974 |
|
| 3 |
liveuser |
2975 |
#如果要取消圖例
|
|
|
2976 |
if($conf["disableText"]=="true"){
|
| 226 |
liveuser |
2977 |
|
| 3 |
liveuser |
2978 |
#產生沒有圖例的長條圖
|
|
|
2979 |
$conf["R.writeRfile"]["textToWrite"][]="barplot(count,names=timeLabel,main=barplotMain,xlab=xlabStr,ylab=ylabStr)";
|
| 226 |
liveuser |
2980 |
|
| 3 |
liveuser |
2981 |
}#if end
|
| 226 |
liveuser |
2982 |
|
| 3 |
liveuser |
2983 |
#反之代表不取消圖例
|
|
|
2984 |
else{
|
| 226 |
liveuser |
2985 |
|
| 3 |
liveuser |
2986 |
#產生有圖例的長條圖
|
|
|
2987 |
$conf["R.writeRfile"]["textToWrite"][]="barplot(count,names=timeLabel,main=barplotMain,xlab=xlabStr,ylab=ylabStr,legend.text=legendStr)";
|
| 226 |
liveuser |
2988 |
|
| 3 |
liveuser |
2989 |
}#else end
|
| 226 |
liveuser |
2990 |
|
| 3 |
liveuser |
2991 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
| 226 |
liveuser |
2992 |
|
| 3 |
liveuser |
2993 |
#$line有幾個元素就執行幾次迴圈
|
|
|
2994 |
for($i=0;$i<count($line);$i++){
|
| 226 |
liveuser |
2995 |
|
| 3 |
liveuser |
2996 |
#存入劃線的R語法
|
|
|
2997 |
$conf["R.writeRfile"]["textToWrite"][]=$line[$i];
|
| 226 |
liveuser |
2998 |
|
| 3 |
liveuser |
2999 |
}#for end
|
| 226 |
liveuser |
3000 |
|
| 3 |
liveuser |
3001 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
3002 |
$conf["R.writeRfile"]["textToWrite"][]="#關閉繪圖裝置";
|
|
|
3003 |
$conf["R.writeRfile"]["textToWrite"][]="dev.off()";
|
|
|
3004 |
#$conf["textToWrite"],要寫入的字串內容陣列,一個元素代表一行文字,每行結尾會自動換行。
|
|
|
3005 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3006 |
$conf["R.writeRfile"]["fileArgu"]=$conf["fileArgu"];;
|
|
|
3007 |
$rScriptCreateResult=R::writeRfile($conf["R.writeRfile"]);
|
|
|
3008 |
unset($conf["R.writeRfile"]);
|
| 226 |
liveuser |
3009 |
|
| 3 |
liveuser |
3010 |
#如果R腳本檔建立失敗
|
|
|
3011 |
if($rScriptCreateResult["status"]=="false"){
|
| 226 |
liveuser |
3012 |
|
| 3 |
liveuser |
3013 |
#設置執行不正常
|
|
|
3014 |
$result["status"]="false";
|
| 226 |
liveuser |
3015 |
|
| 3 |
liveuser |
3016 |
#設置執行錯誤訊息
|
|
|
3017 |
$result["error"]=$rScriptCreateResult;
|
| 226 |
liveuser |
3018 |
|
| 3 |
liveuser |
3019 |
#回傳結果
|
|
|
3020 |
return $result;
|
| 226 |
liveuser |
3021 |
|
| 3 |
liveuser |
3022 |
}#if end
|
| 226 |
liveuser |
3023 |
|
| 3 |
liveuser |
3024 |
#執行R腳本
|
|
|
3025 |
#函式說明:
|
|
|
3026 |
#執行R腳本,執行完畢後,會刪除R的腳本與暫存R執行後的輸出的檔案.
|
|
|
3027 |
#回傳的結果:
|
|
|
3028 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3029 |
#$result["errror"],錯誤訊息陣列
|
|
|
3030 |
#$result["lineArray"],字串陣列,R輸出結果,每個元素代表一行的輸出.
|
|
|
3031 |
#$result["lineCount"],整數,R輸出的總共行數.
|
|
|
3032 |
#必填的參數:
|
|
|
3033 |
#$conf["rPositionAndName"],字串,R腳本的位置與名稱.
|
|
|
3034 |
$conf["R.executeR"]["rPositionAndName"]=$rScriptCreateResult["newCreatedRfilePathAndName"];
|
|
|
3035 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3036 |
$conf["R.executeR"]["fileArgu"]=$conf["fileArgu"];
|
|
|
3037 |
#可省略的參數:
|
|
|
3038 |
#$conf["disbaleOptimal"],字串,"true"代表取消輸出的優化,可以顯示版本訊息、歡迎訊息、儲存暫存檔,預設為"false"要進行優化.
|
|
|
3039 |
#$conf["disbaleOptimal"]="true";
|
|
|
3040 |
$executeRresult=R::executeR($conf["R.executeR"]);
|
|
|
3041 |
unset($conf["R.executeR"]);
|
| 226 |
liveuser |
3042 |
|
| 3 |
liveuser |
3043 |
#如果執行R失敗
|
|
|
3044 |
if($executeRresult["status"]=="false"){
|
| 226 |
liveuser |
3045 |
|
| 3 |
liveuser |
3046 |
#設置執行不正常
|
|
|
3047 |
$result["status"]="false";
|
| 226 |
liveuser |
3048 |
|
| 3 |
liveuser |
3049 |
#設置執行錯誤訊息
|
|
|
3050 |
$result["error"]=$executeRresult;
|
| 226 |
liveuser |
3051 |
|
| 3 |
liveuser |
3052 |
#回傳結果
|
|
|
3053 |
return $result;
|
| 226 |
liveuser |
3054 |
|
| 3 |
liveuser |
3055 |
}#if end
|
| 226 |
liveuser |
3056 |
|
| 3 |
liveuser |
3057 |
#檢查圖片檔案是否有產生
|
|
|
3058 |
#涵式說明:檢查多個檔案與資料夾是否存在.
|
|
|
3059 |
#回傳的結果:
|
|
|
3060 |
#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
|
|
|
3061 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
3062 |
#必填的參數:
|
|
|
3063 |
$conf["fileAccess.checkMultiFileExist"]["fileArray"]=array($conf["imgFileName"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
3064 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3065 |
$conf["fileAccess.checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
|
|
|
3066 |
#參考資料來源:
|
|
|
3067 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
3068 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
3069 |
$fileCheckResult=fileAccess::checkMultiFileExist($conf["fileAccess.checkMultiFileExist"]);
|
|
|
3070 |
unset($conf["fileAccess.checkMultiFileExist"]);
|
| 226 |
liveuser |
3071 |
|
| 3 |
liveuser |
3072 |
#如果要產生的圖片不存在
|
|
|
3073 |
if($fileCheckResult["varExist"][0]=="false"){
|
| 226 |
liveuser |
3074 |
|
| 3 |
liveuser |
3075 |
#設置執行不正常
|
|
|
3076 |
$result["status"]="false";
|
| 226 |
liveuser |
3077 |
|
| 3 |
liveuser |
3078 |
#設置執行錯誤訊息
|
|
|
3079 |
$result["error"]=$fileCheckResult;
|
| 226 |
liveuser |
3080 |
|
| 3 |
liveuser |
3081 |
#回傳結果
|
|
|
3082 |
return $result;
|
| 226 |
liveuser |
3083 |
|
| 3 |
liveuser |
3084 |
}#if end
|
| 226 |
liveuser |
3085 |
|
| 3 |
liveuser |
3086 |
#取得圖片位置與名稱
|
|
|
3087 |
$result["img"]=$conf["imgFileName"];
|
| 226 |
liveuser |
3088 |
|
| 3 |
liveuser |
3089 |
#函數說明:
|
|
|
3090 |
#用data:mimeType;base64,imgVar的形式來提供圖片的連結,亦即圖片儲存在變數裡面,本函式包含顯示圖片的語法.
|
|
|
3091 |
#回傳結果:
|
|
|
3092 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3093 |
#$result["error"],錯誤訊息
|
|
|
3094 |
#$result["content"],圖片的連結資訊
|
| 226 |
liveuser |
3095 |
#$result["function"],當前執行的函數名稱
|
| 3 |
liveuser |
3096 |
#必填參數:
|
|
|
3097 |
#$conf["img::data"]["imgPosition"],要轉存成2元碼的圖片檔案位置與名稱
|
|
|
3098 |
$conf["img::data"]["imgPosition"]=$conf["imgFileName"];
|
|
|
3099 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3100 |
$conf["img::data"]["fileArgu"]=$conf["fileArgu"];
|
|
|
3101 |
#可省略參數:
|
|
|
3102 |
#$conf["alt"],若沒有圖片要用什麼文字顯示。
|
|
|
3103 |
#$conf["alt"]="";
|
|
|
3104 |
#$conf["style"],字串陣列,要使用的style,key為樣式名稱,value為樣式值.
|
|
|
3105 |
$conf["img::data"]["style"]=array("width"=>"100%");
|
|
|
3106 |
#$conf["class"],圖片要套用的css樣式名稱.
|
|
|
3107 |
#$conf["class"]="";
|
|
|
3108 |
#$conf["mimeType"],2元碼的內容是什麼,預設為"image/*".
|
|
|
3109 |
$conf["img::data"]["mimeType"]="image/svg+xml";
|
|
|
3110 |
#$conf["compressType"],2元碼壓縮的方式,預設為"base64".
|
|
|
3111 |
#$conf["compressType"]="base64";
|
|
|
3112 |
#$conf["delImg"],讀取完圖片檔案後,要移除圖片嗎?"true"代表要移除,"false"代表不要移除,預設為"false".
|
|
|
3113 |
$conf["img::data"]["delImg"]=$conf["del"];
|
|
|
3114 |
#參考資料:
|
|
|
3115 |
#將檔案用字串變數儲存起來=>http://php.net/manual/en/function.file-get-contents.php
|
|
|
3116 |
#壓縮2元碼=>http://php.net/manual/en/function.base64-encode.php
|
|
|
3117 |
$data=img::data($conf["img::data"]);
|
| 226 |
liveuser |
3118 |
unset($conf["img::data"]);
|
|
|
3119 |
|
| 3 |
liveuser |
3120 |
#如果顯示圖片失敗
|
|
|
3121 |
if($data["status"]=="false"){
|
| 226 |
liveuser |
3122 |
|
| 3 |
liveuser |
3123 |
#設置執行失敗
|
|
|
3124 |
$result["status"]="false";
|
| 226 |
liveuser |
3125 |
|
| 3 |
liveuser |
3126 |
#設置執行錯誤訊息
|
|
|
3127 |
$result["error"]=$data;
|
| 226 |
liveuser |
3128 |
|
| 3 |
liveuser |
3129 |
#回傳結果
|
|
|
3130 |
return $result;
|
| 226 |
liveuser |
3131 |
|
|
|
3132 |
}#if end
|
|
|
3133 |
|
| 3 |
liveuser |
3134 |
#取得顯示圖片的語法
|
| 226 |
liveuser |
3135 |
$result["content"]=$data["content"];
|
|
|
3136 |
|
| 3 |
liveuser |
3137 |
#執行到這邊代表執行正常
|
|
|
3138 |
$result["status"]="true";
|
| 226 |
liveuser |
3139 |
|
| 3 |
liveuser |
3140 |
#回傳結果
|
| 226 |
liveuser |
3141 |
return $result;
|
|
|
3142 |
|
| 3 |
liveuser |
3143 |
}#function createBarPlot end
|
| 226 |
liveuser |
3144 |
|
| 3 |
liveuser |
3145 |
/*
|
|
|
3146 |
#函式說明
|
|
|
3147 |
#繪製直方圖
|
|
|
3148 |
#回傳結果:
|
|
|
3149 |
#$result["status"],執行正常與否,"true"代表正常;"false"代表不正常
|
|
|
3150 |
#$result["error"],錯誤訊息陣列
|
|
|
3151 |
#$result["function"],當前函數名稱
|
|
|
3152 |
#$result["img"],圖片的位置與名稱
|
|
|
3153 |
#$result["content"],放置圖片的語法
|
|
|
3154 |
#必填參數:
|
|
|
3155 |
#$conf["numArray"],字串陣列,要進行分組統計的原始資料
|
|
|
3156 |
$conf["numArray"]=array();
|
|
|
3157 |
#$conf["classCount"],字串,資料要分成幾組
|
| 226 |
liveuser |
3158 |
$conf["classCount"]="5";
|
| 3 |
liveuser |
3159 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3160 |
$conf["fileArgu"]=__FILE__;
|
|
|
3161 |
#可省略參數:
|
|
|
3162 |
#$conf["imgFileName"],字串,圖片存放的位置與名稱,預設爲 "hist-".$SESSION["username"]."svg"
|
|
|
3163 |
#$conf["imgFileName"]=".R/hist-".$SESSION["username"]."svg";
|
|
|
3164 |
#$conf["del"],字串,讀取完圖片之後是否要移除之,"ture"代表要,"false"代表不要,預設為"true"代表要.
|
|
|
3165 |
#$conf["del"]="";
|
|
|
3166 |
#$conf["histTitle"],字串,長條圖的標題,預設爲空。
|
|
|
3167 |
#$conf["histTitle"]="";
|
|
|
3168 |
#$conf["xlabName"],x軸的名稱,預設爲區間
|
|
|
3169 |
#$conf["xlabName"]="區間";
|
|
|
3170 |
#$conf["ylabName"],y軸的名稱,預設爲頻率
|
|
|
3171 |
#$conf["ylabName"]="頻率";
|
|
|
3172 |
#參考資料:
|
|
|
3173 |
#無.
|
|
|
3174 |
#備註:
|
|
|
3175 |
#無
|
|
|
3176 |
*/
|
|
|
3177 |
public static function createHist(&$conf=array()){
|
| 226 |
liveuser |
3178 |
|
| 3 |
liveuser |
3179 |
#初始化要回傳的內容
|
|
|
3180 |
$result=array();
|
| 226 |
liveuser |
3181 |
|
| 3 |
liveuser |
3182 |
#取得當前函數名稱
|
|
|
3183 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
3184 |
|
| 3 |
liveuser |
3185 |
#如果 $conf 不為陣列
|
|
|
3186 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
3187 |
|
| 3 |
liveuser |
3188 |
#設置執行失敗
|
|
|
3189 |
$result["status"]="false";
|
| 226 |
liveuser |
3190 |
|
| 3 |
liveuser |
3191 |
#設置執行錯誤訊息
|
|
|
3192 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
3193 |
|
|
|
3194 |
#如果傳入的參數為 null
|
|
|
3195 |
if($conf==null){
|
| 226 |
liveuser |
3196 |
|
| 3 |
liveuser |
3197 |
#設置執行錯誤訊息
|
|
|
3198 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
3199 |
|
| 3 |
liveuser |
3200 |
}#if end
|
|
|
3201 |
|
|
|
3202 |
#回傳結果
|
|
|
3203 |
return $result;
|
| 226 |
liveuser |
3204 |
|
| 3 |
liveuser |
3205 |
}#if end
|
| 226 |
liveuser |
3206 |
|
| 3 |
liveuser |
3207 |
#檢查必填的參數
|
|
|
3208 |
#涵式說明:
|
|
|
3209 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
3210 |
#回傳的結果:
|
|
|
3211 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3212 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3213 |
#$result["function"],當前執行的函式名稱.
|
|
|
3214 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
3215 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
3216 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
3217 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
3218 |
#必填寫的參數:
|
|
|
3219 |
$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
3220 |
$conf["variableCheck.isexistMulti"]["variableCheck"]=array("numArray","fileArgu");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
3221 |
#可以省略的參數:
|
| 226 |
liveuser |
3222 |
$conf["variableCheck.isexistMulti"]["variableType"]=array("array","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
3223 |
$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
3224 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
|
|
|
3225 |
unset($conf["variableCheck.isexistMulti"]);
|
| 226 |
liveuser |
3226 |
|
| 3 |
liveuser |
3227 |
#如果檢查失敗
|
|
|
3228 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
3229 |
|
| 3 |
liveuser |
3230 |
#設置執行不正常
|
|
|
3231 |
$result["status"]="false";
|
| 226 |
liveuser |
3232 |
|
| 3 |
liveuser |
3233 |
#設置執行錯誤訊息
|
|
|
3234 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
3235 |
|
| 3 |
liveuser |
3236 |
#回傳結果
|
|
|
3237 |
return $result;
|
| 226 |
liveuser |
3238 |
|
| 3 |
liveuser |
3239 |
}#if end
|
| 226 |
liveuser |
3240 |
|
| 3 |
liveuser |
3241 |
#如果檢查不通過
|
|
|
3242 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
3243 |
|
| 3 |
liveuser |
3244 |
#設置執行不正常
|
|
|
3245 |
$result["status"]="false";
|
| 226 |
liveuser |
3246 |
|
| 3 |
liveuser |
3247 |
#設置執行錯誤訊息
|
|
|
3248 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
3249 |
|
| 3 |
liveuser |
3250 |
#回傳結果
|
|
|
3251 |
return $result;
|
| 226 |
liveuser |
3252 |
|
| 3 |
liveuser |
3253 |
}#if end
|
| 226 |
liveuser |
3254 |
|
| 3 |
liveuser |
3255 |
#檢查可省略的參數
|
|
|
3256 |
#函式說明:
|
|
|
3257 |
#檢查一包含數個可省略變數的陣列變數,其型態是否正確,省略掉的陣列變數可以直接給定預設值。
|
|
|
3258 |
#回傳結果:
|
|
|
3259 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3260 |
#$result["error"],錯誤訊息陣列.
|
|
|
3261 |
#$result["function"],當前執行的函式名稱.
|
|
|
3262 |
#$result["passed"],參數是否都通過檢查,"true",代表有通過檢查,"false"代表沒有通過檢查。
|
|
|
3263 |
#必填參數:
|
|
|
3264 |
#$conf["checkedVar"],陣列,要檢查的變數陣列名稱為?
|
|
|
3265 |
$conf["variableCheck.checkSkipableVarType"]["checkedVar"]=$conf;
|
|
|
3266 |
#$conf["sikpableVarNameArray"],字串陣列,要檢查型態是否設定正確的變數名稱陣列.
|
|
|
3267 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"]=array("imgFileName","del","histTitle","xlabName","ylabName");
|
|
|
3268 |
#$conf["skipableVarTypeArray"],字串陣列,要檢查的每個變數,其型態應該要為何?
|
|
|
3269 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"]=array("string","string","string","string","string");
|
|
|
3270 |
#$argu,要直接存取的陣列變數名稱,變數前面加上「&」,如果要在別的函式裡面使用本函式,請記得將變動過結果($argu)給使用該函式的設定變數(通常是$conf=$argu).
|
|
|
3271 |
$argu=&$conf;
|
|
|
3272 |
#可省略參數:
|
|
|
3273 |
#$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"],字串陣列,每個不存的變數要初始化為什麼,"null"代表不指定.
|
|
|
3274 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"]=array(".R/hist-".$_SESSION["username"].".svg","true"," ","區間","頻率");
|
|
|
3275 |
#無
|
|
|
3276 |
$checkResult=variableCheck::checkSkipableVarType($conf["variableCheck.checkSkipableVarType"],$argu);
|
|
|
3277 |
unset($conf["variableCheck.checkSkipableVarType"]);
|
| 226 |
liveuser |
3278 |
|
| 3 |
liveuser |
3279 |
#如果檢查失敗
|
|
|
3280 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
3281 |
|
| 3 |
liveuser |
3282 |
#設置執行不正常
|
|
|
3283 |
$result["status"]="false";
|
| 226 |
liveuser |
3284 |
|
| 3 |
liveuser |
3285 |
#設置執行錯誤訊息
|
|
|
3286 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
3287 |
|
| 3 |
liveuser |
3288 |
#回傳結果
|
|
|
3289 |
return $result;
|
| 226 |
liveuser |
3290 |
|
| 3 |
liveuser |
3291 |
}#if end
|
| 226 |
liveuser |
3292 |
|
| 3 |
liveuser |
3293 |
#如果檢查不通過
|
|
|
3294 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
3295 |
|
| 3 |
liveuser |
3296 |
#設置執行不正常
|
|
|
3297 |
$result["status"]="false";
|
| 226 |
liveuser |
3298 |
|
| 3 |
liveuser |
3299 |
#設置執行錯誤訊息
|
|
|
3300 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
3301 |
|
| 3 |
liveuser |
3302 |
#回傳結果
|
|
|
3303 |
return $result;
|
| 226 |
liveuser |
3304 |
|
| 3 |
liveuser |
3305 |
}#if end
|
| 226 |
liveuser |
3306 |
|
| 3 |
liveuser |
3307 |
#初始化 要進行統計的數字資料
|
|
|
3308 |
$numData="numData=c(";
|
| 226 |
liveuser |
3309 |
|
| 3 |
liveuser |
3310 |
#有幾個比例陣列就執行幾次
|
|
|
3311 |
for($i=0;$i<count($conf["numArray"]);$i++){
|
| 226 |
liveuser |
3312 |
|
| 3 |
liveuser |
3313 |
#如果不是最後一個比例
|
|
|
3314 |
if($i!=count($conf["numArray"])-1){
|
| 226 |
liveuser |
3315 |
|
| 3 |
liveuser |
3316 |
#串接比例,結尾加逗號
|
|
|
3317 |
$numData=$numData.$conf["numArray"][$i].",";
|
| 226 |
liveuser |
3318 |
|
| 3 |
liveuser |
3319 |
}#if end
|
| 226 |
liveuser |
3320 |
|
| 3 |
liveuser |
3321 |
#反之是最後一個比例
|
|
|
3322 |
else{
|
| 226 |
liveuser |
3323 |
|
| 3 |
liveuser |
3324 |
#串接比例,最後面加上)
|
|
|
3325 |
$numData=$numData.$conf["numArray"][$i].")";
|
| 226 |
liveuser |
3326 |
|
| 3 |
liveuser |
3327 |
}#else end
|
| 226 |
liveuser |
3328 |
|
| 3 |
liveuser |
3329 |
}#for end
|
| 226 |
liveuser |
3330 |
|
| 3 |
liveuser |
3331 |
#涵式說明:
|
|
|
3332 |
#建立R檔案
|
|
|
3333 |
#回傳的結果:
|
|
|
3334 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
|
|
|
3335 |
#$result["error"],錯誤訊息陣列.
|
|
|
3336 |
#$result["newCreatedRfilePathAndName"],R腳本檔的位置與名稱
|
|
|
3337 |
#必填的參數:
|
|
|
3338 |
$conf["R.writeRfile"]["addAndName"]=".R/hist-".$_SESSION["username"].".R";#R檔案的位置與名稱
|
|
|
3339 |
$conf["R.writeRfile"]["textToWrite"][]="#hist直方圖";
|
|
|
3340 |
$conf["R.writeRfile"]["textToWrite"][]="#將原始數字向量進行分組";
|
|
|
3341 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
3342 |
$conf["R.writeRfile"]["textToWrite"][]="#要分組的資料內容";
|
|
|
3343 |
$conf["R.writeRfile"]["textToWrite"][]=$numData;
|
|
|
3344 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
3345 |
$conf["R.writeRfile"]["textToWrite"][]="#設置圖片輸出的設定";
|
|
|
3346 |
$conf["R.writeRfile"]["textToWrite"][]="svg(filename=\"".$conf["imgFileName"]."\")";
|
|
|
3347 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
3348 |
$conf["R.writeRfile"]["textToWrite"][]="#直方圖的標題";
|
|
|
3349 |
$conf["R.writeRfile"]["textToWrite"][]="histMain=c(\"".$conf["histTitle"]."\")";
|
|
|
3350 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
3351 |
$conf["R.writeRfile"]["textToWrite"][]="#改用UTF-8去讀";
|
|
|
3352 |
$conf["R.writeRfile"]["textToWrite"][]="Encoding(histMain)<-\"UTF-8\"";
|
|
|
3353 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
3354 |
$conf["R.writeRfile"]["textToWrite"][]="#x軸標題";
|
|
|
3355 |
$conf["R.writeRfile"]["textToWrite"][]="xlabStr=c(\"".$conf["xlabName"]."\")";
|
|
|
3356 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
3357 |
$conf["R.writeRfile"]["textToWrite"][]="#改用UTF-8去讀";
|
|
|
3358 |
$conf["R.writeRfile"]["textToWrite"][]="Encoding(xlabStr)<-\"UTF-8\"";
|
|
|
3359 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
3360 |
$conf["R.writeRfile"]["textToWrite"][]="#y軸標題";
|
|
|
3361 |
$conf["R.writeRfile"]["textToWrite"][]="ylabStr=c(\"".$conf["ylabName"]."\")";
|
|
|
3362 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
3363 |
$conf["R.writeRfile"]["textToWrite"][]="#改用UTF-8去讀";
|
|
|
3364 |
$conf["R.writeRfile"]["textToWrite"][]="Encoding(ylabStr)<-\"UTF-8\"";
|
|
|
3365 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
3366 |
$conf["R.writeRfile"]["textToWrite"][]="#繪製直方圖";
|
|
|
3367 |
$conf["R.writeRfile"]["textToWrite"][]="#要分組的資料爲numData";
|
|
|
3368 |
$conf["R.writeRfile"]["textToWrite"][]="#圖的標題爲 \"一年內的每月的分佈\"";
|
|
|
3369 |
$conf["R.writeRfile"]["textToWrite"][]="#x軸標題爲 \"出現月份\"";
|
|
|
3370 |
$conf["R.writeRfile"]["textToWrite"][]="#y軸標題爲 \"出現頻率\"";
|
|
|
3371 |
$conf["R.writeRfile"]["textToWrite"][]="hist(numData,nclass=".$conf["classCount"].",main=histMain,xlab=xlabStr,ylab=ylabStr)";
|
|
|
3372 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
3373 |
$conf["R.writeRfile"]["textToWrite"][]="#關閉繪圖裝置";
|
|
|
3374 |
$conf["R.writeRfile"]["textToWrite"][]="dev.off()";
|
|
|
3375 |
#$conf["textToWrite"],要寫入的字串內容陣列,一個元素代表一行文字,每行結尾會自動換行。
|
|
|
3376 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3377 |
$conf["R.writeRfile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
3378 |
$rScriptCreateResult=R::writeRfile($conf["R.writeRfile"]);
|
|
|
3379 |
unset($conf["R.writeRfile"]);
|
| 226 |
liveuser |
3380 |
|
| 3 |
liveuser |
3381 |
#如果R腳本檔建立失敗
|
|
|
3382 |
if($rScriptCreateResult["status"]=="false"){
|
| 226 |
liveuser |
3383 |
|
| 3 |
liveuser |
3384 |
#設置執行不正常
|
|
|
3385 |
$result["status"]="false";
|
| 226 |
liveuser |
3386 |
|
| 3 |
liveuser |
3387 |
#設置執行錯誤訊息
|
|
|
3388 |
$result["error"]=$rScriptCreateResult;
|
| 226 |
liveuser |
3389 |
|
| 3 |
liveuser |
3390 |
#回傳結果
|
|
|
3391 |
return $result;
|
| 226 |
liveuser |
3392 |
|
| 3 |
liveuser |
3393 |
}#if end
|
| 226 |
liveuser |
3394 |
|
| 3 |
liveuser |
3395 |
#執行R腳本
|
|
|
3396 |
#函式說明:
|
|
|
3397 |
#執行R腳本,執行完畢後,會刪除R的腳本與暫存R執行後的輸出的檔案.
|
|
|
3398 |
#回傳的結果:
|
|
|
3399 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3400 |
#$result["errror"],錯誤訊息陣列
|
|
|
3401 |
#$result["lineArray"],字串陣列,R輸出結果,每個元素代表一行的輸出.
|
|
|
3402 |
#$result["lineCount"],整數,R輸出的總共行數.
|
|
|
3403 |
#必填的參數:
|
|
|
3404 |
#$conf["rPositionAndName"],字串,R腳本的位置與名稱.
|
|
|
3405 |
$conf["R.executeR"]["rPositionAndName"]=$rScriptCreateResult["newCreatedRfilePathAndName"];
|
|
|
3406 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3407 |
$conf["R.executeR"]["fileArgu"]=$conf["fileArgu"];
|
|
|
3408 |
#可省略的參數:
|
|
|
3409 |
#$conf["disbaleOptimal"],字串,"true"代表取消輸出的優化,可以顯示版本訊息、歡迎訊息、儲存暫存檔,預設為"false"要進行優化.
|
|
|
3410 |
#$conf["disbaleOptimal"]="true";
|
|
|
3411 |
$executeRresult=R::executeR($conf["R.executeR"]);
|
|
|
3412 |
unset($conf["R.executeR"]);
|
| 226 |
liveuser |
3413 |
|
| 3 |
liveuser |
3414 |
#如果執行R失敗
|
|
|
3415 |
if($executeRresult["status"]=="false"){
|
| 226 |
liveuser |
3416 |
|
| 3 |
liveuser |
3417 |
#設置執行不正常
|
|
|
3418 |
$result["status"]="false";
|
| 226 |
liveuser |
3419 |
|
| 3 |
liveuser |
3420 |
#設置執行錯誤訊息
|
|
|
3421 |
$result["error"]=$executeRresult;
|
| 226 |
liveuser |
3422 |
|
| 3 |
liveuser |
3423 |
#回傳結果
|
|
|
3424 |
return $result;
|
| 226 |
liveuser |
3425 |
|
| 3 |
liveuser |
3426 |
}#if end
|
| 226 |
liveuser |
3427 |
|
| 3 |
liveuser |
3428 |
#檢查圖片檔案是否有產生
|
|
|
3429 |
#涵式說明:檢查多個檔案與資料夾是否存在.
|
|
|
3430 |
#回傳的結果:
|
|
|
3431 |
#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
|
|
|
3432 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
3433 |
#必填的參數:
|
|
|
3434 |
$conf["fileAccess.checkMultiFileExist"]["fileArray"]=array($conf["imgFileName"]);#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
3435 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3436 |
$conf["fileAccess.checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
|
|
|
3437 |
#參考資料來源:
|
|
|
3438 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
3439 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
3440 |
$fileCheckResult=fileAccess::checkMultiFileExist($conf["fileAccess.checkMultiFileExist"]);
|
|
|
3441 |
unset($conf["fileAccess.checkMultiFileExist"]);
|
| 226 |
liveuser |
3442 |
|
| 3 |
liveuser |
3443 |
#如果要產生的圖片不存在
|
|
|
3444 |
if($fileCheckResult["varExist"][0]=="false"){
|
| 226 |
liveuser |
3445 |
|
| 3 |
liveuser |
3446 |
#設置執行不正常
|
|
|
3447 |
$result["status"]="false";
|
| 226 |
liveuser |
3448 |
|
| 3 |
liveuser |
3449 |
#設置執行錯誤訊息
|
|
|
3450 |
$result["error"]=$fileCheckResult;
|
| 226 |
liveuser |
3451 |
|
| 3 |
liveuser |
3452 |
#回傳結果
|
|
|
3453 |
return $result;
|
| 226 |
liveuser |
3454 |
|
| 3 |
liveuser |
3455 |
}#if end
|
| 226 |
liveuser |
3456 |
|
| 3 |
liveuser |
3457 |
#取得圖片位置與名稱
|
|
|
3458 |
$result["img"]=$conf["imgFileName"];
|
| 226 |
liveuser |
3459 |
|
| 3 |
liveuser |
3460 |
#函數說明:
|
|
|
3461 |
#用data:mimeType;base64,imgVar的形式來提供圖片的連結,亦即圖片儲存在變數裡面,本函式包含顯示圖片的語法.
|
|
|
3462 |
#回傳結果:
|
|
|
3463 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3464 |
#$result["error"],錯誤訊息
|
|
|
3465 |
#$result["content"],圖片的連結資訊
|
| 226 |
liveuser |
3466 |
#$result["function"],當前執行的函數名稱
|
| 3 |
liveuser |
3467 |
#必填參數:
|
|
|
3468 |
#$conf["img::data"]["imgPosition"],要轉存成2元碼的圖片檔案位置與名稱
|
|
|
3469 |
$conf["img::data"]["imgPosition"]=$conf["imgFileName"];
|
|
|
3470 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3471 |
$conf["img::data"]["fileArgu"]=$conf["fileArgu"];
|
|
|
3472 |
#可省略參數:
|
|
|
3473 |
#$conf["alt"],若沒有圖片要用什麼文字顯示。
|
|
|
3474 |
#$conf["alt"]="";
|
|
|
3475 |
#$conf["style"],字串陣列,要使用的style,key為樣式名稱,value為樣式值.
|
|
|
3476 |
$conf["img::data"]["style"]=array("width"=>"100%");
|
|
|
3477 |
#$conf["class"],圖片要套用的css樣式名稱.
|
|
|
3478 |
#$conf["class"]="";
|
|
|
3479 |
#$conf["mimeType"],2元碼的內容是什麼,預設為"image/*".
|
|
|
3480 |
$conf["img::data"]["mimeType"]="image/svg+xml";
|
|
|
3481 |
#$conf["compressType"],2元碼壓縮的方式,預設為"base64".
|
|
|
3482 |
#$conf["compressType"]="base64";
|
|
|
3483 |
#$conf["delImg"],讀取完圖片檔案後,要移除圖片嗎?"true"代表要移除,"false"代表不要移除,預設為"false".
|
|
|
3484 |
$conf["img::data"]["delImg"]=$conf["del"];
|
|
|
3485 |
#參考資料:
|
|
|
3486 |
#將檔案用字串變數儲存起來=>http://php.net/manual/en/function.file-get-contents.php
|
|
|
3487 |
#壓縮2元碼=>http://php.net/manual/en/function.base64-encode.php
|
|
|
3488 |
$data=img::data($conf["img::data"]);
|
| 226 |
liveuser |
3489 |
unset($conf["img::data"]);
|
|
|
3490 |
|
| 3 |
liveuser |
3491 |
#如果顯示圖片失敗
|
|
|
3492 |
if($data["status"]=="false"){
|
| 226 |
liveuser |
3493 |
|
| 3 |
liveuser |
3494 |
#設置執行失敗
|
|
|
3495 |
$result["status"]="false";
|
| 226 |
liveuser |
3496 |
|
| 3 |
liveuser |
3497 |
#設置執行錯誤訊息
|
|
|
3498 |
$result["error"]=$data;
|
| 226 |
liveuser |
3499 |
|
| 3 |
liveuser |
3500 |
#回傳結果
|
|
|
3501 |
return $result;
|
| 226 |
liveuser |
3502 |
|
|
|
3503 |
}#if end
|
|
|
3504 |
|
| 3 |
liveuser |
3505 |
#取得顯示圖片的語法
|
| 226 |
liveuser |
3506 |
$result["content"]=$data["content"];
|
|
|
3507 |
|
| 3 |
liveuser |
3508 |
#執行到這邊代表執行正常
|
|
|
3509 |
$result["status"]="true";
|
| 226 |
liveuser |
3510 |
|
| 3 |
liveuser |
3511 |
#回傳結果
|
|
|
3512 |
return $result;
|
| 226 |
liveuser |
3513 |
|
| 3 |
liveuser |
3514 |
}#function createHist end
|
| 226 |
liveuser |
3515 |
|
| 3 |
liveuser |
3516 |
/*
|
|
|
3517 |
#函式說明:
|
|
|
3518 |
#運用apriori進行關聯分析,用來分析多個名目變數選項組合預測某個行爲的,支持度,信度,解釋力,分析結果會排除其中一個條件或結果變數爲空值者。
|
|
|
3519 |
#回傳結果:
|
|
|
3520 |
#$result["status"],執行正常與否,"true"代表正常;"false"代表不正常
|
|
|
3521 |
#$result["error"],錯誤訊息陣列
|
|
|
3522 |
#$result["function"],當前函數名稱
|
|
|
3523 |
#$result["oriOutPut"],R原始的分析結果輸出
|
|
|
3524 |
#$result["content"],分析結果
|
|
|
3525 |
#$result["content"]["rulesCount"],記錄總共有幾筆關聯規則
|
|
|
3526 |
#$result["content"]["rulesArray"],規則的內容
|
|
|
3527 |
#$result["content"]["rulesArray"][$i],代表第$i+1個規則的內容陣列
|
|
|
3528 |
#$result["content"]["rulesArray"][$i]["lhsName"][$j],表第$i+1個規則的第$j+1個條件的名稱
|
|
|
3529 |
#$result["content"]["rulesArray"][$i]["lhsValue"][$j],表第$i+1個規則的第$j+1個條件名稱對應的數值內容
|
|
|
3530 |
#$result["content"]["rulesArray"][$i]["rhsName"][$j],表第$i+1個規則的第$j+1個結果的名稱
|
|
|
3531 |
#$result["content"]["rulesArray"][$i]["rhsValue"][$j],表第$i+1個規則的第$j+1個結果名稱對應的數值內容
|
|
|
3532 |
#$result["content"]["rulesArray"][$i]["support"],表示$i+1個規則的support值
|
|
|
3533 |
#$result["content"]["rulesArray"][$i]["confidence"],表示$i+1個規則的support值
|
|
|
3534 |
#$result["content"]["rulesArray"][$i]["lift"],表示$i+1個規則的support值
|
|
|
3535 |
#必填參數:
|
|
|
3536 |
#$conf["csvFile"],字串,要讀取的csv檔位置與名稱,欄位數量必須大於2欄.
|
|
|
3537 |
$conf["csvFile"]="";
|
|
|
3538 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3539 |
$conf["fileArgu"]=__FILE__;
|
|
|
3540 |
#可省略參數:
|
|
|
3541 |
#$conf["forecastVarName"],字串,指定多個要預測變數名稱,預設不指定.
|
|
|
3542 |
#$conf["forecastVarName"]="";
|
|
|
3543 |
#$conf["forecastVarValueArray"],字串陣列,指定預測的變數要等於哪些數值,預設不指定,若指定則至少要有兩個元素.
|
|
|
3544 |
#$conf["forecastVarValueArray"]=array();
|
|
|
3545 |
#$conf["support"],字串,支持度要多少,ex:"0.05".
|
|
|
3546 |
#$conf["support"]="";
|
|
|
3547 |
#$conf["confidence"],字串,信度要多少,ex:"0.8".
|
|
|
3548 |
#$conf["confidence"]="";
|
|
|
3549 |
#參考資料:
|
|
|
3550 |
#無.
|
|
|
3551 |
#備註:
|
|
|
3552 |
#無
|
|
|
3553 |
*/
|
|
|
3554 |
public static function apriori(&$conf){
|
| 226 |
liveuser |
3555 |
|
| 3 |
liveuser |
3556 |
#初始化要回傳的內容
|
|
|
3557 |
$result=array();
|
| 226 |
liveuser |
3558 |
|
| 3 |
liveuser |
3559 |
#取得當前函數名稱
|
|
|
3560 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
3561 |
|
| 3 |
liveuser |
3562 |
#如果 $conf 不為陣列
|
|
|
3563 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
3564 |
|
| 3 |
liveuser |
3565 |
#設置執行失敗
|
|
|
3566 |
$result["status"]="false";
|
| 226 |
liveuser |
3567 |
|
| 3 |
liveuser |
3568 |
#設置執行錯誤訊息
|
|
|
3569 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
3570 |
|
|
|
3571 |
#如果傳入的參數為 null
|
|
|
3572 |
if($conf==null){
|
| 226 |
liveuser |
3573 |
|
| 3 |
liveuser |
3574 |
#設置執行錯誤訊息
|
|
|
3575 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
3576 |
|
| 3 |
liveuser |
3577 |
}#if end
|
|
|
3578 |
|
|
|
3579 |
#回傳結果
|
|
|
3580 |
return $result;
|
| 226 |
liveuser |
3581 |
|
| 3 |
liveuser |
3582 |
}#if end
|
| 226 |
liveuser |
3583 |
|
| 3 |
liveuser |
3584 |
#檢查必填參數
|
|
|
3585 |
#涵式說明:
|
|
|
3586 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
3587 |
#回傳的結果:
|
|
|
3588 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3589 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
3590 |
#$result["function"],當前執行的函式名稱.
|
|
|
3591 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
3592 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
3593 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
3594 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
3595 |
#必填寫的參數:
|
|
|
3596 |
$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
3597 |
$conf["variableCheck.isexistMulti"]["variableCheck"]=array("csvFile","fileArgu");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
3598 |
#可以省略的參數:
|
| 226 |
liveuser |
3599 |
$conf["variableCheck.isexistMulti"]["variableType"]=array("string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
3600 |
$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
3601 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
|
|
|
3602 |
unset($conf["variableCheck.isexistMulti"]);
|
| 226 |
liveuser |
3603 |
|
| 3 |
liveuser |
3604 |
#如果檢查失敗
|
|
|
3605 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
3606 |
|
| 3 |
liveuser |
3607 |
#設置執行不正常
|
|
|
3608 |
$result["status"]="false";
|
| 226 |
liveuser |
3609 |
|
| 3 |
liveuser |
3610 |
#設置執行錯誤訊息
|
|
|
3611 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
3612 |
|
| 3 |
liveuser |
3613 |
#回傳結果
|
|
|
3614 |
return $result;
|
| 226 |
liveuser |
3615 |
|
| 3 |
liveuser |
3616 |
}#if end
|
| 226 |
liveuser |
3617 |
|
| 3 |
liveuser |
3618 |
#如果檢查不通過
|
|
|
3619 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
3620 |
|
| 3 |
liveuser |
3621 |
#設置執行不正常
|
|
|
3622 |
$result["status"]="false";
|
| 226 |
liveuser |
3623 |
|
| 3 |
liveuser |
3624 |
#設置執行錯誤訊息
|
|
|
3625 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
3626 |
|
| 3 |
liveuser |
3627 |
#回傳結果
|
|
|
3628 |
return $result;
|
| 226 |
liveuser |
3629 |
|
| 3 |
liveuser |
3630 |
}#if end
|
| 226 |
liveuser |
3631 |
|
| 3 |
liveuser |
3632 |
#檢查可省略的參數
|
|
|
3633 |
#函式說明:
|
|
|
3634 |
#檢查一包含數個可省略變數的陣列變數,其型態是否正確,省略掉的陣列變數可以直接給定預設值。
|
|
|
3635 |
#回傳結果:
|
|
|
3636 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3637 |
#$result["error"],錯誤訊息陣列.
|
|
|
3638 |
#$result["function"],當前執行的函式名稱.
|
|
|
3639 |
#$result["passed"],參數是否都通過檢查,"true",代表有通過檢查,"false"代表沒有通過檢查。
|
|
|
3640 |
#必填參數:
|
|
|
3641 |
#$conf["checkedVar"],陣列,要檢查的變數陣列名稱為?
|
|
|
3642 |
$conf["variableCheck.checkSkipableVarType"]["checkedVar"]=$conf;
|
|
|
3643 |
#$conf["sikpableVarNameArray"],字串陣列,要檢查型態是否設定正確的變數名稱陣列.
|
|
|
3644 |
$conf["variableCheck.checkSkipableVarType"]["sikpableVarNameArray"]=array("forecastVarName","forecastVarValueArray","support","confidence","lift");
|
|
|
3645 |
#$conf["skipableVarTypeArray"],字串陣列,要檢查的每個變數,其型態應該要為何?
|
|
|
3646 |
$conf["variableCheck.checkSkipableVarType"]["skipableVarTypeArray"]=array("string","array","string","string","string");
|
|
|
3647 |
#$argu,要直接存取的陣列變數名稱,變數前面加上「&」,如果要在別的函式裡面使用本函式,請記得將變動過結果($argu)給使用該函式的設定變數(通常是$conf=$argu).
|
|
|
3648 |
$argu=&$conf;
|
|
|
3649 |
#可省略參數:
|
|
|
3650 |
#$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"],字串陣列,每個不存的變數要初始化為什麼,"null"代表不指定.
|
|
|
3651 |
#$conf["variableCheck.checkSkipableVarType"]["skipableVarDefaultValue"]=array(".R/hist-".$_SESSION["username"].".png"," ","區間","頻率");
|
|
|
3652 |
#無
|
|
|
3653 |
$checkResult=variableCheck::checkSkipableVarType($conf["variableCheck.checkSkipableVarType"],$argu);
|
|
|
3654 |
unset($conf["variableCheck.checkSkipableVarType"]);
|
| 226 |
liveuser |
3655 |
|
| 3 |
liveuser |
3656 |
#如果檢查失敗
|
|
|
3657 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
3658 |
|
| 3 |
liveuser |
3659 |
#設置執行不正常
|
|
|
3660 |
$result["status"]="false";
|
| 226 |
liveuser |
3661 |
|
| 3 |
liveuser |
3662 |
#設置執行錯誤訊息
|
|
|
3663 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
3664 |
|
| 3 |
liveuser |
3665 |
#回傳結果
|
|
|
3666 |
return $result;
|
| 226 |
liveuser |
3667 |
|
| 3 |
liveuser |
3668 |
}#if end
|
| 226 |
liveuser |
3669 |
|
| 3 |
liveuser |
3670 |
#如果檢查不通過
|
|
|
3671 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
3672 |
|
| 3 |
liveuser |
3673 |
#設置執行不正常
|
|
|
3674 |
$result["status"]="false";
|
| 226 |
liveuser |
3675 |
|
| 3 |
liveuser |
3676 |
#設置執行錯誤訊息
|
|
|
3677 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
3678 |
|
| 3 |
liveuser |
3679 |
#回傳結果
|
|
|
3680 |
return $result;
|
| 226 |
liveuser |
3681 |
|
| 3 |
liveuser |
3682 |
}#if end
|
| 226 |
liveuser |
3683 |
|
| 3 |
liveuser |
3684 |
#讀取csv檔標題欄位的內容
|
|
|
3685 |
#涵式說明:
|
|
|
3686 |
#讀取csv檔案的內容
|
|
|
3687 |
#回傳得結果:
|
|
|
3688 |
#$result["status"],執行是否正常,"true"代表正常;"false"代表不正常.
|
|
|
3689 |
#$result["error"],錯誤訊息陣列.
|
|
|
3690 |
#$result["content"],csv檔案內容的陣列
|
|
|
3691 |
#$result["content"]["$i"]["$j"]代表第$i+1列第$j+1欄位的內容.
|
|
|
3692 |
#如果 $conf["firstLineVarName"]爲"true"的話則會多回傳 $result["content"]["第幾列"]["第一列各個欄位的名稱"]
|
|
|
3693 |
#$result["title"],欄位的名稱
|
|
|
3694 |
#$result["lineCount"],總共幾列資料
|
|
|
3695 |
#必填的參數:
|
|
|
3696 |
$conf["csv.read"]["csvFilePositionAndName"]=$conf["csvFile"];#csv檔案的位置
|
|
|
3697 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3698 |
$conf["csv.read"]["fileArgu"]=$conf["fileArgu"];
|
|
|
3699 |
#可省略的參數:
|
|
|
3700 |
$conf["csv.read"]["firstLineVarName"]="true";#第一行是否爲變數名稱(各個欄位的名稱)
|
|
|
3701 |
#參考資料來源:
|
|
|
3702 |
#http://www.php.net/manual/en/function.str-split.php
|
|
|
3703 |
#參考資料來源
|
|
|
3704 |
#http://php.net/manual/en/function.fgetcsv.php
|
|
|
3705 |
$readCsvResult=csv::read($conf["csv.read"]);
|
|
|
3706 |
unset($conf["csv.read"]);
|
| 226 |
liveuser |
3707 |
|
| 3 |
liveuser |
3708 |
#如果讀取csv檔,失敗
|
|
|
3709 |
if($readCsvResult["status"]=="false"){
|
| 226 |
liveuser |
3710 |
|
| 3 |
liveuser |
3711 |
#設置執行不正常
|
|
|
3712 |
$result["status"]="false";
|
| 226 |
liveuser |
3713 |
|
| 3 |
liveuser |
3714 |
#設置執行錯誤訊息
|
|
|
3715 |
$result["error"]=$readCsvResult;
|
| 226 |
liveuser |
3716 |
|
| 3 |
liveuser |
3717 |
#回傳結果
|
|
|
3718 |
return $result;
|
| 226 |
liveuser |
3719 |
|
| 3 |
liveuser |
3720 |
}#if end
|
| 226 |
liveuser |
3721 |
|
| 3 |
liveuser |
3722 |
#如果欄位數量沒有大於2
|
|
|
3723 |
if(count($readCsvResult["title"])<=2){
|
| 226 |
liveuser |
3724 |
|
| 3 |
liveuser |
3725 |
#設置執行不正常
|
|
|
3726 |
$result["status"]="false";
|
| 226 |
liveuser |
3727 |
|
| 3 |
liveuser |
3728 |
#設置執行錯誤訊息
|
|
|
3729 |
$result["error"]="csv檔案的欄位數量須大於2";
|
| 226 |
liveuser |
3730 |
|
| 3 |
liveuser |
3731 |
#回傳結果
|
|
|
3732 |
return $result;
|
| 226 |
liveuser |
3733 |
|
| 3 |
liveuser |
3734 |
}#if end
|
| 226 |
liveuser |
3735 |
|
| 3 |
liveuser |
3736 |
#取得標題欄位的內容
|
|
|
3737 |
$columnTitle=$readCsvResult["title"];
|
| 226 |
liveuser |
3738 |
|
| 3 |
liveuser |
3739 |
#初始化更新標題欄位的R語法
|
|
|
3740 |
$updateColumnsNameStr="colnames(data)<-c(";
|
| 226 |
liveuser |
3741 |
|
| 3 |
liveuser |
3742 |
#執行 $columnTitle 的數量次數回圈
|
|
|
3743 |
for($i=0;$i<count($columnTitle);$i++){
|
| 226 |
liveuser |
3744 |
|
| 3 |
liveuser |
3745 |
#如果不是最後一個標題
|
|
|
3746 |
if($i!=count($columnTitle)-1){
|
| 226 |
liveuser |
3747 |
|
| 3 |
liveuser |
3748 |
#串接標題名稱與逗號
|
|
|
3749 |
$updateColumnsNameStr=$updateColumnsNameStr."\"".$columnTitle[$i]."\",";
|
| 226 |
liveuser |
3750 |
|
| 3 |
liveuser |
3751 |
}#if end
|
| 226 |
liveuser |
3752 |
|
| 3 |
liveuser |
3753 |
#反之爲最後一個標題
|
|
|
3754 |
else{
|
| 226 |
liveuser |
3755 |
|
| 3 |
liveuser |
3756 |
#串接標題名稱與「)」
|
|
|
3757 |
$updateColumnsNameStr=$updateColumnsNameStr."\"".$columnTitle[$i]."\")";
|
| 226 |
liveuser |
3758 |
|
| 3 |
liveuser |
3759 |
}#else end
|
| 226 |
liveuser |
3760 |
|
| 3 |
liveuser |
3761 |
}#for end
|
| 226 |
liveuser |
3762 |
|
| 3 |
liveuser |
3763 |
#初始化要寫入到R腳本的逐行內容
|
|
|
3764 |
$dataToWrite=array();
|
| 226 |
liveuser |
3765 |
|
| 3 |
liveuser |
3766 |
#設置要寫到R腳本的資料
|
|
|
3767 |
$dataToWrite[]="#資料探堪-關聯分析-apriori";
|
|
|
3768 |
$dataToWrite[]="";
|
|
|
3769 |
$dataToWrite[]="#匯入 arules 套件";
|
|
|
3770 |
$dataToWrite[]="library(arules)";
|
|
|
3771 |
$dataToWrite[]="";
|
|
|
3772 |
$dataToWrite[]="#讀取資料檔";
|
|
|
3773 |
$dataToWrite[]="data=read.csv(\"".$conf["csvFile"]."\")";
|
|
|
3774 |
$dataToWrite[]="";
|
|
|
3775 |
$dataToWrite[]="#更新欄位變數內容";
|
|
|
3776 |
$dataToWrite[]=$updateColumnsNameStr;
|
|
|
3777 |
$dataToWrite[]="";
|
| 226 |
liveuser |
3778 |
|
| 3 |
liveuser |
3779 |
#初始化 aprior 的 param 字串
|
|
|
3780 |
$parameter="parameter=list(minlen=2";
|
| 226 |
liveuser |
3781 |
|
| 3 |
liveuser |
3782 |
#如果存在 $conf["support"]
|
|
|
3783 |
if(isset($conf["support"])){
|
| 226 |
liveuser |
3784 |
|
| 3 |
liveuser |
3785 |
#設置最低支持度
|
|
|
3786 |
$parameter=$parameter.",support=".$conf["support"];
|
| 226 |
liveuser |
3787 |
|
| 3 |
liveuser |
3788 |
}#if end
|
| 226 |
liveuser |
3789 |
|
| 3 |
liveuser |
3790 |
#如果存在 $conf["confidence"]
|
|
|
3791 |
if(isset($conf["confidence"])){
|
| 226 |
liveuser |
3792 |
|
| 3 |
liveuser |
3793 |
#設置最低信度
|
|
|
3794 |
$parameter=$parameter.",confidence=".$conf["confidence"];
|
| 226 |
liveuser |
3795 |
|
|
|
3796 |
}#if end
|
|
|
3797 |
|
| 3 |
liveuser |
3798 |
#結束 param 字串
|
|
|
3799 |
$parameter=$parameter.")";
|
| 226 |
liveuser |
3800 |
|
| 3 |
liveuser |
3801 |
#如果有指定預測結果的變數與其數值內容
|
|
|
3802 |
if(isset($conf["forecastVarName"]) && isset($conf["forecastVarValueArray"])){
|
| 226 |
liveuser |
3803 |
|
| 3 |
liveuser |
3804 |
#如果 $conf["forecastVarValueArray"] 的元素數量小於 2
|
|
|
3805 |
if(count($conf["forecastVarValueArray"])<2){
|
| 226 |
liveuser |
3806 |
|
| 3 |
liveuser |
3807 |
#設置執行錯誤
|
|
|
3808 |
$result["status"]="false";
|
| 226 |
liveuser |
3809 |
|
| 3 |
liveuser |
3810 |
#設置執行錯誤訊息
|
|
|
3811 |
$result["error"][]="變數 \"forecastVarValueArray\"(apriori的RHS)至少需要兩個項目";
|
| 226 |
liveuser |
3812 |
|
| 3 |
liveuser |
3813 |
#回傳結果
|
|
|
3814 |
return $result;
|
| 226 |
liveuser |
3815 |
|
| 3 |
liveuser |
3816 |
}#if end
|
| 226 |
liveuser |
3817 |
|
| 3 |
liveuser |
3818 |
#建立皆為 $conf["forecastVarName"] 的陣列
|
|
|
3819 |
#函式說明:
|
|
|
3820 |
#建立一個陣列,可以指派陣列的內容,然後回傳
|
|
|
3821 |
#回傳的結果:
|
|
|
3822 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3823 |
#$result["function"],當前執行的函數名稱.
|
|
|
3824 |
#$result["error"],錯誤訊息陣列.
|
|
|
3825 |
#$result["content"],爲陣列變數內容
|
|
|
3826 |
#必填的參數:
|
|
|
3827 |
$conf["arrays::create"]["arrayContent"]=array($conf["forecastVarName"]);#陣列元素的內容,須爲陣列值。
|
|
|
3828 |
#可省略的參數:
|
|
|
3829 |
$conf["arrays::create"]["arrayCounts"]=count($conf["forecastVarValueArray"]);#爲陣列的元素有幾個,若沒設定,則數量爲$conf["arrayContent"]裏的元素數量
|
|
|
3830 |
$conf["arrays::create"]["theSameAs"]="true";#若設爲"true",則所有元素內容都跟第一個元素內容相同
|
|
|
3831 |
$forecastVarNameArray=arrays::create($conf["arrays::create"]);
|
|
|
3832 |
unset($conf["arrays::create"]);
|
| 226 |
liveuser |
3833 |
|
| 3 |
liveuser |
3834 |
#如果建立 皆為 $conf["forecastVarName"] 的陣列失敗
|
|
|
3835 |
if($forecastVarNameArray["status"]=="false"){
|
| 226 |
liveuser |
3836 |
|
| 3 |
liveuser |
3837 |
#設置執行不正常
|
|
|
3838 |
$result["status"]="false";
|
| 226 |
liveuser |
3839 |
|
| 3 |
liveuser |
3840 |
#設置執行錯誤訊息
|
|
|
3841 |
$result["error"]=$forecastVarNameArray;
|
| 226 |
liveuser |
3842 |
|
| 3 |
liveuser |
3843 |
#回傳結果
|
|
|
3844 |
return $result;
|
| 226 |
liveuser |
3845 |
|
| 3 |
liveuser |
3846 |
}#if end
|
| 226 |
liveuser |
3847 |
|
| 3 |
liveuser |
3848 |
#建立皆為 「=」 的陣列
|
|
|
3849 |
#函式說明:
|
|
|
3850 |
#建立一個陣列,可以指派陣列的內容,然後回傳
|
|
|
3851 |
#回傳的結果:
|
|
|
3852 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
3853 |
#$result["function"],當前執行的函數名稱.
|
|
|
3854 |
#$result["error"],錯誤訊息陣列.
|
|
|
3855 |
#$result["content"],爲陣列變數內容
|
|
|
3856 |
#必填的參數:
|
|
|
3857 |
$conf["arrays::create"]["arrayContent"]=array("=");#陣列元素的內容,須爲陣列值。
|
|
|
3858 |
#可省略的參數:
|
|
|
3859 |
$conf["arrays::create"]["arrayCounts"]=count($conf["forecastVarValueArray"]);#爲陣列的元素有幾個,若沒設定,則數量爲$conf["arrayContent"]裏的元素數量
|
|
|
3860 |
$conf["arrays::create"]["theSameAs"]="true";#若設爲"true",則所有元素內容都跟第一個元素內容相同
|
|
|
3861 |
$equalArray=arrays::create($conf["arrays::create"]);
|
|
|
3862 |
unset($conf["arrays::create"]);
|
| 226 |
liveuser |
3863 |
|
| 3 |
liveuser |
3864 |
#如果建立 皆為「=」的陣列失敗
|
|
|
3865 |
if($equalArray["status"]=="false"){
|
| 226 |
liveuser |
3866 |
|
| 3 |
liveuser |
3867 |
#設置執行不正常
|
|
|
3868 |
$result["status"]="false";
|
| 226 |
liveuser |
3869 |
|
| 3 |
liveuser |
3870 |
#設置執行錯誤訊息
|
|
|
3871 |
$result["error"]=$equalArray;
|
| 226 |
liveuser |
3872 |
|
| 3 |
liveuser |
3873 |
#回傳結果
|
|
|
3874 |
return $result;
|
| 226 |
liveuser |
3875 |
|
| 3 |
liveuser |
3876 |
}#if end
|
| 226 |
liveuser |
3877 |
|
| 3 |
liveuser |
3878 |
#將 指定預測結果的變數與其數值內容 合併成一維陣列
|
|
|
3879 |
#函式說明:
|
|
|
3880 |
#透過多個擁有一樣數量元素的一維陣列,透過指定的連接字串,組成一組同樣數量的一維陣列。
|
|
|
3881 |
#回傳結果:
|
|
|
3882 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常。
|
|
|
3883 |
#$result["error"],錯誤訊息。
|
|
|
3884 |
#$result["content"],組合成新值的一維陣列。
|
|
|
3885 |
#$result["function"],當前執行的函數名稱。
|
|
|
3886 |
#必填參數:
|
|
|
3887 |
#$conf["R::combineToNewArray"]["arrays"],二維陣列,爲要依序由哪些陣列變數來進行組合
|
|
|
3888 |
$conf["R::combineToNewArray"]["arrays"]=array($forecastVarNameArray["content"],$conf["forecastVarValueArray"]);
|
|
|
3889 |
#可省略參數:
|
|
|
3890 |
#$conf["R::combineToNewArray"]["combineSymbolArray"],陣列字串,數量爲$conf["arrays"]減一,爲用於連結各一維陣列變數的連接字串,預設皆爲"<=>"。
|
|
|
3891 |
$conf["R::combineToNewArray"]["combineSymbolArray"]=$equalArray["content"];
|
|
|
3892 |
$combineToNewArray=arrays::combineToNewArray($conf["R::combineToNewArray"]);
|
|
|
3893 |
unset($conf["R::combineToNewArray"]);
|
| 226 |
liveuser |
3894 |
|
| 3 |
liveuser |
3895 |
#如果合併兩個一維陣列失敗
|
|
|
3896 |
if($combineToNewArray["status"]=="false"){
|
| 226 |
liveuser |
3897 |
|
| 3 |
liveuser |
3898 |
#設置執行不正常
|
|
|
3899 |
$result["status"]="false";
|
| 226 |
liveuser |
3900 |
|
| 3 |
liveuser |
3901 |
#設置執行錯誤訊息
|
|
|
3902 |
$result["error"]=$combineToNewArray;
|
| 226 |
liveuser |
3903 |
|
| 3 |
liveuser |
3904 |
#回傳結果
|
|
|
3905 |
return $result;
|
| 226 |
liveuser |
3906 |
|
|
|
3907 |
}#if end
|
|
|
3908 |
|
| 3 |
liveuser |
3909 |
#組裝 $conf["forecastVarNameArray"] 與 $conf["forecastVarValueArray"] 為 $appearance
|
|
|
3910 |
#涵式說明:
|
|
|
3911 |
#避免超出4096bytes限制的條件下產生向量變數語法
|
|
|
3912 |
#請勿使用 vectorPart 作為R的變數,因為這是用於組合向量變數的暫存變數.
|
|
|
3913 |
#回傳結果:
|
|
|
3914 |
#$result["status"],執行正常與否,"true"代表正常;"false"代表不正常
|
|
|
3915 |
#$result["error"],錯誤訊息陣列
|
|
|
3916 |
#$result["function"],當前函數名稱
|
|
|
3917 |
#$result["rVectorCreate"],建立R向量變數的語法陣列,一個元素代表一列的內容。
|
|
|
3918 |
#$result["lineCount"],用了幾列程式完成向量變數的建立
|
|
|
3919 |
#必填參數:
|
|
|
3920 |
#$conf["R::createFixedVectorVar"]["vectorName"],字串,向量變數在R裡面的名稱。
|
|
|
3921 |
$conf["R::createFixedVectorVar"]["vectorName"]="rhsCondition";
|
|
|
3922 |
#$conf["R::createFixedVectorVar"]["vectorData"],陣列變數,要產生的向量變數資料。
|
|
|
3923 |
$conf["R::createFixedVectorVar"]["vectorData"]=$combineToNewArray["content"];
|
|
|
3924 |
#$conf["R::createFixedVectorVar"]["writeTarget"],參考陣列變數,向量變數產生的語法要寫入哪個儲存R腳本的陣列變數。
|
|
|
3925 |
$conf["R::createFixedVectorVar"]["writeTarget"]=&$dataToWrite;
|
|
|
3926 |
$createFixedVectorVar=R::createFixedVectorVar($conf["R::createFixedVectorVar"]);
|
|
|
3927 |
unset($conf["R::createFixedVectorVar"]);
|
| 226 |
liveuser |
3928 |
|
| 3 |
liveuser |
3929 |
#如果建立向量變數失敗
|
|
|
3930 |
if($createFixedVectorVar["status"]=="false"){
|
| 226 |
liveuser |
3931 |
|
| 3 |
liveuser |
3932 |
#設置執行不正常
|
|
|
3933 |
$result["status"]="false";
|
| 226 |
liveuser |
3934 |
|
| 3 |
liveuser |
3935 |
#設置執行錯誤訊息
|
|
|
3936 |
$result["error"]=$createFixedVectorVar;
|
| 226 |
liveuser |
3937 |
|
| 3 |
liveuser |
3938 |
#回傳結果
|
|
|
3939 |
return $result;
|
| 226 |
liveuser |
3940 |
|
| 3 |
liveuser |
3941 |
}#if end
|
| 226 |
liveuser |
3942 |
|
| 3 |
liveuser |
3943 |
$dataToWrite[]="#使用 apriori 對data進行資料探堪 並將所有規則存在 rules";
|
|
|
3944 |
$dataToWrite[]="#control = list(verbose=F)代表不顯示一些過程資訊";
|
|
|
3945 |
$dataToWrite[]="#parameter = list(minlen=2)代表P(A)與P(B)不能爲空集合";
|
|
|
3946 |
$dataToWrite[]="#appearance = list(rhs=c(\"Survived=No\", \"Survived=Yes\"),default=\"lhs\")代表結果變數Survived必須為\"No\"或 \"Yes\",原因變數不限定.";
|
|
|
3947 |
$dataToWrite[]="rules<-apriori(data,control = list(verbose=F),".$parameter.",appearance=list(rhs=rhsCondition,default=\"lhs\"))";
|
| 226 |
liveuser |
3948 |
|
| 3 |
liveuser |
3949 |
}#if end
|
| 226 |
liveuser |
3950 |
|
| 3 |
liveuser |
3951 |
#反之沒有指定
|
|
|
3952 |
else{
|
| 226 |
liveuser |
3953 |
|
| 3 |
liveuser |
3954 |
$dataToWrite[]="#使用 apriori 對data進行資料探堪 並將所有規則存在 rules";
|
|
|
3955 |
$dataToWrite[]="#control = list(verbose=F)代表不顯示一些過程資訊";
|
|
|
3956 |
$dataToWrite[]="#parameter = list(minlen=2)代表P(A)與P(B)不能爲空集合";
|
|
|
3957 |
$dataToWrite[]="rules<-apriori(data,control = list(verbose=F),".$parameter.")";
|
| 226 |
liveuser |
3958 |
|
| 3 |
liveuser |
3959 |
}#else end
|
| 226 |
liveuser |
3960 |
|
| 3 |
liveuser |
3961 |
$dataToWrite[]="";
|
|
|
3962 |
$dataToWrite[]="#檢示總共找到幾條規則rules";
|
|
|
3963 |
$dataToWrite[]="rules";
|
|
|
3964 |
$dataToWrite[]="";
|
|
|
3965 |
$dataToWrite[]="#設定規則的 support confidence lift 比例到小數點後三位就好";
|
|
|
3966 |
$dataToWrite[]="quality(rules)<-round(quality(rules),digits=3)";
|
|
|
3967 |
$dataToWrite[]="";
|
|
|
3968 |
$dataToWrite[]="#排序規則的順序,用lift來排,預設爲遞減排序。";
|
|
|
3969 |
$dataToWrite[]="rules.sorted<-sort(rules,by=\"lift\")";
|
|
|
3970 |
$dataToWrite[]="";
|
|
|
3971 |
$dataToWrite[]="#檢示所有規則的資料";
|
|
|
3972 |
$dataToWrite[]="inspect(rules.sorted)";
|
| 226 |
liveuser |
3973 |
|
| 3 |
liveuser |
3974 |
#涵式說明:
|
|
|
3975 |
#建立R檔案
|
|
|
3976 |
#回傳的結果:
|
|
|
3977 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
|
|
|
3978 |
#$result["error"],錯誤訊息陣列.
|
|
|
3979 |
#$result["newCreatedRfilePathAndName"],R腳本檔的位置與名稱
|
|
|
3980 |
#必填的參數:
|
|
|
3981 |
if(!isset($_SESSION))
|
| 226 |
liveuser |
3982 |
{
|
| 3 |
liveuser |
3983 |
$conf["R.writeRfile"]["addAndName"]=".R/".$_SERVER["USER"]."-apriori.R";#R檔案的位置與名稱
|
|
|
3984 |
}
|
|
|
3985 |
else if(isset($_SESSION["username"]))
|
|
|
3986 |
{
|
|
|
3987 |
$conf["R.writeRfile"]["addAndName"]=".R/".$_SESSION["username"]."-apriori.R";#R檔案的位置與名稱
|
|
|
3988 |
}
|
|
|
3989 |
else
|
|
|
3990 |
{
|
|
|
3991 |
#取得系統時間
|
|
|
3992 |
$unixTime=time::getMicrotime();
|
| 226 |
liveuser |
3993 |
|
| 3 |
liveuser |
3994 |
$conf["R.writeRfile"]["addAndName"]=".R/".$unixTime."-apriori.R";#R檔案的位置與名稱
|
|
|
3995 |
}
|
|
|
3996 |
$conf["R.writeRfile"]["textToWrite"]=$dataToWrite;#要寫入的字串內容陣列,一個元素代表一行文字,每行結尾會自動換行。
|
|
|
3997 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
3998 |
$conf["R.writeRfile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
3999 |
$writeRfileResult=R::writeRfile($conf["R.writeRfile"]);
|
|
|
4000 |
unset($conf["R.writeRfile"]);
|
| 226 |
liveuser |
4001 |
|
| 3 |
liveuser |
4002 |
#移除暫存的R腳本內容變數
|
|
|
4003 |
unset($dataToWrite);
|
| 226 |
liveuser |
4004 |
|
| 3 |
liveuser |
4005 |
#如果 R 腳本寫入失敗
|
|
|
4006 |
if($writeRfileResult["status"]=="false"){
|
| 226 |
liveuser |
4007 |
|
| 3 |
liveuser |
4008 |
#設置執行不正常
|
|
|
4009 |
$result["status"]="false";
|
| 226 |
liveuser |
4010 |
|
| 3 |
liveuser |
4011 |
#設置錯誤訊息
|
|
|
4012 |
$result["error"]=$writeRfileResult;
|
| 226 |
liveuser |
4013 |
|
| 3 |
liveuser |
4014 |
#回傳結果
|
|
|
4015 |
return $result;
|
| 226 |
liveuser |
4016 |
|
| 3 |
liveuser |
4017 |
}#if end
|
| 226 |
liveuser |
4018 |
|
| 3 |
liveuser |
4019 |
#取得R腳本的位置
|
|
|
4020 |
$rScriptAdd=$writeRfileResult["newCreatedRfilePathAndName"];
|
| 226 |
liveuser |
4021 |
|
| 3 |
liveuser |
4022 |
#執行R腳本
|
|
|
4023 |
#函式說明:
|
|
|
4024 |
#執行R腳本,執行完畢後,會刪除R的腳本與暫存R執行後的輸出的檔案.
|
|
|
4025 |
#回傳的結果:
|
|
|
4026 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4027 |
#$result["errror"],錯誤訊息陣列
|
|
|
4028 |
#$result["lineArray"],字串陣列,R輸出結果,每個元素代表一行的輸出.
|
|
|
4029 |
#$result["lineCount"],整數,R輸出的總共行數.
|
|
|
4030 |
#必填的參數:
|
|
|
4031 |
#$conf["R.executeR"]["rPositionAndName"],字串,R腳本的位置與名稱.
|
|
|
4032 |
$conf["R.executeR"]["rPositionAndName"]=$rScriptAdd;
|
|
|
4033 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
4034 |
$conf["R.executeR"]["fileArgu"]=$conf["fileArgu"];
|
|
|
4035 |
#可省略的參數:
|
|
|
4036 |
#$conf["R.executeR"]["disbaleOptimal"],字串,"true"代表取消輸出的優化,可以顯示版本訊息、歡迎訊息、儲存暫存檔,預設為"false"要進行優化.
|
|
|
4037 |
#$conf["R.executeR"]["disbaleOptimal"]="true";
|
|
|
4038 |
$executeResult=R::executeR($conf["R.executeR"]);
|
|
|
4039 |
unset($conf["R.executeR"]);
|
| 226 |
liveuser |
4040 |
|
| 3 |
liveuser |
4041 |
#如果執行R腳本出錯
|
|
|
4042 |
if($executeResult["status"]=="false"){
|
| 226 |
liveuser |
4043 |
|
| 3 |
liveuser |
4044 |
#設置執行不正常
|
|
|
4045 |
$result["status"]="false";
|
| 226 |
liveuser |
4046 |
|
| 3 |
liveuser |
4047 |
#設置錯誤訊息
|
|
|
4048 |
$result["error"]=$executeResult;
|
| 226 |
liveuser |
4049 |
|
| 3 |
liveuser |
4050 |
#回傳結果
|
|
|
4051 |
return $result;
|
| 226 |
liveuser |
4052 |
|
| 3 |
liveuser |
4053 |
}#if end
|
| 226 |
liveuser |
4054 |
|
| 3 |
liveuser |
4055 |
#取得執行R後的輸出
|
|
|
4056 |
$result["oriOutPut"]=$executeResult;
|
| 226 |
liveuser |
4057 |
|
| 3 |
liveuser |
4058 |
#初始化記錄規則的陣列變數
|
|
|
4059 |
$rulesArray=array();
|
| 226 |
liveuser |
4060 |
|
| 3 |
liveuser |
4061 |
#初始化儲存規則計數的數字
|
|
|
4062 |
$rulesNum=0;
|
| 226 |
liveuser |
4063 |
|
| 3 |
liveuser |
4064 |
#初始化暫存lhs條件的陣列變數
|
|
|
4065 |
$lhsNameArrays=array();
|
|
|
4066 |
$lhsValueArrays=array();
|
| 226 |
liveuser |
4067 |
|
| 3 |
liveuser |
4068 |
#初始化分析資料的列是從第幾列開始
|
| 226 |
liveuser |
4069 |
$rulesLineStart=28;
|
|
|
4070 |
|
| 3 |
liveuser |
4071 |
#如果有指定預測結果的變數與其數值內容
|
|
|
4072 |
if(isset($conf["forecastVarName"]) && isset($conf["forecastVarValueArray"])){
|
| 226 |
liveuser |
4073 |
|
| 3 |
liveuser |
4074 |
#設置分析資料的列是從第31列開始
|
|
|
4075 |
$rulesLineStart=$rulesLineStart+$createFixedVectorVar["lineCount"]+1;
|
| 226 |
liveuser |
4076 |
|
|
|
4077 |
}#if end
|
|
|
4078 |
|
| 3 |
liveuser |
4079 |
#依據每行的輸出結果
|
|
|
4080 |
for($i=$rulesLineStart;$i<$executeResult["lineCount"]-1;$i++){
|
| 226 |
liveuser |
4081 |
|
| 3 |
liveuser |
4082 |
#如果分析資料的開始列為 "NULL"
|
|
|
4083 |
if($executeResult["lineArray"][$rulesLineStart]=="NULL"){
|
| 226 |
liveuser |
4084 |
|
| 3 |
liveuser |
4085 |
#設置執行正常
|
|
|
4086 |
$result["status"]="true";
|
| 226 |
liveuser |
4087 |
|
| 3 |
liveuser |
4088 |
#取得規則內容
|
|
|
4089 |
$result["content"]["rulesArray"]=array();
|
| 226 |
liveuser |
4090 |
|
| 3 |
liveuser |
4091 |
#設置規則筆數
|
|
|
4092 |
$result["content"]["rulesCount"]=0;
|
| 226 |
liveuser |
4093 |
|
| 3 |
liveuser |
4094 |
#回傳結果
|
|
|
4095 |
return $result;
|
| 226 |
liveuser |
4096 |
|
|
|
4097 |
}#if end
|
|
|
4098 |
|
| 3 |
liveuser |
4099 |
#用空格區分,看第一個是否為關聯規則的筆數.
|
|
|
4100 |
#涵式說明:
|
|
|
4101 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
4102 |
#回傳的參數:
|
|
|
4103 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4104 |
#$result["error"],錯誤訊息陣列
|
|
|
4105 |
#$result["function"],當前執行的函數名稱.
|
|
|
4106 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
4107 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
4108 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
4109 |
#必填的參數:
|
|
|
4110 |
$conf["stringProcess::spiltString"]["stringIn"]=$executeResult["lineArray"][$i];#要處理的字串。
|
|
|
4111 |
$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
|
|
|
4112 |
#備註:
|
|
|
4113 |
#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
|
|
|
4114 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
4115 |
unset($conf["stringProcess::spiltString"]);
|
|
|
4116 |
|
| 3 |
liveuser |
4117 |
#如果分割字串失敗
|
|
|
4118 |
if($spiltString["status"]=="false"){
|
| 226 |
liveuser |
4119 |
|
| 3 |
liveuser |
4120 |
#設置執行不正常
|
|
|
4121 |
$result["status"]="false";
|
| 226 |
liveuser |
4122 |
|
| 3 |
liveuser |
4123 |
#設置錯誤訊息
|
|
|
4124 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
4125 |
|
| 3 |
liveuser |
4126 |
#回傳結果
|
|
|
4127 |
return $result;
|
| 226 |
liveuser |
4128 |
|
|
|
4129 |
}#if end
|
|
|
4130 |
|
| 3 |
liveuser |
4131 |
#如果分割好的第一段是 ($rulesNum+1) 則代表新的規則開始
|
|
|
4132 |
if($spiltString["dataArray"][0]==$rulesNum+1){
|
| 226 |
liveuser |
4133 |
|
| 3 |
liveuser |
4134 |
#規則加1
|
|
|
4135 |
$rulesNum++;
|
| 226 |
liveuser |
4136 |
|
| 3 |
liveuser |
4137 |
}#if end
|
| 226 |
liveuser |
4138 |
|
| 3 |
liveuser |
4139 |
#如果有讀到 「=>」 則代表是當前規則的結束
|
|
|
4140 |
#函式說明:
|
|
|
4141 |
#檢查字串裡面有無指定的關鍵字
|
|
|
4142 |
#回傳的結果:
|
|
|
4143 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
4144 |
#$result["error"],錯誤訊息
|
|
|
4145 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
4146 |
#$result["keyWordCount"],找到的關鍵字數量.
|
|
|
4147 |
#必填的參數:
|
|
|
4148 |
$conf["search.findKeyWord"]["keyWord"]="=>";#想要搜尋的關鍵字
|
|
|
4149 |
$conf["search.findKeyWord"]["string"]=$executeResult["lineArray"][$i];#要被搜尋的字串內容
|
|
|
4150 |
#可省略的參數:
|
|
|
4151 |
#$conf["search.findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
4152 |
$searchResult=search::findKeyWord($conf["search.findKeyWord"]);
|
| 226 |
liveuser |
4153 |
unset($conf["search.findKeyWord"]);
|
|
|
4154 |
|
| 3 |
liveuser |
4155 |
#如果 $searchResult["status"] 等於 "false"
|
|
|
4156 |
if($searchResult["status"]=="false"){
|
| 226 |
liveuser |
4157 |
|
| 3 |
liveuser |
4158 |
#設置執行不正常
|
|
|
4159 |
$result["status"]="false";
|
| 226 |
liveuser |
4160 |
|
| 3 |
liveuser |
4161 |
#設置錯誤訊息
|
|
|
4162 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
4163 |
|
| 3 |
liveuser |
4164 |
#回傳結果
|
|
|
4165 |
return $result;
|
| 226 |
liveuser |
4166 |
|
|
|
4167 |
}#if end
|
|
|
4168 |
|
| 3 |
liveuser |
4169 |
#如果有找到關鍵字
|
|
|
4170 |
if($searchResult["founded"]=="true"){
|
| 226 |
liveuser |
4171 |
|
| 3 |
liveuser |
4172 |
#解析原因與導致的結果字串
|
| 226 |
liveuser |
4173 |
|
| 3 |
liveuser |
4174 |
#涵式說明:
|
|
|
4175 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
4176 |
#回傳的參數:
|
|
|
4177 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4178 |
#$result["error"],錯誤訊息陣列
|
|
|
4179 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
4180 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
4181 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
4182 |
#必填的參數:
|
|
|
4183 |
$conf["stringProcess.spiltString"]["stringIn"]=$executeResult["lineArray"][$i];#要處理的字串。
|
|
|
4184 |
$conf["stringProcess.spiltString"]["spiltSymbol"]="=>";#爲以哪個符號作爲分割
|
|
|
4185 |
$rulesStr=stringProcess::spiltString($conf["stringProcess.spiltString"]);
|
|
|
4186 |
unset($conf["stringProcess.spiltString"]);
|
| 226 |
liveuser |
4187 |
|
| 3 |
liveuser |
4188 |
#如果處理結果字串出錯
|
|
|
4189 |
if($rulesStr["status"]=="false"){
|
| 226 |
liveuser |
4190 |
|
| 3 |
liveuser |
4191 |
#設置執行不正常
|
|
|
4192 |
$result["status"]="false";
|
| 226 |
liveuser |
4193 |
|
| 3 |
liveuser |
4194 |
#設置錯誤訊息
|
|
|
4195 |
$result["error"]=$rulesStr;
|
| 226 |
liveuser |
4196 |
|
| 3 |
liveuser |
4197 |
#回傳結果
|
|
|
4198 |
return $result;
|
| 226 |
liveuser |
4199 |
|
| 3 |
liveuser |
4200 |
}#if end
|
| 226 |
liveuser |
4201 |
|
|
|
4202 |
#取得原因字串
|
| 3 |
liveuser |
4203 |
$factorStr=$rulesStr["dataArray"][0];
|
| 226 |
liveuser |
4204 |
|
| 3 |
liveuser |
4205 |
#取得結果字串
|
|
|
4206 |
$resultStr=$rulesStr["dataArray"][1];
|
| 226 |
liveuser |
4207 |
|
| 3 |
liveuser |
4208 |
#解析原因字串的變數名稱與其數值
|
|
|
4209 |
#涵式說明:
|
|
|
4210 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
4211 |
#回傳的參數:
|
|
|
4212 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4213 |
#$result["error"],錯誤訊息陣列
|
|
|
4214 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
4215 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
4216 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
4217 |
#必填的參數:
|
|
|
4218 |
$conf["stringProcess.spiltString"]["stringIn"]=$factorStr;#要處理的字串。
|
|
|
4219 |
$conf["stringProcess.spiltString"]["spiltSymbol"]="=";#爲以哪個符號作爲分割
|
|
|
4220 |
$factorStr=stringProcess::spiltString($conf["stringProcess.spiltString"]);
|
|
|
4221 |
unset($conf["stringProcess.spiltString"]);
|
| 226 |
liveuser |
4222 |
|
| 3 |
liveuser |
4223 |
#如果處理結果字串出錯
|
|
|
4224 |
if($factorStr["status"]=="false"){
|
| 226 |
liveuser |
4225 |
|
| 3 |
liveuser |
4226 |
#設置執行不正常
|
|
|
4227 |
$result["status"]="false";
|
| 226 |
liveuser |
4228 |
|
| 3 |
liveuser |
4229 |
#設置錯誤訊息
|
|
|
4230 |
$result["error"]=$factorStr;
|
| 226 |
liveuser |
4231 |
|
| 3 |
liveuser |
4232 |
#回傳結果
|
|
|
4233 |
return $result;
|
| 226 |
liveuser |
4234 |
|
| 3 |
liveuser |
4235 |
}#if end
|
| 226 |
liveuser |
4236 |
|
| 3 |
liveuser |
4237 |
#剔除原因字串中不需要的字
|
|
|
4238 |
#涵式說明:
|
|
|
4239 |
#處理多個字串避免網頁出錯
|
|
|
4240 |
#回傳的結果:
|
|
|
4241 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
4242 |
#$result["error"],錯誤訊息
|
|
|
4243 |
#$result["processedStrArray"],處理好的字串陣列
|
|
|
4244 |
#必填的參數:
|
|
|
4245 |
$conf["stringProcess::correctMutiStrCharacter"]["stringIn"]=array($factorStr["dataArray"][0],$factorStr["dataArray"][1]);#爲要處理的字串陣列
|
|
|
4246 |
#可省略的參數:
|
|
|
4247 |
$conf["stringProcess::correctMutiStrCharacter"]["selectedCharacter"]=array($rulesNum,"{","}",".",",",";"," ");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
4248 |
#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
|
|
|
4249 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
4250 |
#$conf["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
4251 |
$factorStr=stringProcess::correctMutiStrCharacter($conf["stringProcess::correctMutiStrCharacter"]);
|
|
|
4252 |
unset($conf["stringProcess::correctMutiStrCharacter"]);
|
| 226 |
liveuser |
4253 |
|
| 3 |
liveuser |
4254 |
#如果處理結果字串出錯
|
|
|
4255 |
if($factorStr["status"]=="false"){
|
| 226 |
liveuser |
4256 |
|
| 3 |
liveuser |
4257 |
#設置執行不正常
|
|
|
4258 |
$result["status"]="false";
|
| 226 |
liveuser |
4259 |
|
| 3 |
liveuser |
4260 |
#設置錯誤訊息
|
|
|
4261 |
$result["error"]=$factorStr;
|
| 226 |
liveuser |
4262 |
|
| 3 |
liveuser |
4263 |
#回傳結果
|
|
|
4264 |
return $result;
|
| 226 |
liveuser |
4265 |
|
| 3 |
liveuser |
4266 |
}#if end
|
| 226 |
liveuser |
4267 |
|
| 3 |
liveuser |
4268 |
#取得導致的原因
|
|
|
4269 |
$rulesArray[$rulesNum]["lhsName"][]=$factorStr["processedStrArray"][0];
|
|
|
4270 |
$rulesArray[$rulesNum]["lhsValue"][]=$factorStr["processedStrArray"][1];
|
| 226 |
liveuser |
4271 |
|
|
|
4272 |
#解析結果字串的變數名稱與其數值
|
| 3 |
liveuser |
4273 |
#涵式說明:
|
|
|
4274 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
4275 |
#回傳的參數:
|
|
|
4276 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4277 |
#$result["error"],錯誤訊息陣列
|
|
|
4278 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
4279 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
4280 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
4281 |
#必填的參數:
|
|
|
4282 |
$conf["stringProcess.spiltString"]["stringIn"]=$resultStr;#要處理的字串。
|
|
|
4283 |
$conf["stringProcess.spiltString"]["spiltSymbol"]="=";#爲以哪個符號作爲分割
|
|
|
4284 |
$resultStr=stringProcess::spiltString($conf["stringProcess.spiltString"]);
|
|
|
4285 |
unset($conf["stringProcess.spiltString"]);
|
| 226 |
liveuser |
4286 |
|
| 3 |
liveuser |
4287 |
#如果處理結果字串出錯
|
|
|
4288 |
if($resultStr["status"]=="false"){
|
| 226 |
liveuser |
4289 |
|
| 3 |
liveuser |
4290 |
#設置執行不正常
|
|
|
4291 |
$result["status"]="false";
|
| 226 |
liveuser |
4292 |
|
| 3 |
liveuser |
4293 |
#設置錯誤訊息
|
|
|
4294 |
$result["error"]=$resultStr;
|
| 226 |
liveuser |
4295 |
|
| 3 |
liveuser |
4296 |
#回傳結果
|
|
|
4297 |
return $result;
|
| 226 |
liveuser |
4298 |
|
| 3 |
liveuser |
4299 |
}#if end
|
| 226 |
liveuser |
4300 |
|
| 3 |
liveuser |
4301 |
#涵式說明:
|
|
|
4302 |
#處理多個字串避免網頁出錯
|
|
|
4303 |
#回傳的結果:
|
|
|
4304 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
4305 |
#$result["error"],錯誤訊息
|
|
|
4306 |
#$result["processedStrArray"],處理好的字串陣列
|
|
|
4307 |
#必填的參數:
|
|
|
4308 |
$conf["stringProcess::correctMutiStrCharacter"]["stringIn"]=array($resultStr["dataArray"][0]);#爲要處理的字串陣列
|
|
|
4309 |
#可省略的參數:
|
|
|
4310 |
$conf["stringProcess::correctMutiStrCharacter"]["selectedCharacter"]=array("{","}",";"," ",".");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
4311 |
#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
|
|
|
4312 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
4313 |
#$conf["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
4314 |
$resultName=stringProcess::correctMutiStrCharacter($conf["stringProcess::correctMutiStrCharacter"]);
|
|
|
4315 |
unset($conf["stringProcess::correctMutiStrCharacter"]);
|
| 226 |
liveuser |
4316 |
|
| 3 |
liveuser |
4317 |
#如果處理結果字串出錯
|
|
|
4318 |
if($resultName["status"]=="false"){
|
| 226 |
liveuser |
4319 |
|
| 3 |
liveuser |
4320 |
#設置執行不正常
|
|
|
4321 |
$result["status"]="false";
|
| 226 |
liveuser |
4322 |
|
| 3 |
liveuser |
4323 |
#設置錯誤訊息
|
|
|
4324 |
$result["error"]=$resultName;
|
| 226 |
liveuser |
4325 |
|
| 3 |
liveuser |
4326 |
#回傳結果
|
|
|
4327 |
return $result;
|
| 226 |
liveuser |
4328 |
|
| 3 |
liveuser |
4329 |
}#if end
|
| 226 |
liveuser |
4330 |
|
| 3 |
liveuser |
4331 |
#取得導致的結果名稱
|
|
|
4332 |
$rulesArray[$rulesNum]["rhsName"][]=$resultName["processedStrArray"][0];
|
| 226 |
liveuser |
4333 |
|
| 3 |
liveuser |
4334 |
#取得導致的結果名稱對應的內容與其相關數值
|
|
|
4335 |
$resultValueAndOthers=$resultStr["dataArray"][1];
|
| 226 |
liveuser |
4336 |
|
| 3 |
liveuser |
4337 |
#解析導致的結果名稱對應的內容與其相關數值
|
|
|
4338 |
#涵式說明:
|
|
|
4339 |
#處理多個字串避免網頁出錯
|
|
|
4340 |
#回傳的結果:
|
|
|
4341 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
4342 |
#$result["error"],錯誤訊息
|
|
|
4343 |
#$result["processedStrArray"],處理好的字串陣列
|
|
|
4344 |
#必填的參數:
|
|
|
4345 |
$conf["stringProcess::correctMutiStrCharacter"]["stringIn"]=array($resultValueAndOthers);#爲要處理的字串陣列
|
|
|
4346 |
#可省略的參數:
|
|
|
4347 |
$conf["stringProcess::correctMutiStrCharacter"]["selectedCharacter"]=array("{","}",";");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
4348 |
#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
|
|
|
4349 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
4350 |
#$conf["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
4351 |
$resultValueAndOthers=stringProcess::correctMutiStrCharacter($conf["stringProcess::correctMutiStrCharacter"]);
|
|
|
4352 |
unset($conf["stringProcess::correctMutiStrCharacter"]);
|
| 226 |
liveuser |
4353 |
|
| 3 |
liveuser |
4354 |
#如果處理結果字串出錯
|
|
|
4355 |
if($resultValueAndOthers["status"]=="false"){
|
| 226 |
liveuser |
4356 |
|
| 3 |
liveuser |
4357 |
#設置執行不正常
|
|
|
4358 |
$result["status"]="false";
|
| 226 |
liveuser |
4359 |
|
| 3 |
liveuser |
4360 |
#設置錯誤訊息
|
|
|
4361 |
$result["error"]=$resultValueAndOthers;
|
| 226 |
liveuser |
4362 |
|
| 3 |
liveuser |
4363 |
#回傳結果
|
|
|
4364 |
return $result;
|
| 226 |
liveuser |
4365 |
|
| 3 |
liveuser |
4366 |
}#if end
|
| 226 |
liveuser |
4367 |
|
| 3 |
liveuser |
4368 |
#涵式說明:
|
|
|
4369 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
4370 |
#回傳的參數:
|
|
|
4371 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4372 |
#$result["error"],錯誤訊息陣列
|
|
|
4373 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
4374 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
4375 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
4376 |
#必填的參數:
|
|
|
4377 |
$conf["stringProcess.spiltString"]["stringIn"]=$resultValueAndOthers["processedStrArray"][0];#要處理的字串。
|
|
|
4378 |
$conf["stringProcess.spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
|
|
|
4379 |
$resultValue=stringProcess::spiltString($conf["stringProcess.spiltString"]);
|
|
|
4380 |
unset($conf["stringProcess.spiltString"]);
|
| 226 |
liveuser |
4381 |
|
| 3 |
liveuser |
4382 |
#如果處理結果字串出錯
|
|
|
4383 |
if($resultValue["status"]=="false"){
|
| 226 |
liveuser |
4384 |
|
| 3 |
liveuser |
4385 |
#設置執行不正常
|
|
|
4386 |
$result["status"]="false";
|
| 226 |
liveuser |
4387 |
|
| 3 |
liveuser |
4388 |
#設置錯誤訊息
|
|
|
4389 |
$result["error"]=$resultValue;
|
| 226 |
liveuser |
4390 |
|
| 3 |
liveuser |
4391 |
#回傳結果
|
|
|
4392 |
return $result;
|
| 226 |
liveuser |
4393 |
|
| 3 |
liveuser |
4394 |
}#if end
|
| 226 |
liveuser |
4395 |
|
| 3 |
liveuser |
4396 |
#取得導致的結果名稱對應的數值
|
|
|
4397 |
$rulesArray[$rulesNum]["rhsValue"][]=$resultValue["dataArray"][0];
|
| 226 |
liveuser |
4398 |
|
| 3 |
liveuser |
4399 |
#取得導致結果名稱對應數值的 support
|
|
|
4400 |
$rulesArray[$rulesNum]["support"][]=$resultValue["dataArray"][1];
|
| 226 |
liveuser |
4401 |
|
| 3 |
liveuser |
4402 |
#取得導致結果名稱對應數值的 confidence
|
|
|
4403 |
$rulesArray[$rulesNum]["confidence"][]=$resultValue["dataArray"][2];
|
| 226 |
liveuser |
4404 |
|
| 3 |
liveuser |
4405 |
#取得導致結果名稱對應數值的 lift
|
|
|
4406 |
$rulesArray[$rulesNum]["lift"][]=$resultValue["dataArray"][3];
|
| 226 |
liveuser |
4407 |
|
| 3 |
liveuser |
4408 |
}#if end
|
| 226 |
liveuser |
4409 |
|
| 3 |
liveuser |
4410 |
#反之沒有找到關鍵字
|
|
|
4411 |
else{
|
| 226 |
liveuser |
4412 |
|
| 3 |
liveuser |
4413 |
#取得該行結果
|
|
|
4414 |
$thisLine=$executeResult["lineArray"][$i];
|
| 226 |
liveuser |
4415 |
|
| 3 |
liveuser |
4416 |
#涵式說明:
|
|
|
4417 |
#處理多個字串避免網頁出錯
|
|
|
4418 |
#回傳的結果:
|
|
|
4419 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
4420 |
#$result["function"],當前執行的函數.
|
|
|
4421 |
#$result["error"],錯誤訊息
|
|
|
4422 |
#$result["processedStrArray"],處理好的字串陣列
|
|
|
4423 |
#必填的參數:
|
|
|
4424 |
$conf["stringProcess::correctMutiStrCharacter"]["stringIn"]=array($thisLine);#爲要處理的字串陣列
|
|
|
4425 |
#可省略的參數:
|
|
|
4426 |
$conf["stringProcess::correctMutiStrCharacter"]["selectedCharacter"]=array(" ","{","}",";",".",","," ");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
4427 |
#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
|
|
|
4428 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
4429 |
#$conf["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
4430 |
$thisLine=stringProcess::correctMutiStrCharacter($conf["stringProcess::correctMutiStrCharacter"]);
|
|
|
4431 |
unset($conf["stringProcess::correctMutiStrCharacter"]);
|
| 226 |
liveuser |
4432 |
|
| 3 |
liveuser |
4433 |
#如果處理結果字串出錯
|
|
|
4434 |
if($thisLine["status"]=="false"){
|
| 226 |
liveuser |
4435 |
|
| 3 |
liveuser |
4436 |
#設置執行不正常
|
|
|
4437 |
$result["status"]="false";
|
| 226 |
liveuser |
4438 |
|
| 3 |
liveuser |
4439 |
#設置錯誤訊息
|
|
|
4440 |
$result["error"]=$thisLine;
|
| 226 |
liveuser |
4441 |
|
| 3 |
liveuser |
4442 |
#回傳結果
|
|
|
4443 |
return $result;
|
| 226 |
liveuser |
4444 |
|
| 3 |
liveuser |
4445 |
}#if end
|
| 226 |
liveuser |
4446 |
|
| 3 |
liveuser |
4447 |
#涵式說明:
|
|
|
4448 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
4449 |
#回傳的參數:
|
|
|
4450 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4451 |
#$result["error"],錯誤訊息陣列
|
|
|
4452 |
#$result["function"],當前執行的函數名稱.
|
|
|
4453 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
4454 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
4455 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
4456 |
#必填的參數:
|
|
|
4457 |
$conf["stringProcess.spiltString"]["stringIn"]=$thisLine["processedStrArray"][0];#要處理的字串。
|
|
|
4458 |
$conf["stringProcess.spiltString"]["spiltSymbol"]="=";#爲以哪個符號作爲分割
|
|
|
4459 |
$conditionStr=stringProcess::spiltString($conf["stringProcess.spiltString"]);
|
|
|
4460 |
unset($conf["stringProcess.spiltString"]);
|
| 226 |
liveuser |
4461 |
|
| 3 |
liveuser |
4462 |
#如果處理結果字串出錯
|
|
|
4463 |
if($conditionStr["status"]=="false"){
|
| 226 |
liveuser |
4464 |
|
| 3 |
liveuser |
4465 |
#設置執行不正常
|
|
|
4466 |
$result["status"]="false";
|
| 226 |
liveuser |
4467 |
|
| 3 |
liveuser |
4468 |
#設置錯誤訊息
|
|
|
4469 |
$result["error"]=$conditionStr;
|
| 226 |
liveuser |
4470 |
|
| 3 |
liveuser |
4471 |
#回傳結果
|
|
|
4472 |
return $result;
|
| 226 |
liveuser |
4473 |
|
| 3 |
liveuser |
4474 |
}#if end
|
| 226 |
liveuser |
4475 |
|
| 3 |
liveuser |
4476 |
#將導致的原因變數名稱前的規則號碼剔除
|
|
|
4477 |
#涵式說明:
|
|
|
4478 |
#處理字串避免網頁出錯
|
|
|
4479 |
#回傳的結果:
|
|
|
4480 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4481 |
#$result["function"],當前執行的函數.
|
|
|
4482 |
#$result["content"],爲處理好的字串.
|
|
|
4483 |
#$result["error"],錯誤訊息陣列.
|
|
|
4484 |
#必填的參數:
|
|
|
4485 |
$conf["stringProcess::correctCharacter"]["stringIn"]=$conditionStr["dataArray"][0];#爲要處理的字串
|
|
|
4486 |
#可省略的參數:
|
|
|
4487 |
$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array($rulesNum);#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
4488 |
#若不設定則預設爲要將這些字串作替換("<",">","=","//","'","$","%","&","|","/*","*\/","#","\"")。
|
|
|
4489 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
4490 |
#$conf["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
4491 |
$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);
|
|
|
4492 |
unset($conf["stringProcess::correctCharacter"]);
|
| 226 |
liveuser |
4493 |
|
| 3 |
liveuser |
4494 |
#如果修正出錯
|
|
|
4495 |
if($correctCharacter["status"]=="false"){
|
| 226 |
liveuser |
4496 |
|
| 3 |
liveuser |
4497 |
#設置執行不正常
|
|
|
4498 |
$result["status"]="false";
|
| 226 |
liveuser |
4499 |
|
| 3 |
liveuser |
4500 |
#設置錯誤訊息
|
|
|
4501 |
$result["error"]=$correctCharacter;
|
| 226 |
liveuser |
4502 |
|
| 3 |
liveuser |
4503 |
#回傳結果
|
|
|
4504 |
return $result;
|
| 226 |
liveuser |
4505 |
|
|
|
4506 |
}#if end
|
|
|
4507 |
|
| 3 |
liveuser |
4508 |
#取得處理好的導致的原因變數名稱
|
|
|
4509 |
$rulesArray[$rulesNum]["lhsName"][]=$correctCharacter["content"];
|
| 226 |
liveuser |
4510 |
|
| 3 |
liveuser |
4511 |
#如果 $conditionStr["dataArray"][1] 不存在
|
|
|
4512 |
if(!isset($conditionStr["dataArray"][1])){
|
| 226 |
liveuser |
4513 |
|
| 3 |
liveuser |
4514 |
#設爲 ""
|
|
|
4515 |
$conditionStr["dataArray"][1]="";
|
| 226 |
liveuser |
4516 |
|
| 3 |
liveuser |
4517 |
}#if end
|
| 226 |
liveuser |
4518 |
|
| 3 |
liveuser |
4519 |
#取得導致的原因變數名稱其值爲何
|
|
|
4520 |
$rulesArray[$rulesNum]["lhsValue"][]=$conditionStr["dataArray"][1];
|
| 226 |
liveuser |
4521 |
|
| 3 |
liveuser |
4522 |
}#else end
|
| 226 |
liveuser |
4523 |
|
| 3 |
liveuser |
4524 |
}#for end
|
| 226 |
liveuser |
4525 |
|
| 3 |
liveuser |
4526 |
#取得規則內容
|
|
|
4527 |
$result["content"]["rulesArray"]=$rulesArray;
|
| 226 |
liveuser |
4528 |
|
| 3 |
liveuser |
4529 |
#取得規則的數量
|
| 226 |
liveuser |
4530 |
$result["content"]["rulesCount"]=count($rulesArray);
|
|
|
4531 |
|
|
|
4532 |
#設置執行正常
|
| 3 |
liveuser |
4533 |
$result["status"]="true";
|
| 226 |
liveuser |
4534 |
|
| 3 |
liveuser |
4535 |
#回傳結果
|
|
|
4536 |
return $result;
|
| 226 |
liveuser |
4537 |
|
| 3 |
liveuser |
4538 |
}#funciton apriori end
|
| 226 |
liveuser |
4539 |
|
| 3 |
liveuser |
4540 |
/*
|
|
|
4541 |
#函式說明:
|
|
|
4542 |
#繪製樣本中其中兩個題項填寫狀況的交叉表
|
|
|
4543 |
#回傳結果:
|
|
|
4544 |
#$result["status"],執行正常與否,"true"代表正常;"false"代表不正常
|
|
|
4545 |
#$result["error"],錯誤訊息陣列
|
|
|
4546 |
#$result["function"],當前函數名稱
|
|
|
4547 |
#$result["RscriptContent"],執行的R腳本內容
|
|
|
4548 |
#$result["content"],交叉表的資料
|
|
|
4549 |
#$result["content"]["xLabelTypeName"],欄項目的類型名稱
|
| 226 |
liveuser |
4550 |
#$result["content"]["yLabelTypeName"],列項目的類型名稱
|
| 3 |
liveuser |
4551 |
#$result["content"]["xLabelName"],欄項目名稱陣列
|
|
|
4552 |
#$result["content"]["yLabelName"],列項目名稱陣列
|
|
|
4553 |
#$result["content"][$i]["xLabelName"],交叉表從上致下,從左至右第$i+1個數值的x軸項目名稱.
|
|
|
4554 |
#$result["content"][$i]["yLabelName"],交叉表從上致下,從左至右第$i+1個數值的y軸項目名稱.
|
|
|
4555 |
#$result["content"][$i]["value"],交叉表從上致下,從左至右第$i+1個數值.
|
| 226 |
liveuser |
4556 |
#$result["content"]["htmlAddress"],交叉表html檔案的位址與檔案名稱.
|
| 3 |
liveuser |
4557 |
#必填參數:
|
|
|
4558 |
#$conf["dnnStr"],字串陣列,每個資料集的名稱
|
|
|
4559 |
$conf["dnnStr"]=array("","","");
|
|
|
4560 |
#$conf["dataArrayA"],字串陣列,要繪製交叉表的資料A,元素數量必須跟$conf["dataArrayB"]一樣。
|
|
|
4561 |
$conf["dataArrayA"]=array();
|
|
|
4562 |
#$conf["dataArrayB"],字串陣列,要繪製交叉表的資料B,元素數量必須跟$conf["dataArrayA"]一樣。
|
|
|
4563 |
$conf["dataArrayB"]=array();
|
|
|
4564 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
4565 |
$conf["fileArgu"]=__FILE__;
|
|
|
4566 |
#可省略參數:
|
|
|
4567 |
#$conf["dataArrayC"],字串陣列,要繪製交叉表的資料C(有幾種資料就會產生幾張交叉表)
|
|
|
4568 |
#$conf["dataArrayC"]=array();
|
|
|
4569 |
#$conf["crossTableAddress"],字串,產生好的crossTable網頁檔要存在哪裡,名稱為何,副檔名(.html)會自動補上,不設定的話,就不會產生html檔.
|
|
|
4570 |
#$conf["crossTableAddress"]="";
|
|
|
4571 |
#參考資料:
|
|
|
4572 |
#無.
|
|
|
4573 |
#備註:
|
|
|
4574 |
#無
|
|
|
4575 |
*/
|
|
|
4576 |
public static function table(&$conf){
|
| 226 |
liveuser |
4577 |
|
| 3 |
liveuser |
4578 |
#初始化要回傳的結果
|
|
|
4579 |
$result=array();
|
| 226 |
liveuser |
4580 |
|
| 3 |
liveuser |
4581 |
#如果 $conf 不等於 "array"
|
| 226 |
liveuser |
4582 |
if(gettype($conf)!="array"){
|
|
|
4583 |
|
| 3 |
liveuser |
4584 |
#設定錯誤識別
|
|
|
4585 |
$result["status"]="false";
|
| 226 |
liveuser |
4586 |
|
| 3 |
liveuser |
4587 |
#設置錯誤訊息
|
|
|
4588 |
$result["error"]="參數的Key指定有誤!";
|
| 226 |
liveuser |
4589 |
|
| 3 |
liveuser |
4590 |
#如果傳入的參數為 null
|
|
|
4591 |
if($conf==null){
|
| 226 |
liveuser |
4592 |
|
| 3 |
liveuser |
4593 |
#設置執行錯誤訊息
|
|
|
4594 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
4595 |
|
| 3 |
liveuser |
4596 |
}#if end
|
| 226 |
liveuser |
4597 |
|
| 3 |
liveuser |
4598 |
#回傳結果
|
|
|
4599 |
return $result;
|
| 226 |
liveuser |
4600 |
|
| 3 |
liveuser |
4601 |
}#if end
|
| 226 |
liveuser |
4602 |
|
| 3 |
liveuser |
4603 |
#如果 $_SESSION["username"] 不存在
|
|
|
4604 |
if(!isset($_SESSION["username"])){
|
| 226 |
liveuser |
4605 |
|
| 3 |
liveuser |
4606 |
#設為"NULL"
|
|
|
4607 |
$_SESSION["username"]="NULL";
|
| 226 |
liveuser |
4608 |
|
| 3 |
liveuser |
4609 |
}#if end
|
| 226 |
liveuser |
4610 |
|
| 3 |
liveuser |
4611 |
#檢查參數
|
|
|
4612 |
#函式說明:
|
|
|
4613 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
4614 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4615 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4616 |
#$result["function"],當前執行的函式名稱.
|
|
|
4617 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
4618 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
4619 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
4620 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
4621 |
#必填寫的參數:
|
|
|
4622 |
#$conf["variableCheck.checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
4623 |
$conf["variableCheck.checkArguments"]["varInput"]=&$conf;
|
|
|
4624 |
#$conf["variableCheck.checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
4625 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","dnnStr","dataArrayA","dataArrayB");
|
| 226 |
liveuser |
4626 |
#$conf["variableCheck.checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
4627 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableType"]=array("string","array","array","array");
|
|
|
4628 |
#$conf["variableCheck.checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
4629 |
$conf["variableCheck.checkArguments"]["referenceVarKey"]="variableCheck.checkArguments";
|
|
|
4630 |
#可以省略的參數:
|
|
|
4631 |
#$conf["variableCheck.checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"false"。
|
|
|
4632 |
$conf["variableCheck.checkArguments"]["canBeEmptyString"]="false";
|
|
|
4633 |
#$conf["variableCheck.checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
4634 |
$conf["variableCheck.checkArguments"]["skipableVariableName"]=array("dataArrayC","crossTableAddress");
|
| 226 |
liveuser |
4635 |
#$conf["variableCheck.checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
4636 |
$conf["variableCheck.checkArguments"]["skipableVariableType"]=array("array","string");
|
|
|
4637 |
#$conf["variableCheck.checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
4638 |
$conf["variableCheck.checkArguments"]["skipableVarDefaultValue"]=array(null,".R/table-".$_SESSION["username"].".html");
|
|
|
4639 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
4640 |
$conf["variableCheck.checkArguments"]["arrayCountEqualCheck"][]=array("dataArrayA","dataArrayB","dataArrayC");
|
|
|
4641 |
$checkArgumentsResult=variableCheck::checkArguments($conf["variableCheck.checkArguments"]);
|
|
|
4642 |
unset($conf["variableCheck.checkArguments"]);
|
| 226 |
liveuser |
4643 |
|
| 3 |
liveuser |
4644 |
#如果檢查參數失敗
|
|
|
4645 |
if($checkArgumentsResult["status"]=="false"){
|
| 226 |
liveuser |
4646 |
|
| 3 |
liveuser |
4647 |
#設置執行失敗
|
|
|
4648 |
$result["status"]="false";
|
| 226 |
liveuser |
4649 |
|
| 3 |
liveuser |
4650 |
#設置執行錯誤
|
|
|
4651 |
$result["error"]=$checkArgumentsResult;
|
| 226 |
liveuser |
4652 |
|
| 3 |
liveuser |
4653 |
#回傳結果
|
|
|
4654 |
return $result;
|
| 226 |
liveuser |
4655 |
|
| 3 |
liveuser |
4656 |
}#if end
|
| 226 |
liveuser |
4657 |
|
| 3 |
liveuser |
4658 |
#如果參數檢查不通過
|
|
|
4659 |
if($checkArgumentsResult["passed"]=="false"){
|
| 226 |
liveuser |
4660 |
|
| 3 |
liveuser |
4661 |
#設置執行失敗
|
|
|
4662 |
$result["status"]="false";
|
| 226 |
liveuser |
4663 |
|
| 3 |
liveuser |
4664 |
#設置執行錯誤
|
|
|
4665 |
$result["error"]=$checkArgumentsResult;
|
| 226 |
liveuser |
4666 |
|
| 3 |
liveuser |
4667 |
#回傳結果
|
|
|
4668 |
return $result;
|
| 226 |
liveuser |
4669 |
|
| 3 |
liveuser |
4670 |
}#if end
|
| 226 |
liveuser |
4671 |
|
| 3 |
liveuser |
4672 |
#初始化儲存資料集C的字串變數
|
|
|
4673 |
$dataArrayC="";
|
| 226 |
liveuser |
4674 |
|
| 3 |
liveuser |
4675 |
#產生用於產生交叉表的R語法
|
| 226 |
liveuser |
4676 |
|
| 3 |
liveuser |
4677 |
#初始化儲存資料集名稱的變數
|
|
|
4678 |
$dnnStr="c(";
|
| 226 |
liveuser |
4679 |
|
| 3 |
liveuser |
4680 |
#如果 $dataArrayC 等於 ""
|
|
|
4681 |
if($dataArrayC==""){
|
| 226 |
liveuser |
4682 |
|
| 3 |
liveuser |
4683 |
#串接兩個資料集名稱
|
|
|
4684 |
$dnnStr=$dnnStr."\"".$conf["dnnStr"][0]."\","."\"".$conf["dnnStr"][1]."\")";
|
| 226 |
liveuser |
4685 |
|
| 3 |
liveuser |
4686 |
#產生用於產生交叉表的R語法
|
|
|
4687 |
$table="table(dataA,dataB,dnn=dnnStr)";
|
| 226 |
liveuser |
4688 |
|
| 3 |
liveuser |
4689 |
}#if end
|
| 226 |
liveuser |
4690 |
|
| 3 |
liveuser |
4691 |
#反之
|
|
|
4692 |
else{
|
| 226 |
liveuser |
4693 |
|
| 3 |
liveuser |
4694 |
#串接三個資料集名稱
|
|
|
4695 |
$dnnStr=$dnnStr."\"".$conf["dnnStr"][0]."\","."\"".$conf["dnnStr"][1]."\""."\","."\"".$conf["dnnStr"][2]."\")";
|
| 226 |
liveuser |
4696 |
|
| 3 |
liveuser |
4697 |
$table="table(dataA,dataB,dataC,dnn=dnnStr)";
|
| 226 |
liveuser |
4698 |
|
| 3 |
liveuser |
4699 |
}#else end
|
| 226 |
liveuser |
4700 |
|
| 3 |
liveuser |
4701 |
#取得欄項目的類型名稱
|
|
|
4702 |
$result["content"]["xLabelTypeName"]=$conf["dnnStr"][1];
|
| 226 |
liveuser |
4703 |
|
|
|
4704 |
#取得列項目的類型名稱
|
| 3 |
liveuser |
4705 |
$result["content"]["yLabelTypeName"]=$conf["dnnStr"][0];
|
| 226 |
liveuser |
4706 |
|
| 3 |
liveuser |
4707 |
#涵式說明:
|
|
|
4708 |
#建立R檔案
|
|
|
4709 |
#回傳的結果:
|
|
|
4710 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
|
|
|
4711 |
#$result["error"],錯誤訊息陣列.
|
|
|
4712 |
#$result["newCreatedRfilePathAndName"],R腳本檔的位置與名稱
|
|
|
4713 |
#必填的參數:
|
|
|
4714 |
$conf["R.writeRfile"]["addAndName"]=".R/table-".$_SESSION["username"].".R";#R檔案的位置與名稱
|
|
|
4715 |
#要寫入的字串內容陣列,一個元素代表一行文字,每行結尾會自動換行。
|
|
|
4716 |
$conf["R.writeRfile"]["textToWrite"][]="#產生交叉表的R腳本";
|
|
|
4717 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
4718 |
$conf["R.writeRfile"]["textToWrite"][]="#資料集描述";
|
|
|
4719 |
$conf["R.writeRfile"]["textToWrite"][]="dnnStr=".$dnnStr;
|
|
|
4720 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
4721 |
$conf["R.writeRfile"]["textToWrite"][]="#資料集A(會稱呈現在Y軸)";
|
| 226 |
liveuser |
4722 |
|
| 3 |
liveuser |
4723 |
#建立資料集A
|
|
|
4724 |
#涵式說明:
|
|
|
4725 |
#避免超出4096bytes限制的條件下產生向量變數語法
|
|
|
4726 |
#請勿使用 __vectorPart 作為R的變數,因為這是用於組合向量變數的暫存變數.
|
|
|
4727 |
#回傳結果:
|
|
|
4728 |
#$result["status"],執行正常與否,"true"代表正常;"false"代表不正常
|
|
|
4729 |
#$result["error"],錯誤訊息陣列
|
|
|
4730 |
#$result["function"],當前函數名稱
|
|
|
4731 |
#$result["rVectorCreate"],建立R向量變數的語法陣列,一個元素代表一列的內容。
|
|
|
4732 |
#必填參數:
|
|
|
4733 |
#$conf["R::createFixedVectorVar"]["vectorName"],字串,向量變數在R裡面的名稱。
|
|
|
4734 |
$conf["R::createFixedVectorVar"]["vectorName"]="dataA";
|
|
|
4735 |
#$conf["R::createFixedVectorVar"]["vectorData"],陣列變數,要產生的向量變數資料。
|
|
|
4736 |
$conf["R::createFixedVectorVar"]["vectorData"]=$conf["dataArrayA"];
|
|
|
4737 |
#$conf["R::createFixedVectorVar"]["writeTarget"],參考陣列變數,向量變數產生的語法要寫入哪個儲存R腳本的陣列變數。
|
|
|
4738 |
$conf["R::createFixedVectorVar"]["writeTarget"]=&$conf["R.writeRfile"]["textToWrite"];
|
|
|
4739 |
$createFixedVectorVar=R::createFixedVectorVar($conf["R::createFixedVectorVar"]);
|
|
|
4740 |
unset($conf["R::createFixedVectorVar"]);
|
| 226 |
liveuser |
4741 |
|
| 3 |
liveuser |
4742 |
#如果新增建立R向量變數失敗
|
|
|
4743 |
if($createFixedVectorVar["status"]=="false"){
|
| 226 |
liveuser |
4744 |
|
| 3 |
liveuser |
4745 |
#設置執行失敗
|
|
|
4746 |
$result["status"]="false";
|
| 226 |
liveuser |
4747 |
|
| 3 |
liveuser |
4748 |
#設置執行錯誤
|
|
|
4749 |
$result["error"]=$createFixedVectorVar;
|
| 226 |
liveuser |
4750 |
|
| 3 |
liveuser |
4751 |
#回傳結果
|
|
|
4752 |
return $result;
|
| 226 |
liveuser |
4753 |
|
| 3 |
liveuser |
4754 |
}#if end
|
| 226 |
liveuser |
4755 |
|
| 3 |
liveuser |
4756 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
4757 |
$conf["R.writeRfile"]["textToWrite"][]="#資料集B(會稱呈現在X軸)";
|
| 226 |
liveuser |
4758 |
|
| 3 |
liveuser |
4759 |
#建立資料集B
|
|
|
4760 |
#涵式說明:
|
|
|
4761 |
#避免超出4096bytes限制的條件下產生向量變數語法
|
|
|
4762 |
#請勿使用 __vectorPart 作為R的變數,因為這是用於組合向量變數的暫存變數.
|
|
|
4763 |
#回傳結果:
|
|
|
4764 |
#$result["status"],執行正常與否,"true"代表正常;"false"代表不正常
|
|
|
4765 |
#$result["error"],錯誤訊息陣列
|
|
|
4766 |
#$result["function"],當前函數名稱
|
|
|
4767 |
#$result["rVectorCreate"],建立R向量變數的語法陣列,一個元素代表一列的內容。
|
|
|
4768 |
#必填參數:
|
|
|
4769 |
#$conf["R::createFixedVectorVar"]["vectorName"],字串,向量變數在R裡面的名稱。
|
|
|
4770 |
$conf["R::createFixedVectorVar"]["vectorName"]="dataB";
|
|
|
4771 |
#$conf["R::createFixedVectorVar"]["vectorData"],陣列變數,要產生的向量變數資料。
|
|
|
4772 |
$conf["R::createFixedVectorVar"]["vectorData"]=$conf["dataArrayB"];
|
|
|
4773 |
#$conf["R::createFixedVectorVar"]["writeTarget"],參考陣列變數,向量變數產生的語法要寫入哪個儲存R腳本的陣列變數。
|
|
|
4774 |
$conf["R::createFixedVectorVar"]["writeTarget"]=&$conf["R.writeRfile"]["textToWrite"];
|
|
|
4775 |
$createFixedVectorVar=R::createFixedVectorVar($conf["R::createFixedVectorVar"]);
|
|
|
4776 |
unset($conf["R::createFixedVectorVar"]);
|
| 226 |
liveuser |
4777 |
|
| 3 |
liveuser |
4778 |
#如果新增建立R向量變數失敗
|
|
|
4779 |
if($createFixedVectorVar["status"]=="false"){
|
| 226 |
liveuser |
4780 |
|
| 3 |
liveuser |
4781 |
#設置執行失敗
|
|
|
4782 |
$result["status"]="false";
|
| 226 |
liveuser |
4783 |
|
| 3 |
liveuser |
4784 |
#設置執行錯誤
|
|
|
4785 |
$result["error"]=$createFixedVectorVar;
|
| 226 |
liveuser |
4786 |
|
| 3 |
liveuser |
4787 |
#回傳結果
|
|
|
4788 |
return $result;
|
| 226 |
liveuser |
4789 |
|
| 3 |
liveuser |
4790 |
}#if end
|
| 226 |
liveuser |
4791 |
|
| 3 |
liveuser |
4792 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
4793 |
$conf["R.writeRfile"]["textToWrite"][]="#第三個資料集,有幾種資料就會繪製幾個交叉表";
|
| 226 |
liveuser |
4794 |
|
| 3 |
liveuser |
4795 |
#如果 $conf["dataArrayC"] 存在
|
|
|
4796 |
if(isset($conf["dataArrayC"])){
|
| 226 |
liveuser |
4797 |
|
| 3 |
liveuser |
4798 |
#如果 $conf["dataArrayC"] 不為 ""
|
|
|
4799 |
if($conf["dataArrayC"]!=""){
|
| 226 |
liveuser |
4800 |
|
| 3 |
liveuser |
4801 |
#建立資料集C
|
|
|
4802 |
#涵式說明:
|
|
|
4803 |
#避免超出4096bytes限制的條件下產生向量變數語法
|
|
|
4804 |
#請勿使用 __vectorPart 作為R的變數,因為這是用於組合向量變數的暫存變數.
|
|
|
4805 |
#回傳結果:
|
|
|
4806 |
#$result["status"],執行正常與否,"true"代表正常;"false"代表不正常
|
|
|
4807 |
#$result["error"],錯誤訊息陣列
|
|
|
4808 |
#$result["function"],當前函數名稱
|
|
|
4809 |
#$result["rVectorCreate"],建立R向量變數的語法陣列,一個元素代表一列的內容。
|
|
|
4810 |
#必填參數:
|
|
|
4811 |
#$conf["R::createFixedVectorVar"]["vectorName"],字串,向量變數在R裡面的名稱。
|
|
|
4812 |
$conf["R::createFixedVectorVar"]["vectorName"]="dataC";
|
|
|
4813 |
#$conf["R::createFixedVectorVar"]["vectorData"],陣列變數,要產生的向量變數資料。
|
|
|
4814 |
$conf["R::createFixedVectorVar"]["vectorData"]=$conf["dataArrayC"];
|
|
|
4815 |
#$conf["R::createFixedVectorVar"]["writeTarget"],參考陣列變數,向量變數產生的語法要寫入哪個儲存R腳本的陣列變數。
|
|
|
4816 |
$conf["R::createFixedVectorVar"]["writeTarget"]=&$conf["R.writeRfile"]["textToWrite"];
|
|
|
4817 |
$createFixedVectorVar=R::createFixedVectorVar($conf["R::createFixedVectorVar"]);
|
| 226 |
liveuser |
4818 |
unset($conf["R::createFixedVectorVar"]);
|
|
|
4819 |
|
| 3 |
liveuser |
4820 |
#如果新增建立R向量變數失敗
|
|
|
4821 |
if($createFixedVectorVar["status"]=="false"){
|
| 226 |
liveuser |
4822 |
|
| 3 |
liveuser |
4823 |
#設置執行失敗
|
|
|
4824 |
$result["status"]="false";
|
| 226 |
liveuser |
4825 |
|
| 3 |
liveuser |
4826 |
#設置執行錯誤
|
|
|
4827 |
$result["error"]=$createFixedVectorVar;
|
| 226 |
liveuser |
4828 |
|
| 3 |
liveuser |
4829 |
#回傳結果
|
|
|
4830 |
return $result;
|
| 226 |
liveuser |
4831 |
|
|
|
4832 |
}#if end
|
|
|
4833 |
|
| 3 |
liveuser |
4834 |
}#if end
|
| 226 |
liveuser |
4835 |
|
| 3 |
liveuser |
4836 |
}#if end
|
| 226 |
liveuser |
4837 |
|
| 3 |
liveuser |
4838 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
4839 |
$conf["R.writeRfile"]["textToWrite"][]="#產生交叉表";
|
|
|
4840 |
$conf["R.writeRfile"]["textToWrite"][]="data.table=".$table;
|
|
|
4841 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
4842 |
$conf["R.writeRfile"]["textToWrite"][]="#輸出列的項目名稱";
|
|
|
4843 |
$conf["R.writeRfile"]["textToWrite"][]="cat(rownames(data.table),file=\".R/table-".$_SESSION["username"]."-R-CatOutput\",append=FALSE)";
|
|
|
4844 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
4845 |
$conf["R.writeRfile"]["textToWrite"][]="#輸出換行符號附加到 .R/table-".$_SESSION["username"]."-R-CatOutput";
|
|
|
4846 |
$conf["R.writeRfile"]["textToWrite"][]="cat(\"\r\n\",file=\".R/table-".$_SESSION["username"]."-R-CatOutput\",append=TRUE)";
|
|
|
4847 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
4848 |
$conf["R.writeRfile"]["textToWrite"][]="#印出欄的項目名稱";
|
|
|
4849 |
$conf["R.writeRfile"]["textToWrite"][]="cat(colnames(data.table),file=\".R/table-".$_SESSION["username"]."-R-CatOutput\",append=TRUE)";
|
|
|
4850 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
4851 |
$conf["R.writeRfile"]["textToWrite"][]="#輸出換行符號附加到 .R/table-".$_SESSION["username"]."-R-CatOutput";
|
|
|
4852 |
$conf["R.writeRfile"]["textToWrite"][]="cat(\"\r\n\",file=\".R/table-".$_SESSION["username"]."-R-CatOutput\",append=TRUE)";
|
|
|
4853 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
4854 |
$conf["R.writeRfile"]["textToWrite"][]="#印出交叉表";
|
|
|
4855 |
$conf["R.writeRfile"]["textToWrite"][]="cat(data.table,file=\".R/table-".$_SESSION["username"]."-R-CatOutput\",append=TRUE)";
|
|
|
4856 |
$conf["R.writeRfile"]["textToWrite"][]="";
|
|
|
4857 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
4858 |
$conf["R.writeRfile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
4859 |
$writeRfile=R::writeRfile($conf["R.writeRfile"]);
|
|
|
4860 |
unset($conf["R.writeRfile"]);
|
| 226 |
liveuser |
4861 |
|
| 3 |
liveuser |
4862 |
#如果R腳本檔建立失敗
|
|
|
4863 |
if($writeRfile["status"]=="false"){
|
| 226 |
liveuser |
4864 |
|
| 3 |
liveuser |
4865 |
#設置執行不正常
|
|
|
4866 |
$result["status"]="false";
|
| 226 |
liveuser |
4867 |
|
| 3 |
liveuser |
4868 |
#設置執行錯誤訊息
|
|
|
4869 |
$result["error"]=$writeRfile;
|
| 226 |
liveuser |
4870 |
|
| 3 |
liveuser |
4871 |
#回傳結果
|
|
|
4872 |
return $result;
|
| 226 |
liveuser |
4873 |
|
| 3 |
liveuser |
4874 |
}#if end
|
| 226 |
liveuser |
4875 |
|
| 3 |
liveuser |
4876 |
#執行R腳本檔
|
|
|
4877 |
#函式說明:
|
|
|
4878 |
#執行R腳本,執行完畢後,會刪除R的腳本與暫存R執行後的輸出的檔案.
|
|
|
4879 |
#回傳的結果:
|
|
|
4880 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4881 |
#$result["errror"],錯誤訊息陣列
|
|
|
4882 |
#$result["lineArray"],字串陣列,R輸出結果,每個元素代表一行的輸出.
|
|
|
4883 |
#$result["lineCount"],整數,R輸出的總共行數.
|
|
|
4884 |
#$result["RscriptContent"],執行的R腳本內容.
|
|
|
4885 |
#必填的參數:
|
|
|
4886 |
#$conf["R.executeR"]["rPositionAndName"],字串,R腳本的位置與名稱.
|
|
|
4887 |
$conf["R.executeR"]["rPositionAndName"]=$writeRfile["newCreatedRfilePathAndName"];
|
|
|
4888 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
4889 |
$conf["R.executeR"]["fileArgu"]=$conf["fileArgu"];
|
|
|
4890 |
#可省略的參數:
|
|
|
4891 |
#$conf["R.executeR"]["disbaleOptimal"],字串,"true"代表取消輸出的優化,可以顯示版本訊息、歡迎訊息、儲存暫存檔,預設為"false"要進行優化.
|
|
|
4892 |
#$conf["R.executeR"]["disbaleOptimal"]="true";
|
|
|
4893 |
$executeRresult=R::executeR($conf["R.executeR"]);
|
|
|
4894 |
unset($conf["R.executeR"]);
|
| 226 |
liveuser |
4895 |
|
| 3 |
liveuser |
4896 |
#如果執行R腳本失敗
|
|
|
4897 |
if($executeRresult["status"]=="false"){
|
| 226 |
liveuser |
4898 |
|
| 3 |
liveuser |
4899 |
#設置執行不正常
|
|
|
4900 |
$result["status"]="false";
|
| 226 |
liveuser |
4901 |
|
| 3 |
liveuser |
4902 |
#設置執行錯誤訊息
|
|
|
4903 |
$result["error"]=$executeRresult;
|
| 226 |
liveuser |
4904 |
|
| 3 |
liveuser |
4905 |
#回傳結果
|
|
|
4906 |
return $result;
|
| 226 |
liveuser |
4907 |
|
| 3 |
liveuser |
4908 |
}#if end
|
| 226 |
liveuser |
4909 |
|
| 3 |
liveuser |
4910 |
#檢查 ".R/table-".$_SESSION["username"]."-R-CatOutput" 是否存在
|
|
|
4911 |
#涵式說明:檢查多個檔案與資料夾是否存在.
|
|
|
4912 |
#回傳的結果:
|
|
|
4913 |
#$result["varName"][$i],爲第$i個資料夾或檔案的名稱。
|
|
|
4914 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
4915 |
#必填的參數:
|
|
|
4916 |
$conf["fileAccess.checkMultiFileExist"]["fileArray"]=array(".R/table-".$_SESSION["username"]."-R-CatOutput");#要檢查書否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
4917 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
4918 |
$conf["fileAccess.checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
|
|
|
4919 |
#參考資料來源:
|
|
|
4920 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
4921 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
4922 |
$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess.checkMultiFileExist"]);
|
|
|
4923 |
unset($conf["fileAccess.checkMultiFileExist"]);
|
| 226 |
liveuser |
4924 |
|
| 3 |
liveuser |
4925 |
#如果 ".R/table-".$_SESSION["username"]."-R-CatOutput" 不存在
|
|
|
4926 |
if($checkMultiFileExist["varExist"][0]=="false"){
|
| 226 |
liveuser |
4927 |
|
| 3 |
liveuser |
4928 |
#設置執行失敗
|
|
|
4929 |
$result["status"]="false";
|
| 226 |
liveuser |
4930 |
|
| 3 |
liveuser |
4931 |
#設置執行錯誤
|
|
|
4932 |
$result["error"]=$checkMultiFileExist;
|
| 226 |
liveuser |
4933 |
|
| 3 |
liveuser |
4934 |
#回傳結果
|
|
|
4935 |
return $result;
|
| 226 |
liveuser |
4936 |
|
| 3 |
liveuser |
4937 |
}#if end
|
| 226 |
liveuser |
4938 |
|
|
|
4939 |
#讀取 ".R/table-".$_SESSION["username"]."-R-CatOutput" 檔案的內容以便存取列與欄的項目名稱.
|
| 3 |
liveuser |
4940 |
#函式說明:
|
|
|
4941 |
#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
|
|
|
4942 |
#回傳的變數說明:
|
|
|
4943 |
#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗。
|
|
|
4944 |
#$result["error"],錯誤訊息提示
|
|
|
4945 |
#$result["fileContent"],爲檔案的內容陣列
|
|
|
4946 |
#$result["lineCount"],爲檔案內容總共的行數
|
|
|
4947 |
#$result["fullContent"],為檔案的完整內容
|
|
|
4948 |
#必填的參數:
|
|
|
4949 |
$conf["fileAccess.getFileContent"]["filePositionAndName"]=".R/table-".$_SESSION["username"]."-R-CatOutput";#爲檔案的位置以及名稱
|
|
|
4950 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
4951 |
$conf["fileAccess.getFileContent"]["fileArgu"]=$conf["fileArgu"];
|
|
|
4952 |
#參考資料:
|
|
|
4953 |
#file():取得檔案內容的行數
|
|
|
4954 |
#http:#php.net/manual/en/function.file.php
|
|
|
4955 |
#rtrim():剔除透過file()取得每行內容結尾的換行符號.
|
|
|
4956 |
$getFileContent=fileAccess::getFileContent($conf["fileAccess.getFileContent"]);
|
|
|
4957 |
unset($conf["fileAccess.getFileContent"]);
|
| 226 |
liveuser |
4958 |
|
| 3 |
liveuser |
4959 |
#如果 讀取檔案 ".R/table-".$_SESSION["username"]."-R-CatOutput" 失敗
|
|
|
4960 |
if($getFileContent["status"]=="false"){
|
| 226 |
liveuser |
4961 |
|
| 3 |
liveuser |
4962 |
#設置執行失敗
|
|
|
4963 |
$result["status"]="false";
|
| 226 |
liveuser |
4964 |
|
| 3 |
liveuser |
4965 |
#設置執行錯誤
|
|
|
4966 |
$result["error"]=$getFileContent;
|
| 226 |
liveuser |
4967 |
|
| 3 |
liveuser |
4968 |
#回傳結果
|
|
|
4969 |
return $result;
|
| 226 |
liveuser |
4970 |
|
| 3 |
liveuser |
4971 |
}#if end
|
| 226 |
liveuser |
4972 |
|
| 3 |
liveuser |
4973 |
#取得列項目名稱
|
|
|
4974 |
$rowStr=$getFileContent["fileContent"][0];
|
| 226 |
liveuser |
4975 |
|
| 3 |
liveuser |
4976 |
#解析列項目名稱
|
|
|
4977 |
#涵式說明:
|
|
|
4978 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
4979 |
#回傳的參數:
|
|
|
4980 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4981 |
#$result["error"],錯誤訊息陣列
|
|
|
4982 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
4983 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
4984 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
4985 |
#必填的參數:
|
|
|
4986 |
$conf["stringProcess.spiltString"]["stringIn"]=$rowStr;#要處理的字串。
|
|
|
4987 |
$conf["stringProcess.spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
|
|
|
4988 |
#備註:
|
|
|
4989 |
#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
|
| 226 |
liveuser |
4990 |
$spiltString=stringProcess::spiltString($conf["stringProcess.spiltString"]);
|
| 3 |
liveuser |
4991 |
unset($conf["stringProcess.spiltString"]);
|
| 226 |
liveuser |
4992 |
|
| 3 |
liveuser |
4993 |
#如果解析列項目字串失敗
|
|
|
4994 |
if($spiltString["status"]=="false"){
|
| 226 |
liveuser |
4995 |
|
| 3 |
liveuser |
4996 |
#設置執行失敗
|
|
|
4997 |
$result["status"]="false";
|
| 226 |
liveuser |
4998 |
|
| 3 |
liveuser |
4999 |
#設置執行錯誤
|
|
|
5000 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
5001 |
|
| 3 |
liveuser |
5002 |
#回傳結果
|
|
|
5003 |
return $result;
|
| 226 |
liveuser |
5004 |
|
| 3 |
liveuser |
5005 |
}#if end
|
| 226 |
liveuser |
5006 |
|
|
|
5007 |
#取得解析好的列項目陣列
|
| 3 |
liveuser |
5008 |
$result["content"]["yLabelName"]=$spiltString["dataArray"];
|
| 226 |
liveuser |
5009 |
|
| 3 |
liveuser |
5010 |
#取得欄項目名稱
|
|
|
5011 |
$colStr=$getFileContent["fileContent"][1];
|
| 226 |
liveuser |
5012 |
|
| 3 |
liveuser |
5013 |
#解析欄項目名稱
|
|
|
5014 |
#涵式說明:
|
|
|
5015 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
5016 |
#回傳的參數:
|
|
|
5017 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5018 |
#$result["error"],錯誤訊息陣列
|
|
|
5019 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
5020 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
5021 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
5022 |
#必填的參數:
|
|
|
5023 |
$conf["stringProcess.spiltString"]["stringIn"]=$colStr;#要處理的字串。
|
|
|
5024 |
$conf["stringProcess.spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
|
|
|
5025 |
#備註:
|
|
|
5026 |
#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
|
| 226 |
liveuser |
5027 |
$spiltString=stringProcess::spiltString($conf["stringProcess.spiltString"]);
|
| 3 |
liveuser |
5028 |
unset($conf["stringProcess.spiltString"]);
|
| 226 |
liveuser |
5029 |
|
| 3 |
liveuser |
5030 |
#如果解析列項目字串失敗
|
|
|
5031 |
if($spiltString["status"]=="false"){
|
| 226 |
liveuser |
5032 |
|
| 3 |
liveuser |
5033 |
#設置執行失敗
|
|
|
5034 |
$result["status"]="false";
|
| 226 |
liveuser |
5035 |
|
| 3 |
liveuser |
5036 |
#設置執行錯誤
|
|
|
5037 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
5038 |
|
| 3 |
liveuser |
5039 |
#回傳結果
|
|
|
5040 |
return $result;
|
| 226 |
liveuser |
5041 |
|
| 3 |
liveuser |
5042 |
}#if end
|
| 226 |
liveuser |
5043 |
|
|
|
5044 |
#取得解析好的行項目陣列
|
| 3 |
liveuser |
5045 |
$result["content"]["xLabelName"]=$spiltString["dataArray"];
|
| 226 |
liveuser |
5046 |
|
| 3 |
liveuser |
5047 |
#解析交叉表的結果(要回傳)
|
| 226 |
liveuser |
5048 |
|
| 3 |
liveuser |
5049 |
#檢示分析好的資料
|
|
|
5050 |
#var_dump($getFileContent);
|
| 226 |
liveuser |
5051 |
|
| 3 |
liveuser |
5052 |
#取得交叉分析的資料
|
|
|
5053 |
#$getFileContent["fileContent"][2];
|
| 226 |
liveuser |
5054 |
|
| 3 |
liveuser |
5055 |
#切割 $executeRresult["lineArray"][$i] 字串
|
|
|
5056 |
#涵式說明:
|
|
|
5057 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
5058 |
#回傳的參數:
|
|
|
5059 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5060 |
#$result["error"],錯誤訊息陣列
|
|
|
5061 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
5062 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
5063 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
5064 |
#必填的參數:
|
|
|
5065 |
$conf["stringProcess.spiltString"]["stringIn"]=$getFileContent["fileContent"][2];#要處理的字串。
|
|
|
5066 |
$conf["stringProcess.spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
|
|
|
5067 |
#備註:
|
|
|
5068 |
#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
|
| 226 |
liveuser |
5069 |
$spiltString=stringProcess::spiltString($conf["stringProcess.spiltString"]);
|
| 3 |
liveuser |
5070 |
unset($conf["stringProcess.spiltString"]);
|
| 226 |
liveuser |
5071 |
|
| 3 |
liveuser |
5072 |
#如果解析列項目字串失敗
|
|
|
5073 |
if($spiltString["status"]=="false"){
|
| 226 |
liveuser |
5074 |
|
| 3 |
liveuser |
5075 |
#設置執行失敗
|
|
|
5076 |
$result["status"]="false";
|
| 226 |
liveuser |
5077 |
|
| 3 |
liveuser |
5078 |
#設置執行錯誤
|
|
|
5079 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
5080 |
|
| 3 |
liveuser |
5081 |
#回傳結果
|
|
|
5082 |
return $result;
|
| 226 |
liveuser |
5083 |
|
| 3 |
liveuser |
5084 |
}#if end
|
| 226 |
liveuser |
5085 |
|
| 3 |
liveuser |
5086 |
#有幾個交叉表的元素就執行幾次迴圈
|
|
|
5087 |
for($j=0;$j<$spiltString["dataCounts"];$j++){
|
| 226 |
liveuser |
5088 |
|
| 3 |
liveuser |
5089 |
(int)$xLabelNameKey=($j+1)/count($result["content"]["yLabelName"])-1;
|
|
|
5090 |
(int)$yLabelNameKey=($j+1)/count($result["content"]["xLabelName"])-1;
|
| 226 |
liveuser |
5091 |
|
| 3 |
liveuser |
5092 |
#$result["content"][$i]["xLabelName"],交叉表從上致下,從左至右第$i+1個數值的x軸項目名稱.
|
|
|
5093 |
#$result["content"][$i]["yLabelName"],交叉表從上致下,從左至右第$i+1個數值的y軸項目名稱.
|
|
|
5094 |
#$result["content"][$i]["value"],交叉表從上致下,從左至右第$i+1個數值.
|
| 226 |
liveuser |
5095 |
|
| 3 |
liveuser |
5096 |
#建立暫存的數值資訊陣列
|
|
|
5097 |
#參考資料來源:
|
|
|
5098 |
#http://php.net/manual/en/function.array-combine.php
|
|
|
5099 |
$keys=array("xLabelName","yLabelName","value");
|
|
|
5100 |
$values=array($result["content"]["xLabelName"][$xLabelNameKey],$result["content"]["yLabelName"][$yLabelNameKey],$spiltString["dataArray"][$j]);
|
|
|
5101 |
$tempArray=array_combine($keys,$values);
|
| 226 |
liveuser |
5102 |
|
| 3 |
liveuser |
5103 |
#取得特定數值的資訊
|
|
|
5104 |
$result["content"][]=$tempArray;
|
| 226 |
liveuser |
5105 |
|
| 3 |
liveuser |
5106 |
#debug
|
|
|
5107 |
#echo "<p>Entered!</p>";
|
| 226 |
liveuser |
5108 |
|
| 3 |
liveuser |
5109 |
}#for end
|
| 226 |
liveuser |
5110 |
|
| 3 |
liveuser |
5111 |
#移除 ".R/table-".$_SESSION["username"]."-R-CatOutput" 檔案
|
|
|
5112 |
#涵式說明:
|
|
|
5113 |
#移除檔案
|
|
|
5114 |
#回傳的結果:
|
|
|
5115 |
#$result["status"],"true"代表移除成功,"false"代表移除失敗.
|
|
|
5116 |
#$result["error"],錯誤訊息陣列
|
|
|
5117 |
#$result["warning"],警告訊息陣列
|
|
|
5118 |
#$result["function"],當前執行的函數名稱
|
|
|
5119 |
#必填的參數:
|
|
|
5120 |
$conf["=fileAccess.delFile"]["fileAddress"]=".R/table-".$_SESSION["username"]."-R-CatOutput";#要移除檔案的位置
|
|
|
5121 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
5122 |
$conf["=fileAccess.delFile"]["fileArgu"]=$conf["fileArgu"];
|
|
|
5123 |
$delFile=fileAccess::delFile($conf["=fileAccess.delFile"]);
|
|
|
5124 |
unset($conf["=fileAccess.delFile"]);
|
| 226 |
liveuser |
5125 |
|
| 3 |
liveuser |
5126 |
#如果移除檔案失敗
|
|
|
5127 |
if($delFile["status"]=="false"){
|
| 226 |
liveuser |
5128 |
|
| 3 |
liveuser |
5129 |
#設置執行失敗
|
|
|
5130 |
$result["status"]="false";
|
| 226 |
liveuser |
5131 |
|
| 3 |
liveuser |
5132 |
#設置執行錯誤
|
|
|
5133 |
$result["error"]=$delFile;
|
| 226 |
liveuser |
5134 |
|
| 3 |
liveuser |
5135 |
#回傳結果
|
|
|
5136 |
return $result;
|
| 226 |
liveuser |
5137 |
|
| 3 |
liveuser |
5138 |
}#if end
|
| 226 |
liveuser |
5139 |
|
| 3 |
liveuser |
5140 |
#取得執行的R腳本內容
|
|
|
5141 |
$result["RscriptContent"]=$executeRresult["RscriptContent"];
|
| 226 |
liveuser |
5142 |
|
| 3 |
liveuser |
5143 |
#如果 $conf["crossTableAddress"] 有設定
|
|
|
5144 |
if(isset($conf["crossTableAddress"])){
|
| 226 |
liveuser |
5145 |
|
| 3 |
liveuser |
5146 |
#如果 $conf["crossTableAddress"] 不為 ""
|
|
|
5147 |
if($conf["crossTableAddress"]!=""){
|
| 226 |
liveuser |
5148 |
|
| 3 |
liveuser |
5149 |
$conf["crossTableAddress"]=$conf["crossTableAddress"].".html";
|
| 226 |
liveuser |
5150 |
|
| 3 |
liveuser |
5151 |
#建立顯示交叉表結果的html檔案
|
|
|
5152 |
#函式說明:
|
|
|
5153 |
#檢查要建立的檔案路徑是否存在,若不存在則建立新檔案,若檔案已存在則會在原檔名後面加上從(1)開始的編號,再度嘗試建立檔案,以避免資料異常.
|
|
|
5154 |
#回傳的結果:
|
|
|
5155 |
#$result["status"],執行狀態,"true"代表執行正常,"false"代表執行失敗.
|
|
|
5156 |
#$result["error"],錯誤訊息陣列.
|
|
|
5157 |
#$result["createdFileName"],建立好的檔案名稱.
|
|
|
5158 |
#$result["createdFilePath"],檔案建立的路徑.
|
|
|
5159 |
#$result["createdFilePathAndName"].建立好的檔案名稱與路徑.
|
|
|
5160 |
#必填的參數:
|
|
|
5161 |
#$conf["checkedFileAndPath"],字串陣列,要建立的檔案路徑
|
|
|
5162 |
$conf["fileAccess"]["createFileAfterCheck"]["checkedFileAndPath"]=$conf["crossTableAddress"];
|
|
|
5163 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
5164 |
$conf["fileAccess"]["createFileAfterCheck"]["fileArgu"]=$conf["fileArgu"];
|
|
|
5165 |
$createHtmlFile=fileAccess::createFileAfterCheck($conf["fileAccess"]["createFileAfterCheck"]);
|
|
|
5166 |
unset($conf["fileAccess"]["createFileAfterCheck"]);
|
| 226 |
liveuser |
5167 |
|
| 3 |
liveuser |
5168 |
#如果建立顯示交叉表結果的html檔案失敗
|
|
|
5169 |
if($createHtmlFile["status"]=="false"){
|
| 226 |
liveuser |
5170 |
|
| 3 |
liveuser |
5171 |
#設置執行不正常的識別
|
|
|
5172 |
$result["status"]="false";
|
| 226 |
liveuser |
5173 |
|
| 3 |
liveuser |
5174 |
#設置錯誤訊息
|
|
|
5175 |
$result["status"]=$createHtmlFile;
|
| 226 |
liveuser |
5176 |
|
| 3 |
liveuser |
5177 |
#回傳結果
|
|
|
5178 |
return $result;
|
| 226 |
liveuser |
5179 |
|
| 3 |
liveuser |
5180 |
}#if end
|
| 226 |
liveuser |
5181 |
|
| 3 |
liveuser |
5182 |
#初始化表格的內容語法
|
|
|
5183 |
$tableContent="<table border = 1px>";
|
| 226 |
liveuser |
5184 |
|
| 3 |
liveuser |
5185 |
#第一列開始
|
|
|
5186 |
$tableContent=$tableContent."<tr>";
|
| 226 |
liveuser |
5187 |
|
| 3 |
liveuser |
5188 |
#第一列第一個元素
|
|
|
5189 |
$tableContent=$tableContent."<td>".$result["content"]["yLabelTypeName"]."\\".$result["content"]["xLabelTypeName"]."</td>";
|
| 226 |
liveuser |
5190 |
|
| 3 |
liveuser |
5191 |
#第一列後面其他的元素
|
| 226 |
liveuser |
5192 |
|
| 3 |
liveuser |
5193 |
#有幾個 $result["content"]["xLabelName"] 就執行幾次
|
|
|
5194 |
for($i=0;$i<count($result["content"]["xLabelName"]);$i++){
|
| 226 |
liveuser |
5195 |
|
| 3 |
liveuser |
5196 |
$tableContent=$tableContent."<td>".$result["content"]["xLabelName"][$i]."</td>";
|
| 226 |
liveuser |
5197 |
|
| 3 |
liveuser |
5198 |
}#for end
|
| 226 |
liveuser |
5199 |
|
| 3 |
liveuser |
5200 |
#第一列結束
|
|
|
5201 |
$tableContent=$tableContent."</tr>";
|
| 226 |
liveuser |
5202 |
|
| 3 |
liveuser |
5203 |
#有幾個 $result["content"]["yLabelName"] 就執行幾次
|
|
|
5204 |
for($i=0;$i<count($result["content"]["yLabelName"]);$i++){
|
| 226 |
liveuser |
5205 |
|
| 3 |
liveuser |
5206 |
#第$i+1列開始
|
|
|
5207 |
$tableContent=$tableContent."<tr>";
|
| 226 |
liveuser |
5208 |
|
| 3 |
liveuser |
5209 |
#第$i+1列的名稱
|
|
|
5210 |
$tableContent=$tableContent."<td>".$result["content"]["yLabelName"][$i]."</td>";
|
| 226 |
liveuser |
5211 |
|
| 3 |
liveuser |
5212 |
#有幾個 $result["content"]["xLabelName"] 就執行幾次
|
|
|
5213 |
for($j=0;$j<count($result["content"]["xLabelName"]);$j++){
|
| 226 |
liveuser |
5214 |
|
| 3 |
liveuser |
5215 |
#第$i+1列 第$j+1欄的 數值內容
|
|
|
5216 |
$tableContent=$tableContent."<td>".$result["content"][($i*count($result["content"]["xLabelTypeName"])+$j)]["value"]."</td>";
|
| 226 |
liveuser |
5217 |
|
| 3 |
liveuser |
5218 |
}#for end
|
| 226 |
liveuser |
5219 |
|
| 3 |
liveuser |
5220 |
#第$i+1列結束
|
| 226 |
liveuser |
5221 |
$tableContent=$tableContent."</tr>";
|
|
|
5222 |
|
| 3 |
liveuser |
5223 |
}#for end
|
| 226 |
liveuser |
5224 |
|
| 3 |
liveuser |
5225 |
#表格語法的結束
|
|
|
5226 |
$tableContent=$tableContent."</table>";
|
| 226 |
liveuser |
5227 |
|
| 3 |
liveuser |
5228 |
#寫入產生交叉表的html語法
|
|
|
5229 |
#涵式說明:
|
|
|
5230 |
#將多行字串寫入到檔案
|
|
|
5231 |
#回傳的結果:
|
|
|
5232 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
5233 |
#$result["error"],錯誤訊息陣列.
|
|
|
5234 |
#必填的參數:
|
|
|
5235 |
#$conf["fileAccess.writeMultiLine"]["fileName"],字串,爲要編輯的檔案名稱
|
|
|
5236 |
$conf["fileAccess.writeMultiLine"]["fileName"]=$createHtmlFile["createdFilePathAndName"];
|
|
|
5237 |
#$conf["fileAccess.writeMultiLine"]["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容
|
|
|
5238 |
#$conf["fileAccess.writeMultiLine"]["inputString"][$i] 代表第 $i+1 行。
|
|
|
5239 |
$conf["fileAccess.writeMultiLine"]["inputString"][]="<html>";
|
|
|
5240 |
$conf["fileAccess.writeMultiLine"]["inputString"][]="<head>";
|
|
|
5241 |
$conf["fileAccess.writeMultiLine"]["inputString"][]="<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">";
|
|
|
5242 |
$conf["fileAccess.writeMultiLine"]["inputString"][]="</head>";
|
|
|
5243 |
$conf["fileAccess.writeMultiLine"]["inputString"][]="<body>";
|
|
|
5244 |
$conf["fileAccess.writeMultiLine"]["inputString"][]=$tableContent;
|
|
|
5245 |
$conf["fileAccess.writeMultiLine"]["inputString"][]="</body>";
|
|
|
5246 |
$conf["fileAccess.writeMultiLine"]["inputString"][]="</html>";
|
|
|
5247 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
5248 |
$conf["fileAccess.writeMultiLine"]["fileArgu"]=$conf["fileArgu"];
|
|
|
5249 |
#可省略的參數:
|
|
|
5250 |
#$conf["fileAccess.writeMultiLine"]["inputString"]["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
|
|
|
5251 |
$writeHtmlData=fileAccess::writeMultiLine($conf["fileAccess.writeMultiLine"]);
|
| 226 |
liveuser |
5252 |
unset($conf["fileAccess.writeMultiLine"]);
|
|
|
5253 |
|
| 3 |
liveuser |
5254 |
#如果 寫入html 語法失敗
|
|
|
5255 |
if($writeHtmlData["status"]=="false"){
|
| 226 |
liveuser |
5256 |
|
| 3 |
liveuser |
5257 |
#設置執行不正常的識別
|
|
|
5258 |
$result["status"]="false";
|
| 226 |
liveuser |
5259 |
|
| 3 |
liveuser |
5260 |
#設置錯誤訊息
|
|
|
5261 |
$result["status"]=$writeHtmlData;
|
| 226 |
liveuser |
5262 |
|
| 3 |
liveuser |
5263 |
#回傳結果
|
|
|
5264 |
return $result;
|
| 226 |
liveuser |
5265 |
|
| 3 |
liveuser |
5266 |
}#if end
|
| 226 |
liveuser |
5267 |
|
| 3 |
liveuser |
5268 |
}#if end
|
| 226 |
liveuser |
5269 |
|
| 3 |
liveuser |
5270 |
}#if end
|
| 226 |
liveuser |
5271 |
|
| 3 |
liveuser |
5272 |
#如果有設定交叉表網頁檔的保存位置
|
|
|
5273 |
if(isset($conf["crossTableAddress"])){
|
| 226 |
liveuser |
5274 |
|
|
|
5275 |
#取得網頁檔案位置
|
| 3 |
liveuser |
5276 |
$result["content"]["htmlAddress"]=$conf["crossTableAddress"];
|
| 226 |
liveuser |
5277 |
|
| 3 |
liveuser |
5278 |
}#if end
|
| 226 |
liveuser |
5279 |
|
| 3 |
liveuser |
5280 |
#設置執行正常
|
|
|
5281 |
$result["status"]="true";
|
| 226 |
liveuser |
5282 |
|
| 3 |
liveuser |
5283 |
#回傳結果
|
|
|
5284 |
return $result;
|
| 226 |
liveuser |
5285 |
|
| 3 |
liveuser |
5286 |
}#function table end
|
| 226 |
liveuser |
5287 |
|
| 3 |
liveuser |
5288 |
/*
|
|
|
5289 |
#函式說明:
|
|
|
5290 |
#交叉分析,分析兩變數的關係,將結果輸出到html檔案裡面,其中若樣本數大於30則用卡方檢定,若樣本數小於30則用費雪精確獨立性檢定。
|
|
|
5291 |
#回傳結果:
|
|
|
5292 |
#$result["status"],執行正常與否,"true"代表正常;"false"代表不正常
|
|
|
5293 |
#$result["error"],錯誤訊息陣列
|
|
|
5294 |
#$result["function"],當前函數名稱
|
| 226 |
liveuser |
5295 |
#$result["content"],分析結果
|
| 3 |
liveuser |
5296 |
#$result["content"]["htmlReport"],報表網頁檔的位置
|
|
|
5297 |
#$result["content"]["pairedDataCount"],觀察值的筆數
|
|
|
5298 |
#$result["content"]["varAtype"],變數一的類別陣列
|
|
|
5299 |
#$result["content"]["varBtype"],變數二的類別陣列
|
|
|
5300 |
#$result["content"]["array"]["變數一類別之一"]["變數二類別之一"]["count"],變數一與變數二交叉位置的頻率
|
|
|
5301 |
#$result["content"]["array"]["變數一類別之一"]["變數二類別之一"]["radio"],變數一與變數二交叉位置的比例
|
|
|
5302 |
#$result["content"]["chi2"],卡方值,若不適用則為"null".
|
|
|
5303 |
#$result["content"]["df"],自由度,若不適用則為"null"
|
|
|
5304 |
#$result["content"]["chi2pValue"],p值,若不適用則為"null"
|
| 226 |
liveuser |
5305 |
#$result["content"]["fisherTestVarRelationship"],取得費雪檢定的兩變數關係,若不適用則為"null"
|
| 3 |
liveuser |
5306 |
#$result["content"]["fisherTestPvalue"],取得費雪檢定的p值,若不適用則為"null"
|
|
|
5307 |
#$result["content"]["rCode"],執行的R程式內容.
|
|
|
5308 |
#$result["content"]["rCodeFile"],#儲存輸出的R程式檔案位置與名稱.
|
|
|
5309 |
#$result["content"]["rawOutput"],R原始的分析結果輸出.
|
|
|
5310 |
#必填參數:
|
|
|
5311 |
#$conf["dnnStr"],字串陣列,每個資料集的名稱
|
|
|
5312 |
$conf["dnnStr"]=array("","");
|
|
|
5313 |
#$conf["dataArrayA"],字串陣列,要繪製交叉表的資料A,元素數量必須跟$conf["dataArrayB"]一樣。
|
|
|
5314 |
$conf["dataArrayA"]=array();
|
|
|
5315 |
#$conf["dataArrayB"],字串陣列,要繪製交叉表的資料B,元素數量必須跟$conf["dataArrayA"]一樣。
|
|
|
5316 |
$conf["dataArrayB"]=array();
|
|
|
5317 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
5318 |
$conf["fileArgu"]=__FILE__;
|
|
|
5319 |
#可省略參數:
|
|
|
5320 |
#$conf["outRfile"],字串,輸出執行的R程式腳本其儲存位置與名稱,副檔名「.R」會自動加上,預設不輸出.
|
|
|
5321 |
#$conf["outRfile"]="";
|
|
|
5322 |
#$conf["crossTableAddress"],字串,產生好的交叉分析網頁檔要存在哪裡,名稱為何,副檔名(.html)會自動補上,預設的位置與名稱為".R/crossTable-".$_SESSION["username"]
|
|
|
5323 |
#$conf["crossTableAddress"]="";
|
|
|
5324 |
#$conf["title"],字串陣列,交叉表的標題,一個元素代表一列,預設為"交叉表"
|
|
|
5325 |
#$conf["title"]=array("交叉表");
|
|
|
5326 |
#參考資料來源:
|
|
|
5327 |
#http://www2.nsysu.edu.tw/politics/liu/teaching/dataAnalysis/lectureNotes/03_descriptiveStatistics.R
|
|
|
5328 |
#卡方獨立性(或稱齊一性)檢定=>http://www.r-web.com.tw/stat/step1.php?method=chi2_test_ind_hom
|
|
|
5329 |
#費雪精確檢定=>http://www.r-web.com.tw/stat/step1.php?method=fisher_test
|
|
|
5330 |
#備註:
|
|
|
5331 |
#取得比例有時會失敗
|
|
|
5332 |
*/
|
|
|
5333 |
public static function crossTable(&$conf){
|
| 226 |
liveuser |
5334 |
|
| 3 |
liveuser |
5335 |
#初始化要回傳的內容
|
|
|
5336 |
$result=array();
|
| 226 |
liveuser |
5337 |
|
| 3 |
liveuser |
5338 |
#取得當前函數名稱
|
|
|
5339 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
5340 |
|
| 3 |
liveuser |
5341 |
#如果 $conf 不為陣列
|
|
|
5342 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
5343 |
|
| 3 |
liveuser |
5344 |
#設置執行失敗
|
|
|
5345 |
$result["status"]="false";
|
| 226 |
liveuser |
5346 |
|
| 3 |
liveuser |
5347 |
#設置執行錯誤訊息
|
|
|
5348 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
5349 |
|
|
|
5350 |
#如果傳入的參數為 null
|
|
|
5351 |
if($conf==null){
|
| 226 |
liveuser |
5352 |
|
| 3 |
liveuser |
5353 |
#設置執行錯誤訊息
|
|
|
5354 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
5355 |
|
| 3 |
liveuser |
5356 |
}#if end
|
|
|
5357 |
|
|
|
5358 |
#回傳結果
|
|
|
5359 |
return $result;
|
| 226 |
liveuser |
5360 |
|
| 3 |
liveuser |
5361 |
}#if end
|
| 226 |
liveuser |
5362 |
|
| 3 |
liveuser |
5363 |
#如果 $_SESSION["username"] 不存在
|
|
|
5364 |
if(!isset($_SESSION["username"])){
|
| 226 |
liveuser |
5365 |
|
| 3 |
liveuser |
5366 |
#設為"NULL"
|
|
|
5367 |
$_SESSION["username"]="NULL";
|
| 226 |
liveuser |
5368 |
|
| 3 |
liveuser |
5369 |
}#if end
|
| 226 |
liveuser |
5370 |
|
| 3 |
liveuser |
5371 |
#檢查參數
|
|
|
5372 |
#函式說明:
|
|
|
5373 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
5374 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5375 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
5376 |
#$result["function"],當前執行的函式名稱.
|
|
|
5377 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
5378 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
5379 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
5380 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
5381 |
#必填寫的參數:
|
|
|
5382 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
5383 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
5384 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
5385 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","dnnStr","dataArrayA","dataArrayB");
|
| 226 |
liveuser |
5386 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
5387 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array","array","array");
|
|
|
5388 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
5389 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
5390 |
#可以省略的參數:
|
|
|
5391 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
5392 |
#$conf["canBeEmptyString"]="false";
|
|
|
5393 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
5394 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("crossTableAddress","title","outRfile");
|
| 226 |
liveuser |
5395 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
5396 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","string");
|
|
|
5397 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
5398 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(".R/crossTable-".$_SESSION["username"],array("交叉表"),"null");
|
|
|
5399 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
5400 |
$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("dataArrayA","dataArrayB");
|
|
|
5401 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
5402 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
5403 |
|
| 3 |
liveuser |
5404 |
#如果檢查失敗
|
|
|
5405 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
5406 |
|
| 3 |
liveuser |
5407 |
#設置執行不正常
|
|
|
5408 |
$result["status"]="false";
|
| 226 |
liveuser |
5409 |
|
| 3 |
liveuser |
5410 |
#設置錯誤訊息
|
|
|
5411 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
5412 |
|
| 3 |
liveuser |
5413 |
#回傳結果
|
|
|
5414 |
return $result;
|
| 226 |
liveuser |
5415 |
|
| 3 |
liveuser |
5416 |
}#if end
|
| 226 |
liveuser |
5417 |
|
| 3 |
liveuser |
5418 |
#如果檢查不通過
|
|
|
5419 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
5420 |
|
| 3 |
liveuser |
5421 |
#設置執行不正常
|
|
|
5422 |
$result["status"]="false";
|
| 226 |
liveuser |
5423 |
|
| 3 |
liveuser |
5424 |
#設置錯誤訊息
|
|
|
5425 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
5426 |
|
| 3 |
liveuser |
5427 |
#回傳結果
|
|
|
5428 |
return $result;
|
| 226 |
liveuser |
5429 |
|
| 3 |
liveuser |
5430 |
}#if end
|
| 226 |
liveuser |
5431 |
|
| 3 |
liveuser |
5432 |
#產生資料標題R語法字串
|
|
|
5433 |
$r_VarTitle="dnnStr=c(\"".$conf["dnnStr"][0]."\",\"".$conf["dnnStr"][1]."\")";
|
| 226 |
liveuser |
5434 |
|
| 3 |
liveuser |
5435 |
#涵式說明:
|
|
|
5436 |
#建立R檔案
|
|
|
5437 |
#回傳的結果:
|
|
|
5438 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
|
|
|
5439 |
#$result["error"],錯誤訊息陣列.
|
|
|
5440 |
#$result["newCreatedRfilePathAndName"],R腳本檔的位置與名稱
|
|
|
5441 |
#必填的參數:
|
|
|
5442 |
$conf["R::writeRfile"]["addAndName"]=".R/crossTable-".$_SESSION["username"].".R";#R檔案的位置與名稱
|
|
|
5443 |
#$conf["R::writeRfile"]["textToWrite"]=array("");#要寫入的字串內容陣列,一個元素代表一行文字,每行結尾會自動換行。
|
|
|
5444 |
$conf["R::writeRfile"]["textToWrite"][]="#匯入gmodels套件";
|
|
|
5445 |
$conf["R::writeRfile"]["textToWrite"][]="library(gmodels)";
|
|
|
5446 |
$conf["R::writeRfile"]["textToWrite"][]="";
|
|
|
5447 |
$conf["R::writeRfile"]["textToWrite"][]="#產生資料標題";
|
|
|
5448 |
$conf["R::writeRfile"]["textToWrite"][]=$r_VarTitle;
|
|
|
5449 |
$conf["R::writeRfile"]["textToWrite"][]="";
|
| 226 |
liveuser |
5450 |
|
| 3 |
liveuser |
5451 |
#從 $conf["dataArrayA"] 產生R資料變數
|
|
|
5452 |
#涵式說明:
|
|
|
5453 |
#避免超出4096bytes限制的條件下產生向量變數語法
|
|
|
5454 |
#請勿使用 vectorPart 作為R的變數,因為這是用於組合向量變數的暫存變數.
|
|
|
5455 |
#回傳結果:
|
|
|
5456 |
#$result["status"],執行正常與否,"true"代表正常;"false"代表不正常
|
|
|
5457 |
#$result["error"],錯誤訊息陣列
|
|
|
5458 |
#$result["function"],當前函數名稱
|
|
|
5459 |
#$result["rVectorCreate"],建立R向量變數的語法陣列,一個元素代表一列的內容。
|
|
|
5460 |
#必填參數:
|
|
|
5461 |
#$conf["vectorName"],字串,向量變數在R裡面的名稱。
|
|
|
5462 |
$conf["R::createFixedVectorVar"]["vectorName"]="var1";
|
|
|
5463 |
#$conf["vectorData"],陣列變數,要產生的向量變數資料。
|
|
|
5464 |
$conf["R::createFixedVectorVar"]["vectorData"]=$conf["dataArrayA"];
|
|
|
5465 |
#$conf["writeTarget"],參考陣列變數,向量變數產生的語法要寫入哪個儲存R腳本的陣列變數。
|
|
|
5466 |
$conf["R::createFixedVectorVar"]["writeTarget"]=&$conf["R::writeRfile"]["textToWrite"];
|
|
|
5467 |
$createFixedVectorVar=R::createFixedVectorVar($conf["R::createFixedVectorVar"]);
|
|
|
5468 |
unset($conf["R::createFixedVectorVar"]);
|
| 226 |
liveuser |
5469 |
|
| 3 |
liveuser |
5470 |
#如果從 $conf["dataArrayA"] 產生R資料變數失敗
|
|
|
5471 |
if($createFixedVectorVar["status"]=="false"){
|
| 226 |
liveuser |
5472 |
|
| 3 |
liveuser |
5473 |
#設置執行不正常
|
|
|
5474 |
$result["status"]="false";
|
| 226 |
liveuser |
5475 |
|
| 3 |
liveuser |
5476 |
#設置錯誤訊息
|
|
|
5477 |
$result["error"]=$createFixedVectorVar;
|
| 226 |
liveuser |
5478 |
|
| 3 |
liveuser |
5479 |
#回傳結果
|
|
|
5480 |
return $result;
|
| 226 |
liveuser |
5481 |
|
| 3 |
liveuser |
5482 |
}#if end
|
| 226 |
liveuser |
5483 |
|
| 3 |
liveuser |
5484 |
$conf["R::writeRfile"]["textToWrite"][]="";
|
| 226 |
liveuser |
5485 |
|
| 3 |
liveuser |
5486 |
#從 $conf["dataArrayB"] 產生R資料變數
|
|
|
5487 |
#涵式說明:
|
|
|
5488 |
#避免超出4096bytes限制的條件下產生向量變數語法
|
|
|
5489 |
#請勿使用 vectorPart 作為R的變數,因為這是用於組合向量變數的暫存變數.
|
|
|
5490 |
#回傳結果:
|
|
|
5491 |
#$result["status"],執行正常與否,"true"代表正常;"false"代表不正常
|
|
|
5492 |
#$result["error"],錯誤訊息陣列
|
|
|
5493 |
#$result["function"],當前函數名稱
|
|
|
5494 |
#$result["rVectorCreate"],建立R向量變數的語法陣列,一個元素代表一列的內容。
|
|
|
5495 |
#必填參數:
|
|
|
5496 |
#$conf["vectorName"],字串,向量變數在R裡面的名稱。
|
|
|
5497 |
$conf["R::createFixedVectorVar"]["vectorName"]="var2";
|
|
|
5498 |
#$conf["vectorData"],陣列變數,要產生的向量變數資料。
|
|
|
5499 |
$conf["R::createFixedVectorVar"]["vectorData"]=$conf["dataArrayB"];
|
|
|
5500 |
#$conf["writeTarget"],參考陣列變數,向量變數產生的語法要寫入哪個儲存R腳本的陣列變數。
|
|
|
5501 |
$conf["R::createFixedVectorVar"]["writeTarget"]=&$conf["R::writeRfile"]["textToWrite"];
|
|
|
5502 |
$createFixedVectorVar=R::createFixedVectorVar($conf["R::createFixedVectorVar"]);
|
|
|
5503 |
unset($conf["R::createFixedVectorVar"]);
|
| 226 |
liveuser |
5504 |
|
| 3 |
liveuser |
5505 |
#如果從 $conf["dataArrayB"] 產生R資料變數失敗
|
|
|
5506 |
if($createFixedVectorVar["status"]=="false"){
|
| 226 |
liveuser |
5507 |
|
| 3 |
liveuser |
5508 |
#設置執行不正常
|
|
|
5509 |
$result["status"]="false";
|
| 226 |
liveuser |
5510 |
|
| 3 |
liveuser |
5511 |
#設置錯誤訊息
|
|
|
5512 |
$result["error"]=$createFixedVectorVar;
|
| 226 |
liveuser |
5513 |
|
| 3 |
liveuser |
5514 |
#回傳結果
|
|
|
5515 |
return $result;
|
| 226 |
liveuser |
5516 |
|
| 3 |
liveuser |
5517 |
}#if end
|
| 226 |
liveuser |
5518 |
|
| 3 |
liveuser |
5519 |
$conf["R::writeRfile"]["textToWrite"][]="";
|
| 226 |
liveuser |
5520 |
|
| 3 |
liveuser |
5521 |
#放置交叉分析的語法
|
|
|
5522 |
$conf["R::writeRfile"]["textToWrite"][]="#交叉分析";
|
| 226 |
liveuser |
5523 |
|
| 3 |
liveuser |
5524 |
#如果是小樣本(總樣本數30筆以下)
|
|
|
5525 |
if(count($conf["dataArrayA"])<30){
|
| 226 |
liveuser |
5526 |
|
| 3 |
liveuser |
5527 |
$conf["R::writeRfile"]["textToWrite"][]="CrossTable(var1,var2,dnn=dnnStr,prop.t=FALSE,prop.c=FALSE,prop.chisq=FALSE,chisq=TRUE,fisher=TRUE)";
|
| 226 |
liveuser |
5528 |
|
| 3 |
liveuser |
5529 |
}#if end
|
| 226 |
liveuser |
5530 |
|
|
|
5531 |
#反之是大樣本
|
| 3 |
liveuser |
5532 |
else{
|
| 226 |
liveuser |
5533 |
|
| 3 |
liveuser |
5534 |
$conf["R::writeRfile"]["textToWrite"][]="CrossTable(var1,var2,dnn=dnnStr,prop.t=FALSE,prop.c=FALSE,prop.chisq=FALSE,chisq=TRUE,fisher=FALSE)";
|
| 226 |
liveuser |
5535 |
|
| 3 |
liveuser |
5536 |
}#if end
|
| 226 |
liveuser |
5537 |
|
| 3 |
liveuser |
5538 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
| 226 |
liveuser |
5539 |
$conf["R::writeRfile"]["fileArgu"]=$conf["fileArgu"];
|
| 3 |
liveuser |
5540 |
$writeRfile=R::writeRfile($conf["R::writeRfile"]);
|
|
|
5541 |
unset($conf["R::writeRfile"]);
|
| 226 |
liveuser |
5542 |
|
| 3 |
liveuser |
5543 |
#如果建立R腳本檔案失敗
|
|
|
5544 |
if($writeRfile["status"]=="false"){
|
| 226 |
liveuser |
5545 |
|
| 3 |
liveuser |
5546 |
#設置執行不正常
|
|
|
5547 |
$result["status"]="false";
|
| 226 |
liveuser |
5548 |
|
| 3 |
liveuser |
5549 |
#設置錯誤訊息
|
|
|
5550 |
$result["error"]=$writeRfile;
|
| 226 |
liveuser |
5551 |
|
| 3 |
liveuser |
5552 |
#回傳結果
|
|
|
5553 |
return $result;
|
| 226 |
liveuser |
5554 |
|
| 3 |
liveuser |
5555 |
}#if end
|
| 226 |
liveuser |
5556 |
|
| 3 |
liveuser |
5557 |
#函式說明:
|
|
|
5558 |
#執行R腳本,執行完畢後,會刪除R的腳本與暫存R執行後的輸出的檔案.
|
|
|
5559 |
#回傳的結果:
|
|
|
5560 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5561 |
#$result["errror"],錯誤訊息陣列
|
|
|
5562 |
#$result["lineArray"],字串陣列,R輸出結果,每個元素代表一行的輸出.
|
|
|
5563 |
#$result["lineCount"],整數,R輸出的總共行數.
|
|
|
5564 |
#$result["RscriptContent"],執行的R腳本內容,一個元素代表一列.
|
|
|
5565 |
#必填的參數:
|
|
|
5566 |
#$conf["rPositionAndName"],字串,R腳本的位置與名稱.
|
|
|
5567 |
$conf["R::executeR"]["rPositionAndName"]=$writeRfile["newCreatedRfilePathAndName"];
|
|
|
5568 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
5569 |
$conf["R::executeR"]["fileArgu"]=$conf["fileArgu"];
|
|
|
5570 |
#可省略的參數:
|
|
|
5571 |
#$conf["disbaleOptimal"],字串,"true"代表取消輸出的優化,可以顯示版本訊息、歡迎訊息、儲存暫存檔,預設為"false"要進行優化.
|
|
|
5572 |
#$conf["disbaleOptimal"]="true";
|
|
|
5573 |
$executeR=R::executeR($conf["R::executeR"]);
|
|
|
5574 |
unset($conf["R::executeR"]);
|
| 226 |
liveuser |
5575 |
|
| 3 |
liveuser |
5576 |
#如果執行R腳本失敗
|
|
|
5577 |
if($executeR["status"]=="false"){
|
| 226 |
liveuser |
5578 |
|
| 3 |
liveuser |
5579 |
#設置執行不正常
|
|
|
5580 |
$result["status"]="false";
|
| 226 |
liveuser |
5581 |
|
| 3 |
liveuser |
5582 |
#設置錯誤訊息
|
|
|
5583 |
$result["error"]=$executeR;
|
| 226 |
liveuser |
5584 |
|
| 3 |
liveuser |
5585 |
#回傳結果
|
|
|
5586 |
return $result;
|
| 226 |
liveuser |
5587 |
|
| 3 |
liveuser |
5588 |
}#if end
|
| 226 |
liveuser |
5589 |
|
| 3 |
liveuser |
5590 |
#取得交叉分析的原始結果
|
|
|
5591 |
$result["content"]["rawOutput"]=$executeR["lineArray"];
|
| 226 |
liveuser |
5592 |
|
| 3 |
liveuser |
5593 |
#取得執行的R腳本內容
|
|
|
5594 |
$result["content"]["rCode"]=$executeR["RscriptContent"];
|
| 226 |
liveuser |
5595 |
|
| 3 |
liveuser |
5596 |
#如果有設置 $conf["outRfile"]
|
|
|
5597 |
if($conf["outRfile"]){
|
| 226 |
liveuser |
5598 |
|
| 3 |
liveuser |
5599 |
#將 $result["content"]["rCode"] 內容寫入到 R 檔案裡面
|
|
|
5600 |
#涵式說明:
|
|
|
5601 |
#將多行字串寫入到檔案
|
|
|
5602 |
#回傳的結果:
|
|
|
5603 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
5604 |
#$result["error"],錯誤訊息陣列.
|
|
|
5605 |
#必填的參數:
|
|
|
5606 |
#$conf["fileName"],字串,爲要編輯的檔案名稱
|
|
|
5607 |
$conf["fileAccess::writeMultiLine"]["fileName"]=$conf["outRfile"].".R";
|
|
|
5608 |
#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容
|
|
|
5609 |
#$conf["inputString"][$i] 代表第 $i+1 行。
|
|
|
5610 |
$conf["fileAccess::writeMultiLine"]["inputString"]=$result["content"]["rCode"];
|
|
|
5611 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
5612 |
$conf["fileAccess::writeMultiLine"]["fileArgu"]=$conf["fileArgu"];
|
|
|
5613 |
#可省略的參數:
|
|
|
5614 |
#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
|
|
|
5615 |
$outRfile=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
|
|
|
5616 |
unset($conf["fileAccess::writeMultiLine"]);
|
| 226 |
liveuser |
5617 |
|
| 3 |
liveuser |
5618 |
#如果輸出R腳本失敗
|
|
|
5619 |
if($outRfile["status"]=="false"){
|
| 226 |
liveuser |
5620 |
|
| 3 |
liveuser |
5621 |
#設置執行不正常
|
|
|
5622 |
$result["status"]="false";
|
| 226 |
liveuser |
5623 |
|
| 3 |
liveuser |
5624 |
#設置錯誤訊息
|
|
|
5625 |
$result["error"]=$outRfile;
|
| 226 |
liveuser |
5626 |
|
| 3 |
liveuser |
5627 |
#回傳結果
|
|
|
5628 |
return $result;
|
| 226 |
liveuser |
5629 |
|
| 3 |
liveuser |
5630 |
}#if end
|
| 226 |
liveuser |
5631 |
|
| 3 |
liveuser |
5632 |
#儲存輸出的R程式檔案位置與名稱
|
|
|
5633 |
$result["content"]["rCodeFile"]=$conf["outRfile"].".R";
|
| 226 |
liveuser |
5634 |
|
| 3 |
liveuser |
5635 |
}#if end
|
| 226 |
liveuser |
5636 |
|
| 3 |
liveuser |
5637 |
#初始化儲存資料分析的起點列數
|
|
|
5638 |
$rowStartLine=0;
|
| 226 |
liveuser |
5639 |
|
| 3 |
liveuser |
5640 |
#有幾列輸出就執行幾次迴圈
|
|
|
5641 |
for($i=0;$i<$executeR["lineCount"];$i++){
|
| 226 |
liveuser |
5642 |
|
| 3 |
liveuser |
5643 |
#var_dump($executeR["lineArray"][$i]);
|
| 226 |
liveuser |
5644 |
|
| 3 |
liveuser |
5645 |
#定位到有 "Total Observations in Table:" 的列
|
|
|
5646 |
#函式說明:
|
|
|
5647 |
#檢查字串裡面有無指定的關鍵字
|
|
|
5648 |
#回傳的結果:
|
|
|
5649 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
5650 |
#$result["error"],錯誤訊息
|
|
|
5651 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
5652 |
#$result["keyWordCount"],找到的關鍵字數量.
|
|
|
5653 |
#必填的參數:
|
|
|
5654 |
$conf["search::findKeyWord"]["keyWord"]="Total Observations in Table:";#想要搜尋的關鍵字
|
|
|
5655 |
$conf["search::findKeyWord"]["string"]=$executeR["lineArray"][$i];#要被搜尋的字串內容
|
|
|
5656 |
#可省略的參數:
|
|
|
5657 |
#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
5658 |
$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
|
|
|
5659 |
unset($conf["search::findKeyWord"]);
|
| 226 |
liveuser |
5660 |
|
| 3 |
liveuser |
5661 |
#如果搜尋關鍵字失敗
|
|
|
5662 |
if($findKeyWord["status"]=="false"){
|
| 226 |
liveuser |
5663 |
|
| 3 |
liveuser |
5664 |
#設置執行不正常
|
|
|
5665 |
$result["status"]="false";
|
| 226 |
liveuser |
5666 |
|
| 3 |
liveuser |
5667 |
#設置錯誤訊息
|
|
|
5668 |
$result["error"]=$findKeyWord;
|
| 226 |
liveuser |
5669 |
|
| 3 |
liveuser |
5670 |
#回傳結果
|
|
|
5671 |
return $result;
|
| 226 |
liveuser |
5672 |
|
| 3 |
liveuser |
5673 |
}#if end
|
| 226 |
liveuser |
5674 |
|
| 3 |
liveuser |
5675 |
#如果有找到關鍵字
|
|
|
5676 |
if($findKeyWord["founded"]=="true"){
|
| 226 |
liveuser |
5677 |
|
| 3 |
liveuser |
5678 |
#取得分析結果開始的列數
|
|
|
5679 |
$rowStartLine=$i;
|
| 226 |
liveuser |
5680 |
|
| 3 |
liveuser |
5681 |
#跳出迴圈
|
|
|
5682 |
break;
|
| 226 |
liveuser |
5683 |
|
| 3 |
liveuser |
5684 |
}#if end
|
| 226 |
liveuser |
5685 |
|
| 3 |
liveuser |
5686 |
}#for end
|
| 226 |
liveuser |
5687 |
|
| 3 |
liveuser |
5688 |
#解析資料的筆數
|
| 226 |
liveuser |
5689 |
|
| 3 |
liveuser |
5690 |
#涵式說明:
|
|
|
5691 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
5692 |
#回傳的參數:
|
|
|
5693 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5694 |
#$result["error"],錯誤訊息陣列
|
|
|
5695 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
5696 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
5697 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
5698 |
#必填的參數:
|
|
|
5699 |
$conf["stringProcess::spiltString"]["stringIn"]=$executeR["lineArray"][$rowStartLine];#要處理的字串。
|
|
|
5700 |
$conf["stringProcess::spiltString"]["spiltSymbol"]=": ";#爲以哪個符號作爲分割
|
|
|
5701 |
#備註:
|
|
|
5702 |
#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
|
|
|
5703 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
5704 |
unset($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
5705 |
|
| 3 |
liveuser |
5706 |
#如果分割字串失敗
|
|
|
5707 |
if($spiltString["status"]=="false"){
|
| 226 |
liveuser |
5708 |
|
| 3 |
liveuser |
5709 |
#設置執行不正常
|
|
|
5710 |
$result["status"]="false";
|
| 226 |
liveuser |
5711 |
|
| 3 |
liveuser |
5712 |
#設置錯誤訊息
|
|
|
5713 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
5714 |
|
| 3 |
liveuser |
5715 |
#回傳結果
|
|
|
5716 |
return $result;
|
| 226 |
liveuser |
5717 |
|
| 3 |
liveuser |
5718 |
}#if end
|
| 226 |
liveuser |
5719 |
|
| 3 |
liveuser |
5720 |
#取得觀察值筆數
|
|
|
5721 |
$result["content"]["pairedDataCount"]=$spiltString["dataArray"][1];
|
| 226 |
liveuser |
5722 |
|
| 3 |
liveuser |
5723 |
#取得變數一($conf["dataArrayA"])的種類
|
| 226 |
liveuser |
5724 |
|
| 3 |
liveuser |
5725 |
#初始化儲存變數一$conf["dataArrayA"])的種類
|
|
|
5726 |
$result["content"]["varAtype"]=array();
|
| 226 |
liveuser |
5727 |
|
| 3 |
liveuser |
5728 |
#debug
|
|
|
5729 |
#var_dump($rowStartLine+6);
|
|
|
5730 |
#var_dump($executeR["lineCount"]);
|
| 226 |
liveuser |
5731 |
|
| 3 |
liveuser |
5732 |
#執行迴圈直到遇到 "Column Total" 為止,一次加三
|
|
|
5733 |
for($i=$rowStartLine+6;$i<$executeR["lineCount"];$i=$i+3){
|
| 226 |
liveuser |
5734 |
|
| 3 |
liveuser |
5735 |
#echo "<p>entered!</p>";
|
| 226 |
liveuser |
5736 |
|
| 3 |
liveuser |
5737 |
#涵式說明:
|
|
|
5738 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
5739 |
#回傳的參數:
|
|
|
5740 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5741 |
#$result["error"],錯誤訊息陣列
|
|
|
5742 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
5743 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
5744 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
5745 |
#必填的參數:
|
|
|
5746 |
$conf["stringProcess::spiltString"]["stringIn"]=$executeR["lineArray"][$i];#要處理的字串。
|
|
|
5747 |
$conf["stringProcess::spiltString"]["spiltSymbol"]="|";#爲以哪個符號作爲分割
|
|
|
5748 |
#備註:
|
|
|
5749 |
#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
|
|
|
5750 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
5751 |
unset($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
5752 |
|
| 3 |
liveuser |
5753 |
#如果分割字串失敗
|
|
|
5754 |
if($spiltString["status"]=="false"){
|
| 226 |
liveuser |
5755 |
|
| 3 |
liveuser |
5756 |
#設置執行不正常
|
|
|
5757 |
$result["status"]="false";
|
| 226 |
liveuser |
5758 |
|
| 3 |
liveuser |
5759 |
#設置錯誤訊息
|
|
|
5760 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
5761 |
|
| 3 |
liveuser |
5762 |
#回傳結果
|
|
|
5763 |
return $result;
|
| 226 |
liveuser |
5764 |
|
| 3 |
liveuser |
5765 |
}#if end
|
| 226 |
liveuser |
5766 |
|
| 3 |
liveuser |
5767 |
#搜尋分割好的第一個字串是否有關鍵字 "Column Total"
|
|
|
5768 |
#函式說明:
|
|
|
5769 |
#檢查字串裡面有無指定的關鍵字
|
|
|
5770 |
#回傳的結果:
|
|
|
5771 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
5772 |
#$result["error"],錯誤訊息
|
|
|
5773 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
5774 |
#$result["keyWordCount"],找到的關鍵字數量.
|
|
|
5775 |
#必填的參數:
|
|
|
5776 |
$conf["search::findKeyWord"]["keyWord"]="Column Total";#想要搜尋的關鍵字
|
|
|
5777 |
$conf["search::findKeyWord"]["string"]=$spiltString["dataArray"][0];#要被搜尋的字串內容
|
|
|
5778 |
#可省略的參數:
|
|
|
5779 |
#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
5780 |
$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
|
|
|
5781 |
unset($conf["search::findKeyWord"]);
|
| 226 |
liveuser |
5782 |
|
| 3 |
liveuser |
5783 |
#如果尋找關鍵字失敗
|
|
|
5784 |
if($findKeyWord["status"]=="false"){
|
| 226 |
liveuser |
5785 |
|
| 3 |
liveuser |
5786 |
#設置執行不正常
|
|
|
5787 |
$result["status"]="false";
|
| 226 |
liveuser |
5788 |
|
| 3 |
liveuser |
5789 |
#設置錯誤訊息
|
|
|
5790 |
$result["error"]=$findKeyWord;
|
| 226 |
liveuser |
5791 |
|
| 3 |
liveuser |
5792 |
#回傳結果
|
|
|
5793 |
return $result;
|
| 226 |
liveuser |
5794 |
|
| 3 |
liveuser |
5795 |
}#if end
|
| 226 |
liveuser |
5796 |
|
| 3 |
liveuser |
5797 |
#如果有找到關鍵字 "Column Total"
|
|
|
5798 |
if($findKeyWord["founded"]=="true"){
|
| 226 |
liveuser |
5799 |
|
| 3 |
liveuser |
5800 |
#跳出迴圈
|
|
|
5801 |
break;
|
| 226 |
liveuser |
5802 |
|
| 3 |
liveuser |
5803 |
}#if end
|
| 226 |
liveuser |
5804 |
|
| 3 |
liveuser |
5805 |
#剔除變數一類別字串的空白
|
|
|
5806 |
#涵式說明:
|
|
|
5807 |
#處理字串避免網頁出錯
|
|
|
5808 |
#回傳的結果:
|
|
|
5809 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5810 |
#$result["function"],當前執行的函數.
|
|
|
5811 |
#$result["content"],爲處理好的字串.
|
|
|
5812 |
#$result["error"],錯誤訊息陣列.
|
|
|
5813 |
#必填的參數:
|
|
|
5814 |
$conf["stringProcess::correctCharacter"]["stringIn"]=$spiltString["dataArray"][0];#爲要處理的字串
|
|
|
5815 |
#可省略的參數:
|
|
|
5816 |
$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array(" ");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
5817 |
#若不設定則預設爲要將這些字串作替換("<",">","=","//","'","$","%","&","|","/*","*\/","#","\"")。
|
|
|
5818 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
5819 |
$conf["stringProcess::correctCharacter"]["changeTo"]=array("");#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
5820 |
$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);
|
|
|
5821 |
unset($conf["stringProcess::correctCharacter"]);
|
| 226 |
liveuser |
5822 |
|
| 3 |
liveuser |
5823 |
#如果 處理類別字串失敗
|
|
|
5824 |
if($correctCharacter["status"]=="false"){
|
| 226 |
liveuser |
5825 |
|
| 3 |
liveuser |
5826 |
#設置執行不正常
|
|
|
5827 |
$result["status"]="false";
|
| 226 |
liveuser |
5828 |
|
| 3 |
liveuser |
5829 |
#設置錯誤訊息
|
|
|
5830 |
$result["error"]=$correctCharacter;
|
| 226 |
liveuser |
5831 |
|
| 3 |
liveuser |
5832 |
#回傳結果
|
|
|
5833 |
return $result;
|
| 226 |
liveuser |
5834 |
|
| 3 |
liveuser |
5835 |
}#if end
|
| 226 |
liveuser |
5836 |
|
| 3 |
liveuser |
5837 |
#取得第一個變數的種類字串
|
|
|
5838 |
$result["content"]["varAtype"][]=$correctCharacter["content"];
|
| 226 |
liveuser |
5839 |
|
| 3 |
liveuser |
5840 |
}#for end
|
| 226 |
liveuser |
5841 |
|
| 3 |
liveuser |
5842 |
#取得變數二($conf["dataArrayB"])的種類
|
| 226 |
liveuser |
5843 |
|
| 3 |
liveuser |
5844 |
#涵式說明:
|
|
|
5845 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
5846 |
#回傳的參數:
|
|
|
5847 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5848 |
#$result["error"],錯誤訊息陣列
|
|
|
5849 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
5850 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
5851 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
5852 |
#必填的參數:
|
|
|
5853 |
$conf["stringProcess::spiltString"]["stringIn"]=$executeR["lineArray"][$rowStartLine+4];#要處理的字串。
|
|
|
5854 |
$conf["stringProcess::spiltString"]["spiltSymbol"]="|";#爲以哪個符號作爲分割
|
|
|
5855 |
#備註:
|
|
|
5856 |
#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
|
|
|
5857 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
5858 |
unset($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
5859 |
|
| 3 |
liveuser |
5860 |
#如果分割字串失敗
|
|
|
5861 |
if($spiltString["status"]=="false"){
|
| 226 |
liveuser |
5862 |
|
| 3 |
liveuser |
5863 |
#設置執行不正常
|
|
|
5864 |
$result["status"]="false";
|
| 226 |
liveuser |
5865 |
|
| 3 |
liveuser |
5866 |
#設置錯誤訊息
|
|
|
5867 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
5868 |
|
| 3 |
liveuser |
5869 |
#回傳結果
|
|
|
5870 |
return $result;
|
| 226 |
liveuser |
5871 |
|
| 3 |
liveuser |
5872 |
}#if end
|
| 226 |
liveuser |
5873 |
|
| 3 |
liveuser |
5874 |
#初始化儲存變數二($conf["dataArrayB"])的種類
|
|
|
5875 |
$result["content"]["varBtype"]=array();
|
| 226 |
liveuser |
5876 |
|
| 3 |
liveuser |
5877 |
#執行 分割成的段數-2 次迴圈(亦即去頭去尾)
|
|
|
5878 |
for($i=1;$i<$spiltString["dataCounts"]-1;$i++){
|
| 226 |
liveuser |
5879 |
|
| 3 |
liveuser |
5880 |
#剔除變數二類別字串的空白
|
|
|
5881 |
#涵式說明:
|
|
|
5882 |
#處理字串避免網頁出錯
|
|
|
5883 |
#回傳的結果:
|
|
|
5884 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5885 |
#$result["function"],當前執行的函數.
|
|
|
5886 |
#$result["content"],爲處理好的字串.
|
|
|
5887 |
#$result["error"],錯誤訊息陣列.
|
|
|
5888 |
#必填的參數:
|
|
|
5889 |
$conf["stringProcess::correctCharacter"]["stringIn"]=$spiltString["dataArray"][$i];#爲要處理的字串
|
|
|
5890 |
#可省略的參數:
|
|
|
5891 |
$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array(" ");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
5892 |
#若不設定則預設爲要將這些字串作替換("<",">","=","//","'","$","%","&","|","/*","*\/","#","\"")。
|
|
|
5893 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
5894 |
$conf["stringProcess::correctCharacter"]["changeTo"]=array("");#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
5895 |
$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);
|
|
|
5896 |
unset($conf["stringProcess::correctCharacter"]);
|
| 226 |
liveuser |
5897 |
|
| 3 |
liveuser |
5898 |
#如果處理字串失敗
|
|
|
5899 |
if($correctCharacter["status"]=="false"){
|
| 226 |
liveuser |
5900 |
|
| 3 |
liveuser |
5901 |
#設置執行不正常
|
|
|
5902 |
$result["status"]="false";
|
| 226 |
liveuser |
5903 |
|
| 3 |
liveuser |
5904 |
#設置錯誤訊息
|
|
|
5905 |
$result["error"]=$correctCharacter;
|
| 226 |
liveuser |
5906 |
|
| 3 |
liveuser |
5907 |
#回傳結果
|
|
|
5908 |
return $result;
|
| 226 |
liveuser |
5909 |
|
| 3 |
liveuser |
5910 |
}#if end
|
| 226 |
liveuser |
5911 |
|
| 3 |
liveuser |
5912 |
#取得變數二類別
|
|
|
5913 |
$result["content"]["varBtype"][]=$correctCharacter["content"];
|
| 226 |
liveuser |
5914 |
|
|
|
5915 |
}#for end
|
|
|
5916 |
|
| 3 |
liveuser |
5917 |
#$executeR["lineArray"][$rowStartLine]
|
| 226 |
liveuser |
5918 |
|
| 3 |
liveuser |
5919 |
#依據變數一與二建立交叉分析數據的頻率
|
| 226 |
liveuser |
5920 |
|
| 3 |
liveuser |
5921 |
#執行迴圈直到遇到 "Column Total" 為止,一次加三
|
|
|
5922 |
for($i=$rowStartLine+6;$i<$executeR["lineCount"];$i=$i+3){
|
| 226 |
liveuser |
5923 |
|
| 3 |
liveuser |
5924 |
#涵式說明:
|
|
|
5925 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
5926 |
#回傳的參數:
|
|
|
5927 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5928 |
#$result["error"],錯誤訊息陣列
|
|
|
5929 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
5930 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
5931 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
5932 |
#必填的參數:
|
|
|
5933 |
$conf["stringProcess::spiltString"]["stringIn"]=$executeR["lineArray"][$i];#要處理的字串。
|
|
|
5934 |
$conf["stringProcess::spiltString"]["spiltSymbol"]="|";#爲以哪個符號作爲分割
|
|
|
5935 |
#備註:
|
|
|
5936 |
#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
|
|
|
5937 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
5938 |
unset($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
5939 |
|
| 3 |
liveuser |
5940 |
#如果分割字串失敗
|
|
|
5941 |
if($spiltString["status"]=="false"){
|
| 226 |
liveuser |
5942 |
|
| 3 |
liveuser |
5943 |
#設置執行不正常
|
|
|
5944 |
$result["status"]="false";
|
| 226 |
liveuser |
5945 |
|
| 3 |
liveuser |
5946 |
#設置錯誤訊息
|
|
|
5947 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
5948 |
|
| 3 |
liveuser |
5949 |
#回傳結果
|
|
|
5950 |
return $result;
|
| 226 |
liveuser |
5951 |
|
| 3 |
liveuser |
5952 |
}#if end
|
| 226 |
liveuser |
5953 |
|
| 3 |
liveuser |
5954 |
#搜尋分割好的第一個字串是否有關鍵字 "Column Total"
|
|
|
5955 |
#函式說明:
|
|
|
5956 |
#檢查字串裡面有無指定的關鍵字
|
|
|
5957 |
#回傳的結果:
|
|
|
5958 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
5959 |
#$result["error"],錯誤訊息
|
|
|
5960 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
5961 |
#$result["keyWordCount"],找到的關鍵字數量.
|
|
|
5962 |
#必填的參數:
|
|
|
5963 |
$conf["search::findKeyWord"]["keyWord"]="Column Total";#想要搜尋的關鍵字
|
|
|
5964 |
$conf["search::findKeyWord"]["string"]=$spiltString["dataArray"][0];#要被搜尋的字串內容
|
|
|
5965 |
#可省略的參數:
|
|
|
5966 |
#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
5967 |
$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
|
|
|
5968 |
unset($conf["search::findKeyWord"]);
|
| 226 |
liveuser |
5969 |
|
| 3 |
liveuser |
5970 |
#如果尋找關鍵字失敗
|
|
|
5971 |
if($findKeyWord["status"]=="false"){
|
| 226 |
liveuser |
5972 |
|
| 3 |
liveuser |
5973 |
#設置執行不正常
|
|
|
5974 |
$result["status"]="false";
|
| 226 |
liveuser |
5975 |
|
| 3 |
liveuser |
5976 |
#設置錯誤訊息
|
|
|
5977 |
$result["error"]=$findKeyWord;
|
| 226 |
liveuser |
5978 |
|
| 3 |
liveuser |
5979 |
#回傳結果
|
|
|
5980 |
return $result;
|
| 226 |
liveuser |
5981 |
|
| 3 |
liveuser |
5982 |
}#if end
|
| 226 |
liveuser |
5983 |
|
| 3 |
liveuser |
5984 |
#如果有找到關鍵字 "Column Total"
|
|
|
5985 |
if($findKeyWord["founded"]=="true"){
|
| 226 |
liveuser |
5986 |
|
| 3 |
liveuser |
5987 |
#跳出迴圈
|
|
|
5988 |
break;
|
| 226 |
liveuser |
5989 |
|
| 3 |
liveuser |
5990 |
}#if end
|
| 226 |
liveuser |
5991 |
|
| 3 |
liveuser |
5992 |
#debug
|
|
|
5993 |
#echo "<p>entered!<p>";
|
| 226 |
liveuser |
5994 |
|
| 3 |
liveuser |
5995 |
#執行 分割成的段數-2 次迴圈(亦即去頭去尾)
|
|
|
5996 |
for($j=1;$j<$spiltString["dataCounts"]-1;$j++){
|
| 226 |
liveuser |
5997 |
|
| 3 |
liveuser |
5998 |
#debug
|
|
|
5999 |
#echo "<p>entered!<p>";
|
| 226 |
liveuser |
6000 |
|
| 3 |
liveuser |
6001 |
#剔除變數一類別字串的空白
|
|
|
6002 |
#涵式說明:
|
|
|
6003 |
#處理字串避免網頁出錯
|
|
|
6004 |
#回傳的結果:
|
|
|
6005 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6006 |
#$result["function"],當前執行的函數.
|
|
|
6007 |
#$result["content"],爲處理好的字串.
|
|
|
6008 |
#$result["error"],錯誤訊息陣列.
|
|
|
6009 |
#必填的參數:
|
|
|
6010 |
$conf["stringProcess::correctCharacter"]["stringIn"]=$spiltString["dataArray"][0];#爲要處理的字串
|
|
|
6011 |
#可省略的參數:
|
|
|
6012 |
$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array(" ");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
6013 |
#若不設定則預設爲要將這些字串作替換("<",">","=","//","'","$","%","&","|","/*","*\/","#","\"")。
|
|
|
6014 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
6015 |
$conf["stringProcess::correctCharacter"]["changeTo"]=array("");#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
6016 |
$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);
|
|
|
6017 |
unset($conf["stringProcess::correctCharacter"]);
|
| 226 |
liveuser |
6018 |
|
| 3 |
liveuser |
6019 |
#如果 處理類別字串失敗
|
|
|
6020 |
if($correctCharacter["status"]=="false"){
|
| 226 |
liveuser |
6021 |
|
| 3 |
liveuser |
6022 |
#設置執行不正常
|
|
|
6023 |
$result["status"]="false";
|
| 226 |
liveuser |
6024 |
|
| 3 |
liveuser |
6025 |
#設置錯誤訊息
|
|
|
6026 |
$result["error"]=$correctCharacter;
|
| 226 |
liveuser |
6027 |
|
| 3 |
liveuser |
6028 |
#回傳結果
|
|
|
6029 |
return $result;
|
| 226 |
liveuser |
6030 |
|
| 3 |
liveuser |
6031 |
}#if end
|
| 226 |
liveuser |
6032 |
|
| 3 |
liveuser |
6033 |
#暫存變數一的名稱
|
|
|
6034 |
$var1Name=$correctCharacter["content"];
|
| 226 |
liveuser |
6035 |
|
| 3 |
liveuser |
6036 |
#暫存變數二的名稱
|
|
|
6037 |
$var2Name=$result["content"]["varBtype"][$j-1];
|
| 226 |
liveuser |
6038 |
|
| 3 |
liveuser |
6039 |
#剔除變數一與類別二交叉的頻率字串的空白
|
|
|
6040 |
#涵式說明:
|
|
|
6041 |
#處理字串避免網頁出錯
|
|
|
6042 |
#回傳的結果:
|
|
|
6043 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6044 |
#$result["function"],當前執行的函數.
|
|
|
6045 |
#$result["content"],爲處理好的字串.
|
|
|
6046 |
#$result["error"],錯誤訊息陣列.
|
|
|
6047 |
#必填的參數:
|
|
|
6048 |
$conf["stringProcess::correctCharacter"]["stringIn"]=$spiltString["dataArray"][$j];#爲要處理的字串
|
|
|
6049 |
#可省略的參數:
|
|
|
6050 |
$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array(" ");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
6051 |
#若不設定則預設爲要將這些字串作替換("<",">","=","//","'","$","%","&","|","/*","*\/","#","\"")。
|
|
|
6052 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
6053 |
$conf["stringProcess::correctCharacter"]["changeTo"]=array("");#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
6054 |
$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);
|
|
|
6055 |
unset($conf["stringProcess::correctCharacter"]);
|
| 226 |
liveuser |
6056 |
|
| 3 |
liveuser |
6057 |
#如果 處理類別字串失敗
|
|
|
6058 |
if($correctCharacter["status"]=="false"){
|
| 226 |
liveuser |
6059 |
|
| 3 |
liveuser |
6060 |
#設置執行不正常
|
|
|
6061 |
$result["status"]="false";
|
| 226 |
liveuser |
6062 |
|
| 3 |
liveuser |
6063 |
#設置錯誤訊息
|
|
|
6064 |
$result["error"]=$correctCharacter;
|
| 226 |
liveuser |
6065 |
|
| 3 |
liveuser |
6066 |
#回傳結果
|
|
|
6067 |
return $result;
|
| 226 |
liveuser |
6068 |
|
| 3 |
liveuser |
6069 |
}#if end
|
| 226 |
liveuser |
6070 |
|
| 3 |
liveuser |
6071 |
#取得頻率
|
|
|
6072 |
$result["content"]["array"][$var1Name][$var2Name]["count"]=$correctCharacter["content"];
|
| 226 |
liveuser |
6073 |
|
| 3 |
liveuser |
6074 |
}#for end
|
| 226 |
liveuser |
6075 |
|
| 3 |
liveuser |
6076 |
}#for end
|
| 226 |
liveuser |
6077 |
|
| 3 |
liveuser |
6078 |
#依據變數一與二建立交叉分析數據的比例
|
| 226 |
liveuser |
6079 |
|
| 3 |
liveuser |
6080 |
#執行迴圈直到遇到 "Column Total" 為止,一次加三
|
|
|
6081 |
for($i=$rowStartLine+7;$i<$executeR["lineCount"];$i=$i+3){
|
| 226 |
liveuser |
6082 |
|
| 3 |
liveuser |
6083 |
#debug
|
|
|
6084 |
#echo "<p>entered!<p>";
|
| 226 |
liveuser |
6085 |
|
| 3 |
liveuser |
6086 |
#涵式說明:
|
|
|
6087 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
6088 |
#回傳的參數:
|
|
|
6089 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6090 |
#$result["error"],錯誤訊息陣列
|
|
|
6091 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
6092 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
6093 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
6094 |
#必填的參數:
|
|
|
6095 |
$conf["stringProcess::spiltString"]["stringIn"]=$executeR["lineArray"][$i];#要處理的字串。
|
|
|
6096 |
$conf["stringProcess::spiltString"]["spiltSymbol"]="|";#爲以哪個符號作爲分割
|
|
|
6097 |
#備註:
|
|
|
6098 |
#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
|
|
|
6099 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
6100 |
unset($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
6101 |
|
| 3 |
liveuser |
6102 |
#debug
|
|
|
6103 |
#var_dump($spiltString);
|
| 226 |
liveuser |
6104 |
|
| 3 |
liveuser |
6105 |
#如果分割字串失敗
|
|
|
6106 |
if($spiltString["status"]=="false"){
|
| 226 |
liveuser |
6107 |
|
| 3 |
liveuser |
6108 |
#設置執行不正常
|
|
|
6109 |
$result["status"]="false";
|
| 226 |
liveuser |
6110 |
|
| 3 |
liveuser |
6111 |
#設置錯誤訊息
|
|
|
6112 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
6113 |
|
| 3 |
liveuser |
6114 |
#回傳結果
|
|
|
6115 |
return $result;
|
| 226 |
liveuser |
6116 |
|
| 3 |
liveuser |
6117 |
}#if end
|
| 226 |
liveuser |
6118 |
|
| 3 |
liveuser |
6119 |
#搜尋分割好的第一個字串是否有關鍵字 "-"
|
|
|
6120 |
#函式說明:
|
|
|
6121 |
#檢查字串裡面有無指定的關鍵字
|
|
|
6122 |
#回傳的結果:
|
|
|
6123 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
6124 |
#$result["error"],錯誤訊息
|
|
|
6125 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
6126 |
#$result["keyWordCount"],找到的關鍵字數量.
|
|
|
6127 |
#必填的參數:
|
|
|
6128 |
$conf["search::findKeyWord"]["keyWord"]="-";#想要搜尋的關鍵字
|
|
|
6129 |
$conf["search::findKeyWord"]["string"]=$spiltString["dataArray"][0];#要被搜尋的字串內容
|
|
|
6130 |
#可省略的參數:
|
|
|
6131 |
#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
6132 |
$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
|
|
|
6133 |
unset($conf["search::findKeyWord"]);
|
| 226 |
liveuser |
6134 |
|
| 3 |
liveuser |
6135 |
#如果尋找關鍵字失敗
|
|
|
6136 |
if($findKeyWord["status"]=="false"){
|
| 226 |
liveuser |
6137 |
|
| 3 |
liveuser |
6138 |
#設置執行不正常
|
|
|
6139 |
$result["status"]="false";
|
| 226 |
liveuser |
6140 |
|
| 3 |
liveuser |
6141 |
#設置錯誤訊息
|
|
|
6142 |
$result["error"]=$findKeyWord;
|
| 226 |
liveuser |
6143 |
|
| 3 |
liveuser |
6144 |
#回傳結果
|
|
|
6145 |
return $result;
|
| 226 |
liveuser |
6146 |
|
| 3 |
liveuser |
6147 |
}#if end
|
| 226 |
liveuser |
6148 |
|
| 3 |
liveuser |
6149 |
#如果有找到關鍵字 "-"
|
|
|
6150 |
if($findKeyWord["founded"]=="true"){
|
| 226 |
liveuser |
6151 |
|
| 3 |
liveuser |
6152 |
#跳出迴圈
|
|
|
6153 |
break;
|
| 226 |
liveuser |
6154 |
|
| 3 |
liveuser |
6155 |
}#if end
|
| 226 |
liveuser |
6156 |
|
| 3 |
liveuser |
6157 |
#B變數有幾個類別就執行幾次
|
|
|
6158 |
for($j=0;$j<count($result["content"]["varBtype"]);$j++){
|
| 226 |
liveuser |
6159 |
|
| 3 |
liveuser |
6160 |
#debug
|
|
|
6161 |
#echo "<p>entered!<p>";
|
| 226 |
liveuser |
6162 |
|
| 3 |
liveuser |
6163 |
#debug
|
|
|
6164 |
#var_dump($spiltString);
|
| 226 |
liveuser |
6165 |
|
| 3 |
liveuser |
6166 |
#debug
|
|
|
6167 |
#echo "\r\n".$spiltString["dataArray"][$j+1]."\r\n";
|
| 226 |
liveuser |
6168 |
|
| 3 |
liveuser |
6169 |
#剔除變數A與B交叉的頻率比例字串的空白
|
|
|
6170 |
#涵式說明:
|
|
|
6171 |
#處理字串避免網頁出錯
|
|
|
6172 |
#回傳的結果:
|
|
|
6173 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6174 |
#$result["function"],當前執行的函數.
|
|
|
6175 |
#$result["content"],爲處理好的字串.
|
|
|
6176 |
#$result["error"],錯誤訊息陣列.
|
|
|
6177 |
#必填的參數:
|
|
|
6178 |
$conf["stringProcess::correctCharacter"]["stringIn"]=$spiltString["dataArray"][$j+1];#爲要處理的字串
|
|
|
6179 |
#可省略的參數:
|
|
|
6180 |
$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array(" ");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
6181 |
#若不設定則預設爲要將這些字串作替換("<",">","=","//","'","$","%","&","|","/*","*\/","#","\"")。
|
|
|
6182 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
6183 |
$conf["stringProcess::correctCharacter"]["changeTo"]=array("");#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
6184 |
$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);
|
|
|
6185 |
unset($conf["stringProcess::correctCharacter"]);
|
| 226 |
liveuser |
6186 |
|
| 3 |
liveuser |
6187 |
#debug
|
|
|
6188 |
#echo "\r\n\$i=".$i." \$rowStartLine=".$rowStartLine." BtypeCount=".count($result["content"]["varBtype"])."\r\n";
|
| 226 |
liveuser |
6189 |
|
| 3 |
liveuser |
6190 |
#debug
|
|
|
6191 |
#echo "\r\n".($i-7-$rowStartLine)/(3)."\r\n";
|
| 226 |
liveuser |
6192 |
|
| 3 |
liveuser |
6193 |
#debug
|
|
|
6194 |
#echo "\r\n[".$result["content"]["varAtype"][(($i-7-$rowStartLine)/3)]."][".$result["content"]["varBtype"][$j]."][\"radio\"]=".$correctCharacter["content"]."\r\n";
|
| 226 |
liveuser |
6195 |
|
| 3 |
liveuser |
6196 |
#debug
|
|
|
6197 |
#var_dump($correctCharacter);
|
| 226 |
liveuser |
6198 |
|
| 3 |
liveuser |
6199 |
#如果剔除空白失敗
|
|
|
6200 |
if($correctCharacter["status"]=="false"){
|
| 226 |
liveuser |
6201 |
|
| 3 |
liveuser |
6202 |
#設置執行不正常
|
|
|
6203 |
$result["status"]="false";
|
| 226 |
liveuser |
6204 |
|
| 3 |
liveuser |
6205 |
#設置錯誤訊息
|
|
|
6206 |
$result["error"]=$correctCharacter;
|
| 226 |
liveuser |
6207 |
|
| 3 |
liveuser |
6208 |
#回傳結果
|
|
|
6209 |
return $result;
|
| 226 |
liveuser |
6210 |
|
| 3 |
liveuser |
6211 |
}#if end
|
| 226 |
liveuser |
6212 |
|
| 3 |
liveuser |
6213 |
#取得變數A與B交叉的比例
|
|
|
6214 |
$result["content"]["array"][$result["content"]["varAtype"][($i-7-$rowStartLine)/(3)]][$result["content"]["varBtype"][$j]]["radio"]=$correctCharacter["content"];
|
| 226 |
liveuser |
6215 |
|
| 3 |
liveuser |
6216 |
}#for end
|
| 226 |
liveuser |
6217 |
|
| 3 |
liveuser |
6218 |
}#for end
|
| 226 |
liveuser |
6219 |
|
| 3 |
liveuser |
6220 |
#初始化儲存卡方檢定結果開始的列數
|
|
|
6221 |
$chiSquaredStartRow=0;
|
| 226 |
liveuser |
6222 |
|
| 3 |
liveuser |
6223 |
#尋找 "Pearson's Chi-squared test" 所在的列數
|
| 226 |
liveuser |
6224 |
|
| 3 |
liveuser |
6225 |
#有幾列輸出就執行幾次迴圈
|
|
|
6226 |
for($i=0;$i<$executeR["lineCount"];$i++){
|
| 226 |
liveuser |
6227 |
|
| 3 |
liveuser |
6228 |
#定位到有 "Pearson's Chi-squared test" 的列
|
|
|
6229 |
#函式說明:
|
|
|
6230 |
#檢查字串裡面有無指定的關鍵字
|
|
|
6231 |
#回傳的結果:
|
|
|
6232 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
6233 |
#$result["error"],錯誤訊息
|
|
|
6234 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
6235 |
#$result["keyWordCount"],找到的關鍵字數量.
|
|
|
6236 |
#必填的參數:
|
|
|
6237 |
$conf["search::findKeyWord"]["keyWord"]="Pearson's Chi-squared test";#想要搜尋的關鍵字
|
|
|
6238 |
$conf["search::findKeyWord"]["string"]=$executeR["lineArray"][$i];#要被搜尋的字串內容
|
|
|
6239 |
#可省略的參數:
|
|
|
6240 |
#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
6241 |
$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
|
|
|
6242 |
unset($conf["search::findKeyWord"]);
|
| 226 |
liveuser |
6243 |
|
| 3 |
liveuser |
6244 |
#如果搜尋關鍵字失敗
|
|
|
6245 |
if($findKeyWord["status"]=="false"){
|
| 226 |
liveuser |
6246 |
|
| 3 |
liveuser |
6247 |
#設置執行不正常
|
|
|
6248 |
$result["status"]="false";
|
| 226 |
liveuser |
6249 |
|
| 3 |
liveuser |
6250 |
#設置錯誤訊息
|
|
|
6251 |
$result["error"]=$findKeyWord;
|
| 226 |
liveuser |
6252 |
|
| 3 |
liveuser |
6253 |
#回傳結果
|
|
|
6254 |
return $result;
|
| 226 |
liveuser |
6255 |
|
| 3 |
liveuser |
6256 |
}#if end
|
| 226 |
liveuser |
6257 |
|
| 3 |
liveuser |
6258 |
#如果有找到關鍵字
|
|
|
6259 |
if($findKeyWord["founded"]=="true"){
|
| 226 |
liveuser |
6260 |
|
| 3 |
liveuser |
6261 |
#取得卡方檢定結果開始的列數
|
|
|
6262 |
$chiSquaredStartRow=$i;
|
| 226 |
liveuser |
6263 |
|
| 3 |
liveuser |
6264 |
#跳出迴圈
|
|
|
6265 |
break;
|
| 226 |
liveuser |
6266 |
|
| 3 |
liveuser |
6267 |
}#if end
|
| 226 |
liveuser |
6268 |
|
| 3 |
liveuser |
6269 |
}#for end
|
| 226 |
liveuser |
6270 |
|
| 3 |
liveuser |
6271 |
#解析卡方檢定的結果
|
|
|
6272 |
#涵式說明:
|
|
|
6273 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
6274 |
#回傳的參數:
|
|
|
6275 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6276 |
#$result["error"],錯誤訊息陣列
|
|
|
6277 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
6278 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
6279 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
6280 |
#必填的參數:
|
|
|
6281 |
$conf["stringProcess::spiltString"]["stringIn"]=$executeR["lineArray"][$chiSquaredStartRow+2];#要處理的字串。
|
|
|
6282 |
$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
|
|
|
6283 |
#備註:
|
|
|
6284 |
#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
|
|
|
6285 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
6286 |
unset($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
6287 |
|
| 3 |
liveuser |
6288 |
#如果分割字串失敗
|
|
|
6289 |
if($spiltString["status"]=="false"){
|
| 226 |
liveuser |
6290 |
|
| 3 |
liveuser |
6291 |
#設置執行不正常
|
|
|
6292 |
$result["status"]="false";
|
| 226 |
liveuser |
6293 |
|
| 3 |
liveuser |
6294 |
#設置錯誤訊息
|
|
|
6295 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
6296 |
|
| 3 |
liveuser |
6297 |
#回傳結果
|
|
|
6298 |
return $result;
|
| 226 |
liveuser |
6299 |
|
| 3 |
liveuser |
6300 |
}#if end
|
| 226 |
liveuser |
6301 |
|
| 3 |
liveuser |
6302 |
#取得卡方值
|
|
|
6303 |
$result["content"]["chi2"]=$spiltString["dataArray"][2];
|
| 226 |
liveuser |
6304 |
|
| 3 |
liveuser |
6305 |
#取得自由度
|
|
|
6306 |
$result["content"]["df"]=$spiltString["dataArray"][5];
|
| 226 |
liveuser |
6307 |
|
| 3 |
liveuser |
6308 |
#取得p值
|
|
|
6309 |
$result["content"]["chi2pValue"]=$spiltString["dataArray"][8];
|
| 226 |
liveuser |
6310 |
|
| 3 |
liveuser |
6311 |
#如果是小樣本(總樣本數30筆以下)
|
|
|
6312 |
if(count($conf["dataArrayA"])<30){
|
| 226 |
liveuser |
6313 |
|
| 3 |
liveuser |
6314 |
#初始化儲存費雪檢定結果開始的列數
|
|
|
6315 |
$fisherTestStartRow=0;
|
| 226 |
liveuser |
6316 |
|
| 3 |
liveuser |
6317 |
#尋找 "Fisher's Exact Test for Count Data" 所在的列數
|
| 226 |
liveuser |
6318 |
|
| 3 |
liveuser |
6319 |
#有幾列輸出就執行幾次迴圈
|
|
|
6320 |
for($i=0;$i<$executeR["lineCount"];$i++){
|
| 226 |
liveuser |
6321 |
|
| 3 |
liveuser |
6322 |
#定位到有 "Fisher's Exact Test for Count Data" 的列
|
|
|
6323 |
#函式說明:
|
|
|
6324 |
#檢查字串裡面有無指定的關鍵字
|
|
|
6325 |
#回傳的結果:
|
|
|
6326 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
6327 |
#$result["error"],錯誤訊息
|
|
|
6328 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
6329 |
#$result["keyWordCount"],找到的關鍵字數量.
|
|
|
6330 |
#必填的參數:
|
|
|
6331 |
$conf["search::findKeyWord"]["keyWord"]="Fisher's Exact Test for Count Data";#想要搜尋的關鍵字
|
|
|
6332 |
$conf["search::findKeyWord"]["string"]=$executeR["lineArray"][$i];#要被搜尋的字串內容
|
|
|
6333 |
#可省略的參數:
|
|
|
6334 |
#$conf["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
6335 |
$findKeyWord=search::findKeyWord($conf["search::findKeyWord"]);
|
|
|
6336 |
unset($conf["search::findKeyWord"]);
|
| 226 |
liveuser |
6337 |
|
| 3 |
liveuser |
6338 |
#如果搜尋關鍵字失敗
|
|
|
6339 |
if($findKeyWord["status"]=="false"){
|
| 226 |
liveuser |
6340 |
|
| 3 |
liveuser |
6341 |
#設置執行不正常
|
|
|
6342 |
$result["status"]="false";
|
| 226 |
liveuser |
6343 |
|
| 3 |
liveuser |
6344 |
#設置錯誤訊息
|
|
|
6345 |
$result["error"]=$findKeyWord;
|
| 226 |
liveuser |
6346 |
|
| 3 |
liveuser |
6347 |
#回傳結果
|
|
|
6348 |
return $result;
|
| 226 |
liveuser |
6349 |
|
| 3 |
liveuser |
6350 |
}#if end
|
| 226 |
liveuser |
6351 |
|
| 3 |
liveuser |
6352 |
#如果有找到關鍵字
|
|
|
6353 |
if($findKeyWord["founded"]=="true"){
|
| 226 |
liveuser |
6354 |
|
| 3 |
liveuser |
6355 |
#取得費雪檢定結果開始的列數
|
|
|
6356 |
$fisherTestStartRow=$i;
|
| 226 |
liveuser |
6357 |
|
| 3 |
liveuser |
6358 |
#跳出迴圈
|
|
|
6359 |
break;
|
| 226 |
liveuser |
6360 |
|
| 3 |
liveuser |
6361 |
}#if end
|
| 226 |
liveuser |
6362 |
|
| 3 |
liveuser |
6363 |
}#for end
|
| 226 |
liveuser |
6364 |
|
|
|
6365 |
#取得費雪檢定的兩變數關係
|
|
|
6366 |
$result["content"]["fisherTestVarRelationship"]=$executeR["lineArray"][$fisherTestStartRow+2];
|
|
|
6367 |
|
|
|
6368 |
#解析費雪檢定結果
|
| 3 |
liveuser |
6369 |
#涵式說明:
|
|
|
6370 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
6371 |
#回傳的參數:
|
|
|
6372 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6373 |
#$result["error"],錯誤訊息陣列
|
|
|
6374 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
6375 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
6376 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
6377 |
#必填的參數:
|
|
|
6378 |
$conf["stringProcess::spiltString"]["stringIn"]=$executeR["lineArray"][$fisherTestStartRow+3];#要處理的字串。
|
|
|
6379 |
$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
|
|
|
6380 |
#備註:
|
|
|
6381 |
#建議新增如果透過" "分割後的內容含有""的元素,將其移除,並將後面有內容的元素補上,key也重新排序。
|
|
|
6382 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
6383 |
unset($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
6384 |
|
| 3 |
liveuser |
6385 |
#如果分割字串失敗
|
|
|
6386 |
if($spiltString["status"]=="false"){
|
| 226 |
liveuser |
6387 |
|
| 3 |
liveuser |
6388 |
#設置執行不正常
|
|
|
6389 |
$result["status"]="false";
|
| 226 |
liveuser |
6390 |
|
| 3 |
liveuser |
6391 |
#設置錯誤訊息
|
|
|
6392 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
6393 |
|
| 3 |
liveuser |
6394 |
#回傳結果
|
|
|
6395 |
return $result;
|
| 226 |
liveuser |
6396 |
|
| 3 |
liveuser |
6397 |
}#if end
|
| 226 |
liveuser |
6398 |
|
| 3 |
liveuser |
6399 |
#取得費雪檢定的p值
|
|
|
6400 |
$result["content"]["fisherTestPvalue"]=$spiltString["dataArray"][2];
|
| 226 |
liveuser |
6401 |
|
| 3 |
liveuser |
6402 |
}#if end
|
| 226 |
liveuser |
6403 |
|
| 3 |
liveuser |
6404 |
#反之是大於30筆樣本的大樣本
|
|
|
6405 |
else{
|
| 226 |
liveuser |
6406 |
|
|
|
6407 |
#取得費雪檢定的兩變數關係
|
| 3 |
liveuser |
6408 |
$result["content"]["fisherTestVarRelationship"]="不適用於大樣本";
|
| 226 |
liveuser |
6409 |
|
| 3 |
liveuser |
6410 |
#取得費雪檢定的p值
|
|
|
6411 |
$result["content"]["fisherTestPvalue"]="不適用於大樣本";
|
| 226 |
liveuser |
6412 |
|
| 3 |
liveuser |
6413 |
}#else end
|
| 226 |
liveuser |
6414 |
|
| 3 |
liveuser |
6415 |
#輸出網頁檔的位置
|
|
|
6416 |
#$conf["crossTableAddress"]
|
| 226 |
liveuser |
6417 |
|
| 3 |
liveuser |
6418 |
#初始化儲存交叉分析表標題的字串
|
|
|
6419 |
$title="";
|
| 226 |
liveuser |
6420 |
|
| 3 |
liveuser |
6421 |
#標題陣列變數有幾個就執行幾次迴圈
|
|
|
6422 |
for($i=0;$i<count($conf["title"]);$i++){
|
| 226 |
liveuser |
6423 |
|
| 3 |
liveuser |
6424 |
#如果是最後一個元素
|
|
|
6425 |
if($i==count($conf["title"])-1){
|
| 226 |
liveuser |
6426 |
|
| 3 |
liveuser |
6427 |
$title=$title.$conf["title"][$i]."<p>";
|
| 226 |
liveuser |
6428 |
|
| 3 |
liveuser |
6429 |
}#if end
|
| 226 |
liveuser |
6430 |
|
| 3 |
liveuser |
6431 |
#反之不是最後一個元素
|
|
|
6432 |
else{
|
| 226 |
liveuser |
6433 |
|
| 3 |
liveuser |
6434 |
$title=$title.$conf["title"][$i]."<br>";
|
| 226 |
liveuser |
6435 |
|
| 3 |
liveuser |
6436 |
}#else end
|
| 226 |
liveuser |
6437 |
|
| 3 |
liveuser |
6438 |
}#for end
|
| 226 |
liveuser |
6439 |
|
| 3 |
liveuser |
6440 |
#初始化交叉分析表格呈現的html語法
|
|
|
6441 |
$tableContent="<table border = 1px>";
|
| 226 |
liveuser |
6442 |
|
| 3 |
liveuser |
6443 |
#第一列開始
|
|
|
6444 |
$tableContent=$tableContent."<tr>";
|
| 226 |
liveuser |
6445 |
|
| 3 |
liveuser |
6446 |
#第一列欄開始
|
|
|
6447 |
$tableContent=$tableContent."<td>".$conf["dnnStr"][0]."\\".$conf["dnnStr"][1]."</td>";
|
| 226 |
liveuser |
6448 |
|
| 3 |
liveuser |
6449 |
#第一列變數B的種類名稱
|
|
|
6450 |
for($i=0;$i<count($result["content"]["varBtype"]);$i++){
|
| 226 |
liveuser |
6451 |
|
| 3 |
liveuser |
6452 |
$tableContent=$tableContent."<td>".$result["content"]["varBtype"][$i]."</td>";
|
| 226 |
liveuser |
6453 |
|
| 3 |
liveuser |
6454 |
}#for end
|
| 226 |
liveuser |
6455 |
|
| 3 |
liveuser |
6456 |
#第一列結束
|
|
|
6457 |
$tableContent=$tableContent."</tr>";
|
| 226 |
liveuser |
6458 |
|
| 3 |
liveuser |
6459 |
#變數A有幾類就執行幾次
|
|
|
6460 |
for($i=0;$i<count($result["content"]["varAtype"]);$i++){
|
| 226 |
liveuser |
6461 |
|
| 3 |
liveuser |
6462 |
#列的開始
|
|
|
6463 |
$tableContent=$tableContent."<tr>";
|
| 226 |
liveuser |
6464 |
|
| 3 |
liveuser |
6465 |
#放置變數A的類別名稱
|
|
|
6466 |
$tableContent=$tableContent."<td>".$result["content"]["varAtype"][$i]."</td>";
|
| 226 |
liveuser |
6467 |
|
| 3 |
liveuser |
6468 |
#變數B有幾種就執行幾次
|
|
|
6469 |
for($k=0;$k<count($result["content"]["varBtype"]);$k++){
|
| 226 |
liveuser |
6470 |
|
| 3 |
liveuser |
6471 |
#如果沒有比比例數值
|
|
|
6472 |
if(!isset($result["content"]["array"][$result["content"]["varAtype"][$i]][$result["content"]["varBtype"][$k]]["radio"])){
|
| 226 |
liveuser |
6473 |
|
| 3 |
liveuser |
6474 |
#預設為"0.0"
|
|
|
6475 |
$result["content"]["array"][$result["content"]["varAtype"][$i]][$result["content"]["varBtype"][$k]]["radio"]="0.0";
|
| 226 |
liveuser |
6476 |
|
| 3 |
liveuser |
6477 |
}#if end
|
| 226 |
liveuser |
6478 |
|
| 3 |
liveuser |
6479 |
#欄的內容
|
|
|
6480 |
$tableContent=$tableContent."<td>".$result["content"]["array"][$result["content"]["varAtype"][$i]][$result["content"]["varBtype"][$k]]["count"]."<=>".$result["content"]["array"][$result["content"]["varAtype"][$i]][$result["content"]["varBtype"][$k]]["radio"]."</td>";
|
| 226 |
liveuser |
6481 |
|
| 3 |
liveuser |
6482 |
}#for end
|
| 226 |
liveuser |
6483 |
|
| 3 |
liveuser |
6484 |
#列的結束
|
| 226 |
liveuser |
6485 |
$tableContent=$tableContent."</tr>";
|
|
|
6486 |
|
| 3 |
liveuser |
6487 |
}#for end
|
| 226 |
liveuser |
6488 |
|
| 3 |
liveuser |
6489 |
#表格結束
|
|
|
6490 |
$tableContent=$tableContent."</table>";
|
| 226 |
liveuser |
6491 |
|
| 3 |
liveuser |
6492 |
#建立網頁檔
|
|
|
6493 |
#涵式說明:
|
|
|
6494 |
#將多行字串寫入到檔案
|
|
|
6495 |
#回傳的結果:
|
|
|
6496 |
#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
|
|
|
6497 |
#$result["error"],錯誤訊息陣列.
|
|
|
6498 |
#必填的參數:
|
|
|
6499 |
#$conf["fileName"],字串,爲要編輯的檔案名稱
|
|
|
6500 |
$conf["fileAccess::writeMultiLine"]["fileName"]=$conf["crossTableAddress"].".html";
|
|
|
6501 |
#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容
|
|
|
6502 |
#$conf["inputString"][$i] 代表第 $i+1 行。
|
|
|
6503 |
$conf["fileAccess::writeMultiLine"]["inputString"][]="<html>";
|
|
|
6504 |
$conf["fileAccess::writeMultiLine"]["inputString"][]="<head>";
|
|
|
6505 |
$conf["fileAccess::writeMultiLine"]["inputString"][]="<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">";
|
|
|
6506 |
$conf["fileAccess::writeMultiLine"]["inputString"][]="</head>";
|
|
|
6507 |
$conf["fileAccess::writeMultiLine"]["inputString"][]="<body>";
|
|
|
6508 |
$conf["fileAccess::writeMultiLine"]["inputString"][]=$title;
|
|
|
6509 |
$conf["fileAccess::writeMultiLine"]["inputString"][]=$tableContent;
|
|
|
6510 |
$conf["fileAccess::writeMultiLine"]["inputString"][]="<p>";
|
|
|
6511 |
$conf["fileAccess::writeMultiLine"]["inputString"][]="卡方檢定 卡方值:".$result["content"]["chi2"]." 自由度:".$result["content"]["df"]." p值:".$result["content"]["chi2pValue"]."<p>";
|
|
|
6512 |
$conf["fileAccess::writeMultiLine"]["inputString"][]="費雪檢定 兩變數關係:".$result["content"]["fisherTestVarRelationship"]." p值:".$result["content"]["fisherTestPvalue"]."<br>";
|
|
|
6513 |
$conf["fileAccess::writeMultiLine"]["inputString"][]="</body>";
|
|
|
6514 |
$conf["fileAccess::writeMultiLine"]["inputString"][]="</html>";
|
|
|
6515 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
6516 |
$conf["fileAccess::writeMultiLine"]["fileArgu"]=$conf["fileArgu"];
|
|
|
6517 |
#可省略的參數:
|
|
|
6518 |
#$conf["fileAccess::writeMultiLine"]["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
|
|
|
6519 |
$createHtmlReport=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
|
| 226 |
liveuser |
6520 |
unset($conf["fileAccess::writeMultiLine"]);
|
|
|
6521 |
|
| 3 |
liveuser |
6522 |
#如果建立交叉分析報表網頁檔失敗
|
|
|
6523 |
if($createHtmlReport["status"]=="false"){
|
| 226 |
liveuser |
6524 |
|
| 3 |
liveuser |
6525 |
#設置執行不正常
|
|
|
6526 |
$result["status"]="false";
|
| 226 |
liveuser |
6527 |
|
| 3 |
liveuser |
6528 |
#設置錯誤訊息
|
|
|
6529 |
$result["error"]=$createHtmlReport;
|
| 226 |
liveuser |
6530 |
|
| 3 |
liveuser |
6531 |
#回傳結果
|
|
|
6532 |
return $result;
|
|
|
6533 |
|
| 226 |
liveuser |
6534 |
}#if end
|
|
|
6535 |
|
| 3 |
liveuser |
6536 |
#取得產生的網頁檔位置
|
|
|
6537 |
$result["content"]["htmlReport"]=$conf["crossTableAddress"].".html";
|
|
|
6538 |
|
|
|
6539 |
#設置執行正常
|
|
|
6540 |
$result["status"]="true";
|
| 226 |
liveuser |
6541 |
|
| 3 |
liveuser |
6542 |
#回傳結果
|
|
|
6543 |
return $result;
|
| 226 |
liveuser |
6544 |
|
| 3 |
liveuser |
6545 |
}#function crossTable end
|
| 226 |
liveuser |
6546 |
|
| 3 |
liveuser |
6547 |
/*
|
|
|
6548 |
#函式說明:
|
|
|
6549 |
#運用線性模式進行關聯分析
|
|
|
6550 |
#回傳結果:
|
|
|
6551 |
#$result["status"],執行正常與否,"true"代表正常;"false"代表不正常
|
|
|
6552 |
#$result["error"],錯誤訊息陣列
|
|
|
6553 |
#$result["function"],當前函數名稱
|
|
|
6554 |
#$result["content"],分析結果
|
|
|
6555 |
#必填參數:
|
|
|
6556 |
#$conf["csvFile"],字串,要讀取的csv檔位置與名稱。
|
|
|
6557 |
$conf["csvFile"]="";
|
|
|
6558 |
#$conf["factorVarNameArray"],字串陣列,用於預測的變數欄位名稱。
|
|
|
6559 |
$conf["factorVarNameArray"]=array();
|
|
|
6560 |
#$conf["forcastVarName"],字串陣列,用於預測的變數欄位名稱。
|
|
|
6561 |
$conf["forcastVarName"]=array();
|
|
|
6562 |
#可省略參數:
|
|
|
6563 |
#無.
|
|
|
6564 |
#參考資料:
|
|
|
6565 |
#無.
|
|
|
6566 |
#備註:
|
|
|
6567 |
#建構中...
|
|
|
6568 |
#目前考慮停止開發,因爲無法用名目尺度去推論。
|
|
|
6569 |
*/
|
|
|
6570 |
public static function lm(&$conf){
|
| 226 |
liveuser |
6571 |
|
| 3 |
liveuser |
6572 |
#初始化要回傳的結果
|
|
|
6573 |
$result=array();
|
| 226 |
liveuser |
6574 |
|
| 3 |
liveuser |
6575 |
#如果 $conf 不等於 "array"
|
| 226 |
liveuser |
6576 |
if(gettype($conf)!="array"){
|
|
|
6577 |
|
| 3 |
liveuser |
6578 |
#設定錯誤識別
|
|
|
6579 |
$result["status"]="false";
|
| 226 |
liveuser |
6580 |
|
| 3 |
liveuser |
6581 |
#設置錯誤訊息
|
|
|
6582 |
$result["error"]="參數的Key指定有誤!";
|
| 226 |
liveuser |
6583 |
|
| 3 |
liveuser |
6584 |
#如果傳入的參數為 null
|
|
|
6585 |
if($conf==null){
|
| 226 |
liveuser |
6586 |
|
| 3 |
liveuser |
6587 |
#設置執行錯誤訊息
|
|
|
6588 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
6589 |
|
| 3 |
liveuser |
6590 |
}#if end
|
| 226 |
liveuser |
6591 |
|
| 3 |
liveuser |
6592 |
#回傳結果
|
|
|
6593 |
return $result;
|
| 226 |
liveuser |
6594 |
|
| 3 |
liveuser |
6595 |
}#if end
|
| 226 |
liveuser |
6596 |
|
| 3 |
liveuser |
6597 |
#檢查必填參數
|
|
|
6598 |
#涵式說明:
|
|
|
6599 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
6600 |
#回傳的結果:
|
|
|
6601 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6602 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
6603 |
#$result["function"],當前執行的函式名稱.
|
|
|
6604 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
6605 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
6606 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
6607 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
6608 |
#必填寫的參數:
|
|
|
6609 |
$conf["variableCheck.isexistMulti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
6610 |
$conf["variableCheck.isexistMulti"]["variableCheck"]=array("csvFile","factorVarNameArray","forcastVarName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
6611 |
#可以省略的參數:
|
| 226 |
liveuser |
6612 |
$conf["variableCheck.isexistMulti"]["variableType"]=array("string","array","name");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
6613 |
$conf["variableCheck.isexistMulti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
6614 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck.isexistMulti"]);
|
|
|
6615 |
unset($conf["variableCheck.isexistMulti"]);
|
| 226 |
liveuser |
6616 |
|
| 3 |
liveuser |
6617 |
#如果檢查失敗
|
|
|
6618 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
6619 |
|
| 3 |
liveuser |
6620 |
#設置執行不正常
|
|
|
6621 |
$result["status"]="false";
|
| 226 |
liveuser |
6622 |
|
| 3 |
liveuser |
6623 |
#設置執行錯誤訊息
|
|
|
6624 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
6625 |
|
| 3 |
liveuser |
6626 |
#回傳結果
|
|
|
6627 |
return $result;
|
| 226 |
liveuser |
6628 |
|
| 3 |
liveuser |
6629 |
}#if end
|
| 226 |
liveuser |
6630 |
|
| 3 |
liveuser |
6631 |
#如果檢查不通過
|
|
|
6632 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
6633 |
|
| 3 |
liveuser |
6634 |
#設置執行不正常
|
|
|
6635 |
$result["status"]="false";
|
| 226 |
liveuser |
6636 |
|
| 3 |
liveuser |
6637 |
#設置執行錯誤訊息
|
|
|
6638 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
6639 |
|
| 3 |
liveuser |
6640 |
#回傳結果
|
|
|
6641 |
return $result;
|
| 226 |
liveuser |
6642 |
|
| 3 |
liveuser |
6643 |
}#if end
|
| 226 |
liveuser |
6644 |
|
| 3 |
liveuser |
6645 |
#初始化要寫入到R腳本的逐行內容
|
|
|
6646 |
$dataToWrite=array();
|
| 226 |
liveuser |
6647 |
|
| 3 |
liveuser |
6648 |
$dataToWrite[]="#線性迴歸分析";
|
| 226 |
liveuser |
6649 |
|
| 3 |
liveuser |
6650 |
#涵式說明:
|
|
|
6651 |
#建立R檔案
|
|
|
6652 |
#回傳的結果:
|
|
|
6653 |
#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
|
|
|
6654 |
#$result["error"],錯誤訊息陣列.
|
|
|
6655 |
#$result["newCreatedRfilePathAndName"],R腳本檔的位置與名稱
|
|
|
6656 |
#必填的參數:
|
|
|
6657 |
$conf["R.writeRfile"]["addAndName"]=".R/".$_SESSION["username"]."-lm.R";#R檔案的位置與名稱
|
|
|
6658 |
$conf["R.writeRfile"]["textToWrite"]=array("");#要寫入的字串內容陣列,一個元素代表一行文字,每行結尾會自動換行。
|
|
|
6659 |
$writeRfileResult=R::writeRfile($conf["R.writeRfile"]);
|
|
|
6660 |
unset($conf["R.writeRfile"]);
|
| 226 |
liveuser |
6661 |
|
| 3 |
liveuser |
6662 |
#如果 R 腳本寫入失敗
|
|
|
6663 |
if($writeRfileResult["status"]=="false"){
|
| 226 |
liveuser |
6664 |
|
| 3 |
liveuser |
6665 |
#設置執行不正常
|
|
|
6666 |
$result["status"]="false";
|
| 226 |
liveuser |
6667 |
|
| 3 |
liveuser |
6668 |
#設置錯誤訊息
|
|
|
6669 |
$result["error"]=$writeRfileResult;
|
| 226 |
liveuser |
6670 |
|
| 3 |
liveuser |
6671 |
#回傳結果
|
|
|
6672 |
return $result;
|
| 226 |
liveuser |
6673 |
|
| 3 |
liveuser |
6674 |
}#if end
|
| 226 |
liveuser |
6675 |
|
| 3 |
liveuser |
6676 |
#取得R腳本的位置
|
|
|
6677 |
$rScriptAdd=$writeRfileResult["newCreatedRfilePathAndName"];
|
| 226 |
liveuser |
6678 |
|
| 3 |
liveuser |
6679 |
#執行R腳本
|
|
|
6680 |
#函式說明:
|
|
|
6681 |
#執行R腳本,執行完畢後,會刪除R的腳本與暫存R執行後的輸出的檔案.
|
|
|
6682 |
#回傳的結果:
|
|
|
6683 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6684 |
#$result["errror"],錯誤訊息陣列
|
|
|
6685 |
#$result["lineArray"],字串陣列,R輸出結果,每個元素代表一行的輸出.
|
|
|
6686 |
#$result["lineCount"],整數,R輸出的總共行數.
|
|
|
6687 |
#必填的參數:
|
|
|
6688 |
#$conf["R.executeR"]["rPositionAndName"],字串,R腳本的位置與名稱.
|
|
|
6689 |
$conf["R.executeR"]["rPositionAndName"]=$rScriptAdd;
|
|
|
6690 |
#可省略的參數:
|
|
|
6691 |
#$conf["R.executeR"]["disbaleOptimal"],字串,"true"代表取消輸出的優化,可以顯示版本訊息、歡迎訊息、儲存暫存檔,預設為"false"要進行優化.
|
|
|
6692 |
#$conf["R.executeR"]["disbaleOptimal"]="true";
|
|
|
6693 |
$executeResult=R::executeR($conf["R.executeR"]);
|
|
|
6694 |
unset($conf["R.executeR"]);
|
| 226 |
liveuser |
6695 |
|
| 3 |
liveuser |
6696 |
#如果執行R腳本出錯
|
|
|
6697 |
if($executeResult["status"]=="false"){
|
| 226 |
liveuser |
6698 |
|
| 3 |
liveuser |
6699 |
#設置執行不正常
|
|
|
6700 |
$result["status"]="false";
|
| 226 |
liveuser |
6701 |
|
| 3 |
liveuser |
6702 |
#設置錯誤訊息
|
|
|
6703 |
$result["error"]=$executeResult;
|
| 226 |
liveuser |
6704 |
|
| 3 |
liveuser |
6705 |
#回傳結果
|
|
|
6706 |
return $result;
|
| 226 |
liveuser |
6707 |
|
| 3 |
liveuser |
6708 |
}#if end
|
| 226 |
liveuser |
6709 |
|
| 3 |
liveuser |
6710 |
}#function lm end
|
| 226 |
liveuser |
6711 |
|
| 3 |
liveuser |
6712 |
/*
|
|
|
6713 |
#函式說明:
|
|
|
6714 |
#避免超出4096bytes限制的條件下產生向量變數語法
|
|
|
6715 |
#請勿使用 vectorPart 作為R的變數,因為這是用於組合向量變數的暫存變數.
|
|
|
6716 |
#回傳結果:
|
|
|
6717 |
#$result["status"],執行正常與否,"true"代表正常;"false"代表不正常
|
|
|
6718 |
#$result["error"],錯誤訊息陣列
|
|
|
6719 |
#$result["function"],當前函數名稱
|
|
|
6720 |
#$result["rVectorCreate"],建立R向量變數的語法陣列,一個元素代表一列的內容。
|
|
|
6721 |
#$result["lineCount"],用了幾列程式完成向量變數的建立
|
|
|
6722 |
#必填參數:
|
|
|
6723 |
#$conf["vectorName"],字串,向量變數在R裡面的名稱。
|
|
|
6724 |
$conf["vectorName"]="";
|
|
|
6725 |
#$conf["vectorData"],陣列變數,要產生的向量變數資料。
|
|
|
6726 |
$conf["vectorData"]=array();
|
|
|
6727 |
#$conf["writeTarget"],參考陣列變數,向量變數產生的語法要寫入哪個儲存R腳本的陣列變數。
|
|
|
6728 |
$conf["writeTarget"]=&;
|
|
|
6729 |
#可省略參數:
|
|
|
6730 |
#無.
|
|
|
6731 |
#參考資料:
|
|
|
6732 |
#無.
|
|
|
6733 |
#備註:
|
|
|
6734 |
#無.
|
| 226 |
liveuser |
6735 |
*/
|
| 3 |
liveuser |
6736 |
public static function createFixedVectorVar(&$conf){
|
| 226 |
liveuser |
6737 |
|
| 3 |
liveuser |
6738 |
#初始化要回傳的內容
|
|
|
6739 |
$result=array();
|
| 226 |
liveuser |
6740 |
|
| 3 |
liveuser |
6741 |
#取得當前函數名稱
|
|
|
6742 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
6743 |
|
| 3 |
liveuser |
6744 |
#如果 $conf 不為陣列
|
|
|
6745 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
6746 |
|
| 3 |
liveuser |
6747 |
#設置執行失敗
|
|
|
6748 |
$result["status"]="false";
|
| 226 |
liveuser |
6749 |
|
| 3 |
liveuser |
6750 |
#設置執行錯誤訊息
|
|
|
6751 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
6752 |
|
|
|
6753 |
#如果傳入的參數為 null
|
|
|
6754 |
if($conf==null){
|
| 226 |
liveuser |
6755 |
|
| 3 |
liveuser |
6756 |
#設置執行錯誤訊息
|
|
|
6757 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
6758 |
|
| 3 |
liveuser |
6759 |
}#if end
|
|
|
6760 |
|
|
|
6761 |
#回傳結果
|
|
|
6762 |
return $result;
|
| 226 |
liveuser |
6763 |
|
| 3 |
liveuser |
6764 |
}#if end
|
| 226 |
liveuser |
6765 |
|
| 3 |
liveuser |
6766 |
#初始化儲存建立R向量變數的語法陣列
|
|
|
6767 |
$result["rVectorCreate"]=array();
|
| 226 |
liveuser |
6768 |
|
| 3 |
liveuser |
6769 |
#檢查參數
|
|
|
6770 |
#函式說明:
|
|
|
6771 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
6772 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6773 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
6774 |
#$result["function"],當前執行的函式名稱.
|
|
|
6775 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
6776 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
6777 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
6778 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
6779 |
#必填寫的參數:
|
|
|
6780 |
#$conf["variableCheck.checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
6781 |
$conf["variableCheck.checkArguments"]["varInput"]=&$conf;
|
|
|
6782 |
#$conf["variableCheck.checkArguments"]"mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
6783 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableName"]=array("vectorName","vectorData","writeTarget");
|
| 226 |
liveuser |
6784 |
#$conf["variableCheck.checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
6785 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableType"]=array("string","array","array");
|
|
|
6786 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
6787 |
$conf["variableCheck.checkArguments"]["referenceVarKey"]="variableCheck.checkArguments";
|
|
|
6788 |
#可以省略的參數:
|
|
|
6789 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"false"。
|
|
|
6790 |
#$conf["canBeEmptyString"]="false";
|
|
|
6791 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
6792 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
6793 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
6794 |
#$conf["skipableVariableType"]=array();
|
|
|
6795 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
6796 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
6797 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
6798 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
6799 |
$checkResult=variableCheck::checkArguments($conf["variableCheck.checkArguments"]);
|
|
|
6800 |
unset($conf["variableCheck.checkArguments"]);
|
| 226 |
liveuser |
6801 |
|
| 3 |
liveuser |
6802 |
#如果檢查失敗
|
|
|
6803 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
6804 |
|
| 3 |
liveuser |
6805 |
#設置執行不正常
|
|
|
6806 |
$result["status"]="false";
|
| 226 |
liveuser |
6807 |
|
| 3 |
liveuser |
6808 |
#設置執行錯誤訊息
|
|
|
6809 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
6810 |
|
| 3 |
liveuser |
6811 |
#回傳結果
|
|
|
6812 |
return $result;
|
| 226 |
liveuser |
6813 |
|
| 3 |
liveuser |
6814 |
}#if end
|
| 226 |
liveuser |
6815 |
|
| 3 |
liveuser |
6816 |
#如果檢查不通過
|
|
|
6817 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
6818 |
|
| 3 |
liveuser |
6819 |
#設置執行不正常
|
|
|
6820 |
$result["status"]="false";
|
| 226 |
liveuser |
6821 |
|
| 3 |
liveuser |
6822 |
#設置執行錯誤訊息
|
|
|
6823 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
6824 |
|
| 3 |
liveuser |
6825 |
#回傳結果
|
|
|
6826 |
return $result;
|
| 226 |
liveuser |
6827 |
|
| 3 |
liveuser |
6828 |
}#if end
|
| 226 |
liveuser |
6829 |
|
| 3 |
liveuser |
6830 |
#計算 $conf["vectorData"] 10個一組,可以有幾組
|
|
|
6831 |
(int)$groupsCount=count($conf["vectorData"])/10;
|
| 226 |
liveuser |
6832 |
|
| 3 |
liveuser |
6833 |
#有幾組就執行幾次
|
|
|
6834 |
for($i=0;$i<$groupsCount;$i++){
|
| 226 |
liveuser |
6835 |
|
| 3 |
liveuser |
6836 |
#初始化暫存向量變數語法的變數
|
|
|
6837 |
$rVectorPart="vectorPart=c(";
|
| 226 |
liveuser |
6838 |
|
| 3 |
liveuser |
6839 |
#一次最多執行10次
|
|
|
6840 |
for($j=$i*10;$j<($i+1)*10;$j++){
|
| 226 |
liveuser |
6841 |
|
| 3 |
liveuser |
6842 |
#如果已經讀完全部的向量變數了
|
|
|
6843 |
if(!isset($conf["vectorData"][$j])){
|
| 226 |
liveuser |
6844 |
|
| 3 |
liveuser |
6845 |
#debug
|
|
|
6846 |
#echo "entered!";
|
| 226 |
liveuser |
6847 |
|
| 3 |
liveuser |
6848 |
#結束向量變數語法
|
|
|
6849 |
$rVectorPart=$rVectorPart.")";
|
| 226 |
liveuser |
6850 |
|
| 3 |
liveuser |
6851 |
#跳出迴圈
|
|
|
6852 |
break;
|
| 226 |
liveuser |
6853 |
|
| 3 |
liveuser |
6854 |
}#if end
|
| 226 |
liveuser |
6855 |
|
| 3 |
liveuser |
6856 |
#如果是該組第一個向量資料
|
|
|
6857 |
if($j==$i*10){
|
| 226 |
liveuser |
6858 |
|
| 3 |
liveuser |
6859 |
#串聯建立向量變數的語法
|
|
|
6860 |
$rVectorPart=$rVectorPart."\"".$conf["vectorData"][$j]."\"";
|
| 226 |
liveuser |
6861 |
|
| 3 |
liveuser |
6862 |
}#if end
|
| 226 |
liveuser |
6863 |
|
| 3 |
liveuser |
6864 |
#反之不是該組第一個向量資料
|
|
|
6865 |
else{
|
| 226 |
liveuser |
6866 |
|
| 3 |
liveuser |
6867 |
#串聯建立向量變數的語法,向量資料前要加一個逗號。
|
|
|
6868 |
$rVectorPart=$rVectorPart.",\"".$conf["vectorData"][$j]."\"";
|
| 226 |
liveuser |
6869 |
|
| 3 |
liveuser |
6870 |
}#else end
|
| 226 |
liveuser |
6871 |
|
| 3 |
liveuser |
6872 |
#如果是該組的最後一個向量內容
|
|
|
6873 |
if($j==($i+1)*10-1){
|
| 226 |
liveuser |
6874 |
|
| 3 |
liveuser |
6875 |
#結束向量變數語法
|
|
|
6876 |
$rVectorPart=$rVectorPart.")";
|
| 226 |
liveuser |
6877 |
|
|
|
6878 |
}#if end
|
|
|
6879 |
|
| 3 |
liveuser |
6880 |
}#for end
|
| 226 |
liveuser |
6881 |
|
| 3 |
liveuser |
6882 |
#儲存產生部分向量變數內容的R語法
|
|
|
6883 |
$result["rVectorCreate"][]=$rVectorPart;
|
| 226 |
liveuser |
6884 |
|
|
|
6885 |
#如果是第一組
|
|
|
6886 |
if($i==0){
|
|
|
6887 |
|
| 3 |
liveuser |
6888 |
#直接取得向量變數的內容
|
|
|
6889 |
$result["rVectorCreate"][]=$conf["vectorName"]."=vectorPart";
|
| 226 |
liveuser |
6890 |
|
| 3 |
liveuser |
6891 |
}#if end
|
| 226 |
liveuser |
6892 |
|
| 3 |
liveuser |
6893 |
#反之不是第一組
|
|
|
6894 |
else{
|
| 226 |
liveuser |
6895 |
|
| 3 |
liveuser |
6896 |
#組合向量變數的內容
|
|
|
6897 |
$result["rVectorCreate"][]=$conf["vectorName"]."=c(".$conf["vectorName"].",vectorPart)";
|
| 226 |
liveuser |
6898 |
|
| 3 |
liveuser |
6899 |
}#else end
|
| 226 |
liveuser |
6900 |
|
| 3 |
liveuser |
6901 |
}#for end
|
| 226 |
liveuser |
6902 |
|
| 3 |
liveuser |
6903 |
#$result["rVectorCreate"]有幾個元素就執行幾次
|
|
|
6904 |
for($i=0;$i<count($result["rVectorCreate"]);$i++){
|
| 226 |
liveuser |
6905 |
|
| 3 |
liveuser |
6906 |
#增加一列建立向量變數的語法
|
|
|
6907 |
$conf["writeTarget"][]=$result["rVectorCreate"][$i];
|
| 226 |
liveuser |
6908 |
|
| 3 |
liveuser |
6909 |
}#for end
|
| 226 |
liveuser |
6910 |
|
| 3 |
liveuser |
6911 |
#用了幾列程式完成向量變數的建立
|
|
|
6912 |
$result["lineCount"]=count($result["rVectorCreate"]);
|
| 226 |
liveuser |
6913 |
|
| 3 |
liveuser |
6914 |
#設置執行正常的識別
|
|
|
6915 |
$result["status"]="true";
|
| 226 |
liveuser |
6916 |
|
| 3 |
liveuser |
6917 |
#回傳結果
|
|
|
6918 |
return $result;
|
| 226 |
liveuser |
6919 |
|
|
|
6920 |
}#function createFixedVectorVar end
|
|
|
6921 |
|
| 3 |
liveuser |
6922 |
/*
|
|
|
6923 |
#函式說明:
|
|
|
6924 |
#求算相關係數(皮爾森係數),結果會回傳1數值。代表兩筆數據的相關層度,正值代表正相關;負值代表負相關。
|
|
|
6925 |
#回傳結果:
|
|
|
6926 |
#$result["status"],執行是否成功的識別,"true"代表執行正常,"false"代表執行不正常.
|
|
|
6927 |
#$result["error"],錯誤訊息陣列.
|
|
|
6928 |
#$result["function"],當前執行的函數名稱.
|
|
|
6929 |
#$result["content"],相關係數(皮爾森係數).
|
|
|
6930 |
#必填參數:
|
|
|
6931 |
#$conf["rawDataArrayA"],字串陣列,爲第1組數據,元素數量須與$rawDataArray["B"]一樣。
|
|
|
6932 |
$conf["rawDataArrayA"]=array("");
|
|
|
6933 |
#$conf["rawDataArrayB"],字串陣列,爲第2組數據,元素數量須與$rawDataArray["A"]一樣。
|
|
|
6934 |
$conf["rawDataArrayB"]=array("");
|
|
|
6935 |
#可省略參數:
|
|
|
6936 |
#無
|
|
|
6937 |
#參考資料:
|
|
|
6938 |
#http://www.statmethods.net/stats/correlations.html
|
|
|
6939 |
#備註:
|
|
|
6940 |
#建構中
|
|
|
6941 |
*/
|
|
|
6942 |
public static function computeCorrelationCoefficientForNumbericData(&$conf){
|
| 226 |
liveuser |
6943 |
|
| 3 |
liveuser |
6944 |
#初始化要回傳的內容
|
|
|
6945 |
$result=array();
|
| 226 |
liveuser |
6946 |
|
| 3 |
liveuser |
6947 |
#記錄當前執行的函數名稱
|
|
|
6948 |
$result["function"]=__FUNCTION__;
|
|
|
6949 |
|
|
|
6950 |
#初始化要回傳的相關係數(皮爾森係數)
|
|
|
6951 |
$result["content"]="";
|
|
|
6952 |
|
|
|
6953 |
#如果 $conf 不為陣列
|
|
|
6954 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
6955 |
|
| 3 |
liveuser |
6956 |
#設置執行失敗
|
|
|
6957 |
$result["status"]="false";
|
| 226 |
liveuser |
6958 |
|
| 3 |
liveuser |
6959 |
#設置執行錯誤訊息
|
|
|
6960 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
6961 |
|
|
|
6962 |
#如果傳入的參數為 null
|
|
|
6963 |
if($conf==null){
|
| 226 |
liveuser |
6964 |
|
| 3 |
liveuser |
6965 |
#設置執行錯誤訊息
|
|
|
6966 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
6967 |
|
| 3 |
liveuser |
6968 |
}#if end
|
|
|
6969 |
|
|
|
6970 |
#回傳結果
|
|
|
6971 |
return $result;
|
| 226 |
liveuser |
6972 |
|
| 3 |
liveuser |
6973 |
}#if end
|
|
|
6974 |
|
|
|
6975 |
#檢查參數
|
|
|
6976 |
#函式說明:
|
|
|
6977 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
6978 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
6979 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
6980 |
#$result["function"],當前執行的函式名稱.
|
|
|
6981 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
6982 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
6983 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
6984 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
6985 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
6986 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
6987 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
6988 |
#必填寫的參數:
|
|
|
6989 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
6990 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
6991 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
6992 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("rawDataArrayA","rawDataArrayB");
|
| 226 |
liveuser |
6993 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
|
| 3 |
liveuser |
6994 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array","array");
|
|
|
6995 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
6996 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
6997 |
#可以省略的參數:
|
|
|
6998 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
6999 |
$conf["variableCheck::checkArguments"]["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
7000 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
7001 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("asc");
|
| 226 |
liveuser |
7002 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
7003 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
7004 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
7005 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
|
|
|
7006 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
7007 |
$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("rawDataArrayA","rawDataArrayB");
|
|
|
7008 |
#參考資料來源:
|
|
|
7009 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
7010 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
7011 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
7012 |
|
|
|
7013 |
#如果檢查參數失敗
|
|
|
7014 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
7015 |
|
| 3 |
liveuser |
7016 |
#設置執行失敗
|
|
|
7017 |
$result["status"]="false";
|
| 226 |
liveuser |
7018 |
|
| 3 |
liveuser |
7019 |
#設置執行錯誤訊息
|
|
|
7020 |
$result["error"]=$checkArguments;
|
|
|
7021 |
|
|
|
7022 |
#回傳結果
|
|
|
7023 |
return $result;
|
| 226 |
liveuser |
7024 |
|
| 3 |
liveuser |
7025 |
}#if end
|
| 226 |
liveuser |
7026 |
|
| 3 |
liveuser |
7027 |
#如果檢查不通過
|
|
|
7028 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
7029 |
|
| 3 |
liveuser |
7030 |
#設置執行失敗
|
|
|
7031 |
$result["status"]="false";
|
| 226 |
liveuser |
7032 |
|
| 3 |
liveuser |
7033 |
#設置執行錯誤訊息
|
|
|
7034 |
$result["error"]=$checkArguments;
|
|
|
7035 |
|
|
|
7036 |
#回傳結果
|
|
|
7037 |
return $result;
|
| 226 |
liveuser |
7038 |
|
| 3 |
liveuser |
7039 |
}#if end
|
| 226 |
liveuser |
7040 |
|
|
|
7041 |
|
|
|
7042 |
|
|
|
7043 |
}#function computeCorrelationCoefficientForNumbericData end
|
|
|
7044 |
|
| 3 |
liveuser |
7045 |
}#class R end
|
|
|
7046 |
|
|
|
7047 |
?>
|