SPB Git

Repository Public

DemoData.swift 10.1 KB 217 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : KA Maps Engine9// File             : sdk/ios/Example/App/DemoData.swift10// Module           : sdk11// Repository       : https://git.spboucher.ai/ka-maps-engine12// Created          : 2026-12-0113// Last Modified    : 2026-12-0114//15// =============================================================================16// AUTHOR & PROFESSIONAL AFFILIATION17// =============================================================================18//19// Author           : Simon-Pierre Boucher20// Position         : Professor of Finance21// Institution      : Université du Québec en Outaouais (UQO)22// Department       : Département des sciences administratives23// Organization     : SP Boucher24//25// Website          : https://spboucher.ai26// Git              : https://git.spboucher.ai27//28// =============================================================================29// OFFICIAL CONTACT DIRECTORY30// =============================================================================31//32// General          : info@spboucher.ai33// Professional     : contact@spboucher.ai34// Direct           : simon@spboucher.ai35// Research         : research@spboucher.ai36// Development      : dev@spboucher.ai37// Support          : support@spboucher.ai38// Security/Admin   : admin@spboucher.ai39// Notifications    : notifications@spboucher.ai40//41// Preferred Contact: support@spboucher.ai42//43// =============================================================================44// COPYRIGHT & INTELLECTUAL PROPERTY45// =============================================================================46//47// Copyright (c) 202648// Simon-Pierre Boucher49//50// All rights reserved where applicable.51//52// This file is governed by the applicable project license,53// copyright notices, institutional agreements and relevant law.54//55// Unless expressly authorized by the applicable license or56// rights holder, copying, redistribution, sublicensing,57// publication and commercial exploitation are not permitted.58//59// Existing third-party rights and notices remain unaffected.60//61// =============================================================================62// CONFIDENTIALITY & SECURITY63// =============================================================================64//65// Classification   : Public66// Distribution     : Public repository; use is governed by the project license67// Security Contact : admin@spboucher.ai68//69// Access to this source does not independently grant permission70// to redistribute or disclose confidential materials.71//72// Do not embed credentials, private keys, access tokens,73// certificates or confidential personal information.74//75// =============================================================================76// LICENSE & MAINTENANCE77// =============================================================================78//79// License          : None specified (no license file in this repository)80// Maintainer       : Simon-Pierre Boucher81// Technical Contact: dev@spboucher.ai82//83// =============================================================================84// END OF SP BOUCHER SOURCE HEADER85// =============================================================================8687import CoreLocation88import Foundation89import KAMaps9091/// Lieux d'essai : une métropole, une capitale, une campagne.92enum DemoPlace: String, CaseIterable, Identifiable {93    case montreal, quebec, rural94    var id: String { rawValue }9596    var title: String {97        switch self {98        case .montreal: "Montréal"99        case .quebec: "Québec"100        case .rural: "Kamouraska"101        }102    }103104    var coordinate: CLLocationCoordinate2D {105        switch self {106        case .montreal: CLLocationCoordinate2D(latitude: 45.5019, longitude: -73.5674)107        case .quebec: CLLocationCoordinate2D(latitude: 46.8139, longitude: -71.2080)108        case .rural: CLLocationCoordinate2D(latitude: 47.5650, longitude: -69.8660)109        }110    }111112    var zoom: Double { self == .rural ? 12.5 : 13.5 }113}114115/// Générateur déterministe (les essais et les captures sont reproductibles).116struct SeededRandom {117    private var state: UInt64118    init(seed: UInt64) { state = seed &* 0x9E37_79B9_7F4A_7C15 | 1 }119    mutating func next() -> Double {120        state ^= state << 13121        state ^= state >> 7122        state ^= state << 17123        return Double(state % 1_000_000) / 1_000_000124    }125}126127/// Données de démonstration. Ce sont des données FICTIVES, générées : aucune n'est une annonce réelle.128enum DemoData {129    static func price(_ v: Double, brand: KABrand?) -> String {130        switch brand {131        case .louka: return "\(Int(v).formatted(.number.grouping(.automatic))) $"132        default:133            return v >= 1_000_000 ? String(format: "%.2f M$", v / 1_000_000) : "\(Int(v / 1000)) k$"134        }135    }136137    /// Pastilles autour d'un centre (loyers pour Lou-Ka, prix ailleurs).138    static func markers(around c: CLLocationCoordinate2D, count: Int, brand: KABrand?, spread: Double = 0.045, seed: UInt64 = 7) -> [KAMarker] {139        var r = SeededRandom(seed: seed)140        return (0..<count).map { i in141            // Deux noyaux denses + une dispersion : les grappes ont de quoi se former.142            let k = r.next()143            let s = k < 0.45 ? spread * 0.25 : spread144            let lat = c.latitude + (r.next() - 0.5) * s * (k < 0.2 ? 0.6 : 1.4) + (k < 0.2 ? 0.012 : 0)145            let lon = c.longitude + (r.next() - 0.5) * s * 2 + (k < 0.2 ? -0.02 : 0)146            let value = brand == .louka ? 900 + (r.next() * 2200).rounded() : 280_000 + (r.next() * 1_400_000).rounded()147            let n = r.next()148            let nature: KANature = n > 0.92 ? .hypothesis : (n > 0.8 ? .estimated : .observed)149            let label = price(value, brand: brand)150            return KAMarker(id: "m\(i)", coordinate: CLLocationCoordinate2D(latitude: lat, longitude: lon), label: label, value: value, nature: nature, accessibilityLabel: "Fictif \(i + 1), \(label)")151        }152    }153154    static func points(around c: CLLocationCoordinate2D, count: Int, spread: Double = 0.03, seed: UInt64 = 11, range: ClosedRange<Double> = 0...1) -> [KAPoint] {155        var r = SeededRandom(seed: seed)156        return (0..<count).map { i in157            let lat = c.latitude + (r.next() - 0.5) * spread158            let lon = c.longitude + (r.next() - 0.5) * spread * 1.6159            let v = range.lowerBound + r.next() * (range.upperBound - range.lowerBound)160            return KAPoint(id: "p\(i)", coordinate: CLLocationCoordinate2D(latitude: lat, longitude: lon), value: v, height: 20 + v * 120, nature: .estimated)161        }162    }163164    /// Zone d'étude : hexagone autour du centre.165    static func zone(around c: CLLocationCoordinate2D, radius: Double = 0.012) -> [CLLocationCoordinate2D] {166        (0..<6).map { i in167            let a = Double(i) * .pi / 3168            return CLLocationCoordinate2D(latitude: c.latitude + sin(a) * radius * 0.7, longitude: c.longitude + cos(a) * radius)169        }170    }171172    static func path(from c: CLLocationCoordinate2D) -> [CLLocationCoordinate2D] {173        (0..<8).map { i in174            let t = Double(i) / 7175            return CLLocationCoordinate2D(latitude: c.latitude - 0.01 + t * 0.02 + sin(t * 6) * 0.002, longitude: c.longitude - 0.02 + t * 0.04)176        }177    }178179    /// Surface de valeur lissée (gaussienne décentrée) sur une grille.180    static func surface(around c: CLLocationCoordinate2D, half: Double = 0.02, n: Int = 24) -> KASurfaceGrid {181        var values: [Double?] = []182        for row in 0..<n {183            for col in 0..<n {184                let x = Double(col) / Double(n - 1) - 0.4, y = Double(row) / Double(n - 1) - 0.55185                let v = exp(-(x * x + y * y) * 9) + 0.35 * exp(-((x - 0.4) * (x - 0.4) + (y + 0.3) * (y + 0.3)) * 22)186                values.append(row < 2 && col > n - 4 ? nil : v)187            }188        }189        return KASurfaceGrid(bounds: KABounds(west: c.longitude - half * 1.5, south: c.latitude - half, east: c.longitude + half * 1.5, north: c.latitude + half), columns: n, rows: n, values: values)190    }191192    static let valueScale = KAScale(.linear, stops: [(0, "#2f6f8f"), (0.5, "#e8d28a"), (1, "#b5452c")], nullColor: "#9a968c")193    static let stepScale = KAScale(.steps, stops: [(0, "#dfe8d5"), (0.33, "#a9c79a"), (0.66, "#5f9a66"), (0.9, "#2c6b46")], nullColor: "#9a968c")194195    /// Toutes les couches d'application, une par type.196    static func layer(_ kind: KALayerKind, around c: CLLocationCoordinate2D, brand: KABrand?) -> KALayer {197        switch kind {198        case .markers:199            return .markers(id: "markers", markers(around: c, count: 260, brand: brand), cluster: KAClusterOptions(radius: 56, maxZoom: 15, aggregate: .median, label: .count))200        case .points:201            return .points(id: "points", points(around: c, count: 400), radius: 5, scale: valueScale, strokeColor: "#ffffff", strokeWidth: 1, opacity: 0.9)202        case .polygons:203            return .polygon(id: "polygons", ring: zone(around: c), value: 0.6, fillColor: "#b5452c", fillOpacity: 0.18, strokeColor: "#b5452c", strokeWidth: 2, nature: .hypothesis)204        case .lines:205            return .line(id: "lines", path: path(from: c), color: "#1f4e79", width: 4, dash: [8, 5])206        case .heat:207            return .heat(id: "heat", points(around: c, count: 900, spread: 0.05, seed: 23), radius: 26, intensity: 0.9, opacity: 0.75, normalize: true)208        case .buildings:209            return .buildings(id: "buildings", points(around: c, count: 500, spread: 0.012, seed: 31), scale: valueScale, toleranceMeters: 12)210        case .columns:211            return .columns(id: "columns", points(around: CLLocationCoordinate2D(latitude: c.latitude + 0.012, longitude: c.longitude + 0.02), count: 40, spread: 0.012, seed: 43), scale: stepScale, widthMeters: 26)212        case .surface:213            return .surface(id: "surface", surface(around: c), scale: valueScale, fillOpacity: 0.55)214        }215    }216}217
Files main
Menu

Theme