Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable any statistic logs #5846

Merged
merged 1 commit into from
May 27, 2024
Merged
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
130 changes: 65 additions & 65 deletions UnstoppableWallet/UnstoppableWallet/Core/Managers/StatManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,73 +28,73 @@ class StatManager {
}

func logStat(eventPage: StatPage, eventSection: StatSection? = nil, event: StatEvent) {
var parameters: [String: Any]?

if let params = event.params {
parameters = [String: Any]()

for (key, value) in params {
parameters?[key.rawValue] = value
}
}

let record = StatRecord(
timestamp: Int(Date().timeIntervalSince1970),
eventPage: eventPage.rawValue,
eventSection: eventSection?.rawValue,
event: event.name,
params: parameters
)

do {
try storage.save(record: record)
} catch {
print("Cannot save StatRecord: \(error)")
}
// var parameters: [String: Any]?
//
// if let params = event.params {
// parameters = [String: Any]()
//
// for (key, value) in params {
// parameters?[key.rawValue] = value
// }
// }
//
// let record = StatRecord(
// timestamp: Int(Date().timeIntervalSince1970),
// eventPage: eventPage.rawValue,
// eventSection: eventSection?.rawValue,
// event: event.name,
// params: parameters
// )
//
// do {
// try storage.save(record: record)
// } catch {
// print("Cannot save StatRecord: \(error)")
// }
}

func sendStats() {
let lastSent: Double? = userDefaultsStorage.value(for: Self.keyLastSent)

if let lastSent, Date().timeIntervalSince1970 - lastSent < Self.sendThreshold {
return
}

Task { [storage] in
let records = try storage.all()

guard !records.isEmpty else {
return
}

let stats = records.map { record in
var object: [String: Any] = [
"time": record.timestamp,
"event_page": record.eventPage,
"event": record.event,
]

if let eventSection = record.eventSection {
object["event_section"] = eventSection
}

if let params = record.params {
for (key, value) in params {
object[key] = value
}
}

return object
}

// let data = try JSONSerialization.data(withJSONObject: stats)
// let string = String(data: data, encoding: .utf8)
// print(string ?? "N/A")

try await marketKit.send(stats: stats, appVersion: appVersion, appId: appId)

userDefaultsStorage.set(value: Date().timeIntervalSince1970, for: Self.keyLastSent)
try storage.clear()
}
// let lastSent: Double? = userDefaultsStorage.value(for: Self.keyLastSent)
//
// if let lastSent, Date().timeIntervalSince1970 - lastSent < Self.sendThreshold {
// return
// }
//
// Task { [storage] in
// let records = try storage.all()
//
// guard !records.isEmpty else {
// return
// }
//
// let stats = records.map { record in
// var object: [String: Any] = [
// "time": record.timestamp,
// "event_page": record.eventPage,
// "event": record.event,
// ]
//
// if let eventSection = record.eventSection {
// object["event_section"] = eventSection
// }
//
// if let params = record.params {
// for (key, value) in params {
// object[key] = value
// }
// }
//
// return object
// }
//
//// let data = try JSONSerialization.data(withJSONObject: stats)
//// let string = String(data: data, encoding: .utf8)
//// print(string ?? "N/A")
//
// try await marketKit.send(stats: stats, appVersion: appVersion, appId: appId)
//
// userDefaultsStorage.set(value: Date().timeIntervalSince1970, for: Self.keyLastSent)
// try storage.clear()
// }
}
}
Loading