Skip to content

Commit

Permalink
Merge pull request #57 from kookmin-sw/milestone/#3
Browse files Browse the repository at this point in the history
Milestone/#3
  • Loading branch information
J-Yong99 authored Apr 5, 2024
2 parents c53f82d + 9014bfe commit 2a192e6
Show file tree
Hide file tree
Showing 124 changed files with 3,385 additions and 826 deletions.
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이 제거될 때 카운트다운을 중지
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package com.capstone.android.application.ui
import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
Expand All @@ -13,7 +15,6 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
Expand All @@ -26,43 +27,47 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Divider
import androidx.compose.material.Tab
import androidx.compose.material.TabRowDefaults
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.material.TabRow
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.SheetState
import androidx.compose.material3.Text
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.core.graphics.toColorInt
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.capstone.android.application.MainActivity
import com.capstone.android.application.R
import com.capstone.android.application.app.composable.MomentTextField
import com.capstone.android.application.presentation.CountViewModel
import com.capstone.android.application.ui.theme.BackButton_Onboarding
import com.capstone.android.application.ui.theme.BigButton
import com.capstone.android.application.ui.theme.CheckButton
import com.capstone.android.application.ui.theme.CountText
import com.capstone.android.application.ui.theme.P_Bold30
import com.capstone.android.application.ui.theme.P_ExtraBold16
import com.capstone.android.application.ui.theme.P_Medium11
Expand All @@ -76,11 +81,10 @@ import com.capstone.android.application.ui.theme.neutral_600
import com.capstone.android.application.ui.theme.primary_500
import com.capstone.android.application.ui.theme.tertiary_500
import com.capstone.android.application.ui.theme.white
import com.google.accompanist.pager.ExperimentalPagerApi
import com.google.accompanist.pager.HorizontalPager
import com.google.accompanist.pager.pagerTabIndicatorOffset
import com.google.accompanist.pager.rememberPagerState
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

enum class OnboardingScreen(){
Login,
Expand All @@ -102,6 +106,7 @@ class OnboardingActivity:ComponentActivity() {

setContent{
navController = rememberNavController()

Scaffold(
modifier = Modifier.fillMaxSize(),
topBar = {
Expand All @@ -114,7 +119,7 @@ class OnboardingActivity:ComponentActivity() {
){
composable(route=OnboardingScreen.Login.name){ Login() }
composable(route=OnboardingScreen.LoginComplete.name){ LoginComplete()}
composable(route=OnboardingScreen.Signup_email.name){ Signup_email() }
composable(route=OnboardingScreen.Signup_email.name){ Signup_email() }
composable(route=OnboardingScreen.Signup_number.name){ Signup_number() }
composable(route=OnboardingScreen.Signup.name){ Signup() }
composable(route=OnboardingScreen.FindPassword.name){ FindPassword() }
Expand Down Expand Up @@ -531,20 +536,24 @@ class OnboardingActivity:ComponentActivity() {


@Composable
fun Signup_number(){
val number = remember{
mutableStateOf("")
}
fun Signup_number(countViewModel: CountViewModel = viewModel()){

var signnumState = remember {
mutableStateOf(true)
}
val timeLeft by countViewModel.timeLeft.collectAsState()
val number = remember{mutableStateOf("")}
var signnumState = remember {mutableStateOf(true)}
val focusRequester = remember { FocusRequester() }
val focusManager = LocalFocusManager.current

LaunchedEffect(Unit) {
focusRequester.requestFocus()
}
DisposableEffect(Unit) {
countViewModel.startCountdown() // 카운트다운 시작
onDispose {
// DisposableEffect가 해제될 때 카운트다운을 중지하거나 정리할 필요 없음
}
}

Box(modifier = Modifier
.fillMaxSize()
.background(color = tertiary_500)
Expand Down Expand Up @@ -587,13 +596,13 @@ class OnboardingActivity:ComponentActivity() {
.padding(top = 344.dp)
) {
Row(
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier
.padding(horizontal = 8.dp),
horizontalArrangement = Arrangement.Absolute.SpaceBetween
.fillMaxWidth()
.padding(horizontal = 8.dp)
) {
Column {
P_Medium11("인증번호", if(signnumState.value) black else negative_600)
}
P_Medium11("인증번호", if(signnumState.value) black else negative_600)
CountText(timeLeft)
}
Spacer(modifier = Modifier.height(4.dp))
MomentTextField(
Expand Down Expand Up @@ -631,7 +640,7 @@ class OnboardingActivity:ComponentActivity() {
Row(modifier = Modifier
.width(86.dp)
.align(Alignment.End)
.clickable { /*인증번호 재전송 기능*/ }) {
.clickable { countViewModel.restartCountdown() }) {
Column {
Column(modifier = Modifier
.padding(horizontal = 8.dp)) {
Expand Down Expand Up @@ -1229,6 +1238,6 @@ class OnboardingActivity:ComponentActivity() {
@Preview
@Composable
fun OnboardingPreView(){
LoginComplete()
Signup_number()
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package com.capstone.android.application.ui.theme


import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp


Expand Down Expand Up @@ -114,6 +110,22 @@ fun HintText(content : String){
)
}

@Composable
fun CountText(timeLeft: Long){

val min = (timeLeft / 1000) / 60
val sec = (timeLeft / 1000) % 60

Text(
text = String.format("%02d:%02d", min, sec),
style = TextStyle(
color = neutral_600,
fontFamily = PretendardFamily,
fontWeight = FontWeight.Medium,
fontSize = 11.sp)
)
}

@Preview(apiLevel = 33)
@Composable
fun TextPreview() {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion backend/ai/moment-ai/ai_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def ai_server_health():

@app.route('/ai/run', methods=['POST'])
def ai_server_run():
file_name = request.args.get('file_name')
file_name = request.json.get('file_name') # 요청의 JSON 본문에서 'file_name' 가져오기
file_path = request.json.get('file_path') # 요청의 JSON 본문에서 'file_path' 가져오기
if file_name is None:
return jsonify({"error": "'file_name' parameter is missing."}), 400

Expand Down
48 changes: 48 additions & 0 deletions backend/ai/moment-ai/emotion2vec/utils.py
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
1 change: 0 additions & 1 deletion backend/ai/moment-ai/kaggle.json

This file was deleted.

Loading

0 comments on commit 2a192e6

Please sign in to comment.