CreateRoot2 #19

Merged
Utahshi merged 5 commits from CreateRoot2 into master 2024-06-28 01:21:56 +00:00
2 changed files with 73 additions and 83 deletions
Showing only changes of commit d98293a80d - Show all commits

View File

@ -33,14 +33,16 @@ public class CreateRoot {
private final AppDatabase db; private final AppDatabase db;
private int arraySize; private int arraySize;
String testdata[]={"20240604","20240605","20240606"}; boolean secondDuplicates;
String testdata[] = {"20240604", "20240605", "20240606"};
public CreateRoot(AppCompatActivity activity) { public CreateRoot(AppCompatActivity activity) {
this.db = Room.databaseBuilder(activity.getApplicationContext(), AppDatabase.class, "SetUpTable").build(); this.db = Room.databaseBuilder(activity.getApplicationContext(), AppDatabase.class, "SetUpTable").build();
} }
public void receiveData(List<MyDataClass> myDataList) { public Boolean receiveData(List<MyDataClass> myDataList) {
//myDataListの要素data第一希望日と第二希望日に以下を追加する //myDataListの要素data第一希望日と第二希望日に以下を追加する
//保護者の希望時間帯の長さ //保護者の希望時間帯の長さ
@ -78,26 +80,34 @@ public class CreateRoot {
//家庭訪問全体のスケジュールの開始時間を要素とした配列の作成 //家庭訪問全体のスケジュールの開始時間を要素とした配列の作成
int[][][] intervalArray = homeVisitSchedule(); int[][][] intervalArray = homeVisitSchedule();
outPutLogIntervalArray(intervalArray); outPutLogIntervalArray(intervalArray);
//スケジュール作成 //スケジュール作成
boolean Duplicates = createSchedule(myDataList, intervalArray); boolean Duplicates = createSchedule(myDataList, intervalArray);
//重複によるエラー確認 //重複によるエラー確認
if (!Duplicates) { if (!Duplicates) {
sortSchedule(myDataList);
outPutLogSchedule(myDataList); outPutLogSchedule(myDataList);
} else { } else {
//第二希望日で同じ処理を行う //第二希望日で同じ処理を行う
Log.d("CreateRoot", "第二希望");
secondSetData(myDataList); secondSetData(myDataList);
secondTimeZoneSort(myDataList); secondTimeZoneSort(myDataList);
boolean secondDuplicates = secondCreateSchedule(myDataList, intervalArray); secondDuplicates = secondCreateSchedule(myDataList, intervalArray);
if(!secondDuplicates){ if (!secondDuplicates) {
sortSchedule(myDataList);
outPutLogSchedule(myDataList); outPutLogSchedule(myDataList);
}else{
Log.d("CreateRoot", "重複によるエラー");
} }
Log.d("CreateRoot","重複によるエラー");
} }
}); });
if(!secondDuplicates){
return true;
}else{
return false;
}
} }
@ -262,9 +272,11 @@ public class CreateRoot {
intervalList.add(intervalMinutes); intervalList.add(intervalMinutes);
} }
} }
int[][][] intervalArray = new int[3][intervalList.size()][2]; int[][][] intervalArray = new int[3][intervalList.size()][2];
for (int i = 0; i < intervalList.size(); i++) { for (int i = 0; i < intervalList.size(); i++) {
for(int j=0;j<3;j++) { for (int j = 0; j < 3; j++) {
intervalArray[j][i][0] = intervalList.get(i); intervalArray[j][i][0] = intervalList.get(i);
intervalArray[j][i][1] = 0;//割り当てされていないことを表す intervalArray[j][i][1] = 0;//割り当てされていないことを表す
} }
@ -274,11 +286,8 @@ public class CreateRoot {
} }
private void outPutLogIntervalArray(int[][][] intervalArray) { private void outPutLogIntervalArray(int[][][] intervalArray) {
for (int i = 0; i < intervalArray.length; i++) { for (int i = 0; i < intervalArray[0].length; i++) {
for (int j = 0; j < 3; j++) { Log.d("CreateRoot","inteintervalArray:(intex:" + i + ") :"+intervalArray[0][i][0]);
Log.d("CreateRoot:PutLogIntervalArray", "(index:" + i + ") intervalArray:" + intervalArray[j][
i][0]);
}
} }
} }
@ -286,34 +295,18 @@ public class CreateRoot {
private Boolean createSchedule(List<MyDataClass> myDataList, int[][][] intervalArray) { private Boolean createSchedule(List<MyDataClass> myDataList, int[][][] intervalArray) {
for (int i = 0; i < myDataList.size(); i++) { for (int i = 0; i < myDataList.size(); i++) {
for (int j = 0; j < intervalArray.length - 1; j++) { for (int j = 0; j < intervalArray[0].length - 1; j++) {
if (testdata[0].equals(myDataList.get(i).getStartDateString())) { for (int x = 0; x < 3; x++) {
checkSchedule(myDataList,intervalArray,i,j); if (testdata[x].equals(myDataList.get(i).getStartDateString())&&myDataList.get(i).getSchedule()==0) {
// if (intervalArray[0][j][0] >= Integer.parseInt(myDataList.get(i).getParentStartTimeString()) && intervalArray[0][j + 1][0] <= Integer.parseInt(myDataList.get(i).getParentEndTimeString()) && intervalArray[0][j][1] == 0) { String desiredDate=myDataList.get(i).getStartDateString();
// intervalArray[0][j][1] += 1;//割り当て済みを表す checkSchedule(myDataList, intervalArray, i, j, x,desiredDate);
// myDataList.get(i).setSchedule(intervalArray[0][j][0]);
// Log.d("CreateRoot:createSchedule", "(index:" + i + ") :" + myDataList.get(i).getSchedule());
// break;
// }
} else if (testdata[1].equals(myDataList.get(i).getStartDateString())) {
if (intervalArray[1][j][0] >= Integer.parseInt(myDataList.get(i).getParentStartTimeString()) && intervalArray[1][j + 1][0] <= Integer.parseInt(myDataList.get(i).getParentEndTimeString()) && intervalArray[1][j][1] == 0) {
intervalArray[1][j][1] += 1;//割り当て済みを表す
myDataList.get(i).setSchedule(intervalArray[1][j][0]);
Log.d("CreateRoot:createSchedule", "(index:" + i + ") :" + myDataList.get(i).getSchedule());
break; break;
} }
} else if (testdata[2].equals(myDataList.get(i).getStartDateString())) {
if (intervalArray[2][j][0] >= Integer.parseInt(myDataList.get(i).getParentStartTimeString()) && intervalArray[2][j + 1][0] <= Integer.parseInt(myDataList.get(i).getParentEndTimeString()) && intervalArray[2][j][1] == 0) {
intervalArray[2][j][1] += 1;//割り当て済みを表す
myDataList.get(i).setSchedule(intervalArray[2][j][0]);
Log.d("CreateRoot:createSchedule", "(index:" + i + ") :" + myDataList.get(i).getSchedule());
break;
}
} else {
Log.d("CreateRoot", "第一希望日:日付との紐づけエラー");
} }
} }
} }
for (int i = 0; i < myDataList.size(); i++) { for (int i = 0; i < myDataList.size(); i++) {
if (myDataList.get(i).getSchedule() == 0) ; if (myDataList.get(i).getSchedule() == 0) ;
return true; return true;
@ -323,53 +316,38 @@ public class CreateRoot {
private boolean secondCreateSchedule(List<MyDataClass> myDataList, int[][][] intervalArray) { private boolean secondCreateSchedule(List<MyDataClass> myDataList, int[][][] intervalArray) {
for (int i = 0; i < myDataList.size(); i++) { for (int i = 0; i < myDataList.size(); i++) {
for (int j = 0; j < intervalArray.length - 1; j++) { for (int j = 0; j < intervalArray[0].length - 1; j++) {
if(testdata[0].equals(myDataList.get(i).getSecondDayStartDateString())) { for (int x = 0; x < 3; x++) {
if (intervalArray[0][j][0] >= Integer.parseInt(myDataList.get(i).getSecondDayParentStartTimeString()) && intervalArray[0][j + 1][0] <= Integer.parseInt(myDataList.get(i).getSecondDayParentEndTimeString()) && intervalArray[0][j][1] == 0) { if (testdata[x].equals(myDataList.get(i).getSecondDayStartDateString()) && myDataList.get(i).getSchedule() == 0) {
intervalArray[0][j][1] += 1;//割り当て済みを表す String desiredDate=myDataList.get(i).getSecondDayStartDateString();
myDataList.get(i).setSchedule(intervalArray[0][j][0]); checkSchedule(myDataList, intervalArray, i, j, x,desiredDate);
Log.d("CreateRoot:createSchedule", "(index:" + i + ") :" + myDataList.get(i).getSchedule());
break;
} }
}else if(testdata[1].equals(myDataList.get(i).getSecondDayStartDateString())){
if (intervalArray[1][j][0] >= Integer.parseInt(myDataList.get(i).getParentStartTimeString()) && intervalArray[1][j + 1][0] <= Integer.parseInt(myDataList.get(i).getParentEndTimeString()) && intervalArray[1][j][1] == 0) {
intervalArray[1][j][1] += 1;//割り当て済みを表す
myDataList.get(i).setSchedule(intervalArray[1][j][0]);
Log.d("CreateRoot:createSchedule", "(index:" + i + ") :" + myDataList.get(i).getSchedule());
break;
} }
} else if (testdata[2].equals(myDataList.get(i).getSecondDayStartDateString())) {
if (intervalArray[2][j][0] >= Integer.parseInt(myDataList.get(i).getParentStartTimeString()) && intervalArray[2][j + 1][0] <= Integer.parseInt(myDataList.get(i).getParentEndTimeString()) && intervalArray[2][j][1] == 0) {
intervalArray[2][j][1] += 1;//割り当て済みを表す
myDataList.get(i).setSchedule(intervalArray[2][j][0]);
Log.d("CreateRoot:createSchedule", "(index:" + i + ") :" + myDataList.get(i).getSchedule());
break;
}
}else{
Log.d("CreateRoot", "第二希望日:日付との紐づけエラー");
} }
} }
}
for (int i = 0; i < myDataList.size(); i++) { for (int i = 0; i < myDataList.size(); i++) {
if (myDataList.get(i).getSchedule() == 0) ; if (myDataList.get(i).getSchedule() == 0) {
return true; return true;
} }
}
return false; return false;
} }
private void checkSchedule(List<MyDataClass> myDataList,int[][][] intervalArray,int i,int j) { private void checkSchedule(List<MyDataClass> myDataList, int[][][] intervalArray, int i, int j, int x,String desiredDate) {
for (int x = 0; x < 3; x++) {
if(intervalArray[x][j][0] >= Integer.parseInt(myDataList.get(i).getParentStartTimeString()) && intervalArray[x][j + 1][0] <= Integer.parseInt(myDataList.get(i).getParentEndTimeString()) && intervalArray[x][j][1] == 0) if (intervalArray[x][j][0] >= Integer.parseInt(myDataList.get(i).getParentStartTimeString()) && intervalArray[x][j + 1][0] <= Integer.parseInt(myDataList.get(i).getParentEndTimeString()) && intervalArray[x][j][1] == 0) {
{
intervalArray[x][j][1] += 1;//割り当て済みを表す intervalArray[x][j][1] += 1;//割り当て済みを表す
myDataList.get(i).setSchedule(intervalArray[x][j][0]); myDataList.get(i).setSchedule(Integer.parseInt(desiredDate.substring(4,8)+String.valueOf(intervalArray[x][j][0])));
Log.d("CreateRoot:CheckSchedule","(intex:"+i+") :"+myDataList.get(i).getStartDateString());
Log.d("CreateRoot:CheckSchedule", "(index:" + i + ") :" + myDataList.get(i).getSchedule());
break;
} }
} }
private void sortSchedule(List<MyDataClass> myDataList) {
Comparator<MyDataClass> comparator = Comparator.comparing(MyDataClass::getSchedule);
myDataList.sort(comparator);
} }
private void outPutLogSchedule(List<MyDataClass> myDataList) { private void outPutLogSchedule(List<MyDataClass> myDataList) {
for (int i = 0; i < myDataList.size(); i++) { for (int i = 0; i < myDataList.size(); i++) {
Log.d("CreateRoot:outPutLogSchedule", "(index: " + i + ") data: " + myDataList.get(i)); Log.d("CreateRoot:outPutLogSchedule", "(index: " + i + ") data: " + myDataList.get(i));

View File

@ -148,8 +148,13 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
} }
Log.d("MainActivity","myDataList"+ myDataList.size()); Log.d("MainActivity","myDataList"+ myDataList.size());
CreateRoot createRoot = new CreateRoot(MainActivity.this); CreateRoot createRoot = new CreateRoot(MainActivity.this);
createRoot.receiveData(myDataList); Boolean notDuplicates=createRoot.receiveData(myDataList);
latch.countDown(); latch.countDown();
if(notDuplicates){
Log.d("MainActivity","スケジュール作成成功");
}else{
showErrorDialog(latch);
}
}); });
new Thread(() -> { new Thread(() -> {
@ -226,16 +231,23 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
.show(); .show();
} }
public void showErrorDialog() { public void showErrorDialog(CountDownLatch latch) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("警告"); new AlertDialog.Builder(MainActivity.this)
builder.setMessage("保護者の希望の重複が深刻で、ルート検索が行えません。調整してください。"); .setTitle("警告")
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { .setMessage("保護者の重複が重大でルート作成ができません。調整してください")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
latch.countDown();
} }
}); })
builder.show(); .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.show();
} }
} }