This commit is contained in:
it232115 2024-06-27 17:49:55 +09:00
parent e4a4d66237
commit 323b283208
5 changed files with 476 additions and 97 deletions

View File

@ -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">

View File

@ -1,127 +1,381 @@
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) { String testdata[]={"20240604","20240605","20240606"};
this.context = 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 void 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) {
outPutLogSchedule(myDataList);
} else {
//第二希望日で同じ処理を行う
secondSetData(myDataList);
secondTimeZoneSort(myDataList);
boolean secondDuplicates = secondCreateSchedule(myDataList, intervalArray);
if(!secondDuplicates){
outPutLogSchedule(myDataList);
}
Log.d("CreateRoot","重複によるエラー");
}
});
}
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);
Log.d("CreateRoot", "(index: " + i + ") timezone: " + myDataList.get(i).getTimezone());
Log.d("CreateRoot", "(index: " + i + ") startDate: " + myDataList.get(i).getStartDateString());
Log.d("CreateRoot", "(index: " + i + ") data: " + myDataList.get(i));
} }
// timezoneを比較するComparatortimezoneが短い順に並べる }
Comparator<MyDataClass> comparator = new Comparator<MyDataClass>() {
@Override //setDataと処理は同じ(第二希望は任意なのでその点だけ確認)
public int compare(MyDataClass data1, MyDataClass data2) { private void secondSetData(List<MyDataClass> myDataList) {
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++) {
// 希望時間帯の終了時刻から開始時刻を引いて希望時間帯の長さ(timezone)に入れる
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);
}
}
}
private void timeZoneSort(List<MyDataClass> myDataList) {
// timezoneを比較するComparatortimezoneが短い順に並べる
Comparator<MyDataClass> comparator = Comparator.comparing(MyDataClass::getTimezone);
// myDataListをtimezoneの値でソート
myDataList.sort(comparator);
}
private void secondTimeZoneSort(List<MyDataClass> myDataList) {
// timezoneを比較するComparatortimezoneが短い順に並べる
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 + ") timezone: " + myDataList.get(i).getTimezone());
Log.d("CreateRoot", "(index: " + i + ") startDate: " + myDataList.get(i).getStartDateString()); Log.d("CreateRoot", "(index: " + i + ") startDate: " + myDataList.get(i).getStartDateString());
Log.d("CreateRoot", "(index: " + i + ") data: " + myDataList.get(i)); Log.d("CreateRoot:outPutLogBeforeSort", "parentStartTimeString: " + myDataList.get(i).getParentStartTimeString());
Log.d("CreateRoot:outPutLogBeforeSort", "parentEndTimeString: " + myDataList.get(i).getParentEndTimeString());
}
}
private void getRoomData() {
// setUpActivityによって入力されRoomに保存された値を取り出す処理
//Roomの操作の定義
SetUpTableDao setUpTableDao = db.setUpTableDao();
startTimeHomeVisit = setUpTableDao.getStartTime();
endTimeHomeVisit = setUpTableDao.getEndTime();
intervalTime = setUpTableDao.getIntervalTime();
startBreakTime = setUpTableDao.getStartBreakTime();
endBreakTime = setUpTableDao.getEndBreakTime();
}
//Roomからのデータ取得に関するログ
void outPutLogRoomData() {
Log.d("CreateRoot:outPutLogRoomData", "開始時間" + startTimeHomeVisit);
Log.d("CreateRoot:outPutLogRoomData", "終了時刻" + endTimeHomeVisit);
Log.d("CreateRoot:outPutLogRoomData", "一家庭当たりの所要時間" + intervalTime);
Log.d("CreateRoot:outPutLogRoomData", "休憩開始時刻" + startBreakTime);
Log.d("CreateRoot:outPutLogRoomData", "休憩終了時刻" + endBreakTime);
}
private void timeCalculation(String endTimeHomeVisit, String startBreakTime, String endBreakTime) {
//家庭訪問の合計時間を計算するため家庭訪問の終了時間から開始時間を引いた数を求めている但し(0,2)によって先に1時間単位の差を求めた後に(2,4)によって分単位の差を求めている
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))));
//家庭訪問の休憩開始時間から家庭訪問の開始時間を引くことで家庭訪問の開始から休憩時間までの分数を計算
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))));
//家庭訪問の休憩終了時間から家庭訪問の終了時間を引くことで休憩の終わりから家庭訪問の終了時間までの分数を計算
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))));
interval = Integer.parseInt(intervalTime) + 10;//移動時間込みの1家庭当たりの所要時間
arraySize = totalTime / interval;//家庭訪問の合計時間から移動時間込みの1家庭当たりの所要時間を割ることで配列の数を求めている
}
private int[][][] homeVisitSchedule() {
//家庭訪問の開始時間からの経過分数を入れる配列
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++) {
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) {
intervalList.add(intervalMinutes);
}
}
int[][][] intervalArray = new int[3][intervalList.size()][2];
for (int i = 0; i < intervalList.size(); i++) {
for(int j=0;j<3;j++) {
intervalArray[j][i][0] = intervalList.get(i);
intervalArray[j][i][1] = 0;//割り当てされていないことを表す
}
} }
ExecutorService executor = Executors.newSingleThreadExecutor(); return intervalArray;
executor.execute(() -> { }
// setUpActivityによって入力されRoomに保存された値を取り出す処理
SetUpTableDao setUpTableDao = db.setUpTableDao();
String startTime = setUpTableDao.getStartTime();
String endTime = setUpTableDao.getEndTime();
String intervalTime = setUpTableDao.getIntervalTime();
String startBreakTime = setUpTableDao.getStartBreakTime();
String 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で割って配列を作る private void outPutLogIntervalArray(int[][][] intervalArray) {
int startHour = Integer.parseInt(startTime.substring(0, 2)); for (int i = 0; i < intervalArray.length; i++) {
int endHour = Integer.parseInt(endTime.substring(0, 2)); for (int j = 0; j < 3; j++) {
int startMinute = Integer.parseInt(startTime.substring(2, 4)); Log.d("CreateRoot:PutLogIntervalArray", "(index:" + i + ") intervalArray:" + intervalArray[j][
int endMinute = Integer.parseInt(endTime.substring(2, 4)); i][0]);
}
}
}
int totalTime = (endHour - startHour) * 60 + (endMinute - startMinute);
int interval = Integer.parseInt(intervalTime) + 10;
arraySize = totalTime / interval;
int startBreakHour = Integer.parseInt(startBreakTime.substring(0, 2)); private Boolean createSchedule(List<MyDataClass> myDataList, int[][][] intervalArray) {
int startBreakMinute = Integer.parseInt(startBreakTime.substring(2, 4));
int endBreakHour = Integer.parseInt(endBreakTime.substring(0, 2));
int endBreakMinute = Integer.parseInt(endBreakTime.substring(2, 4));
int startBreakTimeMinutes = (startBreakHour - startHour) * 60 + (startBreakMinute - startMinute); for (int i = 0; i < myDataList.size(); i++) {
int endBreakTimeMinutes = (endBreakHour - startHour) * 60 + (endBreakMinute - startMinute); for (int j = 0; j < intervalArray.length - 1; j++) {
if (testdata[0].equals(myDataList.get(i).getStartDateString())) {
checkSchedule(myDataList,intervalArray,i,j);
// 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) {
// intervalArray[0][j][1] += 1;//割り当て済みを表す
// 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;
}
} 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++) {
if (myDataList.get(i).getSchedule() == 0) ;
return true;
}
return false;
}
List<Integer> intervalList = new ArrayList<>(); private boolean secondCreateSchedule(List<MyDataClass> myDataList, int[][][] intervalArray) {
for (int i = 0; i < myDataList.size(); i++) {
for (int i = 0; i < arraySize; i++) { for (int j = 0; j < intervalArray.length - 1; j++) {
int intervalMinutes = i * interval; if(testdata[0].equals(myDataList.get(i).getSecondDayStartDateString())) {
if (intervalMinutes < startBreakTimeMinutes || intervalMinutes >= endBreakTimeMinutes) { 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) {
intervalList.add(intervalMinutes); intervalArray[0][j][1] += 1;//割り当て済みを表す
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).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", "第二希望日:日付との紐づけエラー");
} }
} }
int[] intervalArray = new int[intervalList.size()]; }
for (int i = 0; i < intervalList.size(); i++) { for (int i = 0; i < myDataList.size(); i++) {
intervalArray[i] = intervalList.get(i); if (myDataList.get(i).getSchedule() == 0) ;
} return true;
}
// デバッグ用ログ return false;
for (int i = 0; i < intervalArray.length; i++) {
Log.d("CreateRoot", "家庭訪問時間" + intervalArray[i]);
}
});
} }
}
private void checkSchedule(List<MyDataClass> myDataList,int[][][] intervalArray,int i,int j) {
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)
{
intervalArray[x][j][1] += 1;//割り当て済みを表す
myDataList.get(i).setSchedule(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 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());
}
}
}

View File

@ -20,7 +20,7 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{ public class MainActivity extends AppCompatActivity implements View.OnClickListener {
// ID作成のTextViewとImageView // ID作成のTextViewとImageView
private TextView creatUUID; private TextView creatUUID;
@ -81,36 +81,36 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
} }
// クリック処理 // クリック処理
@Override @Override
public void onClick(View view) { public void onClick(View view) {
// ID作成のクリック処理 // ID作成のクリック処理
if(view == creatUUID){ if (view == creatUUID) {
imageUuid.setImageResource(R.drawable.ischecked_uuid); imageUuid.setImageResource(R.drawable.ischecked_uuid);
showUUIDYesNoDialog();//UUIDを表示するかのダイアログ showUUIDYesNoDialog();//UUIDを表示するかのダイアログ
finish(); // 画面遷移後元の状態に戻す finish(); // 画面遷移後元の状態に戻す
} }
if(view == imageUuid){ if (view == imageUuid) {
imageUuid.setImageResource(R.drawable.ischecked_uuid); imageUuid.setImageResource(R.drawable.ischecked_uuid);
showUUIDYesNoDialog();//UUIDを表示するかのダイアログ showUUIDYesNoDialog();//UUIDを表示するかのダイアログ
finish(); finish();
} }
// セットアップのクリック処理 // セットアップのクリック処理
if(view == setUp){ if (view == setUp) {
imageSetup.setImageResource(R.drawable.ischecked_uuid); imageSetup.setImageResource(R.drawable.ischecked_uuid);
Intent toSetup = new Intent(MainActivity.this,SetUpActivity.class); Intent toSetup = new Intent(MainActivity.this, SetUpActivity.class);
startActivity(toSetup); startActivity(toSetup);
finish(); // 画面遷移後元の状態に戻す finish(); // 画面遷移後元の状態に戻す
} }
if (view == imageSetup){ if (view == imageSetup) {
imageSetup.setImageResource(R.drawable.ischecked_uuid); imageSetup.setImageResource(R.drawable.ischecked_uuid);
Intent toSetup = new Intent(MainActivity.this,SetUpActivity.class); Intent toSetup = new Intent(MainActivity.this, SetUpActivity.class);
startActivity(toSetup); startActivity(toSetup);
finish(); // 画面遷移後元の状態に戻す finish(); // 画面遷移後元の状態に戻す
} }
// ルート作成のクリック処理 // ルート作成のクリック処理
if(view == root){ if (view == root) {
imageRoot.setImageResource(R.drawable.pin); imageRoot.setImageResource(R.drawable.pin);
ExecutorService executor = Executors.newSingleThreadExecutor(); ExecutorService executor = Executors.newSingleThreadExecutor();
@ -135,7 +135,18 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
}); });
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); createRoot.receiveData(myDataList);
latch.countDown(); latch.countDown();
@ -155,21 +166,22 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
executor.shutdown(); executor.shutdown();
} }
if(view == imageRoot){ if (view == imageRoot) {
imageRoot.setImageResource(R.drawable.pin); imageRoot.setImageResource(R.drawable.pin);
Intent toRoot = new Intent(MainActivity.this,Maps.class); Intent toRoot = new Intent(MainActivity.this, Maps.class);
startActivity(toRoot); startActivity(toRoot);
} }
// 提出状況のクリック処理 // 提出状況のクリック処理
if(view == submission){ if (view == submission) {
Intent toSubmission = new Intent(MainActivity.this,SubmissionActivity.class); Intent toSubmission = new Intent(MainActivity.this, SubmissionActivity.class);
startActivity(toSubmission); startActivity(toSubmission);
} }
if(view == imageSubmission){ if (view == imageSubmission) {
Intent toSubmission = new Intent(MainActivity.this,SubmissionActivity.class); Intent toSubmission = new Intent(MainActivity.this, SubmissionActivity.class);
startActivity(toSubmission); startActivity(toSubmission);
} }
} }
private void showUUIDYesNoDialog() { private void showUUIDYesNoDialog() {
//ダイアログの表示 //ダイアログの表示
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
@ -188,11 +200,12 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
builder.setNegativeButton("No", new DialogInterface.OnClickListener() { builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
Log.d("DialogNO","DialogでNoが選ばれました"); Log.d("DialogNO", "DialogでNoが選ばれました");
} }
}); });
builder.show(); builder.show();
} }
//ルート作成のダイアログ //ルート作成のダイアログ
private void showRouteCreationDialog(CountDownLatch latch) { private void showRouteCreationDialog(CountDownLatch latch) {
new AlertDialog.Builder(MainActivity.this) new AlertDialog.Builder(MainActivity.this)
@ -212,4 +225,17 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
}) })
.show(); .show();
} }
}
public void showErrorDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("警告");
builder.setMessage("保護者の希望の重複が深刻で、ルート検索が行えません。調整してください。");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.show();
}
}

View File

@ -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,94 @@ 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;
}
} }

View File

@ -39,4 +39,4 @@ public interface SetUpTableDao {
String getStartBreakTime(); String getStartBreakTime();
@Query("SELECT EndBreakTime FROM SetUpTable") @Query("SELECT EndBreakTime FROM SetUpTable")
String getEndBreakTime(); String getEndBreakTime();
} }