<commit_before>//
//  MainMenuViewController.swift
//  ANN
//
//  Created by user125215 on 3/13/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import UIKit

final class MainMenuViewController: UIViewController {
    
    // MARK: - Properties -
    
    var presenter: MainMenuPresenterInterface!
    
    let trainButton: UIButton = {
        let button = UIButton()
        button.setTitle("TRAIN", for: .normal)
        button.setTitleColor(.menuBackground, for: .normal)
        button.backgroundColor = .menuButton
        button.translatesAutoresizingMaskIntoConstraints = false
    
        return button
    }()
    
    let testButton: UIButton = {
        let button = UIButton()
        button.setTitle("TEST", for: .normal)
        button.setTitleColor(.menuBackground, for: .normal)
        button.backgroundColor = .menuButton
        
        return button
    }()
    
    var closeNeuronViews: [UIView] = []
    var distantNeuronViews: [UIView] = []
    
    // MARK: - Lifecycle -
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.backgroundColor = .menuBackground
        setupViews()
    }
    
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        
        setCornerRadiusAndShadowFor(view: trainButton)
        setCornerRadiusAndShadowFor(view: testButton)
        
        for view in closeNeuronViews {
            setCornerRadiusAndShadowFor(view: view)
            drawSynapsePathsFor(view: view)
        }
    }
    
    // MARK: - Helpers -
    
    fileprivate func setupViews() {
        setupTrainButton()
        setupTestButton()
        setupNeuronViews()
    }
    
    fileprivate func setupNeuronViews() {
        
        for viewIndex in 0..<6 {
            
            let neuronView = UIView()
            var verticalOffset: CGFloat = 3
            var horizontalOffset = -self.view.frame.width/2
            var isOnTop = true
            
            neuronView.backgroundColor = .menuButton
            
            if viewIndex >= 3 {
                horizontalOffset = horizontalOffset * -1
            }
            
            if viewIndex == 1 || viewIndex == 4 {
                verticalOffset = self.view.frame.height
            }
            
            if viewIndex == 2 || viewIndex == 5 {
                isOnTop = false
            }
            
            
            setupConstraintsForMenu(view: neuronView, isOnTop: isOnTop, verticalOffset: verticalOffset, horizontalOffset: horizontalOffset, width: 55)
            closeNeuronViews.append(neuronView)
        }
    }
    
    fileprivate func drawSynapsePathsFor(view: UIView) {
        
        // ??
        let viewCenter = CGPoint(x: view.frame.midX, y: view.frame.midY)
        let buttonCenter = CGPoint(x: trainButton.frame.midX, y: trainButton.frame.midY)
        
        let path = UIBezierPath()
        path.move(to: viewCenter)
        path.addLine(to: buttonCenter)
        path.close()
        
        let layer = CAShapeLayer()
        layer.path = path.cgPath
        layer.strokeColor = UIColor.black.cgColor
        layer.lineWidth = 5.0
        
        view.layer.addSublayer(layer)
    }
    
    fileprivate func setupTrainButton() {
        setupConstraintsForMenu(view: trainButton, isOnTop: true, verticalOffset: 5, horizontalOffset: 0, width: 75)
    }
    
    fileprivate func setupTestButton() {
        setupConstraintsForMenu(view: testButton, isOnTop: false, verticalOffset: 5, horizontalOffset: 0, width: 75)
    }
    
    fileprivate func setCornerRadiusAndShadowFor(view: UIView) {
        view.layer.cornerRadius = view.frame.width / 2
        view.layer.masksToBounds = false
        view.layer.shadowOffset = CGSize(width: 3, height: 3)
        view.layer.shadowRadius = 3
        view.layer.shadowColor = UIColor.black.cgColor
        view.layer.shadowOpacity = 0.5
    }
    
    fileprivate func setupConstraintsForMenu(view: UIView, isOnTop: Bool, verticalOffset: CGFloat, horizontalOffset: CGFloat, width: CGFloat) {
        
        self.view.addSubview(view)
        
        var verticalOffsetConstant = self.view.frame.height / verticalOffset
        
        verticalOffsetConstant = isOnTop ? -verticalOffsetConstant : verticalOffsetConstant
        <commit_msg>implemented bezier paths as synapses<commit_after>//
//  MainMenuViewController.swift
//  ANN
//
//  Created by user125215 on 3/13/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import UIKit

final class MainMenuViewController: UIViewController {
    
    // MARK: - Properties -
    
    var presenter: MainMenuPresenterInterface!
    
    let trainButton: UIButton = {
        let button = UIButton()
        button.setTitle("TRAIN", for: .normal)
        button.setTitleColor(.menuBackground, for: .normal)
        button.backgroundColor = .menuButton
        button.translatesAutoresizingMaskIntoConstraints = false
    
        return button
    }()
    
    let testButton: UIButton = {
        let button = UIButton()
        button.setTitle("TEST", for: .normal)
        button.setTitleColor(.menuBackground, for: .normal)
        button.backgroundColor = .menuButton
        
        return button
    }()
    
    var closeNeuronViews: [UIView] = []
    var distantNeuronViews: [UIView] = []
    
    // MARK: - Lifecycle -
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.backgroundColor = .menuBackground
        setupViews()
    }
    
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        
        setCornerRadiusAndShadowFor(view: trainButton)
        setCornerRadiusAndShadowFor(view: testButton)
        
        for view in closeNeuronViews {
            setCornerRadiusAndShadowFor(view: view)
            drawSynapsePathsFor(view: view)
        }
        
        view.bringSubview(toFront: trainButton)
        view.bringSubview(toFront: testButton)
    }
    
    // MARK: - Helpers -
    
    fileprivate func setupViews() {
        setupTrainButton()
        setupTestButton()
        setupNeuronViews()
    }
    
    fileprivate func setupNeuronViews() {
        
        for viewIndex in 0..<6 {
            
            let neuronView = UIView()
            var verticalOffset: CGFloat = 3
            var horizontalOffset = -self.view.frame.width/2
            var isOnTop = true
            
            neuronView.backgroundColor = .menuButton
            
            if viewIndex >= 3 {
                horizontalOffset = horizontalOffset * -1
            }
            
            if viewIndex == 1 || viewIndex == 4 {
                verticalOffset = self.view.frame.height
            }
            
            if viewIndex == 2 || viewIndex == 5 {
                isOnTop = false
            }
            
            
            setupConstraintsForMenu(view: neuronView, isOnTop: isOnTop, verticalOffset: verticalOffset, horizontalOffset: horizontalOffset, width: 55)
            closeNeuronViews.append(neuronView)
        }
    }
    
    fileprivate func drawSynapsePathsFor(view: UIView) {
        
        // Get points for bezier path relative to superview
        // Point for our neuron view
        let viewRectInSuperview = view.convert(view.frame, from: self.view)
        let viewPointInSuperview = CGPoint(x: viewRectInSuperview.midX, y: viewRectInSuperview.midY)
        
        // Point for train button
        let trainButtonRectInSuperview = view.convert(trainButton.frame, from: self.view)
        let trainButtonPointInSuperview = CGPoint(x: trainButtonRectInSuperview.midX, y: trainButtonRectInSuperview.midY)
        
        // Point for test button
        let testButtonRectInSuperview = view.convert(testButton.frame, from: self.view)
        let testButtonPointInSuperview = CGPoint(x: testButtonRectInSuperview.midX, y: testButtonRectInSuperview.midY)
        
        // Add path from views to train button
        let trainPath = UIBezierPath()
        trainPath.move(to: viewPointInSuperview)
        trainPath.addLine(to: trainButtonPointInSuperview)
        trainPath.close()
        
        // Add path for views to test button
        let testPath = UIBezierPath()
        testPath.move(to: viewPointInSuperview)
        testPath.addLine(to: testButtonPointInSuperview)
        testPath.close()
        
        // Make layer for train button
        let trainLayer = CAShapeLayer()
        trainLayer.path = trainPath.cgPath
        trainLayer.strokeColor = UIColor.menuButton.cgColor
        trainLayer.lineWidth = 3.0
        
        // Make lazer for test button
        let testLayer = CAShapeLayer()
        testLayer.path = testPath.cgPath
        testLayer.strokeColor = UIColor.menuButton.cgColor
        testLayer.lineWidth = 3.0
        
        // Add layers to main view
        view.layer.addSublayer(trainLayer)
        view.layer.addSublayer(testLayer)
    }
    
    fileprivate func setupTrainButton() {
        setupConstraintsForMenu(view: trainButton, isOnTop: true, verticalOffset: 5, horizontalOffset: 0, width: 75)
    }
    
    fileprivate func setupTestButton() {
        setupConstraintsForMenu(view: testButton, isOnTop: false, verticalOffset: 5, horizontalOffset: 0, width: 75)
    }
    
    fileprivate func setCornerRadiusAndShadowFor(view: UIView) {
        view.layer.cornerRadius = view.frame.width / 2
        view.layer.masksToBounds = false
        view.layer.shadowOffset = CGSize(width: 3, height: 3)
        view.layer.shadowRadius = 3
        view.layer.shadowColor = UIColor.black.cgColor
        view.layer.shadowOpacity = 0.5
    }
    
    fileprivate func setupConstraintsForMenu(view: UIView, isOnTop: Bool, verticalOffset: CGFloat, horizontalOffset: CGFloat, width: CGFloat) {
        
        self.view.addSubview(view)
        
        var verticalOffsetConstant = self.view.frame.height / verticalOffset
        
        verticalOffsetConstant = isOnTop ? -verticalOffsetConstant : verticalOffsetConstant
        
{'fraction_non_alphanumeric': 0.08187425387982492, 'fraction_numerical': 0.008754476721050538, 'mean_word_length': 2.026189042745334, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6123708', 'n_tokens_mistral': 2880, 'n_tokens_neox': 2752, 'n_words': 603}