Skip to content

Commit

Permalink
V5.1.0 (#45)
Browse files Browse the repository at this point in the history
* scout app 5.1.0

* fix one-off error

* data viewer explicit failure

* shit

* data dump endpoint

* fix data dump

* rustfmt
  • Loading branch information
JayAgra authored Mar 5, 2024
1 parent ecb6b02 commit 0b717b6
Show file tree
Hide file tree
Showing 48 changed files with 2,389 additions and 1,009 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bear_tracks"
version = "5.0.5"
version = "5.1.0"
edition = "2021"
authors = ["Jayen Agrawal"]
description = "a scouting app for frc"
Expand Down Expand Up @@ -35,7 +35,7 @@ r2d2 = "0.8"
r2d2_sqlite = "0.22"
rand = "0.8.5"
regex = "1.10.3"
reqwest = "0.11.22"
reqwest = { version = "0.11.22", features = ["blocking"] }
serde = { version = "1.0", features = ["derive"] }
serde_cbor_2 = { version = "0.12.0-dev" }
serde_json = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ use static_files::resource_dir;
fn main() -> std::io::Result<()> {
// include files in ./static/public in binary
resource_dir("./static/public").build()
}
}
202 changes: 198 additions & 4 deletions ios/beartracks/bearTracks.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions ios/beartracks/bearTracks/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ import Combine
class AppState: ObservableObject {
#if targetEnvironment(macCatalyst)
@Published public var selectedTab: Tab? = .teams
#elseif os(watchOS)
#else
@Published public var selectedTab: Tab = .teams
#endif
@Published public var loginRequired: Bool = false
private var cancellables: Set<AnyCancellable> = []

#if !os(watchOS)
init() {
$selectedTab
.receive(on: DispatchQueue.main)
.sink { _ in }
.store(in: &cancellables)
}
#endif
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x96",
"green" : "0x93",
"red" : "0x0A"
}
},
"idiom" : "universal"
}
],
Expand Down
2 changes: 1 addition & 1 deletion ios/beartracks/bearTracks/DataViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DataViewModel: ObservableObject {
}

func fetchEventJson(completionBlock: @escaping ([DataEntry]) -> Void) -> Void {
guard let url = URL(string: "https://beartracks.io/api/v1/data/brief/event/\(UserDefaults.standard.string(forKey: "season") ?? "2024")/\(UserDefaults.standard.string(forKey: "eventCode") ?? "CAFR")") else {
guard let url = URL(string: "https://beartracks.io/api/v1/data/brief/event/\(UserDefaults(suiteName: "group.com.jayagra.beartracks")?.string(forKey: "season") ?? "2024")/\(UserDefaults(suiteName: "group.com.jayagra.beartracks")?.string(forKey: "eventCode") ?? "CAFR")") else {
return
}

Expand Down
50 changes: 47 additions & 3 deletions ios/beartracks/bearTracks/DetailedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,19 @@ struct DetailedView: View {
if detailData[0].FullMain.season == 2024 {
ScrollView {
Text("Team \(String(detailData[0].FullMain.team))")
#if !os(watchOS)
.font(.largeTitle)
#else
.font(.title3)
#endif
.padding([.top, .leading])
.frame(maxWidth: .infinity, alignment: .leading)
Text("\(detailData[0].FullMain.level) \(String(detailData[0].FullMain.match_num)) @ \(detailData[0].FullMain.event) \(String(detailData[0].FullMain.season))")
#if !os(watchOS)
.font(.title2)
#else
.font(.body)
#endif
.padding(.leading)
.frame(maxWidth: .infinity, alignment: .leading)
VStack {
Expand All @@ -43,19 +51,31 @@ struct DetailedView: View {
HStack {
VStack {
Text("\(String(detailData[0].FullMain.analysis.split(separator: ",")[3]))s")
#if !os(watchOS)
.font(.title)
#else
.font(.title3)
#endif
Text("intake")
}
.frame(maxWidth: .infinity)
VStack {
Text("\(String(detailData[0].FullMain.analysis.split(separator: ",")[4]))s")
#if !os(watchOS)
.font(.title)
#else
.font(.title3)
#endif
Text("travel")
}
.frame(maxWidth: .infinity)
VStack {
Text("\(String(detailData[0].FullMain.analysis.split(separator: ",")[5]))s")
#if !os(watchOS)
.font(.title)
#else
.font(.title3)
#endif
Text("outtake")
}
.frame(maxWidth: .infinity)
Expand All @@ -67,13 +87,21 @@ struct DetailedView: View {
HStack {
VStack {
Text(String(detailData[0].FullMain.analysis.split(separator: ",")[6]))
#if !os(watchOS)
.font(.title)
#else
.font(.title3)
#endif
Text("speaker")
}
.frame(maxWidth: .infinity)
VStack {
Text(String(detailData[0].FullMain.analysis.split(separator: ",")[7]))
#if !os(watchOS)
.font(.title)
#else
.font(.title3)
#endif
Text("amplifier")
}
.frame(maxWidth: .infinity)
Expand All @@ -87,7 +115,7 @@ struct DetailedView: View {
.frame(maxWidth: .infinity, alignment: .leading)
VStack {
Divider()
ForEach(gameData, id: \.id) { matchTime in
ForEach(gameData) { matchTime in
VStack {
HStack {
switch matchTime.score_type {
Expand Down Expand Up @@ -159,10 +187,19 @@ struct DetailedView: View {
HStack {
Spacer()
Label(String(format: "%.1f", matchTime.intake), systemImage: "tray.and.arrow.down")
#if os(watchOS)
.labelStyle(.titleOnly)
#endif
Spacer()
Label(String(format: "%.1f", matchTime.travel), systemImage: "arrow.up.and.down.and.arrow.left.and.right")
#if os(watchOS)
.labelStyle(.titleOnly)
#endif
Spacer()
Label(String(format: "%.1f", matchTime.outtake), systemImage: "tray.and.arrow.up")
#if os(watchOS)
.labelStyle(.titleOnly)
#endif
Spacer()
}
.padding(.top)
Expand Down Expand Up @@ -294,10 +331,17 @@ struct FullMainData: Codable {
}

/// 2024 season specific data structure for deocding the `game` key of `FullMainData`
struct MatchTime2024: Codable {
let id: Int
struct MatchTime2024: Codable, Identifiable {
var id = UUID()
let score_type: Int
let intake: Float
let outtake: Float
let travel: Float

enum CodingKeys: CodingKey {
case score_type
case intake
case outtake
case travel
}
}
16 changes: 15 additions & 1 deletion ios/beartracks/bearTracks/LoginView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,49 @@ struct LoginView: View {

var body: some View {
VStack {
#if !os(watchOS)
Text("bearTracks")
.font(.title)
Text("v5.0.5 • 2024")
Text("v5.1.0 • 2024")
#endif
if !loading {
if !create {
#if !os(watchOS)
Text("log in")
.font(.title3)
.padding(.top)
#endif
TextField("username", text: $authData[0])
#if !os(watchOS)
.padding([.leading, .trailing, .bottom])
.textFieldStyle(RoundedBorderTextFieldStyle())
#endif
.autocorrectionDisabled(true)
.textInputAutocapitalization(.never)
.textContentType(.username)
SecureField("password", text: $authData[1])
#if !os(watchOS)
.padding()
.textFieldStyle(RoundedBorderTextFieldStyle())
#endif
.autocorrectionDisabled(true)
.textInputAutocapitalization(.never)
.textContentType(.password)
Button("login") {
authAction(type: "login", data: ["username": authData[0], "password": authData[1]])
}
#if !os(watchOS)
.padding()
#endif
.font(.title3)
.buttonStyle(.bordered)
#if !os(watchOS)
Button("create") {
self.create = true
}
#endif
} else {
#if !os(watchOS)
Text("create account")
.font(.title3)
.padding(.top)
Expand Down Expand Up @@ -83,6 +96,7 @@ struct LoginView: View {
Button("login") {
self.create = false
}
#endif
}
} else {
Spacer()
Expand Down
2 changes: 1 addition & 1 deletion ios/beartracks/bearTracks/MatchList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ struct MatchList: View {
}

func fetchMatchJson() {
guard let url = URL(string: "https://beartracks.io/api/v1/events/matches/\(UserDefaults.standard.string(forKey: "season") ?? "2024")/\(UserDefaults.standard.string(forKey: "eventCode") ?? "CAFR")/qualification/\( UserDefaults.standard.string(forKey: "teamNumber") ?? "766")") else {
guard let url = URL(string: "https://beartracks.io/api/v1/events/matches/\(UserDefaults(suiteName: "group.com.jayagra.beartracks")?.string(forKey: "season") ?? "2024")/\(UserDefaults(suiteName: "group.com.jayagra.beartracks")?.string(forKey: "eventCode") ?? "CAFR")/qualification/\(UserDefaults(suiteName: "group.com.jayagra.beartracks")?.string(forKey: "teamNumber") ?? "766")") else {
return
}

Expand Down
2 changes: 1 addition & 1 deletion ios/beartracks/bearTracks/SettingsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ class SettingsManager {
"season": "2024",
"darkMode": true,
]
UserDefaults.standard.register(defaults: defaults)
UserDefaults(suiteName: "group.com.jayagra.beartracks")?.register(defaults: defaults)
}
}
33 changes: 21 additions & 12 deletions ios/beartracks/bearTracks/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import SwiftUI

/// Settings window for event config & logging out
struct SettingsView: View {
@State private var teamNumberInput: String = UserDefaults.standard.string(forKey: "teamNumber") ?? ""
@State private var eventCodeInput: String = UserDefaults.standard.string(forKey: "eventCode") ?? ""
@State private var seasonInput: String = UserDefaults.standard.string(forKey: "season") ?? ""
@State private var darkMode: Bool = UserDefaults.standard.bool(forKey: "darkMode")
@State private var teamNumberInput: String = UserDefaults(suiteName: "group.com.jayagra.beartracks")?.string(forKey: "teamNumber") ?? ""
@State private var eventCodeInput: String = UserDefaults(suiteName: "group.com.jayagra.beartracks")?.string(forKey: "eventCode") ?? ""
@State private var seasonInput: String = UserDefaults(suiteName: "group.com.jayagra.beartracks")?.string(forKey: "season") ?? ""
@State private var darkMode: Bool = UserDefaults(suiteName: "group.com.jayagra.beartracks")?.bool(forKey: "darkMode") ?? true
@State private var showAlert = false
@State private var settingsOptions: [DataMetadata] = []
@State private var showConfirm = false
Expand All @@ -35,9 +35,11 @@ struct SettingsView: View {
.tag(teamNumberInput)
}
}
#if !os(watchOS)
.pickerStyle(.menu)
#endif
.onChange(of: teamNumberInput) { value in
UserDefaults.standard.set(teamNumberInput, forKey: "teamNumber")
UserDefaults(suiteName: "group.com.jayagra.beartracks")?.set(teamNumberInput, forKey: "teamNumber")
}
Picker("Event Code", selection: $eventCodeInput) {
if !settingsOptions.isEmpty {
Expand All @@ -50,9 +52,11 @@ struct SettingsView: View {
.tag(eventCodeInput)
}
}
#if !os(watchOS)
.pickerStyle(.menu)
#endif
.onChange(of: eventCodeInput) { value in
UserDefaults.standard.set(eventCodeInput, forKey: "eventCode")
UserDefaults(suiteName: "group.com.jayagra.beartracks")?.set(eventCodeInput, forKey: "eventCode")
}
Picker("Season", selection: $seasonInput) {
if !settingsOptions.isEmpty {
Expand All @@ -65,13 +69,15 @@ struct SettingsView: View {
.tag(seasonInput)
}
}
#if !os(watchOS)
.pickerStyle(.menu)
#endif
.onChange(of: seasonInput) { value in
UserDefaults.standard.set(seasonInput, forKey: "season")
UserDefaults(suiteName: "group.com.jayagra.beartracks")?.set(seasonInput, forKey: "season")
}
Toggle("Dark Mode", isOn: $darkMode)
.onChange(of: darkMode) { value in
UserDefaults.standard.set(darkMode, forKey: "darkMode")
UserDefaults(suiteName: "group.com.jayagra.beartracks")?.set(darkMode, forKey: "darkMode")
showAlert = true
}
}
Expand Down Expand Up @@ -126,6 +132,9 @@ struct SettingsView: View {
self.settingsOptions = result
}
}
#if os(watchOS)
.ignoresSafeArea(edges: .bottom)
#endif
}

func loadSettingsJson(completionBlock: @escaping ([DataMetadata]) -> Void) -> Void {
Expand Down Expand Up @@ -170,23 +179,23 @@ struct SettingsView: View {
if data != nil {
if let httpResponse = response as? HTTPURLResponse {
if httpResponse.statusCode == 200 {
#if !os(visionOS)
#if !os(visionOS) && !os(watchOS)
UINotificationFeedbackGenerator().notificationOccurred(.success)
#endif
} else {
#if !os(visionOS)
#if !os(visionOS) && !os(watchOS)
UINotificationFeedbackGenerator().notificationOccurred(.error)
#endif
}
}
} else {
#if !os(visionOS)
#if !os(visionOS) && !os(watchOS)
UINotificationFeedbackGenerator().notificationOccurred(.error)
#endif
}
}.resume()
} catch {
#if !os(visionOS)
#if !os(visionOS) && !os(watchOS)
UINotificationFeedbackGenerator().notificationOccurred(.error)
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion ios/beartracks/bearTracks/TeamStatController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TeamStatController: ObservableObject {
@Published public var teamData: [TeamStats] = []

public func fetchTeamDataJson() {
guard let url = URL(string: "https://beartracks.io/api/v1/game/team_data/2024/\(UserDefaults.standard.string(forKey: "eventCode") ?? "CAFR")/\(teamNumber)") else { return }
guard let url = URL(string: "https://beartracks.io/api/v1/game/team_data/2024/\(UserDefaults(suiteName: "group.com.jayagra.beartracks")?.string(forKey: "eventCode") ?? "CAFR")/\(teamNumber)") else { return }
sharedSession.dataTask(with: url) { data, _, error in
if let data = data {
do {
Expand Down
Loading

0 comments on commit 0b717b6

Please sign in to comment.