-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #547 from pennlabs/ticket-scanner
Add the ticket scanner
- Loading branch information
Showing
12 changed files
with
1,007 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
{ | ||
"Version": 1.0, | ||
"Pattern": [ | ||
{ | ||
"Event": { | ||
"Time": 0, | ||
"EventType": "HapticTransient", | ||
"EventParameters": | ||
[ | ||
{ | ||
"ParameterID": "HapticIntensity", | ||
"ParameterValue": 1.0 | ||
}, | ||
{ | ||
"ParameterID": "HapticSharpness", | ||
"ParameterValue": 1.0 | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"Event": { | ||
"Time": 0.05, | ||
"EventType": "HapticTransient", | ||
"EventParameters": | ||
[ | ||
{ | ||
"ParameterID": "HapticIntensity", | ||
"ParameterValue": 0.8 | ||
}, | ||
{ | ||
"ParameterID": "HapticSharpness", | ||
"ParameterValue": 0.6 | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"Event": { | ||
"Time": 0.1, | ||
"EventType": "HapticTransient", | ||
"EventParameters": | ||
[ | ||
{ | ||
"ParameterID": "HapticIntensity", | ||
"ParameterValue": 0.8 | ||
}, | ||
{ | ||
"ParameterID": "HapticSharpness", | ||
"ParameterValue": 0.6 | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"Event": { | ||
"Time": 0.15, | ||
"EventType": "HapticTransient", | ||
"EventParameters": | ||
[ | ||
{ | ||
"ParameterID": "HapticIntensity", | ||
"ParameterValue": 0.8 | ||
}, | ||
{ | ||
"ParameterID": "HapticSharpness", | ||
"ParameterValue": 0.6 | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"Event": { | ||
"Time": 0.2, | ||
"EventType": "HapticTransient", | ||
"EventParameters": | ||
[ | ||
{ | ||
"ParameterID": "HapticIntensity", | ||
"ParameterValue": 0.8 | ||
}, | ||
{ | ||
"ParameterID": "HapticSharpness", | ||
"ParameterValue": 0.6 | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"Version": 1.0, | ||
"Pattern": [ | ||
{ | ||
"Event": { | ||
"Time": 0, | ||
"EventType": "HapticContinuous", | ||
"EventDuration": 0.2, | ||
"EventParameters": | ||
[ | ||
{ | ||
"ParameterID": "HapticIntensity", | ||
"ParameterValue": 0.8 | ||
}, | ||
{ | ||
"ParameterID": "HapticSharpness", | ||
"ParameterValue": 0.5 | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"Version": 1.0, | ||
"Pattern": [ | ||
{ | ||
"Event": { | ||
"Time": 0, | ||
"EventType": "HapticContinuous", | ||
"EventDuration": 0.2, | ||
"EventParameters": | ||
[ | ||
{ | ||
"ParameterID": "HapticIntensity", | ||
"ParameterValue": 0.8 | ||
}, | ||
{ | ||
"ParameterID": "HapticSharpness", | ||
"ParameterValue": 0.5 | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"Event": { | ||
"Time": 0.3, | ||
"EventType": "HapticContinuous", | ||
"EventDuration": 0.2, | ||
"EventParameters": | ||
[ | ||
{ | ||
"ParameterID": "HapticIntensity", | ||
"ParameterValue": 0.8 | ||
}, | ||
{ | ||
"ParameterID": "HapticSharpness", | ||
"ParameterValue": 0.5 | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"Event": { | ||
"Time": 0.6, | ||
"EventType": "HapticContinuous", | ||
"EventDuration": 0.2, | ||
"EventParameters": | ||
[ | ||
{ | ||
"ParameterID": "HapticIntensity", | ||
"ParameterValue": 0.8 | ||
}, | ||
{ | ||
"ParameterID": "HapticSharpness", | ||
"ParameterValue": 0.5 | ||
} | ||
] | ||
} | ||
}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// | ||
// ScannerState.swift | ||
// PennMobile | ||
// | ||
// Created by Anthony Li on 4/22/24. | ||
// Copyright © 2024 PennLabs. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
import UIKit | ||
|
||
struct ScannedTicket { | ||
enum InvalidReason: Error { | ||
case malformedTicket | ||
case badRequest(String) | ||
case notFound | ||
} | ||
|
||
enum Status { | ||
case valid(Ticket) | ||
case duplicate(Ticket) | ||
case invalid(InvalidReason) | ||
} | ||
|
||
var status: Status | ||
var scanTime: Date | ||
} | ||
|
||
enum ScannerState { | ||
case noTicket | ||
case loading(String) | ||
case scanned(ScannedTicket, String) | ||
case error(Error) | ||
} | ||
|
||
extension ScannerState { | ||
struct Label { | ||
var title: LocalizedStringKey | ||
var icon: String | ||
var background: Color | ||
var foreground: Color | ||
} | ||
|
||
var label: Label { | ||
switch self { | ||
case .noTicket: | ||
Label(title: "Scanning", icon: "viewfinder", background: .init(UIColor.systemBackground), foreground: .secondary) | ||
case .loading: | ||
Label(title: "Checking", icon: "ticket", background: .init(UIColor.systemBackground), foreground: .primary) | ||
case .scanned(let ticket, _): | ||
switch ticket.status { | ||
case .valid: | ||
Label(title: "Valid", icon: "checkmark.circle", background: .green, foreground: .white) | ||
case .duplicate: | ||
Label(title: "Duplicate", icon: "exclamationmark.triangle.fill", background: .yellow, foreground: .black) | ||
case .invalid: | ||
Label(title: "Invalid", icon: "hand.raised.fill", background: .red, foreground: .white) | ||
} | ||
case .error: | ||
Label(title: "Error", icon: "ant", background: .init(UIColor.systemBackground), foreground: .red) | ||
} | ||
} | ||
} | ||
|
||
enum ScannerInternalError: Error { | ||
case insufficientEventPermissions | ||
|
||
var localizedDescription: String { | ||
switch self { | ||
case .insufficientEventPermissions: | ||
String(localized: "You don't have permission to validate tickets for this event.") | ||
} | ||
} | ||
} |
Oops, something went wrong.