<commit_before>//
//  DiningAnalyticsView.swift
//  PennMobile
//
//  Created by <NAME> on 2/6/22.
//  Copyright © 2022 PennLabs. All rights reserved.
//

import SwiftUI

struct DiningAnalyticsView: View {
    @EnvironmentObject var diningAnalyticsViewModel: DiningAnalyticsViewModel
    @State var showMissingDiningTokenAlert = false
    @State var showDiningLoginView = false
    @State var notLoggedInAlertShowing = false
    @Environment(\.presentationMode) var presentationMode
    func showCorrectAlert () -> Alert {
        if !Account.isLoggedIn {
            return Alert(title: Text("You must log in to access this feature."), message: Text("Please login on the \"More\" tab."), dismissButton: .default(Text("Ok"), action: { presentationMode.wrappedValue.dismiss() }))
        } else {
            return Alert(title: Text("\"Penn Mobile\" requires you to login to Campus Express to use this feature."),
                         message: Text("Would you like to continue to campus express?"),
                         primaryButton: .default(Text("Continue"), action: {showDiningLoginView = true}),
                         secondaryButton: .cancel({ presentationMode.wrappedValue.dismiss() }))
        }
    }
    var body: some View {
        let dollarXYHistory = Binding(
            get: {
                getSmoothedData(from: diningAnalyticsViewModel.dollarHistory)
            },
            // one directional Binding, setter does not work
            set: {  _ in }
        )
        let swipeXYHistory = Binding(
            get: { getSmoothedData(from: diningAnalyticsViewModel.swipeHistory) },
            // one directional Binding, setter does not work
            set: {  _ in }
        )
        HStack {
            if Account.isLoggedIn, let diningExpiration = UserDefaults.standard.getDiningTokenExpiration(), Date() <= diningExpiration {
                if swipeXYHistory.wrappedValue.isEmpty && dollarXYHistory.wrappedValue.isEmpty {
                    ZStack {
                        Image("DiningAnalyticsBackground")
                            .resizable()
                            .ignoresSafeArea()
                        Text("No Dining\nPlan Found\n ")
                            .multilineTextAlignment(.center)
                            .font(.system(size: 48, weight: .regular))
                            .opacity(0.6)
                    }
                } else {
                    ScrollView {
                        VStack(alignment: .leading, spacing: 20) {
                            Text("Dining Analytics")
                                .font(.system(size: 32))
                                .bold()
                            // Only show dollar history view if there is data for the graph
                            if !dollarXYHistory.wrappedValue.isEmpty {
                                CardView {
                                    PredictionsGraphView(type: "dollars", data: dollarXYHistory, predictedZeroDate: $diningAnalyticsViewModel.dollarPredictedZeroDate, predictedSemesterEndValue: $diningAnalyticsViewModel.predictedDollarSemesterEndBalance, axisLabelsYX: $diningAnalyticsViewModel.dollarAxisLabel, slope: $diningAnalyticsViewModel.dollarSlope)
                                }
                            }
                            // Only show swipe history view if there is data for the graph<commit_msg>"Support" dark mode by forcing black font<commit_after>//
//  DiningAnalyticsView.swift
//  PennMobile
//
//  Created by <NAME> on 2/6/22.
//  Copyright © 2022 PennLabs. All rights reserved.
//

import SwiftUI

struct DiningAnalyticsView: View {
    @EnvironmentObject var diningAnalyticsViewModel: DiningAnalyticsViewModel
    @State var showMissingDiningTokenAlert = false
    @State var showDiningLoginView = false
    @State var notLoggedInAlertShowing = false
    @Environment(\.presentationMode) var presentationMode
    func showCorrectAlert () -> Alert {
        if !Account.isLoggedIn {
            return Alert(title: Text("You must log in to access this feature."), message: Text("Please login on the \"More\" tab."), dismissButton: .default(Text("Ok"), action: { presentationMode.wrappedValue.dismiss() }))
        } else {
            return Alert(title: Text("\"Penn Mobile\" requires you to login to Campus Express to use this feature."),
                         message: Text("Would you like to continue to campus express?"),
                         primaryButton: .default(Text("Continue"), action: {showDiningLoginView = true}),
                         secondaryButton: .cancel({ presentationMode.wrappedValue.dismiss() }))
        }
    }
    var body: some View {
        let dollarXYHistory = Binding(
            get: {
                getSmoothedData(from: diningAnalyticsViewModel.dollarHistory)
            },
            // one directional Binding, setter does not work
            set: {  _ in }
        )
        let swipeXYHistory = Binding(
            get: { getSmoothedData(from: diningAnalyticsViewModel.swipeHistory) },
            // one directional Binding, setter does not work
            set: {  _ in }
        )
        HStack {
            if Account.isLoggedIn, let diningExpiration = UserDefaults.standard.getDiningTokenExpiration(), Date() <= diningExpiration {
                if swipeXYHistory.wrappedValue.isEmpty && dollarXYHistory.wrappedValue.isEmpty {
                    ZStack {
                        Image("DiningAnalyticsBackground")
                            .resizable()
                            .ignoresSafeArea()
                        Text("No Dining\nPlan Found\n ")
                            .multilineTextAlignment(.center)
                            .font(.system(size: 48, weight: .regular))
                            .foregroundColor(.black)
                            .opacity(0.6)
                    }
                } else {
                    ScrollView {
                        VStack(alignment: .leading, spacing: 20) {
                            Text("Dining Analytics")
                                .font(.system(size: 32))
                                .bold()
                            // Only show dollar history view if there is data for the graph
                            if !dollarXYHistory.wrappedValue.isEmpty {
                                CardView {
                                    PredictionsGraphView(type: "dollars", data: dollarXYHistory, predictedZeroDate: $diningAnalyticsViewModel.dollarPredictedZeroDate, predictedSemesterEndValue: $diningAnalyticsViewModel.predictedDollarSemesterEndBalance, axisLabelsYX: $diningAnalyticsViewModel.dollarAxisLabel, slope: $diningAnalyticsViewModel.dollarSlope)
                                }
                            }
                            // Only show swipe history view if there is data for the graph
{'fraction_non_alphanumeric': 0.08341810783316378, 'fraction_numerical': 0.004650486847841883, 'mean_word_length': 1.6861826697892273, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4147574', 'n_tokens_mistral': 1735, 'n_tokens_neox': 1601, 'n_words': 418}