forked from kookmin-sw/cap-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Milestone/#3
- Loading branch information
Showing
124 changed files
with
3,385 additions
and
826 deletions.
There are no files selected for viewing
67 changes: 66 additions & 1 deletion
67
...-android/app/src/main/java/com/capstone/android/application/presentation/TestViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,69 @@ | ||
package com.capstone.android.application.presentation | ||
|
||
import android.util.Log | ||
import androidx.compose.runtime.State | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.launch | ||
import kotlin.math.max | ||
|
||
class TestViewModel { | ||
} | ||
} | ||
|
||
|
||
class CountViewModel : ViewModel(){ | ||
|
||
val time = 180*1000L | ||
private val _timeLeft = MutableStateFlow(time) // 3분을 초 단위로 초기화 | ||
val timeLeft = _timeLeft.asStateFlow() | ||
|
||
private var countdownJob: Job? = null | ||
|
||
private var startTime = 0L // 카운트다운 시작 시간 (밀리초 단위) | ||
|
||
fun startCountdown() { | ||
if (countdownJob == null) { | ||
startTime = System.currentTimeMillis() // 현재 시간을 시작 시간으로 저장 | ||
countdownJob = viewModelScope.launch { | ||
while (true) { | ||
val elapsedTime = System.currentTimeMillis() - startTime | ||
val remainingTime = max(0, time - elapsedTime) | ||
_timeLeft.value = remainingTime | ||
Log.d("remainingTime", "startCountdown: $remainingTime") | ||
delay(1000) // 1초마다 업데이트 | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun restartCountdown() { | ||
countdownJob?.cancel() // 기존의 카운트다운을 취소 | ||
_timeLeft.value = time // 시간을 다시 초기값으로 설정 | ||
updateCountdown() // 카운트다운 다시 시작 | ||
} | ||
|
||
fun updateCountdown() { | ||
countdownJob?.cancel() // 이미 진행 중인 카운트다운을 취소 | ||
startTime = System.currentTimeMillis() // 현재 시간을 시작 시간으로 저장 | ||
countdownJob = viewModelScope.launch { | ||
while (true) { | ||
val currentTime = System.currentTimeMillis() | ||
val elapsedTime = currentTime - startTime | ||
val remainingTime = max(0, time - elapsedTime) | ||
_timeLeft.value = remainingTime | ||
delay(1000) // 1초마다 업데이트 | ||
|
||
} | ||
} | ||
} | ||
override fun onCleared() { | ||
super.onCleared() | ||
countdownJob?.cancel() // ViewModel이 제거될 때 카운트다운을 중지 | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+632 Bytes
Android/moment-android/app/src/main/res/drawable-hdpi/img_alarm_grey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+532 Bytes
Android/moment-android/app/src/main/res/drawable-hdpi/img_alarmup_grey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+795 Bytes
Android/moment-android/app/src/main/res/drawable-xhdpi/img_alarm_grey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+659 Bytes
Android/moment-android/app/src/main/res/drawable-xhdpi/img_alarmup_grey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.24 KB
Android/moment-android/app/src/main/res/drawable-xxhdpi/img_alarm_grey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+977 Bytes
Android/moment-android/app/src/main/res/drawable-xxhdpi/img_alarmup_grey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.24 KB
Android/moment-android/app/src/main/res/drawable-xxxhdpi/img_alarm_grey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.31 KB
Android/moment-android/app/src/main/res/drawable-xxxhdpi/img_alarmup_grey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+420 Bytes
Android/moment-android/app/src/main/res/drawable/img_alarm_grey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+378 Bytes
Android/moment-android/app/src/main/res/drawable/img_alarmup_grey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import os | ||
import pandas as pd | ||
import torchaudio | ||
from torch.utils.data import Dataset, DataLoader | ||
from sklearn.model_selection import train_test_split | ||
|
||
|
||
|
||
class CustomDataset(Dataset): | ||
def __init__(self, csv_file): | ||
self.data = pd.read_csv(csv_file) | ||
|
||
def __len__(self): | ||
return len(self.data) | ||
|
||
def __getitem__(self, idx): | ||
file_name = self.data.iloc[idx]['path'] | ||
label = self.data.iloc[idx]['labels'] | ||
|
||
if os.path.splitext(file_name)[-1] == '.wav': | ||
feat = None | ||
|
||
elif os.path.splitext(file_name)[-1] == '.npy': | ||
feat = None | ||
|
||
return feat, label | ||
|
||
|
||
if __name__ == '__main__': | ||
# CSV 파일 경로 및 오디오 파일이 있는 루트 디렉토리 경로 | ||
csv_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'datas/TESS.csv') | ||
|
||
# 데이터셋 객체 생성 | ||
dataset = CustomDataset(csv_file) | ||
|
||
# 데이터셋 분할 | ||
train_dataset, test_dataset = train_test_split(dataset, test_size=0.2, random_state=42) | ||
train_dataset, val_dataset = train_test_split(train_dataset, test_size=0.1, random_state=42) | ||
|
||
# 데이터로더 생성 | ||
batch_size = 2 | ||
train_dataloader = DataLoader(train_dataset, batch_size=batch_size, shuffle=True) | ||
val_dataloader = DataLoader(val_dataset, batch_size=batch_size, shuffle=False) | ||
test_dataloader = DataLoader(test_dataset, batch_size=batch_size, shuffle=False) | ||
|
||
for batch in train_dataloader: | ||
print(batch) | ||
break |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.