Refactoring everything

This commit is contained in:
Ivan Bushchik 2022-01-18 20:23:35 +03:00
parent 852092ae8e
commit d192d6e334
5 changed files with 108 additions and 186 deletions

View file

@ -7,14 +7,12 @@
objects = {
/* Begin PBXBuildFile section */
4F7E91CD279615A200CB18B7 /* SubjectView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F7E91CC279615A200CB18B7 /* SubjectView.swift */; };
4FEB3F0F2795DFE90005C604 /* GradeMapperApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FEB3EFF2795DFE80005C604 /* GradeMapperApp.swift */; };
4FEB3F112795DFE90005C604 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FEB3F002795DFE80005C604 /* ContentView.swift */; };
4FEB3F132795DFE90005C604 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4FEB3F012795DFE90005C604 /* Assets.xcassets */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
4F7E91CC279615A200CB18B7 /* SubjectView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubjectView.swift; sourceTree = "<group>"; };
4FD40DBC279702A900A5A6D2 /* GradeMapper (iOS).entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "GradeMapper (iOS).entitlements"; sourceTree = "<group>"; };
4FEB3EFF2795DFE80005C604 /* GradeMapperApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GradeMapperApp.swift; sourceTree = "<group>"; };
4FEB3F002795DFE80005C604 /* ContentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
@ -50,7 +48,6 @@
4FEB3EFF2795DFE80005C604 /* GradeMapperApp.swift */,
4FEB3F002795DFE80005C604 /* ContentView.swift */,
4FEB3F012795DFE90005C604 /* Assets.xcassets */,
4F7E91CC279615A200CB18B7 /* SubjectView.swift */,
);
path = Shared;
sourceTree = "<group>";
@ -141,7 +138,6 @@
buildActionMask = 2147483647;
files = (
4FEB3F112795DFE90005C604 /* ContentView.swift in Sources */,
4F7E91CD279615A200CB18B7 /* SubjectView.swift in Sources */,
4FEB3F0F2795DFE90005C604 /* GradeMapperApp.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -269,6 +265,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = F5PQ7AR4DP;
"ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
@ -289,7 +286,7 @@
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TARGETED_DEVICE_FAMILY = "1,2,6";
};
name = Debug;
};
@ -302,6 +299,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = F5PQ7AR4DP;
"ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
@ -322,7 +320,7 @@
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TARGETED_DEVICE_FAMILY = "1,2,6";
VALIDATE_PRODUCT = YES;
};
name = Release;

View file

@ -3,4 +3,22 @@
uuid = "1FA12096-94D4-4153-9D70-423E3C4922F7"
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "DB7E51B9-F3B0-41A1-892B-99BA9E5AF18A"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Shared/ContentView.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "16"
endingLineNumber = "16"
landmarkName = "Grade"
landmarkType = "13">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>

View file

@ -1,36 +1,71 @@
//
// ContentView.swift
// Shared
// SubjectView.swift
// GradeMapper
//
// Created by Иван Бущик on 17.01.2022.
// Created by Иван Бущик on 18.01.2022.
//
import SwiftUI
enum Grade: Int, Identifiable, CaseIterable{
case One = 1
case Two = 2
case Three = 3
case Four = 4
case Five = 5
struct ContentView: View{
var body: some View {
VStack(alignment: .center) {
Text("GradeMapper")
.font(.largeTitle)
.fontWeight(.heavy)
.multilineTextAlignment(.center)
NavigationView {
List{
ForEach(subjectsNames, id: \.self) {
subjectName in NavigationLink("\(subjectName)", destination: SubjectView(name: subjectName))
}
}
}
}.padding([.leading, .top], 5.0)
}
var id: Int { self.rawValue }
}
struct ContentView: View {
var counter = counters()
@State var sr: Double = 0
@State private var selectedGrade = Grade.One
@State var selectedTypeOfGrade = "Контрольная работа"
var body: some View {
Text("GradeMapper")
.font(.largeTitle)
.fontWeight(.heavy)
.multilineTextAlignment(.center)
.padding(.top, -75)
VStack(alignment: .center, spacing: 75){
VStack(alignment: .leading, spacing: 30){
Picker("Тип оценки", selection: $selectedTypeOfGrade){
ForEach([String](coof.keys), id: \.self) {
subjectSN in Text("\(subjectSN)")
}
}.pickerStyle(.wheel)
VStack{
Picker("Оценка", selection: $selectedGrade){
ForEach(Grade.allCases, id: \.self) {
currGrade in Text("\(currGrade.rawValue)")
}
}
}.pickerStyle(.segmented).padding(.horizontal, 20)
}.padding(.top, 100)
Button ("Добавить оценку"){
counter.multiplier = coof[selectedTypeOfGrade]!
counter.gradesWeighted += Double(selectedGrade.rawValue) * counter.multiplier
counter.weightsSum += counter.multiplier
self.sr = (counter.gradesWeighted / counter.weightsSum)
}.buttonStyle(.borderedProminent)
Text(String("Средний балл: \(self.sr)"))
.fontWeight(.bold)
Button ("Очистить"){
counter.multiplier = 1.5
counter.gradesWeighted = 0
counter.weightsSum = 0
self.sr = 0
}.buttonStyle(.borderedProminent)
}
.padding(.top, -155.0)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
static var previews: some View {
ContentView()
}
}

View file

@ -7,39 +7,17 @@
import SwiftUI
class helpMe{
class counters{
var multiplier: Double
var subjectName: String
var subjectSubName: String
var grade: Int
var sum: Double
var sr: Double
var gradesWeighted: Double = 0
var weightsSum: Double = 0
var history: [Int]
init(){
self.multiplier = 1.5
self.subjectName = "Русский язык"
self.subjectSubName = "Контрольная работа"
self.multiplier = 1.0
self.gradesWeighted = 0
self.weightsSum = 0
self.sr = 0
self.sum = 0
self.grade = 0
self.history = []
}
func set(n1: String, n2: String) -> Void{
self.multiplier = subjects[n1]![n2]!
self.subjectName = n1
self.subjectSubName = n2
}
func setGrade(grade: Int){
self.grade = grade
}
}
@main
struct GradeMapperApp: App {
var body: some Scene {
@ -49,69 +27,29 @@ struct GradeMapperApp: App {
}
}
var subjects: [String : [String : Double]] = [
"Русский язык": [
"Контрольная работа": 1.5,
"Контрольный диктант": 1.5,
"Административная контрольная работа": 1.5,
"Словарный диктант": 1.4,
"Домашнее сочинение": 1.4,
"Изложение": 1.4,
"Проверочная работа": 1.3,
"Самостоятельная работа": 1.2,
"Работа на уроке": 1.0,
"Тест": 1.0,
"Сочинение": 1.0,
"Домашняя работа": 1.0
], "Литература": [
"Контрольная работа": 1.5,
"Классное сочинение": 1.5,
"Домашнее сочинение": 1.4,
"Проверочная работа": 1.3,
"Самостоятельная работа": 1.2,
"Работа на уроке": 1.0,
"Тест": 1.0,
"Сочинение": 1.0,
"Домашняя работа": 1.0
], "Алгебрa": [
"Контрольная работа": 1.5,
"Административная контрольная работа": 1.5,
"Контрольная практическая работа": 1.5,
"Зачёт": 1.5,
"Проверочная работа": 1.3,
"Самостоятельная работа": 1.2,
"Работа на уроке": 1.0,
"Домашняя работа": 1.0
], "Геометрия": [
"Контрольная работа": 1.5,
"Административная контрольная работа": 1.5,
"Контрольная практическая работа": 1.5,
"Зачёт": 1.5,
"Проверочная работа": 1.3,
"Практическая работа": 1.3,
"Самостоятельная работа": 1.2,
"Работа на уроке": 1.0,
"Домашняя работа": 1.0
], "Физика": [
"Контрольная работа": 1.5,
"Зачёт": 1.5,
"Проверочная работа": 1.3,
"Практическая работа": 1.3,
"Срезовая работа": 1.3,
"Лабораторная работа": 1.3,
"Самостоятельная работа": 1.2,
"Работа на уроке": 1.0,
"Тест": 1.0,
"Домашняя работа": 1.0
], "Информатика": [
"Контрольная работа": 1.5,
"Зачёт": 1.5,
"Проверочная работа": 1.3,
"Практическая работа": 1.3,
"Самостоятельная работа": 1.2,
"Работа на уроке": 1.0,
"Домашняя работа": 1.0
]
var coof = [
"Работа на уроке": 1.0,
"Тест": 1.0,
"Чтение наизусть": 1.0,
"Сочинение": 1.0,
"Дистанционный урок": 1.0,
"Электронное обучение": 1.0,
"Ведение тетради": 1.0,
"Викторина": 1.0,
"Работа над ошибками": 1.0,
"Самостоятельная работа": 1.2,
"Проверочная работа": 1.3,
"Практическая работа": 1.3,
"Лабораторная работа": 1.3,
"Срезовая работа": 1.3,
"Словарный диктант": 1.4,
"Домашнее сочинение": 1.4,
"Аудирование": 1.4,
"Изложение": 1.4,
"Контрольная работа": 1.5,
"Контрольный диктант": 1.5,
"Контрольная практическая работа": 1.5,
"Административная к.р.": 1.5,
"Зачёт": 1.5,
"Классное сочинение": 1.5
]
var subjectsNames: [String] = [String](subjects.keys)

View file

@ -1,67 +0,0 @@
//
// SubjectView.swift
// GradeMapper
//
// Created by Иван Бущик on 18.01.2022.
//
import SwiftUI
enum Grade: Int, Identifiable, CaseIterable{
case One = 1
case Two = 2
case Three = 3
case Four = 4
case Five = 5
var id: Int { self.rawValue }
}
struct SubjectView: View {
var ow = helpMe()
@State var srr: Double = 0
var name: String
@State private var selectedGrade = Grade.One
@State var selectedTypeOfGrade = "Контрольная работа"
var body: some View {
var current = subjects[name]!
VStack(alignment: .center, spacing: 75){
Text("\(name)")
.font(.title)
.fontWeight(.black)
.multilineTextAlignment(.center)
VStack(alignment: .leading, spacing: 30){
Picker("Тип оценки", selection: $selectedTypeOfGrade){
ForEach([String](subjects[name]!.keys), id: \.self) {
subjectSN in Text("\(subjectSN)")
}
}.pickerStyle(.wheel)
VStack{
Picker("Оценка", selection: $selectedGrade){
ForEach(Grade.allCases, id: \.self) {
currGrade in Text("\(currGrade.rawValue)")
}
}
}.pickerStyle(.segmented)
}
Button ("Добавить оценку"){
ow.multiplier = current[selectedTypeOfGrade]!
ow.gradesWeighted += Double(selectedGrade.rawValue) * ow.multiplier
ow.weightsSum += ow.multiplier
ow.sr = (ow.gradesWeighted / ow.weightsSum)
print(ow.sr)
print(ow.multiplier)
self.srr = ow.sr
}.buttonStyle(.borderedProminent)
Text(String("Средний балл: \(self.srr)"))
.fontWeight(.bold)
}
.padding(.top, -155.0)
}
}
struct SubjectView_Previews: PreviewProvider {
static var previews: some View {
SubjectView(name: "Русский язык")
}
}