murakumo_UUIDを何とかするの会 #21

Merged
murakumo merged 3 commits from murakumo_UUIDを何とかするの会 into master 2024-06-28 02:02:01 +00:00
7 changed files with 470 additions and 93 deletions
Showing only changes of commit 1da1217bda - Show all commits

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,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);
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);
}
} }
ExecutorService executor = Executors.newSingleThreadExecutor();
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で割って配列を作る int[][][] intervalArray = new int[3][intervalList.size()][2];
int startHour = Integer.parseInt(startTime.substring(0, 2)); for (int i = 0; i < intervalList.size(); i++) {
int endHour = Integer.parseInt(endTime.substring(0, 2)); for (int j = 0; j < 3; j++) {
int startMinute = Integer.parseInt(startTime.substring(2, 4)); intervalArray[j][i][0] = intervalList.get(i);
int endMinute = Integer.parseInt(endTime.substring(2, 4)); intervalArray[j][i][1] = 0;//割り当てされていないことを表す
}
}
int totalTime = (endHour - startHour) * 60 + (endMinute - startMinute); return intervalArray;
int interval = Integer.parseInt(intervalTime) + 10; }
arraySize = totalTime / interval;
int startBreakHour = Integer.parseInt(startBreakTime.substring(0, 2)); private void outPutLogIntervalArray(int[][][] intervalArray) {
int startBreakMinute = Integer.parseInt(startBreakTime.substring(2, 4)); for (int i = 0; i < intervalArray[0].length; i++) {
int endBreakHour = Integer.parseInt(endBreakTime.substring(0, 2)); Log.d("CreateRoot", "inteintervalArray:(intex:" + i + ") :" + intervalArray[0][i][0]);
int endBreakMinute = Integer.parseInt(endBreakTime.substring(2, 4)); }
}
int startBreakTimeMinutes = (startBreakHour - startHour) * 60 + (startBreakMinute - startMinute);
int endBreakTimeMinutes = (endBreakHour - startHour) * 60 + (endBreakMinute - startMinute);
List<Integer> intervalList = new ArrayList<>(); private Boolean createSchedule(List<MyDataClass> myDataList, int[][][] intervalArray) {
for (int i = 0; i < arraySize; i++) { for (int i = 0; i < myDataList.size(); i++) {
int intervalMinutes = i * interval; for (int j = 0; j < intervalArray[0].length - 1; j++) {
if (intervalMinutes < startBreakTimeMinutes || intervalMinutes >= endBreakTimeMinutes) { for (int x = 0; x < 3; x++) {
intervalList.add(intervalMinutes); 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;
}
} }
} }
int[] intervalArray = new int[intervalList.size()]; }
for (int i = 0; i < intervalList.size(); i++) {
intervalArray[i] = intervalList.get(i);
}
// デバッグ用ログ for (int i = 0; i < myDataList.size(); i++) {
for (int i = 0; i < intervalArray.length; i++) { if (myDataList.get(i).getSchedule() == 0) ;
Log.d("CreateRoot", "家庭訪問時間" + intervalArray[i]); 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());
}
}
}

View File

@ -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;
@ -24,7 +23,7 @@ public class FirestoreReception {
} }
//firestoreから受け取ったデータを束ねるためのマップ //firestoreから受け取ったデータを束ねるためのマップ
public List<MyDataClass>myDataList = new ArrayList<>(); public List<MyDataClass> myDataList = new ArrayList<>();
//ClassIdを引数にデータの作成を行う //ClassIdを引数にデータの作成を行う
public void getDocumentsByClassId(int classId) { public void getDocumentsByClassId(int classId) {
@ -61,7 +60,7 @@ public class FirestoreReception {
//取得したデータをログ表示 //取得したデータをログ表示
for(MyDataClass data :myDataList){ for (MyDataClass data : myDataList) {
Log.i("FirestoreReceptiond", "data: " + data.toString()); Log.i("FirestoreReceptiond", "data: " + data.toString());
} }
} else { } else {
@ -72,12 +71,14 @@ 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;
} }
} }

View File

@ -34,7 +34,7 @@ public class GeoCoder {
Log.d("FirestoreReception", "firstDay: " + firstDay.get(0)); Log.d("FirestoreReception", "firstDay: " + firstDay.get(0));
Log.d("FirestoreReception", "firstDay: " + firstDay.get(1)); Log.d("FirestoreReception", "firstDay: " + firstDay.get(1));
Log.d("FirestoreReception", "studentNumber: " + studentNumber); Log.d("FirestoreReception", "studentNumber: " + studentNumber);
Log.d("FirestoreReception", "latLng: "+latLng ); Log.d("FirestoreReception", "latLng: " + latLng);
} catch (NullPointerException e) { } catch (NullPointerException e) {
Log.e("NullPointerException", "getの中身がnull" + e); Log.e("NullPointerException", "getの中身がnull" + e);

View File

@ -21,7 +21,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 {
// ダイアログの宣言 // ダイアログの宣言
private AlertDialog alertDialog; private AlertDialog alertDialog;
@ -84,8 +84,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
db = FirebaseFirestore.getInstance(); db = FirebaseFirestore.getInstance();
firestoreReception = new FirestoreReception(); firestoreReception = new FirestoreReception();
//TODO:3.classIdをmainアクティビティで取得する手段を作る
//4.以上のことを実装するためにユーザーにid作成setupをすることを促すような制限をかける
if(classId!=100000){ if(classId!=100000){
firestoreReception.getDocumentsByClassId(classId); firestoreReception.getDocumentsByClassId(classId);
} }
@ -120,7 +118,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
} }
// ルート作成のクリック処理 // ルート作成のクリック処理
if(view == root){ if (view == root) {
imageRoot.setImageResource(R.drawable.pin); imageRoot.setImageResource(R.drawable.pin);
fetchDataAndCreateRoute(); fetchDataAndCreateRoute();
@ -136,7 +134,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
toSubmission.putParcelableArrayListExtra("submissionStudents", submissionStudents); toSubmission.putParcelableArrayListExtra("submissionStudents", submissionStudents);
startActivity(toSubmission); startActivity(toSubmission);
} }
if(view == imageSubmission){ if (view == imageSubmission) {
ArrayList<SubmissionStudent> submissionStudents = getSubmissionStudents(); ArrayList<SubmissionStudent> submissionStudents = getSubmissionStudents();
Intent toSubmission = new Intent(MainActivity.this, SubmissionActivity.class); Intent toSubmission = new Intent(MainActivity.this, SubmissionActivity.class);
toSubmission.putParcelableArrayListExtra("submissionStudents", submissionStudents); toSubmission.putParcelableArrayListExtra("submissionStudents", submissionStudents);
@ -158,8 +156,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() {
@ -173,6 +169,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
alertDialog.show(); alertDialog.show();
} }
//ルート作成の非同期処理 //ルート作成の非同期処理
private void fetchDataAndCreateRoute() { private void fetchDataAndCreateRoute() {
//非同期処理の開始 //非同期処理の開始
@ -201,10 +198,26 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
// タスク2: Firestoreからデータを取得 // タスク2: Firestoreからデータを取得
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(() -> {
@ -221,6 +234,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)
@ -241,6 +255,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<>();

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

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();
} }