Skip to content

Commit

Permalink
#A014 - worker progress
Browse files Browse the repository at this point in the history
  • Loading branch information
smilesj committed Oct 27, 2015
1 parent 7e66f41 commit 2c34dfb
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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() {
Expand All @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand All @@ -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();
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,13 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
}

private void getProgressAll(){
Log.d("---SJ P_ :", String.valueOf(workerDataList.size()));
double workerCnt = workerDataList.size();
double workerPer = 1 / workerCnt;
double remainder = 1 - (workerPer * workerCnt);
double tempValue = 0;
Log.d("---SJ8_workerPer" , String.valueOf(workerPer));
Log.d("---SJ8_remainder", String.valueOf(remainder));

for(int i = 0; i < workerCnt; i++){
Log.d("---SJ8_progress", String.valueOf(workerDataList.get(i).getWorkerProgress()));
tempValue += workerDataList.get(i).getWorkerProgress() * workerPer;
Log.d("---SJ8_tempValue", String.valueOf(tempValue));
}
progressAllValue = (int)tempValue +(int)(remainder * 100) ;
progressAll.setProgress(progressAllValue);
Expand Down

0 comments on commit 2c34dfb

Please sign in to comment.