-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUserModel.swift
88 lines (82 loc) · 3.56 KB
/
UserModel.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// UserModel.swift
// All In
//
// Created by Peter Bidoshi on 4/22/24.
//
import Foundation
// Helper function to generate monthly gain loss data
private func generateMonthlyGainLoss() -> [DailyGainLoss] {
var result: [DailyGainLoss] = []
for i in 1...12 {
let date = Calendar.current.date(byAdding: .day, value: -(12-i), to: Date())!
let value = Int.random(in: -800...1200)
result.append(DailyGainLoss(day: "\(i)", value: value, date: date))
}
return result
}
struct User: Codable, Identifiable {
let id: Int
let username: String
let email: String
let balance: Int
let contracts: [Contract]
let sellerTransactions: [Transaction]
let buyerTransactions: [Transaction]
let createdAt: Date
let totalProfit: Int
let ranking: Int
let weeklyGainLoss: [DailyGainLoss]
let monthlyGainLoss: [DailyGainLoss]
}
extension User {
static let dummyData: [User] = [
User(
id: 0,
username: "antoinztte",
email: "[email protected]",
balance: 1000,
contracts: [
Contract.dummyData[0],
Contract.dummyData[1]
],
sellerTransactions: [],
buyerTransactions: [],
createdAt: Calendar.current.date(byAdding: .day, value: -17, to: Date())!,
totalProfit: 64,
ranking: 52,
weeklyGainLoss: [
DailyGainLoss(day: "M", value: 1000, date: Calendar.current.date(byAdding: .day, value: -6, to: Date())!),
DailyGainLoss(day: "T", value: -2000, date: Calendar.current.date(byAdding: .day, value: -5, to: Date())!),
DailyGainLoss(day: "W", value: 3000, date: Calendar.current.date(byAdding: .day, value: -4, to: Date())!),
DailyGainLoss(day: "TH", value: -1500, date: Calendar.current.date(byAdding: .day, value: -3, to: Date())!),
DailyGainLoss(day: "F", value: 2500, date: Calendar.current.date(byAdding: .day, value: -2, to: Date())!),
DailyGainLoss(day: "S", value: 1200, date: Calendar.current.date(byAdding: .day, value: -1, to: Date())!),
DailyGainLoss(day: "SU", value: -800, date: Date())
],
monthlyGainLoss: generateMonthlyGainLoss()
),
User(
id: 1,
username: "peterbidoshi",
email: "[email protected]",
balance: 1500,
contracts: [],
sellerTransactions: [],
buyerTransactions: [],
createdAt: Calendar.current.date(byAdding: .day, value: -30, to: Date())!,
totalProfit: 25,
ranking: 87,
weeklyGainLoss: [
DailyGainLoss(day: "M", value: 500, date: Calendar.current.date(byAdding: .day, value: -6, to: Date())!),
DailyGainLoss(day: "T", value: 4000, date: Calendar.current.date(byAdding: .day, value: -5, to: Date())!),
DailyGainLoss(day: "W", value: -2500, date: Calendar.current.date(byAdding: .day, value: -4, to: Date())!),
DailyGainLoss(day: "TH", value: 200, date: Calendar.current.date(byAdding: .day, value: -3, to: Date())!),
DailyGainLoss(day: "F", value: -1200, date: Calendar.current.date(byAdding: .day, value: -2, to: Date())!),
DailyGainLoss(day: "S", value: 600, date: Calendar.current.date(byAdding: .day, value: -1, to: Date())!),
DailyGainLoss(day: "SU", value: 2000, date: Date())
],
monthlyGainLoss: generateMonthlyGainLoss()
)
]
}