Skip to content

Commit

Permalink
Merge branch 'refactor/screening'
Browse files Browse the repository at this point in the history
  • Loading branch information
akarataev committed Nov 29, 2018
2 parents 66c53f0 + 5d53b53 commit e094efc
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 52 deletions.
8 changes: 6 additions & 2 deletions Gleam.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
BE331EA662B877DD9175FB3D /* ScreeningRouterInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82F75E5F707471D02F7B6B11 /* ScreeningRouterInput.swift */; };
C4EDC4CBBA97051A6177615B /* ScreeningViewOutput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1282BEE749F79E31E60D9980 /* ScreeningViewOutput.swift */; };
D71EABBE21963AEC00EBE287 /* StyleExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D71EABBD21963AEC00EBE287 /* StyleExtensions.swift */; };
D761474221AF0D6E00E33305 /* ClassLabels.swift in Sources */ = {isa = PBXBuildFile; fileRef = D761474121AF0D6E00E33305 /* ClassLabels.swift */; };
D763539521971B4A00F01C6A /* StatusIndicatorViewDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D763539421971B4A00F01C6A /* StatusIndicatorViewDelegate.swift */; };
D7791B332196DCCD007A450C /* FTVGG16.mlmodel in Sources */ = {isa = PBXBuildFile; fileRef = D7791B322196DCCC007A450C /* FTVGG16.mlmodel */; };
D7791B352196DD57007A450C /* ImagePreprocessing.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7791B342196DD57007A450C /* ImagePreprocessing.swift */; };
Expand Down Expand Up @@ -118,6 +119,7 @@
A8BF2C576BB7C4870FDAC243 /* Pods-Gleam.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Gleam.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Gleam/Pods-Gleam.debug.xcconfig"; sourceTree = "<group>"; };
CD0D98666C9DBB37CB815CAD /* ScreeningModuleConfigurator.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = ScreeningModuleConfigurator.swift; sourceTree = "<group>"; };
D71EABBD21963AEC00EBE287 /* StyleExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StyleExtensions.swift; sourceTree = "<group>"; };
D761474121AF0D6E00E33305 /* ClassLabels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClassLabels.swift; sourceTree = "<group>"; };
D763539421971B4A00F01C6A /* StatusIndicatorViewDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusIndicatorViewDelegate.swift; sourceTree = "<group>"; };
D7791B322196DCCC007A450C /* FTVGG16.mlmodel */ = {isa = PBXFileReference; lastKnownFileType = file.mlmodel; path = FTVGG16.mlmodel; sourceTree = "<group>"; };
D7791B342196DD57007A450C /* ImagePreprocessing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImagePreprocessing.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -423,6 +425,7 @@
D7791B342196DD57007A450C /* ImagePreprocessing.swift */,
D7791B362196DE65007A450C /* SkinCancerClassificator.swift */,
D7791B382196DE78007A450C /* SkinCancerClassificatorDelegate.swift */,
D761474121AF0D6E00E33305 /* ClassLabels.swift */,
);
path = ML;
sourceTree = "<group>";
Expand Down Expand Up @@ -758,6 +761,7 @@
50D8E4862197223200663FEC /* UserSettings.swift in Sources */,
8B0798C7371363D33791C6FE /* ScreeningInteractor.swift in Sources */,
504328AF2195F7D2000FA9B7 /* CollectionSetupable.swift in Sources */,
D761474221AF0D6E00E33305 /* ClassLabels.swift in Sources */,
BE331EA662B877DD9175FB3D /* ScreeningRouterInput.swift in Sources */,
5079894C2195D5F100A6BE9D /* OnboardingViewController.swift in Sources */,
504328C321961631000FA9B7 /* GleamService.swift in Sources */,
Expand Down Expand Up @@ -919,7 +923,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 9;
CURRENT_PROJECT_VERSION = 12;
DEVELOPMENT_TEAM = U67ZU8H7H4;
INFOPLIST_FILE = Gleam/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -940,7 +944,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 9;
CURRENT_PROJECT_VERSION = 12;
DEVELOPMENT_TEAM = U67ZU8H7H4;
INFOPLIST_FILE = Gleam/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand Down
13 changes: 10 additions & 3 deletions Gleam/Components/CaptureButton/CaptureButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,16 @@ class CaptureButton: UIButton {

extension CaptureButton {

func repeatPulseAnimation(count: Int) {
func startAnimation(for sender: CaptureButton, by mode: CaptureMode) {
switch mode {
case .live:
self.repeatPulseAnimation(count: 9)
case .photo:
self.repeatPulseAnimation(count: 1)
}
}

private func repeatPulseAnimation(count: Int) {
guard count > 0 else { return }
UIView.animate(withDuration: 0.3, animations: {
self.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
Expand All @@ -40,8 +49,6 @@ extension CaptureButton {
self.repeatPulseAnimation(count: count - 1)
})
})


}
}

4 changes: 2 additions & 2 deletions Gleam/Components/CaptureModeSegment/CaptureModeSegment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ extension CaptureModeSegment {
// MARK: - implement capture segment mode

@objc enum CaptureMode: Int {
case live
case photo
case live = 10
case photo = 1
}


Expand Down
3 changes: 1 addition & 2 deletions Gleam/Components/IndicatorView/StatusIndicatorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ private extension StatusIndicatorView {
extension StatusIndicatorView {

@objc func diagnosisViewDidTap(sender: UIView) {
print("tap")
self.delegate?.statusIndicatorViewDidTap(sender: sender)
}
}
Expand All @@ -112,7 +111,7 @@ private extension StatusIndicatorView {
)

self.diagnosisView.applyStyles (
diagnosis: state.diagnosisDescription,
diagnosis: state.description,
color: state.color
)
}
Expand Down
2 changes: 1 addition & 1 deletion Gleam/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>9</string>
<string>12</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>TyphoonInitialAssemblies</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import UIKit
}
}

var diagnosisDescription: String {
var description: String {
switch self {
case .low:
return "LOW RISK"
Expand Down
18 changes: 10 additions & 8 deletions Gleam/Modules/Screening/Interactor/ScreeningInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class ScreeningInteractor: NSObject, ScreeningInteractorInput {
var capturedData: Array<(String, Float)> = []


@objc var classificator: SkinCancerClassificator! {
@objc weak var classificator: SkinCancerClassificator! {
didSet { classificator.delegate = self }
}

@objc var captureSession: VideoCaptureSession! {
@objc weak var captureSession: VideoCaptureSession! {
didSet { captureSession.addVideoBufferOutput(delegate: self) }
}

Expand All @@ -39,19 +39,19 @@ extension ScreeningInteractor {
}

func setNumberOfCapturedImages(by mode: CaptureMode) {
self.imagesNumber = mode == .live ? 10: 1
self.imagesNumber = mode.rawValue
}

func evaluateDiagnosis() {
let benign = getPredictedScore(by: "Benign")
let malignant = getPredictedScore(by: "Malignant")
let benign = getPredictedScore(by: .benign)
let malignant = getPredictedScore(by: .malignant)
output.presentResultOfClassification (
result: malignant > benign ? .high: .low
)
}

func getPredictedScore(by status: String) -> Float {
return self.capturedData.filter { $0.0 == status }
func getPredictedScore(by label: ClassLabel) -> Float {
return self.capturedData.filter { $0.0 == label.rawValue }
.reduce(0) { $0 + $1.1 } / Float(capturedData.count)
}
}
Expand All @@ -72,7 +72,9 @@ extension ScreeningInteractor: SkinCancerClassificatorDelegate {
extension ScreeningInteractor: AVCaptureVideoDataOutputSampleBufferDelegate {

func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
self.provideClassificationRequest { self.classificator.startClassification (sampleBuffer: sampleBuffer) }
self.provideClassificationRequest {
self.classificator.startClassification (sampleBuffer: sampleBuffer)
}
}

func provideClassificationRequest(classificationRequest: () -> Void) {
Expand Down
11 changes: 1 addition & 10 deletions Gleam/Modules/Screening/Presenter/ScreeningPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,12 @@ extension ScreeningPresenter {
}


// MARK: - Processing of user actions

extension ScreeningPresenter {

}


// MARK: - Prerouting section

extension ScreeningPresenter {

func routeToClinicScreen() {
self.router.toClinicScreen (
sender: view.getSender()
)
self.router.toClinicScreen(sender: view.sender)
}

}
11 changes: 1 addition & 10 deletions Gleam/Modules/Screening/View/ScreeningViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,9 @@ extension ScreeningViewController {

@objc func captureButtonDidTap(_ sender: CaptureButton) {
self.statusPanel.indicate()
self.selectCaptureButtonAnimation(for: sender)
self.captureButton.startAnimation(for: sender, by: modeSegmented.mode)
self.output.userRequestImageProcessing(mode: modeSegmented.mode)
}

func selectCaptureButtonAnimation(for sender: CaptureButton) {
switch self.modeSegmented.mode {
case .live:
captureButton.repeatPulseAnimation(count: 9)
case .photo:
captureButton.repeatPulseAnimation(count: 1)
}
}
}


Expand Down
10 changes: 5 additions & 5 deletions Gleam/Modules/Screening/View/ScreeningViewInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ import UIKit
import Foundation

@objc protocol ScreeningViewInput: class {

var sender: UIViewController { get }

func setupInitialState()
func displayDiagnosis(state: DiagnosisRiskState)
func getSender() -> UIViewController
}


// MARK: - setup ScreeningViewController for routing

extension ScreeningViewController {

var sender: UIViewController { return self }

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
output.viewIsPrepareToSegue(segue: segue)
}

func getSender() -> UIViewController {
return self
}
}
4 changes: 1 addition & 3 deletions Gleam/Modules/Screening/View/ScreeningViewOutput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import Foundation
extension ScreeningPresenter {

func viewIsPrepareToSegue(segue: UIStoryboardSegue) {
router.passData (
segue: segue
)
router.passData(segue: segue)
}
}
14 changes: 14 additions & 0 deletions Gleam/Services/ML/ClassLabels.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// ClassLabels.swift
// Gleam
//
// Created by Каратаев Алексей on 28.11.2018.
// Copyright © 2018 Alexey Karataev. All rights reserved.
//

import Foundation

enum ClassLabel: String {
case benign = "Benign"
case malignant = "Malignant"
}
2 changes: 1 addition & 1 deletion Gleam/Services/ML/SkinCancerClassificator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private extension SkinCancerClassificator {

func didFinishedByClass(with stats: Array<VNClassificationObservation>) {
self.delegate?.classificatorFinishedWith (
stats: stats.map { ($0.identifier, confidence: $0.confidence) }
stats: stats.map { ($0.identifier, $0.confidence) }
)
}
}
Expand Down
8 changes: 4 additions & 4 deletions Gleam/Services/Styles/Colors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ extension UIColor {
}

static var lowIndicatorColor: UIColor {
return UIColor (red: 156 / 255, green: 238 / 255, blue: 106 / 255, alpha: 1)
return UIColor(red: 156 / 255, green: 238 / 255, blue: 106 / 255, alpha: 1)
}

static var mediumIndicatorColor: UIColor {
return UIColor (red: 18 / 255, green: 204 / 255, blue: 255 / 255, alpha: 1)
return UIColor(red: 18 / 255, green: 204 / 255, blue: 255 / 255, alpha: 1)
}

static var highIndicatorColor: UIColor {
Expand All @@ -34,11 +34,11 @@ extension UIColor {
}

static var baseButtonColor: UIColor {
return UIColor (red: 17 / 255, green: 181 / 255, blue: 226 / 255, alpha: 0.7)
return UIColor(red: 17 / 255, green: 181 / 255, blue: 226 / 255, alpha: 0.7)
}

static var spotButtonColor: UIColor {
return UIColor (red: 18 / 255, green: 204 / 255, blue: 255 / 255, alpha: 1)
return UIColor(red: 18 / 255, green: 204 / 255, blue: 255 / 255, alpha: 1)
}
}

0 comments on commit e094efc

Please sign in to comment.