Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

달력 하단에 기분 통계 추가 #48

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions PlantingMind/PlantingMind.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
7B2CFC1D2B5A6FFB00641F6D /* CalendarGridView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B2CFC1C2B5A6FFB00641F6D /* CalendarGridView.swift */; };
7B34415D2BA1B87A00DA43F6 /* MonthPickerViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B34415C2BA1B87A00DA43F6 /* MonthPickerViewModel.swift */; };
7B34415F2BA1F85600DA43F6 /* MonthPickerViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B34415E2BA1F85600DA43F6 /* MonthPickerViewModelTests.swift */; };
7B4C07B62BB6B42E00B60CCD /* MoodAnalysisModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B4C07B52BB6B42E00B60CCD /* MoodAnalysisModel.swift */; };
7B4C07B82BB6B6B200B60CCD /* AnalysisView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B4C07B72BB6B6B200B60CCD /* AnalysisView.swift */; };
7B4C07BC2BB6C1F200B60CCD /* AnalysisViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B4C07BB2BB6C1F200B60CCD /* AnalysisViewModelTests.swift */; };
7B4C07BE2BB6C85D00B60CCD /* AnalysisViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B4C07BD2BB6C85D00B60CCD /* AnalysisViewModel.swift */; };
7B571B552B95E5DA0019DEB8 /* MoodRecord+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B571B532B95E5DA0019DEB8 /* MoodRecord+CoreDataClass.swift */; };
7B571B562B95E5DA0019DEB8 /* MoodRecord+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B571B542B95E5DA0019DEB8 /* MoodRecord+CoreDataProperties.swift */; };
7B63CA9E2BA9CB4600943DED /* WidgetKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7B63CA9D2BA9CB4600943DED /* WidgetKit.framework */; };
Expand Down Expand Up @@ -116,6 +120,10 @@
7B2CFC1C2B5A6FFB00641F6D /* CalendarGridView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalendarGridView.swift; sourceTree = "<group>"; };
7B34415C2BA1B87A00DA43F6 /* MonthPickerViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MonthPickerViewModel.swift; sourceTree = "<group>"; };
7B34415E2BA1F85600DA43F6 /* MonthPickerViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MonthPickerViewModelTests.swift; sourceTree = "<group>"; };
7B4C07B52BB6B42E00B60CCD /* MoodAnalysisModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoodAnalysisModel.swift; sourceTree = "<group>"; };
7B4C07B72BB6B6B200B60CCD /* AnalysisView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalysisView.swift; sourceTree = "<group>"; };
7B4C07BB2BB6C1F200B60CCD /* AnalysisViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalysisViewModelTests.swift; sourceTree = "<group>"; };
7B4C07BD2BB6C85D00B60CCD /* AnalysisViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalysisViewModel.swift; sourceTree = "<group>"; };
7B571B532B95E5DA0019DEB8 /* MoodRecord+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MoodRecord+CoreDataClass.swift"; sourceTree = "<group>"; };
7B571B542B95E5DA0019DEB8 /* MoodRecord+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MoodRecord+CoreDataProperties.swift"; sourceTree = "<group>"; };
7B63CA9B2BA9CB4600943DED /* PlantingWidgetExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = PlantingWidgetExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -272,6 +280,7 @@
7B907F742B9997060050D05B /* DayCellViewModelTest.swift */,
7B907F772B9B4CCE0050D05B /* FetchNotificationSpy.swift */,
7B34415E2BA1F85600DA43F6 /* MonthPickerViewModelTests.swift */,
7B4C07BB2BB6C1F200B60CCD /* AnalysisViewModelTests.swift */,
);
path = PlantingMindTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -303,6 +312,16 @@
path = Picker;
sourceTree = "<group>";
};
7B4C07B02BB6A4DD00B60CCD /* Analysis */ = {
isa = PBXGroup;
children = (
7B4C07B52BB6B42E00B60CCD /* MoodAnalysisModel.swift */,
7B4C07B72BB6B6B200B60CCD /* AnalysisView.swift */,
7B4C07BD2BB6C85D00B60CCD /* AnalysisViewModel.swift */,
);
path = Analysis;
sourceTree = "<group>";
};
7B63CA9C2BA9CB4600943DED /* Frameworks */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -341,6 +360,7 @@
7B2CFC1C2B5A6FFB00641F6D /* CalendarGridView.swift */,
7B3441582BA1903300DA43F6 /* Day */,
7B3441592BA190AE00DA43F6 /* Picker */,
7B4C07B02BB6A4DD00B60CCD /* Analysis */,
);
path = Calender;
sourceTree = "<group>";
Expand Down Expand Up @@ -520,8 +540,10 @@
7B0A76D12B906FE100ADC039 /* CoreDataStack.swift in Sources */,
7B907F7C2B9C6F1B0050D05B /* DateExtension.swift in Sources */,
7B02AD622BA0222900D5C850 /* MonthPickerView.swift in Sources */,
7B4C07B62BB6B42E00B60CCD /* MoodAnalysisModel.swift in Sources */,
7BABB0112B5F850200EEEEBB /* ColorExtension.swift in Sources */,
7B0A77112B93196D00ADC039 /* MoodRecordViewModel.swift in Sources */,
7B4C07B82BB6B6B200B60CCD /* AnalysisView.swift in Sources */,
7B0A76CE2B904A1200ADC039 /* MoodRecords.xcdatamodeld in Sources */,
7BC300F52B5E4CE100059068 /* CalendarView.swift in Sources */,
7B2CFC1D2B5A6FFB00641F6D /* CalendarGridView.swift in Sources */,
Expand All @@ -531,6 +553,7 @@
7BAB04F42B9466BC00948CF2 /* Mood.swift in Sources */,
7B2CFC1B2B5A6DE900641F6D /* DayCellView.swift in Sources */,
7BDA3CD72B58F25F006D74FB /* CalendarHeaderView.swift in Sources */,
7B4C07BE2BB6C85D00B60CCD /* AnalysisViewModel.swift in Sources */,
7B907F732B9981E90050D05B /* DayCellViewModel.swift in Sources */,
7B571B552B95E5DA0019DEB8 /* MoodRecord+CoreDataClass.swift in Sources */,
7B11F8282B4549DF00346A41 /* PlantingMindApp.swift in Sources */,
Expand All @@ -543,6 +566,7 @@
files = (
7BAB04F62B946B8700948CF2 /* MoodRecordViewModelTests.swift in Sources */,
7B34415F2BA1F85600DA43F6 /* MonthPickerViewModelTests.swift in Sources */,
7B4C07BC2BB6C1F200B60CCD /* AnalysisViewModelTests.swift in Sources */,
7B907F782B9B4CCE0050D05B /* FetchNotificationSpy.swift in Sources */,
7B907F752B9997060050D05B /* DayCellViewModelTest.swift in Sources */,
7BC300F92B5E5F8E00059068 /* CalendarViewModelTests.swift in Sources */,
Expand Down
46 changes: 46 additions & 0 deletions PlantingMind/PlantingMind/Calender/Analysis/AnalysisView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// AnalysisView.swift
// PlantingMind
//
// Created by 최은주 on 3/29/24.
//

import SwiftUI
import Charts

struct AnalysisView: View {
var viewModel: AnalysisViewModel

var body: some View {
if viewModel.recordsCount == 0 {
Text("mood_statistics_empty")
.multilineTextAlignment(.center)
.font(.title3)
.bold()
.padding()
} else {
Text("mood_statistics")
.font(.title3)
.bold()
.padding([.top, .horizontal])

Chart(viewModel.moodAnalysis, id: \.self) {
BarMark(x: .value("Count", $0.count))
.foregroundStyle(by: .value("Category", $0.mood))
}
.chartForegroundStyleScale([
"nice": Mood.nice.color,
"good": Mood.good.color,
"normal": Mood.normal.color,
"notBad": Mood.notBad.color,
"bad": Mood.bad.color
])
.frame(height: 60)
.padding()
}
}
}

#Preview {
AnalysisView(viewModel: AnalysisViewModel(moods: []))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// AnalysisViewModel.swift
// PlantingMind
//
// Created by 최은주 on 3/29/24.
//

import Foundation

struct AnalysisViewModel {
let moodAnalysis: [MoodAnalysis]

var recordsCount: Int {
moodAnalysis.map { $0.count }.reduce(0,+)
}

init(moods: [MoodRecord]) {
var result: [MoodAnalysis] = []
for mood in Mood.allCases {
let count = moods.filter { $0.mood == mood.rawValue }.count
result.append(MoodAnalysis(mood: mood.rawValue, count: count))
}

self.moodAnalysis = result
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// MoodAnalysisModel.swift
// PlantingMind
//
// Created by 최은주 on 3/29/24.
//

import Foundation

struct MoodAnalysis: Hashable {
let mood: String
let count: Int
}
14 changes: 10 additions & 4 deletions PlantingMind/PlantingMind/Calender/CalendarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ struct CalendarView: View {
@StateObject var calendarViewModel: CalendarViewModel

var body: some View {
VStack {
CalendarHeaderView()
CalendarGridView()
Spacer()
ScrollView {
VStack() {
CalendarHeaderView()
CalendarGridView()
Divider()
.overlay(Color.Custom.line)

AnalysisView(viewModel: AnalysisViewModel(moods: calendarViewModel.moods))
Spacer()
}
}
.environmentObject(calendarViewModel)
.onChange(of: phase) { newValue in
Expand Down
2 changes: 1 addition & 1 deletion PlantingMind/PlantingMind/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct ContentView: View {
VStack {
CalendarView(calendarViewModel: CalendarViewModel(today: Date(), context: context))
}
.padding()
.padding([.horizontal, .top])
}
}

Expand Down
48 changes: 35 additions & 13 deletions PlantingMind/PlantingMind/Localization/Localizable.xcstrings
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
{
"sourceLanguage" : "en",
"strings" : {
"" : {

},
" - " : {

},
"%@" : {

},
"%lld" : {

},
"app_title" : {
"extractionState" : "manual",
"localizations" : {
Expand Down Expand Up @@ -148,6 +136,40 @@
}
}
},
"mood_statistics" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Mood Statistics"
}
},
"ko" : {
"stringUnit" : {
"state" : "translated",
"value" : "마음 현황"
}
}
}
},
"mood_statistics_empty" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "There are no mood records."
}
},
"ko" : {
"stringUnit" : {
"state" : "translated",
"value" : "이달에는 심어둔 마음이 없어요.\n마음 현황을 확인하려면\n기록을 추가해보세요."
}
}
}
},
"mood_title" : {
"extractionState" : "manual",
"localizations" : {
Expand Down Expand Up @@ -303,4 +325,4 @@
}
},
"version" : "1.0"
}
}
38 changes: 38 additions & 0 deletions PlantingMind/PlantingMindTests/AnalysisViewModelTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// AnalysisViewModelTests.swift
// PlantingMindTests
//
// Created by 최은주 on 3/29/24.
//

import XCTest
@testable import PlantingMind

final class AnalysisViewModelTests: XCTestCase {
var viewModel: AnalysisViewModel!

override func setUpWithError() throws {
let context = CoreDataStack(.inMemory).persistentContainer.viewContext

let record1 = MoodRecord(context: context)
record1.mood = Mood.nice.rawValue

let record2 = MoodRecord(context: context)
record2.mood = Mood.bad.rawValue

var records: [MoodRecord] = [record1, record2]

viewModel = AnalysisViewModel(moods: records)
}

func test_MoodRecord_to_MoodAnalysis_변환_체크() throws {
let expectedCount = [1, 0, 0, 0, 1]
let result = viewModel.moodAnalysis.map { $0.count }

XCTAssertEqual(expectedCount, result)
}

func test_전체_기록_카운트() {
XCTAssertEqual(viewModel.recordsCount, 2)
}
}
Loading