修正なう
This commit is contained in:
commit
55a41ce13c
|
@ -1,6 +1,6 @@
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
|
|
@ -1,127 +1,357 @@
|
||||||
package com.example.oplogy;
|
package com.example.oplogy;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.room.Room;
|
import androidx.room.Room;
|
||||||
|
|
||||||
import com.google.firebase.Timestamp;
|
import com.google.firebase.Timestamp;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.TimeZone;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
|
||||||
public class CreateRoot {
|
public class CreateRoot {
|
||||||
private Context context;
|
MyDataClass data;//Firestoreから受け取ったdataを入れる変数
|
||||||
private AppDatabase db;
|
String startTimeHomeVisit;//家庭訪問の開始時間
|
||||||
|
String endTimeHomeVisit;//家庭訪問の終了時間
|
||||||
|
String intervalTime;//家庭訪問の一家庭当たりの時間
|
||||||
|
String startBreakTime;//家庭訪問の休憩の開始時間
|
||||||
|
String endBreakTime;//家庭訪問の休憩の終了時間
|
||||||
|
|
||||||
|
|
||||||
|
int interval;//家庭訪問の一家庭当たりの時間と移動時間の合計
|
||||||
|
int startBreakTimeMinutes;//家庭訪問の開始時間から休憩時間までの時間
|
||||||
|
int endBreakTimeMinutes;//家庭訪問の休憩終了時間から終了時間までの時間
|
||||||
|
|
||||||
|
private final AppDatabase db;
|
||||||
private int arraySize;
|
private int arraySize;
|
||||||
|
|
||||||
public CreateRoot(MainActivity activity) {
|
boolean secondDuplicates;
|
||||||
this.context = activity;
|
|
||||||
|
String testdata[] = {"20240604", "20240605", "20240606"};
|
||||||
|
|
||||||
|
|
||||||
|
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第一希望日と第二希望日に以下を追加する
|
||||||
|
//・保護者の希望時間帯の長さ
|
||||||
|
//・家庭訪問の日付
|
||||||
|
//・保護者の希望時間帯の開始と終了時間
|
||||||
|
setData(myDataList);
|
||||||
|
//希望時間帯の長さ順に並び替える前のログ
|
||||||
|
outPutLogSort(myDataList);
|
||||||
|
//保護者の希望時間帯が短い順にmyDataListのDataを並び替える
|
||||||
|
timeZoneSort(myDataList);
|
||||||
|
//希望時間帯の長さ順に並び替えたあとのログ
|
||||||
|
outPutLogSort(myDataList);
|
||||||
|
|
||||||
|
|
||||||
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
|
executor.execute(() -> {
|
||||||
|
//Roomから以下の情報を取得
|
||||||
|
//・家庭訪問全体の開始時間
|
||||||
|
//・家庭訪問全体の終了時間
|
||||||
|
//・一家庭あたりの家庭訪問の時間
|
||||||
|
//・家庭訪問の休憩開始時間
|
||||||
|
//・家庭訪問の休憩終了時間
|
||||||
|
getRoomData();
|
||||||
|
|
||||||
|
//Roomから取得した情報のログ
|
||||||
|
|
||||||
|
outPutLogRoomData();
|
||||||
|
|
||||||
|
//以下の情報を計算
|
||||||
|
//・家庭訪問の合計時間
|
||||||
|
//・家庭訪問の開始時間から休憩時間までの分数
|
||||||
|
//・家庭訪問の休憩終了時間から終了時間までの分数
|
||||||
|
timeCalculation(endTimeHomeVisit, startBreakTime, endBreakTime);
|
||||||
|
|
||||||
|
//家庭訪問全体のスケジュールの開始時間を要素とした配列の作成
|
||||||
|
int[][][] intervalArray = homeVisitSchedule();
|
||||||
|
|
||||||
|
|
||||||
|
outPutLogIntervalArray(intervalArray);
|
||||||
|
//スケジュール作成
|
||||||
|
boolean Duplicates = createSchedule(myDataList, intervalArray);
|
||||||
|
|
||||||
|
//重複によるエラー確認
|
||||||
|
if (!Duplicates) {
|
||||||
|
sortSchedule(myDataList);
|
||||||
|
outPutLogSchedule(myDataList);
|
||||||
|
} else {
|
||||||
|
//第二希望日で同じ処理を行う
|
||||||
|
Log.d("CreateRoot", "第二希望");
|
||||||
|
secondSetData(myDataList);
|
||||||
|
secondTimeZoneSort(myDataList);
|
||||||
|
secondDuplicates = secondCreateSchedule(myDataList, intervalArray);
|
||||||
|
if (!secondDuplicates) {
|
||||||
|
sortSchedule(myDataList);
|
||||||
|
outPutLogSchedule(myDataList);
|
||||||
|
} else {
|
||||||
|
Log.d("CreateRoot", "重複によるエラー");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!secondDuplicates) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void setData(List<MyDataClass> myDataList) {
|
||||||
for (int i = 0; i < myDataList.size(); i++) {
|
for (int i = 0; i < myDataList.size(); i++) {
|
||||||
// 希望時間帯の終了時刻から開始時刻を引いて希望時間帯の長さ(timezone)に入れる
|
// 希望時間帯の終了時刻から開始時刻を引いて希望時間帯の長さ(timezone)に入れる
|
||||||
MyDataClass data = myDataList.get(i);
|
data = myDataList.get(i);
|
||||||
|
//保護者の第一希望日
|
||||||
List<Timestamp> firstDay = data.getFirstDay();
|
List<Timestamp> firstDay = data.getFirstDay();
|
||||||
Timestamp startTime = firstDay.get(0);
|
|
||||||
Timestamp endTime = firstDay.get(1);
|
//保護者の第一希望日の開始時間
|
||||||
Long timezone = endTime.getSeconds() - startTime.getSeconds();
|
Timestamp parentStartTime = firstDay.get(0);
|
||||||
|
//保護者の第一希望日の終了時間
|
||||||
|
Timestamp parentEndTime = firstDay.get(1);
|
||||||
|
//保護者の第一希望日の希望時間帯の長さ
|
||||||
|
Long timezone = parentEndTime.getSeconds() - parentStartTime.getSeconds();
|
||||||
data.setTimezone(timezone);
|
data.setTimezone(timezone);
|
||||||
|
|
||||||
// TimeStampを日付に変換
|
// TimeStampを日付に変換
|
||||||
Date startDate = new Date(startTime.getSeconds() * 1000);
|
Date startDate = new Date(parentStartTime.getSeconds() * 1000);
|
||||||
Date endDate = new Date(endTime.getSeconds() * 1000);
|
Date endDate = new Date(parentEndTime.getSeconds() * 1000);
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
SimpleDateFormat sdfDateData = new SimpleDateFormat("yyyyMMdd");
|
||||||
String startDateString = sdf.format(startDate);
|
sdfDateData.setTimeZone(TimeZone.getTimeZone("Asia/Tokyo"));
|
||||||
String endDateString = sdf.format(endDate);
|
//第一希望日の日付
|
||||||
|
String startDateString = sdfDateData.format(startDate);
|
||||||
|
String endDateString = sdfDateData.format(endDate);
|
||||||
|
|
||||||
|
|
||||||
|
SimpleDateFormat sdfMinutes = new SimpleDateFormat("HHmm");
|
||||||
|
sdfMinutes.setTimeZone(TimeZone.getTimeZone("Asia/Tokyo"));
|
||||||
|
//保護者の希望開始時間を時間表記にしたもの
|
||||||
|
String parentStartTimeString = sdfMinutes.format(parentStartTime.toDate());
|
||||||
|
//保護者の希望終了時間を時間表記にしたもの
|
||||||
|
String parentEndTimeString = sdfMinutes.format(parentEndTime.toDate());
|
||||||
|
|
||||||
|
|
||||||
// myDataList の中の data に追加する処理
|
// myDataList の中の data に追加する処理
|
||||||
myDataList.get(i).setTimezone(timezone);
|
myDataList.get(i).setTimezone(timezone);
|
||||||
myDataList.get(i).setStartDateString(startDateString);
|
myDataList.get(i).setStartDateString(startDateString);
|
||||||
myDataList.get(i).setEndDateString(endDateString);
|
myDataList.get(i).setEndDateString(endDateString);
|
||||||
|
myDataList.get(i).setParentStartTimeString(parentStartTimeString);
|
||||||
|
myDataList.get(i).setParentEndTimeString(parentEndTimeString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ログ出力
|
//setDataと処理は同じ(第二希望は任意なのでその点だけ確認)
|
||||||
Log.d("CreateRoot", "(index: " + i + ") timezone: " + myDataList.get(i).getTimezone());
|
private void secondSetData(List<MyDataClass> myDataList) {
|
||||||
Log.d("CreateRoot", "(index: " + i + ") startDate: " + myDataList.get(i).getStartDateString());
|
|
||||||
Log.d("CreateRoot", "(index: " + i + ") data: " + myDataList.get(i));
|
|
||||||
}
|
|
||||||
// timezoneを比較するComparator→timezoneが短い順に並べる
|
|
||||||
Comparator<MyDataClass> comparator = new Comparator<MyDataClass>() {
|
|
||||||
@Override
|
|
||||||
public int compare(MyDataClass data1, MyDataClass data2) {
|
|
||||||
return data1.getTimezone().compareTo(data2.getTimezone());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// myDataListをtimezoneの値でソート
|
|
||||||
Collections.sort(myDataList, comparator);
|
|
||||||
// ソート後のmyDataListをログ出力
|
|
||||||
for (int i = 0; i < myDataList.size(); i++) {
|
for (int i = 0; i < myDataList.size(); i++) {
|
||||||
Log.d("CreateRoot", "(index: " + i + ") timezone: " + myDataList.get(i).getTimezone());
|
// 希望時間帯の終了時刻から開始時刻を引いて希望時間帯の長さ(timezone)に入れる
|
||||||
Log.d("CreateRoot", "(index: " + i + ") startDate: " + myDataList.get(i).getStartDateString());
|
data = myDataList.get(i);
|
||||||
Log.d("CreateRoot", "(index: " + i + ") data: " + myDataList.get(i));
|
if (myDataList.get(i).getSecondDay() != null) {
|
||||||
|
//保護者の第二希望日
|
||||||
|
List<Timestamp> secondDay = data.getSecondDay();
|
||||||
|
//保護者の第二希望日の開始時間
|
||||||
|
Timestamp parentStartTime = secondDay.get(0);
|
||||||
|
//保護者の第二希望日の終了時間
|
||||||
|
Timestamp parentEndTime = secondDay.get(1);
|
||||||
|
//保護者の第二希望日の希望時間帯の長さ
|
||||||
|
Long secondDayTimezone = parentEndTime.getSeconds() - parentStartTime.getSeconds();
|
||||||
|
data.setTimezone(secondDayTimezone);
|
||||||
|
|
||||||
|
// TimeStampを日付に変換
|
||||||
|
Date startDate = new Date(parentStartTime.getSeconds() * 1000);
|
||||||
|
Date endDate = new Date(parentEndTime.getSeconds() * 1000);
|
||||||
|
SimpleDateFormat sdfDateData = new SimpleDateFormat("yyyyMMdd");
|
||||||
|
sdfDateData.setTimeZone(TimeZone.getTimeZone("Asia/Tokyo"));
|
||||||
|
//第二希望日の日付
|
||||||
|
String secondDayStartDateString = sdfDateData.format(startDate);
|
||||||
|
String secondDaySndDateString = sdfDateData.format(endDate);
|
||||||
|
|
||||||
|
|
||||||
|
SimpleDateFormat sdfMinutes = new SimpleDateFormat("HHmm");
|
||||||
|
sdfMinutes.setTimeZone(TimeZone.getTimeZone("Asia/Tokyo"));
|
||||||
|
//保護者の希望開始時間を時間表記にしたもの
|
||||||
|
String secondDayParentStartTimeString = sdfMinutes.format(parentStartTime.toDate());
|
||||||
|
//保護者の希望終了時間を時間表記にしたもの
|
||||||
|
String secondDayParentEndTimeString = sdfMinutes.format(parentEndTime.toDate());
|
||||||
|
|
||||||
|
|
||||||
|
// myDataList の中の data に追加する処理
|
||||||
|
myDataList.get(i).setSecondDayTimezone(secondDayTimezone);
|
||||||
|
myDataList.get(i).setSecondDayStartDateString(secondDayStartDateString);
|
||||||
|
myDataList.get(i).setSecondDayEndDateString(secondDaySndDateString);
|
||||||
|
myDataList.get(i).setSecondDayParentStartTimeString(secondDayParentStartTimeString);
|
||||||
|
myDataList.get(i).setSecondDayParentEndTimeString(secondDayParentEndTimeString);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
private void timeZoneSort(List<MyDataClass> myDataList) {
|
||||||
executor.execute(() -> {
|
// timezoneを比較するComparator→timezoneが短い順に並べる
|
||||||
|
Comparator<MyDataClass> comparator = Comparator.comparing(MyDataClass::getTimezone);
|
||||||
|
// myDataListをtimezoneの値でソート
|
||||||
|
myDataList.sort(comparator);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void secondTimeZoneSort(List<MyDataClass> myDataList) {
|
||||||
|
// timezoneを比較するComparator→timezoneが短い順に並べる
|
||||||
|
Comparator<MyDataClass> comparator = Comparator.comparing(MyDataClass::getSecondDayTimezone);
|
||||||
|
// myDataListをtimezoneの値でソート
|
||||||
|
myDataList.sort(comparator);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void outPutLogSort(List<MyDataClass> myDataList) {
|
||||||
|
for (int i = 0; i < myDataList.size(); i++) {
|
||||||
|
Log.d("CreateRoot", "(index: " + i + ") data: " + myDataList.get(i).getPatronName());
|
||||||
|
Log.d("CreateRoot", "(index: " + i + ") data: " + myDataList.get(i).getClass());
|
||||||
|
Log.d("CreateRoot", "(index: " + i + ") timezone: " + myDataList.get(i).getTimezone());
|
||||||
|
Log.d("CreateRoot", "(index: " + i + ") startDate: " + myDataList.get(i).getStartDateString());
|
||||||
|
Log.d("CreateRoot:outPutLogBeforeSort", "parentStartTimeString: " + myDataList.get(i).getParentStartTimeString());
|
||||||
|
Log.d("CreateRoot:outPutLogBeforeSort", "parentEndTimeString: " + myDataList.get(i).getParentEndTimeString());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getRoomData() {
|
||||||
// setUpActivityによって入力され、Roomに保存された値を取り出す処理
|
// setUpActivityによって入力され、Roomに保存された値を取り出す処理
|
||||||
|
//Roomの操作の定義
|
||||||
SetUpTableDao setUpTableDao = db.setUpTableDao();
|
SetUpTableDao setUpTableDao = db.setUpTableDao();
|
||||||
String startTime = setUpTableDao.getStartTime();
|
startTimeHomeVisit = setUpTableDao.getStartTime();
|
||||||
String endTime = setUpTableDao.getEndTime();
|
endTimeHomeVisit = setUpTableDao.getEndTime();
|
||||||
String intervalTime = setUpTableDao.getIntervalTime();
|
intervalTime = setUpTableDao.getIntervalTime();
|
||||||
String startBreakTime = setUpTableDao.getStartBreakTime();
|
startBreakTime = setUpTableDao.getStartBreakTime();
|
||||||
String endBreakTime = setUpTableDao.getEndBreakTime();
|
endBreakTime = setUpTableDao.getEndBreakTime();
|
||||||
// デバッグ用
|
}
|
||||||
Log.d("CreateRoot", "開始時間" + startTime);
|
|
||||||
Log.d("CreateRoot", "終了時刻" + endTime);
|
|
||||||
Log.d("CreateRoot", "一家庭当たりの所要時間" + intervalTime);
|
|
||||||
Log.d("CreateRoot", "休憩開始時刻" + startBreakTime);
|
|
||||||
Log.d("CreateRoot", "休憩終了時刻" + endBreakTime);
|
|
||||||
|
|
||||||
// endTimeからstartTimeの値を引いた値をintervalTime+10で割って配列を作る
|
//Roomからのデータ取得に関するログ
|
||||||
int startHour = Integer.parseInt(startTime.substring(0, 2));
|
void outPutLogRoomData() {
|
||||||
int endHour = Integer.parseInt(endTime.substring(0, 2));
|
Log.d("CreateRoot:outPutLogRoomData", "開始時間" + startTimeHomeVisit);
|
||||||
int startMinute = Integer.parseInt(startTime.substring(2, 4));
|
Log.d("CreateRoot:outPutLogRoomData", "終了時刻" + endTimeHomeVisit);
|
||||||
int endMinute = Integer.parseInt(endTime.substring(2, 4));
|
Log.d("CreateRoot:outPutLogRoomData", "一家庭当たりの所要時間" + intervalTime);
|
||||||
|
Log.d("CreateRoot:outPutLogRoomData", "休憩開始時刻" + startBreakTime);
|
||||||
|
Log.d("CreateRoot:outPutLogRoomData", "休憩終了時刻" + endBreakTime);
|
||||||
|
}
|
||||||
|
|
||||||
int totalTime = (endHour - startHour) * 60 + (endMinute - startMinute);
|
private void timeCalculation(String endTimeHomeVisit, String startBreakTime, String endBreakTime) {
|
||||||
int interval = Integer.parseInt(intervalTime) + 10;
|
//家庭訪問の合計時間を計算するため、家庭訪問の終了時間から開始時間を引いた数を求めている。但し、(0,2)によって先に1時間単位の差を求めた後に、(2,4)によって分単位の差を求めている
|
||||||
arraySize = totalTime / interval;
|
int totalTime = ((Integer.parseInt(endTimeHomeVisit.substring(0, 2)) - (Integer.parseInt(startTimeHomeVisit.substring(0, 2)))) * 60 + ((Integer.parseInt(endTimeHomeVisit.substring(2, 4)))) - (Integer.parseInt(startTimeHomeVisit.substring(2, 4))));
|
||||||
|
//家庭訪問の休憩開始時間から家庭訪問の開始時間を引くことで家庭訪問の開始から休憩時間までの分数を計算
|
||||||
int startBreakHour = Integer.parseInt(startBreakTime.substring(0, 2));
|
startBreakTimeMinutes = ((Integer.parseInt(startBreakTime.substring(0, 2))) - (Integer.parseInt(startTimeHomeVisit.substring(0, 2)))) * 60 + ((Integer.parseInt(startBreakTime.substring(2, 4))) - (Integer.parseInt(startTimeHomeVisit.substring(2, 4))));
|
||||||
int startBreakMinute = Integer.parseInt(startBreakTime.substring(2, 4));
|
//家庭訪問の休憩終了時間から家庭訪問の終了時間を引くことで休憩の終わりから家庭訪問の終了時間までの分数を計算
|
||||||
int endBreakHour = Integer.parseInt(endBreakTime.substring(0, 2));
|
endBreakTimeMinutes = ((Integer.parseInt(endBreakTime.substring(0, 2))) - (Integer.parseInt(startTimeHomeVisit.substring(0, 2)))) * 60 + ((Integer.parseInt(endBreakTime.substring(2, 4))) - (Integer.parseInt(startTimeHomeVisit.substring(2, 4))));
|
||||||
int endBreakMinute = Integer.parseInt(endBreakTime.substring(2, 4));
|
interval = Integer.parseInt(intervalTime) + 10;//移動時間込みの1家庭当たりの所要時間
|
||||||
|
arraySize = totalTime / interval;//家庭訪問の合計時間から移動時間込みの1家庭当たりの所要時間を割ることで配列の数を求めている
|
||||||
int startBreakTimeMinutes = (startBreakHour - startHour) * 60 + (startBreakMinute - startMinute);
|
}
|
||||||
int endBreakTimeMinutes = (endBreakHour - startHour) * 60 + (endBreakMinute - startMinute);
|
|
||||||
|
|
||||||
|
private int[][][] homeVisitSchedule() {
|
||||||
|
//家庭訪問の開始時間からの経過分数を入れる配列
|
||||||
List<Integer> intervalList = new ArrayList<>();
|
List<Integer> intervalList = new ArrayList<>();
|
||||||
|
startBreakTimeMinutes = (((Integer.parseInt(startTimeHomeVisit.substring(0, 2))) + (startBreakTimeMinutes + (Integer.parseInt(startTimeHomeVisit.substring(0, 2)))) / 60) % 24) * 100 + (startBreakTimeMinutes + (Integer.parseInt(startTimeHomeVisit.substring(2, 4)))) % 60;
|
||||||
|
endBreakTimeMinutes = (((Integer.parseInt(startTimeHomeVisit.substring(0, 2))) + (endBreakTimeMinutes + (Integer.parseInt(startTimeHomeVisit.substring(0, 2)))) / 60) % 24) * 100 + (endBreakTimeMinutes + (Integer.parseInt(startTimeHomeVisit.substring(2, 4)))) % 60;
|
||||||
|
|
||||||
|
//休憩時間を除いた家庭訪問の開始時間からの経過分数+家庭訪問の開始時間=家庭訪問のスケジュール区切りをintervalArrayに入れる処理
|
||||||
for (int i = 0; i < arraySize; i++) {
|
for (int i = 0; i < arraySize; i++) {
|
||||||
int intervalMinutes = i * interval;
|
int intervalMinutes = (((Integer.parseInt(startTimeHomeVisit.substring(0, 2))) + (interval * i) / 60) % 24) * 100 + (interval * i) % 60;
|
||||||
|
if (intervalMinutes % 100 >= 60) {
|
||||||
|
intervalMinutes += 40; // 下2桁が60以上の場合は繰り上げる
|
||||||
|
}
|
||||||
if (intervalMinutes < startBreakTimeMinutes || intervalMinutes >= endBreakTimeMinutes) {
|
if (intervalMinutes < startBreakTimeMinutes || intervalMinutes >= endBreakTimeMinutes) {
|
||||||
intervalList.add(intervalMinutes);
|
intervalList.add(intervalMinutes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int[] intervalArray = new int[intervalList.size()];
|
|
||||||
|
int[][][] intervalArray = new int[3][intervalList.size()][2];
|
||||||
for (int i = 0; i < intervalList.size(); i++) {
|
for (int i = 0; i < intervalList.size(); i++) {
|
||||||
intervalArray[i] = intervalList.get(i);
|
for (int j = 0; j < 3; j++) {
|
||||||
|
intervalArray[j][i][0] = intervalList.get(i);
|
||||||
|
intervalArray[j][i][1] = 0;//割り当てされていないことを表す
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// デバッグ用ログ
|
return intervalArray;
|
||||||
for (int i = 0; i < intervalArray.length; i++) {
|
|
||||||
Log.d("CreateRoot", "家庭訪問時間" + intervalArray[i]);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
private void outPutLogIntervalArray(int[][][] intervalArray) {
|
||||||
|
for (int i = 0; i < intervalArray[0].length; i++) {
|
||||||
|
Log.d("CreateRoot", "inteintervalArray:(intex:" + i + ") :" + intervalArray[0][i][0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Boolean createSchedule(List<MyDataClass> myDataList, int[][][] intervalArray) {
|
||||||
|
|
||||||
|
for (int i = 0; i < myDataList.size(); i++) {
|
||||||
|
for (int j = 0; j < intervalArray[0].length - 1; j++) {
|
||||||
|
for (int x = 0; x < 3; x++) {
|
||||||
|
if (testdata[x].equals(myDataList.get(i).getStartDateString()) && myDataList.get(i).getSchedule() == 0) {
|
||||||
|
String desiredDate = myDataList.get(i).getStartDateString();
|
||||||
|
checkSchedule(myDataList, intervalArray, i, j, x, desiredDate);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < myDataList.size(); i++) {
|
||||||
|
if (myDataList.get(i).getSchedule() == 0) ;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean secondCreateSchedule(List<MyDataClass> myDataList, int[][][] intervalArray) {
|
||||||
|
for (int i = 0; i < myDataList.size(); i++) {
|
||||||
|
for (int j = 0; j < intervalArray[0].length - 1; j++) {
|
||||||
|
for (int x = 0; x < 3; x++) {
|
||||||
|
if (testdata[x].equals(myDataList.get(i).getSecondDayStartDateString()) && myDataList.get(i).getSchedule() == 0) {
|
||||||
|
String desiredDate = myDataList.get(i).getSecondDayStartDateString();
|
||||||
|
checkSchedule(myDataList, intervalArray, i, j, x, desiredDate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < myDataList.size(); i++) {
|
||||||
|
if (myDataList.get(i).getSchedule() == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkSchedule(List<MyDataClass> myDataList, int[][][] intervalArray, int i, int j, int x, String desiredDate) {
|
||||||
|
|
||||||
|
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;//割り当て済みを表す
|
||||||
|
myDataList.get(i).setSchedule(Integer.parseInt(desiredDate.substring(4, 8) + String.valueOf(intervalArray[x][j][0])));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sortSchedule(List<MyDataClass> myDataList) {
|
||||||
|
|
||||||
|
Comparator<MyDataClass> comparator = Comparator.comparing(MyDataClass::getSchedule);
|
||||||
|
myDataList.sort(comparator);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void outPutLogSchedule(List<MyDataClass> myDataList) {
|
||||||
|
for (int i = 0; i < myDataList.size(); i++) {
|
||||||
|
Log.d("CreateRoot:outPutLogSchedule", "(index: " + i + ") data: " + myDataList.get(i));
|
||||||
|
Log.d("CreateRoot:outPutLogSchedule", "(index: " + i + ") Schedule: " + myDataList.get(i).getSchedule());
|
||||||
|
Log.d("CreateRoot:outPutLogSchedule", "(index: " + i + ") date: " + myDataList.get(i).getStartDateString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ import com.google.firebase.firestore.QueryDocumentSnapshot;
|
||||||
import com.google.firebase.firestore.QuerySnapshot;
|
import com.google.firebase.firestore.QuerySnapshot;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -73,10 +72,12 @@ public class FirestoreReception {
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Dataのリストのサイズを返す
|
//Dataのリストのサイズを返す
|
||||||
public int getMyDataListSize() {
|
public int getMyDataListSize() {
|
||||||
return myDataList.size();
|
return myDataList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Dataのリストを返す
|
//Dataのリストを返す
|
||||||
public List<MyDataClass> getMyDataList() {
|
public List<MyDataClass> getMyDataList() {
|
||||||
return myDataList;
|
return myDataList;
|
||||||
|
|
|
@ -153,8 +153,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
classId = CreateUUID.generateUUID(classIdList);
|
classId = CreateUUID.generateUUID(classIdList);
|
||||||
Toast.makeText(MainActivity.this, "クラスID: " + classId, Toast.LENGTH_SHORT).show();
|
Toast.makeText(MainActivity.this, "クラスID: " + classId, Toast.LENGTH_SHORT).show();
|
||||||
Log .d("classIdList", classIdList.toString());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
||||||
|
@ -168,6 +166,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
alertDialog.show();
|
alertDialog.show();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//ルート作成の非同期処理
|
//ルート作成の非同期処理
|
||||||
private void fetchDataAndCreateRoute() {
|
private void fetchDataAndCreateRoute() {
|
||||||
//非同期処理の開始
|
//非同期処理の開始
|
||||||
|
@ -196,10 +195,26 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
|
|
||||||
// タスク2: ルート作成を行う
|
// タスク2: ルート作成を行う
|
||||||
executor.execute(() -> {
|
executor.execute(() -> {
|
||||||
List<MyDataClass> myDataList = firestoreReception.getMyDataList();
|
List<MyDataClass> myDataList = null;
|
||||||
|
while (myDataList == null) {
|
||||||
|
myDataList = firestoreReception.getMyDataList();
|
||||||
|
try {
|
||||||
|
Thread.sleep(3000);
|
||||||
|
Log.d("MainActivity", "myDataList" + myDataList.size());
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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, myDataList);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
|
@ -216,6 +231,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
|
|
||||||
executor.shutdown();
|
executor.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
//ルート作成のダイアログ
|
//ルート作成のダイアログ
|
||||||
private void showRouteCreationDialog(CountDownLatch latch) {
|
private void showRouteCreationDialog(CountDownLatch latch) {
|
||||||
new AlertDialog.Builder(MainActivity.this)
|
new AlertDialog.Builder(MainActivity.this)
|
||||||
|
@ -236,6 +252,38 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void showErrorDialog(CountDownLatch latch, List<MyDataClass> myDataList) {
|
||||||
|
List<Integer> studentNumbers = new ArrayList<>();
|
||||||
|
for (int i = 0; i < myDataList.size(); i++) {
|
||||||
|
if (myDataList.get(i).getSchedule() == 0) {
|
||||||
|
studentNumbers.add(myDataList.get(i).getStudentNumber());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
StringBuilder message = new StringBuilder("保護者の重複が重大でルート作成ができません。調整してください。\n出席番号: ");
|
||||||
|
for (int i = 0; i < studentNumbers.size(); i++) {
|
||||||
|
message.append(studentNumbers.get(i));
|
||||||
|
if (i < studentNumbers.size() - 1) {
|
||||||
|
message.append(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
new AlertDialog.Builder(MainActivity.this)
|
||||||
|
.setTitle("警告")
|
||||||
|
.setMessage(message.toString())
|
||||||
|
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
//提出状況の取得
|
//提出状況の取得
|
||||||
private ArrayList<SubmissionStudent> getSubmissionStudents() {
|
private ArrayList<SubmissionStudent> getSubmissionStudents() {
|
||||||
ArrayList<SubmissionStudent> submissionStudents = new ArrayList<>();
|
ArrayList<SubmissionStudent> submissionStudents = new ArrayList<>();
|
||||||
|
@ -302,4 +350,3 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,18 @@ public class MyDataClass {
|
||||||
private Long Timezone;
|
private Long Timezone;
|
||||||
private String startDateString;
|
private String startDateString;
|
||||||
private String endDateString;
|
private String endDateString;
|
||||||
|
private String AssignedStartTime;
|
||||||
|
private int AssignedIndex;
|
||||||
|
private boolean linking;
|
||||||
|
private String parentStartTimeString;
|
||||||
|
private String parentEndTimeString;
|
||||||
|
private int schedule;
|
||||||
|
private String secondDayStartDateString;
|
||||||
|
private String secondDayEndDateString;
|
||||||
|
private Long secondDayTimezone;
|
||||||
|
private String secondDayParentStartTimeString;
|
||||||
|
private String secondDayParentEndTimeString;
|
||||||
|
|
||||||
|
|
||||||
public MyDataClass(String patronName, int classId, List<String> address, List<Timestamp> firstDay, int studentNumber, String childName, List<Timestamp> thirdDay, List<Timestamp> secondDay) {
|
public MyDataClass(String patronName, int classId, List<String> address, List<Timestamp> firstDay, int studentNumber, String childName, List<Timestamp> thirdDay, List<Timestamp> secondDay) {
|
||||||
this.patronName = patronName;
|
this.patronName = patronName;
|
||||||
|
@ -132,7 +144,95 @@ public class MyDataClass {
|
||||||
public String getStartDateString() {
|
public String getStartDateString() {
|
||||||
return startDateString;
|
return startDateString;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStartDateString(String startDateString) {
|
public void setStartDateString(String startDateString) {
|
||||||
this.startDateString = startDateString;
|
this.startDateString = startDateString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setAssignedStartTime(String AssignedStartTime) {
|
||||||
|
this.AssignedStartTime = AssignedStartTime;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String setAssignedEndTime(String s) {
|
||||||
|
return AssignedStartTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAssignedIndex(int AssignedIndex) {
|
||||||
|
this.AssignedIndex = AssignedIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAssignedIndex() {
|
||||||
|
return AssignedIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLinking(boolean linking) {
|
||||||
|
this.linking = linking;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getLinking() {
|
||||||
|
return linking;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParentStartTimeString(String parentStartTimeString) {
|
||||||
|
this.parentStartTimeString = parentStartTimeString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParentEndTimeString(String parentEndTimeString) {
|
||||||
|
this.parentEndTimeString = parentEndTimeString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getParentStartTimeString() {
|
||||||
|
return parentStartTimeString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getParentEndTimeString() {
|
||||||
|
return parentEndTimeString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSchedule(int schedule) {
|
||||||
|
this.schedule = schedule;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSchedule() {
|
||||||
|
return schedule;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSecondDayStartDateString(String secondDayStartDateString) {
|
||||||
|
this.secondDayStartDateString = secondDayStartDateString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSecondDayEndDateString(String secondDayEndDateString) {
|
||||||
|
this.secondDayEndDateString = secondDayEndDateString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSecondDayTimezone(Long secondDayTimezone) {
|
||||||
|
this.secondDayTimezone = secondDayTimezone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getSecondDayTimezone() {
|
||||||
|
return secondDayTimezone;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setSecondDayParentStartTimeString(String secondDayParentStartTimeString) {
|
||||||
|
this.secondDayParentStartTimeString = secondDayParentStartTimeString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSecondDayParentEndTimeString(String secondDayParentEndTimeString) {
|
||||||
|
this.secondDayParentEndTimeString = secondDayParentEndTimeString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSecondDayParentStartTimeString() {
|
||||||
|
return secondDayParentStartTimeString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSecondDayParentEndTimeString() {
|
||||||
|
return secondDayParentEndTimeString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSecondDayStartDateString() {
|
||||||
|
return secondDayStartDateString;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user