-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
77 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
import com.example.seonjae.with.WorkInfoActivity; | ||
import com.example.seonjae.with.data.ProjectData; | ||
import com.example.seonjae.with.data.TodoData; | ||
import com.example.seonjae.with.project.ProjectHomeActivity; | ||
|
||
import org.apache.http.HttpEntity; | ||
import org.apache.http.HttpResponse; | ||
|
@@ -38,6 +39,7 @@ | |
import java.sql.Date; | ||
import java.text.DecimalFormat; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
@@ -51,7 +53,7 @@ public class MP_TODO_Fragment extends Fragment { | |
private ListTodoAdapter tListAdapter = null; | ||
private ArrayList<TodoData> tDataList; | ||
private TodoData pData; | ||
//static Map<String, Integer> projectProgress; | ||
private Map<String, Integer> projectProgress; | ||
private Set<String> projectIDList; | ||
|
||
public MP_TODO_Fragment() { | ||
|
@@ -62,6 +64,7 @@ public MP_TODO_Fragment() { | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
|
||
projectIDList = new HashSet<String>(); | ||
projectProgress = new HashMap<String, Integer>(); | ||
// Inflate the layout for this fragment | ||
tDataList = new ArrayList<TodoData>(); | ||
view = inflater.inflate(R.layout.mp_todo_fragment, container, false); | ||
|
@@ -93,46 +96,50 @@ public void onClick(View view) { | |
// Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG).setAction("Action", null).show(); | ||
} | ||
}); | ||
|
||
updateProgressWorker(); | ||
return view; | ||
} | ||
|
||
// 개인 진행도 구하는 함수 | ||
//( SUM(작업한일의중요도) / SUM(일의 중요도) ) * 100 | ||
public void getProgressWorker(){ | ||
Log.d("---SJ P_ :", String.valueOf(tDataList.size())); | ||
|
||
Iterator<String> itPL = projectIDList.iterator(); | ||
while(itPL.hasNext()){ | ||
String id = itPL.next(); | ||
double priorityCnt = 0; | ||
double workCnt = 0; | ||
double completeCnt = 0; | ||
int progress = 0; | ||
|
||
for(int i= 0; i<tDataList.size(); i++){ | ||
if(tDataList.get(i).getProjectID().equals(id)){ | ||
workCnt++; | ||
priorityCnt += tDataList.get(i).getPriority(); | ||
if(tDataList.get(i).getComplete() != 0) | ||
completeCnt++; | ||
} | ||
} | ||
double workPer = 1 / workCnt; | ||
double workPer = 1 / priorityCnt; | ||
DecimalFormat format = new DecimalFormat(".##"); | ||
String t = format.format(workPer); | ||
workPer = Double.valueOf(t); | ||
double remainder = 1 - (workPer * workCnt); | ||
String r = format.format(remainder); | ||
remainder = Double.valueOf(r); | ||
|
||
|
||
|
||
Log.d("---SJ8_workPer" , id+" : " + String.valueOf(workCnt)); | ||
Log.d("---SJ8_Complete" , id+" : " + String.valueOf(completeCnt)); | ||
// Log.d("---SJ8_remainder", id+" : " + String.valueOf(remainder)); | ||
// for(int i = 0; i < workCnt; i++){ | ||
// Log.d("---SJ9_progress", id+" : " + String.valueOf(tDataList.get(i).getPriority())); | ||
// } | ||
//progressAllValue = (int)tempValue +(int)(remainder * 100) ; | ||
double completePriority = 0; | ||
for(int i= 0; i<tDataList.size(); i++){ | ||
if(tDataList.get(i).getProjectID().equals(id)){ | ||
if(tDataList.get(i).getComplete() == 1) | ||
completePriority += ( tDataList.get(i).getPriority() * workPer); | ||
} | ||
} | ||
completePriority += (int)(remainder * workPer); | ||
progress = (int)((completePriority/1) * 100); | ||
projectProgress.put(id, progress); | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
private void getTodoList() { | ||
|
@@ -174,7 +181,6 @@ protected String doInBackground(String... params) { | |
@Override | ||
protected void onPostExecute(String result) { | ||
String s = result.trim(); | ||
Log.d("--------------SJ 5 :", s); | ||
final String json = s.replaceAll("\"", "\\\""); | ||
try{ | ||
JSONArray jsonArray = new JSONArray(json); | ||
|
@@ -198,6 +204,60 @@ protected void onPostExecute(String result) { | |
GetTodoListAsync la = new GetTodoListAsync(); | ||
la.execute(); | ||
} | ||
|
||
private void updateProgressWorker(){ | ||
class UpdateProgressWorkerAsync extends AsyncTask<String, Void, String> { | ||
@Override | ||
protected String doInBackground(String... params) { | ||
|
||
InputStream is = null; | ||
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); | ||
nameValuePairs.add(new BasicNameValuePair("cnt", String.valueOf(projectProgress.size()))); | ||
nameValuePairs.add(new BasicNameValuePair("user", "[email protected]")); | ||
Iterator<String> iterator = projectProgress.keySet().iterator(); | ||
while(iterator.hasNext()){ | ||
String key = iterator.next(); | ||
int value = projectProgress.get(key); | ||
nameValuePairs.add(new BasicNameValuePair("projectIDs[]", key)); | ||
nameValuePairs.add(new BasicNameValuePair("prioritys[]", String.valueOf(value))); | ||
} | ||
String result = null; | ||
|
||
try { | ||
HttpClient httpClient = new DefaultHttpClient(); | ||
HttpPost httpPost = new HttpPost("http://with7.cloudapp.net/updateProgressWorker.php"); | ||
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "utf-8")); | ||
|
||
HttpResponse response = httpClient.execute(httpPost); | ||
HttpEntity entity = response.getEntity(); | ||
|
||
is = entity.getContent(); | ||
|
||
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8); | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
String line = null; | ||
while ((line = reader.readLine()) != null) { | ||
sb.append(line + "\n"); | ||
} | ||
result = sb.toString(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
protected void onPostExecute(String result) { | ||
String s = result.trim(); | ||
final String json = s.replaceAll("\"", "\\\""); | ||
Log.d("---SJ10 :", "--> " + s); | ||
} | ||
|
||
} | ||
UpdateProgressWorkerAsync la = new UpdateProgressWorkerAsync(); | ||
la.execute(); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters