Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion SPAR/SPAR.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
3D98C7F42D4FE04500462EF4 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D98C7F32D4FE04500462EF4 /* ContentView.swift */; };
3D98C7F62D4FE04700462EF4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3D98C7F52D4FE04700462EF4 /* Assets.xcassets */; };
3D98C7F92D4FE04700462EF4 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3D98C7F82D4FE04700462EF4 /* Preview Assets.xcassets */; };
3DA1AA442DBDB01300678160 /* DiskIOModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D505B6E2DBACDCA00510486 /* DiskIOModel.swift */; };
3DA1AA452DBDB08700678160 /* AppSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D505B5C2DBA657B00510486 /* AppSettings.swift */; };
3DCE45892D68C19200FACBB8 /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DCE45882D68C19200FACBB8 /* Constant.swift */; };
3DCE458B2D68C19F00FACBB8 /* SplashScreenView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DCE458A2D68C19F00FACBB8 /* SplashScreenView.swift */; };
3DCE458D2D68C1A900FACBB8 /* Logger+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DCE458C2D68C1A900FACBB8 /* Logger+Extension.swift */; };
Expand Down Expand Up @@ -216,7 +218,6 @@
3D505B5A2DB9E3F700510486 /* ProcessViewModel.swift */,
3D505B642DBAAE4D00510486 /* DiskUsageViewModel.swift */,
3D505B6A2DBAC5EC00510486 /* CpuUsageViewModel.swift */,
3D505B6E2DBACDCA00510486 /* DiskIOModel.swift */,
3D505B702DBACDE500510486 /* DiskIOViewModel.swift */,
);
path = ViewModel;
Expand All @@ -235,6 +236,7 @@
3D505B5E2DBA94B200510486 /* LoginModel.swift */,
3D505B622DBAAE2C00510486 /* DiskUsage.swift */,
3D505B682DBAB31D00510486 /* CPUUsage.swift */,
3D505B6E2DBACDCA00510486 /* DiskIOModel.swift */,
);
path = Data;
sourceTree = "<group>";
Expand Down Expand Up @@ -445,6 +447,7 @@
3D5995102DB413E300E9215B /* NetworkManagerTests.swift in Sources */,
3D59950B2DB4137E00E9215B /* MockNetworkService.swift in Sources */,
3D5995112DB4162400E9215B /* NetworkManager.swift in Sources */,
3DA1AA442DBDB01300678160 /* DiskIOModel.swift in Sources */,
3D5995152DB4167A00E9215B /* MemoryUsage.swift in Sources */,
3D505B762DBACFB100510486 /* DiskUsage.swift in Sources */,
3D5995132DB4167400E9215B /* ProcessStatus.swift in Sources */,
Expand All @@ -458,6 +461,7 @@
3D505B772DBACFB500510486 /* CPUUsage.swift in Sources */,
3D5995142DB4167700E9215B /* BatteryInfo.swift in Sources */,
3D505B612DBA9EF200510486 /* Onboarding.swift in Sources */,
3DA1AA452DBDB08700678160 /* AppSettings.swift in Sources */,
3D59950C2DB4138E00E9215B /* NetworkService.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,69 @@
landmarkType = "3">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "32F93E3F-4F09-420E-9295-E8DA588C0C40"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "SPAR/ViewModel/BatteryViewModel.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "37"
endingLineNumber = "37"
landmarkName = "fetchBatteryInfo(device:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "04D26233-6466-4FCF-87B6-2158621E72B8"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "SPAR/ViewModel/HomeViewModel.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "37"
endingLineNumber = "37"
landmarkName = "getDeviceData()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "9F496AF5-2BA7-4384-BB8C-F0B60E13AE01"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "SPAR/ViewModel/ProcessViewModel.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "21"
endingLineNumber = "21"
landmarkName = "fetchProcessInfo(device:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "84940FE7-5CAE-4A83-A81B-9ADF5CBFD006"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "SPAR/NetworkService/NetworkManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "29"
endingLineNumber = "29"
landmarkName = "fetchCPUUsageInfo(for:deviceId:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
2 changes: 1 addition & 1 deletion SPAR/SPAR/Data/BatteryInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

struct BatteryInfo: Codable, Identifiable {
let id: Int
let userId: String
let userId: Int
let hasBattery: Bool
let batteryPercentage: Int
let powerConsumption: Double
Expand Down
59 changes: 24 additions & 35 deletions SPAR/SPAR/Data/CPUUsage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,44 @@ struct CpuCoreUsage: Codable {
let usage: Double
}

struct CpuUsage: Codable, Identifiable {
struct CpuUsage: Decodable {
let id: Int
let totalCpuLoad: Double
let perCoreUsage: [CpuCoreUsage]
let userId: Int
let deviceId: String
let timestamp: String

private enum CodingKeys: String, CodingKey {
case id, totalCpuLoad, perCoreUsageJson, userId, deviceId, timestamp
}

// Manual initializer for use in mock/sample data
init(id: Int, totalCpuLoad: Double, perCoreUsage: [CpuCoreUsage], userId: Int, deviceId: String, timestamp: String) {
self.id = id
self.totalCpuLoad = totalCpuLoad
self.perCoreUsage = perCoreUsage
self.userId = userId
self.deviceId = deviceId
self.timestamp = timestamp
let perCoreUsage: [CpuCoreUsage]

enum CodingKeys: String, CodingKey {
case id, totalCpuLoad, userId, deviceId, timestamp, perCoreUsageJson
}

// Decoding from API response

init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

id = try container.decode(Int.self, forKey: .id)
totalCpuLoad = try container.decode(Double.self, forKey: .totalCpuLoad)
userId = try container.decode(Int.self, forKey: .userId)
deviceId = try container.decode(String.self, forKey: .deviceId)
timestamp = try container.decode(String.self, forKey: .timestamp)

let jsonString = try container.decode(String.self, forKey: .perCoreUsageJson)
let jsonData = Data(jsonString.utf8)
perCoreUsage = try JSONDecoder().decode([CpuCoreUsage].self, from: jsonData)

// No cleaning, just decode directly
if let jsonData = jsonString.data(using: .utf8) {
perCoreUsage = (try? JSONDecoder().decode([CpuCoreUsage].self, from: jsonData)) ?? []
} else {
perCoreUsage = []
}
}

// Encoding back to JSON string
func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)

try container.encode(id, forKey: .id)
try container.encode(totalCpuLoad, forKey: .totalCpuLoad)
try container.encode(userId, forKey: .userId)
try container.encode(deviceId, forKey: .deviceId)
try container.encode(timestamp, forKey: .timestamp)

let jsonData = try JSONEncoder().encode(perCoreUsage)
let jsonString = String(data: jsonData, encoding: .utf8)!
try container.encode(jsonString, forKey: .perCoreUsageJson)

// Manual initializer for sample/mock data
init(id: Int, totalCpuLoad: Double, perCoreUsage: [CpuCoreUsage], userId: Int, deviceId: String, timestamp: String) {
self.id = id
self.totalCpuLoad = totalCpuLoad
self.perCoreUsage = perCoreUsage
self.userId = userId
self.deviceId = deviceId
self.timestamp = timestamp
}
}
2 changes: 1 addition & 1 deletion SPAR/SPAR/Data/DeviceSpecification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

struct DeviceSpecification: Codable, Identifiable {
let id: Int
let userId: String
let userId: Int
let deviceName: String
let manufacturer: String
let model: String
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion SPAR/SPAR/Data/LoginModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ struct LoginRequest: Encodable {

struct LoginResponse: Decodable {
let token: String
let id: Int
let userId: Int
}
2 changes: 1 addition & 1 deletion SPAR/SPAR/Data/MemoryUsage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

struct MemoryUsage: Codable, Identifiable {
let id: Int
let userId: String
let userId: Int
let totalMemory: Double
let usedMemory: Double
let availableMemory: Double
Expand Down
57 changes: 45 additions & 12 deletions SPAR/SPAR/Data/MockData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct MockData {
static let sampleDeviceData = """
[
{
"userId": "user123",
"userId": 1,
"deviceId": 5,
"deviceName": "MyComputer",
"manufacturer": "Dell",
Expand All @@ -26,15 +26,15 @@ struct MockData {
"timestamp": "2025-03-28T16:03:30.041384"
},
{
"userId": "user123",
"userId": 1,
"deviceId": 13,
"deviceName": "MyComputer",
"deviceName": "Home",
"manufacturer": "Dell",
"model": "Inspiron 15",
"processor": "Intel Core i7 2.8 GHz",
"cpuPhysicalCores": 4,
"cpuLogicalCores": 8,
"installedRam": 16.0,
"installedRam": 32.0,
"graphics": "NVIDIA GTX 1650",
"operatingSystem": "Windows 10 x64",
"systemType": "x64 operating system, x64-based processor",
Expand All @@ -46,7 +46,7 @@ struct MockData {
static let sampleProcessData = """
[
{
"userId": "user123",
"userId": 1,
"id": 101,
"pid": 1234,
"name": "chrome.exe",
Expand All @@ -55,7 +55,7 @@ struct MockData {
"timestamp": "2025-04-13T15:29:00.236114"
},
{
"userId": "user123",
"userId": 1,
"id": 102,
"pid": 5678,
"name": "node.exe",
Expand All @@ -67,30 +67,63 @@ struct MockData {
""".data(using: .utf8)!

static let sampleBatteryData = """
[
{
"userId": "user123",
"userId": 1,
"id": 7,
"hasBattery": true,
"batteryPercentage": 85,
"powerConsumption": 5.0,
"timestamp": "2025-04-13T15:29:10.549936",
"charging": false
}
]
""".data(using: .utf8)!

static let sampleMemoryUsageData = """
[
{
"userId": "user123",
"userId": 1,
"id": 7,
"totalMemory": 16.0,
"usedMemory": 8.5,
"availableMemory": 7.5,
"timestamp": "2025-04-13T15:28:49.261218"
}
]
""".data(using: .utf8)!
static let sampleDiskUsageData = """
{
"id": 5,
"filesystem": "/dev/sda1",
"sizeGB": 512.0,
"usedGB": 200.0,
"availableGB": 312.0,
"userId": 1,
"deviceId": "331330ac-5f82-43b0-9d39-84e1f7e7e358",
"timestamp": "2025-04-22T15:57:10.390972"
}
""".data(using: .utf8)!
static let sampleCPUUsageData = """
{
"id": 7,
"totalCpuLoad": 42.5,
"perCoreUsageJson": "[{\"core\":1,\"usage\":35.0}]",
"userId": 1,
"deviceId": "331330ac-5f82-43b0-9d39-84e1f7e7e358",
"timestamp": "2025-04-22T15:57:10.351457"
}
""".data(using: .utf8)!
static let sampleDiskIOUsageData = """
{"id": 5,
"readSpeedMBps": 120.0,
"writeSpeedMBps": 80.0,
"userId": 1,
"deviceId": "331330ac-5f82-43b0-9d39-84e1f7e7e358",
"timestamp": "2025-04-22T15:57:10.377292"
}
""".data(using: .utf8)!
static let sampleLoginData = """
{
"token": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhbGljZSIsImlhdCI6MTc0NTM1MDY1NCwiZXhwIjo5MjIzNTQ2NTcxOTIwMn0.BypJMZiF7ooVbYXCioOQAljTyjmR9ET5aJTC9auiVxw",
"userId": 1
}
""".data(using: .utf8)!
}

Expand Down
2 changes: 1 addition & 1 deletion SPAR/SPAR/Data/ProcessStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

struct ProcessStatus: Codable, Identifiable {
let id: Int
let userId: String
let userId: Int
let pid: Int
let name: String
let cpuUsage: Double
Expand Down
4 changes: 2 additions & 2 deletions SPAR/SPAR/Device/BatteryDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct BatteryDetailView: View {
InfoRow(label: StringConstant.deviceName, value: device.deviceName)
InfoRow(label: StringConstant.Charging, value: viewModel.batteryInfo.charging ? StringConstant.batYes : StringConstant.batNo)
InfoRow(label: StringConstant.power, value: String(format: "%.2f W", viewModel.batteryInfo.powerConsumption))
InfoRow(label: StringConstant.timestamp, value: viewModel.batteryInfo.timestamp)
InfoRow(label: StringConstant.timestamp, value: viewModel.batteryInfo.timestamp.toFormattedDate())
}
}
.padding()
Expand Down Expand Up @@ -110,7 +110,7 @@ struct BatteryDetailView: View {
#Preview {
BatteryDetailView(device: DeviceSpecification(
id: 1,
userId: "User123",
userId: 1,
deviceName: "MyComputer",
manufacturer: "Dell",
model: "Inspiron 15",
Expand Down
2 changes: 1 addition & 1 deletion SPAR/SPAR/Device/CpuUsageDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ struct CpuUsageDetailView: View {
#Preview {
CpuUsageDetailView(device: DeviceSpecification(
id: 1,
userId: "User123",
userId: 1,
deviceName: "MyComputer",
manufacturer: "Dell",
model: "Inspiron 15",
Expand Down
2 changes: 1 addition & 1 deletion SPAR/SPAR/Device/DeviceOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ struct DeviceInfoRow: View {
NavigationStack {
DeviceOptions(currentView: .constant(.detailPage), device: DeviceSpecification(
id: 1,
userId: "User123",
userId: 1,
deviceName: "MyComputer",
manufacturer: "Dell",
model: "Inspiron 15",
Expand Down
2 changes: 1 addition & 1 deletion SPAR/SPAR/Device/DiskIODetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ struct DiskIODetailView: View {
#Preview {
DiskIODetailView(device: DeviceSpecification(
id: 1,
userId: "User123",
userId: 1,
deviceName: "MyComputer",
manufacturer: "Dell",
model: "Inspiron 15",
Expand Down
Loading
Loading